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

Commit a4bd59ab authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Skip duplicate USER_SYSTEM start in SystemServiceManager."

parents 029789ce 123aa680
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -351,12 +351,24 @@ public final class SystemServiceManager implements Dumpable {
     * Starts the given user.
     */
    public void onUserStarting(@NonNull TimingsTraceAndSlog t, @UserIdInt int userId) {
        EventLog.writeEvent(EventLogTags.SSM_USER_STARTING, userId);

        final TargetUser targetUser = newTargetUser(userId);
        synchronized (mTargetUsers) {
            // On Automotive / Headless System User Mode, the system user will be started twice:
            // - Once by some external or local service that switches the system user to
            //   the background.
            // - Once by the ActivityManagerService, when the system is marked ready.
            // These two events are not synchronized and the order of execution is
            // non-deterministic. To avoid starting the system user twice, verify whether
            // the system user has already been started by checking the mTargetUsers.
            // TODO(b/242195409): this workaround shouldn't be necessary once we move
            // the headless-user start logic to UserManager-land.
            if (userId == UserHandle.USER_SYSTEM && mTargetUsers.contains(userId)) {
                Slog.e(TAG, "Skipping starting system user twice");
                return;
            }
            mTargetUsers.put(userId, targetUser);
        }
        EventLog.writeEvent(EventLogTags.SSM_USER_STARTING, userId);
        onUser(t, USER_STARTING, /* prevUser= */ null, targetUser);
    }

+14 −9
Original line number Diff line number Diff line
@@ -8400,13 +8400,10 @@ public class ActivityManagerService extends IActivityManager.Stub
        // On Automotive / Headless System User Mode, at this point the system user has already been
        // started and unlocked, and some of the tasks we do here have already been done. So skip
        // those in that case.
        // those in that case. The duplicate system user start is guarded in SystemServiceManager.
        // TODO(b/242195409): this workaround shouldn't be necessary once we move the headless-user
        // start logic to UserManager-land
        final boolean bootingSystemUser = currentUserId == UserHandle.USER_SYSTEM;
        if (bootingSystemUser) {
        // start logic to UserManager-land.
        mUserController.onSystemUserStarting();
        }
        synchronized (this) {
            // Only start up encryption-aware persistent apps; once user is
@@ -8436,7 +8433,15 @@ public class ActivityManagerService extends IActivityManager.Stub
                t.traceEnd();
            }
            if (bootingSystemUser) {
            // Some systems - like automotive - will explicitly unlock system user then switch
            // to a secondary user. Hence, we don't want to send duplicate broadcasts for
            // the system user here.
            // TODO(b/242195409): this workaround shouldn't be necessary once we move
            // the headless-user start logic to UserManager-land.
            final boolean isBootingSystemUser = (currentUserId == UserHandle.USER_SYSTEM)
                    && !UserManager.isHeadlessSystemUserMode();
            if (isBootingSystemUser) {
                t.traceBegin("startHomeOnAllDisplays");
                mAtmInternal.startHomeOnAllDisplays(currentUserId, "systemReady");
                t.traceEnd();
@@ -8447,7 +8452,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            t.traceEnd();
            if (bootingSystemUser) {
            if (isBootingSystemUser) {
                t.traceBegin("sendUserStartBroadcast");
                final int callingUid = Binder.getCallingUid();
                final int callingPid = Binder.getCallingPid();
@@ -8488,7 +8493,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            mAtmInternal.resumeTopActivities(false /* scheduleIdle */);
            t.traceEnd();
            if (bootingSystemUser) {
            if (isBootingSystemUser) {
                t.traceBegin("sendUserSwitchBroadcasts");
                mUserController.sendUserSwitchBroadcasts(-1, currentUserId);
                t.traceEnd();