summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Cerqueira <android@cerqueira.org>2016-11-10 12:15:00 +0000
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-11-10 04:30:11 -0800
commitc15736bb1034f8aca5429ca336a2ab7126fe7a57 (patch)
tree4c8babb1a95b16dfffc1964e549f5313c8c40446
parentc7d2fb722fcf528e465bc3274bbb436edc9aeb2e (diff)
downloadframeworks_base-c15736bb1034f8aca5429ca336a2ab7126fe7a57.zip
frameworks_base-c15736bb1034f8aca5429ca336a2ab7126fe7a57.tar.gz
frameworks_base-c15736bb1034f8aca5429ca336a2ab7126fe7a57.tar.bz2
NotificationManager: Concentrate LED light capabilities at a single location
We had(have) a bunch of individual boolean toggles for various LED behaviors and combinations, which end up getting used as a similarly sprawling bunch of getResource() calls across various locations. And they keep piling up... So... create a new overlayable array of LED capabilities (config_deviceLightCapabilities) where we can throw everything (and expand in the future). Also, create a helper to abstract usage of the old (multi-resource) and new (single resource array) formats to avoid breaking any deployed devices. Change-Id: I7d627914b058861048071fc15776031c4152157f
-rw-r--r--core/java/android/app/INotificationManager.aidl2
-rw-r--r--core/java/android/app/NotificationManager.java28
-rw-r--r--core/res/res/values/cm_symbols.xml3
-rw-r--r--core/res/res/values/config.xml23
-rw-r--r--services/core/java/com/android/server/BatteryService.java16
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java56
6 files changed, 114 insertions, 14 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 59ff413..06c064f 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -103,4 +103,6 @@ interface INotificationManager
void applyRestore(in byte[] payload, int user);
ParceledListSlice getAppActiveNotifications(String callingPkg, int userId);
+
+ boolean deviceLightsCan(int lightCapability);
}
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index d84eee2..eae2599 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -765,4 +765,32 @@ public class NotificationManager
default: return defValue;
}
}
+
+ /** @hide */
+ public static final int LIGHTS_RGB_NOTIFICATION = 0;
+ /** @hide */
+ public static final int LIGHTS_RGB_BATTERY = 1 ;
+ /** @hide */
+ public static final int LIGHTS_MULTIPLE_LED = 2;
+ /** @hide */
+ public static final int LIGHTS_LED_PULSE = 3;
+ /** @hide */
+ public static final int LIGHTS_SEGMENTED_BATTERY_LIGHTS = 4;
+ /** @hide */
+ public static final int LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS = 5;
+
+ /** @hide */
+ public boolean deviceLightsCan(int lightCapability) {
+ INotificationManager service = getService();
+ try {
+ return service.deviceLightsCan(lightCapability);
+ } catch (RemoteException e) {
+ return true;
+ } catch (NullPointerException e) {
+ return true;
+ }
+ // If the service isn't up yet, assume everything is possible
+ }
+
+
}
diff --git a/core/res/res/values/cm_symbols.xml b/core/res/res/values/cm_symbols.xml
index 81f33cb..a56e5ac 100644
--- a/core/res/res/values/cm_symbols.xml
+++ b/core/res/res/values/cm_symbols.xml
@@ -145,4 +145,7 @@
<!--Exposed style for power menu -->
<java-symbol type="style" name="Theme.Power.Dialog" />
+
+ <!-- On-device lights (LED) capabilities -->
+ <java-symbol type="array" name="config_deviceLightCapabilities" />
</resources>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 79bf24e..8b49227 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2575,4 +2575,27 @@
<!-- Whether to persist the notification for when a usb drive device is plugged in -->
<bool name="config_persistUsbDriveNotification">false</bool>
+
+ <!-- What can the LEDs on this device do? If defined, this overrides all of the
+ older settings:
+
+ com.android.internal.R.bool.config_multiColorNotificationLed
+ com.android.internal.R.bool.config_multiColorBatteryLed
+ org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds
+ com.android.internal.R.bool.config_ledCanPulse
+ org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed
+ org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness
+
+ Use the following values from NotificationManager:
+ LIGHTS_RGB_NOTIFICATION = 0
+ LIGHTS_RGB_BATTERY = 1
+ LIGHTS_MULTIPLE_LED = 2
+ LIGHTS_LED_PULSE = 3
+ LIGHTS_SEGMENTED_BATTERY_LIGHTS = 4
+ LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS = 5
+ -->
+
+ <integer-array translatable="false" name="config_deviceLightCapabilities">
+ </integer-array>
+
</resources>
diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java
index 19ce5a7..97ad02c 100644
--- a/services/core/java/com/android/server/BatteryService.java
+++ b/services/core/java/com/android/server/BatteryService.java
@@ -1027,19 +1027,19 @@ public final class BatteryService extends SystemService {
private final int mBatteryLedOff;
public Led(Context context, LightsManager lights) {
+ NotificationManager nm = context.getSystemService(NotificationManager.class);
mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);
// Does the Device support changing battery LED colors?
- mMultiColorLed = context.getResources().getBoolean(
- com.android.internal.R.bool.config_multiColorBatteryLed);
+ mMultiColorLed = nm.deviceLightsCan(NotificationManager.LIGHTS_RGB_BATTERY);
// Is the notification LED brightness changeable ?
- mAdjustableNotificationLedBrightness = context.getResources().getBoolean(
- org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness);
+ mAdjustableNotificationLedBrightness = nm.deviceLightsCan(
+ NotificationManager.LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS);
// Does the Device have multiple LEDs ?
- mMultipleNotificationLeds = context.getResources().getBoolean(
- org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds);
+ mMultipleNotificationLeds = nm.deviceLightsCan(
+ NotificationManager.LIGHTS_MULTIPLE_LED);
mBatteryLedOn = context.getResources().getInteger(
com.android.internal.R.integer.config_notificationsBatteryLedOn);
@@ -1048,8 +1048,8 @@ public final class BatteryService extends SystemService {
// Does the Device have segmented battery LED support? In this case, we send the level
// in the alpha channel of the color and let the HAL sort it out.
- mUseSegmentedBatteryLed = context.getResources().getBoolean(
- org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed);
+ mUseSegmentedBatteryLed = nm.deviceLightsCan(
+ NotificationManager.LIGHTS_SEGMENTED_BATTERY_LIGHTS);
}
/**
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 052d010..422aee2 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1227,8 +1227,7 @@ public class NotificationManagerService extends SystemService {
mDefaultNotificationLedOff = resources.getInteger(
R.integer.config_defaultNotificationLedOff);
- mMultiColorNotificationLed = resources.getBoolean(
- R.bool.config_multiColorNotificationLed);
+ mMultiColorNotificationLed = deviceLightsCan(NotificationManager.LIGHTS_RGB_NOTIFICATION);
mNotificationPulseCustomLedValues = new HashMap<String, NotificationLedValues>();
@@ -1250,10 +1249,10 @@ public class NotificationManagerService extends SystemService {
VIBRATE_PATTERN_MAXLEN,
DEFAULT_VIBRATE_PATTERN);
- mAdjustableNotificationLedBrightness = resources.getBoolean(
- org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness);
- mMultipleNotificationLeds = resources.getBoolean(
- org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds);
+ mAdjustableNotificationLedBrightness = deviceLightsCan(
+ NotificationManager.LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS);
+ mMultipleNotificationLeds = deviceLightsCan(
+ NotificationManager.LIGHTS_MULTIPLE_LED);
mUseAttentionLight = resources.getBoolean(R.bool.config_useAttentionLight);
@@ -1396,6 +1395,47 @@ public class NotificationManagerService extends SystemService {
scheduleInterruptionFilterChanged(interruptionFilter);
}
+ private int deviceLightsCapabilities() {
+ Resources resources = getContext().getResources();
+ int capabilities = SystemProperties.getInt("sys.lights.capabilities", 0);
+
+ if (capabilities == 0) {
+ int[] deviceCaps = resources.getIntArray(
+ com.android.internal.R.array.config_deviceLightCapabilities);
+ for (int cap : deviceCaps) {
+ capabilities |= 1<<cap;
+ }
+ }
+
+ /* Legacy format */
+ if (capabilities == 0) {
+ if (resources.getBoolean(com.android.internal.R.bool.config_multiColorNotificationLed)) {
+ capabilities |= 1<<NotificationManager.LIGHTS_RGB_NOTIFICATION;
+ }
+ if (resources.getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) {
+ capabilities |= 1<<NotificationManager.LIGHTS_RGB_BATTERY;
+ }
+ if (resources.getBoolean(com.android.internal.R.bool.config_ledCanPulse)) {
+ capabilities |= 1<<NotificationManager.LIGHTS_LED_PULSE;
+ }
+ if (resources.getBoolean(org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds)) {
+ capabilities |= 1<<NotificationManager.LIGHTS_MULTIPLE_LED;
+ }
+ if (resources.getBoolean(org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed)) {
+ capabilities |= 1<<NotificationManager.LIGHTS_SEGMENTED_BATTERY_LIGHTS;
+ }
+ if (resources.getBoolean(org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness)) {
+ capabilities |= 1<<NotificationManager.LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS;
+ }
+ }
+ return capabilities;
+ }
+
+ /** @hide */
+ public boolean deviceLightsCan(int lightCapability) {
+ return ( (deviceLightsCapabilities() & 1<<lightCapability) != 0 );
+ }
+
private final IBinder mService = new INotificationManager.Stub() {
// Toasts
// ============================================================================
@@ -2161,6 +2201,10 @@ public class NotificationManagerService extends SystemService {
Binder.restoreCallingIdentity(identity);
}
}
+
+ public boolean deviceLightsCan(int lightCapability) {
+ return ( (deviceLightsCapabilities() & 1<<lightCapability) != 0 );
+ }
};
private String disableNotificationEffects(NotificationRecord record) {