Prevent false touch when folding device (2/2)

This CL will add new api to cancel current touch when fold transition
started.

Bug: 203549969
Test: manual
Change-Id: Id03fbeb05014dcb9f99901c36db1a88cbe110880
This commit is contained in:
Arthur Hung
2021-12-03 14:17:05 +00:00
parent 789acb12fa
commit f885746db7
5 changed files with 35 additions and 2 deletions

View File

@@ -144,4 +144,6 @@ interface IInputManager {
void openLightSession(int deviceId, String opPkg, in IBinder token);
void closeLightSession(int deviceId, in IBinder token);
void cancelCurrentTouch();
}

View File

@@ -1649,6 +1649,18 @@ public final class InputManager {
}
}
/**
* Cancel all ongoing pointer gestures on all displays.
* @hide
*/
public void cancelCurrentTouch() {
try {
mIm.cancelCurrentTouch();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Listens for changes in input devices.
*/

View File

@@ -20,6 +20,7 @@ import android.content.Context
import android.graphics.PixelFormat
import android.hardware.devicestate.DeviceStateManager
import android.hardware.devicestate.DeviceStateManager.FoldStateListener
import android.hardware.input.InputManager
import android.hardware.display.DisplayManager
import android.os.Handler
import android.os.Trace
@@ -195,8 +196,7 @@ class UnfoldLightRevealOverlayAnimation @Inject constructor(
params.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
params.fitInsetsTypes = 0
params.flags = (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
params.setTrustedOverlay()
val packageName: String = context.opPackageName
@@ -239,6 +239,8 @@ class UnfoldLightRevealOverlayAnimation @Inject constructor(
if (scrimView == null) {
addView()
}
// Disable input dispatching during transition.
InputManager.getInstance().cancelCurrentTouch()
}
}

View File

@@ -347,6 +347,7 @@ public class InputManagerService extends IInputManager.Stub
private static native boolean nativeEnableSensor(long ptr, int deviceId, int sensorType,
int samplingPeriodUs, int maxBatchReportLatencyUs);
private static native void nativeDisableSensor(long ptr, int deviceId, int sensorType);
private static native void nativeCancelCurrentTouch(long ptr);
// Maximum number of milliseconds to wait for input event injection.
private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
@@ -2509,6 +2510,16 @@ public class InputManagerService extends IInputManager.Stub
}
}
@Override
public void cancelCurrentTouch() {
if (!checkCallingPermission(android.Manifest.permission.MONITOR_INPUT,
"cancelCurrentTouch()")) {
throw new SecurityException("Requires MONITOR_INPUT permission");
}
nativeCancelCurrentTouch(mPtr);
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;

View File

@@ -2292,6 +2292,11 @@ static jboolean nativeFlushSensor(JNIEnv* env, jclass /* clazz */, jlong ptr, ji
sensorType));
}
static void nativeCancelCurrentTouch(JNIEnv* env, jclass /* clazz */, jlong ptr) {
NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
im->getInputManager()->getDispatcher().cancelCurrentTouch();
}
// ----------------------------------------------------------------------------
static const JNINativeMethod gInputManagerMethods[] = {
@@ -2371,6 +2376,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
{"nativeEnableSensor", "(JIIII)Z", (void*)nativeEnableSensor},
{"nativeDisableSensor", "(JII)V", (void*)nativeDisableSensor},
{"nativeFlushSensor", "(JII)Z", (void*)nativeFlushSensor},
{"nativeCancelCurrentTouch", "(J)V", (void*)nativeCancelCurrentTouch},
};
#define FIND_CLASS(var, className) \