Merge "Add logging to Dream stop." into rvc-dev

This commit is contained in:
Santos Cordon
2020-04-29 14:04:14 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 19 deletions

View File

@@ -62,6 +62,7 @@ final class DreamController {
private final Listener mListener; private final Listener mListener;
private final IWindowManager mIWindowManager; private final IWindowManager mIWindowManager;
private long mDreamStartTime; private long mDreamStartTime;
private String mSavedStopReason;
private final Intent mDreamingStartedIntent = new Intent(Intent.ACTION_DREAMING_STARTED) private final Intent mDreamingStartedIntent = new Intent(Intent.ACTION_DREAMING_STARTED)
.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
@@ -77,14 +78,15 @@ final class DreamController {
public void run() { public void run() {
if (mCurrentDream != null && mCurrentDream.mBound && !mCurrentDream.mConnected) { if (mCurrentDream != null && mCurrentDream.mBound && !mCurrentDream.mConnected) {
Slog.w(TAG, "Bound dream did not connect in the time allotted"); Slog.w(TAG, "Bound dream did not connect in the time allotted");
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "slow to connect");
} }
} }
}; };
private final Runnable mStopStubbornDreamRunnable = () -> { private final Runnable mStopStubbornDreamRunnable = () -> {
Slog.w(TAG, "Stubborn dream did not finish itself in the time allotted"); Slog.w(TAG, "Stubborn dream did not finish itself in the time allotted");
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "slow to finish");
mSavedStopReason = null;
}; };
public DreamController(Context context, Handler handler, Listener listener) { public DreamController(Context context, Handler handler, Listener listener) {
@@ -116,7 +118,7 @@ final class DreamController {
public void startDream(Binder token, ComponentName name, public void startDream(Binder token, ComponentName name,
boolean isTest, boolean canDoze, int userId, PowerManager.WakeLock wakeLock) { boolean isTest, boolean canDoze, int userId, PowerManager.WakeLock wakeLock) {
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "starting new dream");
Trace.traceBegin(Trace.TRACE_TAG_POWER, "startDream"); Trace.traceBegin(Trace.TRACE_TAG_POWER, "startDream");
try { try {
@@ -141,12 +143,12 @@ final class DreamController {
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
new UserHandle(userId))) { new UserHandle(userId))) {
Slog.e(TAG, "Unable to bind dream service: " + intent); Slog.e(TAG, "Unable to bind dream service: " + intent);
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "bindService failed");
return; return;
} }
} catch (SecurityException ex) { } catch (SecurityException ex) {
Slog.e(TAG, "Unable to bind dream service: " + intent, ex); Slog.e(TAG, "Unable to bind dream service: " + intent, ex);
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "unable to bind service: SecExp.");
return; return;
} }
@@ -157,7 +159,7 @@ final class DreamController {
} }
} }
public void stopDream(boolean immediate) { public void stopDream(boolean immediate, String reason) {
if (mCurrentDream == null) { if (mCurrentDream == null) {
return; return;
} }
@@ -173,6 +175,7 @@ final class DreamController {
// Give the dream a moment to wake up and finish itself gently. // Give the dream a moment to wake up and finish itself gently.
mCurrentDream.mWakingGently = true; mCurrentDream.mWakingGently = true;
try { try {
mSavedStopReason = reason;
mCurrentDream.mService.wakeUp(); mCurrentDream.mService.wakeUp();
mHandler.postDelayed(mStopStubbornDreamRunnable, DREAM_FINISH_TIMEOUT); mHandler.postDelayed(mStopStubbornDreamRunnable, DREAM_FINISH_TIMEOUT);
return; return;
@@ -186,7 +189,9 @@ final class DreamController {
mCurrentDream = null; mCurrentDream = null;
Slog.i(TAG, "Stopping dream: name=" + oldDream.mName Slog.i(TAG, "Stopping dream: name=" + oldDream.mName
+ ", isTest=" + oldDream.mIsTest + ", canDoze=" + oldDream.mCanDoze + ", isTest=" + oldDream.mIsTest + ", canDoze=" + oldDream.mCanDoze
+ ", userId=" + oldDream.mUserId); + ", userId=" + oldDream.mUserId
+ ", reason='" + reason + "'"
+ (mSavedStopReason == null ? "" : "(from '" + mSavedStopReason + "')"));
MetricsLogger.hidden(mContext, MetricsLogger.hidden(mContext,
oldDream.mCanDoze ? MetricsEvent.DOZING : MetricsEvent.DREAMING); oldDream.mCanDoze ? MetricsEvent.DOZING : MetricsEvent.DREAMING);
MetricsLogger.histogram(mContext, MetricsLogger.histogram(mContext,
@@ -195,6 +200,7 @@ final class DreamController {
mHandler.removeCallbacks(mStopUnconnectedDreamRunnable); mHandler.removeCallbacks(mStopUnconnectedDreamRunnable);
mHandler.removeCallbacks(mStopStubbornDreamRunnable); mHandler.removeCallbacks(mStopStubbornDreamRunnable);
mSavedStopReason = null;
if (oldDream.mSentStartBroadcast) { if (oldDream.mSentStartBroadcast) {
mContext.sendBroadcastAsUser(mDreamingStoppedIntent, UserHandle.ALL); mContext.sendBroadcastAsUser(mDreamingStoppedIntent, UserHandle.ALL);
@@ -233,7 +239,7 @@ final class DreamController {
mCurrentDream.mDreamingStartedCallback); mCurrentDream.mDreamingStartedCallback);
} catch (RemoteException ex) { } catch (RemoteException ex) {
Slog.e(TAG, "The dream service died unexpectedly.", ex); Slog.e(TAG, "The dream service died unexpectedly.", ex);
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "attach failed");
return; return;
} }
@@ -287,7 +293,7 @@ final class DreamController {
mHandler.post(() -> { mHandler.post(() -> {
mService = null; mService = null;
if (mCurrentDream == DreamRecord.this) { if (mCurrentDream == DreamRecord.this) {
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "binder died");
} }
}); });
} }
@@ -312,7 +318,7 @@ final class DreamController {
mHandler.post(() -> { mHandler.post(() -> {
mService = null; mService = null;
if (mCurrentDream == DreamRecord.this) { if (mCurrentDream == DreamRecord.this) {
stopDream(true /*immediate*/); stopDream(true /*immediate*/, "service disconnected");
} }
}); });
} }

View File

@@ -121,7 +121,7 @@ public final class DreamManagerService extends SystemService {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
writePulseGestureEnabled(); writePulseGestureEnabled();
synchronized (mLock) { synchronized (mLock) {
stopDreamLocked(false /*immediate*/); stopDreamLocked(false /*immediate*/, "user switched");
} }
} }
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
@@ -180,7 +180,7 @@ public final class DreamManagerService extends SystemService {
// for example when being undocked. // for example when being undocked.
long time = SystemClock.uptimeMillis(); long time = SystemClock.uptimeMillis();
mPowerManager.userActivity(time, false /*noChangeLights*/); mPowerManager.userActivity(time, false /*noChangeLights*/);
stopDreamInternal(false /*immediate*/); stopDreamInternal(false /*immediate*/, "request awaken");
} }
private void finishSelfInternal(IBinder token, boolean immediate) { private void finishSelfInternal(IBinder token, boolean immediate) {
@@ -197,7 +197,7 @@ public final class DreamManagerService extends SystemService {
// device may simply go to sleep. // device may simply go to sleep.
synchronized (mLock) { synchronized (mLock) {
if (mCurrentDreamToken == token) { if (mCurrentDreamToken == token) {
stopDreamLocked(immediate); stopDreamLocked(immediate, "finished self");
} }
} }
} }
@@ -218,9 +218,9 @@ public final class DreamManagerService extends SystemService {
} }
} }
private void stopDreamInternal(boolean immediate) { private void stopDreamInternal(boolean immediate, String reason) {
synchronized (mLock) { synchronized (mLock) {
stopDreamLocked(immediate); stopDreamLocked(immediate, reason);
} }
} }
@@ -373,7 +373,7 @@ public final class DreamManagerService extends SystemService {
return; return;
} }
stopDreamLocked(true /*immediate*/); stopDreamLocked(true /*immediate*/, "starting new dream");
Slog.i(TAG, "Entering dreamland."); Slog.i(TAG, "Entering dreamland.");
@@ -392,7 +392,7 @@ public final class DreamManagerService extends SystemService {
})); }));
} }
private void stopDreamLocked(final boolean immediate) { private void stopDreamLocked(final boolean immediate, String reason) {
if (mCurrentDreamToken != null) { if (mCurrentDreamToken != null) {
if (immediate) { if (immediate) {
Slog.i(TAG, "Leaving dreamland."); Slog.i(TAG, "Leaving dreamland.");
@@ -408,7 +408,7 @@ public final class DreamManagerService extends SystemService {
@Override @Override
public void run() { public void run() {
Slog.i(TAG, "Performing gentle wake from dream."); Slog.i(TAG, "Performing gentle wake from dream.");
mController.stopDream(immediate); mController.stopDream(immediate, reason);
} }
}); });
} }
@@ -696,7 +696,7 @@ public final class DreamManagerService extends SystemService {
@Override @Override
public void stopDream(boolean immediate) { public void stopDream(boolean immediate) {
stopDreamInternal(immediate); stopDreamInternal(immediate, "requested stopDream");
} }
@Override @Override