Uses windowContext for the MagnificationGestureHandler

ContextImpl checks the incorrect Context usage in S.
If non-ui context access window service, it would throw an
IllegalAccessException.
And the bug happened because the GestureDectectors in
PanningScalingHandler.class don't have the correct context.
So we have to apply using uiContext for the GestureDectectors
and MagnificationGestureHandler.

Bug: 185154435
Test: none
Change-Id: I942192011526d0e4ce68e6121855bd321c499f56
This commit is contained in:
mincheli
2021-05-03 08:30:02 +08:00
parent 3ed02ffeb1
commit 1b2cf756a7
4 changed files with 17 additions and 7 deletions

View File

@@ -16,6 +16,9 @@
package com.android.server.accessibility;
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
import android.annotation.MainThread;
import android.content.Context;
import android.graphics.Region;
@@ -557,12 +560,16 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
MagnificationGestureHandler magnificationGestureHandler;
if (mAms.getMagnificationMode(displayId)
== Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW) {
magnificationGestureHandler = new WindowMagnificationGestureHandler(displayContext,
final Context uiContext = displayContext.createWindowContext(
TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY, null /* options */);
magnificationGestureHandler = new WindowMagnificationGestureHandler(uiContext,
mAms.getWindowMagnificationMgr(), mAms.getMagnificationController(),
detectControlGestures, triggerable,
displayId);
} else {
magnificationGestureHandler = new FullScreenMagnificationGestureHandler(displayContext,
final Context uiContext = displayContext.createWindowContext(
TYPE_MAGNIFICATION_OVERLAY, null /* options */);
magnificationGestureHandler = new FullScreenMagnificationGestureHandler(uiContext,
mAms.getFullScreenMagnificationController(), mAms.getMagnificationController(),
detectControlGestures, triggerable,
new WindowMagnificationPromptController(displayContext, mUserId), displayId);

View File

@@ -34,6 +34,7 @@ import static java.util.Arrays.copyOfRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiContext;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -139,7 +140,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
private PointerCoords[] mTempPointerCoords;
private PointerProperties[] mTempPointerProperties;
public FullScreenMagnificationGestureHandler(Context context,
public FullScreenMagnificationGestureHandler(@UiContext Context context,
FullScreenMagnificationController fullScreenMagnificationController,
Callback callback,
boolean detectTripleTap,

View File

@@ -19,6 +19,7 @@ package com.android.server.accessibility.magnification;
import static java.lang.Math.abs;
import android.annotation.NonNull;
import android.annotation.UiContext;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
@@ -63,8 +64,8 @@ class PanningScalingHandler extends
private boolean mScaling;
private boolean mEnable;
PanningScalingHandler(Context context, float maxScale, float minScale, boolean blockScroll,
@NonNull MagnificationDelegate magnificationDelegate) {
PanningScalingHandler(@UiContext Context context, float maxScale, float minScale,
boolean blockScroll, @NonNull MagnificationDelegate magnificationDelegate) {
mDisplayId = context.getDisplayId();
mMaxScale = maxScale;
mMinScale = minScale;

View File

@@ -24,6 +24,7 @@ import static java.util.Arrays.asList;
import static java.util.Arrays.copyOfRange;
import android.annotation.Nullable;
import android.annotation.UiContext;
import android.content.Context;
import android.graphics.Point;
import android.provider.Settings;
@@ -86,7 +87,7 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
private final Context mContext;
private final Point mTempPoint = new Point();
public WindowMagnificationGestureHandler(Context context,
public WindowMagnificationGestureHandler(@UiContext Context context,
WindowMagnificationManager windowMagnificationMgr,
Callback callback,
boolean detectTripleTap, boolean detectShortcutTrigger, int displayId) {
@@ -342,7 +343,7 @@ public class WindowMagnificationGestureHandler extends MagnificationGestureHandl
*/
private final boolean mDetectTripleTap;
DetectingState(Context context, boolean detectTripleTap) {
DetectingState(@UiContext Context context, boolean detectTripleTap) {
mDetectTripleTap = detectTripleTap;
final MultiTap multiTap = new MultiTap(context, mDetectTripleTap ? 3 : 1,
mDetectTripleTap