frameworks/base
Révision | c15736bb1034f8aca5429ca336a2ab7126fe7a57 (tree) |
---|---|
l'heure | 2016-11-10 21:30:11 |
Auteur | Ricardo Cerqueira <android@cerq...> |
Commiter | Gerrit Code Review |
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
@@ -103,4 +103,6 @@ interface INotificationManager | ||
103 | 103 | void applyRestore(in byte[] payload, int user); |
104 | 104 | |
105 | 105 | ParceledListSlice getAppActiveNotifications(String callingPkg, int userId); |
106 | + | |
107 | + boolean deviceLightsCan(int lightCapability); | |
106 | 108 | } |
@@ -765,4 +765,32 @@ public class NotificationManager | ||
765 | 765 | default: return defValue; |
766 | 766 | } |
767 | 767 | } |
768 | + | |
769 | + /** @hide */ | |
770 | + public static final int LIGHTS_RGB_NOTIFICATION = 0; | |
771 | + /** @hide */ | |
772 | + public static final int LIGHTS_RGB_BATTERY = 1 ; | |
773 | + /** @hide */ | |
774 | + public static final int LIGHTS_MULTIPLE_LED = 2; | |
775 | + /** @hide */ | |
776 | + public static final int LIGHTS_LED_PULSE = 3; | |
777 | + /** @hide */ | |
778 | + public static final int LIGHTS_SEGMENTED_BATTERY_LIGHTS = 4; | |
779 | + /** @hide */ | |
780 | + public static final int LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS = 5; | |
781 | + | |
782 | + /** @hide */ | |
783 | + public boolean deviceLightsCan(int lightCapability) { | |
784 | + INotificationManager service = getService(); | |
785 | + try { | |
786 | + return service.deviceLightsCan(lightCapability); | |
787 | + } catch (RemoteException e) { | |
788 | + return true; | |
789 | + } catch (NullPointerException e) { | |
790 | + return true; | |
791 | + } | |
792 | + // If the service isn't up yet, assume everything is possible | |
793 | + } | |
794 | + | |
795 | + | |
768 | 796 | } |
@@ -145,4 +145,7 @@ | ||
145 | 145 | |
146 | 146 | <!--Exposed style for power menu --> |
147 | 147 | <java-symbol type="style" name="Theme.Power.Dialog" /> |
148 | + | |
149 | + <!-- On-device lights (LED) capabilities --> | |
150 | + <java-symbol type="array" name="config_deviceLightCapabilities" /> | |
148 | 151 | </resources> |
@@ -2575,4 +2575,27 @@ | ||
2575 | 2575 | |
2576 | 2576 | <!-- Whether to persist the notification for when a usb drive device is plugged in --> |
2577 | 2577 | <bool name="config_persistUsbDriveNotification">false</bool> |
2578 | + | |
2579 | + <!-- What can the LEDs on this device do? If defined, this overrides all of the | |
2580 | + older settings: | |
2581 | + | |
2582 | + com.android.internal.R.bool.config_multiColorNotificationLed | |
2583 | + com.android.internal.R.bool.config_multiColorBatteryLed | |
2584 | + org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds | |
2585 | + com.android.internal.R.bool.config_ledCanPulse | |
2586 | + org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed | |
2587 | + org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness | |
2588 | + | |
2589 | + Use the following values from NotificationManager: | |
2590 | + LIGHTS_RGB_NOTIFICATION = 0 | |
2591 | + LIGHTS_RGB_BATTERY = 1 | |
2592 | + LIGHTS_MULTIPLE_LED = 2 | |
2593 | + LIGHTS_LED_PULSE = 3 | |
2594 | + LIGHTS_SEGMENTED_BATTERY_LIGHTS = 4 | |
2595 | + LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS = 5 | |
2596 | + --> | |
2597 | + | |
2598 | + <integer-array translatable="false" name="config_deviceLightCapabilities"> | |
2599 | + </integer-array> | |
2600 | + | |
2578 | 2601 | </resources> |
@@ -1027,19 +1027,19 @@ public final class BatteryService extends SystemService { | ||
1027 | 1027 | private final int mBatteryLedOff; |
1028 | 1028 | |
1029 | 1029 | public Led(Context context, LightsManager lights) { |
1030 | + NotificationManager nm = context.getSystemService(NotificationManager.class); | |
1030 | 1031 | mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY); |
1031 | 1032 | |
1032 | 1033 | // Does the Device support changing battery LED colors? |
1033 | - mMultiColorLed = context.getResources().getBoolean( | |
1034 | - com.android.internal.R.bool.config_multiColorBatteryLed); | |
1034 | + mMultiColorLed = nm.deviceLightsCan(NotificationManager.LIGHTS_RGB_BATTERY); | |
1035 | 1035 | |
1036 | 1036 | // Is the notification LED brightness changeable ? |
1037 | - mAdjustableNotificationLedBrightness = context.getResources().getBoolean( | |
1038 | - org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness); | |
1037 | + mAdjustableNotificationLedBrightness = nm.deviceLightsCan( | |
1038 | + NotificationManager.LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS); | |
1039 | 1039 | |
1040 | 1040 | // Does the Device have multiple LEDs ? |
1041 | - mMultipleNotificationLeds = context.getResources().getBoolean( | |
1042 | - org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds); | |
1041 | + mMultipleNotificationLeds = nm.deviceLightsCan( | |
1042 | + NotificationManager.LIGHTS_MULTIPLE_LED); | |
1043 | 1043 | |
1044 | 1044 | mBatteryLedOn = context.getResources().getInteger( |
1045 | 1045 | com.android.internal.R.integer.config_notificationsBatteryLedOn); |
@@ -1048,8 +1048,8 @@ public final class BatteryService extends SystemService { | ||
1048 | 1048 | |
1049 | 1049 | // Does the Device have segmented battery LED support? In this case, we send the level |
1050 | 1050 | // in the alpha channel of the color and let the HAL sort it out. |
1051 | - mUseSegmentedBatteryLed = context.getResources().getBoolean( | |
1052 | - org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed); | |
1051 | + mUseSegmentedBatteryLed = nm.deviceLightsCan( | |
1052 | + NotificationManager.LIGHTS_SEGMENTED_BATTERY_LIGHTS); | |
1053 | 1053 | } |
1054 | 1054 | |
1055 | 1055 | /** |
@@ -1227,8 +1227,7 @@ public class NotificationManagerService extends SystemService { | ||
1227 | 1227 | mDefaultNotificationLedOff = resources.getInteger( |
1228 | 1228 | R.integer.config_defaultNotificationLedOff); |
1229 | 1229 | |
1230 | - mMultiColorNotificationLed = resources.getBoolean( | |
1231 | - R.bool.config_multiColorNotificationLed); | |
1230 | + mMultiColorNotificationLed = deviceLightsCan(NotificationManager.LIGHTS_RGB_NOTIFICATION); | |
1232 | 1231 | |
1233 | 1232 | mNotificationPulseCustomLedValues = new HashMap<String, NotificationLedValues>(); |
1234 | 1233 |
@@ -1250,10 +1249,10 @@ public class NotificationManagerService extends SystemService { | ||
1250 | 1249 | VIBRATE_PATTERN_MAXLEN, |
1251 | 1250 | DEFAULT_VIBRATE_PATTERN); |
1252 | 1251 | |
1253 | - mAdjustableNotificationLedBrightness = resources.getBoolean( | |
1254 | - org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness); | |
1255 | - mMultipleNotificationLeds = resources.getBoolean( | |
1256 | - org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds); | |
1252 | + mAdjustableNotificationLedBrightness = deviceLightsCan( | |
1253 | + NotificationManager.LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS); | |
1254 | + mMultipleNotificationLeds = deviceLightsCan( | |
1255 | + NotificationManager.LIGHTS_MULTIPLE_LED); | |
1257 | 1256 | |
1258 | 1257 | mUseAttentionLight = resources.getBoolean(R.bool.config_useAttentionLight); |
1259 | 1258 |
@@ -1396,6 +1395,47 @@ public class NotificationManagerService extends SystemService { | ||
1396 | 1395 | scheduleInterruptionFilterChanged(interruptionFilter); |
1397 | 1396 | } |
1398 | 1397 | |
1398 | + private int deviceLightsCapabilities() { | |
1399 | + Resources resources = getContext().getResources(); | |
1400 | + int capabilities = SystemProperties.getInt("sys.lights.capabilities", 0); | |
1401 | + | |
1402 | + if (capabilities == 0) { | |
1403 | + int[] deviceCaps = resources.getIntArray( | |
1404 | + com.android.internal.R.array.config_deviceLightCapabilities); | |
1405 | + for (int cap : deviceCaps) { | |
1406 | + capabilities |= 1<<cap; | |
1407 | + } | |
1408 | + } | |
1409 | + | |
1410 | + /* Legacy format */ | |
1411 | + if (capabilities == 0) { | |
1412 | + if (resources.getBoolean(com.android.internal.R.bool.config_multiColorNotificationLed)) { | |
1413 | + capabilities |= 1<<NotificationManager.LIGHTS_RGB_NOTIFICATION; | |
1414 | + } | |
1415 | + if (resources.getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) { | |
1416 | + capabilities |= 1<<NotificationManager.LIGHTS_RGB_BATTERY; | |
1417 | + } | |
1418 | + if (resources.getBoolean(com.android.internal.R.bool.config_ledCanPulse)) { | |
1419 | + capabilities |= 1<<NotificationManager.LIGHTS_LED_PULSE; | |
1420 | + } | |
1421 | + if (resources.getBoolean(org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds)) { | |
1422 | + capabilities |= 1<<NotificationManager.LIGHTS_MULTIPLE_LED; | |
1423 | + } | |
1424 | + if (resources.getBoolean(org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed)) { | |
1425 | + capabilities |= 1<<NotificationManager.LIGHTS_SEGMENTED_BATTERY_LIGHTS; | |
1426 | + } | |
1427 | + if (resources.getBoolean(org.cyanogenmod.platform.internal.R.bool.config_adjustableNotificationLedBrightness)) { | |
1428 | + capabilities |= 1<<NotificationManager.LIGHTS_ADJUSTABLE_NOTIFICATION_BRIGHTNESS; | |
1429 | + } | |
1430 | + } | |
1431 | + return capabilities; | |
1432 | + } | |
1433 | + | |
1434 | + /** @hide */ | |
1435 | + public boolean deviceLightsCan(int lightCapability) { | |
1436 | + return ( (deviceLightsCapabilities() & 1<<lightCapability) != 0 ); | |
1437 | + } | |
1438 | + | |
1399 | 1439 | private final IBinder mService = new INotificationManager.Stub() { |
1400 | 1440 | // Toasts |
1401 | 1441 | // ============================================================================ |
@@ -2161,6 +2201,10 @@ public class NotificationManagerService extends SystemService { | ||
2161 | 2201 | Binder.restoreCallingIdentity(identity); |
2162 | 2202 | } |
2163 | 2203 | } |
2204 | + | |
2205 | + public boolean deviceLightsCan(int lightCapability) { | |
2206 | + return ( (deviceLightsCapabilities() & 1<<lightCapability) != 0 ); | |
2207 | + } | |
2164 | 2208 | }; |
2165 | 2209 | |
2166 | 2210 | private String disableNotificationEffects(NotificationRecord record) { |