Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c84c29d authored by Arthur Hung's avatar Arthur Hung Committed by Android (Google) Code Review
Browse files

Merge "Prevent false touch when folding device (2/2)"

parents bd5e9da1 f885746d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -144,4 +144,6 @@ interface IInputManager {
    void openLightSession(int deviceId, String opPkg, in IBinder token);

    void closeLightSession(int deviceId, in IBinder token);

    void cancelCurrentTouch();
}
+12 −0
Original line number Diff line number Diff line
@@ -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.
     */
+4 −2
Original line number Diff line number Diff line
@@ -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()
        }
    }

+11 −0
Original line number Diff line number Diff line
@@ -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;
+6 −0
Original line number Diff line number Diff line
@@ -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) \