Merge changes from topic "cherrypick-enable_input_rot_flag-ev5656cryw" into sc-v2-dev
* changes: Enable input window rotation flag InputManagerService: Use default display for input injection if not specified
This commit is contained in:
committed by
Android (Google) Code Review
commit
5039deff4e
@@ -106,7 +106,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
|
|||||||
static final String DEBUG_MISSING_GESTURE_TAG = "NoBackGesture";
|
static final String DEBUG_MISSING_GESTURE_TAG = "NoBackGesture";
|
||||||
|
|
||||||
private static final boolean ENABLE_PER_WINDOW_INPUT_ROTATION =
|
private static final boolean ENABLE_PER_WINDOW_INPUT_ROTATION =
|
||||||
SystemProperties.getBoolean("persist.debug.per_window_input_rotation", false);
|
SystemProperties.getBoolean("persist.debug.per_window_input_rotation", true);
|
||||||
|
|
||||||
private ISystemGestureExclusionListener mGestureExclusionListener =
|
private ISystemGestureExclusionListener mGestureExclusionListener =
|
||||||
new ISystemGestureExclusionListener.Stub() {
|
new ISystemGestureExclusionListener.Stub() {
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class InputManagerService extends IInputManager.Stub
|
|||||||
private static final boolean UNTRUSTED_TOUCHES_TOAST = false;
|
private static final boolean UNTRUSTED_TOUCHES_TOAST = false;
|
||||||
|
|
||||||
public static final boolean ENABLE_PER_WINDOW_INPUT_ROTATION =
|
public static final boolean ENABLE_PER_WINDOW_INPUT_ROTATION =
|
||||||
SystemProperties.getBoolean("persist.debug.per_window_input_rotation", false);
|
SystemProperties.getBoolean("persist.debug.per_window_input_rotation", true);
|
||||||
|
|
||||||
// Pointer to native input manager service object.
|
// Pointer to native input manager service object.
|
||||||
private final long mPtr;
|
private final long mPtr;
|
||||||
@@ -189,7 +189,7 @@ public class InputManagerService extends IInputManager.Stub
|
|||||||
private final InputManagerHandler mHandler;
|
private final InputManagerHandler mHandler;
|
||||||
|
|
||||||
// Context cache used for loading pointer resources.
|
// Context cache used for loading pointer resources.
|
||||||
private Context mDisplayContext;
|
private Context mPointerIconDisplayContext;
|
||||||
|
|
||||||
private final File mDoubleTouchGestureEnableFile;
|
private final File mDoubleTouchGestureEnableFile;
|
||||||
|
|
||||||
@@ -839,21 +839,31 @@ public class InputManagerService extends IInputManager.Stub
|
|||||||
throw new IllegalArgumentException("mode is invalid");
|
throw new IllegalArgumentException("mode is invalid");
|
||||||
}
|
}
|
||||||
if (ENABLE_PER_WINDOW_INPUT_ROTATION) {
|
if (ENABLE_PER_WINDOW_INPUT_ROTATION) {
|
||||||
if (event instanceof MotionEvent) {
|
// Motion events that are pointer events or relative mouse events will need to have the
|
||||||
final Context dispCtx = getContextForDisplay(event.getDisplayId());
|
// inverse display rotation applied to them.
|
||||||
final Display display = dispCtx.getDisplay();
|
if (event instanceof MotionEvent
|
||||||
|
&& (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)
|
||||||
|
|| event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE))) {
|
||||||
|
Context displayContext = getContextForDisplay(event.getDisplayId());
|
||||||
|
if (displayContext == null) {
|
||||||
|
displayContext = Objects.requireNonNull(
|
||||||
|
getContextForDisplay(Display.DEFAULT_DISPLAY));
|
||||||
|
}
|
||||||
|
final Display display = displayContext.getDisplay();
|
||||||
final int rotation = display.getRotation();
|
final int rotation = display.getRotation();
|
||||||
if (rotation != ROTATION_0) {
|
if (rotation != ROTATION_0) {
|
||||||
final MotionEvent motion = (MotionEvent) event;
|
final MotionEvent motion = (MotionEvent) event;
|
||||||
// Injections are currently expected to be in the space of the injector (ie.
|
// Injections are currently expected to be in the space of the injector (ie.
|
||||||
// usually assumed to be post-rotated). Thus we need to unrotate into raw
|
// usually assumed to be post-rotated). Thus we need to un-rotate into raw
|
||||||
// input coordinates for dispatch.
|
// input coordinates for dispatch.
|
||||||
final Point sz = new Point();
|
final Point sz = new Point();
|
||||||
display.getRealSize(sz);
|
if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
|
||||||
if ((rotation % 2) != 0) {
|
display.getRealSize(sz);
|
||||||
final int tmpX = sz.x;
|
if ((rotation % 2) != 0) {
|
||||||
sz.x = sz.y;
|
final int tmpX = sz.x;
|
||||||
sz.y = tmpX;
|
sz.x = sz.y;
|
||||||
|
sz.y = tmpX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
motion.applyTransform(MotionEvent.createRotateMatrix(
|
motion.applyTransform(MotionEvent.createRotateMatrix(
|
||||||
(4 - rotation), sz.x, sz.y));
|
(4 - rotation), sz.x, sz.y));
|
||||||
@@ -1742,6 +1752,11 @@ public class InputManagerService extends IInputManager.Stub
|
|||||||
|
|
||||||
/** Clean up input window handles of the given display. */
|
/** Clean up input window handles of the given display. */
|
||||||
public void onDisplayRemoved(int displayId) {
|
public void onDisplayRemoved(int displayId) {
|
||||||
|
if (mPointerIconDisplayContext != null
|
||||||
|
&& mPointerIconDisplayContext.getDisplay().getDisplayId() == displayId) {
|
||||||
|
mPointerIconDisplayContext = null;
|
||||||
|
}
|
||||||
|
|
||||||
nativeDisplayRemoved(mPtr, displayId);
|
nativeDisplayRemoved(mPtr, displayId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2971,24 +2986,43 @@ public class InputManagerService extends IInputManager.Stub
|
|||||||
|
|
||||||
// Native callback.
|
// Native callback.
|
||||||
private PointerIcon getPointerIcon(int displayId) {
|
private PointerIcon getPointerIcon(int displayId) {
|
||||||
return PointerIcon.getDefaultIcon(getContextForDisplay(displayId));
|
return PointerIcon.getDefaultIcon(getContextForPointerIcon(displayId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Context getContextForDisplay(int displayId) {
|
@NonNull
|
||||||
if (mDisplayContext != null && mDisplayContext.getDisplay().getDisplayId() == displayId) {
|
private Context getContextForPointerIcon(int displayId) {
|
||||||
return mDisplayContext;
|
if (mPointerIconDisplayContext != null
|
||||||
}
|
&& mPointerIconDisplayContext.getDisplay().getDisplayId() == displayId) {
|
||||||
|
return mPointerIconDisplayContext;
|
||||||
if (mContext.getDisplay().getDisplayId() == displayId) {
|
|
||||||
mDisplayContext = mContext;
|
|
||||||
return mDisplayContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and cache context for non-default display.
|
// Create and cache context for non-default display.
|
||||||
final DisplayManager displayManager = mContext.getSystemService(DisplayManager.class);
|
mPointerIconDisplayContext = getContextForDisplay(displayId);
|
||||||
|
|
||||||
|
// Fall back to default display if the requested displayId does not exist.
|
||||||
|
if (mPointerIconDisplayContext == null) {
|
||||||
|
mPointerIconDisplayContext = getContextForDisplay(Display.DEFAULT_DISPLAY);
|
||||||
|
}
|
||||||
|
return mPointerIconDisplayContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Context getContextForDisplay(int displayId) {
|
||||||
|
if (displayId == Display.INVALID_DISPLAY) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (mContext.getDisplay().getDisplayId() == displayId) {
|
||||||
|
return mContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
final DisplayManager displayManager = Objects.requireNonNull(
|
||||||
|
mContext.getSystemService(DisplayManager.class));
|
||||||
final Display display = displayManager.getDisplay(displayId);
|
final Display display = displayManager.getDisplay(displayId);
|
||||||
mDisplayContext = mContext.createDisplayContext(display);
|
if (display == null) {
|
||||||
return mDisplayContext;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mContext.createDisplayContext(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Native callback.
|
// Native callback.
|
||||||
|
|||||||
Reference in New Issue
Block a user