diff options
Diffstat (limited to 'services/java/com/android/server/PowerManagerService.java')
| -rw-r--r-- | services/java/com/android/server/PowerManagerService.java | 213 |
1 files changed, 127 insertions, 86 deletions
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index 444c8de..8584d74 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -59,6 +59,7 @@ import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN; import java.io.FileDescriptor; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; @@ -180,8 +181,12 @@ class PowerManagerService extends IPowerManager.Stub private final LockList mLocks = new LockList(); private Intent mScreenOffIntent; private Intent mScreenOnIntent; - private HardwareService mHardware; + private LightsService mLightsService; private Context mContext; + private LightsService.Light mLcdLight; + private LightsService.Light mButtonLight; + private LightsService.Light mKeyboardLight; + private LightsService.Light mAttentionLight; private UnsynchronizedWakeLock mBroadcastWakeLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInPartialLock; @@ -208,21 +213,20 @@ class PowerManagerService extends IPowerManager.Stub private boolean mLightSensorEnabled; private float mLightSensorValue = -1; private float mLightSensorPendingValue = -1; - private int mLightSensorBrightness = -1; + private int mLightSensorScreenBrightness = -1; + private int mLightSensorButtonBrightness = -1; + private int mLightSensorKeyboardBrightness = -1; private boolean mDimScreen = true; private long mNextTimeout; private volatile int mPokey = 0; private volatile boolean mPokeAwakeOnSet = false; private volatile boolean mInitComplete = false; private HashMap<IBinder,PokeLock> mPokeLocks = new HashMap<IBinder,PokeLock>(); - // mScreenOnTime and mScreenOnStartTime are used for computing total time screen - // has been on since boot - private long mScreenOnTime; - private long mScreenOnStartTime; // mLastScreenOnTime is the time the screen was last turned on private long mLastScreenOnTime; private boolean mPreventScreenOn; private int mScreenBrightnessOverride = -1; + private int mButtonBrightnessOverride = -1; private boolean mUseSoftwareAutoBrightness; private boolean mAutoBrightessEnabled; private int[] mAutoBrightnessLevels; @@ -416,19 +420,23 @@ class PowerManagerService extends IPowerManager.Stub // Add ourself to the Watchdog monitors. Watchdog.getInstance().addMonitor(this); - mScreenOnStartTime = SystemClock.elapsedRealtime(); } private ContentQueryMap mSettings; - void init(Context context, HardwareService hardware, IActivityManager activity, + void init(Context context, LightsService lights, IActivityManager activity, BatteryService battery) { - mHardware = hardware; + mLightsService = lights; mContext = context; mActivityService = activity; mBatteryStats = BatteryStatsService.getService(); mBatteryService = battery; + mLcdLight = lights.getLight(LightsService.LIGHT_ID_BACKLIGHT); + mButtonLight = lights.getLight(LightsService.LIGHT_ID_BUTTONS); + mKeyboardLight = lights.getLight(LightsService.LIGHT_ID_KEYBOARD); + mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION); + mHandlerThread = new HandlerThread("PowerManagerService") { @Override protected void onLooperPrepared() { @@ -923,7 +931,8 @@ class PowerManagerService extends IPowerManager.Stub pw.println(" mKeylightDelay=" + mKeylightDelay + " mDimDelay=" + mDimDelay + " mScreenOffDelay=" + mScreenOffDelay); pw.println(" mPreventScreenOn=" + mPreventScreenOn - + " mScreenBrightnessOverride=" + mScreenBrightnessOverride); + + " mScreenBrightnessOverride=" + mScreenBrightnessOverride + + " mButtonBrightnessOverride=" + mButtonBrightnessOverride); pw.println(" mTotalDelaySetting=" + mTotalDelaySetting); pw.println(" mLastScreenOnTime=" + mLastScreenOnTime); pw.println(" mBroadcastWakeLock=" + mBroadcastWakeLock); @@ -937,8 +946,11 @@ class PowerManagerService extends IPowerManager.Stub pw.println(" mProximityPendingValue=" + mProximityPendingValue); pw.println(" mLastProximityEventTime=" + mLastProximityEventTime); pw.println(" mLightSensorEnabled=" + mLightSensorEnabled); - pw.println(" mLightSensorValue=" + mLightSensorValue); - pw.println(" mLightSensorPendingValue=" + mLightSensorPendingValue); + pw.println(" mLightSensorValue=" + mLightSensorValue + + " mLightSensorPendingValue=" + mLightSensorPendingValue); + pw.println(" mLightSensorScreenBrightness=" + mLightSensorScreenBrightness + + " mLightSensorButtonBrightness=" + mLightSensorButtonBrightness + + " mLightSensorKeyboardBrightness=" + mLightSensorKeyboardBrightness); pw.println(" mUseSoftwareAutoBrightness=" + mUseSoftwareAutoBrightness); pw.println(" mAutoBrightessEnabled=" + mAutoBrightessEnabled); mScreenBrightness.dump(pw, " mScreenBrightness: "); @@ -1306,7 +1318,18 @@ class PowerManagerService extends IPowerManager.Stub } } } - + + public void setButtonBrightnessOverride(int brightness) { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); + + synchronized (mLocks) { + if (mButtonBrightnessOverride != brightness) { + mButtonBrightnessOverride = brightness; + updateLightsLocked(mPowerState, BUTTON_BRIGHT_BIT | KEYBOARD_BRIGHT_BIT); + } + } + } + /** * Sanity-check that gets called 5 seconds after any call to * preventScreenOn(true). This ensures that the original call @@ -1348,13 +1371,8 @@ class PowerManagerService extends IPowerManager.Stub enableLightSensor(on); if (!on) { // make sure button and key backlights are off too - int brightnessMode = (mUseSoftwareAutoBrightness - ? HardwareService.BRIGHTNESS_MODE_SENSOR - : HardwareService.BRIGHTNESS_MODE_USER); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, 0, - brightnessMode); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, 0, - brightnessMode); + mButtonLight.turnOff(); + mKeyboardLight.turnOff(); // clear current value so we will update based on the new conditions // when the sensor is reenabled. mLightSensorValue = -1; @@ -1455,8 +1473,7 @@ class PowerManagerService extends IPowerManager.Stub err = setScreenStateLocked(true); long identity = Binder.clearCallingIdentity(); try { - mBatteryStats.noteScreenBrightness( - getPreferredBrightness()); + mBatteryStats.noteScreenBrightness(getPreferredBrightness()); mBatteryStats.noteScreenOn(); } catch (RemoteException e) { Log.w(TAG, "RemoteException calling noteScreenOn on BatteryStatsService", e); @@ -1469,7 +1486,6 @@ class PowerManagerService extends IPowerManager.Stub err = 0; } - mScreenOnStartTime = SystemClock.elapsedRealtime(); mLastTouchDown = 0; mTotalTouchDownTime = 0; mTouchCycles = 0; @@ -1512,10 +1528,6 @@ class PowerManagerService extends IPowerManager.Stub mTotalTouchDownTime, mTouchCycles); mLastTouchDown = 0; int err = setScreenStateLocked(false); - if (mScreenOnStartTime != 0) { - mScreenOnTime += SystemClock.elapsedRealtime() - mScreenOnStartTime; - mScreenOnStartTime = 0; - } if (err == 0) { int why = becauseOfUser ? WindowManagerPolicy.OFF_BECAUSE_OF_USER @@ -1532,6 +1544,8 @@ class PowerManagerService extends IPowerManager.Stub private void updateLightsLocked(int newState, int forceState) { final int oldState = mPowerState; + newState = applyButtonState(newState); + newState = applyKeyboardState(newState); final int realDifference = (newState ^ oldState); final int difference = realDifference | forceState; if (difference == 0) { @@ -1550,9 +1564,9 @@ class PowerManagerService extends IPowerManager.Stub if ((newState & KEYBOARD_BRIGHT_BIT) == 0) { mKeyboardBrightness.setTargetLocked(Power.BRIGHTNESS_OFF, ANIM_STEPS, INITIAL_KEYBOARD_BRIGHTNESS, - preferredBrightness); + Power.BRIGHTNESS_ON); } else { - mKeyboardBrightness.setTargetLocked(preferredBrightness, + mKeyboardBrightness.setTargetLocked(Power.BRIGHTNESS_ON, ANIM_STEPS, INITIAL_KEYBOARD_BRIGHTNESS, Power.BRIGHTNESS_OFF); } @@ -1571,9 +1585,9 @@ class PowerManagerService extends IPowerManager.Stub if ((newState & BUTTON_BRIGHT_BIT) == 0) { mButtonBrightness.setTargetLocked(Power.BRIGHTNESS_OFF, ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS, - preferredBrightness); + Power.BRIGHTNESS_ON); } else { - mButtonBrightness.setTargetLocked(preferredBrightness, + mButtonBrightness.setTargetLocked(Power.BRIGHTNESS_ON, ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS, Power.BRIGHTNESS_OFF); } @@ -1710,22 +1724,16 @@ class PowerManagerService extends IPowerManager.Stub private void setLightBrightness(int mask, int value) { int brightnessMode = (mAutoBrightessEnabled - ? HardwareService.BRIGHTNESS_MODE_SENSOR - : HardwareService.BRIGHTNESS_MODE_USER); + ? LightsService.BRIGHTNESS_MODE_SENSOR + : LightsService.BRIGHTNESS_MODE_USER); if ((mask & SCREEN_BRIGHT_BIT) != 0) { - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, value, - brightnessMode); + mLcdLight.setBrightness(value, brightnessMode); } - brightnessMode = (mUseSoftwareAutoBrightness - ? HardwareService.BRIGHTNESS_MODE_SENSOR - : HardwareService.BRIGHTNESS_MODE_USER); if ((mask & BUTTON_BRIGHT_BIT) != 0) { - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, value, - brightnessMode); + mButtonLight.setBrightness(value); } if ((mask & KEYBOARD_BRIGHT_BIT) != 0) { - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, value, - brightnessMode); + mKeyboardLight.setBrightness(value); } } @@ -1829,9 +1837,9 @@ class PowerManagerService extends IPowerManager.Stub try { if (mScreenBrightnessOverride >= 0) { return mScreenBrightnessOverride; - } else if (mLightSensorBrightness >= 0 && mUseSoftwareAutoBrightness + } else if (mLightSensorScreenBrightness >= 0 && mUseSoftwareAutoBrightness && mAutoBrightessEnabled) { - return mLightSensorBrightness; + return mLightSensorScreenBrightness; } final int brightness = Settings.System.getInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS); @@ -1842,6 +1850,40 @@ class PowerManagerService extends IPowerManager.Stub } } + private int applyButtonState(int state) { + int brightness = -1; + if (mButtonBrightnessOverride >= 0) { + brightness = mButtonBrightnessOverride; + } else if (mLightSensorButtonBrightness >= 0 && mUseSoftwareAutoBrightness) { + brightness = mLightSensorButtonBrightness; + } + if (brightness > 0) { + return state | BUTTON_BRIGHT_BIT; + } else if (brightness == 0) { + return state & ~BUTTON_BRIGHT_BIT; + } else { + return state; + } + } + + private int applyKeyboardState(int state) { + int brightness = -1; + if (!mKeyboardVisible) { + brightness = 0; + } else if (mButtonBrightnessOverride >= 0) { + brightness = mButtonBrightnessOverride; + } else if (mLightSensorKeyboardBrightness >= 0 && mUseSoftwareAutoBrightness) { + brightness = mLightSensorKeyboardBrightness; + } + if (brightness > 0) { + return state | KEYBOARD_BRIGHT_BIT; + } else if (brightness == 0) { + return state & ~KEYBOARD_BRIGHT_BIT; + } else { + return state; + } + } + public boolean isScreenOn() { synchronized (mLocks) { return (mPowerState & SCREEN_ON_BIT) != 0; @@ -2017,7 +2059,9 @@ class PowerManagerService extends IPowerManager.Stub } else { keyboardValue = 0; } - mLightSensorBrightness = lcdValue; + mLightSensorScreenBrightness = lcdValue; + mLightSensorButtonBrightness = buttonValue; + mLightSensorKeyboardBrightness = keyboardValue; if (mDebugLightSensor) { Log.d(TAG, "lcdValue " + lcdValue); @@ -2035,37 +2079,32 @@ class PowerManagerService extends IPowerManager.Stub } } else { int brightnessMode = (mAutoBrightessEnabled - ? HardwareService.BRIGHTNESS_MODE_SENSOR - : HardwareService.BRIGHTNESS_MODE_USER); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, - lcdValue, brightnessMode); + ? LightsService.BRIGHTNESS_MODE_SENSOR + : LightsService.BRIGHTNESS_MODE_USER); + mLcdLight.setBrightness(lcdValue, brightnessMode); } } - if (ANIMATE_BUTTON_LIGHTS) { - if (mButtonBrightness.setTargetLocked(buttonValue, - AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS, - (int)mButtonBrightness.curValue)) { - startAnimation = true; + if (mButtonBrightnessOverride < 0) { + if (ANIMATE_BUTTON_LIGHTS) { + if (mButtonBrightness.setTargetLocked(buttonValue, + AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS, + (int)mButtonBrightness.curValue)) { + startAnimation = true; + } + } else { + mButtonLight.setBrightness(buttonValue); } - } else { - int brightnessMode = (mUseSoftwareAutoBrightness - ? HardwareService.BRIGHTNESS_MODE_SENSOR - : HardwareService.BRIGHTNESS_MODE_USER); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, - buttonValue, brightnessMode); } - if (ANIMATE_KEYBOARD_LIGHTS) { - if (mKeyboardBrightness.setTargetLocked(keyboardValue, - AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS, - (int)mKeyboardBrightness.curValue)) { - startAnimation = true; + if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) { + if (ANIMATE_KEYBOARD_LIGHTS) { + if (mKeyboardBrightness.setTargetLocked(keyboardValue, + AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS, + (int)mKeyboardBrightness.curValue)) { + startAnimation = true; + } + } else { + mKeyboardLight.setBrightness(keyboardValue); } - } else { - int brightnessMode = (mUseSoftwareAutoBrightness - ? HardwareService.BRIGHTNESS_MODE_SENSOR - : HardwareService.BRIGHTNESS_MODE_USER); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, - keyboardValue, brightnessMode); } if (startAnimation) { if (mDebugLightSensor) { @@ -2091,16 +2130,16 @@ class PowerManagerService extends IPowerManager.Stub } /** - * Returns the time the screen has been on since boot, in millis. - * @return screen on time + * Reboot the device immediately, passing 'reason' (may be null) + * to the underlying __reboot system call. Should not return. */ - public long getScreenOnTime() { - synchronized (mLocks) { - if (mScreenOnStartTime == 0) { - return mScreenOnTime; - } else { - return SystemClock.elapsedRealtime() - mScreenOnStartTime + mScreenOnTime; - } + public void reboot(String reason) + { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); + try { + Power.reboot(reason); + } catch (IOException e) { + Log.e(TAG, "reboot failed", e); } } @@ -2393,12 +2432,9 @@ class PowerManagerService extends IPowerManager.Stub mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); // Don't let applications turn the screen all the way off brightness = Math.max(brightness, Power.BRIGHTNESS_DIM); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BACKLIGHT, brightness, - HardwareService.BRIGHTNESS_MODE_USER); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_KEYBOARD, - (mKeyboardVisible ? brightness : 0), HardwareService.BRIGHTNESS_MODE_USER); - mHardware.setLightBrightness_UNCHECKED(HardwareService.LIGHT_ID_BUTTONS, brightness, - HardwareService.BRIGHTNESS_MODE_USER); + mLcdLight.setBrightness(brightness); + mKeyboardLight.setBrightness(mKeyboardVisible ? brightness : 0); + mButtonLight.setBrightness(brightness); long identity = Binder.clearCallingIdentity(); try { mBatteryStats.noteScreenBrightness(brightness); @@ -2426,6 +2462,11 @@ class PowerManagerService extends IPowerManager.Stub } } + public void setAttentionLight(boolean on, int color) { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); + mAttentionLight.setFlashing(color, LightsService.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0); + } + private void enableProximityLockLocked() { if (mDebugProximitySensor) { Log.d(TAG, "enableProximityLockLocked"); |
