summaryrefslogtreecommitdiffstats
path: root/policy/src/com/android
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@android.com>2011-04-13 01:01:32 -0400
committerDaniel Sandler <dsandler@google.com>2011-05-24 10:28:52 -0400
commit0601eb7953cbf77d92826bef3ca37e208d922de7 (patch)
tree2c03cf6044b025e951648a6ea42577f3292e8f33 /policy/src/com/android
parent52ee3eb4ebf108e593cc85b79d0aa1f651c69e35 (diff)
downloadframeworks_base-0601eb7953cbf77d92826bef3ca37e208d922de7.zip
frameworks_base-0601eb7953cbf77d92826bef3ca37e208d922de7.tar.gz
frameworks_base-0601eb7953cbf77d92826bef3ca37e208d922de7.tar.bz2
Framework support for Android Dreams.
A Dream is an activity that is launched by the window manager after a specified idle time. You might think of this as a "screen saver", but with the same capacity for interactivity as any other application. The window manager maintains a timer (like the screen lock timer) that is reset on userActivity; the timer is suspended during wakelocks and when the screen is off. When the timer elapses, the user's preferred dream module is launched (by reading Settings.Secure.DREAM_COMPONENT, which is configured through the Settings app UI). Like a dock app, the user can install new dreams and a single application package may contain multiple dream activities. Unlike the dock mode, however, there is no "screensaver mode" for the system to manage. This allows us to offer the user the ability to run a dream at any time, in addition to making the overall mechanism quite simple. There is no public API for this facility. There is, however, a useful/recommended base class for dream activities in the support library (change I4559a958). Change-Id: Ied691856f88cfa38a7aca496d015f9a595da72f2
Diffstat (limited to 'policy/src/com/android')
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java94
1 files changed, 91 insertions, 3 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 03afc82..f34044d 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -23,6 +23,7 @@ import android.app.IUiModeManager;
import android.app.UiModeManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -344,6 +345,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
int mLockScreenTimeout;
boolean mLockScreenTimerActive;
+ // visual screen saver support
+ int mScreenSaverTimeout;
+ boolean mScreenSaverEnabled = false;
+
// Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
int mEndcallBehavior;
@@ -399,6 +404,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
resolver.registerContentObserver(Settings.System.getUriFor(
"fancy_rotation_anim"), false, this);
+ resolver.registerContentObserver(Settings.System.getUriFor(
+ Settings.Secure.DREAM_TIMEOUT), false, this);
updateSettings();
}
@@ -832,6 +839,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mHasSoftInput = hasSoftInput;
updateRotation = true;
}
+
+ mScreenSaverTimeout = Settings.System.getInt(resolver,
+ Settings.Secure.DREAM_TIMEOUT, 0);
+ mScreenSaverEnabled = true;
+ updateScreenSaverTimeoutLocked();
}
if (updateRotation) {
updateRotation(0);
@@ -2595,6 +2607,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mScreenOn = false;
updateOrientationListenerLp();
updateLockScreenTimeout();
+ updateScreenSaverTimeoutLocked();
}
}
@@ -2606,6 +2619,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mScreenOn = true;
updateOrientationListenerLp();
updateLockScreenTimeout();
+ updateScreenSaverTimeoutLocked();
}
}
@@ -2886,6 +2900,63 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mStatusBarService.userActivity();
} catch (RemoteException ex) {}
}
+
+ synchronized (mLock) {
+ updateScreenSaverTimeoutLocked();
+ }
+ }
+
+ Runnable mScreenSaverActivator = new Runnable() {
+ public void run() {
+ synchronized (this) {
+ if (!(mScreenSaverEnabled && mScreenOn)) {
+ Log.w(TAG, "mScreenSaverActivator ran, but the screensaver should not be showing. Who's driving this thing?");
+ return;
+ }
+
+ if (localLOGV) Log.v(TAG, "mScreenSaverActivator entering dreamland");
+ try {
+ String component = Settings.System.getString(
+ mContext.getContentResolver(), Settings.Secure.DREAM_COMPONENT);
+ if (component != null) {
+ ComponentName cn = ComponentName.unflattenFromString(component);
+ Intent intent = new Intent(Intent.ACTION_MAIN)
+ .setComponent(cn)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
+ | Intent.FLAG_ACTIVITY_NO_USER_ACTION
+ | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ mContext.startActivity(intent);
+ } else {
+ Log.e(TAG, "Couldn't start screen saver: none selected");
+ }
+ } catch (android.content.ActivityNotFoundException exc) {
+ // no screensaver? give up
+ Log.e(TAG, "Couldn't start screen saver: none installed");
+ }
+ }
+ }
+ };
+
+ // Must call while holding mLock
+ private void updateScreenSaverTimeoutLocked() {
+ synchronized (mScreenSaverActivator) {
+ mHandler.removeCallbacks(mScreenSaverActivator);
+ if (mScreenSaverEnabled && mScreenOn && mScreenSaverTimeout > 0) {
+ if (localLOGV)
+ Log.v(TAG, "scheduling screensaver for " + mScreenSaverTimeout + "ms from now");
+ mHandler.postDelayed(mScreenSaverActivator, mScreenSaverTimeout);
+ } else {
+ if (localLOGV) {
+ if (mScreenSaverTimeout == 0)
+ Log.v(TAG, "screen saver disabled by user");
+ else if (!mScreenOn)
+ Log.v(TAG, "screen saver disabled while screen off");
+ else
+ Log.v(TAG, "screen saver disabled by wakelock");
+ }
+ }
+ }
}
Runnable mScreenLockTimeout = new Runnable() {
@@ -3081,10 +3152,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return true;
}
+ public void screenOnStartedLw() {
+ // The window manager has just grabbed a wake lock. This is our cue to disable the screen
+ // saver.
+ synchronized (mLock) {
+ mScreenSaverEnabled = false;
+ }
+ }
+
public void screenOnStoppedLw() {
- if (!mKeyguardMediator.isShowingAndNotHidden() && mPowerManager.isScreenOn()) {
- long curTime = SystemClock.uptimeMillis();
- mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT);
+ if (mPowerManager.isScreenOn()) {
+ if (!mKeyguardMediator.isShowingAndNotHidden()) {
+ long curTime = SystemClock.uptimeMillis();
+ mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT);
+ }
+
+ synchronized (mLock) {
+ // even if the keyguard is up, now that all the wakelocks have been released, we
+ // should re-enable the screen saver
+ mScreenSaverEnabled = true;
+ updateScreenSaverTimeoutLocked();
+ }
}
}