frameworks/base
修訂 | 33086de92a6d1a06e0203ba17de6fe74f5d7a413 (tree) |
---|---|
時間 | 2016-10-05 20:38:59 |
作者 | Steve Kondik <steve@cyng...> |
Commiter | Steve Kondik |
lights: Automatically generate an LED color for notifications
Change-Id: I7288e52499819a6a6c75ed9d9ba7cfa1b13c5669
nms: Only generate LED colors if the device has a multicolored LED
Change-Id: Iedfceba6bfc86b2761d8af57ecab51026bfa4c19
@@ -80,6 +80,7 @@ import android.content.pm.ParceledListSlice; | ||
80 | 80 | import android.content.pm.UserInfo; |
81 | 81 | import android.content.res.Resources; |
82 | 82 | import android.database.ContentObserver; |
83 | +import android.graphics.drawable.Drawable; | |
83 | 84 | import android.media.AudioAttributes; |
84 | 85 | import android.media.AudioManager; |
85 | 86 | import android.media.AudioManagerInternal; |
@@ -147,6 +148,7 @@ import com.android.server.vr.VrManagerInternal; | ||
147 | 148 | import com.android.server.notification.ManagedServices.UserProfiles; |
148 | 149 | |
149 | 150 | import cyanogenmod.providers.CMSettings; |
151 | +import cyanogenmod.util.ColorUtils; | |
150 | 152 | |
151 | 153 | import cyanogenmod.providers.CMSettings; |
152 | 154 | import libcore.io.IoUtils; |
@@ -262,6 +264,8 @@ public class NotificationManagerService extends SystemService { | ||
262 | 264 | private boolean mMultipleNotificationLeds; |
263 | 265 | private boolean mMultipleLedsEnabledSetting = false; |
264 | 266 | |
267 | + private boolean mAutoGenerateNotificationColor = true; | |
268 | + | |
265 | 269 | private boolean mScreenOnEnabled = false; |
266 | 270 | private boolean mScreenOnDefault = false; |
267 | 271 |
@@ -286,6 +290,8 @@ public class NotificationManagerService extends SystemService { | ||
286 | 290 | private boolean mNotificationPulseEnabled; |
287 | 291 | private ArrayMap<String, NotificationLedValues> mNotificationPulseCustomLedValues; |
288 | 292 | private Map<String, String> mPackageNameMappings; |
293 | + private final ArrayMap<String, Integer> mGeneratedPackageLedColors = | |
294 | + new ArrayMap<String, Integer>(); | |
289 | 295 | |
290 | 296 | // for checking lockscreen status |
291 | 297 | private KeyguardManager mKeyguardManager; |
@@ -324,6 +330,8 @@ public class NotificationManagerService extends SystemService { | ||
324 | 330 | private ConditionProviders mConditionProviders; |
325 | 331 | private NotificationUsageStats mUsageStats; |
326 | 332 | |
333 | + private boolean mMultiColorNotificationLed; | |
334 | + | |
327 | 335 | private static final int MY_UID = Process.myUid(); |
328 | 336 | private static final int MY_PID = Process.myPid(); |
329 | 337 | private RankingHandler mRankingHandler; |
@@ -892,6 +900,9 @@ public class NotificationManagerService extends SystemService { | ||
892 | 900 | resolver.registerContentObserver(CMSettings.System.getUriFor( |
893 | 901 | CMSettings.System.NOTIFICATION_LIGHT_SCREEN_ON), |
894 | 902 | false, this, UserHandle.USER_ALL); |
903 | + resolver.registerContentObserver(CMSettings.System.getUriFor( | |
904 | + CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO), false, | |
905 | + this, UserHandle.USER_ALL); | |
895 | 906 | if (mAdjustableNotificationLedBrightness) { |
896 | 907 | resolver.registerContentObserver(CMSettings.System.getUriFor( |
897 | 908 | CMSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL), |
@@ -916,6 +927,11 @@ public class NotificationManagerService extends SystemService { | ||
916 | 927 | mNotificationPulseEnabled = Settings.System.getIntForUser(resolver, |
917 | 928 | Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0; |
918 | 929 | |
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 | + | |
919 | 935 | // LED default color |
920 | 936 | mDefaultNotificationColor = CMSettings.System.getIntForUser(resolver, |
921 | 937 | CMSettings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR, |
@@ -931,6 +947,9 @@ public class NotificationManagerService extends SystemService { | ||
931 | 947 | CMSettings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_OFF, |
932 | 948 | mDefaultNotificationLedOff, UserHandle.USER_CURRENT); |
933 | 949 | |
950 | + // LED generated notification colors | |
951 | + mGeneratedPackageLedColors.clear(); | |
952 | + | |
934 | 953 | // LED custom notification colors |
935 | 954 | mNotificationPulseCustomLedValues.clear(); |
936 | 955 | if (CMSettings.System.getIntForUser(resolver, |
@@ -1104,6 +1123,9 @@ public class NotificationManagerService extends SystemService { | ||
1104 | 1123 | mDefaultNotificationLedOff = resources.getInteger( |
1105 | 1124 | R.integer.config_defaultNotificationLedOff); |
1106 | 1125 | |
1126 | + mMultiColorNotificationLed = resources.getBoolean( | |
1127 | + R.bool.config_multiColorNotificationLed); | |
1128 | + | |
1107 | 1129 | mNotificationPulseCustomLedValues = new ArrayMap<String, NotificationLedValues>(); |
1108 | 1130 | |
1109 | 1131 | mPackageNameMappings = new ArrayMap<String, String>(); |
@@ -3747,7 +3769,7 @@ public class NotificationManagerService extends SystemService { | ||
3747 | 3769 | ledOnMS = ledValues.onMS >= 0 ? ledValues.onMS : mDefaultNotificationLedOn; |
3748 | 3770 | ledOffMS = ledValues.offMS >= 0 ? ledValues.offMS : mDefaultNotificationLedOff; |
3749 | 3771 | } else if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) { |
3750 | - ledARGB = mDefaultNotificationColor; | |
3772 | + ledARGB = generateLedColorForNotification(ledNotification); | |
3751 | 3773 | ledOnMS = mDefaultNotificationLedOn; |
3752 | 3774 | ledOffMS = mDefaultNotificationLedOff; |
3753 | 3775 | } else { |
@@ -3809,6 +3831,36 @@ public class NotificationManagerService extends SystemService { | ||
3809 | 3831 | return mNotificationPulseCustomLedValues.get(mapPackage(packageName)); |
3810 | 3832 | } |
3811 | 3833 | |
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 | + | |
3812 | 3864 | private String mapPackage(String pkg) { |
3813 | 3865 | if (!mPackageNameMappings.containsKey(pkg)) { |
3814 | 3866 | return pkg; |