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

Commit 60f53e67 authored by Tony Mak's avatar Tony Mak
Browse files

Do not skip broadcast if the parent user is running

What's the problem is:
1. Work profile is not running (work mode is OFF)
2. Uninstall an app
3. ACTION_PACKAGE_REMOVED is sent to work profile
4. AMS skipped the broadcast as the target user of the broadcast is
   not running, but LauncherAppsService is indeed listening to .
5. LauncherAppsService failed to notify Launcher the package change.

Proposed solution:
Not skipping broadcast if its parent user is running. Please also note that
since ag/2325045, BroadcastQueue won't deliever broadcast to
receiver running in stopped users.

Test: Turn off work, remove/ Install any app in work profile, observe
   that Launcher reloads accordingly.
Test: Install an app in work profile, turn off work mode, switch
      to secondary user, adb uninstall that app. Switch back to user 0,
       observe Launcher reloads accordingly.
Test: Reboot the device, didn't see any "Skipping broadcast of" log.

BUG: 70503418

Change-Id: I35a269b09ab83a32a13cc7bc2066c8f71ba9f960
parent 82b43303
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -19900,16 +19900,14 @@ public class ActivityManagerService extends IActivityManager.Stub
        userId = mUserController.handleIncomingUser(callingPid, callingUid, userId, true,
                ALLOW_NON_FULL, "broadcast", callerPackage);
        // Make sure that the user who is receiving this broadcast is running.
        // If not, we will just skip it. Make an exception for shutdown broadcasts
        // and upgrade steps.
        if (userId != UserHandle.USER_ALL && !mUserController.isUserRunning(userId, 0)) {
        // Make sure that the user who is receiving this broadcast or its parent is running.
        // If not, we will just skip it. Make an exception for shutdown broadcasts, upgrade steps.
        if (userId != UserHandle.USER_ALL && !mUserController.isUserOrItsParentRunning(userId)) {
            if ((callingUid != SYSTEM_UID
                    || (intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) == 0)
                    && !Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
                Slog.w(TAG, "Skipping broadcast of " + intent
                        + ": user " + userId + " is stopped");
                        + ": user " + userId + " and its parent (if any) are stopped");
                return ActivityManager.BROADCAST_FAILED_USER_STOPPED;
            }
        }
+13 −0
Original line number Diff line number Diff line
@@ -1737,6 +1737,19 @@ class UserController implements Handler.Callback {
        }
    }

    boolean isUserOrItsParentRunning(int userId) {
        synchronized (mLock) {
            if (isUserRunning(userId, 0)) {
                return true;
            }
            final int parentUserId = mUserProfileGroupIds.get(userId, UserInfo.NO_PROFILE_GROUP_ID);
            if (parentUserId == UserInfo.NO_PROFILE_GROUP_ID) {
                return false;
            }
            return isUserRunning(parentUserId, 0);
        }
    }

    boolean isCurrentProfile(int userId) {
        synchronized (mLock) {
            return ArrayUtils.contains(mCurrentProfileIds, userId);