Push active dream component to WindowManager instead of pulling.

Instead of pulling the active dream component, we push the component
when a dream is started. This ensures that the active component remains
in sync with the currently active dream.

Bug: 246091760
Test: flashed device and verified dreams are working correctly
Change-Id: Ifece2dc62486b74794f0d333d19bec2ab3bc9229
This commit is contained in:
Lucas Silva
2022-10-28 16:03:38 -04:00
parent bffe18bf28
commit a057442725
5 changed files with 30 additions and 63 deletions

View File

@@ -16,7 +16,6 @@
package android.service.dreams;
import android.content.ComponentName;
/**
* Dream manager local system service interface.
@@ -59,19 +58,4 @@ public abstract class DreamManagerInternal {
* @param isScreenOn True if the screen is currently on.
*/
public abstract boolean canStartDreaming(boolean isScreenOn);
/**
* Called by the ActivityTaskManagerService to verify that the startDreamActivity
* request comes from the current active dream component.
*
* This function and its call path should not acquire the DreamManagerService lock
* to avoid deadlock with the ActivityTaskManager lock.
*
* TODO: Make this interaction push-based - the DreamManager should inform the
* ActivityTaskManager whenever the active dream component changes.
*
* @param doze If true returns the current active doze component. Otherwise, returns the
* active dream component.
*/
public abstract ComponentName getActiveDreamComponent(boolean doze);
}

View File

@@ -1327,6 +1327,12 @@
"group": "WM_DEBUG_ANIM",
"at": "com\/android\/server\/wm\/WindowState.java"
},
"-787664727": {
"message": "Cannot launch dream activity due to invalid state. dream component: %s packageName: %s",
"level": "ERROR",
"group": "WM_DEBUG_DREAM",
"at": "com\/android\/server\/wm\/ActivityTaskManagerService.java"
},
"-784959154": {
"message": "Attempted to add private presentation window to a non-private display. Aborting.",
"level": "WARN",
@@ -2857,6 +2863,12 @@
"group": "WM_DEBUG_BOOT",
"at": "com\/android\/server\/wm\/WindowManagerService.java"
},
"601283564": {
"message": "Dream packageName does not match active dream. Package %s does not match %s",
"level": "ERROR",
"group": "WM_DEBUG_DREAM",
"at": "com\/android\/server\/wm\/ActivityTaskManagerService.java"
},
"608694300": {
"message": " NEW SURFACE SESSION %s",
"level": "INFO",
@@ -3097,12 +3109,6 @@
"group": "WM_DEBUG_STARTING_WINDOW",
"at": "com\/android\/server\/wm\/WindowStateAnimator.java"
},
"829869827": {
"message": "Cannot launch dream activity due to invalid state. dreaming: %b packageName: %s",
"level": "ERROR",
"group": "WM_DEBUG_DREAM",
"at": "com\/android\/server\/wm\/ActivityTaskManagerService.java"
},
"835814848": {
"message": "%s",
"level": "INFO",
@@ -4135,12 +4141,6 @@
"group": "WM_DEBUG_WINDOW_ORGANIZER",
"at": "com\/android\/server\/wm\/TaskOrganizerController.java"
},
"1918771553": {
"message": "Dream packageName does not match active dream. Package %s does not match %s or %s",
"level": "ERROR",
"group": "WM_DEBUG_DREAM",
"at": "com\/android\/server\/wm\/ActivityTaskManagerService.java"
},
"1921821199": {
"message": "Preserving %s until the new one is added",
"level": "VERBOSE",

View File

@@ -491,10 +491,6 @@ public final class DreamManagerService extends SystemService {
}
}
private ComponentName getActiveDreamComponentInternal(boolean doze) {
return chooseDreamForUser(doze, ActivityManager.getCurrentUser());
}
/**
* If doze is true, returns the doze component for the user.
* Otherwise, returns the system dream component, if present.
@@ -647,7 +643,7 @@ public final class DreamManagerService extends SystemService {
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, DREAM_WAKE_LOCK_TAG);
final Binder dreamToken = mCurrentDream.token;
mHandler.post(wakeLock.wrap(() -> {
mAtmInternal.notifyDreamStateChanged(true);
mAtmInternal.notifyActiveDreamChanged(name);
mController.startDream(dreamToken, name, isPreviewMode, canDoze, userId, wakeLock,
mDreamOverlayServiceName, reason);
}));
@@ -672,7 +668,7 @@ public final class DreamManagerService extends SystemService {
@GuardedBy("mLock")
private void cleanupDreamLocked() {
mHandler.post(() -> mAtmInternal.notifyDreamStateChanged(false /*dreaming*/));
mHandler.post(() -> mAtmInternal.notifyActiveDreamChanged(null));
if (mCurrentDream == null) {
return;
@@ -1012,11 +1008,6 @@ public final class DreamManagerService extends SystemService {
return canStartDreamingInternal(isScreenOn);
}
@Override
public ComponentName getActiveDreamComponent(boolean doze) {
return getActiveDreamComponentInternal(doze);
}
@Override
public void requestDream() {
requestDreamInternal();

View File

@@ -287,8 +287,10 @@ public abstract class ActivityTaskManagerInternal {
/**
* Called when the device changes its dreaming state.
*
* @param activeDreamComponent The currently active dream. If null, the device is not dreaming.
*/
public abstract void notifyDreamStateChanged(boolean dreaming);
public abstract void notifyActiveDreamChanged(@Nullable ComponentName activeDreamComponent);
/**
* Set a uid that is allowed to bypass stopped app switches, launching an app

View File

@@ -208,7 +208,6 @@ import android.os.UserManager;
import android.os.WorkSource;
import android.provider.Settings;
import android.service.dreams.DreamActivity;
import android.service.dreams.DreamManagerInternal;
import android.service.voice.IVoiceInteractionSession;
import android.service.voice.VoiceInteractionManagerInternal;
import android.sysprop.DisplayProperties;
@@ -669,11 +668,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
private volatile boolean mSleeping;
/**
* The mDreaming state is set by the {@link DreamManagerService} when it receives a request to
* start/stop the dream. It is set to true shortly before the {@link DreamService} is started.
* It is set to false after the {@link DreamService} is stopped.
* The mActiveDreamComponent state is set by the {@link DreamManagerService} when it receives a
* request to start/stop the dream. It is set to the active dream shortly before the
* {@link DreamService} is started. It is set to null after the {@link DreamService} is stopped.
*/
private volatile boolean mDreaming;
@Nullable
private volatile ComponentName mActiveDreamComponent;
/**
* The process state used for processes that are running the top activities.
@@ -1442,31 +1442,21 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
boolean isDreaming() {
return mDreaming;
return mActiveDreamComponent != null;
}
boolean canLaunchDreamActivity(String packageName) {
if (!mDreaming || packageName == null) {
if (mActiveDreamComponent == null || packageName == null) {
ProtoLog.e(WM_DEBUG_DREAM, "Cannot launch dream activity due to invalid state. "
+ "dreaming: %b packageName: %s", mDreaming, packageName);
+ "dream component: %s packageName: %s", mActiveDreamComponent, packageName);
return false;
}
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 */);
if (activeDream != null && packageName.equals(activeDream.getPackageName())) {
return true;
}
final ComponentName activeDoze = dreamManager.getActiveDreamComponent(true /* doze */);
if (activeDoze != null && packageName.equals(activeDoze.getPackageName())) {
if (packageName.equals(mActiveDreamComponent.getPackageName())) {
return true;
}
ProtoLog.e(WM_DEBUG_DREAM,
"Dream packageName does not match active dream. Package %s does not match %s or %s",
packageName, String.valueOf(activeDream), String.valueOf(activeDoze));
"Dream packageName does not match active dream. Package %s does not match %s",
packageName, String.valueOf(mActiveDreamComponent));
return false;
}
@@ -5676,9 +5666,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
@Override
public void notifyDreamStateChanged(boolean dreaming) {
public void notifyActiveDreamChanged(@Nullable ComponentName dreamComponent) {
synchronized (mGlobalLock) {
mDreaming = dreaming;
mActiveDreamComponent = dreamComponent;
}
}