am 8db6d9af: Merge "Clean up certain state transitions in DreamService." into klp-modular-dev

* commit '8db6d9af58b9b81dbd764acd3f6a379afb539bf6':
  Clean up certain state transitions in DreamService.
This commit is contained in:
Jeff Brown
2014-04-03 03:25:02 +00:00
committed by Android Git Automerger

View File

@ -153,11 +153,11 @@ public class DreamService extends Service implements Window.Callback {
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private IBinder mWindowToken; private IBinder mWindowToken;
private Window mWindow; private Window mWindow;
private WindowManager mWindowManager; private boolean mInteractive;
private boolean mInteractive = false;
private boolean mLowProfile = true; private boolean mLowProfile = true;
private boolean mFullscreen = false; private boolean mFullscreen;
private boolean mScreenBright = true; private boolean mScreenBright = true;
private boolean mStarted;
private boolean mFinished; private boolean mFinished;
private boolean mCanDoze; private boolean mCanDoze;
private boolean mDozing; private boolean mDozing;
@ -340,7 +340,7 @@ public class DreamService extends Service implements Window.Callback {
* @return The current window manager, or null if the dream is not started. * @return The current window manager, or null if the dream is not started.
*/ */
public WindowManager getWindowManager() { public WindowManager getWindowManager() {
return mWindowManager; return mWindow != null ? mWindow.getWindowManager() : null;
} }
/** /**
@ -623,7 +623,7 @@ public class DreamService extends Service implements Window.Callback {
* @hide experimental * @hide experimental
*/ */
public DozeHardware getDozeHardware() { public DozeHardware getDozeHardware() {
if (mCanDoze && mDozeHardware == null) { if (mCanDoze && mDozeHardware == null && mWindowToken != null) {
try { try {
IDozeHardware hardware = mSandman.getDozeHardware(mWindowToken); IDozeHardware hardware = mSandman.getDozeHardware(mWindowToken);
if (hardware != null) { if (hardware != null) {
@ -701,24 +701,25 @@ public class DreamService extends Service implements Window.Callback {
* Must run on mHandler. * Must run on mHandler.
*/ */
private final void detach() { private final void detach() {
if (mWindow == null) { if (mStarted) {
// already detached! if (mDebug) Slog.v(TAG, "detach(): Calling onDreamingStopped()");
return; mStarted = false;
onDreamingStopped();
} }
if (mDebug) Slog.v(TAG, "detach(): Calling onDreamingStopped()"); if (mWindow != null) {
onDreamingStopped(); // force our window to be removed synchronously
if (mDebug) Slog.v(TAG, "detach(): Removing window from window manager");
mWindow.getWindowManager().removeViewImmediate(mWindow.getDecorView());
mWindow = null;
}
if (mDebug) Slog.v(TAG, "detach(): Removing window from window manager"); if (mWindowToken != null) {
// the following will print a log message if it finds any other leaked windows
// force our window to be removed synchronously WindowManagerGlobal.getInstance().closeAll(mWindowToken,
mWindowManager.removeViewImmediate(mWindow.getDecorView()); this.getClass().getName(), "Dream");
// the following will print a log message if it finds any other leaked windows mWindowToken = null;
WindowManagerGlobal.getInstance().closeAll(mWindowToken, }
this.getClass().getName(), "Dream");
mWindow = null;
mWindowToken = null;
} }
/** /**
@ -746,12 +747,13 @@ public class DreamService extends Service implements Window.Callback {
if (mDebug) Slog.v(TAG, "Attached on thread " + Thread.currentThread().getId()); if (mDebug) Slog.v(TAG, "Attached on thread " + Thread.currentThread().getId());
mWindowToken = windowToken; mWindowToken = windowToken;
mCanDoze = canDoze;
mWindow = PolicyManager.makeNewWindow(this); mWindow = PolicyManager.makeNewWindow(this);
mWindow.setCallback(this); mWindow.setCallback(this);
mWindow.requestFeature(Window.FEATURE_NO_TITLE); mWindow.requestFeature(Window.FEATURE_NO_TITLE);
mWindow.setBackgroundDrawable(new ColorDrawable(0xFF000000)); mWindow.setBackgroundDrawable(new ColorDrawable(0xFF000000));
mWindow.setFormat(PixelFormat.OPAQUE); mWindow.setFormat(PixelFormat.OPAQUE);
mCanDoze = canDoze;
if (mDebug) Slog.v(TAG, String.format("Attaching window token: %s to window of type %s", if (mDebug) Slog.v(TAG, String.format("Attaching window token: %s to window of type %s",
windowToken, WindowManager.LayoutParams.TYPE_DREAM)); windowToken, WindowManager.LayoutParams.TYPE_DREAM));
@ -769,26 +771,28 @@ public class DreamService extends Service implements Window.Callback {
| (mScreenBright ? WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON : 0) | (mScreenBright ? WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON : 0)
); );
mWindow.setAttributes(lp); mWindow.setAttributes(lp);
if (mDebug) Slog.v(TAG, "Created and attached window: " + mWindow);
mWindow.setWindowManager(null, windowToken, "dream", true); mWindow.setWindowManager(null, windowToken, "dream", true);
mWindowManager = mWindow.getWindowManager();
if (mDebug) Slog.v(TAG, "Window added on thread " + Thread.currentThread().getId());
applySystemUiVisibilityFlags( applySystemUiVisibilityFlags(
(mLowProfile ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0), (mLowProfile ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0),
View.SYSTEM_UI_FLAG_LOW_PROFILE); View.SYSTEM_UI_FLAG_LOW_PROFILE);
getWindowManager().addView(mWindow.getDecorView(), mWindow.getAttributes());
try {
getWindowManager().addView(mWindow.getDecorView(), mWindow.getAttributes());
} catch (WindowManager.BadTokenException ex) {
// This can happen because the dream manager service will remove the token
// immediately without necessarily waiting for the dream to start.
// We should receive a finish message soon.
Slog.i(TAG, "attach() called after window token already removed, dream will "
+ "finish soon");
mWindow = null;
return;
}
// start it up // start it up
mHandler.post(new Runnable() { if (mDebug) Slog.v(TAG, "Calling onDreamingStarted()");
@Override mStarted = true;
public void run() { onDreamingStarted();
if (mDebug) Slog.v(TAG, "Calling onDreamingStarted()");
onDreamingStarted();
}
});
} }
private void safelyFinish() { private void safelyFinish() {
@ -831,7 +835,7 @@ public class DreamService extends Service implements Window.Callback {
WindowManager.LayoutParams lp = mWindow.getAttributes(); WindowManager.LayoutParams lp = mWindow.getAttributes();
lp.flags = applyFlags(lp.flags, flags, mask); lp.flags = applyFlags(lp.flags, flags, mask);
mWindow.setAttributes(lp); mWindow.setAttributes(lp);
mWindowManager.updateViewLayout(mWindow.getDecorView(), lp); mWindow.getWindowManager().updateViewLayout(mWindow.getDecorView(), lp);
} }
} }