From 7e3f139b7267bf5054660156dbe93aecfe2d8705 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 5 Apr 2022 18:23:31 +0000 Subject: [PATCH] [Multiple Users] Start activity as system user. Ensure that activity is started as system user when launched within the systemui process. Bug: b/228193032 Test: Manual on device Change-Id: I803d8961f2c11d98f08858506e9ff510c0427e94 --- .../statusbar/phone/CentralSurfaces.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java index 1625d9b7f486c..829ae9a0bb1f1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java @@ -1708,7 +1708,7 @@ public class CentralSurfaces extends CoreStartable implements @Nullable ActivityLaunchAnimator.Controller animationController, boolean showOverLockscreenWhenLocked) { startActivity(intent, dismissShade, animationController, showOverLockscreenWhenLocked, - UserHandle.CURRENT); + getActivityUserHandle(intent)); } @Override @@ -1795,7 +1795,7 @@ public class CentralSurfaces extends CoreStartable implements public void startActivity(Intent intent, boolean dismissShade, Callback callback) { startActivityDismissingKeyguard(intent, false, dismissShade, false /* disallowEnterPictureInPictureWhileLaunching */, callback, 0, - null /* animationController */, UserHandle.CURRENT); + null /* animationController */, getActivityUserHandle(intent)); } public void setQsExpanded(boolean expanded) { @@ -2425,7 +2425,7 @@ public class CentralSurfaces extends CoreStartable implements boolean dismissShade, int flags) { startActivityDismissingKeyguard(intent, onlyProvisioned, dismissShade, false /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, - flags, null /* animationController */, UserHandle.CURRENT); + flags, null /* animationController */, getActivityUserHandle(intent)); } public void startActivityDismissingKeyguard(final Intent intent, boolean onlyProvisioned, @@ -2868,7 +2868,7 @@ public class CentralSurfaces extends CoreStartable implements null /* callback */, 0 /* flags */, animationController, - UserHandle.CURRENT), + getActivityUserHandle(intent)), delay); } @@ -3602,7 +3602,8 @@ public class CentralSurfaces extends CoreStartable implements mLaunchEmergencyActionWhenFinishedWaking = false; Intent emergencyIntent = getEmergencyActionIntent(); if (emergencyIntent != null) { - mContext.startActivityAsUser(emergencyIntent, UserHandle.CURRENT); + mContext.startActivityAsUser(emergencyIntent, + getActivityUserHandle(emergencyIntent)); } } updateScrimController(); @@ -4500,4 +4501,20 @@ public class CentralSurfaces extends CoreStartable implements @Override public void dispatchDemoCommand(String command, Bundle args) { } }; + + /** + * Determines what UserHandle to use when launching an activity. + * + * We want to ensure that activities that are launched within the systemui process should be + * launched as user of the current process. + * @param intent + * @return UserHandle + */ + private UserHandle getActivityUserHandle(Intent intent) { + if (intent.getComponent() != null + && mContext.getPackageName().equals(intent.getComponent().getPackageName())) { + return new UserHandle(UserHandle.myUserId()); + } + return UserHandle.CURRENT; + } }