import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.ContentObserver;
+import android.graphics.drawable.Drawable;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioManagerInternal;
import com.android.server.notification.ManagedServices.UserProfiles;
import cyanogenmod.providers.CMSettings;
+import cyanogenmod.util.ColorUtils;
import cyanogenmod.providers.CMSettings;
import libcore.io.IoUtils;
private boolean mMultipleNotificationLeds;
private boolean mMultipleLedsEnabledSetting = false;
+ private boolean mAutoGenerateNotificationColor = true;
+
private boolean mScreenOnEnabled = false;
private boolean mScreenOnDefault = false;
private boolean mNotificationPulseEnabled;
private ArrayMap<String, NotificationLedValues> mNotificationPulseCustomLedValues;
private Map<String, String> mPackageNameMappings;
+ private final ArrayMap<String, Integer> mGeneratedPackageLedColors =
+ new ArrayMap<String, Integer>();
// for checking lockscreen status
private KeyguardManager mKeyguardManager;
private ConditionProviders mConditionProviders;
private NotificationUsageStats mUsageStats;
+ private boolean mMultiColorNotificationLed;
+
private static final int MY_UID = Process.myUid();
private static final int MY_PID = Process.myPid();
private RankingHandler mRankingHandler;
resolver.registerContentObserver(CMSettings.System.getUriFor(
CMSettings.System.NOTIFICATION_LIGHT_SCREEN_ON),
false, this, UserHandle.USER_ALL);
+ resolver.registerContentObserver(CMSettings.System.getUriFor(
+ CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO), false,
+ this, UserHandle.USER_ALL);
if (mAdjustableNotificationLedBrightness) {
resolver.registerContentObserver(CMSettings.System.getUriFor(
CMSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL),
mNotificationPulseEnabled = Settings.System.getIntForUser(resolver,
Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0;
+ // Automatically pick a color for LED if not set
+ mAutoGenerateNotificationColor = CMSettings.System.getIntForUser(resolver,
+ CMSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO,
+ 1, UserHandle.USER_CURRENT) != 0;
+
// LED default color
mDefaultNotificationColor = CMSettings.System.getIntForUser(resolver,
CMSettings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR,
CMSettings.System.NOTIFICATION_LIGHT_PULSE_DEFAULT_LED_OFF,
mDefaultNotificationLedOff, UserHandle.USER_CURRENT);
+ // LED generated notification colors
+ mGeneratedPackageLedColors.clear();
+
// LED custom notification colors
mNotificationPulseCustomLedValues.clear();
if (CMSettings.System.getIntForUser(resolver,
mDefaultNotificationLedOff = resources.getInteger(
R.integer.config_defaultNotificationLedOff);
+ mMultiColorNotificationLed = resources.getBoolean(
+ R.bool.config_multiColorNotificationLed);
+
mNotificationPulseCustomLedValues = new ArrayMap<String, NotificationLedValues>();
mPackageNameMappings = new ArrayMap<String, String>();
ledOnMS = ledValues.onMS >= 0 ? ledValues.onMS : mDefaultNotificationLedOn;
ledOffMS = ledValues.offMS >= 0 ? ledValues.offMS : mDefaultNotificationLedOff;
} else if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
- ledARGB = mDefaultNotificationColor;
+ ledARGB = generateLedColorForNotification(ledNotification);
ledOnMS = mDefaultNotificationLedOn;
ledOffMS = mDefaultNotificationLedOff;
} else {
return mNotificationPulseCustomLedValues.get(mapPackage(packageName));
}
+ private int generateLedColorForNotification(NotificationRecord ledNotification) {
+ if (!mAutoGenerateNotificationColor) {
+ return mDefaultNotificationColor;
+ }
+ if (!mMultiColorNotificationLed) {
+ return mDefaultNotificationColor;
+ }
+ final String packageName = ledNotification.sbn.getPackageName();
+ final String mapping = mapPackage(packageName);
+ int color = mDefaultNotificationColor;
+
+ if (mGeneratedPackageLedColors.containsKey(mapping)) {
+ return mGeneratedPackageLedColors.get(mapping);
+ }
+
+ PackageManager pm = getContext().getPackageManager();
+ Drawable icon;
+ try {
+ icon = pm.getApplicationIcon(mapping);
+ } catch (NameNotFoundException e) {
+ Slog.e(TAG, e.getMessage(), e);
+ return color;
+ }
+
+ color = ColorUtils.generateAlertColorFromDrawable(icon);
+ mGeneratedPackageLedColors.put(mapping, color);
+
+ return color;
+ }
+
private String mapPackage(String pkg) {
if (!mPackageNameMappings.containsKey(pkg)) {
return pkg;