am 3766ae55: Merge change I707f53cd into eclair-mr2
Merge commit '3766ae5551e6231c251b0af38206aea30a49df63' into eclair-mr2-plus-aosp * commit '3766ae5551e6231c251b0af38206aea30a49df63': LightsService cleanup:
This commit is contained in:
@@ -30,6 +30,9 @@ public class LightsService {
|
||||
static final int LIGHT_ID_BATTERY = 3;
|
||||
static final int LIGHT_ID_NOTIFICATIONS = 4;
|
||||
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_TIMED = 1;
|
||||
@@ -45,13 +48,85 @@ public class LightsService {
|
||||
*/
|
||||
static final int BRIGHTNESS_MODE_SENSOR = 1;
|
||||
|
||||
private boolean mAttentionLightOn;
|
||||
private boolean mPulsing;
|
||||
private final Light mLights[] = new Light[LIGHT_ID_COUNT];
|
||||
|
||||
public final class Light {
|
||||
|
||||
private Light(int id) {
|
||||
mId = id;
|
||||
}
|
||||
|
||||
public void setBrightness(int brightness) {
|
||||
setBrightness(brightness, BRIGHTNESS_MODE_USER);
|
||||
}
|
||||
|
||||
public void setBrightness(int brightness, int brightnessMode) {
|
||||
synchronized (this) {
|
||||
int color = brightness & 0x000000ff;
|
||||
color = 0xff000000 | (color << 16) | (color << 8) | color;
|
||||
setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
synchronized (this) {
|
||||
setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlashing(int color, int mode, int onMS, int offMS) {
|
||||
synchronized (this) {
|
||||
setLightLocked(color, mode, onMS, offMS, BRIGHTNESS_MODE_USER);
|
||||
}
|
||||
}
|
||||
|
||||
public void pulse() {
|
||||
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 turnOff() {
|
||||
synchronized (this) {
|
||||
setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopFlashing() {
|
||||
synchronized (this) {
|
||||
setLightLocked(mColor, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_USER);
|
||||
}
|
||||
}
|
||||
|
||||
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 int mId;
|
||||
private int mColor;
|
||||
private int mMode;
|
||||
private int mOnMS;
|
||||
private int mOffMS;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
@@ -59,65 +134,15 @@ public class LightsService {
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
void setLightOff(int light) {
|
||||
setLight_native(mNativePointer, light, 0, LIGHT_FLASH_NONE, 0, 0, 0);
|
||||
}
|
||||
|
||||
void setLightBrightness(int light, int brightness, int brightnessMode) {
|
||||
int b = brightness & 0x000000ff;
|
||||
b = 0xff000000 | (b << 16) | (b << 8) | b;
|
||||
setLight_native(mNativePointer, light, b, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
|
||||
}
|
||||
|
||||
void setLightColor(int light, int color) {
|
||||
setLight_native(mNativePointer, light, color, LIGHT_FLASH_NONE, 0, 0, 0);
|
||||
}
|
||||
|
||||
void setLightFlashing(int light, int color, int mode, int onMS, int offMS) {
|
||||
setLight_native(mNativePointer, light, color, mode, onMS, offMS, 0);
|
||||
}
|
||||
|
||||
public void setAttentionLight(boolean on, int color) {
|
||||
// Not worthy of a permission. We shouldn't have a flashlight permission.
|
||||
synchronized (this) {
|
||||
mAttentionLightOn = on;
|
||||
mPulsing = false;
|
||||
setLight_native(mNativePointer, LIGHT_ID_ATTENTION, color,
|
||||
LIGHT_FLASH_HARDWARE, on ? 3 : 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void pulseBreathingLight() {
|
||||
synchronized (this) {
|
||||
// HACK: Added at the last minute of cupcake -- design this better;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
public Light getLight(int id) {
|
||||
return mLights[id];
|
||||
}
|
||||
|
||||
private Handler mH = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
synchronized (this) {
|
||||
if (false) {
|
||||
Log.d(TAG, "pulse cleanup handler firing mPulsing=" + mPulsing);
|
||||
}
|
||||
if (mPulsing) {
|
||||
mPulsing = false;
|
||||
setLight_native(mNativePointer, LIGHT_ID_ATTENTION,
|
||||
mAttentionLightOn ? 0xffffffff : 0,
|
||||
LIGHT_FLASH_NONE, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
Light light = (Light)msg.obj;
|
||||
light.stopFlashing();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -87,6 +87,9 @@ class NotificationManagerService extends INotificationManager.Stub
|
||||
private WorkerHandler mHandler;
|
||||
private StatusBarService mStatusBarService;
|
||||
private LightsService mLightsService;
|
||||
private LightsService.Light mBatteryLight;
|
||||
private LightsService.Light mNotificationLight;
|
||||
private LightsService.Light mAttentionLight;
|
||||
|
||||
private NotificationRecord mSoundNotification;
|
||||
private AsyncPlayer mSound;
|
||||
@@ -376,6 +379,10 @@ class NotificationManagerService extends INotificationManager.Stub
|
||||
mStatusBarService = statusBar;
|
||||
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.
|
||||
// After that, including subsequent boots, init with notifications turned on.
|
||||
// This works on the first boot because the setup wizard will toggle this
|
||||
@@ -678,7 +685,7 @@ class NotificationManagerService extends INotificationManager.Stub
|
||||
long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
r.statusBarKey = mStatusBarService.addIcon(icon, n);
|
||||
mLightsService.pulseBreathingLight();
|
||||
mAttentionLight.pulse();
|
||||
}
|
||||
finally {
|
||||
Binder.restoreCallingIdentity(identity);
|
||||
@@ -969,24 +976,20 @@ class NotificationManagerService extends INotificationManager.Stub
|
||||
// Battery low always shows, other states only show if charging.
|
||||
if (mBatteryLow) {
|
||||
if (mBatteryCharging) {
|
||||
mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY,
|
||||
BATTERY_LOW_ARGB);
|
||||
mBatteryLight.setColor(BATTERY_LOW_ARGB);
|
||||
} else {
|
||||
// Flash when battery is low and not charging
|
||||
mLightsService.setLightFlashing(LightsService.LIGHT_ID_BATTERY,
|
||||
BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED,
|
||||
BATTERY_BLINK_ON, BATTERY_BLINK_OFF);
|
||||
mBatteryLight.setFlashing(BATTERY_LOW_ARGB, LightsService.LIGHT_FLASH_TIMED,
|
||||
BATTERY_BLINK_ON, BATTERY_BLINK_OFF);
|
||||
}
|
||||
} else if (mBatteryCharging) {
|
||||
if (mBatteryFull) {
|
||||
mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY,
|
||||
BATTERY_FULL_ARGB);
|
||||
mBatteryLight.setColor(BATTERY_FULL_ARGB);
|
||||
} else {
|
||||
mLightsService.setLightColor(LightsService.LIGHT_ID_BATTERY,
|
||||
BATTERY_MEDIUM_ARGB);
|
||||
mBatteryLight.setColor(BATTERY_MEDIUM_ARGB);
|
||||
}
|
||||
} else {
|
||||
mLightsService.setLightOff(LightsService.LIGHT_ID_BATTERY);
|
||||
mBatteryLight.turnOff();
|
||||
}
|
||||
|
||||
// handle notification lights
|
||||
@@ -998,10 +1001,9 @@ class NotificationManagerService extends INotificationManager.Stub
|
||||
}
|
||||
}
|
||||
if (mLedNotification == null) {
|
||||
mLightsService.setLightOff(LightsService.LIGHT_ID_NOTIFICATIONS);
|
||||
mNotificationLight.turnOff();
|
||||
} else {
|
||||
mLightsService.setLightFlashing(
|
||||
LightsService.LIGHT_ID_NOTIFICATIONS,
|
||||
mNotificationLight.setFlashing(
|
||||
mLedNotification.notification.ledARGB,
|
||||
LightsService.LIGHT_FLASH_TIMED,
|
||||
mLedNotification.notification.ledOnMS,
|
||||
|
||||
@@ -183,6 +183,10 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
private Intent mScreenOnIntent;
|
||||
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;
|
||||
@@ -428,6 +432,11 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
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() {
|
||||
@@ -1362,13 +1371,8 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
enableLightSensor(on);
|
||||
if (!on) {
|
||||
// make sure button and key backlights are off too
|
||||
int brightnessMode = (mUseSoftwareAutoBrightness
|
||||
? LightsService.BRIGHTNESS_MODE_SENSOR
|
||||
: LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, 0,
|
||||
brightnessMode);
|
||||
mLightsService.setLightBrightness(LightsService.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;
|
||||
@@ -1723,19 +1727,13 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
? LightsService.BRIGHTNESS_MODE_SENSOR
|
||||
: LightsService.BRIGHTNESS_MODE_USER);
|
||||
if ((mask & SCREEN_BRIGHT_BIT) != 0) {
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, value,
|
||||
brightnessMode);
|
||||
mLcdLight.setBrightness(value, brightnessMode);
|
||||
}
|
||||
brightnessMode = (mUseSoftwareAutoBrightness
|
||||
? LightsService.BRIGHTNESS_MODE_SENSOR
|
||||
: LightsService.BRIGHTNESS_MODE_USER);
|
||||
if ((mask & BUTTON_BRIGHT_BIT) != 0) {
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, value,
|
||||
brightnessMode);
|
||||
mButtonLight.setBrightness(value);
|
||||
}
|
||||
if ((mask & KEYBOARD_BRIGHT_BIT) != 0) {
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD, value,
|
||||
brightnessMode);
|
||||
mKeyboardLight.setBrightness(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2083,8 +2081,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
int brightnessMode = (mAutoBrightessEnabled
|
||||
? LightsService.BRIGHTNESS_MODE_SENSOR
|
||||
: LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT,
|
||||
lcdValue, brightnessMode);
|
||||
mLcdLight.setBrightness(lcdValue, brightnessMode);
|
||||
}
|
||||
}
|
||||
if (mButtonBrightnessOverride < 0) {
|
||||
@@ -2095,11 +2092,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
startAnimation = true;
|
||||
}
|
||||
} else {
|
||||
int brightnessMode = (mUseSoftwareAutoBrightness
|
||||
? LightsService.BRIGHTNESS_MODE_SENSOR
|
||||
: LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS,
|
||||
buttonValue, brightnessMode);
|
||||
mButtonLight.setBrightness(buttonValue);
|
||||
}
|
||||
}
|
||||
if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) {
|
||||
@@ -2110,11 +2103,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
startAnimation = true;
|
||||
}
|
||||
} else {
|
||||
int brightnessMode = (mUseSoftwareAutoBrightness
|
||||
? LightsService.BRIGHTNESS_MODE_SENSOR
|
||||
: LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD,
|
||||
keyboardValue, brightnessMode);
|
||||
mKeyboardLight.setBrightness(keyboardValue);
|
||||
}
|
||||
}
|
||||
if (startAnimation) {
|
||||
@@ -2443,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);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BACKLIGHT, brightness,
|
||||
LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_KEYBOARD,
|
||||
(mKeyboardVisible ? brightness : 0), LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLightsService.setLightBrightness(LightsService.LIGHT_ID_BUTTONS, brightness,
|
||||
LightsService.BRIGHTNESS_MODE_USER);
|
||||
mLcdLight.setBrightness(brightness);
|
||||
mKeyboardLight.setBrightness(mKeyboardVisible ? brightness : 0);
|
||||
mButtonLight.setBrightness(brightness);
|
||||
long identity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mBatteryStats.noteScreenBrightness(brightness);
|
||||
@@ -2478,7 +2464,7 @@ class PowerManagerService extends IPowerManager.Stub
|
||||
|
||||
public void setAttentionLight(boolean on, int color) {
|
||||
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() {
|
||||
|
||||
@@ -39,6 +39,8 @@ enum {
|
||||
LIGHT_INDEX_BATTERY = 3,
|
||||
LIGHT_INDEX_NOTIFICATIONS = 4,
|
||||
LIGHT_INDEX_ATTENTION = 5,
|
||||
LIGHT_INDEX_BLUETOOTH = 6,
|
||||
LIGHT_INDEX_WIFI = 7,
|
||||
LIGHT_COUNT
|
||||
};
|
||||
|
||||
@@ -80,6 +82,10 @@ static jint init_native(JNIEnv *env, jobject clazz)
|
||||
= get_device(module, LIGHT_ID_NOTIFICATIONS);
|
||||
devices->lights[LIGHT_INDEX_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 {
|
||||
memset(devices, 0, sizeof(Devices));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user