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

Commit 24df693d authored by nebkat's avatar nebkat Committed by Steve Kondik
Browse files

Custom LED notification (1/2 framework)

Change-Id: If0b0a70d495dae63bea7fe61940f7803b97514c1
parent 4538cf82
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -1910,6 +1910,36 @@ public final class Settings {
         */
        public static final String BATTERY_LIGHT_PULSE = "battery_light_pulse";

        /*
         * What color to use for the notification LED by default
         * @hide
         */
        public static final String NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR = "notification_light_pulse_default_color";

        /**
         * How long to flash the notification LED by default
         * @hide
         */
        public static final String NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_ON = "notification_light_pulse_default_led_on";

        /**
         * How long to wait between flashes for the notification LED by default
         * @hide
         */
        public static final String NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_OFF = "notification_light_pulse_default_led_off";

        /**
         * Whether to use the custom LED values for the notification pulse LED.
         * @hide
         */
        public static final String NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE = "notification_light_pulse_custom_enable";

        /**
         * Which custom LED values to use for the notification pulse LED.
         * @hide
         */
        public static final String NOTIFICATION_LIGHT_PULSE_CUSTOM_VALUES = "notification_light_pulse_custom_enable";

        /**
         * Show pointer location on screen?
         * 0 = no
+95 −12
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/** {@hide} */
public class NotificationManagerService extends INotificationManager.Stub
@@ -105,6 +106,7 @@ public class NotificationManagerService extends INotificationManager.Stub
    private boolean mWasScreenOn = false;
    private boolean mInCall = false;
    private boolean mNotificationPulseEnabled;
    private HashMap<String, NotificationLedValues> mNotificationPulseCustomLedValues;

    private final ArrayList<NotificationRecord> mNotificationList =
            new ArrayList<NotificationRecord>();
@@ -226,6 +228,12 @@ public class NotificationManagerService extends INotificationManager.Stub
        }
    }

    class NotificationLedValues {
        public int color;
        public int onMS;
        public int offMS;
    }

    private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks
            = new StatusBarManagerService.NotificationCallbacks() {

@@ -374,20 +382,48 @@ public class NotificationManagerService extends INotificationManager.Stub
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NOTIFICATION_LIGHT_PULSE), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_ON), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_OFF), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_VALUES), false, this);
            update();
        }

        @Override public void onChange(boolean selfChange) {
            update();
            updateNotificationPulse();
        }

        public void update() {
            ContentResolver resolver = mContext.getContentResolver();
            boolean pulseEnabled = Settings.System.getInt(resolver,
            // LED enabled
            mNotificationPulseEnabled = Settings.System.getInt(resolver,
                    Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
            if (mNotificationPulseEnabled != pulseEnabled) {
                mNotificationPulseEnabled = pulseEnabled;
                updateNotificationPulse();

            // LED default color
            mDefaultNotificationColor = Settings.System.getInt(resolver,
                    Settings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR, mDefaultNotificationColor);

            // LED default on MS
            mDefaultNotificationLedOn = Settings.System.getInt(resolver,
                    Settings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_ON, mDefaultNotificationLedOn);

            // LED default off MS
            mDefaultNotificationLedOff = Settings.System.getInt(resolver,
                    Settings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_OFF, mDefaultNotificationLedOff);

            // LED custom notification colors
            mNotificationPulseCustomLedValues.clear();
            if (Settings.System.getInt(resolver,
                    Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE, 0) != 0) {
                parseNotificationPulseCustomValuesString(Settings.System.getString(resolver,
                        Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_VALUES));
            }
        }
    }
@@ -417,6 +453,8 @@ public class NotificationManagerService extends INotificationManager.Stub
        mDefaultNotificationLedOff = resources.getInteger(
                com.android.internal.R.integer.config_defaultNotificationLedOff);

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

        // Don't start allowing notifications until the setup wizard has run once.
        // After that, including subsequent boots, init with notifications turned on.
        // This works on the first boot because the setup wizard will toggle this
@@ -1096,13 +1134,24 @@ public class NotificationManagerService extends INotificationManager.Stub
        if (mInCall || mScreenOn || (wasScreenOn && !forceWithScreenOff)) {
            mNotificationLight.turnOff();
        } else {
            int ledARGB = mLedNotification.notification.ledARGB;
            int ledOnMS = mLedNotification.notification.ledOnMS;
            int ledOffMS = mLedNotification.notification.ledOffMS;
            int ledARGB;
            int ledOnMS;
            int ledOffMS;
            NotificationLedValues ledValues = getLedValuesForNotification(mLedNotification);
            if (ledValues != null) {
                ledARGB = ledValues.color;
                ledOnMS = ledValues.onMS;
                ledOffMS = ledValues.offMS;
            } else {
                if ((mLedNotification.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
                    ledARGB = mDefaultNotificationColor;
                    ledOnMS = mDefaultNotificationLedOn;
                    ledOffMS = mDefaultNotificationLedOff;
                } else {
                    ledARGB = mLedNotification.notification.ledARGB;
                    ledOnMS = mLedNotification.notification.ledOnMS;
                    ledOffMS = mLedNotification.notification.ledOffMS;
                }
            }
            if (mNotificationPulseEnabled) {
                // pulse repeatedly
@@ -1112,6 +1161,40 @@ public class NotificationManagerService extends INotificationManager.Stub
        }
    }

    private void parseNotificationPulseCustomValuesString(String customLedValuesString) {
        if (TextUtils.isEmpty(customLedValuesString)) {
            return;
        }

        for (String packageValuesString : customLedValuesString.split("|")) {
            String[] packageValues = packageValuesString.split("=");
            if (packageValues.length != 2) {
                Log.e(TAG, "Error parsing custom led values for unknown package");
                continue;
            }
            String packageName = packageValues[0];
            String[] values = packageValues[1].split(";");
            if (values.length != 3) {
                Log.e(TAG, "Error parsing custom led values '" + packageValues[1] + "' for " + packageName);
                continue;
            }
            NotificationLedValues ledValues = new NotificationLedValues();
            try {
                ledValues.color = Integer.parseInt(values[0]);
                ledValues.onMS = Integer.parseInt(values[1]);
                ledValues.offMS = Integer.parseInt(values[2]);
            } catch (Exception e) {
                Log.e(TAG, "Error parsing custom led values '" + packageValues[1] + "' for " + packageName);
                continue;
            }
            mNotificationPulseCustomLedValues.put(packageName, ledValues);
        }
    }

    private NotificationLedValues getLedValuesForNotification(NotificationRecord ledNotification) {
        return mNotificationPulseCustomLedValues.get(ledNotification.pkg);
    }

    // lock on mNotificationList
    private int indexOfNotificationLocked(String pkg, String tag, int id)
    {