1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.window;
18 
19 import android.view.InputWindowHandle;
20 
21 import libcore.util.NativeAllocationRegistry;
22 
23 /**
24  * Listener for getting {@link InputWindowHandle} updates from SurfaceFlinger.
25  * @hide
26  */
27 public abstract class WindowInfosListener {
28     private final long mNativeListener;
29 
WindowInfosListener()30     public WindowInfosListener() {
31         NativeAllocationRegistry registry = NativeAllocationRegistry.createMalloced(
32                 WindowInfosListener.class.getClassLoader(), nativeGetFinalizer());
33 
34         mNativeListener = nativeCreate(this);
35         registry.registerNativeAllocation(this, mNativeListener);
36     }
37 
38     /**
39      * Called when WindowInfos in SurfaceFlinger have changed.
40      * @param windowHandles Reverse Z ordered array of window information that was on screen,
41      *                      where the first value is the topmost window.
42      */
onWindowInfosChanged(InputWindowHandle[] windowHandles)43     public abstract void onWindowInfosChanged(InputWindowHandle[] windowHandles);
44 
45     /**
46      * Register the WindowInfosListener.
47      */
register()48     public void register() {
49         nativeRegister(mNativeListener);
50     }
51 
52     /**
53      * Unregisters the WindowInfosListener.
54      */
unregister()55     public void unregister() {
56         nativeUnregister(mNativeListener);
57     }
58 
nativeCreate(WindowInfosListener thiz)59     private static native long nativeCreate(WindowInfosListener thiz);
nativeRegister(long ptr)60     private static native void nativeRegister(long ptr);
nativeUnregister(long ptr)61     private static native void nativeUnregister(long ptr);
nativeGetFinalizer()62     private static native long nativeGetFinalizer();
63 }
64