Skip to content

Commit c15736b

Browse files
rmccGerrit Code Review
authored andcommitted
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
1 parent c7d2fb7 commit c15736b

6 files changed

Lines changed: 114 additions & 14 deletions

File tree

core/java/android/app/INotificationManager.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ interface INotificationManager
103103
void applyRestore(in byte[] payload, int user);
104104

105105
ParceledListSlice getAppActiveNotifications(String callingPkg, int userId);
106+
107+
boolean deviceLightsCan(int lightCapability);
106108
}

core/java/android/app/NotificationManager.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,4 +765,32 @@ public static int zenModeFromInterruptionFilter(int interruptionFilter, int defV
765765
default: return defValue;
766766
}
767767
}
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+
768796
}

core/res/res/values/cm_symbols.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,7 @@
145145

146146
<!--Exposed style for power menu -->
147147
<java-symbol type="style" name="Theme.Power.Dialog" />
148+
149+
<!-- On-device lights (LED) capabilities -->
150+
<java-symbol type="array" name="config_deviceLightCapabilities" />
148151
</resources>

core/res/res/values/config.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,4 +2575,27 @@
25752575

25762576
<!-- Whether to persist the notification for when a usb drive device is plugged in -->
25772577
<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+
25782601
</resources>

services/core/java/com/android/server/BatteryService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,19 +1027,19 @@ private final class Led {
10271027
private final int mBatteryLedOff;
10281028

10291029
public Led(Context context, LightsManager lights) {
1030+
NotificationManager nm = context.getSystemService(NotificationManager.class);
10301031
mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);
10311032

10321033
// 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);
10351035

10361036
// 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);
10391039

10401040
// 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);
10431043

10441044
mBatteryLedOn = context.getResources().getInteger(
10451045
com.android.internal.R.integer.config_notificationsBatteryLedOn);
@@ -1048,8 +1048,8 @@ public Led(Context context, LightsManager lights) {
10481048

10491049
// Does the Device have segmented battery LED support? In this case, we send the level
10501050
// 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);
10531053
}
10541054

10551055
/**

services/core/java/com/android/server/notification/NotificationManagerService.java

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,7 @@ void onPolicyChanged() {
12271227
mDefaultNotificationLedOff = resources.getInteger(
12281228
R.integer.config_defaultNotificationLedOff);
12291229

1230-
mMultiColorNotificationLed = resources.getBoolean(
1231-
R.bool.config_multiColorNotificationLed);
1230+
mMultiColorNotificationLed = deviceLightsCan(NotificationManager.LIGHTS_RGB_NOTIFICATION);
12321231

12331232
mNotificationPulseCustomLedValues = new HashMap<String, NotificationLedValues>();
12341233

@@ -1250,10 +1249,10 @@ void onPolicyChanged() {
12501249
VIBRATE_PATTERN_MAXLEN,
12511250
DEFAULT_VIBRATE_PATTERN);
12521251

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);
12571256

12581257
mUseAttentionLight = resources.getBoolean(R.bool.config_useAttentionLight);
12591258

@@ -1396,6 +1395,47 @@ private void updateInterruptionFilterLocked() {
13961395
scheduleInterruptionFilterChanged(interruptionFilter);
13971396
}
13981397

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+
13991439
private final IBinder mService = new INotificationManager.Stub() {
14001440
// Toasts
14011441
// ============================================================================
@@ -2161,6 +2201,10 @@ public void setNotificationPolicy(String pkg, Policy policy) {
21612201
Binder.restoreCallingIdentity(identity);
21622202
}
21632203
}
2204+
2205+
public boolean deviceLightsCan(int lightCapability) {
2206+
return ( (deviceLightsCapabilities() & 1<<lightCapability) != 0 );
2207+
}
21642208
};
21652209

21662210
private String disableNotificationEffects(NotificationRecord record) {

0 commit comments

Comments
 (0)