Automatic screen brightness adjustment :
Mainly from the sensor analysis of the separation of light ray sensors, therefore, the analysis of the automatic adjustment of the screen brightness (mobile phone with the intensity of the light self-regulation, that is, in the light of the screen automatically light some, dark when the automatic dimming some, save light on the eyes have stimulation) ...
(I know the process from the setbacks), now began to talk about the flow, if there is no place to want the cattle to point out ...
Start with the sttings, in the diaplay screen brightness adjustment, there is a progress, there is a checkbox above (automatically adjust the brightness of the screen),
Then of course we go to look for the files under the settings, and first find
Diaplaysettings.java files and display_setting.xml files, Display_setting.xml can find the appropriate components, but The code that calls the corresponding component cannot be found in the Diaplaysettings.java file.
Then we go to the settings, to find Brightnesspreference.java files, yes this file is automatically adjust the brightness of the file, we first look at the code:
The constructor has mautomaticavailable = Context.getresources (). Getboolean (Com.android.internal.r.bool.config_automatic_ brightness_available);
Starting to think that the value of MAUTOMATICAVAILABL (true, in Config.xml) is to determine whether the brightness is automatically adjusted, because in my follow-up to Powermanagerservice.java, in Initinthread ()
Musesoftwareautobrightness = Resources.getboolean (
com.android.internal.r.bool.config_automatic_brightness_available);
if (musesoftwareautobrightness) {
Mautobrightnesslevels = Resources.getintarray (
Com.android.internal.r.array.config_autobrightnesslevels)//The value of the Automatically adjusted call Getautobrightnessvalue (int sensorValue, Int[] Values) method
Mlcdbacklightvalues = Resources.getintarray (
Com.android.internal.r.array.config_autobrightnesslcdbacklightvalues);
Mbuttonbacklightvalues = Resources.getintarray (
Com.android.internal.r.array.config_autobrightnessbuttonbacklightvalues);
Mkeyboardbacklightvalues = Resources.getintarray (.....)
。。。。。。 It looks as if the value of the Config.xml file Config_autobrightnesslevels is obtained when musesoftwareautobrightness is true, and then automatically adjusts according to the light. But the value of Mautomaticavailabl only indicates that there is no automatic adjustment of the screen function (for example, you will change the Config.xml file config_automatic_brightness_available value to False, Compilation substitution framework-res.apk A checkbox that does not automatically adjust in screen brightness adjustment, which also explains the value that the constructor initializes mautomaticavailabl at the outset.
Next, there are Onprogresschanged,onstarttrackingtouch (SeekBar SeekBar) in the Brightnesspreference.java file, Onstoptrackingtouch ( SeekBar SeekBar) method, these can be understood at a glance is not introduced, in the Onbinddialogview (View view) method has
Mcheckbox = (CheckBox) View.findviewbyid (R.id.automatic_mode);
if (mautomaticavailable) {//when there is an automatic tuning function
Mcheckbox.setoncheckedchangelistener (this);//Add a listener event for a checkbox
try {
Moldautomatic = Settings.System.getInt (GetContext (). Getcontentresolver (),
Settings.System.SCREEN_BRIGHTNESS_MODE);
。。。。。。
mainly see public void oncheckedchanged (Compoundbutton buttonview, Boolean ischecked) {
SetMode (ischecked?) Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
: Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
if (!ischecked) {
Setbrightness (mseekbar.getprogress () + minimum_backlight);
}
}
This is where you choose to automatically adjust the brightness of the checkbox, if selected then SetMode (Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC), and the data into the database.
Here's the point: there's a database that jumps to when the values in the database change to Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC.
Powermanagerservice.java Initinthread () in Contentresolver resolver = Mcontext.getcontentresolver ();
Cursor settingscursor = resolver.query (Settings.System.CONTENT_URI, NULL,
"(" + Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?) or ("
+ Settings.System.NAME + "=?)",
New string[]{stay_on_while_plugged_in, Screen_off_timeout, Dim_screen, Xec_dls_control,
Screen_brightness_mode, Window_animation_scale, Transition_animation_scale},
NULL);
Msettings = new Contentquerymap (Settingscursor, Settings.System.NAME, True, Mhandler);
Settingsobserver settingsobserver = new Settingsobserver ();
Msettings.addobserver (Settingsobserver);
Triggers events that occur when data in the database changes.
Systemready () in Powermanagerservice.java () (only once on the power-on call is no longer called)
if (musesoftwareautobrightness) {
LOG.I ("Frist", "frist=" + "AAAA");
Mlightsensor = Msensormanager.getdefaultsensor (sensor.type_light);
Enablelightsensor (TRUE);
}
And musesoftwareautobrightness is the true value in the Initinthread () thread, then to Enablelightsensor (true); method to see
if (enable) {
Msensormanager.registerlistener (Mlightlistener, Mlightsensor,
Sensormanager.sensor_delay_normal);
}
If the value passed is true, that is, the enable=true is listening and using an inductive sensor_delay_normal that matches the change in the screen direction.
Then look at the Mlightlistener event: Sensoreventlistener mlightlistener = new Sensoreventlistener () {
public void Onsensorchanged (Sensorevent event) {
Synchronized (mlocks) {
int value = (int) event.values[0];//get current data from event
LOG.I ("Value", "value=" +value);
Long milliseconds = Systemclock.elapsedrealtime ();
if (mdebuglightsensor) {
SLOG.D (TAG, "Onsensorchanged:light value:" + value);
}
Mhandler.removecallbacks (Mautobrightnesstask);
if (mlightsensorvalue!= value) {//mlightsensorvalue is the current screen brightness
if (Mlightsensorvalue = = 1 | |
Milliseconds < Mlastscreenontime + Mlightsensorwarmuptime) {
Process the value immediately if screen has just turned on
lightsensorchangedlocked (value);
} else {
Delay processing to debounce the sensor
Mlightsensorpendingvalue = Value;//mlightsensorpendingvalue is ready to set the brightness
Mhandler.postdelayed (Mautobrightnesstask, light_sensor_delay);//to Mautobrightnesstask thread to complete automatic adjustment
}
} else {
Mlightsensorpendingvalue =-1;
}
}
}
The current screen brightness is definitely unequal to 1, so do else in mhandler.postdelayed (Mautobrightnesstask, Light_sensor_delay), then we go to Mautobrightnesstask
Thread look: private Runnable Mautobrightnesstask = new Runnable () {
public void Run () {
Synchronized (mlocks) {
int value = (int) mlightsensorpendingvalue;
LOG.I ("Mlightsensorpendingvalue", "Mlightsensorpendingvalue" +mlightsensorpendingvalue);
if (value >= 0) {
Mlightsensorpendingvalue =-1;
lightsensorchangedlocked (value);
}
}
}
It's just a constant call to lightsensorchangedlocked (value)
private void lightsensorchangedlocked (int value) {
。。。。。。。
if (mlightsensorvalue!= value) {
Mlightsensorvalue = value;
if ((Mpowerstate & battery_low_bit) = = 0) {
Use light sensor value no matter it's in a dock or not.
int lcdvalue = Getautobrightnessvalue (
Value
mlcdbacklightvalues)//Get the value inside the Mlcdbacklightvalues
int buttonvalue = Getautobrightnessvalue (value, mbuttonbacklightvalues);
int keyboardvalue;
if (mkeyboardvisible) {
Keyboardvalue = Getautobrightnessvalue (value, mkeyboardbacklightvalues);
} else {
Keyboardvalue = 0;
}
。。。
if (mautobrightessenabled && mscreenbrightnessoverride < 0) {//Set screen brightness
Mscreenbrightness.settargetlocked (Lcdvalue, Autobrightness_anim_steps,
Initial_screen_brightness, (int) mscreenbrightness.curvalue);
}
。。。。。
}