1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.framework.permission.tests; 18 19import java.util.ArrayList; 20 21import android.telephony.SmsManager; 22import android.test.AndroidTestCase; 23import android.test.suitebuilder.annotation.SmallTest; 24 25/** 26 * Verify that SmsManager apis cannot be called without required permissions. 27 */ 28public class SmsManagerPermissionTest extends AndroidTestCase { 29 30 private static final String MSG_CONTENTS = "hi"; 31 private static final short DEST_PORT = (short)1004; 32 private static final String DEST_NUMBER = "4567"; 33 private static final String SRC_NUMBER = "1234"; 34 35 /** 36 * Verify that SmsManager.sendTextMessage requires permissions. 37 * <p>Tests Permission: 38 * {@link android.Manifest.permission#SEND_SMS}. 39 */ 40 @SmallTest 41 public void testSendTextMessage() { 42 try { 43 SmsManager.getDefault().sendTextMessage(SRC_NUMBER, DEST_NUMBER, MSG_CONTENTS, null, 44 null); 45 fail("SmsManager.sendTextMessage did not throw SecurityException as expected"); 46 } catch (SecurityException e) { 47 // expected 48 } 49 } 50 51 /** 52 * Verify that SmsManager.sendDataMessage requires permissions. 53 * <p>Tests Permission: 54 * {@link android.Manifest.permission#SEND_SMS}. 55 */ 56 @SmallTest 57 public void testSendDataMessage() { 58 try { 59 SmsManager.getDefault().sendDataMessage(SRC_NUMBER, DEST_NUMBER, DEST_PORT, 60 MSG_CONTENTS.getBytes(), null, null); 61 fail("SmsManager.sendDataMessage did not throw SecurityException as expected"); 62 } catch (SecurityException e) { 63 // expected 64 } 65 } 66 67 /** 68 * Verify that SmsManager.sendMultipartMessage requires permissions. 69 * <p>Tests Permission: 70 * {@link android.Manifest.permission#SEND_MMS}. 71 */ 72 @SmallTest 73 public void testSendMultipartMessage() { 74 try { 75 ArrayList<String> msgParts = new ArrayList<String>(2); 76 msgParts.add(MSG_CONTENTS); 77 msgParts.add("foo"); 78 SmsManager.getDefault().sendMultipartTextMessage(SRC_NUMBER, DEST_NUMBER, msgParts, 79 null, null); 80 fail("SmsManager.sendMultipartTextMessage did not throw SecurityException as expected"); 81 } catch (SecurityException e) { 82 // expected 83 } 84 } 85} 86