Loading src/java/com/android/internal/telephony/euicc/EuiccController.java +17 −26 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.annotation.Nullable; import android.app.AppOpsManager; import android.app.PendingIntent; import android.app.admin.DevicePolicyManager; import android.app.admin.flags.Flags; import android.app.compat.CompatChanges; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -622,10 +621,8 @@ public class EuiccController extends IEuiccController.Stub { Bundle resolvedBundle, PendingIntent callbackIntent) { mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); boolean callerHasAdminPrivileges = false; if (Flags.esimManagementEnabled()) { callerHasAdminPrivileges = callerCanManageDevicePolicyManagedSubscriptions( callingPackage); boolean callerHasAdminPrivileges = callerCanManageDevicePolicyManagedSubscriptions(callingPackage); if (callerHasAdminPrivileges && (switchAfterDownload && !shouldAllowSwitchAfterDownload( callingPackage))) { // Throw error if calling admin does not have privileges to enable Loading @@ -640,7 +637,6 @@ public class EuiccController extends IEuiccController.Stub { sendResult(callbackIntent, ERROR, null); return; } } // Don't try to resolve the port index for apps which are not targeting on T for backward // compatibility. instead always use default port 0. boolean shouldResolvePortIndex = isCompatChangeEnabled(callingPackage, Loading Loading @@ -1077,9 +1073,7 @@ public class EuiccController extends IEuiccController.Stub { public void deleteSubscription(int cardId, int subscriptionId, String callingPackage, PendingIntent callbackIntent) { boolean callerCanWriteEmbeddedSubscriptions = callerCanWriteEmbeddedSubscriptions(); boolean callerIsAdmin = Flags.esimManagementEnabled() && callerCanManageDevicePolicyManagedSubscriptions(callingPackage); boolean callerIsAdmin = callerCanManageDevicePolicyManagedSubscriptions(callingPackage); mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); long token = Binder.clearCallingIdentity(); Loading Loading @@ -1752,7 +1746,7 @@ public class EuiccController extends IEuiccController.Stub { private void refreshSubscriptionsOwnership(boolean isCallerAdmin, String callingPackage, int cardId, Set<Integer> subscriptionsBefore) { if (Flags.esimManagementEnabled() && isCallerAdmin) { if (isCallerAdmin) { // Mark the newly downloaded subscriptions as being owned by an admin so // that actions for that subscription can be restricted, // and the admin is limited to effecting only these subscriptions. Loading Loading @@ -1878,9 +1872,6 @@ public class EuiccController extends IEuiccController.Stub { } private Set<Integer> getCurrentEmbeddedSubscriptionIds(int cardId) { if (!Flags.esimManagementEnabled()) { return new ArraySet<>(); } List<SubscriptionInfo> subscriptionInfos = mSubscriptionManager.getAvailableSubscriptionInfoList(); int subCount = (subscriptionInfos != null) ? subscriptionInfos.size() : 0; Loading tests/telephonytests/src/com/android/internal/telephony/euicc/EuiccControllerTest.java +2 −56 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import static org.mockito.Mockito.when; import android.Manifest; import android.annotation.Nullable; import android.app.PendingIntent; import android.app.admin.flags.Flags; import android.compat.testing.PlatformCompatChangeRule; import android.content.Context; import android.content.Intent; Loading Loading @@ -89,12 +88,12 @@ import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.mockito.stubbing.Stubber; Loading Loading @@ -877,7 +876,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_noAdminPermission() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(false); setUpUiccSlotData(); Loading @@ -903,7 +901,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_adminPermission() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setHasWriteEmbeddedPermission(false); Loading @@ -918,7 +915,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_adminPermission_usingSwitchAfterDownload_fails() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading @@ -944,7 +940,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_profileOwner_usingSwitchAfterDownload_fails() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading Loading @@ -973,7 +968,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_orgOwnedProfileOwner_usingSwitchAfterDownload_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading @@ -999,7 +993,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_deviceOwner_usingSwitchAfterDownload_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading @@ -1025,7 +1018,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_onlyAdminManagedAllowed_callerNotAdmin_error() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(false); setHasWriteEmbeddedPermission(true); doReturn(true) Loading @@ -1039,29 +1031,10 @@ public class EuiccControllerTest extends TelephonyTest { assertFalse(mController.mCalledRefreshSubscriptionsAndSendResult); } @Test @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_onlyAdminManagedAllowed_callerNotAdmin_disabled_success() throws Exception { mSetFlagsRule.disableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(false); setHasWriteEmbeddedPermission(true); doReturn(true) .when(mUserManager) .hasUserRestriction(UserManager.DISALLOW_SIM_GLOBALLY); callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */, EuiccService.RESULT_OK, 0 /* resolvableError */, "whatever" /* callingPackage */); verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK, 0 /* detailedCode */); assertTrue(mController.mCalledRefreshSubscriptionsAndSendResult); } @Test @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_onlyAdminManagedAllowed_callerIsAdmin_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setHasWriteEmbeddedPermission(false); doReturn(true) Loading Loading @@ -1122,7 +1095,6 @@ public class EuiccControllerTest extends TelephonyTest { @Test public void testDeleteSubscription_adminOwned_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); String callingPackage = "whatever"; Loading @@ -1145,34 +1117,8 @@ public class EuiccControllerTest extends TelephonyTest { 0 /* detailedCode */); } @Test public void testDeleteSubscription_adminOwned_featureDisabled_success() throws Exception { mSetFlagsRule.disableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(true); setHasManageDevicePolicyManagedSubscriptionsPermission(false); String callingPackage = "whatever"; SubscriptionInfo subInfo1 = new SubscriptionInfo.Builder() .setId(SUBSCRIPTION_ID) .setEmbedded(true) .setIccId(ICC_ID) .setCardId(CARD_ID) .setPortIndex(TelephonyManager.DEFAULT_PORT_INDEX) .setGroupOwner(callingPackage) .build(); ArrayList<SubscriptionInfo> subInfos = new ArrayList<>(Arrays.asList(subInfo1)); when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(subInfos); callDeleteSubscription( SUBSCRIPTION_ID, ICC_ID, true /* complete */, 0 /* result */, callingPackage /* callingPackage */); verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK, 0 /* detailedCode */); } @Test public void testDeleteSubscription_adminOwned_noPermissions_error() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(false); String callingPackage = "whatever"; Loading Loading
src/java/com/android/internal/telephony/euicc/EuiccController.java +17 −26 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.annotation.Nullable; import android.app.AppOpsManager; import android.app.PendingIntent; import android.app.admin.DevicePolicyManager; import android.app.admin.flags.Flags; import android.app.compat.CompatChanges; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -622,10 +621,8 @@ public class EuiccController extends IEuiccController.Stub { Bundle resolvedBundle, PendingIntent callbackIntent) { mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); boolean callerHasAdminPrivileges = false; if (Flags.esimManagementEnabled()) { callerHasAdminPrivileges = callerCanManageDevicePolicyManagedSubscriptions( callingPackage); boolean callerHasAdminPrivileges = callerCanManageDevicePolicyManagedSubscriptions(callingPackage); if (callerHasAdminPrivileges && (switchAfterDownload && !shouldAllowSwitchAfterDownload( callingPackage))) { // Throw error if calling admin does not have privileges to enable Loading @@ -640,7 +637,6 @@ public class EuiccController extends IEuiccController.Stub { sendResult(callbackIntent, ERROR, null); return; } } // Don't try to resolve the port index for apps which are not targeting on T for backward // compatibility. instead always use default port 0. boolean shouldResolvePortIndex = isCompatChangeEnabled(callingPackage, Loading Loading @@ -1077,9 +1073,7 @@ public class EuiccController extends IEuiccController.Stub { public void deleteSubscription(int cardId, int subscriptionId, String callingPackage, PendingIntent callbackIntent) { boolean callerCanWriteEmbeddedSubscriptions = callerCanWriteEmbeddedSubscriptions(); boolean callerIsAdmin = Flags.esimManagementEnabled() && callerCanManageDevicePolicyManagedSubscriptions(callingPackage); boolean callerIsAdmin = callerCanManageDevicePolicyManagedSubscriptions(callingPackage); mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); long token = Binder.clearCallingIdentity(); Loading Loading @@ -1752,7 +1746,7 @@ public class EuiccController extends IEuiccController.Stub { private void refreshSubscriptionsOwnership(boolean isCallerAdmin, String callingPackage, int cardId, Set<Integer> subscriptionsBefore) { if (Flags.esimManagementEnabled() && isCallerAdmin) { if (isCallerAdmin) { // Mark the newly downloaded subscriptions as being owned by an admin so // that actions for that subscription can be restricted, // and the admin is limited to effecting only these subscriptions. Loading Loading @@ -1878,9 +1872,6 @@ public class EuiccController extends IEuiccController.Stub { } private Set<Integer> getCurrentEmbeddedSubscriptionIds(int cardId) { if (!Flags.esimManagementEnabled()) { return new ArraySet<>(); } List<SubscriptionInfo> subscriptionInfos = mSubscriptionManager.getAvailableSubscriptionInfoList(); int subCount = (subscriptionInfos != null) ? subscriptionInfos.size() : 0; Loading
tests/telephonytests/src/com/android/internal/telephony/euicc/EuiccControllerTest.java +2 −56 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import static org.mockito.Mockito.when; import android.Manifest; import android.annotation.Nullable; import android.app.PendingIntent; import android.app.admin.flags.Flags; import android.compat.testing.PlatformCompatChangeRule; import android.content.Context; import android.content.Intent; Loading Loading @@ -89,12 +88,12 @@ import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.mockito.stubbing.Stubber; Loading Loading @@ -877,7 +876,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_noAdminPermission() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(false); setUpUiccSlotData(); Loading @@ -903,7 +901,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_adminPermission() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setHasWriteEmbeddedPermission(false); Loading @@ -918,7 +915,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_adminPermission_usingSwitchAfterDownload_fails() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading @@ -944,7 +940,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_profileOwner_usingSwitchAfterDownload_fails() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading Loading @@ -973,7 +968,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_orgOwnedProfileOwner_usingSwitchAfterDownload_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading @@ -999,7 +993,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_deviceOwner_usingSwitchAfterDownload_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setUpUiccSlotData(); Loading @@ -1025,7 +1018,6 @@ public class EuiccControllerTest extends TelephonyTest { @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_onlyAdminManagedAllowed_callerNotAdmin_error() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(false); setHasWriteEmbeddedPermission(true); doReturn(true) Loading @@ -1039,29 +1031,10 @@ public class EuiccControllerTest extends TelephonyTest { assertFalse(mController.mCalledRefreshSubscriptionsAndSendResult); } @Test @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_onlyAdminManagedAllowed_callerNotAdmin_disabled_success() throws Exception { mSetFlagsRule.disableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(false); setHasWriteEmbeddedPermission(true); doReturn(true) .when(mUserManager) .hasUserRestriction(UserManager.DISALLOW_SIM_GLOBALLY); callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */, EuiccService.RESULT_OK, 0 /* resolvableError */, "whatever" /* callingPackage */); verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK, 0 /* detailedCode */); assertTrue(mController.mCalledRefreshSubscriptionsAndSendResult); } @Test @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS}) public void testDownloadSubscription_onlyAdminManagedAllowed_callerIsAdmin_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasManageDevicePolicyManagedSubscriptionsPermission(true); setHasWriteEmbeddedPermission(false); doReturn(true) Loading Loading @@ -1122,7 +1095,6 @@ public class EuiccControllerTest extends TelephonyTest { @Test public void testDeleteSubscription_adminOwned_success() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(true); String callingPackage = "whatever"; Loading @@ -1145,34 +1117,8 @@ public class EuiccControllerTest extends TelephonyTest { 0 /* detailedCode */); } @Test public void testDeleteSubscription_adminOwned_featureDisabled_success() throws Exception { mSetFlagsRule.disableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(true); setHasManageDevicePolicyManagedSubscriptionsPermission(false); String callingPackage = "whatever"; SubscriptionInfo subInfo1 = new SubscriptionInfo.Builder() .setId(SUBSCRIPTION_ID) .setEmbedded(true) .setIccId(ICC_ID) .setCardId(CARD_ID) .setPortIndex(TelephonyManager.DEFAULT_PORT_INDEX) .setGroupOwner(callingPackage) .build(); ArrayList<SubscriptionInfo> subInfos = new ArrayList<>(Arrays.asList(subInfo1)); when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(subInfos); callDeleteSubscription( SUBSCRIPTION_ID, ICC_ID, true /* complete */, 0 /* result */, callingPackage /* callingPackage */); verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK, 0 /* detailedCode */); } @Test public void testDeleteSubscription_adminOwned_noPermissions_error() throws Exception { mSetFlagsRule.enableFlags(Flags.FLAG_ESIM_MANAGEMENT_ENABLED); setHasWriteEmbeddedPermission(false); setHasManageDevicePolicyManagedSubscriptionsPermission(false); String callingPackage = "whatever"; Loading