From c15736bb1034f8aca5429ca336a2ab7126fe7a57 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Thu, 10 Nov 2016 12:15:00 +0000 Subject: 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 --- .../java/com/android/server/BatteryService.java | 16 +++---- .../notification/NotificationManagerService.java | 56 +++++++++++++++++++--- 2 files changed, 58 insertions(+), 14 deletions(-) (limited to 'services') 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(); @@ -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<