Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 434d2568 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

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
parent 09d3caf0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -100,4 +100,6 @@ interface INotificationManager
    void applyRestore(in byte[] payload, int user);

    ParceledListSlice getAppActiveNotifications(String callingPkg, int userId);

    boolean deviceLightsCan(int lightCapability);
}
+28 −0
Original line number Diff line number Diff line
@@ -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
    }


}
+3 −0
Original line number Diff line number Diff line
@@ -157,4 +157,7 @@

    <!-- Usb drive persistent notification -->
    <java-symbol type="bool" name="config_persistUsbDriveNotification" />

    <!-- On-device lights (LED) capabilities -->
    <java-symbol type="array" name="config_deviceLightCapabilities" />
</resources>
+23 −0
Original line number Diff line number Diff line
@@ -2570,4 +2570,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>
+6 −6
Original line number Diff line number Diff line
@@ -1030,19 +1030,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);
Loading