自动亮度

 

一.自动亮度流程图:

自动亮度_第1张图片

主要的过程就是通过监听light sensor数据,得到对应的Lux值,再通过配置的"lux-亮度关系"表计算出当前的亮度,然后设置亮度值。

sensor改变设置自动亮度:

mScreenAutoBrightness

updateAutoBrightness:705, AutomaticBrightnessController (com.android.server.display)
updateAmbientLux:665, AutomaticBrightnessController (com.android.server.display)
handleLightSensorEvent:443, AutomaticBrightnessController (com.android.server.display)
access$500:45, AutomaticBrightnessController (com.android.server.display)
onSensorChanged:806, AutomaticBrightnessController$1 (com.android.server.display)
dispatchSensorEvent:835, SystemSensorManager$SensorEventQueue (android.hardware)
nativePollOnce:-1, MessageQueue (android.os)
next:326, MessageQueue (android.os)
loop:165, Looper (android.os)
run:65, HandlerThread (android.os)
run:44, ServiceThread (com.android.server)

AutomaticBrightnessController->onSensorChanged监听亮度变化

设置亮度方法:

com/android/server/display/LocalDisplayAdapter.java

                    private void setDisplayBrightness(int brightness) {
                        if (DEBUG) {
                            Slog.d(TAG, "setDisplayBrightness("
                                    + "id=" + displayId + ", brightness=" + brightness + ")");
                        }

                        Trace.traceBegin(Trace.TRACE_TAG_POWER, "setDisplayBrightness("
                                + "id=" + displayId + ", brightness=" + brightness + ")");
                        try {
                            mBacklight.setBrightness(brightness);
                            Trace.traceCounter(Trace.TRACE_TAG_POWER,
                                    "ScreenBrightness", brightness);
                        } finally {
                            Trace.traceEnd(Trace.TRACE_TAG_POWER);
                        }
                    }

mBacklight.setBrightness(brightness);

 

log:

 

logcat -s AutomaticBrightnessController

01-10 20:23:17.782 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=7, newScreenAutoBrightness=2047

01-10 20:23:18.984 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=2047, newScreenAutoBrightness=583

01-10 20:23:19.846 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=583, newScreenAutoBrightness=195

01-10 20:23:20.488 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=195, newScreenAutoBrightness=10

01-10 20:23:21.313 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=10, newScreenAutoBrightness=1654

01-10 20:23:22.176 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=1654, newScreenAutoBrightness=1664

01-10 20:23:50.023 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=-1, newScreenAutoBrightness=1765

01-10 20:23:50.715 1534 1592 D AutomaticBrightnessController: updateAutoBrightness: mScreenAutoBrightness=1765, newScreenAutoBrightness=1716

 

自动亮度_第2张图片

 

未完。。。。

 

 

你可能感兴趣的:(安卓系统)