diff options
author | Daniel Sandler <dsandler@android.com> | 2011-05-26 06:01:41 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-05-26 06:01:41 -0700 |
commit | 8c1132e3ceed8e1a8c696e2afe0e6fe456ccd7ef (patch) | |
tree | 91476edcc4d1ce9b1a92acd45058a8ab33f1a1fb /policy | |
parent | 42c5a1666c4e576ccd5974233513100aad2c1534 (diff) | |
parent | 0601eb7953cbf77d92826bef3ca37e208d922de7 (diff) | |
download | frameworks_base-8c1132e3ceed8e1a8c696e2afe0e6fe456ccd7ef.zip frameworks_base-8c1132e3ceed8e1a8c696e2afe0e6fe456ccd7ef.tar.gz frameworks_base-8c1132e3ceed8e1a8c696e2afe0e6fe456ccd7ef.tar.bz2 |
Merge "Framework support for Android Dreams."
Diffstat (limited to 'policy')
-rwxr-xr-x | policy/src/com/android/internal/policy/impl/PhoneWindowManager.java | 94 |
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 e5abeac..e48dbe9 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); @@ -2603,6 +2615,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { mScreenOn = false; updateOrientationListenerLp(); updateLockScreenTimeout(); + updateScreenSaverTimeoutLocked(); } } @@ -2614,6 +2627,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { mScreenOn = true; updateOrientationListenerLp(); updateLockScreenTimeout(); + updateScreenSaverTimeoutLocked(); } } @@ -2894,6 +2908,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() { @@ -3089,10 +3160,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(); + } } } |