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

Commit 1186e687 authored by Chris Ye's avatar Chris Ye
Browse files

Move InputApplication to use std::shared_ptr.

Move InputApplicationHandle away from RefBase based.
Modernize the code and make it ready to auto-generate parcelable
InputApplicationInfo from AIDL interface.

Bug: 160010896
Test: atest libinput_tests
Change-Id: If46f3376071be61df9d700bb03f67c4a715a7e00
parent f35e819b
Loading
Loading
Loading
Loading
+8 −11
Original line number Original line Diff line number Diff line
@@ -77,32 +77,28 @@ bool NativeInputApplicationHandle::updateInfo() {
    return mInfo.token.get() != nullptr;
    return mInfo.token.get() != nullptr;
}
}



// --- Global functions ---
// --- Global functions ---


sp<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
std::shared_ptr<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
        JNIEnv* env, jobject inputApplicationHandleObj) {
        JNIEnv* env, jobject inputApplicationHandleObj) {
    if (!inputApplicationHandleObj) {
    if (!inputApplicationHandleObj) {
        return NULL;
        return NULL;
    }
    }


    AutoMutex _l(gHandleMutex);
    AutoMutex _l(gHandleMutex);

    jlong ptr = env->GetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr);
    jlong ptr = env->GetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr);
    NativeInputApplicationHandle* handle;
    std::shared_ptr<NativeInputApplicationHandle>* handle;
    if (ptr) {
    if (ptr) {
        handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
        handle = reinterpret_cast<std::shared_ptr<NativeInputApplicationHandle>*>(ptr);
    } else {
    } else {
        jweak objWeak = env->NewWeakGlobalRef(inputApplicationHandleObj);
        jweak objWeak = env->NewWeakGlobalRef(inputApplicationHandleObj);
        handle = new NativeInputApplicationHandle(objWeak);
        handle = new std::shared_ptr(std::make_shared<NativeInputApplicationHandle>(objWeak));
        handle->incStrong((void*)android_view_InputApplicationHandle_getHandle);
        env->SetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr,
        env->SetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr,
                reinterpret_cast<jlong>(handle));
                reinterpret_cast<jlong>(handle));
    }
    }
    return handle;
    return *handle;
}
}



// --- JNI ---
// --- JNI ---


static void android_view_InputApplicationHandle_nativeDispose(JNIEnv* env, jobject obj) {
static void android_view_InputApplicationHandle_nativeDispose(JNIEnv* env, jobject obj) {
@@ -112,8 +108,9 @@ static void android_view_InputApplicationHandle_nativeDispose(JNIEnv* env, jobje
    if (ptr) {
    if (ptr) {
        env->SetLongField(obj, gInputApplicationHandleClassInfo.ptr, 0);
        env->SetLongField(obj, gInputApplicationHandleClassInfo.ptr, 0);


        NativeInputApplicationHandle* handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
        std::shared_ptr<NativeInputApplicationHandle>* handle =
        handle->decStrong((void*)android_view_InputApplicationHandle_getHandle);
                reinterpret_cast<std::shared_ptr<NativeInputApplicationHandle>*>(ptr);
        delete handle;
    }
    }
}
}


+1 −2
Original line number Original line Diff line number Diff line
@@ -39,8 +39,7 @@ private:
    jweak mObjWeak;
    jweak mObjWeak;
};
};



extern std::shared_ptr<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
extern sp<InputApplicationHandle> android_view_InputApplicationHandle_getHandle(
        JNIEnv* env, jobject inputApplicationHandleObj);
        JNIEnv* env, jobject inputApplicationHandleObj);


} // namespace android
} // namespace android
+2 −2
Original line number Original line Diff line number Diff line
@@ -168,7 +168,7 @@ bool NativeInputWindowHandle::updateInfo() {
    jobject inputApplicationHandleObj = env->GetObjectField(obj,
    jobject inputApplicationHandleObj = env->GetObjectField(obj,
            gInputWindowHandleClassInfo.inputApplicationHandle);
            gInputWindowHandleClassInfo.inputApplicationHandle);
    if (inputApplicationHandleObj) {
    if (inputApplicationHandleObj) {
        sp<InputApplicationHandle> inputApplicationHandle =
        std::shared_ptr<InputApplicationHandle> inputApplicationHandle =
                android_view_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
                android_view_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
        if (inputApplicationHandle != nullptr) {
        if (inputApplicationHandle != nullptr) {
            inputApplicationHandle->updateInfo();
            inputApplicationHandle->updateInfo();
+12 −8
Original line number Original line Diff line number Diff line
@@ -239,9 +239,9 @@ public:
    void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
    void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
                      uint32_t policyFlags) override;
                      uint32_t policyFlags) override;
    void notifyConfigurationChanged(nsecs_t when) override;
    void notifyConfigurationChanged(nsecs_t when) override;
    std::chrono::nanoseconds notifyAnr(const sp<InputApplicationHandle>& inputApplicationHandle,
    std::chrono::nanoseconds notifyAnr(
                                       const sp<IBinder>& token,
            const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
                                       const std::string& reason) override;
            const sp<IBinder>& token, const std::string& reason) override;
    void notifyInputChannelBroken(const sp<IBinder>& token) override;
    void notifyInputChannelBroken(const sp<IBinder>& token) override;
    void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) override;
    void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) override;
    bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override;
    bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override;
@@ -682,8 +682,8 @@ void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
    checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
    checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
}
}


static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
static jobject getInputApplicationHandleObjLocalRef(
        const sp<InputApplicationHandle>& inputApplicationHandle) {
        JNIEnv* env, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) {
    if (inputApplicationHandle == nullptr) {
    if (inputApplicationHandle == nullptr) {
        return nullptr;
        return nullptr;
    }
    }
@@ -694,8 +694,8 @@ static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
}
}


std::chrono::nanoseconds NativeInputManager::notifyAnr(
std::chrono::nanoseconds NativeInputManager::notifyAnr(
        const sp<InputApplicationHandle>& inputApplicationHandle, const sp<IBinder>& token,
        const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
        const std::string& reason) {
        const sp<IBinder>& token, const std::string& reason) {
#if DEBUG_INPUT_DISPATCHER_POLICY
#if DEBUG_INPUT_DISPATCHER_POLICY
    ALOGD("notifyANR");
    ALOGD("notifyANR");
#endif
#endif
@@ -780,8 +780,12 @@ void NativeInputManager::displayRemoved(JNIEnv* env, int32_t displayId) {


void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId,
void NativeInputManager::setFocusedApplication(JNIEnv* env, int32_t displayId,
        jobject applicationHandleObj) {
        jobject applicationHandleObj) {
    sp<InputApplicationHandle> applicationHandle =
    if (!applicationHandleObj) {
        return;
    }
    std::shared_ptr<InputApplicationHandle> applicationHandle =
            android_view_InputApplicationHandle_getHandle(env, applicationHandleObj);
            android_view_InputApplicationHandle_getHandle(env, applicationHandleObj);
    applicationHandle->updateInfo();
    mInputManager->getDispatcher()->setFocusedApplication(displayId, applicationHandle);
    mInputManager->getDispatcher()->setFocusedApplication(displayId, applicationHandle);
}
}