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

Commit 7b66ed58 authored by Adam Connors's avatar Adam Connors Committed by Amith Yamasani
Browse files

Send ACTION_MANAGED_PROFILE_REMOVED broadcast.

When the managed profile is removed, this new intent
is used to inform the rest of the system.

Change-Id: I1748bed0a7ee0122f69d5c78235a79f8e205efec
parent 27ecb35b
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1092,6 +1092,9 @@ public class UserManagerService extends IUserManager.Stub {
            // on next startup, in case the runtime stops now before stopping and
            // removing the user completely.
            user.partial = true;
            // Mark it as disabled, so that it isn't returned any more when
            // profiles are queried.
            user.flags |= UserInfo.FLAG_DISABLED;
            writeUserLocked(user);
        }
        if (DBG) Slog.i(LOG_TAG, "Stopping user " + userHandle);
@@ -1120,6 +1123,7 @@ public class UserManagerService extends IUserManager.Stub {
        // wiping the user's system directory and removing from the user list
        long ident = Binder.clearCallingIdentity();
        try {
            final boolean isManaged = getUserInfo(userHandle).isManagedProfile();
            Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED);
            addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle);
            mContext.sendOrderedBroadcastAsUser(addedIntent, UserHandle.ALL,
@@ -1140,6 +1144,11 @@ public class UserManagerService extends IUserManager.Stub {
                                            removeUserStateLocked(userHandle);
                                        }
                                    }
                                    // Send broadcast to notify system that the user removed was a
                                    // managed user.
                                    if (isManaged) {
                                        sendProfileRemovedBroadcast(userHandle);
                                    }
                                }
                            }.start();
                        }
@@ -1191,6 +1200,13 @@ public class UserManagerService extends IUserManager.Stub {
        parent.delete();
    }

    private void sendProfileRemovedBroadcast(int userHandle) {
        Intent managedProfileIntent = new Intent(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        managedProfileIntent.putExtra(Intent.EXTRA_USER, new UserHandle(userHandle));
        // Note: This makes an assumption that the parent owner is user 0.
        mContext.sendBroadcastAsUser(managedProfileIntent, UserHandle.OWNER, null);
    }

    @Override
    public Bundle getApplicationRestrictions(String packageName) {
        return getApplicationRestrictionsForUser(packageName, UserHandle.getCallingUserId());