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

Commit 0bcbe644 authored by Robert Carr's avatar Robert Carr
Browse files

Track native changes: Rework InputApplicationInfo

First we move it inside of InputWindowInfo instead of InputWindowHandle
so it is part of the data sent across binder. Second we give it a persistent
identity of an IBinder token and use this for comparisons.

Bug: 80101428
Bug: 113136004
Bug: 111440400
Test: EndToEndNativeInputTest. Existing tests pass.
Change-Id: Id89a40e66887d834020f8e645fd1fb48adb7ee2e
parent eadae82b
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view;

import android.os.IBinder;

/**
 * Functions as a handle for an application that can receive input.
 * Enables the native input dispatcher to refer indirectly to the window manager's
@@ -28,19 +30,18 @@ public final class InputApplicationHandle {
    @SuppressWarnings("unused")
    private long ptr;

    // The window manager's application window token.
    public final Object appWindowToken;

    // Application name.
    public String name;

    // Dispatching timeout.
    public long dispatchingTimeoutNanos;

    public IBinder token;

    private native void nativeDispose();

    public InputApplicationHandle(Object appWindowToken) {
        this.appWindowToken = appWindowToken;
    public InputApplicationHandle(IBinder token) {
        this.token = token;
    }

    @Override
+14 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <utils/threads.h>

#include "android_hardware_input_InputApplicationHandle.h"
#include "android_util_Binder.h"

namespace android {

@@ -29,6 +30,7 @@ static struct {
    jfieldID ptr;
    jfieldID name;
    jfieldID dispatchingTimeoutNanos;
    jfieldID token;
} gInputApplicationHandleClassInfo;

static Mutex gHandleMutex;
@@ -75,6 +77,15 @@ bool NativeInputApplicationHandle::updateInfo() {
    mInfo->dispatchingTimeout = env->GetLongField(obj,
            gInputApplicationHandleClassInfo.dispatchingTimeoutNanos);

    jobject tokenObj = env->GetObjectField(obj,
            gInputApplicationHandleClassInfo.token);
    if (tokenObj) {
        mInfo->token = ibinderForJavaObject(env, tokenObj);
        env->DeleteLocalRef(tokenObj);
    } else {
        mInfo->token.clear();
    }

    env->DeleteLocalRef(obj);
    return true;
}
@@ -153,6 +164,9 @@ int register_android_server_InputApplicationHandle(JNIEnv* env) {
            clazz,
            "dispatchingTimeoutNanos", "J");

    GET_FIELD_ID(gInputApplicationHandleClassInfo.token, clazz,
            "token", "Landroid/os/IBinder;");

    return 0;
}

+15 −10
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "android_hardware_input_InputWindowHandle.h"
#include "android_hardware_input_InputApplicationHandle.h"
#include "android_util_Binder.h"

namespace android {

@@ -60,9 +61,7 @@ static Mutex gHandleMutex;

// --- NativeInputWindowHandle ---

NativeInputWindowHandle::NativeInputWindowHandle(
        const sp<InputApplicationHandle>& inputApplicationHandle, jweak objWeak) :
        InputWindowHandle(inputApplicationHandle),
NativeInputWindowHandle::NativeInputWindowHandle(jweak objWeak) :
        mObjWeak(objWeak) {
}

@@ -153,6 +152,18 @@ bool NativeInputWindowHandle::updateInfo() {
    mInfo.displayId = env->GetIntField(obj,
            gInputWindowHandleClassInfo.displayId);

    jobject inputApplicationHandleObj = env->GetObjectField(obj,
            gInputWindowHandleClassInfo.inputApplicationHandle);
    if (inputApplicationHandleObj) {
        sp<InputApplicationHandle> inputApplicationHandle =
            android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
        if (inputApplicationHandle != nullptr) {
            inputApplicationHandle->updateInfo();
            mInfo.applicationInfo = *(inputApplicationHandle->getInfo());
        }
        env->DeleteLocalRef(inputApplicationHandleObj);
    }

    env->DeleteLocalRef(obj);
    return true;
}
@@ -173,14 +184,8 @@ sp<NativeInputWindowHandle> android_server_InputWindowHandle_getHandle(
    if (ptr) {
        handle = reinterpret_cast<NativeInputWindowHandle*>(ptr);
    } else {
        jobject inputApplicationHandleObj = env->GetObjectField(inputWindowHandleObj,
                gInputWindowHandleClassInfo.inputApplicationHandle);
        sp<InputApplicationHandle> inputApplicationHandle =
                android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
        env->DeleteLocalRef(inputApplicationHandleObj);

        jweak objWeak = env->NewWeakGlobalRef(inputWindowHandleObj);
        handle = new NativeInputWindowHandle(inputApplicationHandle, objWeak);
        handle = new NativeInputWindowHandle(objWeak);
        handle->incStrong((void*)android_server_InputWindowHandle_getHandle);
        env->SetLongField(inputWindowHandleObj, gInputWindowHandleClassInfo.ptr,
                reinterpret_cast<jlong>(handle));
+1 −2
Original line number Diff line number Diff line
@@ -26,8 +26,7 @@ namespace android {

class NativeInputWindowHandle : public InputWindowHandle {
public:
    NativeInputWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle,
            jweak objWeak);
    NativeInputWindowHandle(jweak objWeak);
    virtual ~NativeInputWindowHandle();

    jobject getInputWindowHandleObjLocalRef(JNIEnv* env);
+1 −1
Original line number Diff line number Diff line
@@ -304,7 +304,7 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        mActivityComponent = activityComponent;
        mVoiceInteraction = voiceInteraction;
        mFillsParent = fillsParent;
        mInputApplicationHandle = new InputApplicationHandle(this);
        mInputApplicationHandle = new InputApplicationHandle(appToken.asBinder());
    }

    void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
Loading