From 9fbefebbc9373d5600d28fbf1368b20950a26980 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Tue, 15 Mar 2022 09:07:46 -0400 Subject: [PATCH] Launch user switcher as SYSTEM This switching activity should always be run as the system user. Support specifying a UserHandle on activity transitions. Fixes: 219638055 Test: manual, check user switching from multiple profiles Change-Id: I4098481daeed2423ffac5023d101171e0b4cc84a --- .../systemui/plugins/ActivityStarter.java | 4 +++ .../systemui/ActivityStarterDelegate.java | 10 +++++++ .../statusbar/phone/CentralSurfaces.java | 26 +++++++++++++------ .../CentralSurfacesCommandQueueCallbacks.java | 4 +-- .../phone/MultiUserSwitchController.java | 3 ++- .../StatusBarUserSwitcherController.kt | 3 ++- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java index 6d088f090bcd6..1fec3314a13e0 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java @@ -17,6 +17,7 @@ package com.android.systemui.plugins; import android.annotation.Nullable; import android.app.PendingIntent; import android.content.Intent; +import android.os.UserHandle; import android.view.View; import com.android.systemui.animation.ActivityLaunchAnimator; @@ -70,6 +71,9 @@ public interface ActivityStarter { void startActivity(Intent intent, boolean dismissShade, @Nullable ActivityLaunchAnimator.Controller animationController, boolean showOverLockscreenWhenLocked); + void startActivity(Intent intent, boolean dismissShade, + @Nullable ActivityLaunchAnimator.Controller animationController, + boolean showOverLockscreenWhenLocked, UserHandle userHandle); void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade); void startActivity(Intent intent, boolean dismissShade, Callback callback); void postStartActivityDismissingKeyguard(Intent intent, int delay); diff --git a/packages/SystemUI/src/com/android/systemui/ActivityStarterDelegate.java b/packages/SystemUI/src/com/android/systemui/ActivityStarterDelegate.java index 5bd620e873b0c..7af6f6677f3f5 100644 --- a/packages/SystemUI/src/com/android/systemui/ActivityStarterDelegate.java +++ b/packages/SystemUI/src/com/android/systemui/ActivityStarterDelegate.java @@ -16,6 +16,7 @@ package com.android.systemui; import android.app.PendingIntent; import android.content.Intent; +import android.os.UserHandle; import android.view.View; import androidx.annotation.Nullable; @@ -99,6 +100,15 @@ public class ActivityStarterDelegate implements ActivityStarter { showOverLockscreenWhenLocked)); } + @Override + public void startActivity(Intent intent, boolean dismissShade, + @Nullable ActivityLaunchAnimator.Controller animationController, + boolean showOverLockscreenWhenLocked, UserHandle userHandle) { + mActualStarterOptionalLazy.get().ifPresent( + starter -> starter.startActivity(intent, dismissShade, animationController, + showOverLockscreenWhenLocked, userHandle)); + } + @Override public void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade) { mActualStarterOptionalLazy.get().ifPresent( 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 ec2d608b26833..6a7e8eb5446ba 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java @@ -1695,12 +1695,20 @@ public class CentralSurfaces extends CoreStartable implements public void startActivity(Intent intent, boolean dismissShade, @Nullable ActivityLaunchAnimator.Controller animationController, boolean showOverLockscreenWhenLocked) { + startActivity(intent, dismissShade, animationController, showOverLockscreenWhenLocked, + UserHandle.CURRENT); + } + + @Override + public void startActivity(Intent intent, boolean dismissShade, + @Nullable ActivityLaunchAnimator.Controller animationController, + boolean showOverLockscreenWhenLocked, UserHandle userHandle) { // Make sure that we dismiss the keyguard if it is directly dismissable or when we don't // want to show the activity above it. if (mKeyguardStateController.isUnlocked() || !showOverLockscreenWhenLocked) { startActivityDismissingKeyguard(intent, false, dismissShade, - false /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, - 0 /* flags */, animationController); + false /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, + 0 /* flags */, animationController, userHandle); return; } @@ -1755,7 +1763,7 @@ public class CentralSurfaces extends CoreStartable implements .create(mContext) .addNextIntent(intent) .startActivities(getActivityOptions(getDisplayId(), adapter), - UserHandle.CURRENT)); + userHandle)); } /** @@ -1775,7 +1783,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 */); + null /* animationController */, UserHandle.CURRENT); } public void setQsExpanded(boolean expanded) { @@ -2417,7 +2425,7 @@ public class CentralSurfaces extends CoreStartable implements boolean dismissShade, int flags) { startActivityDismissingKeyguard(intent, onlyProvisioned, dismissShade, false /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, - flags, null /* animationController */); + flags, null /* animationController */, UserHandle.CURRENT); } public void startActivityDismissingKeyguard(final Intent intent, boolean onlyProvisioned, @@ -2428,7 +2436,8 @@ public class CentralSurfaces extends CoreStartable implements void startActivityDismissingKeyguard(final Intent intent, boolean onlyProvisioned, final boolean dismissShade, final boolean disallowEnterPictureInPictureWhileLaunching, final Callback callback, int flags, - @Nullable ActivityLaunchAnimator.Controller animationController) { + @Nullable ActivityLaunchAnimator.Controller animationController, + final UserHandle userHandle) { if (onlyProvisioned && !mDeviceProvisionedController.isDeviceProvisioned()) return; final boolean willLaunchResolverActivity = @@ -2487,7 +2496,7 @@ public class CentralSurfaces extends CoreStartable implements intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, - options.toBundle(), UserHandle.CURRENT.getIdentifier()); + options.toBundle(), userHandle.getIdentifier()); } catch (RemoteException e) { Log.w(TAG, "Unable to start activity", e); } @@ -2860,7 +2869,8 @@ public class CentralSurfaces extends CoreStartable implements false /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, 0 /* flags */, - animationController), + animationController, + UserHandle.CURRENT), delay); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java index 536be1c1a866d..c4e655a45ca69 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java @@ -371,7 +371,7 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba mCentralSurfaces.startActivityDismissingKeyguard(cameraIntent, false /* onlyProvisioned */, true /* dismissShade */, true /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, 0, - null /* animationController */); + null /* animationController */, UserHandle.CURRENT); } else { if (!mCentralSurfaces.isDeviceInteractive()) { // Avoid flickering of the scrim when we instant launch the camera and the bouncer @@ -428,7 +428,7 @@ public class CentralSurfacesCommandQueueCallbacks implements CommandQueue.Callba mCentralSurfaces.startActivityDismissingKeyguard(emergencyIntent, false /* onlyProvisioned */, true /* dismissShade */, true /* disallowEnterPictureInPictureWhileLaunching */, null /* callback */, 0, - null /* animationController */); + null /* animationController */, UserHandle.CURRENT); return; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java index 324d47eed1db2..799e5feb1586d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitchController.java @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone; import static com.android.systemui.DejankUtils.whitelistIpcs; import android.content.Intent; +import android.os.UserHandle; import android.os.UserManager; import android.view.View; import android.view.ViewGroup; @@ -62,7 +63,7 @@ public class MultiUserSwitchController extends ViewController { mActivityStarter.startActivity(intent, true /* dismissShade */, ActivityLaunchAnimator.Controller.fromView(v, null), - true /* showOverlockscreenwhenlocked */); + true /* showOverlockscreenwhenlocked */, UserHandle.SYSTEM); } else { mUserSwitchDialogController.showDialog(v); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherController.kt index 909261f0eb7e6..62549a70897b2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherController.kt @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.phone.userswitcher import android.content.Intent +import android.os.UserHandle import android.view.View import com.android.systemui.animation.ActivityLaunchAnimator import com.android.systemui.flags.FeatureFlags @@ -67,7 +68,7 @@ class StatusBarUserSwitcherControllerImpl @Inject constructor( activityStarter.startActivity(intent, true /* dismissShade */, ActivityLaunchAnimator.Controller.fromView(view, null), - true /* showOverlockscreenwhenlocked */) + true /* showOverlockscreenwhenlocked */, UserHandle.SYSTEM) } else { userSwitcherDialogController.showDialog(view) }