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

Commit 19be2632 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Save brightness changes when mode switched to manual" into main

parents a8114aaa 04b9ae39
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -149,6 +149,13 @@ public class BrightnessSetting {
        }
        }
    }
    }


    /**
     * Flush the brightness update that has been made to the persistent data store.
     */
    public void saveIfNeeded() {
        mPersistentDataStore.saveIfNeeded();
    }

    /**
    /**
     * @return The brightness for the default display in nits. Used when the underlying display
     * @return The brightness for the default display in nits. Used when the underlying display
     * device has changed but we want to persist the nit value.
     * device has changed but we want to persist the nit value.
+5 −0
Original line number Original line Diff line number Diff line
@@ -2484,6 +2484,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
        mAutomaticBrightnessStrategy.setUseAutoBrightness(screenBrightnessModeSetting
        mAutomaticBrightnessStrategy.setUseAutoBrightness(screenBrightnessModeSetting
                == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
                == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        if (screenBrightnessModeSetting == Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL) {
            // In manual mode, all brightness changes should be saved immediately.
            mDisplayBrightnessController.saveBrightnessIfNeeded();
        }
    }
    }




+7 −0
Original line number Original line Diff line number Diff line
@@ -338,6 +338,13 @@ public final class DisplayBrightnessController {
        setBrightness(brightnessValue, maxBrightness);
        setBrightness(brightnessValue, maxBrightness);
    }
    }


    /**
     * Flush the brightness update that has been made to the persistent data store.
     */
    public void saveBrightnessIfNeeded() {
        mBrightnessSetting.saveIfNeeded();
    }

    /**
    /**
     * Sets the current screen brightness, and notifies the BrightnessSetting about the change.
     * Sets the current screen brightness, and notifies the BrightnessSetting about the change.
     */
     */
+14 −0
Original line number Original line Diff line number Diff line
@@ -2213,6 +2213,20 @@ public final class DisplayPowerControllerTest {
                /* ignoreAnimationLimits= */ anyBoolean());
                /* ignoreAnimationLimits= */ anyBoolean());
    }
    }


    @Test
    public void testManualBrightnessModeSavesBrightness() {
        DisplayPowerRequest dpr = new DisplayPowerRequest();
        mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
        advanceTime(1); // Initialize

        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        advanceTime(1);

        verify(mHolder.brightnessSetting).saveIfNeeded();
    }

    /**
    /**
     * Creates a mock and registers it to {@link LocalServices}.
     * Creates a mock and registers it to {@link LocalServices}.
     */
     */