Methods Summary |
---|
public void | addContentView(android.view.View view, ViewGroup.LayoutParams params)Adds a view to the Dream's window, leaving other content views in place.
Note: Requires a window, do not call before {@link #onAttachedToWindow()}
getWindow().addContentView(view, params);
|
private int | applyFlags(int oldFlags, int flags, int mask)
return (oldFlags&~mask) | (flags&mask);
|
private void | applySystemUiVisibilityFlags(int flags, int mask)
View v = mWindow == null ? null : mWindow.getDecorView();
if (v != null) {
v.setSystemUiVisibility(applyFlags(v.getSystemUiVisibility(), flags, mask));
}
|
private void | applyWindowFlags(int flags, int mask)
if (mWindow != null) {
WindowManager.LayoutParams lp = mWindow.getAttributes();
lp.flags = applyFlags(lp.flags, flags, mask);
mWindow.setAttributes(lp);
mWindow.getWindowManager().updateViewLayout(mWindow.getDecorView(), lp);
}
|
private final void | attach(android.os.IBinder windowToken, boolean canDoze)Called when the Dream is ready to be shown.
Must run on mHandler.
if (mWindowToken != null) {
Slog.e(TAG, "attach() called when already attached with token=" + mWindowToken);
return;
}
if (mFinished || mWaking) {
Slog.w(TAG, "attach() called after dream already finished");
try {
mSandman.finishSelf(windowToken, true /*immediate*/);
} catch (RemoteException ex) {
// system server died
}
return;
}
mWindowToken = windowToken;
mCanDoze = canDoze;
if (mWindowless && !mCanDoze) {
throw new IllegalStateException("Only doze dreams can be windowless");
}
if (!mWindowless) {
mWindow = PolicyManager.makeNewWindow(this);
mWindow.setCallback(this);
mWindow.requestFeature(Window.FEATURE_NO_TITLE);
mWindow.setBackgroundDrawable(new ColorDrawable(0xFF000000));
mWindow.setFormat(PixelFormat.OPAQUE);
if (mDebug) Slog.v(TAG, String.format("Attaching window token: %s to window of type %s",
windowToken, WindowManager.LayoutParams.TYPE_DREAM));
WindowManager.LayoutParams lp = mWindow.getAttributes();
lp.type = WindowManager.LayoutParams.TYPE_DREAM;
lp.token = windowToken;
lp.windowAnimations = com.android.internal.R.style.Animation_Dream;
lp.flags |= ( WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| (mFullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0)
| (mScreenBright ? WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON : 0)
);
mWindow.setAttributes(lp);
// Workaround: Currently low-profile and in-window system bar backgrounds don't go
// along well. Dreams usually don't need such bars anyways, so disable them by default.
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
mWindow.setWindowManager(null, windowToken, "dream", true);
applySystemUiVisibilityFlags(
(mLowProfile ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0),
View.SYSTEM_UI_FLAG_LOW_PROFILE);
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;
}
}
// We need to defer calling onDreamingStarted until after onWindowAttached,
// which is posted to the handler by addView, so we post onDreamingStarted
// to the handler also. Need to watch out here in case detach occurs before
// this callback is invoked.
mHandler.post(new Runnable() {
@Override
public void run() {
if (mWindow != null || mWindowless) {
if (mDebug) Slog.v(TAG, "Calling onDreamingStarted()");
mStarted = true;
onDreamingStarted();
}
}
});
|
public boolean | canDoze()Returns true if this dream is allowed to doze.
The value returned by this method is only meaningful when the dream has started.
return mCanDoze;
|
private static int | clampAbsoluteBrightness(int value)
return MathUtils.constrain(value, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
|
private final void | detach()Called by DreamController.stopDream() when the Dream is about to be unbound and destroyed.
Must run on mHandler.
if (mStarted) {
if (mDebug) Slog.v(TAG, "detach(): Calling onDreamingStopped()");
mStarted = false;
onDreamingStopped();
}
if (mWindow != null) {
// 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 (mWindowToken != null) {
// the following will print a log message if it finds any other leaked windows
WindowManagerGlobal.getInstance().closeAll(mWindowToken,
this.getClass().getName(), "Dream");
mWindowToken = null;
mCanDoze = false;
}
|
public boolean | dispatchGenericMotionEvent(android.view.MotionEvent event){@inheritDoc}
if (!mInteractive) {
if (mDebug) Slog.v(TAG, "Waking up on genericMotionEvent");
wakeUp();
return true;
}
return mWindow.superDispatchGenericMotionEvent(event);
|
public boolean | dispatchKeyEvent(android.view.KeyEvent event){@inheritDoc}
// TODO: create more flexible version of mInteractive that allows use of KEYCODE_BACK
if (!mInteractive) {
if (mDebug) Slog.v(TAG, "Waking up on keyEvent");
wakeUp();
return true;
} else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (mDebug) Slog.v(TAG, "Waking up on back key");
wakeUp();
return true;
}
return mWindow.superDispatchKeyEvent(event);
|
public boolean | dispatchKeyShortcutEvent(android.view.KeyEvent event){@inheritDoc}
if (!mInteractive) {
if (mDebug) Slog.v(TAG, "Waking up on keyShortcutEvent");
wakeUp();
return true;
}
return mWindow.superDispatchKeyShortcutEvent(event);
|
public boolean | dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event){@inheritDoc}
return false;
|
public boolean | dispatchTouchEvent(android.view.MotionEvent event){@inheritDoc}
// TODO: create more flexible version of mInteractive that allows clicks
// but finish()es on any other kind of activity
if (!mInteractive) {
if (mDebug) Slog.v(TAG, "Waking up on touchEvent");
wakeUp();
return true;
}
return mWindow.superDispatchTouchEvent(event);
|
public boolean | dispatchTrackballEvent(android.view.MotionEvent event){@inheritDoc}
if (!mInteractive) {
if (mDebug) Slog.v(TAG, "Waking up on trackballEvent");
wakeUp();
return true;
}
return mWindow.superDispatchTrackballEvent(event);
|
protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)
DumpUtils.dumpAsync(mHandler, new Dump() {
@Override
public void dump(PrintWriter pw) {
dumpOnHandler(fd, pw, args);
}
}, pw, 1000);
|
protected void | dumpOnHandler(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)
pw.print(TAG + ": ");
if (mWindowToken == null) {
pw.println("stopped");
} else {
pw.println("running (token=" + mWindowToken + ")");
}
pw.println(" window: " + mWindow);
pw.print(" flags:");
if (isInteractive()) pw.print(" interactive");
if (isLowProfile()) pw.print(" lowprofile");
if (isFullscreen()) pw.print(" fullscreen");
if (isScreenBright()) pw.print(" bright");
if (isWindowless()) pw.print(" windowless");
if (isDozing()) pw.print(" dozing");
else if (canDoze()) pw.print(" candoze");
pw.println();
if (canDoze()) {
pw.println(" doze screen state: " + Display.stateToString(mDozeScreenState));
pw.println(" doze screen brightness: " + mDozeScreenBrightness);
}
|
public android.view.View | findViewById(int id)Finds a view that was identified by the id attribute from the XML that
was processed in {@link #onCreate}.
Note: Requires a window, do not call before {@link #onAttachedToWindow()}
return getWindow().findViewById(id);
|
public final void | finish()Stops the dream and detaches from the window.
When the dream ends, the system will be allowed to go to sleep fully unless there
is a reason for it to be awake such as recent user activity or wake locks being held.
if (mDebug) Slog.v(TAG, "finish(): mFinished=" + mFinished);
if (!mFinished) {
mFinished = true;
if (mWindowToken == null) {
Slog.w(TAG, "Finish was called before the dream was attached.");
} else {
try {
mSandman.finishSelf(mWindowToken, true /*immediate*/);
} catch (RemoteException ex) {
// system server died
}
}
stopSelf(); // if launched via any other means
}
|
public int | getDozeScreenBrightness()Gets the screen brightness to use while dozing.
return mDozeScreenBrightness;
|
public int | getDozeScreenState()Gets the screen state to use while dozing.
return mDozeScreenState;
|
private boolean | getSystemUiVisibilityFlagValue(int flag, boolean defaultValue)
View v = mWindow == null ? null : mWindow.getDecorView();
return v == null ? defaultValue : (v.getSystemUiVisibility() & flag) != 0;
|
public android.view.Window | getWindow()Retrieves the current {@link android.view.Window} for the dream.
Behaves similarly to {@link android.app.Activity#getWindow()}.
return mWindow;
|
private boolean | getWindowFlagValue(int flag, boolean defaultValue)
return mWindow == null ? defaultValue : (mWindow.getAttributes().flags & flag) != 0;
|
public android.view.WindowManager | getWindowManager()Retrieves the current {@link android.view.WindowManager} for the dream.
Behaves similarly to {@link android.app.Activity#getWindowManager()}.
return mWindow != null ? mWindow.getWindowManager() : null;
|
public boolean | isDozing()Returns true if the dream will allow the system to enter a low-power state while
it is running without actually turning off the screen. Defaults to false,
keeping the application processor awake while the dream is running.
return mDozing;
|
public boolean | isFullscreen()Returns whether or not this dream is in fullscreen mode. Defaults to false.
return mFullscreen;
|
public boolean | isInteractive()Returns whether or not this dream is interactive. Defaults to false.
return mInteractive;
|
public boolean | isLowProfile()Returns whether or not this dream is in low profile mode. Defaults to true.
return getSystemUiVisibilityFlagValue(View.SYSTEM_UI_FLAG_LOW_PROFILE, mLowProfile);
|
public boolean | isScreenBright()Returns whether or not this dream keeps the screen bright while dreaming.
Defaults to false, allowing the screen to dim if necessary.
return getWindowFlagValue(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, mScreenBright);
|
public boolean | isWindowless()Returns whether or not this dream is windowless. Only available to doze dreams.
return mWindowless;
|
public void | onActionModeFinished(android.view.ActionMode mode){@inheritDoc}
|
public void | onActionModeStarted(android.view.ActionMode mode){@inheritDoc}
|
public void | onAttachedToWindow(){@inheritDoc}
|
public final android.os.IBinder | onBind(android.content.Intent intent){@inheritDoc}
if (mDebug) Slog.v(TAG, "onBind() intent = " + intent);
return new DreamServiceWrapper();
|
public void | onContentChanged(){@inheritDoc}
|
public void | onCreate()Called when this Dream is constructed.
if (mDebug) Slog.v(TAG, "onCreate()");
super.onCreate();
|
public boolean | onCreatePanelMenu(int featureId, android.view.Menu menu){@inheritDoc}
return false;
|
public android.view.View | onCreatePanelView(int featureId){@inheritDoc}
return null;
|
public void | onDestroy(){@inheritDoc}
if (mDebug) Slog.v(TAG, "onDestroy()");
// hook for subclasses
// Just in case destroy came in before detach, let's take care of that now
detach();
super.onDestroy();
|
public void | onDetachedFromWindow(){@inheritDoc}
|
public void | onDreamingStarted()Called when the dream's window has been created and is visible and animation may now begin.
if (mDebug) Slog.v(TAG, "onDreamingStarted()");
// hook for subclasses
|
public void | onDreamingStopped()Called when this Dream is stopped, either by external request or by calling finish(),
before the window has been removed.
if (mDebug) Slog.v(TAG, "onDreamingStopped()");
// hook for subclasses
|
public boolean | onMenuItemSelected(int featureId, android.view.MenuItem item){@inheritDoc}
return false;
|
public boolean | onMenuOpened(int featureId, android.view.Menu menu){@inheritDoc}
return false;
|
public void | onPanelClosed(int featureId, android.view.Menu menu){@inheritDoc}
|
public boolean | onPreparePanel(int featureId, android.view.View view, android.view.Menu menu){@inheritDoc}
return false;
|
public boolean | onSearchRequested(){@inheritDoc}
return false;
|
public void | onWakeUp()Called when the dream is being asked to stop itself and wake.
The default implementation simply calls {@link #finish} which ends the dream
immediately. Subclasses may override this function to perform a smooth exit
transition then call {@link #finish} afterwards.
Note that the dream will only be given a short period of time (currently about
five seconds) to wake up. If the dream does not finish itself in a timely manner
then the system will forcibly finish it once the time allowance is up.
finish();
|
public void | onWindowAttributesChanged(android.view.WindowManager.LayoutParams attrs){@inheritDoc}
|
public void | onWindowFocusChanged(boolean hasFocus){@inheritDoc}
|
public android.view.ActionMode | onWindowStartingActionMode(android.view.ActionMode.Callback callback){@inheritDoc}
return null;
|
public void | setContentView(int layoutResID)Inflates a layout resource and set it to be the content view for this Dream.
Behaves similarly to {@link android.app.Activity#setContentView(int)}.
Note: Requires a window, do not call before {@link #onAttachedToWindow()}
getWindow().setContentView(layoutResID);
|
public void | setContentView(android.view.View view)Sets a view to be the content view for this Dream.
Behaves similarly to {@link android.app.Activity#setContentView(android.view.View)} in an activity,
including using {@link ViewGroup.LayoutParams#MATCH_PARENT} as the layout height and width of the view.
Note: This requires a window, so you should usually call it during
{@link #onAttachedToWindow()} and never earlier (you cannot call it
during {@link #onCreate}).
getWindow().setContentView(view);
|
public void | setContentView(android.view.View view, ViewGroup.LayoutParams params)Sets a view to be the content view for this Dream.
Behaves similarly to
{@link android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)}
in an activity.
Note: This requires a window, so you should usually call it during
{@link #onAttachedToWindow()} and never earlier (you cannot call it
during {@link #onCreate}).
getWindow().setContentView(view, params);
|
public void | setDebug(boolean dbg)
mDebug = dbg;
|
public void | setDozeScreenBrightness(int brightness)Sets the screen brightness to use while dozing.
The value of this property determines the power state of the primary display
once {@link #startDozing} has been called. The default value is
{@link PowerManager#BRIGHTNESS_DEFAULT} which lets the system decide.
The dream may set a different brightness before starting to doze and may adjust
the brightness while dozing to conserve power and achieve various effects.
Note that dream may specify any brightness in the full 0-255 range, including
values that are less than the minimum value for manual screen brightness
adjustments by the user. In particular, the value may be set to 0 which may
turn off the backlight entirely while still leaving the screen on although
this behavior is device dependent and not guaranteed.
The available range of display brightness values and their behavior while dozing is
hardware dependent and may vary across devices. The dream may therefore
need to be modified or configured to correctly support the hardware.
if (brightness != PowerManager.BRIGHTNESS_DEFAULT) {
brightness = clampAbsoluteBrightness(brightness);
}
if (mDozeScreenBrightness != brightness) {
mDozeScreenBrightness = brightness;
updateDoze();
}
|
public void | setDozeScreenState(int state)Sets the screen state to use while dozing.
The value of this property determines the power state of the primary display
once {@link #startDozing} has been called. The default value is
{@link Display#STATE_UNKNOWN} which lets the system decide.
The dream may set a different state before starting to doze and may
perform transitions between states while dozing to conserve power and
achieve various effects.
It is recommended that the state be set to {@link Display#STATE_DOZE_SUSPEND}
once the dream has completely finished drawing and before it releases its wakelock
to allow the display hardware to be fully suspended. While suspended, the
display will preserve its on-screen contents or hand off control to dedicated
doze hardware if the devices supports it. If the doze suspend state is
used, the dream must make sure to set the mode back
to {@link Display#STATE_DOZE} or {@link Display#STATE_ON} before drawing again
since the display updates may be ignored and not seen by the user otherwise.
The set of available display power states and their behavior while dozing is
hardware dependent and may vary across devices. The dream may therefore
need to be modified or configured to correctly support the hardware.
if (mDozeScreenState != state) {
mDozeScreenState = state;
updateDoze();
}
|
public void | setFullscreen(boolean fullscreen)Controls {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN}
on the dream's window.
if (mFullscreen != fullscreen) {
mFullscreen = fullscreen;
int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
applyWindowFlags(mFullscreen ? flag : 0, flag);
}
|
public void | setInteractive(boolean interactive)Marks this dream as interactive to receive input events.
Non-interactive dreams (default) will dismiss on the first input event.
Interactive dreams should call {@link #finish()} to dismiss themselves.
mInteractive = interactive;
|
public void | setLowProfile(boolean lowProfile)Sets View.SYSTEM_UI_FLAG_LOW_PROFILE on the content view.
if (mLowProfile != lowProfile) {
mLowProfile = lowProfile;
int flag = View.SYSTEM_UI_FLAG_LOW_PROFILE;
applySystemUiVisibilityFlags(mLowProfile ? flag : 0, flag);
}
|
public void | setScreenBright(boolean screenBright)Marks this dream as keeping the screen bright while dreaming.
if (mScreenBright != screenBright) {
mScreenBright = screenBright;
int flag = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
applyWindowFlags(mScreenBright ? flag : 0, flag);
}
|
public void | setWindowless(boolean windowless)Marks this dream as windowless. Only available to doze dreams.
mWindowless = windowless;
|
public void | startDozing()Starts dozing, entering a deep dreamy sleep.
Dozing enables the system to conserve power while the user is not actively interacting
with the device. While dozing, the display will remain on in a low-power state
and will continue to show its previous contents but the application processor and
other system components will be allowed to suspend when possible.
While the application processor is suspended, the dream may stop executing code
for long periods of time. Prior to being suspended, the dream may schedule periodic
wake-ups to render new content by scheduling an alarm with the {@link AlarmManager}.
The dream may also keep the CPU awake by acquiring a
{@link android.os.PowerManager#PARTIAL_WAKE_LOCK partial wake lock} when necessary.
Note that since the purpose of doze mode is to conserve power (especially when
running on battery), the dream should not wake the CPU very often or keep it
awake for very long.
It is a good idea to call this method some time after the dream's entry animation
has completed and the dream is ready to doze. It is important to completely
finish all of the work needed before dozing since the application processor may
be suspended at any moment once this method is called unless other wake locks
are being held.
Call {@link #stopDozing} or {@link #finish} to stop dozing.
if (mCanDoze && !mDozing) {
mDozing = true;
updateDoze();
}
|
public void | stopDozing()Stops dozing, returns to active dreaming.
This method reverses the effect of {@link #startDozing}. From this moment onward,
the application processor will be kept awake as long as the dream is running
or until the dream starts dozing again.
if (mDozing) {
mDozing = false;
try {
mSandman.stopDozing(mWindowToken);
} catch (RemoteException ex) {
// system server died
}
}
|
private void | updateDoze()
if (mDozing) {
try {
mSandman.startDozing(mWindowToken, mDozeScreenState, mDozeScreenBrightness);
} catch (RemoteException ex) {
// system server died
}
}
|
public final void | wakeUp()Wakes the dream up gently.
Calls {@link #onWakeUp} to give the dream a chance to perform an exit transition.
When the transition is over, the dream should call {@link #finish}.
wakeUp(false);
|
private void | wakeUp(boolean fromSystem)
if (mDebug) Slog.v(TAG, "wakeUp(): fromSystem=" + fromSystem
+ ", mWaking=" + mWaking + ", mFinished=" + mFinished);
if (!mWaking && !mFinished) {
mWaking = true;
// As a minor optimization, invoke the callback first in case it simply
// calls finish() immediately so there wouldn't be much point in telling
// the system that we are finishing the dream gently.
onWakeUp();
// Now tell the system we are waking gently, unless we already told
// it we were finishing immediately.
if (!fromSystem && !mFinished) {
if (mWindowToken == null) {
Slog.w(TAG, "WakeUp was called before the dream was attached.");
} else {
try {
mSandman.finishSelf(mWindowToken, false /*immediate*/);
} catch (RemoteException ex) {
// system server died
}
}
}
}
|