1 /**
2  * Copyright (C) 2019 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 package com.android.systemui.shared.system;
17 
18 import android.hardware.input.InputManagerGlobal;
19 import android.os.Looper;
20 import android.os.Trace;
21 import android.util.Log;
22 import android.view.Choreographer;
23 import android.view.InputMonitor;
24 import android.view.SurfaceControl;
25 
26 import androidx.annotation.NonNull;
27 
28 import com.android.systemui.shared.system.InputChannelCompat.InputEventListener;
29 import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver;
30 
31 /**
32  * @see android.view.InputMonitor
33  */
34 public class InputMonitorCompat {
35     static final String TAG = "InputMonitorCompat";
36     private final InputMonitor mInputMonitor;
37     private final String mName;
38 
39     /**
40      * Monitor input on the specified display for gestures.
41      */
InputMonitorCompat(@onNull String name, int displayId)42     public InputMonitorCompat(@NonNull String name, int displayId) {
43         mName = name + "-disp" + displayId;
44         mInputMonitor = InputManagerGlobal.getInstance()
45                 .monitorGestureInput(name, displayId);
46         Trace.instant(Trace.TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " created");
47         Log.d(TAG, "Input monitor (" + mName + ") created");
48 
49     }
50 
51     /**
52      * @see InputMonitor#pilferPointers()
53      */
pilferPointers()54     public void pilferPointers() {
55         mInputMonitor.pilferPointers();
56     }
57 
58     /**
59      * @see InputMonitor#getSurface()
60      */
getSurface()61     public SurfaceControl getSurface() {
62         return mInputMonitor.getSurface();
63     }
64 
65     /**
66      * @see InputMonitor#dispose()
67      */
dispose()68     public void dispose() {
69         mInputMonitor.dispose();
70         Trace.instant(Trace.TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " disposed");
71         Log.d(TAG, "Input monitor (" + mName + ") disposed");
72     }
73 
74     /**
75      * @see InputMonitor#getInputChannel()
76      */
getInputReceiver(Looper looper, Choreographer choreographer, InputEventListener listener)77     public InputEventReceiver getInputReceiver(Looper looper, Choreographer choreographer,
78             InputEventListener listener) {
79         Trace.instant(Trace.TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " receiver created");
80         Log.d(TAG, "Input event receiver for monitor (" + mName + ") created");
81         return new InputEventReceiver(mName, mInputMonitor.getInputChannel(), looper, choreographer,
82                 listener);
83     }
84 }
85