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

Commit 0ba97960 authored by Martijn Coenen's avatar Martijn Coenen Committed by Android (Google) Code Review
Browse files

Merge "Do not send (LOCKED_)BOOT_COMPLETED to private space apps." into main

parents 5a2ce67a 7e3aab80
Loading
Loading
Loading
Loading
+42 −5
Original line number Diff line number Diff line
@@ -1680,6 +1680,11 @@ public class ActivityManagerService extends IActivityManager.Stub
    PermissionManagerServiceInternal mPermissionManagerInt;
    private TestUtilityService mTestUtilityService;
    // Packages which have received a (LOCKED_)BOOT_COMPLETED broadcast since
    // the private space profile has been started
    @GuardedBy("this")
    private final ArraySet<String> mPrivateSpaceBootCompletedPackages = new ArraySet<String>();
    /**
     * Whether to force background check on all apps (for battery saver) or not.
     */
@@ -2307,6 +2312,19 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public void onUserStopped(@NonNull TargetUser user) {
            mService.mBatteryStatsService.onCleanupUser(user.getUserIdentifier());
            if (android.os.Flags.allowPrivateProfile()
                    && android.multiuser.Flags.enablePrivateSpaceFeatures()) {
                final UserManagerInternal umInternal =
                        LocalServices.getService(UserManagerInternal.class);
                UserInfo userInfo = umInternal.getUserInfo(user.getUserIdentifier());
                if (userInfo != null && userInfo.isPrivateProfile()) {
                    synchronized (mService) {
                        mService.mPrivateSpaceBootCompletedPackages.clear();
                    }
                }
            }
        }
        public ActivityManagerService getService() {
@@ -5042,14 +5060,33 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    /**
     * Send LOCKED_BOOT_COMPLETED and BOOT_COMPLETED to the package explicitly when unstopped
     * Send LOCKED_BOOT_COMPLETED and BOOT_COMPLETED to the package explicitly when unstopped,
     * or when the package first starts in private space
     */
    private void maybeSendBootCompletedLocked(ProcessRecord app) {
        boolean sendBroadcast = false;
        if (android.os.Flags.allowPrivateProfile()
                && android.multiuser.Flags.enablePrivateSpaceFeatures()) {
            final UserManagerInternal umInternal =
                    LocalServices.getService(UserManagerInternal.class);
            UserInfo userInfo = umInternal.getUserInfo(app.userId);
            if (userInfo != null && userInfo.isPrivateProfile()) {
                // Packages in private space get deferred boot completed whenever they start the
                // first time since profile start
                if (!mPrivateSpaceBootCompletedPackages.contains(app.info.packageName)) {
                    mPrivateSpaceBootCompletedPackages.add(app.info.packageName);
                    sendBroadcast = true;
                } // else, stopped packages in private space may still hit the logic below
            }
        }
        if (!sendBroadcast) {
            if (!android.content.pm.Flags.stayStopped()) return;
            // Nothing to do if it wasn't previously stopped
            if (!app.wasForceStopped() && !app.getWindowProcessController().wasForceStopped()) {
                return;
            }
        }
        // Send LOCKED_BOOT_COMPLETED, if necessary
        if (app.getApplicationInfo().isEncryptionAware()) {
+15 −0
Original line number Diff line number Diff line
@@ -671,6 +671,14 @@ class UserController implements Handler.Callback {
    }

    private void sendLockedBootCompletedBroadcast(IIntentReceiver receiver, @UserIdInt int userId) {
        if (android.os.Flags.allowPrivateProfile()
                && android.multiuser.Flags.enablePrivateSpaceFeatures()) {
            final UserInfo userInfo = getUserInfo(userId);
            if (userInfo != null && userInfo.isPrivateProfile()) {
                Slogf.i(TAG, "Skipping LOCKED_BOOT_COMPLETED for private profile user #" + userId);
                return;
            }
        }
        final Intent intent = new Intent(Intent.ACTION_LOCKED_BOOT_COMPLETED, null);
        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
        intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT
@@ -877,6 +885,13 @@ class UserController implements Handler.Callback {

        mHandler.obtainMessage(USER_UNLOCKED_MSG, userId, 0).sendToTarget();

        if (android.os.Flags.allowPrivateProfile()
                && android.multiuser.Flags.enablePrivateSpaceFeatures()) {
            if (userInfo.isPrivateProfile()) {
                Slogf.i(TAG, "Skipping BOOT_COMPLETED for private profile user #" + userId);
                return;
            }
        }
        Slogf.i(TAG, "Posting BOOT_COMPLETED user #" + userId);
        // Do not report secondary users, runtime restarts or first boot/upgrade
        if (userId == UserHandle.USER_SYSTEM