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

Commit 5751ff39 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "fix(non linear font scaling): restore font scale to default instead of...

Merge "fix(non linear font scaling): restore font scale to default instead of original" into udc-dev am: 887a8ffd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23191501



Change-Id: Iaa14c89b1940432014008243530476775c0ac6b2
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1e1e9d0e 887a8ffd
Loading
Loading
Loading
Loading
+23 −15
Original line number Original line Diff line number Diff line
@@ -45,7 +45,6 @@ import com.android.frameworks.coretests.R;
import org.hamcrest.Description;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.TestRule;
@@ -67,22 +66,9 @@ public class FontScaleConverterActivityTest {
    @Rule
    @Rule
    public TestRule compatChangeRule = new PlatformCompatChangeRule();
    public TestRule compatChangeRule = new PlatformCompatChangeRule();


    private float mOriginalFontScale = Float.MIN_VALUE;

    @Before
    public void setup() {
        mOriginalFontScale = Settings.System.getFloat(
            InstrumentationRegistry.getInstrumentation().getContext().getContentResolver(),
            Settings.System.FONT_SCALE,
            Float.MIN_VALUE
        );
    }

    @After
    @After
    public void teardown() {
    public void teardown() {
        if (mOriginalFontScale != Float.MIN_VALUE) {
        restoreSystemFontScaleToDefault();
            setSystemFontScale(mOriginalFontScale);
        }
    }
    }


    @IwTest(focusArea = "accessibility")
    @IwTest(focusArea = "accessibility")
@@ -160,6 +146,28 @@ public class FontScaleConverterActivityTest {
        );
        );
    }
    }


    private static void restoreSystemFontScaleToDefault() {
        ShellIdentityUtils.invokeWithShellPermissions(() -> {
            // TODO(b/279083734): would use Settings.System.resetToDefaults() if it existed
            Settings.System.putString(
                    InstrumentationRegistry.getInstrumentation()
                            .getContext()
                            .getContentResolver(),
                    Settings.System.FONT_SCALE,
                    null,
                    /* overrideableByRestore= */ true);
        });

        PollingCheck.waitFor(
                /* timeout= */ 5000,
                () -> InstrumentationRegistry.getInstrumentation()
                                        .getContext()
                                        .getResources()
                                        .getConfiguration()
                                        .fontScale == 1
        );
    }

    private Matcher<View> withTextSizeInRange(float sizeStartPx, float sizeEndPx) {
    private Matcher<View> withTextSizeInRange(float sizeStartPx, float sizeEndPx) {
        return new BoundedMatcher<>(TextView.class) {
        return new BoundedMatcher<>(TextView.class) {
            private static final float TOLERANCE = 0.05f;
            private static final float TOLERANCE = 0.05f;