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

Commit d3e2e404 authored by Michael Wright's avatar Michael Wright Committed by Automerger Merge Worker
Browse files

Merge "Teach TestableSettingsProvider about special UserHandles" into udc-dev am: 947b03a7

parents 4a904690 947b03a7
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.test.TestLooper;
import android.provider.Settings;
import android.testing.TestableContext;
@@ -140,9 +139,9 @@ public final class DisplayPowerController2Test {

        // Put the system into manual brightness by default, just to minimize unexpected events and
        // have a consistent starting state
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

        addLocalServiceMock(WindowManagerPolicy.class, mWindowManagerPolicyMock);
        addLocalServiceMock(ColorDisplayService.ColorDisplayServiceInternal.class,
@@ -422,9 +421,9 @@ public final class DisplayPowerController2Test {

    @Test
    public void testDisplayBrightnessFollowers_AutomaticBrightness() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        final float brightness = 0.4f;
        final float nits = 300;
        final float ambientLux = 3000;
@@ -541,9 +540,9 @@ public final class DisplayPowerController2Test {

    @Test
    public void testSetScreenOffBrightnessSensorEnabled_DisplayIsOff() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        DisplayPowerRequest dpr = new DisplayPowerRequest();
        dpr.policy = DisplayPowerRequest.POLICY_OFF;
@@ -574,9 +573,9 @@ public final class DisplayPowerController2Test {

    @Test
    public void testSetScreenOffBrightnessSensorEnabled_DisplayIsInDoze() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        DisplayPowerRequest dpr = new DisplayPowerRequest();
        dpr.policy = DisplayPowerRequest.POLICY_DOZE;
@@ -621,9 +620,9 @@ public final class DisplayPowerController2Test {

    @Test
    public void testSetScreenOffBrightnessSensorDisabled_DisplayIsDisabled() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        mHolder = createDisplayPowerController(DISPLAY_ID, UNIQUE_ID, /* isEnabled= */ false);

        DisplayPowerRequest dpr = new DisplayPowerRequest();
+10 −11
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.test.TestLooper;
import android.provider.Settings;
import android.testing.TestableContext;
@@ -141,9 +140,9 @@ public final class DisplayPowerControllerTest {

        // Put the system into manual brightness by default, just to minimize unexpected events and
        // have a consistent starting state
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);


        addLocalServiceMock(WindowManagerPolicy.class, mWindowManagerPolicyMock);
@@ -426,9 +425,9 @@ public final class DisplayPowerControllerTest {

    @Test
    public void testDisplayBrightnessFollowers_AutomaticBrightness() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        final float brightness = 0.4f;
        final float nits = 300;
        final float ambientLux = 3000;
@@ -546,9 +545,9 @@ public final class DisplayPowerControllerTest {

    @Test
    public void testSetScreenOffBrightnessSensorEnabled_DisplayIsOff() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        DisplayPowerRequest dpr = new DisplayPowerRequest();
        dpr.policy = DisplayPowerRequest.POLICY_OFF;
@@ -579,9 +578,9 @@ public final class DisplayPowerControllerTest {

    @Test
    public void testSetScreenOffBrightnessSensorEnabled_DisplayIsInDoze() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        DisplayPowerRequest dpr = new DisplayPowerRequest();
        dpr.policy = DisplayPowerRequest.POLICY_DOZE;
@@ -626,9 +625,9 @@ public final class DisplayPowerControllerTest {

    @Test
    public void testSetScreenOffBrightnessSensorDisabled_DisplayIsDisabled() {
        Settings.System.putIntForUser(mContext.getContentResolver(),
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE,
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

        mHolder = createDisplayPowerController(DISPLAY_ID, UNIQUE_ID, /* isEnabled= */ false);

+5 −1
Original line number Diff line number Diff line
@@ -72,7 +72,11 @@ public class TestableSettingsProvider extends MockContentProvider {

    public Bundle call(String method, String arg, Bundle extras) {
        // Methods are "GET_system", "GET_global", "PUT_secure", etc.
        final int userId = extras.getInt(Settings.CALL_METHOD_USER_KEY, UserHandle.myUserId());
        int userId = extras.getInt(Settings.CALL_METHOD_USER_KEY, UserHandle.USER_CURRENT);
        if (userId == UserHandle.USER_CURRENT || userId == UserHandle.USER_CURRENT_OR_SELF) {
            userId = UserHandle.myUserId();
        }

        final String[] commands = method.split("_", 2);
        final String op = commands[0];
        final String table = commands[1];