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

Commit dadc0fb0 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputManagerService: Convert global monitors to focus input monitors

Bug: 216789894
Test: Presubmit
Flag: EXEMPT refactor
Change-Id: Ied529620bd50d1303ec9209c41abc33319df5c1a
parent 3850d545
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -799,19 +799,23 @@ public class InputManagerService extends IInputManager.Stub
    }

    /**
     * Creates an input channel that will receive all input from the input dispatcher.
     * Creates an input channel that will receive all non-pointer input going to focused windows
     * from the input dispatcher.
     *
     * This API is intended to be used only for creating debugging tools to visualize focus input.
     *
     * @param inputChannelName The input channel name.
     * @param displayId Target display id.
     * @return The input channel.
     */
    public InputChannel monitorInput(@NonNull String inputChannelName, int displayId) {
    public InputChannel monitorFocusInput(@NonNull String inputChannelName, int displayId) {
        Objects.requireNonNull(inputChannelName, "inputChannelName not be null");

        if (displayId < Display.DEFAULT_DISPLAY) {
            throw new IllegalArgumentException("displayId must >= 0.");
        }

        return mNative.createInputMonitor(displayId, inputChannelName, Binder.getCallingPid());
        return mNative.createFocusInputMonitor(displayId, inputChannelName, Binder.getCallingPid());
    }

    @NonNull
+2 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ interface NativeInputManagerService {

    InputChannel createInputChannel(String name);

    InputChannel createInputMonitor(int displayId, String name, int pid);
    InputChannel createFocusInputMonitor(int displayId, String name, int pid);

    void removeInputChannel(IBinder connectionToken);

@@ -372,7 +372,7 @@ interface NativeInputManagerService {
        public native InputChannel createInputChannel(String name);

        @Override
        public native InputChannel createInputMonitor(int displayId, String name, int pid);
        public native InputChannel createFocusInputMonitor(int displayId, String name, int pid);

        @Override
        public native void removeInputChannel(IBinder connectionToken);
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class FocusEventDebugGlobalMonitor extends InputEventReceiver {
    private final FocusEventDebugView mDebugView;

    FocusEventDebugGlobalMonitor(FocusEventDebugView debugView, InputManagerService service) {
        super(service.monitorInput("FocusEventDebugGlobalMonitor", Display.DEFAULT_DISPLAY),
        super(service.monitorFocusInput("FocusEventDebugGlobalMonitor", Display.DEFAULT_DISPLAY),
            UiThread.getHandler().getLooper());
        mDebugView = debugView;
    }
+3 −3
Original line number Diff line number Diff line
@@ -1182,9 +1182,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this);
        mRemoteDisplayChangeController = new RemoteDisplayChangeController(this);

        final InputChannel inputChannel = mWmService.mInputManager.monitorInput(
                "PointerEventDispatcher" + mDisplayId, mDisplayId);
        mPointerEventDispatcher = new PointerEventDispatcher(inputChannel);
        final InputChannel pointerSpyInputChannel =
                mWmService.mInputManager.createInputChannel("PointerEventDispatcher" + mDisplayId);
        mPointerEventDispatcher = new PointerEventDispatcher(pointerSpyInputChannel);

        if (mWmService.mAtmService.getRecentTasks() != null) {
            registerPointerEventListener(
+9 −10
Original line number Diff line number Diff line
@@ -327,9 +327,8 @@ public:
    void setDisplayTopology(JNIEnv* env, jobject topologyGraph);

    base::Result<std::unique_ptr<InputChannel>> createInputChannel(const std::string& name);
    base::Result<std::unique_ptr<InputChannel>> createInputMonitor(ui::LogicalDisplayId displayId,
                                                                   const std::string& name,
                                                                   gui::Pid pid);
    base::Result<std::unique_ptr<InputChannel>> createFocusInputMonitor(
            ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid);
    status_t removeInputChannel(const sp<IBinder>& connectionToken);
    status_t pilferPointers(const sp<IBinder>& token);

@@ -689,10 +688,10 @@ base::Result<std::unique_ptr<InputChannel>> NativeInputManager::createInputChann
    return mInputManager->getDispatcher().createInputChannel(name);
}

base::Result<std::unique_ptr<InputChannel>> NativeInputManager::createInputMonitor(
base::Result<std::unique_ptr<InputChannel>> NativeInputManager::createFocusInputMonitor(
        ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) {
    ATRACE_CALL();
    return mInputManager->getDispatcher().createInputMonitor(displayId, name, pid);
    return mInputManager->getDispatcher().createFocusInputMonitor(displayId, name, pid);
}

status_t NativeInputManager::removeInputChannel(const sp<IBinder>& connectionToken) {
@@ -2343,7 +2342,7 @@ static jobject nativeCreateInputChannel(JNIEnv* env, jobject nativeImplObj, jstr
    return inputChannelObj;
}

static jobject nativeCreateInputMonitor(JNIEnv* env, jobject nativeImplObj, jint displayId,
static jobject nativeCreateFocusInputMonitor(JNIEnv* env, jobject nativeImplObj, jint displayId,
                                             jstring nameObj, jint pid) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

@@ -2357,7 +2356,7 @@ static jobject nativeCreateInputMonitor(JNIEnv* env, jobject nativeImplObj, jint
    std::string name = nameChars.c_str();

    base::Result<std::unique_ptr<InputChannel>> inputChannel =
            im->createInputMonitor(ui::LogicalDisplayId{displayId}, name, gui::Pid{pid});
            im->createFocusInputMonitor(ui::LogicalDisplayId{displayId}, name, gui::Pid{pid});

    if (!inputChannel.ok()) {
        std::string message = inputChannel.error().message();
@@ -3334,8 +3333,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"getKeyCodeForKeyLocation", "(II)I", (void*)nativeGetKeyCodeForKeyLocation},
        {"createInputChannel", "(Ljava/lang/String;)Landroid/view/InputChannel;",
         (void*)nativeCreateInputChannel},
        {"createInputMonitor", "(ILjava/lang/String;I)Landroid/view/InputChannel;",
         (void*)nativeCreateInputMonitor},
        {"createFocusInputMonitor", "(ILjava/lang/String;I)Landroid/view/InputChannel;",
         (void*)nativeCreateFocusInputMonitor},
        {"removeInputChannel", "(Landroid/os/IBinder;)V", (void*)nativeRemoveInputChannel},
        {"pilferPointers", "(Landroid/os/IBinder;)V", (void*)nativePilferPointers},
        {"setInputFilterEnabled", "(Z)V", (void*)nativeSetInputFilterEnabled},
Loading