Merge "Dispatch accessibility gesture if device supports touch" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-02-09 05:36:36 +00:00
committed by Android (Google) Code Review
4 changed files with 13 additions and 16 deletions

View File

@@ -372,12 +372,11 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
@Override
public void dispatchGesture(int sequence, ParceledListSlice gestureSteps, int displayId) {
final boolean isTouchableDisplay = mWindowManagerService.isTouchableDisplay(displayId);
synchronized (mLock) {
if (mSecurityPolicy.canPerformGestures(this)) {
MotionEventInjector motionEventInjector =
mSystemSupport.getMotionEventInjectorForDisplayLocked(displayId);
if (motionEventInjector != null && isTouchableDisplay) {
if (mWindowManagerService.isTouchOrFaketouchDevice()) {
motionEventInjector.injectEvents(
gestureSteps.getList(), mServiceInterface, sequence, displayId);
} else {

View File

@@ -611,9 +611,9 @@ public abstract class WindowManagerInternal {
public abstract void removeNonHighRefreshRatePackage(@NonNull String packageName);
/**
* Checks if this display is touchable.
* Checks if the device supports touch or faketouch.
*/
public abstract boolean isTouchableDisplay(int displayId);
public abstract boolean isTouchOrFaketouchDevice();
/**
* Returns the info associated with the input token used to determine if a key should be

View File

@@ -750,6 +750,7 @@ public class WindowManagerService extends IWindowManager.Stub
final TaskSnapshotController mTaskSnapshotController;
boolean mIsTouchDevice;
boolean mIsFakeTouchDevice;
final H mH = new H();
@@ -4960,6 +4961,8 @@ public class WindowManagerService extends IWindowManager.Stub
mRoot.forAllDisplays(DisplayContent::reconfigureDisplayLocked);
mIsTouchDevice = mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TOUCHSCREEN);
mIsFakeTouchDevice = mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_FAKETOUCH);
}
try {
@@ -7956,13 +7959,10 @@ public class WindowManagerService extends IWindowManager.Stub
}
@Override
public boolean isTouchableDisplay(int displayId) {
public boolean isTouchOrFaketouchDevice() {
synchronized (mGlobalLock) {
final DisplayContent displayContent = mRoot.getDisplayContent(displayId);
final Configuration configuration =
displayContent != null ? displayContent.getConfiguration() : null;
return configuration != null
&& configuration.touchscreen == Configuration.TOUCHSCREEN_FINGER;
// All touchable devices are also faketouchable.
return mIsFakeTouchDevice;
}
}

View File

@@ -110,8 +110,6 @@ public class AccessibilityServiceConnectionTest {
mMockResolveInfo.serviceInfo.applicationInfo = mock(ApplicationInfo.class);
when(mMockIBinder.queryLocalInterface(any())).thenReturn(mMockServiceClient);
when(mMockWindowManagerInternal.isTouchableDisplay(Display.DEFAULT_DISPLAY)).thenReturn(
true);
mConnection = new AccessibilityServiceConnection(mMockUserState, mMockContext,
COMPONENT_NAME, mMockServiceInfo, SERVICE_ID, mHandler, new Object(),
@@ -197,8 +195,9 @@ public class AccessibilityServiceConnectionTest {
}
@Test
public void sendGesture_touchableDisplay_injectEvents()
public void sendGesture_touchableDevice_injectEvents()
throws RemoteException {
when(mMockWindowManagerInternal.isTouchOrFaketouchDevice()).thenReturn(true);
setServiceBinding(COMPONENT_NAME);
mConnection.bindLocked();
mConnection.onServiceConnected(COMPONENT_NAME, mMockIBinder);
@@ -213,10 +212,9 @@ public class AccessibilityServiceConnectionTest {
}
@Test
public void sendGesture_untouchableDisplay_performGestureResultFailed()
public void sendGesture_untouchableDevice_performGestureResultFailed()
throws RemoteException {
when(mMockWindowManagerInternal.isTouchableDisplay(Display.DEFAULT_DISPLAY)).thenReturn(
false);
when(mMockWindowManagerInternal.isTouchOrFaketouchDevice()).thenReturn(false);
setServiceBinding(COMPONENT_NAME);
mConnection.bindLocked();
mConnection.onServiceConnected(COMPONENT_NAME, mMockIBinder);