aboutsummaryrefslogtreecommitdiff
path: root/tests/telephonytests
diff options
context:
space:
mode:
authorMichael Groover <mpgroover@google.com>2020-06-22 19:25:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-06-22 19:25:34 +0000
commita44841eadca4e952de5746f13463f34083007c26 (patch)
treeff3a51da27455f9867d5bf82af6a4b4241021874 /tests/telephonytests
parent81306bdf1dca24a023ebc73d1314ca0c021723db (diff)
parenta368034a41e111bdb60ec29afcf0c3c4ca623e38 (diff)
downloadtelephony-a44841eadca4e952de5746f13463f34083007c26.tar.gz
Merge "Setup TelephonyPermissions mocks for all SubscriptionController tests" into rvc-dev
Diffstat (limited to 'tests/telephonytests')
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java14
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java4
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java35
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java12
4 files changed, 58 insertions, 7 deletions
diff --git a/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java
index f99fc35323..6480f65438 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java
@@ -647,14 +647,22 @@ public class PhoneSubInfoControllerTest extends TelephonyTest {
assertEquals("+18052345678",
mPhoneSubInfoControllerUT.getLine1NumberForSubscriber(1, TAG, FEATURE_ID));
- /* case 6: only enable READ_SMS */
+ /* case 6: only enable READ_SMS; without the appop should throw SecurityException */
doReturn(AppOpsManager.MODE_ERRORED).when(mAppOsMgr).noteOp(
eq(AppOpsManager.OPSTR_READ_PHONE_STATE), anyInt(), eq(TAG), eq(FEATURE_ID),
nullable(String.class));
mContextFixture.removeCallingOrSelfPermission(READ_PHONE_STATE);
mContextFixture.addCallingOrSelfPermission(READ_SMS);
- assertNull(mPhoneSubInfoControllerUT.getLine1NumberForSubscriber(0, TAG, FEATURE_ID));
- assertNull(mPhoneSubInfoControllerUT.getLine1NumberForSubscriber(1, TAG, FEATURE_ID));
+ try {
+ mPhoneSubInfoControllerUT.getLine1NumberForSubscriber(0, TAG, FEATURE_ID);
+ Assert.fail("expected SecurityException thrown");
+ } catch (SecurityException expected) {
+ }
+ try {
+ mPhoneSubInfoControllerUT.getLine1NumberForSubscriber(1, TAG, FEATURE_ID);
+ Assert.fail("expected SecurityException thrown");
+ } catch (SecurityException expected) {
+ }
/* case 7: enable READ_SMS and OP_READ_SMS */
doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOsMgr).noteOp(
diff --git a/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java
index 1cceb49a4d..d25e5bfe0b 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java
@@ -119,6 +119,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
doReturn(1).when(mProxyController).getMaxRafSupported();
mContextFixture.putIntArrayResource(com.android.internal.R.array.sim_colors, new int[]{5});
+
+ setupMocksForTelephonyPermissions(Build.VERSION_CODES.R);
}
@After
@@ -1386,7 +1388,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
mSubscriptionControllerUT.setDisplayNumber(DISPLAY_NUMBER, getFirstSubId());
mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL);
mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
- setupMocksForTelephonyPermissions(mCallingPackage, Build.VERSION_CODES.R);
+ setupMocksForTelephonyPermissions(Build.VERSION_CODES.R);
doReturn(AppOpsManager.MODE_DEFAULT).when(mAppOpsManager).noteOp(
eq(AppOpsManager.OPSTR_WRITE_SMS), anyInt(), anyString(),
nullable(String.class), nullable(String.class));
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java
index 9794dfc5a9..dbaa29a76d 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyPermissionsTest.java
@@ -273,6 +273,41 @@ public class TelephonyPermissionsTest {
}
@Test
+ public void testCheckReadPhoneNumber_hasReadSmsNoAppop() throws Exception {
+ // If an app has been granted the READ_SMS permission, but the OPSTR_READ_SMS appop has been
+ // revoked then instead of immediately returning false the phone number access check should
+ // check if the caller has the READ_PHONE_NUMBERS permission and appop.
+ setupMocksForDeviceIdentifiersErrorPath();
+ doNothing().when(mMockContext).enforcePermission(
+ android.Manifest.permission.READ_SMS, PID, UID, MSG);
+ doNothing().when(mMockContext).enforcePermission(
+ android.Manifest.permission.READ_PHONE_NUMBERS, PID, UID, MSG);
+ when(mMockAppOps.noteOp(eq(AppOpsManager.OPSTR_READ_PHONE_NUMBERS), eq(UID), eq(PACKAGE),
+ eq(FEATURE), nullable(String.class))).thenReturn(AppOpsManager.MODE_ALLOWED);
+ assertTrue(TelephonyPermissions.checkReadPhoneNumber(
+ mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG));
+ }
+
+ @Test
+ public void testCheckReadPhoneNumber_hasReadSmsAndReadPhoneNumbersNoAppops() throws Exception {
+ // If an app has both the READ_SMS and READ_PHONE_NUMBERS permissions granted but does not
+ // have the corresponding appops instead of returning false for not having the appop granted
+ // a SecurityException should be thrown.
+ setupMocksForDeviceIdentifiersErrorPath();
+ doNothing().when(mMockContext).enforcePermission(
+ android.Manifest.permission.READ_SMS, PID, UID, MSG);
+ doNothing().when(mMockContext).enforcePermission(
+ android.Manifest.permission.READ_PHONE_NUMBERS, PID, UID, MSG);
+ try {
+ TelephonyPermissions.checkReadPhoneNumber(
+ mMockContext, SUB_ID, PID, UID, PACKAGE, FEATURE, MSG);
+ fail("Should have thrown SecurityException");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ @Test
public void testCheckReadDeviceIdentifiers_noPermissions() throws Exception {
setupMocksForDeviceIdentifiersErrorPath();
try {
diff --git a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
index 7c0bdd9a3c..ab60b6d4dc 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
@@ -774,17 +774,23 @@ public abstract class TelephonyTest {
}
protected void setupMocksForTelephonyPermissions() throws Exception {
- setupMocksForTelephonyPermissions(TAG, Build.VERSION_CODES.Q);
+ setupMocksForTelephonyPermissions(Build.VERSION_CODES.Q);
}
- protected void setupMocksForTelephonyPermissions(String packageName, int targetSdkVersion)
+ protected void setupMocksForTelephonyPermissions(int targetSdkVersion)
throws Exception {
// If the calling package does not meet the new requirements for device identifier access
// TelephonyPermissions will query the PackageManager for the ApplicationInfo of the package
// to determine the target SDK. For apps targeting Q a SecurityException is thrown
// regardless of if the package satisfies the previous requirements for device ID access.
+
+ // Any tests that query for SubscriptionInfo objects will trigger a phone number access
+ // check that will first query the ApplicationInfo as apps targeting R+ can no longer
+ // access the phone number with the READ_PHONE_STATE permission and instead must meet one of
+ // the other requirements. This ApplicationInfo is generalized to any package name since
+ // some tests will simulate invocation from other packages.
mApplicationInfo.targetSdkVersion = targetSdkVersion;
- doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfoAsUser(eq(packageName),
+ doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfoAsUser(anyString(),
anyInt(), any());
// TelephonyPermissions uses a SystemAPI to check if the calling package meets any of the