问题描述: 省电模式下调节背光亮度后重启手机,背光亮度恢复默认。
分析过程:
正常的情况下是只要是进入省电模式都会用一个小于 1 的系数去乘以背景光亮度 screenBrightness ,这
样背景光亮度就会变暗,退出省电模式就会 reset 这个背景光的亮度。
此 bug 是因为在省电模式下重启并没有在 reset 后 set ,而是在 set 的基础上又 set 了一次,如果在省电模
式下反复重启,就会反复 set ,导致屏幕越来越暗。
解决方案:
加一个标记,标记是在省电模式下重启,如果是在省电模式下重启就不用再 set.
diff --git a/services/core/java/com/android/server/power/PowerSaveModeController.javab/services/core/java/com/android/server/power/PowerSaveModeController.java
index b3b7275..7082f01 100644
--- a/services/core/java/com/android/server/power/PowerSaveModeController.java
+++ b/services/core/java/com/android/server/power/PowerSaveModeController.java
@@ -345,10 +345,17 @@ public class PowerSaveModeController extends BroadcastReceiver {
saveConfig(LAST_SCREEN_BRIGHTNESS_MODEL, screenMode);
saveConfig(LAST_SCREEN_BRIGHTNESS, screenBrightness);
-
- int brightness = screenBrightness
+ int brightness;
+ if (SystemProperties.getBoolean("persist.sys.power.save",false)) {
+
brightness = screenBrightness;
+
} else {
+
brightness = screenBrightness
* (getMaxScreenLightPowerSave() - getMinScreenLight())
/ (DEFAULT_MAX_SCREEN_BRIGHTNESS - getMinScreenLight());
+ } + //int brightness = screenBrightness
+ // * (getMaxScreenLightPowerSave() - getMinScreenLight())
+ // / (DEFAULT_MAX_SCREEN_BRIGHTNESS - getMinScreenLight());
if (DEBUG_VALUE)
Log.d(LOG_TAG, "setScreenLight - CurrentscreenMode is " + screenMode
@@ -359,9 +366,11 @@ public class PowerSaveModeController extends BroadcastReceiver {
DEFAULT_SCREEN_BRIGHTNESS_MODE);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS,
brightness);
+
SystemProperties.set("persist.sys.power.save","true");
}private void resetScreenLight() {
+
SystemProperties.set("persist.sys.power.save","false");
if (DEBUG_PROCESS)
Log.d(LOG_TAG, "resetScreenLight");
分析过程:
正常的情况下是只要是进入省电模式都会用一个小于 1 的系数去乘以背景光亮度 screenBrightness ,这
样背景光亮度就会变暗,退出省电模式就会 reset 这个背景光的亮度。
此 bug 是因为在省电模式下重启并没有在 reset 后 set ,而是在 set 的基础上又 set 了一次,如果在省电模
式下反复重启,就会反复 set ,导致屏幕越来越暗。
解决方案:
加一个标记,标记是在省电模式下重启,如果是在省电模式下重启就不用再 set.
diff --git a/services/core/java/com/android/server/power/PowerSaveModeController.javab/services/core/java/com/android/server/power/PowerSaveModeController.java
index b3b7275..7082f01 100644
--- a/services/core/java/com/android/server/power/PowerSaveModeController.java
+++ b/services/core/java/com/android/server/power/PowerSaveModeController.java
@@ -345,10 +345,17 @@ public class PowerSaveModeController extends BroadcastReceiver {
saveConfig(LAST_SCREEN_BRIGHTNESS_MODEL, screenMode);
saveConfig(LAST_SCREEN_BRIGHTNESS, screenBrightness);
-
- int brightness = screenBrightness
+ int brightness;
+ if (SystemProperties.getBoolean("persist.sys.power.save",false)) {
+
brightness = screenBrightness;
+
} else {
+
brightness = screenBrightness
* (getMaxScreenLightPowerSave() - getMinScreenLight())
/ (DEFAULT_MAX_SCREEN_BRIGHTNESS - getMinScreenLight());
+ } + //int brightness = screenBrightness
+ // * (getMaxScreenLightPowerSave() - getMinScreenLight())
+ // / (DEFAULT_MAX_SCREEN_BRIGHTNESS - getMinScreenLight());
if (DEBUG_VALUE)
Log.d(LOG_TAG, "setScreenLight - CurrentscreenMode is " + screenMode
@@ -359,9 +366,11 @@ public class PowerSaveModeController extends BroadcastReceiver {
DEFAULT_SCREEN_BRIGHTNESS_MODE);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS,
brightness);
+
SystemProperties.set("persist.sys.power.save","true");
}private void resetScreenLight() {
+
SystemProperties.set("persist.sys.power.save","false");
if (DEBUG_PROCESS)
Log.d(LOG_TAG, "resetScreenLight");