Loading services/java/com/android/server/LightsService.java +80 −55 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,9 @@ public class LightsService { static final int LIGHT_ID_BATTERY = 3; static final int LIGHT_ID_BATTERY = 3; static final int LIGHT_ID_NOTIFICATIONS = 4; static final int LIGHT_ID_NOTIFICATIONS = 4; static final int LIGHT_ID_ATTENTION = 5; static final int LIGHT_ID_ATTENTION = 5; static final int LIGHT_ID_BLUETOOTH = 6; static final int LIGHT_ID_WIFI = 7; static final int LIGHT_ID_COUNT = 8; static final int LIGHT_FLASH_NONE = 0; static final int LIGHT_FLASH_NONE = 0; static final int LIGHT_FLASH_TIMED = 1; static final int LIGHT_FLASH_TIMED = 1; Loading @@ -45,79 +48,101 @@ public class LightsService { */ */ static final int BRIGHTNESS_MODE_SENSOR = 1; static final int BRIGHTNESS_MODE_SENSOR = 1; private boolean mAttentionLightOn; private final Light mLights[] = new Light[LIGHT_ID_COUNT]; private boolean mPulsing; LightsService(Context context) { public final class Light { mNativePointer = init_native(); private Light(int id) { mContext = context; mId = id; } } protected void finalize() throws Throwable { public void setBrightness(int brightness) { finalize_native(mNativePointer); setBrightness(brightness, BRIGHTNESS_MODE_USER); super.finalize(); } } void setLightOff(int light) { public void setBrightness(int brightness, int brightnessMode) { setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0, 0); synchronized (this) { int color = brightness & 0x000000ff; color = 0xff000000 | (color << 16) | (color << 8) | color; setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode); } } } void setLightBrightness(int light, int brightness, int brightnessMode) { public void setColor(int color) { int b = brightness & 0x000000ff; synchronized (this) { b = 0xff000000 | (b << 16) | (b << 8) | b; setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, 0); setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0, brightnessMode); } } } void setLightColor(int light, int color) { public void setFlashing(int color, int mode, int onMS, int offMS) { setLight_native(mNativePointer, light, color, LIGHT_FLASH_NONE, 0, 0, 0); synchronized (this) { setLightLocked(color, mode, onMS, offMS, BRIGHTNESS_MODE_USER); } } } void setLightFlashing(int light, int color, int mode, int onMS, int offMS) { public void pulse() { setLight_native(mNativePointer, light, color, mode, onMS, offMS, 0); synchronized (this) { if (mColor == 0 && !mFlashing) { setLightLocked(0x00ffffff, LIGHT_FLASH_HARDWARE, 7, 0, BRIGHTNESS_MODE_USER); mH.sendMessageDelayed(Message.obtain(mH, 1, this), 3000); } } } } public void setAttentionLight(boolean on, int color) { public void turnOff() { // Not worthy of a permission. We shouldn't have a flashlight permission. synchronized (this) { synchronized (this) { mAttentionLightOn = on; setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, 0); mPulsing = false; setLight_native(mNativePointer, LIGHT_ID_ATTENTION, color, LIGHT_FLASH_HARDWARE, on ? 3 : 0, 0, 0); } } } } public void pulseBreathingLight() { private void stopFlashing() { synchronized (this) { synchronized (this) { // HACK: Added at the last minute of cupcake -- design this better; setLightLocked(mColor, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_USER); // Don't reuse the attention light -- make another one. if (false) { Log.d(TAG, "pulseBreathingLight mAttentionLightOn=" + mAttentionLightOn + " mPulsing=" + mPulsing); } } if (!mAttentionLightOn && !mPulsing) { mPulsing = true; setLight_native(mNativePointer, LIGHT_ID_ATTENTION, 0x00ffffff, LIGHT_FLASH_HARDWARE, 7, 0, 0); mH.sendMessageDelayed(Message.obtain(mH, 1), 3000); } } private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) { if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) { mColor = color; mMode = mode; mOnMS = onMS; mOffMS = offMS; setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode); } } } } private Handler mH = new Handler() { private int mId; @Override private int mColor; public void handleMessage(Message msg) { private int mMode; synchronized (this) { private int mOnMS; if (false) { private int mOffMS; Log.d(TAG, "pulse cleanup handler firing mPulsing=" + mPulsing); private boolean mFlashing; } LightsService(Context context) { mNativePointer = init_native(); mContext = context; for (int i = 0; i < LIGHT_ID_COUNT; i++) { mLights[i] = new Light(i); } } } if (mPulsing) { mPulsing = false; protected void finalize() throws Throwable { setLight_native(mNativePointer, LIGHT_ID_ATTENTION, finalize_native(mNativePointer); mAttentionLightOn ? 0xffffffff : 0, super.finalize(); LIGHT_FLASH_NONE, 0, 0, 0); } } public Light getLight(int id) { return mLights[id]; } } private Handler mH = new Handler() { @Override public void handleMessage(Message msg) { Light light = (Light)msg.obj; light.stopFlashing(); } } }; }; Loading services/java/com/android/server/NotificationManagerService.java +16 −14 Original line number Original line Diff line number Diff line Loading @@ -87,6 +87,9 @@ class NotificationManagerService extends INotificationManager.Stub private WorkerHandler mHandler; private WorkerHandler mHandler; private StatusBarService mStatusBarService; private StatusBarService mStatusBarService; private LightsService mLightsService; private LightsService mLightsService; private LightsService.Light mBatteryLight; private LightsService.Light mNotificationLight; private LightsService.Light mAttentionLight; private NotificationRecord mSoundNotification; private NotificationRecord mSoundNotification; private AsyncPlayer mSound; private AsyncPlayer mSound; Loading Loading @@ -376,6 +379,10 @@ class NotificationManagerService extends INotificationManager.Stub mStatusBarService = statusBar; mStatusBarService = statusBar; statusBar.setNotificationCallbacks(mNotificationCallbacks); statusBar.setNotificationCallbacks(mNotificationCallbacks); mBatteryLight = lights.getLight(LightsService.LIGHT_ID_BATTERY); mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS); mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION); // Don't start allowing notifications until the setup wizard has run once. // Don't start allowing notifications until the setup wizard has run once. // After that, including subsequent boots, init with notifications turned on. // After that, including subsequent boots, init with notifications turned on. // This works on the first boot because the setup wizard will toggle this // This works on the first boot because the setup wizard will toggle this Loading Loading @@ -678,7 +685,7 @@ class NotificationManagerService extends INotificationManager.Stub long identity = Binder.clearCallingIdentity(); long identity = Binder.clearCallingIdentity(); try { try { r.statusBarKey = mStatusBarService.addIcon(icon, n); r.statusBarKey = mStatusBarService.addIcon(icon, n); mLightsService.pulseBreathingLight(); mAttentionLight.pulse(); } } finally { finally { Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity); Loading Loading @@ -969,24 +976,20 @@ class NotificationManagerService extends INotificationManager.Stub // Battery low always shows, other states only show if charging. // Battery low always shows, other states only show if charging. if (mBatteryLow) { if (mBatteryLow) { if (mBatteryCharging) { if (mBatteryCharging) { mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setColor(BATTERY_LOW_ARGB); BATTERY_LOW_ARGB); } else { } else { // Flash when battery is low and not charging // Flash when battery is low and not charging mLightsService.setLightFlashing(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setFlashing(BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED, BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED, BATTERY_BLINK_ON, BATTERY_BLINK_OFF); BATTERY_BLINK_ON, BATTERY_BLINK_OFF); } } } else if (mBatteryCharging) { } else if (mBatteryCharging) { if (mBatteryFull) { if (mBatteryFull) { mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setColor(BATTERY_FULL_ARGB); BATTERY_FULL_ARGB); } else { } else { mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setColor(BATTERY_MEDIUM_ARGB); BATTERY_MEDIUM_ARGB); } } } else { } else { mLightsService.setLightOff(LightsService.LIGHT_ID_BATTERY); mBatteryLight.turnOff(); } } // handle notification lights // handle notification lights Loading @@ -998,10 +1001,9 @@ class NotificationManagerService extends INotificationManager.Stub } } } } if (mLedNotification == null) { if (mLedNotification == null) { mLightsService.setLightOff(LightsService.LIGHT_ID_NOTIFICATIONS); mNotificationLight.turnOff(); } else { } else { mLightsService.setLightFlashing( mNotificationLight.setFlashing( LightsService.LIGHT_ID_NOTIFICATIONS, mLedNotification.notification.ledARGB, mLedNotification.notification.ledARGB, LightsService.LIGHT_FLASH_TIMED, LightsService.LIGHT_FLASH_TIMED, mLedNotification.notification.ledOnMS, mLedNotification.notification.ledOnMS, Loading services/java/com/android/server/PowerManagerService.java +21 −35 Original line number Original line Diff line number Diff line Loading @@ -183,6 +183,10 @@ class PowerManagerService extends IPowerManager.Stub private Intent mScreenOnIntent; private Intent mScreenOnIntent; private LightsService mLightsService; private LightsService mLightsService; private Context mContext; private Context mContext; private LightsService.Light mLcdLight; private LightsService.Light mButtonLight; private LightsService.Light mKeyboardLight; private LightsService.Light mAttentionLight; private UnsynchronizedWakeLock mBroadcastWakeLock; private UnsynchronizedWakeLock mBroadcastWakeLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInPartialLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInPartialLock; Loading Loading @@ -428,6 +432,11 @@ class PowerManagerService extends IPowerManager.Stub mBatteryStats = BatteryStatsService.getService(); mBatteryStats = BatteryStatsService.getService(); mBatteryService = battery; 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") { mHandlerThread = new HandlerThread("PowerManagerService") { @Override @Override protected void onLooperPrepared() { protected void onLooperPrepared() { Loading Loading @@ -1362,13 +1371,8 @@ class PowerManagerService extends IPowerManager.Stub enableLightSensor(on); enableLightSensor(on); if (!on) { if (!on) { // make sure button and key backlights are off too // make sure button and key backlights are off too int brightnessMode = (mUseSoftwareAutoBrightness mButtonLight.turnOff(); ? LightsService.BRIGHTNESS_MODE_SENSOR mKeyboardLight.turnOff(); : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, 0, brightnessMode); mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, 0, brightnessMode); // clear current value so we will update based on the new conditions // clear current value so we will update based on the new conditions // when the sensor is reenabled. // when the sensor is reenabled. mLightSensorValue = -1; mLightSensorValue = -1; Loading Loading @@ -1723,19 +1727,13 @@ class PowerManagerService extends IPowerManager.Stub ? LightsService.BRIGHTNESS_MODE_SENSOR ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); : LightsService.BRIGHTNESS_MODE_USER); if ((mask & SCREEN_BRIGHT_BIT) != 0) { if ((mask & SCREEN_BRIGHT_BIT) != 0) { mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, value, mLcdLight.setBrightness(value, brightnessMode); brightnessMode); } } brightnessMode = (mUseSoftwareAutoBrightness ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); if ((mask & BUTTON_BRIGHT_BIT) != 0) { if ((mask & BUTTON_BRIGHT_BIT) != 0) { mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, value, mButtonLight.setBrightness(value); brightnessMode); } } if ((mask & KEYBOARD_BRIGHT_BIT) != 0) { if ((mask & KEYBOARD_BRIGHT_BIT) != 0) { mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, value, mKeyboardLight.setBrightness(value); brightnessMode); } } } } Loading Loading @@ -2083,8 +2081,7 @@ class PowerManagerService extends IPowerManager.Stub int brightnessMode = (mAutoBrightessEnabled int brightnessMode = (mAutoBrightessEnabled ? LightsService.BRIGHTNESS_MODE_SENSOR ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, mLcdLight.setBrightness(lcdValue, brightnessMode); lcdValue, brightnessMode); } } } } if (mButtonBrightnessOverride < 0) { if (mButtonBrightnessOverride < 0) { Loading @@ -2095,11 +2092,7 @@ class PowerManagerService extends IPowerManager.Stub startAnimation = true; startAnimation = true; } } } else { } else { int brightnessMode = (mUseSoftwareAutoBrightness mButtonLight.setBrightness(buttonValue); ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, buttonValue, brightnessMode); } } } } if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) { if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) { Loading @@ -2110,11 +2103,7 @@ class PowerManagerService extends IPowerManager.Stub startAnimation = true; startAnimation = true; } } } else { } else { int brightnessMode = (mUseSoftwareAutoBrightness mKeyboardLight.setBrightness(keyboardValue); ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, keyboardValue, brightnessMode); } } } } if (startAnimation) { if (startAnimation) { Loading Loading @@ -2443,12 +2432,9 @@ class PowerManagerService extends IPowerManager.Stub mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); // Don't let applications turn the screen all the way off // Don't let applications turn the screen all the way off brightness = Math.max(brightness, Power.BRIGHTNESS_DIM); brightness = Math.max(brightness, Power.BRIGHTNESS_DIM); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, brightness, mLcdLight.setBrightness(brightness); LightsService.BRIGHTNESS_MODE_USER); mKeyboardLight.setBrightness(mKeyboardVisible ? brightness : 0); mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, mButtonLight.setBrightness(brightness); (mKeyboardVisible ? brightness : 0), LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, brightness, LightsService.BRIGHTNESS_MODE_USER); long identity = Binder.clearCallingIdentity(); long identity = Binder.clearCallingIdentity(); try { try { mBatteryStats.noteScreenBrightness(brightness); mBatteryStats.noteScreenBrightness(brightness); Loading Loading @@ -2478,7 +2464,7 @@ class PowerManagerService extends IPowerManager.Stub public void setAttentionLight(boolean on, int color) { public void setAttentionLight(boolean on, int color) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); mLightsService.setAttentionLight(on, color); mAttentionLight.setFlashing(color, LightsService.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0); } } private void enableProximityLockLocked() { private void enableProximityLockLocked() { Loading services/jni/com_android_server_LightsService.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,8 @@ enum { LIGHT_INDEX_BATTERY = 3, LIGHT_INDEX_BATTERY = 3, LIGHT_INDEX_NOTIFICATIONS = 4, LIGHT_INDEX_NOTIFICATIONS = 4, LIGHT_INDEX_ATTENTION = 5, LIGHT_INDEX_ATTENTION = 5, LIGHT_INDEX_BLUETOOTH = 6, LIGHT_INDEX_WIFI = 7, LIGHT_COUNT LIGHT_COUNT }; }; Loading Loading @@ -80,6 +82,10 @@ static jint init_native(JNIEnv *env, jobject clazz) = get_device(module, LIGHT_ID_NOTIFICATIONS); = get_device(module, LIGHT_ID_NOTIFICATIONS); devices->lights[LIGHT_INDEX_ATTENTION] devices->lights[LIGHT_INDEX_ATTENTION] = get_device(module, LIGHT_ID_ATTENTION); = get_device(module, LIGHT_ID_ATTENTION); devices->lights[LIGHT_INDEX_BLUETOOTH] = get_device(module, LIGHT_ID_BLUETOOTH); devices->lights[LIGHT_INDEX_WIFI] = get_device(module, LIGHT_ID_WIFI); } else { } else { memset(devices, 0, sizeof(Devices)); memset(devices, 0, sizeof(Devices)); } } Loading Loading
services/java/com/android/server/LightsService.java +80 −55 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,9 @@ public class LightsService { static final int LIGHT_ID_BATTERY = 3; static final int LIGHT_ID_BATTERY = 3; static final int LIGHT_ID_NOTIFICATIONS = 4; static final int LIGHT_ID_NOTIFICATIONS = 4; static final int LIGHT_ID_ATTENTION = 5; static final int LIGHT_ID_ATTENTION = 5; static final int LIGHT_ID_BLUETOOTH = 6; static final int LIGHT_ID_WIFI = 7; static final int LIGHT_ID_COUNT = 8; static final int LIGHT_FLASH_NONE = 0; static final int LIGHT_FLASH_NONE = 0; static final int LIGHT_FLASH_TIMED = 1; static final int LIGHT_FLASH_TIMED = 1; Loading @@ -45,79 +48,101 @@ public class LightsService { */ */ static final int BRIGHTNESS_MODE_SENSOR = 1; static final int BRIGHTNESS_MODE_SENSOR = 1; private boolean mAttentionLightOn; private final Light mLights[] = new Light[LIGHT_ID_COUNT]; private boolean mPulsing; LightsService(Context context) { public final class Light { mNativePointer = init_native(); private Light(int id) { mContext = context; mId = id; } } protected void finalize() throws Throwable { public void setBrightness(int brightness) { finalize_native(mNativePointer); setBrightness(brightness, BRIGHTNESS_MODE_USER); super.finalize(); } } void setLightOff(int light) { public void setBrightness(int brightness, int brightnessMode) { setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0, 0); synchronized (this) { int color = brightness & 0x000000ff; color = 0xff000000 | (color << 16) | (color << 8) | color; setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode); } } } void setLightBrightness(int light, int brightness, int brightnessMode) { public void setColor(int color) { int b = brightness & 0x000000ff; synchronized (this) { b = 0xff000000 | (b << 16) | (b << 8) | b; setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, 0); setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0, brightnessMode); } } } void setLightColor(int light, int color) { public void setFlashing(int color, int mode, int onMS, int offMS) { setLight_native(mNativePointer, light, color, LIGHT_FLASH_NONE, 0, 0, 0); synchronized (this) { setLightLocked(color, mode, onMS, offMS, BRIGHTNESS_MODE_USER); } } } void setLightFlashing(int light, int color, int mode, int onMS, int offMS) { public void pulse() { setLight_native(mNativePointer, light, color, mode, onMS, offMS, 0); synchronized (this) { if (mColor == 0 && !mFlashing) { setLightLocked(0x00ffffff, LIGHT_FLASH_HARDWARE, 7, 0, BRIGHTNESS_MODE_USER); mH.sendMessageDelayed(Message.obtain(mH, 1, this), 3000); } } } } public void setAttentionLight(boolean on, int color) { public void turnOff() { // Not worthy of a permission. We shouldn't have a flashlight permission. synchronized (this) { synchronized (this) { mAttentionLightOn = on; setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, 0); mPulsing = false; setLight_native(mNativePointer, LIGHT_ID_ATTENTION, color, LIGHT_FLASH_HARDWARE, on ? 3 : 0, 0, 0); } } } } public void pulseBreathingLight() { private void stopFlashing() { synchronized (this) { synchronized (this) { // HACK: Added at the last minute of cupcake -- design this better; setLightLocked(mColor, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_USER); // Don't reuse the attention light -- make another one. if (false) { Log.d(TAG, "pulseBreathingLight mAttentionLightOn=" + mAttentionLightOn + " mPulsing=" + mPulsing); } } if (!mAttentionLightOn && !mPulsing) { mPulsing = true; setLight_native(mNativePointer, LIGHT_ID_ATTENTION, 0x00ffffff, LIGHT_FLASH_HARDWARE, 7, 0, 0); mH.sendMessageDelayed(Message.obtain(mH, 1), 3000); } } private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) { if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) { mColor = color; mMode = mode; mOnMS = onMS; mOffMS = offMS; setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode); } } } } private Handler mH = new Handler() { private int mId; @Override private int mColor; public void handleMessage(Message msg) { private int mMode; synchronized (this) { private int mOnMS; if (false) { private int mOffMS; Log.d(TAG, "pulse cleanup handler firing mPulsing=" + mPulsing); private boolean mFlashing; } LightsService(Context context) { mNativePointer = init_native(); mContext = context; for (int i = 0; i < LIGHT_ID_COUNT; i++) { mLights[i] = new Light(i); } } } if (mPulsing) { mPulsing = false; protected void finalize() throws Throwable { setLight_native(mNativePointer, LIGHT_ID_ATTENTION, finalize_native(mNativePointer); mAttentionLightOn ? 0xffffffff : 0, super.finalize(); LIGHT_FLASH_NONE, 0, 0, 0); } } public Light getLight(int id) { return mLights[id]; } } private Handler mH = new Handler() { @Override public void handleMessage(Message msg) { Light light = (Light)msg.obj; light.stopFlashing(); } } }; }; Loading
services/java/com/android/server/NotificationManagerService.java +16 −14 Original line number Original line Diff line number Diff line Loading @@ -87,6 +87,9 @@ class NotificationManagerService extends INotificationManager.Stub private WorkerHandler mHandler; private WorkerHandler mHandler; private StatusBarService mStatusBarService; private StatusBarService mStatusBarService; private LightsService mLightsService; private LightsService mLightsService; private LightsService.Light mBatteryLight; private LightsService.Light mNotificationLight; private LightsService.Light mAttentionLight; private NotificationRecord mSoundNotification; private NotificationRecord mSoundNotification; private AsyncPlayer mSound; private AsyncPlayer mSound; Loading Loading @@ -376,6 +379,10 @@ class NotificationManagerService extends INotificationManager.Stub mStatusBarService = statusBar; mStatusBarService = statusBar; statusBar.setNotificationCallbacks(mNotificationCallbacks); statusBar.setNotificationCallbacks(mNotificationCallbacks); mBatteryLight = lights.getLight(LightsService.LIGHT_ID_BATTERY); mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS); mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION); // Don't start allowing notifications until the setup wizard has run once. // Don't start allowing notifications until the setup wizard has run once. // After that, including subsequent boots, init with notifications turned on. // After that, including subsequent boots, init with notifications turned on. // This works on the first boot because the setup wizard will toggle this // This works on the first boot because the setup wizard will toggle this Loading Loading @@ -678,7 +685,7 @@ class NotificationManagerService extends INotificationManager.Stub long identity = Binder.clearCallingIdentity(); long identity = Binder.clearCallingIdentity(); try { try { r.statusBarKey = mStatusBarService.addIcon(icon, n); r.statusBarKey = mStatusBarService.addIcon(icon, n); mLightsService.pulseBreathingLight(); mAttentionLight.pulse(); } } finally { finally { Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity); Loading Loading @@ -969,24 +976,20 @@ class NotificationManagerService extends INotificationManager.Stub // Battery low always shows, other states only show if charging. // Battery low always shows, other states only show if charging. if (mBatteryLow) { if (mBatteryLow) { if (mBatteryCharging) { if (mBatteryCharging) { mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setColor(BATTERY_LOW_ARGB); BATTERY_LOW_ARGB); } else { } else { // Flash when battery is low and not charging // Flash when battery is low and not charging mLightsService.setLightFlashing(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setFlashing(BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED, BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED, BATTERY_BLINK_ON, BATTERY_BLINK_OFF); BATTERY_BLINK_ON, BATTERY_BLINK_OFF); } } } else if (mBatteryCharging) { } else if (mBatteryCharging) { if (mBatteryFull) { if (mBatteryFull) { mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setColor(BATTERY_FULL_ARGB); BATTERY_FULL_ARGB); } else { } else { mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY, mBatteryLight.setColor(BATTERY_MEDIUM_ARGB); BATTERY_MEDIUM_ARGB); } } } else { } else { mLightsService.setLightOff(LightsService.LIGHT_ID_BATTERY); mBatteryLight.turnOff(); } } // handle notification lights // handle notification lights Loading @@ -998,10 +1001,9 @@ class NotificationManagerService extends INotificationManager.Stub } } } } if (mLedNotification == null) { if (mLedNotification == null) { mLightsService.setLightOff(LightsService.LIGHT_ID_NOTIFICATIONS); mNotificationLight.turnOff(); } else { } else { mLightsService.setLightFlashing( mNotificationLight.setFlashing( LightsService.LIGHT_ID_NOTIFICATIONS, mLedNotification.notification.ledARGB, mLedNotification.notification.ledARGB, LightsService.LIGHT_FLASH_TIMED, LightsService.LIGHT_FLASH_TIMED, mLedNotification.notification.ledOnMS, mLedNotification.notification.ledOnMS, Loading
services/java/com/android/server/PowerManagerService.java +21 −35 Original line number Original line Diff line number Diff line Loading @@ -183,6 +183,10 @@ class PowerManagerService extends IPowerManager.Stub private Intent mScreenOnIntent; private Intent mScreenOnIntent; private LightsService mLightsService; private LightsService mLightsService; private Context mContext; private Context mContext; private LightsService.Light mLcdLight; private LightsService.Light mButtonLight; private LightsService.Light mKeyboardLight; private LightsService.Light mAttentionLight; private UnsynchronizedWakeLock mBroadcastWakeLock; private UnsynchronizedWakeLock mBroadcastWakeLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInScreenDimLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInPartialLock; private UnsynchronizedWakeLock mStayOnWhilePluggedInPartialLock; Loading Loading @@ -428,6 +432,11 @@ class PowerManagerService extends IPowerManager.Stub mBatteryStats = BatteryStatsService.getService(); mBatteryStats = BatteryStatsService.getService(); mBatteryService = battery; 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") { mHandlerThread = new HandlerThread("PowerManagerService") { @Override @Override protected void onLooperPrepared() { protected void onLooperPrepared() { Loading Loading @@ -1362,13 +1371,8 @@ class PowerManagerService extends IPowerManager.Stub enableLightSensor(on); enableLightSensor(on); if (!on) { if (!on) { // make sure button and key backlights are off too // make sure button and key backlights are off too int brightnessMode = (mUseSoftwareAutoBrightness mButtonLight.turnOff(); ? LightsService.BRIGHTNESS_MODE_SENSOR mKeyboardLight.turnOff(); : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, 0, brightnessMode); mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, 0, brightnessMode); // clear current value so we will update based on the new conditions // clear current value so we will update based on the new conditions // when the sensor is reenabled. // when the sensor is reenabled. mLightSensorValue = -1; mLightSensorValue = -1; Loading Loading @@ -1723,19 +1727,13 @@ class PowerManagerService extends IPowerManager.Stub ? LightsService.BRIGHTNESS_MODE_SENSOR ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); : LightsService.BRIGHTNESS_MODE_USER); if ((mask & SCREEN_BRIGHT_BIT) != 0) { if ((mask & SCREEN_BRIGHT_BIT) != 0) { mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, value, mLcdLight.setBrightness(value, brightnessMode); brightnessMode); } } brightnessMode = (mUseSoftwareAutoBrightness ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); if ((mask & BUTTON_BRIGHT_BIT) != 0) { if ((mask & BUTTON_BRIGHT_BIT) != 0) { mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, value, mButtonLight.setBrightness(value); brightnessMode); } } if ((mask & KEYBOARD_BRIGHT_BIT) != 0) { if ((mask & KEYBOARD_BRIGHT_BIT) != 0) { mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, value, mKeyboardLight.setBrightness(value); brightnessMode); } } } } Loading Loading @@ -2083,8 +2081,7 @@ class PowerManagerService extends IPowerManager.Stub int brightnessMode = (mAutoBrightessEnabled int brightnessMode = (mAutoBrightessEnabled ? LightsService.BRIGHTNESS_MODE_SENSOR ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, mLcdLight.setBrightness(lcdValue, brightnessMode); lcdValue, brightnessMode); } } } } if (mButtonBrightnessOverride < 0) { if (mButtonBrightnessOverride < 0) { Loading @@ -2095,11 +2092,7 @@ class PowerManagerService extends IPowerManager.Stub startAnimation = true; startAnimation = true; } } } else { } else { int brightnessMode = (mUseSoftwareAutoBrightness mButtonLight.setBrightness(buttonValue); ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, buttonValue, brightnessMode); } } } } if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) { if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) { Loading @@ -2110,11 +2103,7 @@ class PowerManagerService extends IPowerManager.Stub startAnimation = true; startAnimation = true; } } } else { } else { int brightnessMode = (mUseSoftwareAutoBrightness mKeyboardLight.setBrightness(keyboardValue); ? LightsService.BRIGHTNESS_MODE_SENSOR : LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, keyboardValue, brightnessMode); } } } } if (startAnimation) { if (startAnimation) { Loading Loading @@ -2443,12 +2432,9 @@ class PowerManagerService extends IPowerManager.Stub mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); // Don't let applications turn the screen all the way off // Don't let applications turn the screen all the way off brightness = Math.max(brightness, Power.BRIGHTNESS_DIM); brightness = Math.max(brightness, Power.BRIGHTNESS_DIM); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, brightness, mLcdLight.setBrightness(brightness); LightsService.BRIGHTNESS_MODE_USER); mKeyboardLight.setBrightness(mKeyboardVisible ? brightness : 0); mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, mButtonLight.setBrightness(brightness); (mKeyboardVisible ? brightness : 0), LightsService.BRIGHTNESS_MODE_USER); mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, brightness, LightsService.BRIGHTNESS_MODE_USER); long identity = Binder.clearCallingIdentity(); long identity = Binder.clearCallingIdentity(); try { try { mBatteryStats.noteScreenBrightness(brightness); mBatteryStats.noteScreenBrightness(brightness); Loading Loading @@ -2478,7 +2464,7 @@ class PowerManagerService extends IPowerManager.Stub public void setAttentionLight(boolean on, int color) { public void setAttentionLight(boolean on, int color) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); mLightsService.setAttentionLight(on, color); mAttentionLight.setFlashing(color, LightsService.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0); } } private void enableProximityLockLocked() { private void enableProximityLockLocked() { Loading
services/jni/com_android_server_LightsService.cpp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,8 @@ enum { LIGHT_INDEX_BATTERY = 3, LIGHT_INDEX_BATTERY = 3, LIGHT_INDEX_NOTIFICATIONS = 4, LIGHT_INDEX_NOTIFICATIONS = 4, LIGHT_INDEX_ATTENTION = 5, LIGHT_INDEX_ATTENTION = 5, LIGHT_INDEX_BLUETOOTH = 6, LIGHT_INDEX_WIFI = 7, LIGHT_COUNT LIGHT_COUNT }; }; Loading Loading @@ -80,6 +82,10 @@ static jint init_native(JNIEnv *env, jobject clazz) = get_device(module, LIGHT_ID_NOTIFICATIONS); = get_device(module, LIGHT_ID_NOTIFICATIONS); devices->lights[LIGHT_INDEX_ATTENTION] devices->lights[LIGHT_INDEX_ATTENTION] = get_device(module, LIGHT_ID_ATTENTION); = get_device(module, LIGHT_ID_ATTENTION); devices->lights[LIGHT_INDEX_BLUETOOTH] = get_device(module, LIGHT_ID_BLUETOOTH); devices->lights[LIGHT_INDEX_WIFI] = get_device(module, LIGHT_ID_WIFI); } else { } else { memset(devices, 0, sizeof(Devices)); memset(devices, 0, sizeof(Devices)); } } Loading