Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9195fc28 authored by Ayush Sharma's avatar Ayush Sharma
Browse files

Transfer subscription ownership on DPC transfer

Manual test
Case1:
1. Set testdpc in org owned profile owner mode
2. Trigger download eSIM from testdpc
3. Ensure that eSIM got downloaded sucessfully
4. Ensure that groupOwner for eSIM in subscription database is testdpc
   package
5. Initiate transfer ownserhip flow from testdpc
6. Ensure that groupOwner for eSIM in subscription database updated with
   new dpc.

Bug: 295301164
Test: atest SubscriptionManagerServiceTest
Change-Id: I92ac3cf6c7be4a9b29fe0292e423c60c1b0757f2
parent 5d0f8f35
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -3957,7 +3957,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        if (policy.mPasswordOwner == oldAdminUid) {
            policy.mPasswordOwner = adminToTransfer.getUid();
        }
        transferSubscriptionOwnership(outgoingReceiver, incomingReceiver);
        saveSettingsLocked(userHandle);
        sendAdminCommandLocked(adminToTransfer, DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED,
                null, null);
@@ -19501,6 +19501,21 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                .write();
    }
    private void transferSubscriptionOwnership(ComponentName admin, ComponentName target) {
        if (Flags.esimManagementEnabled()) {
            SubscriptionManager subscriptionManager = mContext.getSystemService(
                    SubscriptionManager.class);
            for (int subId : getSubscriptionIdsInternal(admin.getPackageName()).toArray()) {
                try {
                    subscriptionManager.setGroupOwner(subId, target.getPackageName());
                } catch (Exception e) {
                    // Shouldn't happen.
                    Slogf.e(LOG_TAG, e, "Error setting group owner for subId: " + subId);
                }
            }
        }
    }
    private void prepareTransfer(ComponentName admin, ComponentName target,
            PersistableBundle bundle, int callingUserId, String adminType) {
        saveTransferOwnershipBundleLocked(bundle, callingUserId);
+25 −0
Original line number Diff line number Diff line
@@ -4613,6 +4613,31 @@ public class SubscriptionManager {
        }
    }

    /**
     * Set owner for this subscription.
     *
     * @param subscriptionId the subId of the subscription.
     * @param groupOwner The group owner to assign to the subscription
     *
     * @throws SecurityException if caller is not authorized.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    public void setGroupOwner(int subscriptionId, @NonNull String groupOwner) {
        try {
            ISub iSub = TelephonyManager.getSubscriptionService();
            if (iSub != null) {
                iSub.setGroupOwner(subscriptionId, groupOwner);
            } else {
                throw new IllegalStateException("[setGroupOwner]: "
                        + "subscription service unavailable");
            }
        } catch (RemoteException ex) {
            ex.rethrowAsRuntimeException();
        }
    }

    /**
     * Set userHandle for a subscription.
     *
+12 −0
Original line number Diff line number Diff line
@@ -309,6 +309,18 @@ interface ISub {
     */
    int setUsageSetting(int usageSetting, int subId, String callingPackage);

    /**
      * Set owner for this subscription.
      *
      * @param subId the unique SubscriptionInfo index in database
      * @param groupOwner The group owner to assign to the subscription
      *
      * @throws SecurityException if caller is not authorized.
      *
      * @hide
      */
     void setGroupOwner(int subId, String groupOwner);

     /**
      * Set userHandle for this subscription.
      *