Adding CTS test case to validate getUiccSlotsInfo should throw security
exception if caller does not have READ_PRIVILEGED_PHONE_STATE.
Test: atest TelephonymanagerTest
Bug: 221431393
Change-Id: Idde1a91ea8692e2cfd2c5103c4f132ca11e2db77
diff --git a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
index cb80083..f6148af 100644
--- a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
@@ -4982,6 +4982,8 @@
public void getUiccSlotInfoTest() {
assumeTrue(hasFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION));
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .adoptShellPermissionIdentity("android.permission.READ_PRIVILEGED_PHONE_STATE");
UiccSlotInfo[] slotInfos = mTelephonyManager.getUiccSlotsInfo();
if (slotInfos == null) {
@@ -5002,6 +5004,22 @@
portInfo.getPortIndex();
}
}
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .dropShellPermissionIdentity();
+ }
+
+ @Test
+ public void testGetUiccSlotInfosFailsWithoutReadPhoneStatePrivilege() {
+ assumeTrue(hasFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION));
+ try {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .dropShellPermissionIdentity();
+ mTelephonyManager.getUiccSlotsInfo();
+ fail("TelephonyManager#getUiccSlotsInfo must be protected "
+ + "with READ_PRIVILEGED_PHONE_STATE");
+ } catch (SecurityException e) {
+ // expected
+ }
}
@Test