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

Commit 6717c5c8 authored by Roy Chou's avatar Roy Chou Committed by Android (Google) Code Review
Browse files

Merge changes I0a48e146,I244903a3 into main

* changes:
  chore(#Magnification): use persisted scale if zoom-in-temporary when magnifier is zoomed out by service
  fix(#WindowMagnification): adjust Settings getter def to true for key ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING
parents 6da341a9 1736e28e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -262,6 +262,9 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
                Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
                mResources.getInteger(R.integer.magnification_default_scale),
                UserHandle.USER_CURRENT);
        mAllowDiagonalScrolling = secureSettings.getIntForUser(
                Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING, 1,
                UserHandle.USER_CURRENT) == 1;

        setupMagnificationSizeScaleOptions();

@@ -1225,6 +1228,12 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
        return isActivated() ? mMagnificationFrame.exactCenterY() : Float.NaN;
    }


    @VisibleForTesting
    boolean isDiagonalScrollingEnabled() {
        return mAllowDiagonalScrolling;
    }

    private CharSequence formatStateDescription(float scale) {
        // Cache the locale-appropriate NumberFormat.  Configuration locale is guaranteed
        // non-null, so the first time this is called we will always get the appropriate
+9 −2
Original line number Diff line number Diff line
@@ -101,7 +101,9 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
    private Button mEditButton;
    private ImageButton mFullScreenButton;
    private int mLastSelectedButtonIndex = MagnificationSize.NONE;

    private boolean mAllowDiagonalScrolling = false;

    /**
     * Amount by which magnification scale changes compared to seekbar in settings.
     * magnitude = 10 means, for every 1 scale increase, 10 progress increase in seekbar.
@@ -141,7 +143,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
        mSecureSettings = secureSettings;

        mAllowDiagonalScrolling = mSecureSettings.getIntForUser(
                Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING, 0,
                Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING, 1,
                UserHandle.USER_CURRENT) == 1;

        mParams = createLayoutParams(context);
@@ -420,6 +422,11 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
                UserHandle.USER_CURRENT);
    }

    @VisibleForTesting
    boolean isDiagonalScrollingEnabled() {
        return mAllowDiagonalScrolling;
    }

    /**
     * Only called from outside to notify the controlling magnifier scale changed
     *
@@ -632,7 +639,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest

    private void toggleDiagonalScrolling() {
        boolean enabled = mSecureSettings.getIntForUser(
                Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING, 0,
                Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING, 1,
                UserHandle.USER_CURRENT) == 1;
        setDiagonalScrolling(!enabled);
    }
+9 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.graphics.RegionIterator;
import android.os.Handler;
import android.os.RemoteException;
import android.os.SystemClock;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableResources;
@@ -223,6 +224,14 @@ public class WindowMagnificationControllerTest extends SysuiTestCase {
        mValueAnimator.cancel();
    }

    @Test
    public void initWindowMagnificationController_checkAllowDiagonalScrollingWithSecureSettings() {
        verify(mSecureSettings).getIntForUser(
                eq(Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING),
                /* def */ eq(1), /* userHandle= */ anyInt());
        assertTrue(mWindowMagnificationController.isDiagonalScrollingEnabled());
    }

    @Test
    public void enableWindowMagnification_showControlAndNotifyBoundsChanged() {
        mInstrumentation.runOnMainSync(() -> {
+21 −1
Original line number Diff line number Diff line
@@ -26,10 +26,12 @@ import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import static org.mockito.AdditionalAnswers.returnsSecondArg;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -109,6 +111,11 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
        mContext.addMockSystemService(Context.WINDOW_SERVICE, mWindowManager);
        mContext.addMockSystemService(Context.ACCESSIBILITY_SERVICE, mAccessibilityManager);

        when(mSecureSettings.getIntForUser(anyString(), anyInt(), anyInt())).then(
                returnsSecondArg());
        when(mSecureSettings.getFloatForUser(anyString(), anyFloat(), anyInt())).then(
                returnsSecondArg());

        mWindowMagnificationSettings = new WindowMagnificationSettings(mContext,
                mWindowMagnificationSettingsCallback, mSfVsyncFrameProvider,
                mSecureSettings);
@@ -127,6 +134,14 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
        mWindowMagnificationSettings.hideSettingPanel();
    }

    @Test
    public void initSettingPanel_checkAllowDiagonalScrollingWithSecureSettings() {
        verify(mSecureSettings).getIntForUser(
                eq(Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING),
                /* def */ eq(1), /* userHandle= */ anyInt());
        assertThat(mWindowMagnificationSettings.isDiagonalScrollingEnabled()).isTrue();
    }

    @Test
    public void showSettingPanel_hasAccessibilityWindowTitle() {
        setupMagnificationCapabilityAndMode(
@@ -273,7 +288,12 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
        // Perform click
        diagonalScrollingSwitch.performClick();

        verify(mWindowMagnificationSettingsCallback).onSetDiagonalScrolling(!currentCheckedState);
        final boolean isAllowed = !currentCheckedState;
        verify(mSecureSettings).putIntForUser(
                eq(Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING),
                /* value= */ eq(isAllowed ? 1 : 0),
                /* userHandle= */ anyInt());
        verify(mWindowMagnificationSettingsCallback).onSetDiagonalScrolling(isAllowed);
    }

    @Test
+54 −3
Original line number Diff line number Diff line
@@ -142,6 +142,8 @@ public class FullScreenMagnificationController implements
        private int mIdOfLastServiceToMagnify = INVALID_SERVICE_ID;
        private boolean mMagnificationActivated = false;

        private boolean mZoomedOutFromService = false;

        @GuardedBy("mLock") @Nullable private MagnificationThumbnail mMagnificationThumbnail;

        DisplayMagnification(int displayId) {
@@ -545,6 +547,24 @@ public class FullScreenMagnificationController implements
            return changed;
        }

        /**
         * Directly Zooms out the scale to 1f with animating the transition. This method is
         * triggered only by service automatically, such as when user context changed.
         */
        void zoomOutFromService() {
            setScaleAndCenter(1.0f, Float.NaN, Float.NaN,
                    transformToStubCallback(true),
                    AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
            mZoomedOutFromService = true;
        }

        /**
         * Whether the zooming out is triggered by {@link #zoomOutFromService}.
         */
        boolean isZoomedOutFromService() {
            return mZoomedOutFromService;
        }

        @GuardedBy("mLock")
        boolean reset(boolean animate) {
            return reset(transformToStubCallback(animate));
@@ -619,6 +639,8 @@ public class FullScreenMagnificationController implements
                            mIdOfLastServiceToMagnify);
                });
            }
            // the zoom scale would be changed so we reset the flag
            mZoomedOutFromService = false;
            return changed;
        }

@@ -944,9 +966,7 @@ public class FullScreenMagnificationController implements
            }

            if (isAlwaysOnMagnificationEnabled()) {
                setScaleAndCenter(displayId, 1.0f, Float.NaN, Float.NaN,
                        true,
                        AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
                zoomOutFromService(displayId);
            } else {
                reset(displayId, true);
            }
@@ -1427,6 +1447,37 @@ public class FullScreenMagnificationController implements
                MagnificationScaleProvider.MAX_SCALE);
    }

    /**
     * Directly Zooms out the scale to 1f with animating the transition. This method is
     * triggered only by service automatically, such as when user context changed.
     *
     * @param displayId The logical display id.
     */
    private void zoomOutFromService(int displayId) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
            if (display == null || !display.isActivated()) {
                return;
            }
            display.zoomOutFromService();
        }
    }

    /**
     * Whether the magnification is zoomed out by {@link #zoomOutFromService(int)}.
     *
     * @param displayId The logical display id.
     */
    public boolean isZoomedOutFromService(int displayId) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
            if (display == null || !display.isActivated()) {
                return false;
            }
            return display.isZoomedOutFromService();
        }
    }

    /**
     * Resets all displays' magnification if last magnifying service is disabled.
     *
Loading