lineage-sdk: DnD light brightness control for battery and notifications
*) Support separate normal and dnd led brightness levels for battery and notifications. *) Move lineage-specific notification bundle extras definitions from fw/b to LineageNotification here in the sdk. *) In addition to the existing bundle extra EXTRA_FORCE_SHOW_LIGHTS, add a new extra EXTRA_FORCE_LIGHT_BRIGHTNESS that can be used to override the brightness level set by a Lineage system setting brightness level on a per notification basis. This is used by the brightness sliders in LineageParts that otherwise would have to juggle changing / restoring the system led brightness setting whenever the a slider is on display. *) Disable all lights in dnd mode when lineage setting ZEN_ALLOW_LIGHTS is set to 0. Change-Id: I917f402a291682b582f68c8324a33c461357dad9
This commit is contained in:
committed by
Bruno Martins
parent
a9aeed9a58
commit
c7a8ed54b5
@@ -790,6 +790,8 @@ package lineageos.providers {
|
||||
field public static final java.lang.String APP_SWITCH_WAKE_SCREEN = "app_switch_wake_screen";
|
||||
field public static final java.lang.String ASSIST_WAKE_SCREEN = "assist_wake_screen";
|
||||
field public static final java.lang.String BACK_WAKE_SCREEN = "back_wake_screen";
|
||||
field public static final java.lang.String BATTERY_LIGHT_BRIGHTNESS_LEVEL = "battery_light_brightness_level";
|
||||
field public static final java.lang.String BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN = "battery_light_brightness_level_zen";
|
||||
field public static final java.lang.String BATTERY_LIGHT_ENABLED = "battery_light_enabled";
|
||||
field public static final java.lang.String BATTERY_LIGHT_FULL_COLOR = "battery_light_full_color";
|
||||
field public static final java.lang.String BATTERY_LIGHT_LOW_COLOR = "battery_light_low_color";
|
||||
@@ -839,6 +841,7 @@ package lineageos.providers {
|
||||
field public static final java.lang.String NAVIGATION_BAR_MENU_ARROW_KEYS = "navigation_bar_menu_arrow_keys";
|
||||
field public static final java.lang.String NAV_BUTTONS = "nav_buttons";
|
||||
field public static final java.lang.String NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL = "notification_light_brightness_level";
|
||||
field public static final java.lang.String NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN = "notification_light_brightness_level_zen";
|
||||
field public static final java.lang.String NOTIFICATION_LIGHT_PULSE_CALL_COLOR = "notification_light_pulse_call_color";
|
||||
field public static final java.lang.String NOTIFICATION_LIGHT_PULSE_CALL_LED_OFF = "notification_light_pulse_call_led_off";
|
||||
field public static final java.lang.String NOTIFICATION_LIGHT_PULSE_CALL_LED_ON = "notification_light_pulse_call_led_on";
|
||||
|
||||
@@ -78,10 +78,22 @@
|
||||
<!-- Default for LineageSettings.Global.POWER_NOTIFICATIONS_RINGTONE -->
|
||||
<string name="def_power_notifications_ringtone" translatable="false">content://settings/system/notification_sound</string>
|
||||
|
||||
<!-- Default value for the battery LEDs brightness -->
|
||||
<integer name="def_battery_brightness_level">255</integer>
|
||||
|
||||
<!-- Default value for the notification LEDs brightness
|
||||
when Do Not Disturb is active -->
|
||||
<integer name="def_battery_brightness_level_zen">255</integer>
|
||||
|
||||
<!-- Default value for the notification LEDs brightness
|
||||
on devices equiped with configurable LED controller -->
|
||||
<integer name="def_notification_brightness_level">255</integer>
|
||||
|
||||
<!-- Default value for the notification LEDs brightness
|
||||
on devices equiped with configurable LED controller
|
||||
when Do Not Disturb is active -->
|
||||
<integer name="def_notification_brightness_level_zen">255</integer>
|
||||
|
||||
<!-- Default value for notification LED customization -->
|
||||
<bool name="def_notification_pulse_custom_enable">false</bool>
|
||||
<string name="def_notification_pulse_custom_value"></string>
|
||||
|
||||
@@ -395,9 +395,18 @@ public class LineageDatabaseHelper extends SQLiteOpenHelper{
|
||||
loadIntegerSetting(stmt, LineageSettings.System.STATUS_BAR_QUICK_QS_PULLDOWN,
|
||||
R.integer.def_qs_quick_pulldown);
|
||||
|
||||
loadIntegerSetting(stmt, LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL,
|
||||
R.integer.def_battery_brightness_level);
|
||||
|
||||
loadIntegerSetting(stmt, LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN,
|
||||
R.integer.def_battery_brightness_level_zen);
|
||||
|
||||
loadIntegerSetting(stmt, LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
|
||||
R.integer.def_notification_brightness_level);
|
||||
|
||||
loadIntegerSetting(stmt, LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN,
|
||||
R.integer.def_notification_brightness_level_zen);
|
||||
|
||||
loadBooleanSetting(stmt, LineageSettings.System.SYSTEM_PROFILES_ENABLED,
|
||||
R.bool.def_profiles_enabled);
|
||||
|
||||
|
||||
@@ -1657,6 +1657,25 @@ public final class LineageSettings {
|
||||
public static final Validator CALL_RECORDING_FORMAT_VALIDATOR =
|
||||
new InclusiveIntegerRangeValidator(0, 1);
|
||||
|
||||
/**
|
||||
* Contains the battery light maximum brightness to use.
|
||||
* Values range from 1 to 255
|
||||
*/
|
||||
public static final String BATTERY_LIGHT_BRIGHTNESS_LEVEL =
|
||||
"battery_light_brightness_level";
|
||||
|
||||
/**
|
||||
* Contains the battery light maximum brightness to use when Do Not
|
||||
* Disturb is active.
|
||||
* Values range from 1 to 255
|
||||
*/
|
||||
public static final String BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN =
|
||||
"battery_light_brightness_level_zen";
|
||||
|
||||
/** @hide */
|
||||
public static final Validator BATTERY_LIGHT_BRIGHTNESS_LEVEL_VALIDATOR =
|
||||
new InclusiveIntegerRangeValidator(1, 255);
|
||||
|
||||
/**
|
||||
* Contains the notifications light maximum brightness to use.
|
||||
* Values range from 1 to 255
|
||||
@@ -1664,6 +1683,14 @@ public final class LineageSettings {
|
||||
public static final String NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL =
|
||||
"notification_light_brightness_level";
|
||||
|
||||
/**
|
||||
* Contains the notifications light maximum brightness to use when Do Not
|
||||
* Disturb is active.
|
||||
* Values range from 1 to 255
|
||||
*/
|
||||
public static final String NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN =
|
||||
"notification_light_brightness_level_zen";
|
||||
|
||||
/** @hide */
|
||||
public static final Validator NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_VALIDATOR =
|
||||
new InclusiveIntegerRangeValidator(1, 255);
|
||||
@@ -2160,8 +2187,14 @@ public final class LineageSettings {
|
||||
USE_EDGE_SERVICE_FOR_GESTURES_VALIDATOR);
|
||||
VALIDATORS.put(STATUS_BAR_NOTIF_COUNT, STATUS_BAR_NOTIF_COUNT_VALIDATOR);
|
||||
VALIDATORS.put(CALL_RECORDING_FORMAT, CALL_RECORDING_FORMAT_VALIDATOR);
|
||||
VALIDATORS.put(BATTERY_LIGHT_BRIGHTNESS_LEVEL,
|
||||
BATTERY_LIGHT_BRIGHTNESS_LEVEL_VALIDATOR);
|
||||
VALIDATORS.put(BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN,
|
||||
BATTERY_LIGHT_BRIGHTNESS_LEVEL_VALIDATOR);
|
||||
VALIDATORS.put(NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
|
||||
NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_VALIDATOR);
|
||||
VALIDATORS.put(NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN,
|
||||
NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_VALIDATOR);
|
||||
VALIDATORS.put(NOTIFICATION_LIGHT_SCREEN_ON,
|
||||
NOTIFICATION_LIGHT_SCREEN_ON_VALIDATOR);
|
||||
VALIDATORS.put(NOTIFICATION_LIGHT_PULSE_DEFAULT_COLOR,
|
||||
|
||||
@@ -95,6 +95,24 @@ public class LedValues {
|
||||
mOffMs = offMs;
|
||||
}
|
||||
|
||||
public void applyAlphaToBrightness() {
|
||||
final int alpha = (mColor >> 24) & 0xFF;
|
||||
if (alpha > 0 && alpha < 255) {
|
||||
mBrightness = mBrightness * alpha / 255;
|
||||
}
|
||||
mColor |= 0xFF000000;
|
||||
}
|
||||
|
||||
public void applyBrightnessToColor() {
|
||||
if (mBrightness > 0 && mBrightness < 255) {
|
||||
int red = ((mColor >> 16) & 0xFF) * mBrightness / 255;
|
||||
int green = ((mColor >> 8) & 0xFF) * mBrightness / 255;
|
||||
int blue = (mColor & 0xFF) * mBrightness / 255;
|
||||
mColor = (red << 16) | (green << 8) | blue;
|
||||
mBrightness = 255;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "enabled=" + mEnabled + " color=#" + String.format("%08X", mColor)
|
||||
|
||||
@@ -16,13 +16,18 @@
|
||||
|
||||
package org.lineageos.internal.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings.Global;
|
||||
import android.util.Slog;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
@@ -45,9 +50,14 @@ public final class LineageBatteryLights {
|
||||
private int mBatteryLowARGB;
|
||||
private int mBatteryMediumARGB;
|
||||
private int mBatteryFullARGB;
|
||||
private int mBatteryBrightness;
|
||||
private int mBatteryBrightnessZen;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private NotificationManager mNotificationManager;
|
||||
private int mZenMode;
|
||||
|
||||
public interface LedUpdater {
|
||||
public void update();
|
||||
}
|
||||
@@ -70,6 +80,19 @@ public final class LineageBatteryLights {
|
||||
mUseSegmentedBatteryLed = LightsCapabilities.supports(
|
||||
mContext, LightsCapabilities.LIGHTS_SEGMENTED_BATTERY_LED);
|
||||
|
||||
// Watch for zen mode changes
|
||||
mNotificationManager = mContext.getSystemService(NotificationManager.class);
|
||||
IntentFilter filter = new IntentFilter(
|
||||
NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
|
||||
context.registerReceiver(new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mZenMode = mNotificationManager.getZenMode();
|
||||
mLedUpdater.update();
|
||||
}
|
||||
}, filter);
|
||||
mZenMode = mNotificationManager.getZenMode();
|
||||
|
||||
SettingsObserver observer = new SettingsObserver(new Handler());
|
||||
observer.observe();
|
||||
}
|
||||
@@ -93,8 +116,17 @@ public final class LineageBatteryLights {
|
||||
return;
|
||||
}
|
||||
|
||||
ledValues.setBrightness(mUseSegmentedBatteryLed ?
|
||||
level : LedValues.LIGHT_BRIGHTNESS_MAXIMUM);
|
||||
final int brightness;
|
||||
if (mUseSegmentedBatteryLed) {
|
||||
brightness = level;
|
||||
} else if (!mMultiColorLed) {
|
||||
brightness = LedValues.LIGHT_BRIGHTNESS_MAXIMUM;
|
||||
} else if (mZenMode == Global.ZEN_MODE_OFF) {
|
||||
brightness = mBatteryBrightness;
|
||||
} else {
|
||||
brightness = mBatteryBrightnessZen;
|
||||
}
|
||||
ledValues.setBrightness(brightness);
|
||||
|
||||
if (low) {
|
||||
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
|
||||
@@ -123,6 +155,17 @@ public final class LineageBatteryLights {
|
||||
if (ledValues.getColor() != 0) {
|
||||
ledValues.setEnabled(true);
|
||||
}
|
||||
// Apply brightness level to color value.
|
||||
if (mMultiColorLed) {
|
||||
ledValues.applyAlphaToBrightness();
|
||||
ledValues.applyBrightnessToColor();
|
||||
// If LED is segmented, reset brightness field to battery level
|
||||
// (applyBrightnessToColor() changes it to 255)
|
||||
if (mUseSegmentedBatteryLed) {
|
||||
ledValues.setBrightness(brightness);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Slog.i(TAG, "calcLights output: ledValues={ " + ledValues + " }");
|
||||
}
|
||||
@@ -146,8 +189,8 @@ public final class LineageBatteryLights {
|
||||
LineageSettings.System.BATTERY_LIGHT_PULSE), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
|
||||
// Light colors
|
||||
if (mMultiColorLed) {
|
||||
// Light colors
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.BATTERY_LIGHT_LOW_COLOR), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
@@ -157,6 +200,14 @@ public final class LineageBatteryLights {
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.BATTERY_LIGHT_FULL_COLOR), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
// Battery brightness level
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
// Battery brightness level in Do Not Disturb mode
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -190,6 +241,17 @@ public final class LineageBatteryLights {
|
||||
LineageSettings.System.BATTERY_LIGHT_FULL_COLOR, res.getInteger(
|
||||
com.android.internal.R.integer.config_notificationsBatteryFullARGB));
|
||||
|
||||
if (mMultiColorLed) {
|
||||
// Battery brightness level
|
||||
mBatteryBrightness = LineageSettings.System.getInt(resolver,
|
||||
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL,
|
||||
LedValues.LIGHT_BRIGHTNESS_MAXIMUM);
|
||||
// Battery brightness level in Do Not Disturb mode
|
||||
mBatteryBrightnessZen = LineageSettings.System.getInt(resolver,
|
||||
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN,
|
||||
LedValues.LIGHT_BRIGHTNESS_MAXIMUM);
|
||||
}
|
||||
|
||||
mLedUpdater.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (C) 2017 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.lineageos.internal.notification;
|
||||
|
||||
public class LineageNotification {
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// Lineage-specific Notification bundle extras
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Used by light picker in Settings to force
|
||||
* notification lights on when screen is on.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_SHOW_LIGHTS = "lineage.forceShowLights";
|
||||
|
||||
/**
|
||||
* Used by light picker in Settings to force
|
||||
* a specific light brightness.
|
||||
*/
|
||||
public static final String EXTRA_FORCE_LIGHT_BRIGHTNESS = "lineage.forceLightBrightness";
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Slog;
|
||||
@@ -41,6 +42,7 @@ import lineageos.util.ColorUtils;
|
||||
|
||||
import org.lineageos.internal.notification.LedValues;
|
||||
import org.lineageos.internal.notification.LightsCapabilities;
|
||||
import org.lineageos.internal.notification.LineageNotification;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -49,13 +51,20 @@ public final class LineageNotificationLights {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
// Light capabilities
|
||||
private boolean mAdjustableNotificationLedBrightness;
|
||||
// Whether the notification light is RGB adjustable.
|
||||
private boolean mMultiColorNotificationLed;
|
||||
// Whether the lights HAL supports changing brightness.
|
||||
private boolean mHALAdjustableBrightness;
|
||||
// Whether the light should be considered brightness adjustable
|
||||
// (via HAL or via modifying RGB values).
|
||||
private boolean mCanAdjustBrightness;
|
||||
|
||||
// Light config
|
||||
private boolean mAutoGenerateNotificationColor;
|
||||
private boolean mScreenOnEnabled;
|
||||
private boolean mZenAllowLights;
|
||||
private int mNotificationLedBrightnessLevel;
|
||||
private int mNotificationLedBrightnessLevelZen;
|
||||
private int mDefaultNotificationColor;
|
||||
private int mDefaultNotificationLedOn;
|
||||
private int mDefaultNotificationLedOff;
|
||||
@@ -65,6 +74,8 @@ public final class LineageNotificationLights {
|
||||
private final ArrayMap<String, Integer> mGeneratedPackageLedColors =
|
||||
new ArrayMap<String, Integer>();
|
||||
|
||||
private int mZenMode;
|
||||
|
||||
// For checking lockscreen status
|
||||
private KeyguardManager mKeyguardManager;
|
||||
|
||||
@@ -83,7 +94,7 @@ public final class LineageNotificationLights {
|
||||
|
||||
final Resources res = mContext.getResources();
|
||||
|
||||
mAdjustableNotificationLedBrightness = LightsCapabilities.supports(
|
||||
mHALAdjustableBrightness = LightsCapabilities.supports(
|
||||
mContext, LightsCapabilities.LIGHTS_ADJUSTABLE_NOTIFICATION_LED_BRIGHTNESS);
|
||||
|
||||
mDefaultNotificationColor = res.getColor(
|
||||
@@ -96,6 +107,10 @@ public final class LineageNotificationLights {
|
||||
mMultiColorNotificationLed = LightsCapabilities.supports(
|
||||
mContext, LightsCapabilities.LIGHTS_RGB_NOTIFICATION_LED);
|
||||
|
||||
// We support brightness adjustment if either the HAL supports it
|
||||
// or the light is RGB adjustable.
|
||||
mCanAdjustBrightness = mHALAdjustableBrightness || mMultiColorNotificationLed;
|
||||
|
||||
mNotificationPulseCustomLedValues = new ArrayMap<String, LedValues>();
|
||||
|
||||
mPackageNameMappings = new ArrayMap<String, String>();
|
||||
@@ -197,27 +212,69 @@ public final class LineageNotificationLights {
|
||||
return mPackageNameMappings.get(pkg);
|
||||
}
|
||||
|
||||
public boolean isForcedOn(Notification n) {
|
||||
if (n.extras != null) {
|
||||
return n.extras.getBoolean(LineageNotification.EXTRA_FORCE_SHOW_LIGHTS, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getForcedBrightness(Notification n) {
|
||||
if (n.extras != null) {
|
||||
return n.extras.getInt(LineageNotification.EXTRA_FORCE_LIGHT_BRIGHTNESS, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setZenMode(int zenMode) {
|
||||
mZenMode = zenMode;
|
||||
mLedUpdater.update();
|
||||
}
|
||||
|
||||
// Called by NotificationManagerService updateLightsLocked().
|
||||
// Takes the lights values as requested by a notification and
|
||||
// updates them according to the active Lineage feature settings.
|
||||
public void calcLights(LedValues ledValues, String packageName, boolean forcedOn,
|
||||
boolean screenOn, boolean inCall, boolean isDefaultLights, int suppressedEffects) {
|
||||
if (DEBUG) {
|
||||
Slog.i(TAG, "calcLights input: ledValues={ " + ledValues + " } packageName="
|
||||
+ packageName + " forcedOn=" + forcedOn + " screenOn=" + screenOn
|
||||
+ " inCall=" + inCall + " isDefaultLights=" + isDefaultLights
|
||||
+ " suppressedEffects=" + suppressedEffects);
|
||||
}
|
||||
|
||||
public void calcLights(LedValues ledValues, String packageName, Notification n,
|
||||
boolean screenActive, int suppressedEffects) {
|
||||
final boolean forcedOn = isForcedOn(n);
|
||||
final int forcedBrightness = getForcedBrightness(n);
|
||||
final boolean isDefaultLights = (n.defaults & Notification.DEFAULT_LIGHTS) != 0;
|
||||
final boolean suppressScreenOff =
|
||||
(suppressedEffects & SUPPRESSED_EFFECT_SCREEN_OFF) != 0;
|
||||
final boolean suppressScreenOn =
|
||||
(suppressedEffects & SUPPRESSED_EFFECT_SCREEN_ON) != 0;
|
||||
final boolean screenActive = screenOn || inCall;
|
||||
|
||||
if (DEBUG) {
|
||||
Slog.i(TAG, "calcLights input: "
|
||||
+ " ledValues={ " + ledValues + " }"
|
||||
+ " packageName=" + packageName
|
||||
+ " notification=" + n
|
||||
+ " screenActive=" + screenActive
|
||||
+ " suppressedEffects=" + suppressedEffects
|
||||
+ " forcedOn=" + forcedOn
|
||||
+ " forcedBrightness=" + forcedBrightness
|
||||
+ " isDefaultLights=" + isDefaultLights
|
||||
+ " suppressScreenOff=" + suppressScreenOff
|
||||
+ " suppressScreenOn=" + suppressScreenOn
|
||||
+ " mCanAdjustBrightness=" + mCanAdjustBrightness
|
||||
+ " mHALAdjustableBrightness=" + mHALAdjustableBrightness
|
||||
+ " mAutoGenerateNotificationColor=" + mAutoGenerateNotificationColor
|
||||
+ " mMultiColorNotificationLed=" + mMultiColorNotificationLed
|
||||
+ " mNotificationLedBrightnessLevel=" + mNotificationLedBrightnessLevel
|
||||
+ " mNotificationLedBrightnessLevelZen=" + mNotificationLedBrightnessLevelZen
|
||||
+ " mScreenOnEnabled= " + mScreenOnEnabled
|
||||
+ " mZenAllowLights=" + mZenAllowLights
|
||||
+ " mZenMode=" + mZenMode
|
||||
);
|
||||
}
|
||||
|
||||
final boolean enableLed;
|
||||
if (forcedOn) {
|
||||
// Forced on always enables
|
||||
enableLed = true;
|
||||
} else if (!mZenAllowLights && mZenMode != Global.ZEN_MODE_OFF) {
|
||||
// DnD configured to disable lights in all modes (except when off).
|
||||
enableLed = false;
|
||||
} else if (screenActive && (!mScreenOnEnabled || suppressScreenOn)) {
|
||||
// Screen on cases where we disable
|
||||
enableLed = false;
|
||||
@@ -233,8 +290,18 @@ public final class LineageNotificationLights {
|
||||
return;
|
||||
}
|
||||
|
||||
ledValues.setBrightness(mAdjustableNotificationLedBrightness ?
|
||||
mNotificationLedBrightnessLevel : LedValues.LIGHT_BRIGHTNESS_MAXIMUM);
|
||||
final int brightness;
|
||||
if (!mCanAdjustBrightness) {
|
||||
// No brightness support available
|
||||
brightness = LedValues.LIGHT_BRIGHTNESS_MAXIMUM;
|
||||
} else if (forcedBrightness > 0) {
|
||||
brightness = forcedBrightness;
|
||||
} else if (mZenMode == Global.ZEN_MODE_OFF) {
|
||||
brightness = mNotificationLedBrightnessLevel;
|
||||
} else {
|
||||
brightness = mNotificationLedBrightnessLevelZen;
|
||||
}
|
||||
ledValues.setBrightness(brightness);
|
||||
|
||||
final LedValues ledValuesPkg = getLedValuesForPackageName(packageName);
|
||||
|
||||
@@ -251,6 +318,12 @@ public final class LineageNotificationLights {
|
||||
ledValues.setOnMs(mDefaultNotificationLedOn);
|
||||
ledValues.setOffMs(mDefaultNotificationLedOff);
|
||||
}
|
||||
// If lights HAL does not support adjustable notification brightness then
|
||||
// scale color value here instead.
|
||||
if (mCanAdjustBrightness && !mHALAdjustableBrightness) {
|
||||
ledValues.applyAlphaToBrightness();
|
||||
ledValues.applyBrightnessToColor();
|
||||
}
|
||||
if (DEBUG) {
|
||||
Slog.i(TAG, "calcLights output: ledValues={ " + ledValues + " }");
|
||||
}
|
||||
@@ -285,12 +358,20 @@ public final class LineageNotificationLights {
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO), false,
|
||||
this, UserHandle.USER_ALL);
|
||||
if (mAdjustableNotificationLedBrightness) {
|
||||
|
||||
if (mCanAdjustBrightness) {
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL),
|
||||
false, this, UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN),
|
||||
false, this, UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
resolver.registerContentObserver(LineageSettings.System.getUriFor(
|
||||
LineageSettings.System.ZEN_ALLOW_LIGHTS), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -336,18 +417,27 @@ public final class LineageNotificationLights {
|
||||
UserHandle.USER_CURRENT));
|
||||
}
|
||||
|
||||
// Notification LED brightness
|
||||
if (mAdjustableNotificationLedBrightness) {
|
||||
mNotificationLedBrightnessLevel = LineageSettings.System.getIntForUser(resolver,
|
||||
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
|
||||
LedValues.LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
// Notification lights with screen on
|
||||
mScreenOnEnabled = (LineageSettings.System.getIntForUser(resolver,
|
||||
LineageSettings.System.NOTIFICATION_LIGHT_SCREEN_ON, 0,
|
||||
UserHandle.USER_CURRENT) != 0);
|
||||
|
||||
// Adustable notification LED brightness.
|
||||
if (mCanAdjustBrightness) {
|
||||
// Normal brightness.
|
||||
mNotificationLedBrightnessLevel = LineageSettings.System.getIntForUser(resolver,
|
||||
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
|
||||
LedValues.LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
|
||||
// Brightness in Do Not Disturb mode.
|
||||
mNotificationLedBrightnessLevelZen = LineageSettings.System.getIntForUser(
|
||||
resolver, LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN,
|
||||
LedValues.LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
mZenAllowLights = LineageSettings.System.getIntForUser(resolver,
|
||||
LineageSettings.System.ZEN_ALLOW_LIGHTS,
|
||||
1, UserHandle.USER_CURRENT) != 0;
|
||||
|
||||
mLedUpdater.update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user