android动态修改屏幕亮度最大值

前言:本文所提出的方案主要通过动态修改lcd-backlight/max_brightness的值已满足动态调节屏幕最大亮度,从而降低耗电量。屏幕默认最大亮度为255时,功耗非常高,根据驱动提供的电池曲线,当屏幕最大亮度降低至原来的80%,功耗能降低原来的50%,故提出此方案解决功耗问题。

android原生系统有配置属性:


255

当我将此默认值调节至204时,拖动调节亮度的seekbar至最大亮度,然后通过adb获取:

adb shell cat /sys/class/leds/lcd-backlight/brightness

确实为204,默认的最大亮度改变了,但是有一个问题,无法动态修改了,因为开机通过config_screenBrightnessSettingMaximum初始化亮度调节的seekbar,最大值变为204了。
毕竟android也没有想到会有这种奇怪的需求吧。

那歪脑筋就动起来了,既然节点有max_brightness,那就动态改改看,一改居然有效。
那就整起来:

  1. SettingsProvider添加System类别的全局控制属性
Index: frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
===================================================================
--- frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java	(版本 1140)
+++ frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java	(版本 1143)
@@ -2325,6 +2325,9 @@
                     R.string.def_time_format);
             // @ 20190428 add. }
 
+            loadIntegerSetting(stmt, Settings.System.SCREEN_HIGH_BRIGHTNESS_MODE,
+                    R.integer.def_screen_high_brightness_mode);	// @ + for BUG #
+
             /*
              * IMPORTANT: Do not add any more upgrade steps here as the global,
              * secure, and system settings are no longer stored in a database
Index: frameworks/base/packages/SettingsProvider/res/values/defaults.xml
===================================================================
--- frameworks/base/packages/SettingsProvider/res/values/defaults.xml	(版本 1140)
+++ frameworks/base/packages/SettingsProvider/res/values/defaults.xml	(版本 1143)
@@ -230,5 +230,8 @@
     
     24
     
+    
+    
+    0
 
 
Index: frameworks/base/core/java/android/provider/Settings.java
===================================================================
--- frameworks/base/core/java/android/provider/Settings.java	(版本 1140)
+++ frameworks/base/core/java/android/provider/Settings.java	(版本 1143)
@@ -3231,6 +3231,13 @@
          */
         public static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1;
 
+        // @ + for BUG # {
+        public static final String SCREEN_HIGH_BRIGHTNESS_MODE = "screen_high_brightness_mode";
+        private static final Validator SCREEN_HIGH_BRIGHTNESS_MODE_VALIDATOR = BOOLEAN_VALIDATOR;
+        public static final int SCREEN_HIGH_BRIGHTNESS_MODE_OFF = 0;
+        public static final int S

你可能感兴趣的:(android_system,android)