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

Commit 609093a8 authored by Ayush Sharma's avatar Ayush Sharma Committed by Android (Google) Code Review
Browse files

Merge "Transfer subscription ownership on DPC transfer" into main

parents 248a426a 9195fc28
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -3935,7 +3935,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);
@@ -19471,6 +19471,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.
      *