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

Commit 7a72cac3 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Add Java and JNI WindowInfosChangedListener hooks to register with SCC" into sc-v2-dev

parents 61414e03 296c6554
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.window;

import android.view.InputWindowHandle;

import libcore.util.NativeAllocationRegistry;

/**
 * Listener for getting {@link InputWindowHandle} updates from SurfaceFlinger.
 * @hide
 */
public abstract class WindowInfosListener {
    private final long mNativeListener;

    public WindowInfosListener() {
        NativeAllocationRegistry registry = NativeAllocationRegistry.createMalloced(
                WindowInfosListener.class.getClassLoader(), nativeGetFinalizer());

        mNativeListener = nativeCreate(this);
        registry.registerNativeAllocation(this, mNativeListener);
    }

    /**
     * Called when WindowInfos in SurfaceFlinger have changed.
     * @param windowHandles Reverse Z ordered array of window information that was on screen,
     *                      where the first value is the topmost window.
     */
    public abstract void onWindowInfosChanged(InputWindowHandle[] windowHandles);

    /**
     * Register the WindowInfosListener.
     */
    public void register() {
        nativeRegister(mNativeListener);
    }

    /**
     * Unregisters the WindowInfosListener.
     */
    public void unregister() {
        nativeUnregister(mNativeListener);
    }

    private static native long nativeCreate(WindowInfosListener thiz);
    private static native void nativeRegister(long ptr);
    private static native void nativeUnregister(long ptr);
    private static native long nativeGetFinalizer();
}
+2 −0
Original line number Diff line number Diff line
@@ -224,6 +224,7 @@ cc_library_shared {
                "fd_utils.cpp",
                "android_hardware_input_InputWindowHandle.cpp",
                "android_hardware_input_InputApplicationHandle.cpp",
                "android_window_WindowInfosListener.cpp",
            ],

            static_libs: [
@@ -236,6 +237,7 @@ cc_library_shared {
                "libgrallocusage",
                "libscrypt_static",
                "libstatssocket_lazy",
                "libskia",
            ],

            shared_libs: [
+3 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ extern int register_com_android_internal_os_ZygoteCommandBuffer(JNIEnv *env);
extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
extern int register_com_android_internal_security_VerityUtils(JNIEnv* env);
extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
extern int register_android_window_WindowInfosListener(JNIEnv* env);

// Namespace for Android Runtime flags applied during boot time.
static const char* RUNTIME_NATIVE_BOOT_NAMESPACE = "runtime_native_boot";
@@ -1649,6 +1650,8 @@ static const RegJNIRec gRegJNI[] = {
        REG_JNI(register_com_android_internal_os_KernelCpuUidBpfMapReader),
        REG_JNI(register_com_android_internal_os_KernelSingleProcessCpuThreadReader),
        REG_JNI(register_com_android_internal_os_KernelSingleUidTimeReader),

        REG_JNI(register_android_window_WindowInfosListener),
};

/*
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ per-file android_view_PointerIcon.* = file:/services/core/java/com/android/serve
# WindowManager
per-file android_graphics_BLASTBufferQueue.cpp = file:/services/core/java/com/android/server/wm/OWNERS
per-file android_view_Surface* = file:/services/core/java/com/android/server/wm/OWNERS
per-file android_window_WindowInfosListener.cpp = file:/services/core/java/com/android/server/wm/OWNERS

# Resources
per-file android_content_res_* = file:/core/java/android/content/res/OWNERS
+19 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@
namespace android {

static struct {
    jclass clazz;
    jmethodID ctor;
    jfieldID ptr;
    jfieldID name;
    jfieldID dispatchingTimeoutMillis;
@@ -101,6 +103,15 @@ std::shared_ptr<InputApplicationHandle> android_view_InputApplicationHandle_getH
    return *handle;
}

jobject android_view_InputApplicationHandle_fromInputApplicationInfo(
        JNIEnv* env, gui::InputApplicationInfo inputApplicationInfo) {
    jobject binderObject = javaObjectForIBinder(env, inputApplicationInfo.token);
    ScopedLocalRef<jstring> name(env, env->NewStringUTF(inputApplicationInfo.name.data()));
    return env->NewObject(gInputApplicationHandleClassInfo.clazz,
                          gInputApplicationHandleClassInfo.ctor, binderObject, name.get(),
                          inputApplicationInfo.dispatchingTimeoutMillis);
}

// --- JNI ---

static void android_view_InputApplicationHandle_nativeDispose(JNIEnv* env, jobject obj) {
@@ -131,6 +142,10 @@ static const JNINativeMethod gInputApplicationHandleMethods[] = {
        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
        LOG_FATAL_IF(! (var), "Unable to find field " fieldName);

#define GET_METHOD_ID(var, clazz, methodName, methodSignature)  \
    var = env->GetMethodID(clazz, methodName, methodSignature); \
    LOG_ALWAYS_FATAL_IF(!(var), "Unable to find method " methodName);

int register_android_view_InputApplicationHandle(JNIEnv* env) {
    int res = jniRegisterNativeMethods(env, "android/view/InputApplicationHandle",
            gInputApplicationHandleMethods, NELEM(gInputApplicationHandleMethods));
@@ -139,6 +154,10 @@ int register_android_view_InputApplicationHandle(JNIEnv* env) {

    jclass clazz;
    FIND_CLASS(clazz, "android/view/InputApplicationHandle");
    gInputApplicationHandleClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);

    GET_METHOD_ID(gInputApplicationHandleClassInfo.ctor, clazz, "<init>",
                  "(Landroid/os/IBinder;Ljava/lang/String;J)V");

    GET_FIELD_ID(gInputApplicationHandleClassInfo.ptr, clazz,
            "ptr", "J");
Loading