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

Commit 0c5a37f0 authored by mincheli's avatar mincheli
Browse files

Hides window magnifier UI when the device screen turns off

When the device screen turns off, window magnification should be
disabled and magnification button UI should be removed.
To show magnification UI again, a user has to use the a11y shortcut or
the gesture to toggle magnification.

Bug: 147260377
Test: atest WindowMagnificationManagerTest
Change-Id: I03d7f54216a98aa60433e35029365c27e2c564cd
parent d7261e6f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
     */
    public FullScreenMagnificationGestureHandler(Context context,
            FullScreenMagnificationController fullScreenMagnificationController,
            MagnificationGestureHandler.ScaleChangedListener listener,
            ScaleChangedListener listener,
            boolean detectTripleTap,
            boolean detectShortcutTrigger,
            int displayId) {
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import com.android.server.accessibility.BaseEventStreamTransformation;
 */
public abstract class MagnificationGestureHandler extends BaseEventStreamTransformation {

    protected final MagnificationGestureHandler.ScaleChangedListener mListener;
    protected final ScaleChangedListener mListener;

    protected MagnificationGestureHandler(ScaleChangedListener listener) {
        mListener = listener;
+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
     */
    public WindowMagnificationGestureHandler(Context context,
            WindowMagnificationManager windowMagnificationMgr,
            MagnificationGestureHandler.ScaleChangedListener listener, boolean detectTripleTap,
            ScaleChangedListener listener, boolean detectTripleTap,
            boolean detectShortcutTrigger, int displayId) {
        super(listener);
        if (DEBUG_ALL) {
+21 −3
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@
package com.android.server.accessibility.magnification;

import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.os.Binder;
import android.os.IBinder;
@@ -52,17 +55,28 @@ public class WindowMagnificationManager implements
    static final float MAX_SCALE = FullScreenMagnificationController.MAX_SCALE;
    static final float MIN_SCALE = FullScreenMagnificationController.MIN_SCALE;

    private final Object mLock = new Object();;
    private final Object mLock = new Object();
    private final Context mContext;
    @VisibleForTesting
    @GuardedBy("mLock")
    @Nullable WindowMagnificationConnectionWrapper mConnectionWrapper;
    @Nullable
    WindowMagnificationConnectionWrapper mConnectionWrapper;
    @GuardedBy("mLock")
    private ConnectionCallback mConnectionCallback;
    @GuardedBy("mLock")
    private SparseArray<WindowMagnifier> mWindowMagnifiers = new SparseArray<>();
    private int mUserId;

    @VisibleForTesting
    protected final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int displayId = context.getDisplayId();
            removeMagnificationButton(displayId);
            disableWindowMagnification(displayId);
        }
    };

    public WindowMagnificationManager(Context context, int userId) {
        mContext = context;
        mUserId = userId;
@@ -133,8 +147,12 @@ public class WindowMagnificationManager implements
            if (connect == isConnected()) {
                return false;
            }
            if (!connect) {
            if (connect) {
                final IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
                mContext.registerReceiver(mScreenStateReceiver, intentFilter);
            } else {
                disableAllWindowMagnifiers();
                mContext.unregisterReceiver(mScreenStateReceiver);
            }
        }

+23 −0
Original line number Diff line number Diff line
@@ -32,7 +32,10 @@ import static org.testng.Assert.assertTrue;

import static java.lang.Float.NaN;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.IBinder;
@@ -300,6 +303,26 @@ public class WindowMagnificationManagerTest {
        assertFalse(mWindowMagnificationManager.isConnected());
    }

    @Test
    public void requestConnection_registerAndUnregisterBroadcastReceiver() {
        assertTrue(mWindowMagnificationManager.requestConnection(true));
        verify(mContext).registerReceiver(any(BroadcastReceiver.class),  any(IntentFilter.class));

        assertTrue(mWindowMagnificationManager.requestConnection(false));
        verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
    }

    @Test
    public void onReceiveScreenOff_removeMagnificationButtonAndDisableWindowMagnification()
            throws RemoteException {
        mWindowMagnificationManager.requestConnection(true);
        mWindowMagnificationManager.mScreenStateReceiver.onReceive(mContext,
                new Intent(Intent.ACTION_SCREEN_OFF));

        verify(mMockConnection.getConnection()).removeMagnificationButton(TEST_DISPLAY);
        verify(mMockConnection.getConnection()).disableWindowMagnification(TEST_DISPLAY);
    }

    private MotionEvent generatePointersDownEvent(PointF[] pointersLocation) {
        final int len = pointersLocation.length;