Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab3fc3dc authored by nadlabak's avatar nadlabak
Browse files

allow the light sensor to be ignored when flashlight is on

on certain devices, the flashlight affects the light sensor, causing the display
autobrightness to switch to the maximum level when flashlight is on

Change-Id: I22d623ce5457fc3ae177b609da8b51904bc73e83
parent 04d8fc70
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -278,6 +278,9 @@
         will not debounce light sensor readings -->
         will not debounce light sensor readings -->
    <integer name="config_lightSensorWarmupTime">0</integer>
    <integer name="config_lightSensorWarmupTime">0</integer>


    <!-- Allows the light sensor to be ignored when flashlight is on -->
    <bool name="config_flashlight_affects_lightsensor">false</bool>

    <!-- Enables swipe versus poly-finger touch disambiguation in the KeyboardView -->
    <!-- Enables swipe versus poly-finger touch disambiguation in the KeyboardView -->
    <bool name="config_swipeDisambiguation">true</bool>
    <bool name="config_swipeDisambiguation">true</bool>


+11 −2
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN;
import static android.provider.Settings.System.STAY_ON_WHILE_PLUGGED_IN;
import static android.provider.Settings.System.TORCH_STATE;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.IOException;
@@ -240,6 +241,8 @@ class PowerManagerService extends IPowerManager.Stub
    private int[] mButtonBacklightValues;
    private int[] mButtonBacklightValues;
    private int[] mKeyboardBacklightValues;
    private int[] mKeyboardBacklightValues;
    private int mLightSensorWarmupTime;
    private int mLightSensorWarmupTime;
    private boolean mFlashlightAffectsLightSensor;
    private boolean mIgnoreLightSensor;


    // Custom light housekeeping
    // Custom light housekeeping
    private long mLightSettingsTag = -1;
    private long mLightSettingsTag = -1;
@@ -455,6 +458,8 @@ class PowerManagerService extends IPowerManager.Stub
                 // DIM_SCREEN
                 // DIM_SCREEN
                //mDimScreen = getInt(DIM_SCREEN) != 0;
                //mDimScreen = getInt(DIM_SCREEN) != 0;


                mIgnoreLightSensor = (getInt(TORCH_STATE) != 0) && mFlashlightAffectsLightSensor;

                updateLightSettings();
                updateLightSettings();


                // SCREEN_BRIGHTNESS_MODE
                // SCREEN_BRIGHTNESS_MODE
@@ -542,6 +547,8 @@ class PowerManagerService extends IPowerManager.Stub
        Resources resources = mContext.getResources();
        Resources resources = mContext.getResources();


        // read settings for auto-brightness
        // read settings for auto-brightness
        mFlashlightAffectsLightSensor = resources.getBoolean(
                com.android.internal.R.bool.config_flashlight_affects_lightsensor);
        mUseSoftwareAutoBrightness = resources.getBoolean(
        mUseSoftwareAutoBrightness = resources.getBoolean(
                com.android.internal.R.bool.config_automatic_brightness_available);
                com.android.internal.R.bool.config_automatic_brightness_available);
        if (mUseSoftwareAutoBrightness) {
        if (mUseSoftwareAutoBrightness) {
@@ -563,9 +570,10 @@ class PowerManagerService extends IPowerManager.Stub
                        + 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 + "=?) or ("
                        + Settings.System.NAME + "=?)",
                        + Settings.System.NAME + "=?)",
                new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN,
                new String[]{STAY_ON_WHILE_PLUGGED_IN, SCREEN_OFF_TIMEOUT, DIM_SCREEN,
                        SCREEN_BRIGHTNESS_MODE, Settings.System.LIGHTS_CHANGED},
                        SCREEN_BRIGHTNESS_MODE, TORCH_STATE, Settings.System.LIGHTS_CHANGED},
                null);
                null);
        mSettings = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, mHandler);
        mSettings = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, mHandler);
        SettingsObserver settingsObserver = new SettingsObserver();
        SettingsObserver settingsObserver = new SettingsObserver();
@@ -3149,7 +3157,8 @@ class PowerManagerService extends IPowerManager.Stub
        public void onSensorChanged(SensorEvent event) {
        public void onSensorChanged(SensorEvent event) {
            synchronized (mLocks) {
            synchronized (mLocks) {
                // ignore light sensor while screen is turning off
                // ignore light sensor while screen is turning off
                if (isScreenTurningOffLocked()) {
                // or when flashlight would affect it
                if (isScreenTurningOffLocked() || mIgnoreLightSensor) {
                    return;
                    return;
                }
                }