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

Commit 8357f7bb authored by Cynthia Wasonga's avatar Cynthia Wasonga Committed by Android (Google) Code Review
Browse files

Merge "Send ACTION_PROFILE_ADDED broadcast"

parents 636c721c 5748e259
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -1387,17 +1387,22 @@ public class UserManagerService extends IUserManager.Stub {
    @Override
    public void setUserEnabled(@UserIdInt int userId) {
        checkManageUsersPermission("enable user");
        synchronized (mPackagesLock) {
        UserInfo info;
        boolean wasUserDisabled = false;
        synchronized (mPackagesLock) {
            synchronized (mUsersLock) {
                info = getUserInfoLU(userId);
            }
                if (info != null && !info.isEnabled()) {
                    wasUserDisabled = true;
                    info.flags ^= UserInfo.FLAG_DISABLED;
                    writeUserLP(getUserDataLU(info.id));
                }
            }
        }
        if (wasUserDisabled && info != null && info.isProfile()) {
            sendProfileAddedBroadcast(info.profileGroupId, info.id);
        }
    }

    @Override
    public void setUserAdmin(@UserIdInt int userId) {
@@ -4867,7 +4872,9 @@ public class UserManagerService extends IUserManager.Stub {
        MetricsLogger.count(mContext, userInfo.isGuest() ? TRON_GUEST_CREATED
                : (userInfo.isDemo() ? TRON_DEMO_CREATED : TRON_USER_CREATED), 1);

        if (!userInfo.isProfile()) {
        if (userInfo.isProfile()) {
            sendProfileAddedBroadcast(userInfo.profileGroupId, userInfo.id);
        } else {
            // If the user switch hasn't been explicitly toggled on or off by the user, turn it on.
            if (android.provider.Settings.Global.getString(mContext.getContentResolver(),
                    android.provider.Settings.Global.USER_SWITCHER_ENABLED) == null) {
@@ -5466,6 +5473,17 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    /**
     * Send {@link Intent#ACTION_PROFILE_ADDED} broadcast when a user of type
     * {@link UserInfo#isProfile()} is added. This broadcast is sent only to dynamic receivers
     * created with {@link Context#registerReceiver}.
     */
    private void sendProfileAddedBroadcast(int parentUserId, int addedUserId) {
        sendProfileBroadcast(
                new Intent(Intent.ACTION_PROFILE_ADDED),
                parentUserId, addedUserId);
    }

    /**
     * Send {@link Intent#ACTION_PROFILE_REMOVED} broadcast when a user of type
     * {@link UserInfo#isProfile()} is removed. Additionally sends
@@ -5484,12 +5502,12 @@ public class UserManagerService extends IUserManager.Stub {
        if (Objects.equals(userType, UserManager.USER_TYPE_PROFILE_MANAGED)) {
            sendManagedProfileRemovedBroadcast(parentUserId, removedUserId);
        }
        sendProfileBroadcastToRegisteredReceivers(
        sendProfileBroadcast(
                new Intent(Intent.ACTION_PROFILE_REMOVED),
                parentUserId, removedUserId);
    }

    private void sendProfileBroadcastToRegisteredReceivers(Intent intent,
    private void sendProfileBroadcast(Intent intent,
            int parentUserId, int userId) {
        final UserHandle parentHandle = UserHandle.of(parentUserId);
        intent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId));
@@ -5500,7 +5518,7 @@ public class UserManagerService extends IUserManager.Stub {

    private void sendManagedProfileRemovedBroadcast(int parentUserId, int removedUserId) {
        Intent managedProfileIntent = new Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        managedProfileIntent.putExtra(Intent.EXTRA_USER, new UserHandle(removedUserId));
        managedProfileIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(removedUserId));
        managedProfileIntent.putExtra(Intent.EXTRA_USER_HANDLE, removedUserId);
        final UserHandle parentHandle = UserHandle.of(parentUserId);
        getDevicePolicyManagerInternal().broadcastIntentToManifestReceivers(