Merge "fix(#Magnification): reset gesture handler state when magnifier deactivates" into udc-dev

This commit is contained in:
Roy Chou
2023-03-12 06:52:10 +00:00
committed by Android (Google) Code Review
3 changed files with 84 additions and 11 deletions

View File

@@ -63,6 +63,7 @@ import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.AccessibilityTraceManager; import com.android.server.accessibility.AccessibilityTraceManager;
import com.android.server.wm.WindowManagerInternal; import com.android.server.wm.WindowManagerInternal;
import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -90,7 +91,9 @@ public class FullScreenMagnificationController implements
private final ScreenStateObserver mScreenStateObserver; private final ScreenStateObserver mScreenStateObserver;
private final MagnificationInfoChangedCallback mMagnificationInfoChangedCallback; @GuardedBy("mLock")
private final ArrayList<MagnificationInfoChangedCallback>
mMagnificationInfoChangedCallbacks = new ArrayList<>();
private final MagnificationScaleProvider mScaleProvider; private final MagnificationScaleProvider mScaleProvider;
@@ -393,8 +396,10 @@ public class FullScreenMagnificationController implements
.setScale(scale) .setScale(scale)
.setCenterX(centerX) .setCenterX(centerX)
.setCenterY(centerY).build(); .setCenterY(centerY).build();
mMagnificationInfoChangedCallback.onFullScreenMagnificationChanged(mDisplayId, mMagnificationInfoChangedCallbacks.forEach(callback -> {
mMagnificationRegion, config); callback.onFullScreenMagnificationChanged(mDisplayId,
mMagnificationRegion, config);
});
if (mUnregisterPending && !isActivated()) { if (mUnregisterPending && !isActivated()) {
unregister(mDeleteAfterUnregister); unregister(mDeleteAfterUnregister);
} }
@@ -502,8 +507,10 @@ public class FullScreenMagnificationController implements
if (changed) { if (changed) {
mMagnificationActivated = activated; mMagnificationActivated = activated;
mMagnificationInfoChangedCallback.onFullScreenMagnificationActivationState( mMagnificationInfoChangedCallbacks.forEach(callback -> {
mDisplayId, mMagnificationActivated); callback.onFullScreenMagnificationActivationState(
mDisplayId, mMagnificationActivated);
});
mControllerCtx.getWindowManager().setForceShowMagnifiableBounds( mControllerCtx.getWindowManager().setForceShowMagnifiableBounds(
mDisplayId, activated); mDisplayId, activated);
} }
@@ -580,8 +587,10 @@ public class FullScreenMagnificationController implements
sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback); sendSpecToAnimation(mCurrentMagnificationSpec, animationCallback);
if (isActivated() && (id != INVALID_SERVICE_ID)) { if (isActivated() && (id != INVALID_SERVICE_ID)) {
mIdOfLastServiceToMagnify = id; mIdOfLastServiceToMagnify = id;
mMagnificationInfoChangedCallback.onRequestMagnificationSpec(mDisplayId, mMagnificationInfoChangedCallbacks.forEach(callback -> {
mIdOfLastServiceToMagnify); callback.onRequestMagnificationSpec(mDisplayId,
mIdOfLastServiceToMagnify);
});
} }
return changed; return changed;
} }
@@ -787,7 +796,7 @@ public class FullScreenMagnificationController implements
mLock = lock; mLock = lock;
mMainThreadId = mControllerCtx.getContext().getMainLooper().getThread().getId(); mMainThreadId = mControllerCtx.getContext().getMainLooper().getThread().getId();
mScreenStateObserver = new ScreenStateObserver(mControllerCtx.getContext(), this); mScreenStateObserver = new ScreenStateObserver(mControllerCtx.getContext(), this);
mMagnificationInfoChangedCallback = magnificationInfoChangedCallback; addInfoChangedCallback(magnificationInfoChangedCallback);
mScaleProvider = scaleProvider; mScaleProvider = scaleProvider;
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
mThumbnailSupplier = thumbnailSupplier; mThumbnailSupplier = thumbnailSupplier;
@@ -1349,7 +1358,11 @@ public class FullScreenMagnificationController implements
* hidden. * hidden.
*/ */
void notifyImeWindowVisibilityChanged(int displayId, boolean shown) { void notifyImeWindowVisibilityChanged(int displayId, boolean shown) {
mMagnificationInfoChangedCallback.onImeWindowVisibilityChanged(displayId, shown); synchronized (mLock) {
mMagnificationInfoChangedCallbacks.forEach(callback -> {
callback.onImeWindowVisibilityChanged(displayId, shown);
});
}
} }
private void onScreenTurnedOff() { private void onScreenTurnedOff() {
@@ -1411,6 +1424,18 @@ public class FullScreenMagnificationController implements
} }
} }
void addInfoChangedCallback(@NonNull MagnificationInfoChangedCallback callback) {
synchronized (mLock) {
mMagnificationInfoChangedCallbacks.add(callback);
}
}
void removeInfoChangedCallback(@NonNull MagnificationInfoChangedCallback callback) {
synchronized (mLock) {
mMagnificationInfoChangedCallbacks.remove(callback);
}
}
private boolean traceEnabled() { private boolean traceEnabled() {
return mControllerCtx.getTraceManager().isA11yTracingEnabledForTypes( return mControllerCtx.getTraceManager().isA11yTracingEnabledForTypes(
FLAGS_WINDOW_MANAGER_INTERNAL); FLAGS_WINDOW_MANAGER_INTERNAL);
@@ -1709,7 +1734,7 @@ public class FullScreenMagnificationController implements
return animate ? STUB_ANIMATION_CALLBACK : null; return animate ? STUB_ANIMATION_CALLBACK : null;
} }
interface MagnificationInfoChangedCallback { interface MagnificationInfoChangedCallback {
/** /**
* Called when the {@link MagnificationSpec} is changed with non-default * Called when the {@link MagnificationSpec} is changed with non-default
@@ -1722,7 +1747,6 @@ public class FullScreenMagnificationController implements
/** /**
* Called when the state of the magnification activation is changed. * Called when the state of the magnification activation is changed.
* It is for the logging data of the magnification activation state.
* *
* @param displayId the logical display id * @param displayId the logical display id
* @param activated {@code true} if the magnification is activated, otherwise {@code false}. * @param activated {@code true} if the magnification is activated, otherwise {@code false}.

View File

@@ -32,6 +32,7 @@ import static java.lang.Math.abs;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Arrays.copyOfRange; import static java.util.Arrays.copyOfRange;
import android.accessibilityservice.MagnificationConfig;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.UiContext; import android.annotation.UiContext;
@@ -40,6 +41,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.Region;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
@@ -129,6 +131,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
@VisibleForTesting final FullScreenMagnificationController mFullScreenMagnificationController; @VisibleForTesting final FullScreenMagnificationController mFullScreenMagnificationController;
private final FullScreenMagnificationController.MagnificationInfoChangedCallback
mMagnificationInfoChangedCallback;
@VisibleForTesting final DelegatingState mDelegatingState; @VisibleForTesting final DelegatingState mDelegatingState;
@VisibleForTesting final DetectingState mDetectingState; @VisibleForTesting final DetectingState mDetectingState;
@VisibleForTesting final PanningScalingState mPanningScalingState; @VisibleForTesting final PanningScalingState mPanningScalingState;
@@ -158,6 +162,40 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
+ ", detectShortcutTrigger = " + detectShortcutTrigger + ")"); + ", detectShortcutTrigger = " + detectShortcutTrigger + ")");
} }
mFullScreenMagnificationController = fullScreenMagnificationController; mFullScreenMagnificationController = fullScreenMagnificationController;
mMagnificationInfoChangedCallback =
new FullScreenMagnificationController.MagnificationInfoChangedCallback() {
@Override
public void onRequestMagnificationSpec(int displayId, int serviceId) {
return;
}
@Override
public void onFullScreenMagnificationActivationState(int displayId,
boolean activated) {
if (displayId != mDisplayId) {
return;
}
if (!activated) {
clearAndTransitionToStateDetecting();
}
}
@Override
public void onImeWindowVisibilityChanged(int displayId, boolean shown) {
return;
}
@Override
public void onFullScreenMagnificationChanged(int displayId,
@NonNull Region region,
@NonNull MagnificationConfig config) {
return;
}
};
mFullScreenMagnificationController.addInfoChangedCallback(
mMagnificationInfoChangedCallback);
mPromptController = promptController; mPromptController = promptController;
mDelegatingState = new DelegatingState(); mDelegatingState = new DelegatingState();
@@ -217,6 +255,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
// Check if need to reset when MagnificationGestureHandler is the last magnifying service. // Check if need to reset when MagnificationGestureHandler is the last magnifying service.
mFullScreenMagnificationController.resetIfNeeded( mFullScreenMagnificationController.resetIfNeeded(
mDisplayId, AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); mDisplayId, AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
mFullScreenMagnificationController.removeInfoChangedCallback(
mMagnificationInfoChangedCallback);
clearAndTransitionToStateDetecting(); clearAndTransitionToStateDetecting();
} }

View File

@@ -415,6 +415,15 @@ public class FullScreenMagnificationGestureHandlerTest {
returnToNormalFrom(STATE_ACTIVATED); returnToNormalFrom(STATE_ACTIVATED);
} }
@Test
public void testMagnifierDeactivates_shortcutTriggeredState_returnToIdleState() {
goFromStateIdleTo(STATE_SHORTCUT_TRIGGERED);
mFullScreenMagnificationController.reset(DISPLAY_0, /* animate= */ false);
assertIn(STATE_IDLE);
}
@Test @Test
public void testThreeFingersOneTap_activatedState_dispatchMotionEvents() { public void testThreeFingersOneTap_activatedState_dispatchMotionEvents() {
goFromStateIdleTo(STATE_ACTIVATED); goFromStateIdleTo(STATE_ACTIVATED);