Merge changes Icea03eb6,Idad15d8e into tm-qpr-dev
* changes: Add more specific start/stop dream reasons. Dream manager improvements.
This commit is contained in:
@@ -29,16 +29,18 @@ public abstract class DreamManagerInternal {
|
|||||||
*
|
*
|
||||||
* @param doze If true, starts the doze dream component if one has been configured,
|
* @param doze If true, starts the doze dream component if one has been configured,
|
||||||
* otherwise starts the user-specified dream.
|
* otherwise starts the user-specified dream.
|
||||||
|
* @param reason The reason to start dreaming, which is logged to help debugging.
|
||||||
*/
|
*/
|
||||||
public abstract void startDream(boolean doze);
|
public abstract void startDream(boolean doze, String reason);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the power manager to stop a dream.
|
* Called by the power manager to stop a dream.
|
||||||
*
|
*
|
||||||
* @param immediate If true, ends the dream summarily, otherwise gives it some time
|
* @param immediate If true, ends the dream summarily, otherwise gives it some time
|
||||||
* to perform a proper exit transition.
|
* to perform a proper exit transition.
|
||||||
|
* @param reason The reason to stop dreaming, which is logged to help debugging.
|
||||||
*/
|
*/
|
||||||
public abstract void stopDream(boolean immediate);
|
public abstract void stopDream(boolean immediate, String reason);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the power manager to determine whether a dream is running.
|
* Called by the power manager to determine whether a dream is running.
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ final class DreamController {
|
|||||||
|
|
||||||
public void startDream(Binder token, ComponentName name,
|
public void startDream(Binder token, ComponentName name,
|
||||||
boolean isPreviewMode, boolean canDoze, int userId, PowerManager.WakeLock wakeLock,
|
boolean isPreviewMode, boolean canDoze, int userId, PowerManager.WakeLock wakeLock,
|
||||||
ComponentName overlayComponentName) {
|
ComponentName overlayComponentName, String reason) {
|
||||||
stopDream(true /*immediate*/, "starting new dream");
|
stopDream(true /*immediate*/, "starting new dream");
|
||||||
|
|
||||||
Trace.traceBegin(Trace.TRACE_TAG_POWER, "startDream");
|
Trace.traceBegin(Trace.TRACE_TAG_POWER, "startDream");
|
||||||
@@ -128,7 +128,7 @@ final class DreamController {
|
|||||||
|
|
||||||
Slog.i(TAG, "Starting dream: name=" + name
|
Slog.i(TAG, "Starting dream: name=" + name
|
||||||
+ ", isPreviewMode=" + isPreviewMode + ", canDoze=" + canDoze
|
+ ", isPreviewMode=" + isPreviewMode + ", canDoze=" + canDoze
|
||||||
+ ", userId=" + userId);
|
+ ", userId=" + userId + ", reason='" + reason + "'");
|
||||||
|
|
||||||
mCurrentDream = new DreamRecord(token, name, isPreviewMode, canDoze, userId, wakeLock);
|
mCurrentDream = new DreamRecord(token, name, isPreviewMode, canDoze, userId, wakeLock);
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ import android.util.Slog;
|
|||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.logging.UiEventLogger;
|
import com.android.internal.logging.UiEventLogger;
|
||||||
import com.android.internal.logging.UiEventLoggerImpl;
|
import com.android.internal.logging.UiEventLoggerImpl;
|
||||||
import com.android.internal.util.DumpUtils;
|
import com.android.internal.util.DumpUtils;
|
||||||
@@ -84,6 +85,9 @@ public final class DreamManagerService extends SystemService {
|
|||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
private static final String TAG = "DreamManagerService";
|
private static final String TAG = "DreamManagerService";
|
||||||
|
|
||||||
|
private static final String DOZE_WAKE_LOCK_TAG = "dream:doze";
|
||||||
|
private static final String DREAM_WAKE_LOCK_TAG = "dream:dream";
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -98,17 +102,11 @@ public final class DreamManagerService extends SystemService {
|
|||||||
private final ComponentName mAmbientDisplayComponent;
|
private final ComponentName mAmbientDisplayComponent;
|
||||||
private final boolean mDismissDreamOnActivityStart;
|
private final boolean mDismissDreamOnActivityStart;
|
||||||
|
|
||||||
private Binder mCurrentDreamToken;
|
@GuardedBy("mLock")
|
||||||
private ComponentName mCurrentDreamName;
|
private DreamRecord mCurrentDream;
|
||||||
private int mCurrentDreamUserId;
|
|
||||||
private boolean mCurrentDreamIsPreview;
|
|
||||||
private boolean mCurrentDreamCanDoze;
|
|
||||||
private boolean mCurrentDreamIsDozing;
|
|
||||||
private boolean mCurrentDreamIsWaking;
|
|
||||||
private boolean mForceAmbientDisplayEnabled;
|
private boolean mForceAmbientDisplayEnabled;
|
||||||
private boolean mDreamsOnlyEnabledForSystemUser;
|
private final boolean mDreamsOnlyEnabledForSystemUser;
|
||||||
private int mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN;
|
|
||||||
private int mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
|
|
||||||
|
|
||||||
// A temporary dream component that, when present, takes precedence over user configured dream
|
// A temporary dream component that, when present, takes precedence over user configured dream
|
||||||
// component.
|
// component.
|
||||||
@@ -116,7 +114,7 @@ public final class DreamManagerService extends SystemService {
|
|||||||
|
|
||||||
private ComponentName mDreamOverlayServiceName;
|
private ComponentName mDreamOverlayServiceName;
|
||||||
|
|
||||||
private AmbientDisplayConfiguration mDozeConfig;
|
private final AmbientDisplayConfiguration mDozeConfig;
|
||||||
private final ActivityInterceptorCallback mActivityInterceptorCallback =
|
private final ActivityInterceptorCallback mActivityInterceptorCallback =
|
||||||
new ActivityInterceptorCallback() {
|
new ActivityInterceptorCallback() {
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -132,8 +130,14 @@ public final class DreamManagerService extends SystemService {
|
|||||||
final boolean activityAllowed = activityType == ACTIVITY_TYPE_HOME
|
final boolean activityAllowed = activityType == ACTIVITY_TYPE_HOME
|
||||||
|| activityType == ACTIVITY_TYPE_DREAM
|
|| activityType == ACTIVITY_TYPE_DREAM
|
||||||
|| activityType == ACTIVITY_TYPE_ASSISTANT;
|
|| activityType == ACTIVITY_TYPE_ASSISTANT;
|
||||||
if (mCurrentDreamToken != null && !mCurrentDreamIsWaking
|
|
||||||
&& !mCurrentDreamIsDozing && !activityAllowed) {
|
boolean shouldRequestAwaken;
|
||||||
|
synchronized (mLock) {
|
||||||
|
shouldRequestAwaken = mCurrentDream != null && !mCurrentDream.isWaking
|
||||||
|
&& !mCurrentDream.isDozing && !activityAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldRequestAwaken) {
|
||||||
requestAwakenInternal(
|
requestAwakenInternal(
|
||||||
"stopping dream due to activity start: " + activityInfo.name);
|
"stopping dream due to activity start: " + activityInfo.name);
|
||||||
}
|
}
|
||||||
@@ -149,7 +153,7 @@ public final class DreamManagerService extends SystemService {
|
|||||||
mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
||||||
mPowerManagerInternal = getLocalService(PowerManagerInternal.class);
|
mPowerManagerInternal = getLocalService(PowerManagerInternal.class);
|
||||||
mAtmInternal = getLocalService(ActivityTaskManagerInternal.class);
|
mAtmInternal = getLocalService(ActivityTaskManagerInternal.class);
|
||||||
mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, TAG);
|
mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, DOZE_WAKE_LOCK_TAG);
|
||||||
mDozeConfig = new AmbientDisplayConfiguration(mContext);
|
mDozeConfig = new AmbientDisplayConfiguration(mContext);
|
||||||
mUiEventLogger = new UiEventLoggerImpl();
|
mUiEventLogger = new UiEventLoggerImpl();
|
||||||
mDreamUiEventLogger = new DreamUiEventLoggerImpl(
|
mDreamUiEventLogger = new DreamUiEventLoggerImpl(
|
||||||
@@ -197,43 +201,38 @@ public final class DreamManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dumpInternal(PrintWriter pw) {
|
private void dumpInternal(PrintWriter pw) {
|
||||||
pw.println("DREAM MANAGER (dumpsys dreams)");
|
synchronized (mLock) {
|
||||||
pw.println();
|
pw.println("DREAM MANAGER (dumpsys dreams)");
|
||||||
pw.println("mCurrentDreamToken=" + mCurrentDreamToken);
|
pw.println();
|
||||||
pw.println("mCurrentDreamName=" + mCurrentDreamName);
|
pw.println("mCurrentDream=" + mCurrentDream);
|
||||||
pw.println("mCurrentDreamUserId=" + mCurrentDreamUserId);
|
pw.println("mForceAmbientDisplayEnabled=" + mForceAmbientDisplayEnabled);
|
||||||
pw.println("mCurrentDreamIsPreview=" + mCurrentDreamIsPreview);
|
pw.println("mDreamsOnlyEnabledForSystemUser=" + mDreamsOnlyEnabledForSystemUser);
|
||||||
pw.println("mCurrentDreamCanDoze=" + mCurrentDreamCanDoze);
|
pw.println("getDozeComponent()=" + getDozeComponent());
|
||||||
pw.println("mCurrentDreamIsDozing=" + mCurrentDreamIsDozing);
|
pw.println();
|
||||||
pw.println("mCurrentDreamIsWaking=" + mCurrentDreamIsWaking);
|
|
||||||
pw.println("mForceAmbientDisplayEnabled=" + mForceAmbientDisplayEnabled);
|
|
||||||
pw.println("mDreamsOnlyEnabledForSystemUser=" + mDreamsOnlyEnabledForSystemUser);
|
|
||||||
pw.println("mCurrentDreamDozeScreenState="
|
|
||||||
+ Display.stateToString(mCurrentDreamDozeScreenState));
|
|
||||||
pw.println("mCurrentDreamDozeScreenBrightness=" + mCurrentDreamDozeScreenBrightness);
|
|
||||||
pw.println("getDozeComponent()=" + getDozeComponent());
|
|
||||||
pw.println();
|
|
||||||
|
|
||||||
DumpUtils.dumpAsync(mHandler, new DumpUtils.Dump() {
|
DumpUtils.dumpAsync(mHandler, (pw1, prefix) -> mController.dump(pw1), pw, "", 200);
|
||||||
@Override
|
}
|
||||||
public void dump(PrintWriter pw, String prefix) {
|
|
||||||
mController.dump(pw);
|
|
||||||
}
|
|
||||||
}, pw, "", 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether a real dream is occurring. */
|
/** Whether a real dream is occurring. */
|
||||||
private boolean isDreamingInternal() {
|
private boolean isDreamingInternal() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return mCurrentDreamToken != null && !mCurrentDreamIsPreview
|
return mCurrentDream != null && !mCurrentDream.isPreview
|
||||||
&& !mCurrentDreamIsWaking;
|
&& !mCurrentDream.isWaking;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether a doze is occurring. */
|
||||||
|
private boolean isDozingInternal() {
|
||||||
|
synchronized (mLock) {
|
||||||
|
return mCurrentDream != null && mCurrentDream.isDozing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether a real dream, or a dream preview is occurring. */
|
/** Whether a real dream, or a dream preview is occurring. */
|
||||||
private boolean isDreamingOrInPreviewInternal() {
|
private boolean isDreamingOrInPreviewInternal() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return mCurrentDreamToken != null && !mCurrentDreamIsWaking;
|
return mCurrentDream != null && !mCurrentDream.isWaking;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +272,7 @@ public final class DreamManagerService extends SystemService {
|
|||||||
// locks are held and the user activity timeout has expired then the
|
// locks are held and the user activity timeout has expired then the
|
||||||
// device may simply go to sleep.
|
// device may simply go to sleep.
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mCurrentDreamToken == token) {
|
if (mCurrentDream != null && mCurrentDream.token == token) {
|
||||||
stopDreamLocked(immediate, "finished self");
|
stopDreamLocked(immediate, "finished self");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,16 +280,17 @@ public final class DreamManagerService extends SystemService {
|
|||||||
|
|
||||||
private void testDreamInternal(ComponentName dream, int userId) {
|
private void testDreamInternal(ComponentName dream, int userId) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
startDreamLocked(dream, true /*isPreviewMode*/, false /*canDoze*/, userId);
|
startDreamLocked(dream, true /*isPreviewMode*/, false /*canDoze*/, userId,
|
||||||
|
"test dream" /*reason*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDreamInternal(boolean doze) {
|
private void startDreamInternal(boolean doze, String reason) {
|
||||||
final int userId = ActivityManager.getCurrentUser();
|
final int userId = ActivityManager.getCurrentUser();
|
||||||
final ComponentName dream = chooseDreamForUser(doze, userId);
|
final ComponentName dream = chooseDreamForUser(doze, userId);
|
||||||
if (dream != null) {
|
if (dream != null) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
startDreamLocked(dream, false /*isPreviewMode*/, doze, userId);
|
startDreamLocked(dream, false /*isPreviewMode*/, doze, userId, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,13 +314,13 @@ public final class DreamManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mCurrentDreamToken == token && mCurrentDreamCanDoze) {
|
if (mCurrentDream != null && mCurrentDream.token == token && mCurrentDream.canDoze) {
|
||||||
mCurrentDreamDozeScreenState = screenState;
|
mCurrentDream.dozeScreenState = screenState;
|
||||||
mCurrentDreamDozeScreenBrightness = screenBrightness;
|
mCurrentDream.dozeScreenBrightness = screenBrightness;
|
||||||
mPowerManagerInternal.setDozeOverrideFromDreamManager(
|
mPowerManagerInternal.setDozeOverrideFromDreamManager(
|
||||||
screenState, screenBrightness);
|
screenState, screenBrightness);
|
||||||
if (!mCurrentDreamIsDozing) {
|
if (!mCurrentDream.isDozing) {
|
||||||
mCurrentDreamIsDozing = true;
|
mCurrentDream.isDozing = true;
|
||||||
mDozeWakeLock.acquire();
|
mDozeWakeLock.acquire();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,8 +333,8 @@ public final class DreamManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mCurrentDreamToken == token && mCurrentDreamIsDozing) {
|
if (mCurrentDream != null && mCurrentDream.token == token && mCurrentDream.isDozing) {
|
||||||
mCurrentDreamIsDozing = false;
|
mCurrentDream.isDozing = false;
|
||||||
mDozeWakeLock.release();
|
mDozeWakeLock.release();
|
||||||
mPowerManagerInternal.setDozeOverrideFromDreamManager(
|
mPowerManagerInternal.setDozeOverrideFromDreamManager(
|
||||||
Display.STATE_UNKNOWN, PowerManager.BRIGHTNESS_DEFAULT);
|
Display.STATE_UNKNOWN, PowerManager.BRIGHTNESS_DEFAULT);
|
||||||
@@ -403,7 +403,7 @@ public final class DreamManagerService extends SystemService {
|
|||||||
ComponentName[] components = componentsFromString(names);
|
ComponentName[] components = componentsFromString(names);
|
||||||
|
|
||||||
// first, ensure components point to valid services
|
// first, ensure components point to valid services
|
||||||
List<ComponentName> validComponents = new ArrayList<ComponentName>();
|
List<ComponentName> validComponents = new ArrayList<>();
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
for (ComponentName component : components) {
|
for (ComponentName component : components) {
|
||||||
if (validateDream(component)) {
|
if (validateDream(component)) {
|
||||||
@@ -439,8 +439,9 @@ public final class DreamManagerService extends SystemService {
|
|||||||
mSystemDreamComponent = componentName;
|
mSystemDreamComponent = componentName;
|
||||||
|
|
||||||
// Switch dream if currently dreaming and not dozing.
|
// Switch dream if currently dreaming and not dozing.
|
||||||
if (isDreamingInternal() && !mCurrentDreamIsDozing) {
|
if (isDreamingInternal() && !isDozingInternal()) {
|
||||||
startDreamInternal(false);
|
startDreamInternal(false /*doze*/, (mSystemDreamComponent == null ? "clear" : "set")
|
||||||
|
+ " system dream component" /*reason*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,13 +479,16 @@ public final class DreamManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
private void startDreamLocked(final ComponentName name,
|
private void startDreamLocked(final ComponentName name,
|
||||||
final boolean isPreviewMode, final boolean canDoze, final int userId) {
|
final boolean isPreviewMode, final boolean canDoze, final int userId,
|
||||||
if (!mCurrentDreamIsWaking
|
final String reason) {
|
||||||
&& Objects.equals(mCurrentDreamName, name)
|
if (mCurrentDream != null
|
||||||
&& mCurrentDreamIsPreview == isPreviewMode
|
&& !mCurrentDream.isWaking
|
||||||
&& mCurrentDreamCanDoze == canDoze
|
&& Objects.equals(mCurrentDream.name, name)
|
||||||
&& mCurrentDreamUserId == userId) {
|
&& mCurrentDream.isPreview == isPreviewMode
|
||||||
|
&& mCurrentDream.canDoze == canDoze
|
||||||
|
&& mCurrentDream.userId == userId) {
|
||||||
Slog.i(TAG, "Already in target dream.");
|
Slog.i(TAG, "Already in target dream.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -493,73 +497,60 @@ public final class DreamManagerService extends SystemService {
|
|||||||
|
|
||||||
Slog.i(TAG, "Entering dreamland.");
|
Slog.i(TAG, "Entering dreamland.");
|
||||||
|
|
||||||
final Binder newToken = new Binder();
|
mCurrentDream = new DreamRecord(name, userId, isPreviewMode, canDoze);
|
||||||
mCurrentDreamToken = newToken;
|
|
||||||
mCurrentDreamName = name;
|
|
||||||
mCurrentDreamIsPreview = isPreviewMode;
|
|
||||||
mCurrentDreamCanDoze = canDoze;
|
|
||||||
mCurrentDreamUserId = userId;
|
|
||||||
|
|
||||||
if (!mCurrentDreamName.equals(mAmbientDisplayComponent)) {
|
if (!mCurrentDream.name.equals(mAmbientDisplayComponent)) {
|
||||||
// TODO(b/213906448): Remove when metrics based on new atom are fully rolled out.
|
// TODO(b/213906448): Remove when metrics based on new atom are fully rolled out.
|
||||||
mUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_START);
|
mUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_START);
|
||||||
mDreamUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_START,
|
mDreamUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_START,
|
||||||
mCurrentDreamName.flattenToString());
|
mCurrentDream.name.flattenToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerManager.WakeLock wakeLock = mPowerManager
|
PowerManager.WakeLock wakeLock = mPowerManager
|
||||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "startDream");
|
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, DREAM_WAKE_LOCK_TAG);
|
||||||
|
final Binder dreamToken = mCurrentDream.token;
|
||||||
mHandler.post(wakeLock.wrap(() -> {
|
mHandler.post(wakeLock.wrap(() -> {
|
||||||
mAtmInternal.notifyDreamStateChanged(true);
|
mAtmInternal.notifyDreamStateChanged(true);
|
||||||
mController.startDream(newToken, name, isPreviewMode, canDoze, userId, wakeLock,
|
mController.startDream(dreamToken, name, isPreviewMode, canDoze, userId, wakeLock,
|
||||||
mDreamOverlayServiceName);
|
mDreamOverlayServiceName, reason);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
private void stopDreamLocked(final boolean immediate, String reason) {
|
private void stopDreamLocked(final boolean immediate, String reason) {
|
||||||
if (mCurrentDreamToken != null) {
|
if (mCurrentDream != null) {
|
||||||
if (immediate) {
|
if (immediate) {
|
||||||
Slog.i(TAG, "Leaving dreamland.");
|
Slog.i(TAG, "Leaving dreamland.");
|
||||||
cleanupDreamLocked();
|
cleanupDreamLocked();
|
||||||
} else if (mCurrentDreamIsWaking) {
|
} else if (mCurrentDream.isWaking) {
|
||||||
return; // already waking
|
return; // already waking
|
||||||
} else {
|
} else {
|
||||||
Slog.i(TAG, "Gently waking up from dream.");
|
Slog.i(TAG, "Gently waking up from dream.");
|
||||||
mCurrentDreamIsWaking = true;
|
mCurrentDream.isWaking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(() -> mController.stopDream(immediate, reason));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Slog.i(TAG, "Performing gentle wake from dream.");
|
|
||||||
mController.stopDream(immediate, reason);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
private void cleanupDreamLocked() {
|
private void cleanupDreamLocked() {
|
||||||
if (!mCurrentDreamName.equals(mAmbientDisplayComponent)) {
|
mHandler.post(() -> mAtmInternal.notifyDreamStateChanged(false /*dreaming*/));
|
||||||
|
|
||||||
|
if (mCurrentDream == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mCurrentDream.name.equals(mAmbientDisplayComponent)) {
|
||||||
// TODO(b/213906448): Remove when metrics based on new atom are fully rolled out.
|
// TODO(b/213906448): Remove when metrics based on new atom are fully rolled out.
|
||||||
mUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_STOP);
|
mUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_STOP);
|
||||||
mDreamUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_STOP,
|
mDreamUiEventLogger.log(DreamUiEventLogger.DreamUiEventEnum.DREAM_STOP,
|
||||||
mCurrentDreamName.flattenToString());
|
mCurrentDream.name.flattenToString());
|
||||||
}
|
}
|
||||||
mCurrentDreamToken = null;
|
if (mCurrentDream.isDozing) {
|
||||||
mCurrentDreamName = null;
|
|
||||||
mCurrentDreamIsPreview = false;
|
|
||||||
mCurrentDreamCanDoze = false;
|
|
||||||
mCurrentDreamUserId = 0;
|
|
||||||
mCurrentDreamIsWaking = false;
|
|
||||||
if (mCurrentDreamIsDozing) {
|
|
||||||
mCurrentDreamIsDozing = false;
|
|
||||||
mDozeWakeLock.release();
|
mDozeWakeLock.release();
|
||||||
}
|
}
|
||||||
mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN;
|
mCurrentDream = null;
|
||||||
mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
|
|
||||||
mHandler.post(() -> {
|
|
||||||
mAtmInternal.notifyDreamStateChanged(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPermission(String permission) {
|
private void checkPermission(String permission) {
|
||||||
@@ -606,7 +597,7 @@ public final class DreamManagerService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public void onDreamStopped(Binder token) {
|
public void onDreamStopped(Binder token) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mCurrentDreamToken == token) {
|
if (mCurrentDream != null && mCurrentDream.token == token) {
|
||||||
cleanupDreamLocked();
|
cleanupDreamLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -624,7 +615,7 @@ public final class DreamManagerService extends SystemService {
|
|||||||
* Handler for asynchronous operations performed by the dream manager.
|
* Handler for asynchronous operations performed by the dream manager.
|
||||||
* Ensures operations to {@link DreamController} are single-threaded.
|
* Ensures operations to {@link DreamController} are single-threaded.
|
||||||
*/
|
*/
|
||||||
private final class DreamHandler extends Handler {
|
private static final class DreamHandler extends Handler {
|
||||||
public DreamHandler(Looper looper) {
|
public DreamHandler(Looper looper) {
|
||||||
super(looper, null, true /*async*/);
|
super(looper, null, true /*async*/);
|
||||||
}
|
}
|
||||||
@@ -865,13 +856,13 @@ public final class DreamManagerService extends SystemService {
|
|||||||
|
|
||||||
private final class LocalService extends DreamManagerInternal {
|
private final class LocalService extends DreamManagerInternal {
|
||||||
@Override
|
@Override
|
||||||
public void startDream(boolean doze) {
|
public void startDream(boolean doze, String reason) {
|
||||||
startDreamInternal(doze);
|
startDreamInternal(doze, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopDream(boolean immediate) {
|
public void stopDream(boolean immediate, String reason) {
|
||||||
stopDreamInternal(immediate, "requested stopDream");
|
stopDreamInternal(immediate, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -890,13 +881,47 @@ public final class DreamManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class DreamRecord {
|
||||||
|
public final Binder token = new Binder();
|
||||||
|
public final ComponentName name;
|
||||||
|
public final int userId;
|
||||||
|
public final boolean isPreview;
|
||||||
|
public final boolean canDoze;
|
||||||
|
public boolean isDozing = false;
|
||||||
|
public boolean isWaking = false;
|
||||||
|
public int dozeScreenState = Display.STATE_UNKNOWN;
|
||||||
|
public int dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
|
||||||
|
|
||||||
|
DreamRecord(ComponentName name, int userId, boolean isPreview, boolean canDoze) {
|
||||||
|
this.name = name;
|
||||||
|
this.userId = userId;
|
||||||
|
this.isPreview = isPreview;
|
||||||
|
this.canDoze = canDoze;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DreamRecord{"
|
||||||
|
+ "token=" + token
|
||||||
|
+ ", name=" + name
|
||||||
|
+ ", userId=" + userId
|
||||||
|
+ ", isPreview=" + isPreview
|
||||||
|
+ ", canDoze=" + canDoze
|
||||||
|
+ ", isDozing=" + isDozing
|
||||||
|
+ ", isWaking=" + isWaking
|
||||||
|
+ ", dozeScreenState=" + dozeScreenState
|
||||||
|
+ ", dozeScreenBrightness=" + dozeScreenBrightness
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final Runnable mSystemPropertiesChanged = new Runnable() {
|
private final Runnable mSystemPropertiesChanged = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (DEBUG) Slog.d(TAG, "System properties changed");
|
if (DEBUG) Slog.d(TAG, "System properties changed");
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mCurrentDreamName != null && mCurrentDreamCanDoze
|
if (mCurrentDream != null && mCurrentDream.name != null && mCurrentDream.canDoze
|
||||||
&& !mCurrentDreamName.equals(getDozeComponent())) {
|
&& !mCurrentDream.name.equals(getDozeComponent())) {
|
||||||
// May have updated the doze component, wake up
|
// May have updated the doze component, wake up
|
||||||
mPowerManager.wakeUp(SystemClock.uptimeMillis(),
|
mPowerManager.wakeUp(SystemClock.uptimeMillis(),
|
||||||
"android.server.dreams:SYSPROP");
|
"android.server.dreams:SYSPROP");
|
||||||
|
|||||||
@@ -1596,7 +1596,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
// If there's a dream running then use home to escape the dream
|
// If there's a dream running then use home to escape the dream
|
||||||
// but don't actually go home.
|
// but don't actually go home.
|
||||||
if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
|
if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
|
||||||
mDreamManagerInternal.stopDream(false /*immediate*/);
|
mDreamManagerInternal.stopDream(false /*immediate*/, "short press on home" /*reason*/);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3226,8 +3226,10 @@ public final class PowerManagerService extends SystemService
|
|||||||
if (mDreamManager != null) {
|
if (mDreamManager != null) {
|
||||||
// Restart the dream whenever the sandman is summoned.
|
// Restart the dream whenever the sandman is summoned.
|
||||||
if (startDreaming) {
|
if (startDreaming) {
|
||||||
mDreamManager.stopDream(/* immediate= */ false);
|
mDreamManager.stopDream(/* immediate= */ false,
|
||||||
mDreamManager.startDream(wakefulness == WAKEFULNESS_DOZING);
|
"power manager request before starting dream" /*reason*/);
|
||||||
|
mDreamManager.startDream(wakefulness == WAKEFULNESS_DOZING,
|
||||||
|
"power manager request" /*reason*/);
|
||||||
}
|
}
|
||||||
isDreaming = mDreamManager.isDreaming();
|
isDreaming = mDreamManager.isDreaming();
|
||||||
} else {
|
} else {
|
||||||
@@ -3312,7 +3314,7 @@ public final class PowerManagerService extends SystemService
|
|||||||
|
|
||||||
// Stop dream.
|
// Stop dream.
|
||||||
if (isDreaming) {
|
if (isDreaming) {
|
||||||
mDreamManager.stopDream(/* immediate= */ false);
|
mDreamManager.stopDream(/* immediate= */ false, "power manager request" /*reason*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -731,7 +731,7 @@ public class PowerManagerServiceTest {
|
|||||||
doAnswer(inv -> {
|
doAnswer(inv -> {
|
||||||
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
||||||
return null;
|
return null;
|
||||||
}).when(mDreamManagerInternalMock).startDream(anyBoolean());
|
}).when(mDreamManagerInternalMock).startDream(anyBoolean(), anyString());
|
||||||
|
|
||||||
setMinimumScreenOffTimeoutConfig(5);
|
setMinimumScreenOffTimeoutConfig(5);
|
||||||
createService();
|
createService();
|
||||||
@@ -753,7 +753,7 @@ public class PowerManagerServiceTest {
|
|||||||
doAnswer(inv -> {
|
doAnswer(inv -> {
|
||||||
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
||||||
return null;
|
return null;
|
||||||
}).when(mDreamManagerInternalMock).startDream(anyBoolean());
|
}).when(mDreamManagerInternalMock).startDream(anyBoolean(), anyString());
|
||||||
|
|
||||||
setMinimumScreenOffTimeoutConfig(5);
|
setMinimumScreenOffTimeoutConfig(5);
|
||||||
createService();
|
createService();
|
||||||
@@ -1168,7 +1168,7 @@ public class PowerManagerServiceTest {
|
|||||||
doAnswer(inv -> {
|
doAnswer(inv -> {
|
||||||
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
||||||
return null;
|
return null;
|
||||||
}).when(mDreamManagerInternalMock).startDream(anyBoolean());
|
}).when(mDreamManagerInternalMock).startDream(anyBoolean(), anyString());
|
||||||
|
|
||||||
final String pkg = mContextSpy.getOpPackageName();
|
final String pkg = mContextSpy.getOpPackageName();
|
||||||
final Binder token = new Binder();
|
final Binder token = new Binder();
|
||||||
@@ -1662,7 +1662,7 @@ public class PowerManagerServiceTest {
|
|||||||
forceDozing();
|
forceDozing();
|
||||||
// Allow handleSandman() to be called asynchronously
|
// Allow handleSandman() to be called asynchronously
|
||||||
advanceTime(500);
|
advanceTime(500);
|
||||||
verify(mDreamManagerInternalMock).startDream(eq(true));
|
verify(mDreamManagerInternalMock).startDream(eq(true), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1700,7 +1700,7 @@ public class PowerManagerServiceTest {
|
|||||||
|
|
||||||
// Allow handleSandman() to be called asynchronously
|
// Allow handleSandman() to be called asynchronously
|
||||||
advanceTime(500);
|
advanceTime(500);
|
||||||
verify(mDreamManagerInternalMock).startDream(eq(true));
|
verify(mDreamManagerInternalMock).startDream(eq(true), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user