• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

修訂33086de92a6d1a06e0203ba17de6fe74f5d7a413 (tree)
時間2016-10-05 20:38:59
作者Steve Kondik <steve@cyng...>
CommiterSteve Kondik

Log Message

lights: Automatically generate an LED color for notifications

  • When an app doesn't specify a color for the LED, as is the usual
    case, we currently just show the default color. This is boring.
    It's also a pain in the ass to manually map all your apps to
    colors.
  • Use our new helpers to generate this color based on the application's
    icon color. Keep a cache to avoid wasting cycles.

Change-Id: I7288e52499819a6a6c75ed9d9ba7cfa1b13c5669

nms: Only generate LED colors if the device has a multicolored LED

  • Check the overlay value before doing any of this stuff.

Change-Id: Iedfceba6bfc86b2761d8af57ecab51026bfa4c19

Change Summary

差異

--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -80,6 +80,7 @@ import android.content.pm.ParceledListSlice;
8080 import android.content.pm.UserInfo;
8181 import android.content.res.Resources;
8282 import android.database.ContentObserver;
83+import android.graphics.drawable.Drawable;
8384 import android.media.AudioAttributes;
8485 import android.media.AudioManager;
8586 import android.media.AudioManagerInternal;
@@ -147,6 +148,7 @@ import com.android.server.vr.VrManagerInternal;
147148 import com.android.server.notification.ManagedServices.UserProfiles;
148149
149150 import cyanogenmod.providers.CMSettings;
151+import cyanogenmod.util.ColorUtils;
150152
151153 import cyanogenmod.providers.CMSettings;
152154 import libcore.io.IoUtils;
@@ -262,6 +264,8 @@ public class NotificationManagerService extends SystemService {
262264 private boolean mMultipleNotificationLeds;
263265 private boolean mMultipleLedsEnabledSetting = false;
264266
267+ private boolean mAutoGenerateNotificationColor = true;
268+
265269 private boolean mScreenOnEnabled = false;
266270 private boolean mScreenOnDefault = false;
267271
@@ -286,6 +290,8 @@ public class NotificationManagerService extends SystemService {
286290 private boolean mNotificationPulseEnabled;
287291 private ArrayMap<String, NotificationLedValues> mNotificationPulseCustomLedValues;
288292 private Map<String, String> mPackageNameMappings;
293+ private final ArrayMap<String, Integer> mGeneratedPackageLedColors =
294+ new ArrayMap<String, Integer>();
289295
290296 // for checking lockscreen status
291297 private KeyguardManager mKeyguardManager;
@@ -324,6 +330,8 @@ public class NotificationManagerService extends SystemService {
324330 private ConditionProviders mConditionProviders;
325331 private NotificationUsageStats mUsageStats;
326332
333+ private boolean mMultiColorNotificationLed;
334+
327335 private static final int MY_UID = Process.myUid();
328336 private static final int MY_PID = Process.myPid();
329337 private RankingHandler mRankingHandler;
@@ -892,6 +900,9 @@ public class NotificationManagerService extends SystemService {
892900 resolver.registerContentObserver(CMSettings.System.getUriFor(
893901 CMSettings.System.NOTIFICATION_LIGHT_SCREEN_ON),
894902 false, this, UserHandle.USER_ALL);
903+ resolver.registerContentObserver(CMSettings.System.getUriFor(
904+ CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO), false,
905+ this, UserHandle.USER_ALL);
895906 if (mAdjustableNotificationLedBrightness) {
896907 resolver.registerContentObserver(CMSettings.System.getUriFor(
897908 CMSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL),
@@ -916,6 +927,11 @@ public class NotificationManagerService extends SystemService {
916927 mNotificationPulseEnabled = Settings.System.getIntForUser(resolver,
917928 Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0;
918929
930+ // Automatically pick a color for LED if not set
931+ mAutoGenerateNotificationColor = CMSettings.System.getIntForUser(resolver,
932+ CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO,
933+ 1, UserHandle.USER_CURRENT) != 0;
934+
919935 // LED default color
920936 mDefaultNotificationColor = CMSettings.System.getIntForUser(resolver,
921937 CMSettings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR,
@@ -931,6 +947,9 @@ public class NotificationManagerService extends SystemService {
931947 CMSettings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_OFF,
932948 mDefaultNotificationLedOff, UserHandle.USER_CURRENT);
933949
950+ // LED generated notification colors
951+ mGeneratedPackageLedColors.clear();
952+
934953 // LED custom notification colors
935954 mNotificationPulseCustomLedValues.clear();
936955 if (CMSettings.System.getIntForUser(resolver,
@@ -1104,6 +1123,9 @@ public class NotificationManagerService extends SystemService {
11041123 mDefaultNotificationLedOff = resources.getInteger(
11051124 R.integer.config_defaultNotificationLedOff);
11061125
1126+ mMultiColorNotificationLed = resources.getBoolean(
1127+ R.bool.config_multiColorNotificationLed);
1128+
11071129 mNotificationPulseCustomLedValues = new ArrayMap<String, NotificationLedValues>();
11081130
11091131 mPackageNameMappings = new ArrayMap<String, String>();
@@ -3747,7 +3769,7 @@ public class NotificationManagerService extends SystemService {
37473769 ledOnMS = ledValues.onMS >= 0 ? ledValues.onMS : mDefaultNotificationLedOn;
37483770 ledOffMS = ledValues.offMS >= 0 ? ledValues.offMS : mDefaultNotificationLedOff;
37493771 } else if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
3750- ledARGB = mDefaultNotificationColor;
3772+ ledARGB = generateLedColorForNotification(ledNotification);
37513773 ledOnMS = mDefaultNotificationLedOn;
37523774 ledOffMS = mDefaultNotificationLedOff;
37533775 } else {
@@ -3809,6 +3831,36 @@ public class NotificationManagerService extends SystemService {
38093831 return mNotificationPulseCustomLedValues.get(mapPackage(packageName));
38103832 }
38113833
3834+ private int generateLedColorForNotification(NotificationRecord ledNotification) {
3835+ if (!mAutoGenerateNotificationColor) {
3836+ return mDefaultNotificationColor;
3837+ }
3838+ if (!mMultiColorNotificationLed) {
3839+ return mDefaultNotificationColor;
3840+ }
3841+ final String packageName = ledNotification.sbn.getPackageName();
3842+ final String mapping = mapPackage(packageName);
3843+ int color = mDefaultNotificationColor;
3844+
3845+ if (mGeneratedPackageLedColors.containsKey(mapping)) {
3846+ return mGeneratedPackageLedColors.get(mapping);
3847+ }
3848+
3849+ PackageManager pm = getContext().getPackageManager();
3850+ Drawable icon;
3851+ try {
3852+ icon = pm.getApplicationIcon(mapping);
3853+ } catch (NameNotFoundException e) {
3854+ Slog.e(TAG, e.getMessage(), e);
3855+ return color;
3856+ }
3857+
3858+ color = ColorUtils.generateAlertColorFromDrawable(icon);
3859+ mGeneratedPackageLedColors.put(mapping, color);
3860+
3861+ return color;
3862+ }
3863+
38123864 private String mapPackage(String pkg) {
38133865 if (!mPackageNameMappings.containsKey(pkg)) {
38143866 return pkg;