From 1fb786caf1036f44268ce25487b4e72f01351f99 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Wed, 19 Jul 2023 23:50:06 +0000 Subject: [PATCH] Skip real action when onStartUser() called for the same user not on the first time Bug: b/291217867 Test: Verified all affected tests pass Change-Id: I8508013d654fa30b9b10fec83e728ddc5f7cfbdb --- .../java/com/android/server/om/OverlayManagerService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/core/java/com/android/server/om/OverlayManagerService.java b/services/core/java/com/android/server/om/OverlayManagerService.java index 7736e2bc64813..52eef47b3759c 100644 --- a/services/core/java/com/android/server/om/OverlayManagerService.java +++ b/services/core/java/com/android/server/om/OverlayManagerService.java @@ -261,6 +261,8 @@ public final class OverlayManagerService extends SystemService { private final OverlayActorEnforcer mActorEnforcer; + private int mPrevStartedUserId = -1; + public OverlayManagerService(@NonNull final Context context) { super(context); try { @@ -338,6 +340,10 @@ public final class OverlayManagerService extends SystemService { } private void onStartUser(@UserIdInt int newUserId) { + // Do nothing when start a user that is the same as the one started previously. + if (newUserId == mPrevStartedUserId) { + return; + } try { traceBegin(TRACE_TAG_RRO, "OMS#onStartUser " + newUserId); // ensure overlays in the settings are up-to-date, and propagate @@ -348,6 +354,7 @@ public final class OverlayManagerService extends SystemService { } finally { traceEnd(TRACE_TAG_RRO); } + mPrevStartedUserId = newUserId; } private static String[] getDefaultOverlayPackages() {