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

Commit adb4b95f authored by Roy Chou's avatar Roy Chou
Browse files

chore(#MagSettingsPanel): make service notify sysui the controlling magnifier scale changed

Add onUserMagnificationScaleChanged method in IWindowMagnificationConnection. When MagnificationController was notified the controlling magnifier scale changed, it would delegate the new scale to WindowMagnification through connection. Once the WindowMagnification was notified the scale changed, it would cache the new scale for the given user/display. The cached scale would be passed to the WindowMagnificationSettings to update the panel seekbar in next cl.

Bug: 286176069
Test: manually
      atest IWindowMagnificationConnectionTest
      atest MagnificationControllerTest
      atest WindowMagnificationConnectionWrapperTest
      atest WindowMagnificationManagerTest
Change-Id: Ia1402c90d6251f85601f41738c8c59f70a26997e
parent 458eef30
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -115,4 +115,13 @@ oneway interface IWindowMagnificationConnection {
     * @param callback the interface to be called.
     */
    void setConnectionCallback(in IWindowMagnificationConnectionCallback callback);

    /**
     * Notify System UI the magnification scale on the specified display for userId is changed.
     *
     * @param userId the user id.
     * @param displayId the logical display id.
     * @param scale magnification scale.
     */
    void onUserMagnificationScaleChanged(int userId, int displayId, float scale);
}
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.internal.accessibility.common;

/**
 * Collection of common constants for accessibility shortcut.
 * Collection of common constants for accessibility magnification.
 */
public final class MagnificationConstants {
    private MagnificationConstants() {}
+17 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.Context;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.util.SparseArray;
import android.view.Display;
import android.view.SurfaceControl;
import android.view.WindowManagerGlobal;
@@ -72,6 +73,9 @@ public class WindowMagnification implements CoreStartable, CommandQueue.Callback
    private WindowMagnificationConnectionImpl mWindowMagnificationConnectionImpl;
    private SysUiState mSysUiState;

    @VisibleForTesting
    SparseArray<SparseArray<Float>> mUsersScales = new SparseArray();

    private static class ControllerSupplier extends
            DisplayIdIndexSupplier<WindowMagnificationController> {

@@ -295,6 +299,19 @@ public class WindowMagnification implements CoreStartable, CommandQueue.Callback
        mModeSwitchesController.removeButton(displayId);
    }

    @MainThread
    void setUserMagnificationScale(int userId, int displayId, float scale) {
        SparseArray<Float> scales = mUsersScales.get(userId);
        if (scales == null) {
            scales = new SparseArray<>();
            mUsersScales.put(userId, scales);
        }
        if (scales.contains(displayId) && scales.get(displayId) == scale) {
            return;
        }
        scales.put(displayId, scale);
    }

    @VisibleForTesting
    final WindowMagnifierCallback mWindowMagnifierCallback = new WindowMagnifierCallback() {
        @Override
+6 −0
Original line number Diff line number Diff line
@@ -98,6 +98,12 @@ class WindowMagnificationConnectionImpl extends IWindowMagnificationConnection.S
        mHandler.post(() -> mWindowMagnification.hideMagnificationSettingsPanel(display));
    }

    @Override
    public void onUserMagnificationScaleChanged(int userId, int displayId, float scale) {
        mHandler.post(() -> mWindowMagnification.setUserMagnificationScale(
                userId, displayId, scale));
    }

    @Override
    public void setConnectionCallback(IWindowMagnificationConnectionCallback callback) {
        mConnectionCallback = callback;
+15 −0
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package com.android.systemui.accessibility;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
@@ -185,6 +187,19 @@ public class IWindowMagnificationConnectionTest extends SysuiTestCase {
        verify(mMagnificationSettingsController).closeMagnificationSettings();
    }

    @Test
    public void onUserMagnificationScaleChanged() throws RemoteException {
        final int testUserId = 1;
        final float testScale = 3.0f;
        mIWindowMagnificationConnection.onUserMagnificationScaleChanged(
                testUserId, TEST_DISPLAY, testScale);
        waitForIdleSync();

        assertTrue(mWindowMagnification.mUsersScales.contains(testUserId));
        assertEquals(mWindowMagnification.mUsersScales.get(testUserId).get(TEST_DISPLAY),
                (Float) testScale);
    }

    private class FakeControllerSupplier extends
            DisplayIdIndexSupplier<WindowMagnificationController> {

Loading