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

Commit e8cb9f65 authored by DvTonder's avatar DvTonder
Browse files

Notification light(LED) settings: package mapping

Credit for this code goes to Marko Mihovilic

This commit allows for framework side override of the application
package name set for Notification light led overrides.  This is used
in cases where the user selectable application sends its notifications
via another package.

Specifically:  GTalk (com.google.android.talk) sends notifications via the
Google services framework (com.google.android.gsf).

Patch set 2  - fix derp and whitespace cleanup
Patch set 4  - fixed another derp
Patch set 5  - fixes typo in comment
Patch set 6  - remove Log.d line
Patch set 7  - allow specifying default values in application notification
               overrides

Change-Id: I0c13ae3acefa0bcb4ffb46ea7eae301081d9f8f6
parent 1d36e06c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -526,4 +526,12 @@
        <item>bootloader</item>
    </string-array>

    <!-- Do not translate. Defines the mapping of notification package names
         from the actual triggering package to the user selectable package.
         E.g. GTalk notifications come via Google Services Framework
         Format: [triggering package]|[user package] -->
    <string-array name="notification_light_package_mapping" translatable="false">
        <item>com.google.android.gsf|com.google.android.talk</item>
    </string-array>

</resources>
+21 −5
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Calendar;
import java.util.Map;

/** {@hide} */
public class NotificationManagerService extends INotificationManager.Stub
@@ -106,12 +107,13 @@ public class NotificationManagerService extends INotificationManager.Stub
    private NotificationRecord mVibrateNotification;
    private Vibrator mVibrator = new Vibrator();

    // for enabling and disabling notification pulse behavior
    // for enabling and disabling notification pulse behaviour
    private boolean mScreenOn = true;
    private boolean mWasScreenOn = false;
    private boolean mInCall = false;
    private boolean mNotificationPulseEnabled;
    private HashMap<String, NotificationLedValues> mNotificationPulseCustomLedValues;
    private Map<String, String> mPackageNameMappings;

    private final ArrayList<NotificationRecord> mNotificationList =
            new ArrayList<NotificationRecord>();
@@ -516,6 +518,13 @@ public class NotificationManagerService extends INotificationManager.Stub

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

        mPackageNameMappings = new HashMap<String, String>();
        for(String mapping : resources.getStringArray(
                com.android.internal.R.array.notification_light_package_mapping)) {
            String[] map = mapping.split("\\|");
            mPackageNameMappings.put(map[0], map[1]);
        }

        // 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
@@ -1233,9 +1242,9 @@ public class NotificationManagerService extends INotificationManager.Stub
            int ledOffMS;
            NotificationLedValues ledValues = getLedValuesForNotification(mLedNotification);
            if (ledValues != null) {
                ledARGB = ledValues.color;
                ledOnMS = ledValues.onMS;
                ledOffMS = ledValues.offMS;
                ledARGB = ledValues.color != 0 ? ledValues.color : mDefaultNotificationColor;
                ledOnMS = ledValues.onMS >= 0 ? ledValues.onMS : mDefaultNotificationLedOn;
                ledOffMS = ledValues.offMS >= 0 ? ledValues.offMS : mDefaultNotificationLedOn;
            } else {
                if ((mLedNotification.notification.defaults & Notification.DEFAULT_LIGHTS) != 0) {
                    ledARGB = mDefaultNotificationColor;
@@ -1286,7 +1295,14 @@ public class NotificationManagerService extends INotificationManager.Stub
    }

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

    private String mapPackage(String pkg) {
        if(!mPackageNameMappings.containsKey(pkg)) {
            return pkg;
        }
        return mPackageNameMappings.get(pkg);
    }

    // lock on mNotificationList