• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.permission.cts;
18 
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 import android.media.AudioManager;
22 import android.telephony.TelephonyManager;
23 import android.test.AndroidTestCase;
24 import android.test.suitebuilder.annotation.SmallTest;
25 
26 /**
27  * Test the non-location-related functionality of TelephonyManager.
28  */
29 public class TelephonyManagerPermissionTest extends AndroidTestCase {
30 
31     private boolean mHasTelephony;
32     TelephonyManager mTelephonyManager = null;
33     private AudioManager mAudioManager;
34 
35     @Override
setUp()36     protected void setUp() throws Exception {
37         super.setUp();
38         mHasTelephony = getContext().getPackageManager().hasSystemFeature(
39                 PackageManager.FEATURE_TELEPHONY);
40         mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
41         assertNotNull(mTelephonyManager);
42         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
43         assertNotNull(mAudioManager);
44     }
45 
46     /**
47      * Verify that TelephonyManager.getDeviceId requires Permission.
48      * <p>
49      * Requires Permission:
50      * {@link android.Manifest.permission#READ_PHONE_STATE}.
51      */
52     @SmallTest
testGetDeviceId()53     public void testGetDeviceId() {
54         if (!mHasTelephony) {
55             return;
56         }
57 
58         try {
59             String id = mTelephonyManager.getDeviceId();
60             fail("Got device ID: " + id);
61         } catch (SecurityException e) {
62             // expected
63         }
64     }
65 
66     /**
67      * Verify that TelephonyManager.getLine1Number requires Permission.
68      * <p>
69      * Requires Permission:
70      * {@link android.Manifest.permission#READ_PHONE_STATE}.
71      */
72     @SmallTest
testGetLine1Number()73     public void testGetLine1Number() {
74         if (!mHasTelephony) {
75             return;
76         }
77 
78         try {
79             String nmbr = mTelephonyManager.getLine1Number();
80             fail("Got line 1 number: " + nmbr);
81         } catch (SecurityException e) {
82             // expected
83         }
84     }
85 
86     /**
87      * Verify that TelephonyManager.getSimSerialNumber requires Permission.
88      * <p>
89      * Requires Permission:
90      * {@link android.Manifest.permission#READ_PHONE_STATE}.
91      */
92     @SmallTest
testGetSimSerialNumber()93     public void testGetSimSerialNumber() {
94         if (!mHasTelephony) {
95             return;
96         }
97 
98         try {
99             String nmbr = mTelephonyManager.getSimSerialNumber();
100             fail("Got SIM serial number: " + nmbr);
101         } catch (SecurityException e) {
102             // expected
103         }
104     }
105 
106     /**
107      * Verify that TelephonyManager.getSubscriberId requires Permission.
108      * <p>
109      * Requires Permission:
110      * {@link android.Manifest.permission#READ_PHONE_STATE}.
111      */
112     @SmallTest
testGetSubscriberId()113     public void testGetSubscriberId() {
114         if (!mHasTelephony) {
115             return;
116         }
117 
118         try {
119             String sid = mTelephonyManager.getSubscriberId();
120             fail("Got subscriber id: " + sid);
121         } catch (SecurityException e) {
122             // expected
123         }
124     }
125 
126     /**
127      * Verify that TelephonyManager.getVoiceMailNumber requires Permission.
128      * <p>
129      * Requires Permission:
130      * {@link android.Manifest.permission#READ_PHONE_STATE}.
131      */
132     @SmallTest
testVoiceMailNumber()133     public void testVoiceMailNumber() {
134         if (!mHasTelephony) {
135             return;
136         }
137 
138         try {
139             String vmnum = mTelephonyManager.getVoiceMailNumber();
140             fail("Got voicemail number: " + vmnum);
141         } catch (SecurityException e) {
142             // expected
143         }
144     }
145     /**
146      * Verify that AudioManager.setMode requires Permission.
147      * <p>
148      * Requires Permissions:
149      * {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS} and
150      * {@link android.Manifest.permission#MODIFY_PHONE_STATE} for
151      * {@link AudioManager#MODE_IN_CALL}.
152      */
153     @SmallTest
testSetMode()154     public void testSetMode() {
155         if (!mHasTelephony) {
156             return;
157         }
158         int audioMode = mAudioManager.getMode();
159         mAudioManager.setMode(AudioManager.MODE_IN_CALL);
160         assertEquals(audioMode, mAudioManager.getMode());
161     }
162 }
163