|
39 | 39 | import android.graphics.PixelFormat; |
40 | 40 | import android.graphics.Rect; |
41 | 41 | import android.graphics.RectF; |
| 42 | +import android.os.BatteryManager; |
42 | 43 | import android.os.Binder; |
43 | 44 | import android.os.Bundle; |
44 | 45 | import android.os.Handler; |
@@ -162,6 +163,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { |
162 | 163 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
163 | 164 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
164 | 165 |
|
| 166 | + // Should screen savers use their own timeout, or the SCREEN_OFF_TIMEOUT? |
| 167 | + static final boolean SEPARATE_TIMEOUT_FOR_SCREEN_SAVER = false; |
| 168 | + |
165 | 169 | static final int LONG_PRESS_POWER_NOTHING = 0; |
166 | 170 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
167 | 171 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
@@ -397,6 +401,7 @@ public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finished |
397 | 401 | // visual screen saver support |
398 | 402 | int mScreenSaverTimeout = 0; |
399 | 403 | boolean mScreenSaverEnabled = true; |
| 404 | + boolean mPluggedIn; |
400 | 405 |
|
401 | 406 | // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.) |
402 | 407 | int mEndcallBehavior; |
@@ -460,8 +465,10 @@ void observe() { |
460 | 465 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
461 | 466 | resolver.registerContentObserver(Settings.System.getUriFor( |
462 | 467 | "fancy_rotation_anim"), false, this); |
463 | | - resolver.registerContentObserver(Settings.Secure.getUriFor( |
464 | | - Settings.Secure.DREAM_TIMEOUT), false, this); |
| 468 | + if (SEPARATE_TIMEOUT_FOR_SCREEN_SAVER) { |
| 469 | + resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 470 | + Settings.Secure.DREAM_TIMEOUT), false, this); |
| 471 | + } // otherwise SCREEN_OFF_TIMEOUT will do nicely |
465 | 472 | updateSettings(); |
466 | 473 | } |
467 | 474 |
|
@@ -768,6 +775,15 @@ public void init(Context context, IWindowManager windowManager, |
768 | 775 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
769 | 776 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
770 | 777 | } |
| 778 | + |
| 779 | + // watch the plug to know whether to trigger the screen saver |
| 780 | + filter = new IntentFilter(); |
| 781 | + filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 782 | + intent = context.registerReceiver(mPowerReceiver, filter); |
| 783 | + if (intent != null) { |
| 784 | + mPluggedIn = (0 != intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0)); |
| 785 | + } |
| 786 | + |
771 | 787 | mVibrator = new Vibrator(); |
772 | 788 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
773 | 789 | com.android.internal.R.array.config_longPressVibePattern); |
@@ -917,8 +933,18 @@ public void updateSettings() { |
917 | 933 | updateRotation = true; |
918 | 934 | } |
919 | 935 |
|
920 | | - mScreenSaverTimeout = Settings.Secure.getInt(resolver, |
921 | | - Settings.Secure.DREAM_TIMEOUT, 0); |
| 936 | + if (SEPARATE_TIMEOUT_FOR_SCREEN_SAVER) { |
| 937 | + mScreenSaverTimeout = Settings.Secure.getInt(resolver, |
| 938 | + Settings.Secure.DREAM_TIMEOUT, 0); |
| 939 | + } else { |
| 940 | + mScreenSaverTimeout = Settings.System.getInt(resolver, |
| 941 | + Settings.System.SCREEN_OFF_TIMEOUT, 0); |
| 942 | + if (mScreenSaverTimeout > 0) { |
| 943 | + // We actually want to activate the screensaver just before the |
| 944 | + // power manager's screen timeout |
| 945 | + mScreenSaverTimeout -= 5000; |
| 946 | + } |
| 947 | + } |
922 | 948 | updateScreenSaverTimeoutLocked(); |
923 | 949 | } |
924 | 950 | if (updateRotation) { |
@@ -2954,6 +2980,15 @@ public void onReceive(Context context, Intent intent) { |
2954 | 2980 | } |
2955 | 2981 | }; |
2956 | 2982 |
|
| 2983 | + BroadcastReceiver mPowerReceiver = new BroadcastReceiver() { |
| 2984 | + public void onReceive(Context context, Intent intent) { |
| 2985 | + if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { |
| 2986 | + mPluggedIn = (0 != intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0)); |
| 2987 | + if (localLOGV) Log.v(TAG, "BATTERY_CHANGED: " + intent + " plugged=" + mPluggedIn); |
| 2988 | + } |
| 2989 | + } |
| 2990 | + }; |
| 2991 | + |
2957 | 2992 | /** {@inheritDoc} */ |
2958 | 2993 | public void screenTurnedOff(int why) { |
2959 | 2994 | EventLog.writeEvent(70000, 0); |
@@ -3420,8 +3455,13 @@ public void run() { |
3420 | 3455 | Log.w(TAG, "mScreenSaverActivator ran, but the screensaver should not be showing. Who's driving this thing?"); |
3421 | 3456 | return; |
3422 | 3457 | } |
| 3458 | + if (!mPluggedIn) { |
| 3459 | + if (localLOGV) Log.v(TAG, "mScreenSaverActivator: not running screen saver when not plugged in"); |
| 3460 | + return; |
| 3461 | + } |
3423 | 3462 |
|
3424 | 3463 | if (localLOGV) Log.v(TAG, "mScreenSaverActivator entering dreamland"); |
| 3464 | + |
3425 | 3465 | try { |
3426 | 3466 | String component = Settings.Secure.getString( |
3427 | 3467 | mContext.getContentResolver(), Settings.Secure.DREAM_COMPONENT); |
|
0 commit comments