blob: 5f74b2a510ca50393147e90a7cec38fdf4bbb2e4 [file] [log] [blame]
Jeff Brown928e0542011-01-10 11:17:36 -08001/*
2 * Copyright (C) 2011 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
Robert Carr788f5742018-07-30 17:46:45 -070017package android.view;
Jeff Brown928e0542011-01-10 11:17:36 -080018
Tiger Huang04dc4cc2019-01-17 18:41:41 +080019import static android.view.Display.INVALID_DISPLAY;
20
Vishnu Nair40efb712019-03-12 13:37:51 -070021import android.annotation.Nullable;
Jeff Brown9302c872011-07-13 22:51:29 -070022import android.graphics.Region;
Robert Carreadae822018-10-11 19:07:03 -070023import android.os.IBinder;
Jeff Brown928e0542011-01-10 11:17:36 -080024
Vishnu Nair40efb712019-03-12 13:37:51 -070025import java.lang.ref.WeakReference;
26
Jeff Brown928e0542011-01-10 11:17:36 -080027/**
28 * Functions as a handle for a window that can receive input.
29 * Enables the native input dispatcher to refer indirectly to the window manager's window state.
30 * @hide
31 */
32public final class InputWindowHandle {
33 // Pointer to the native input window handle.
34 // This field is lazily initialized via JNI.
35 @SuppressWarnings("unused")
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +000036 private long ptr;
Jeff Brown928e0542011-01-10 11:17:36 -080037
38 // The input application handle.
39 public final InputApplicationHandle inputApplicationHandle;
40
Vishnu Nair18782162019-10-08 14:57:16 -070041 // The token associates input data with a window and its input channel. The client input
42 // channel and the server input channel will both contain this token.
Robert Carreadae822018-10-11 19:07:03 -070043 public IBinder token;
Jeff Brown9302c872011-07-13 22:51:29 -070044
45 // The window name.
46 public String name;
47
48 // Window layout params attributes. (WindowManager.LayoutParams)
49 public int layoutParamsFlags;
50 public int layoutParamsType;
51
52 // Dispatching timeout.
53 public long dispatchingTimeoutNanos;
54
55 // Window frame.
56 public int frameLeft;
57 public int frameTop;
58 public int frameRight;
59 public int frameBottom;
60
Robert Carrfcc08522018-11-14 14:02:52 -080061 public int surfaceInset;
62
Jeff Brown9302c872011-07-13 22:51:29 -070063 // Global scaling factor applied to touch events when they are dispatched
64 // to the window
65 public float scaleFactor;
66
67 // Window touchable region.
68 public final Region touchableRegion = new Region();
69
70 // Window is visible.
71 public boolean visible;
72
73 // Window can receive keys.
74 public boolean canReceiveKeys;
75
76 // Window has focus.
77 public boolean hasFocus;
78
79 // Window has wallpaper. (window is the current wallpaper target)
80 public boolean hasWallpaper;
81
82 // Input event dispatching is paused.
83 public boolean paused;
84
Jeff Brown9302c872011-07-13 22:51:29 -070085 // Id of process and user that owns the window.
86 public int ownerPid;
87 public int ownerUid;
88
89 // Window input features.
90 public int inputFeatures;
91
Craig Mautner59c00972012-07-30 12:10:24 -070092 // Display this input is on.
Brad Stenningaf596412018-04-02 12:03:19 -070093 public int displayId;
Craig Mautner59c00972012-07-30 12:10:24 -070094
Tiger Huang04dc4cc2019-01-17 18:41:41 +080095 // If this value is set to a valid display ID, it indicates this window is a portal which
96 // transports the touch of this window to the display indicated by portalToDisplayId.
97 public int portalToDisplayId = INVALID_DISPLAY;
98
Vishnu Nair40efb712019-03-12 13:37:51 -070099 /**
100 * Crops the touchable region to the bounds of the surface provided.
101 *
102 * This can be used in cases where the window is not
103 * {@link android.view.WindowManager#FLAG_NOT_TOUCH_MODAL} but should be constrained to the
104 * bounds of a parent window. That is the window should receive touch events outside its
105 * window but be limited to its stack bounds, such as in the case of split screen.
106 */
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700107 public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null);
Vishnu Nair40efb712019-03-12 13:37:51 -0700108
109 /**
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700110 * Replace {@link touchableRegion} with the bounds of {@link touchableRegionSurfaceControl}. If
Vishnu Nair40efb712019-03-12 13:37:51 -0700111 * the handle is {@code null}, the bounds of the surface associated with this window is used
112 * as the touchable region.
113 */
114 public boolean replaceTouchableRegionWithCrop;
115
Jeff Brown928e0542011-01-10 11:17:36 -0800116 private native void nativeDispose();
117
Vishnu Nair18782162019-10-08 14:57:16 -0700118 public InputWindowHandle(InputApplicationHandle inputApplicationHandle, int displayId) {
Jeff Brown928e0542011-01-10 11:17:36 -0800119 this.inputApplicationHandle = inputApplicationHandle;
Craig Mautner59c00972012-07-30 12:10:24 -0700120 this.displayId = displayId;
Jeff Brown928e0542011-01-10 11:17:36 -0800121 }
122
123 @Override
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700124 public String toString() {
Arthur Hung39134b22018-08-14 11:58:28 +0800125 return new StringBuilder(name != null ? name : "")
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700126 .append(", frame=[").append(frameLeft).append(",").append(frameTop).append(",")
127 .append(frameRight).append(",").append(frameBottom).append("]")
128 .append(", touchableRegion=").append(touchableRegion)
Filip Gruszczynski55149302015-11-25 10:51:25 -0800129 .append(", visible=").append(visible)
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700130 .toString();
131
132 }
133
134 @Override
Jeff Brown928e0542011-01-10 11:17:36 -0800135 protected void finalize() throws Throwable {
Jeff Browncc4f7db2011-08-30 20:34:48 -0700136 try {
137 nativeDispose();
138 } finally {
139 super.finalize();
140 }
Jeff Brown928e0542011-01-10 11:17:36 -0800141 }
Vishnu Nair40efb712019-03-12 13:37:51 -0700142
143 /**
144 * Set the window touchable region to the bounds of {@link touchableRegionBounds} ignoring any
145 * touchable region provided.
146 *
147 * @param bounds surface to set the touchable region to. Set to {@code null} to set the bounds
148 * to the current surface.
149 */
150 public void replaceTouchableRegionWithCrop(@Nullable SurfaceControl bounds) {
151 setTouchableRegionCrop(bounds);
152 replaceTouchableRegionWithCrop = true;
153 }
154
155 /**
156 * Crop the window touchable region to the bounds of the surface provided.
157 */
158 public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700159 touchableRegionSurfaceControl = new WeakReference<>(bounds);
Vishnu Nair40efb712019-03-12 13:37:51 -0700160 }
Jeff Brown928e0542011-01-10 11:17:36 -0800161}