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

Commit 63b59a04 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Release SurfaceControl after creating an input channel

During the input channel creation we are passing a SurfaceControl object to
SystemServer. Holding on to the SurfaceControl in the app extends the lifetime of the SurfaceControl and relies on GC to clean up the last reference.

Bug: 436302937
Flag: EXEMPT bug fix
Test: presubmit
Change-Id: I9cb57171980f356ee67122b0045b28e3bbf7ef21
parent 69e91bb1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -36,6 +36,11 @@ static struct {
    jmethodID removeInputChannel;
} gWindowManagerGlobal;

static struct {
    jclass clazz;
    jmethodID release;
} gSurfaceControl;

std::shared_ptr<InputChannel> createInputChannel(
        const sp<IBinder>& clientToken, const InputTransferToken& hostInputTransferToken,
        const SurfaceControl& surfaceControl, const InputTransferToken& clientInputTransferToken) {
@@ -62,6 +67,7 @@ std::shared_ptr<InputChannel> createInputChannel(
                                                        surfaceControlObj.get(),
                                                        clientInputTransferTokenObj.get()));

    env->CallVoidMethod(surfaceControlObj.get(), gSurfaceControl.release);
    return android_view_InputChannel_getInputChannel(env, inputChannelObj.get());
}

@@ -85,6 +91,10 @@ int register_android_view_WindowManagerGlobal(JNIEnv* env) {
            GetStaticMethodIDOrDie(env, windowManagerGlobalClass, "removeInputChannel",
                                   "(Landroid/os/IBinder;)V");

    jclass surfaceControlClass = FindClassOrDie(env, "android/view/SurfaceControl");
    gSurfaceControl.clazz = MakeGlobalRefOrDie(env, surfaceControlClass);
    gSurfaceControl.release = GetMethodIDOrDie(env, gSurfaceControl.clazz, "release", "()V");

    return NO_ERROR;
}