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

Commit dfc88782 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Hides window magnifier UI when the device screen turns off"

parents 4e8a44c8 0c5a37f0
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;