From bdacdde5b9249e00c141be352804fea11a4841ab Mon Sep 17 00:00:00 2001 From: Galia Peycheva Date: Thu, 2 Jul 2020 13:54:26 +0200 Subject: [PATCH] Allow doze dream package to start a DreamActivity After we made the DreamService use an activity, we introduced checks that only the current active dream component can start a dream activity. This meant that if the doze dream is in a different package, it would get suspended. This CL fixes that by whitelisting also the doze dream package. Bug: 160109097 Test: m && flash && put two different dream as doze and active dream && check that the doze starts Test: atest DreamManagerServiceTests Change-Id: I553dd1d44f3303d18278482b4a4e88a5564a94d3 --- .../com/android/server/wm/ActivityRecord.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 2e9f704484886..241f5e88935a5 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -268,6 +268,7 @@ import android.os.storage.StorageManager; import android.service.dreams.DreamActivity; import android.service.dreams.DreamManagerInternal; import android.service.voice.IVoiceInteractionSession; +import android.text.TextUtils; import android.util.ArraySet; import android.util.EventLog; import android.util.Log; @@ -2054,23 +2055,28 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } static boolean canLaunchDreamActivity(String packageName) { - final DreamManagerInternal dreamManager = - LocalServices.getService(DreamManagerInternal.class); - - // Verify that the package is the current active dream. The getActiveDreamComponent() - // call path does not acquire the DreamManager lock and thus is safe to use. - final ComponentName activeDream = dreamManager.getActiveDreamComponent(false /* doze */); - if (activeDream == null || activeDream.getPackageName() == null - || !activeDream.getPackageName().equals(packageName)) { + if (packageName == null) { return false; } - // Verify that the device is dreaming. if (!LocalServices.getService(ActivityTaskManagerInternal.class).isDreaming()) { return false; } - return true; + final DreamManagerInternal dreamManager = + LocalServices.getService(DreamManagerInternal.class); + + // Verify that the package is the current active dream or doze component. The + // getActiveDreamComponent() call path does not acquire the DreamManager lock and thus + // is safe to use. + final ComponentName activeDream = dreamManager.getActiveDreamComponent(false /* doze */); + final ComponentName activeDoze = dreamManager.getActiveDreamComponent(true /* doze */); + return TextUtils.equals(packageName, getPackageName(activeDream)) + || TextUtils.equals(packageName, getPackageName(activeDoze)); + } + + private static String getPackageName(ComponentName componentName) { + return componentName != null ? componentName.getPackageName() : null; } private void setActivityType(boolean componentSpecified, int launchedFromUid, Intent intent,