1 /* 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 17 #ifndef _UI_INPUT_WINDOW_H 18 #define _UI_INPUT_WINDOW_H 19 20 #include <android/os/TouchOcclusionMode.h> 21 #include <binder/Parcel.h> 22 #include <binder/Parcelable.h> 23 #include <input/Flags.h> 24 #include <input/Input.h> 25 #include <input/InputTransport.h> 26 #include <ui/Rect.h> 27 #include <ui/Region.h> 28 #include <ui/Transform.h> 29 #include <utils/RefBase.h> 30 #include <utils/Timers.h> 31 32 #include "InputApplication.h" 33 34 using android::os::TouchOcclusionMode; 35 36 namespace android { 37 38 /* 39 * Describes the properties of a window that can receive input. 40 */ 41 struct InputWindowInfo : public Parcelable { 42 InputWindowInfo() = default; 43 44 // Window flags from WindowManager.LayoutParams 45 enum class Flag : uint32_t { 46 ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001, 47 DIM_BEHIND = 0x00000002, 48 BLUR_BEHIND = 0x00000004, 49 NOT_FOCUSABLE = 0x00000008, 50 NOT_TOUCHABLE = 0x00000010, 51 NOT_TOUCH_MODAL = 0x00000020, 52 TOUCHABLE_WHEN_WAKING = 0x00000040, 53 KEEP_SCREEN_ON = 0x00000080, 54 LAYOUT_IN_SCREEN = 0x00000100, 55 LAYOUT_NO_LIMITS = 0x00000200, 56 FULLSCREEN = 0x00000400, 57 FORCE_NOT_FULLSCREEN = 0x00000800, 58 DITHER = 0x00001000, 59 SECURE = 0x00002000, 60 SCALED = 0x00004000, 61 IGNORE_CHEEK_PRESSES = 0x00008000, 62 LAYOUT_INSET_DECOR = 0x00010000, 63 ALT_FOCUSABLE_IM = 0x00020000, 64 WATCH_OUTSIDE_TOUCH = 0x00040000, 65 SHOW_WHEN_LOCKED = 0x00080000, 66 SHOW_WALLPAPER = 0x00100000, 67 TURN_SCREEN_ON = 0x00200000, 68 DISMISS_KEYGUARD = 0x00400000, 69 SPLIT_TOUCH = 0x00800000, 70 HARDWARE_ACCELERATED = 0x01000000, 71 LAYOUT_IN_OVERSCAN = 0x02000000, 72 TRANSLUCENT_STATUS = 0x04000000, 73 TRANSLUCENT_NAVIGATION = 0x08000000, 74 LOCAL_FOCUS_MODE = 0x10000000, 75 SLIPPERY = 0x20000000, 76 LAYOUT_ATTACHED_IN_DECOR = 0x40000000, 77 DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000, 78 }; // Window types from WindowManager.LayoutParams 79 80 enum class Type : int32_t { 81 UNKNOWN = 0, 82 FIRST_APPLICATION_WINDOW = 1, 83 BASE_APPLICATION = 1, 84 APPLICATION = 2, 85 APPLICATION_STARTING = 3, 86 LAST_APPLICATION_WINDOW = 99, 87 FIRST_SUB_WINDOW = 1000, 88 APPLICATION_PANEL = FIRST_SUB_WINDOW, 89 APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1, 90 APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2, 91 APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3, 92 APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4, 93 LAST_SUB_WINDOW = 1999, 94 FIRST_SYSTEM_WINDOW = 2000, 95 STATUS_BAR = FIRST_SYSTEM_WINDOW, 96 SEARCH_BAR = FIRST_SYSTEM_WINDOW + 1, 97 PHONE = FIRST_SYSTEM_WINDOW + 2, 98 SYSTEM_ALERT = FIRST_SYSTEM_WINDOW + 3, 99 KEYGUARD = FIRST_SYSTEM_WINDOW + 4, 100 TOAST = FIRST_SYSTEM_WINDOW + 5, 101 SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 6, 102 PRIORITY_PHONE = FIRST_SYSTEM_WINDOW + 7, 103 SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW + 8, 104 KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW + 9, 105 SYSTEM_ERROR = FIRST_SYSTEM_WINDOW + 10, 106 INPUT_METHOD = FIRST_SYSTEM_WINDOW + 11, 107 INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW + 12, 108 WALLPAPER = FIRST_SYSTEM_WINDOW + 13, 109 STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW + 14, 110 SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 15, 111 DRAG = FIRST_SYSTEM_WINDOW + 16, 112 STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW + 17, 113 POINTER = FIRST_SYSTEM_WINDOW + 18, 114 NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19, 115 VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW + 20, 116 BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21, 117 INPUT_CONSUMER = FIRST_SYSTEM_WINDOW + 22, 118 NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW + 24, 119 MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 27, 120 ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW + 32, 121 DOCK_DIVIDER = FIRST_SYSTEM_WINDOW + 34, 122 ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39, 123 NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW + 40, 124 LAST_SYSTEM_WINDOW = 2999, 125 }; 126 127 enum class Feature { 128 DISABLE_TOUCH_PAD_GESTURES = 0x00000001, 129 NO_INPUT_CHANNEL = 0x00000002, 130 DISABLE_USER_ACTIVITY = 0x00000004, 131 }; 132 133 /* These values are filled in by the WM and passed through SurfaceFlinger 134 * unless specified otherwise. 135 */ 136 // This value should NOT be used to uniquely identify the window. There may be different 137 // input windows that have the same token. 138 sp<IBinder> token; 139 // This uniquely identifies the input window. 140 int32_t id = -1; 141 std::string name; 142 Flags<Flag> flags; 143 Type type = Type::UNKNOWN; 144 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5); 145 146 /* These values are filled in by SurfaceFlinger. */ 147 int32_t frameLeft = -1; 148 int32_t frameTop = -1; 149 int32_t frameRight = -1; 150 int32_t frameBottom = -1; 151 152 /* 153 * SurfaceFlinger consumes this value to shrink the computed frame. This is 154 * different from shrinking the touchable region in that it DOES shift the coordinate 155 * space where-as the touchable region does not and is more like "cropping". This 156 * is used for window shadows. 157 */ 158 int32_t surfaceInset = 0; 159 160 // A global scaling factor for all windows. Unlike windowScaleX/Y this results 161 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis. 162 float globalScaleFactor = 1.0f; 163 164 // The opacity of this window, from 0.0 to 1.0 (inclusive). 165 // An alpha of 1.0 means fully opaque and 0.0 means fully transparent. 166 float alpha; 167 168 // Transform applied to individual windows. 169 ui::Transform transform; 170 171 // Display size in its natural rotation. Used to rotate raw coordinates for compatibility. 172 int32_t displayWidth = AMOTION_EVENT_INVALID_DISPLAY_SIZE; 173 int32_t displayHeight = AMOTION_EVENT_INVALID_DISPLAY_SIZE; 174 175 /* 176 * This is filled in by the WM relative to the frame and then translated 177 * to absolute coordinates by SurfaceFlinger once the frame is computed. 178 */ 179 Region touchableRegion; 180 bool visible = false; 181 bool focusable = false; 182 bool hasWallpaper = false; 183 bool paused = false; 184 /* This flag is set when the window is of a trusted type that is allowed to silently 185 * overlay other windows for the purpose of implementing the secure views feature. 186 * Trusted overlays, such as IME windows, can partly obscure other windows without causing 187 * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. 188 */ 189 bool trustedOverlay = false; 190 TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED; 191 int32_t ownerPid = -1; 192 int32_t ownerUid = -1; 193 std::string packageName; 194 Flags<Feature> inputFeatures; 195 int32_t displayId = ADISPLAY_ID_NONE; 196 int32_t portalToDisplayId = ADISPLAY_ID_NONE; 197 InputApplicationInfo applicationInfo; 198 bool replaceTouchableRegionWithCrop = false; 199 wp<IBinder> touchableRegionCropHandle; 200 201 void addTouchableRegion(const Rect& region); 202 203 bool touchableRegionContainsPoint(int32_t x, int32_t y) const; 204 205 bool frameContainsPoint(int32_t x, int32_t y) const; 206 207 bool supportsSplitTouch() const; 208 209 bool overlaps(const InputWindowInfo* other) const; 210 211 bool operator==(const InputWindowInfo& inputChannel) const; 212 213 status_t writeToParcel(android::Parcel* parcel) const override; 214 215 status_t readFromParcel(const android::Parcel* parcel) override; 216 }; 217 218 /* 219 * Handle for a window that can receive input. 220 * 221 * Used by the native input dispatcher to indirectly refer to the window manager objects 222 * that describe a window. 223 */ 224 class InputWindowHandle : public RefBase { 225 public: 226 explicit InputWindowHandle(); 227 InputWindowHandle(const InputWindowHandle& other); 228 InputWindowHandle(const InputWindowInfo& other); 229 getInfo()230 inline const InputWindowInfo* getInfo() const { return &mInfo; } 231 232 sp<IBinder> getToken() const; 233 getId()234 int32_t getId() const { return mInfo.id; } 235 getApplicationToken()236 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; } 237 getName()238 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; } 239 getDispatchingTimeout(std::chrono::nanoseconds defaultValue)240 inline std::chrono::nanoseconds getDispatchingTimeout( 241 std::chrono::nanoseconds defaultValue) const { 242 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue; 243 } 244 245 /** 246 * Requests that the state of this object be updated to reflect 247 * the most current available information about the application. 248 * As this class is created as RefBase object, no pure virtual function is allowed. 249 * 250 * This method should only be called from within the input dispatcher's 251 * critical section. 252 * 253 * Returns true on success, or false if the handle is no longer valid. 254 */ updateInfo()255 virtual bool updateInfo() { return false; } 256 257 /** 258 * Updates from another input window handle. 259 */ 260 void updateFrom(const sp<InputWindowHandle> handle); 261 262 /** 263 * Releases the channel used by the associated information when it is 264 * no longer needed. 265 */ 266 void releaseChannel(); 267 268 // Not override since this class is not derrived from Parcelable. 269 status_t readFromParcel(const android::Parcel* parcel); 270 status_t writeToParcel(android::Parcel* parcel) const; 271 272 protected: 273 virtual ~InputWindowHandle(); 274 275 InputWindowInfo mInfo; 276 }; 277 } // namespace android 278 279 #endif // _UI_INPUT_WINDOW_H 280