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 #pragma once 18 19 #include <android/gui/TouchOcclusionMode.h> 20 #include <android/os/InputConfig.h> 21 #include <binder/Parcel.h> 22 #include <binder/Parcelable.h> 23 #include <ftl/flags.h> 24 #include <ftl/mixins.h> 25 #include <gui/PidUid.h> 26 #include <gui/constants.h> 27 #include <ui/Rect.h> 28 #include <ui/Region.h> 29 #include <ui/Transform.h> 30 #include <utils/RefBase.h> 31 #include <utils/Timers.h> 32 33 #include "InputApplication.h" 34 35 namespace android::gui { 36 37 /* 38 * Describes the properties of a window that can receive input. 39 */ 40 struct WindowInfo : public Parcelable { 41 WindowInfo() = default; 42 43 // Window flags from WindowManager.LayoutParams 44 enum class Flag : uint32_t { 45 ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001, 46 DIM_BEHIND = 0x00000002, 47 BLUR_BEHIND = 0x00000004, 48 NOT_FOCUSABLE = 0x00000008, 49 NOT_TOUCHABLE = 0x00000010, 50 NOT_TOUCH_MODAL = 0x00000020, 51 TOUCHABLE_WHEN_WAKING = 0x00000040, 52 KEEP_SCREEN_ON = 0x00000080, 53 LAYOUT_IN_SCREEN = 0x00000100, 54 LAYOUT_NO_LIMITS = 0x00000200, 55 FULLSCREEN = 0x00000400, 56 FORCE_NOT_FULLSCREEN = 0x00000800, 57 DITHER = 0x00001000, 58 SECURE = 0x00002000, 59 SCALED = 0x00004000, 60 IGNORE_CHEEK_PRESSES = 0x00008000, 61 LAYOUT_INSET_DECOR = 0x00010000, 62 ALT_FOCUSABLE_IM = 0x00020000, 63 WATCH_OUTSIDE_TOUCH = 0x00040000, 64 SHOW_WHEN_LOCKED = 0x00080000, 65 SHOW_WALLPAPER = 0x00100000, 66 TURN_SCREEN_ON = 0x00200000, 67 DISMISS_KEYGUARD = 0x00400000, 68 SPLIT_TOUCH = 0x00800000, 69 HARDWARE_ACCELERATED = 0x01000000, 70 LAYOUT_IN_OVERSCAN = 0x02000000, 71 TRANSLUCENT_STATUS = 0x04000000, 72 TRANSLUCENT_NAVIGATION = 0x08000000, 73 LOCAL_FOCUS_MODE = 0x10000000, 74 SLIPPERY = 0x20000000, 75 LAYOUT_ATTACHED_IN_DECOR = 0x40000000, 76 DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000, 77 }; 78 79 // Window types from WindowManager.LayoutParams 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 95 #define FIRST_SYSTEM_WINDOW_ 2000 96 97 STATUS_BAR = FIRST_SYSTEM_WINDOW_, 98 SEARCH_BAR = FIRST_SYSTEM_WINDOW_ + 1, 99 PHONE = FIRST_SYSTEM_WINDOW_ + 2, 100 SYSTEM_ALERT = FIRST_SYSTEM_WINDOW_ + 3, 101 KEYGUARD = FIRST_SYSTEM_WINDOW_ + 4, 102 TOAST = FIRST_SYSTEM_WINDOW_ + 5, 103 SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW_ + 6, 104 PRIORITY_PHONE = FIRST_SYSTEM_WINDOW_ + 7, 105 SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW_ + 8, 106 KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW_ + 9, 107 SYSTEM_ERROR = FIRST_SYSTEM_WINDOW_ + 10, 108 INPUT_METHOD = FIRST_SYSTEM_WINDOW_ + 11, 109 INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW_ + 12, 110 WALLPAPER = FIRST_SYSTEM_WINDOW_ + 13, 111 STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW_ + 14, 112 SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW_ + 15, 113 DRAG = FIRST_SYSTEM_WINDOW_ + 16, 114 STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW_ + 17, 115 POINTER = FIRST_SYSTEM_WINDOW_ + 18, 116 NAVIGATION_BAR = FIRST_SYSTEM_WINDOW_ + 19, 117 VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW_ + 20, 118 BOOT_PROGRESS = FIRST_SYSTEM_WINDOW_ + 21, 119 INPUT_CONSUMER = FIRST_SYSTEM_WINDOW_ + 22, 120 NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW_ + 24, 121 MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW_ + 27, 122 ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW_ + 32, 123 DOCK_DIVIDER = FIRST_SYSTEM_WINDOW_ + 34, 124 ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW_ + 39, 125 NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW_ + 40, 126 127 FIRST_SYSTEM_WINDOW = FIRST_SYSTEM_WINDOW_, 128 LAST_SYSTEM_WINDOW = 2999, 129 130 #undef FIRST_SYSTEM_WINDOW_ 131 132 // Small range to limit LUT size. 133 ftl_first = FIRST_SYSTEM_WINDOW, 134 ftl_last = FIRST_SYSTEM_WINDOW + 15 135 }; 136 137 // Flags used to determine configuration of this input window. 138 // This is a conversion of os::InputConfig to an enum backed by an unsigned 139 // type. This indicates that they are flags, so it can be used with ftl/enum.h. 140 enum class InputConfig : uint32_t { 141 // clang-format off 142 DEFAULT = 143 static_cast<uint32_t>(os::InputConfig::DEFAULT), 144 NO_INPUT_CHANNEL = 145 static_cast<uint32_t>(os::InputConfig::NO_INPUT_CHANNEL), 146 NOT_VISIBLE = 147 static_cast<uint32_t>(os::InputConfig::NOT_VISIBLE), 148 NOT_FOCUSABLE = 149 static_cast<uint32_t>(os::InputConfig::NOT_FOCUSABLE), 150 NOT_TOUCHABLE = 151 static_cast<uint32_t>(os::InputConfig::NOT_TOUCHABLE), 152 PREVENT_SPLITTING = 153 static_cast<uint32_t>(os::InputConfig::PREVENT_SPLITTING), 154 DUPLICATE_TOUCH_TO_WALLPAPER = 155 static_cast<uint32_t>(os::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER), 156 IS_WALLPAPER = 157 static_cast<uint32_t>(os::InputConfig::IS_WALLPAPER), 158 PAUSE_DISPATCHING = 159 static_cast<uint32_t>(os::InputConfig::PAUSE_DISPATCHING), 160 TRUSTED_OVERLAY = 161 static_cast<uint32_t>(os::InputConfig::TRUSTED_OVERLAY), 162 WATCH_OUTSIDE_TOUCH = 163 static_cast<uint32_t>(os::InputConfig::WATCH_OUTSIDE_TOUCH), 164 SLIPPERY = 165 static_cast<uint32_t>(os::InputConfig::SLIPPERY), 166 DISABLE_USER_ACTIVITY = 167 static_cast<uint32_t>(os::InputConfig::DISABLE_USER_ACTIVITY), 168 DROP_INPUT = 169 static_cast<uint32_t>(os::InputConfig::DROP_INPUT), 170 DROP_INPUT_IF_OBSCURED = 171 static_cast<uint32_t>(os::InputConfig::DROP_INPUT_IF_OBSCURED), 172 SPY = 173 static_cast<uint32_t>(os::InputConfig::SPY), 174 INTERCEPTS_STYLUS = 175 static_cast<uint32_t>(os::InputConfig::INTERCEPTS_STYLUS), 176 CLONE = 177 static_cast<uint32_t>(os::InputConfig::CLONE), 178 // clang-format on 179 }; 180 181 /* These values are filled in by the WM and passed through SurfaceFlinger 182 * unless specified otherwise. 183 */ 184 // This value should NOT be used to uniquely identify the window. There may be different 185 // input windows that have the same token. 186 sp<IBinder> token; 187 188 // The token that identifies which client window this WindowInfo was created for. 189 sp<IBinder> windowToken; 190 191 // This uniquely identifies the input window. 192 int32_t id = -1; 193 std::string name; 194 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5); 195 196 /* These values are filled in by SurfaceFlinger. */ 197 int32_t frameLeft = -1; 198 int32_t frameTop = -1; 199 int32_t frameRight = -1; 200 int32_t frameBottom = -1; 201 202 /* 203 * SurfaceFlinger consumes this value to shrink the computed frame. This is 204 * different from shrinking the touchable region in that it DOES shift the coordinate 205 * space where-as the touchable region does not and is more like "cropping". This 206 * is used for window shadows. 207 */ 208 int32_t surfaceInset = 0; 209 210 // A global scaling factor for all windows. Unlike windowScaleX/Y this results 211 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis. 212 float globalScaleFactor = 1.0f; 213 214 // The opacity of this window, from 0.0 to 1.0 (inclusive). 215 // An alpha of 1.0 means fully opaque and 0.0 means fully transparent. 216 float alpha; 217 218 // Transform applied to individual windows. 219 ui::Transform transform; 220 221 /* 222 * This is filled in by the WM relative to the frame and then translated 223 * to absolute coordinates by SurfaceFlinger once the frame is computed. 224 */ 225 Region touchableRegion; 226 227 TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED; 228 Pid ownerPid = Pid::INVALID; 229 Uid ownerUid = Uid::INVALID; 230 std::string packageName; 231 ftl::Flags<InputConfig> inputConfig; 232 int32_t displayId = ADISPLAY_ID_NONE; 233 InputApplicationInfo applicationInfo; 234 bool replaceTouchableRegionWithCrop = false; 235 wp<IBinder> touchableRegionCropHandle; 236 237 // The window's layout params flags and type set by WM. 238 Type layoutParamsType = Type::UNKNOWN; 239 ftl::Flags<Flag> layoutParamsFlags; 240 241 // The input token for the window to which focus should be transferred when this input window 242 // can be successfully focused. If null, this input window will not transfer its focus to 243 // any other window. 244 sp<IBinder> focusTransferTarget; 245 246 void setInputConfig(ftl::Flags<InputConfig> config, bool value); 247 248 void addTouchableRegion(const Rect& region); 249 250 bool touchableRegionContainsPoint(int32_t x, int32_t y) const; 251 252 bool frameContainsPoint(int32_t x, int32_t y) const; 253 254 bool supportsSplitTouch() const; 255 256 bool isSpy() const; 257 258 bool interceptsStylus() const; 259 260 bool overlaps(const WindowInfo* other) const; 261 262 bool operator==(const WindowInfo& inputChannel) const; 263 264 status_t writeToParcel(android::Parcel* parcel) const override; 265 266 status_t readFromParcel(const android::Parcel* parcel) override; 267 }; 268 269 /* 270 * Handle for a window that can receive input. 271 * 272 * Used by the native input dispatcher to indirectly refer to the window manager objects 273 * that describe a window. 274 */ 275 class WindowInfoHandle : public RefBase { 276 public: 277 explicit WindowInfoHandle(); 278 WindowInfoHandle(const WindowInfoHandle& other); 279 WindowInfoHandle(const WindowInfo& other); 280 getInfo()281 inline const WindowInfo* getInfo() const { return &mInfo; } editInfo()282 inline WindowInfo* editInfo() { return &mInfo; } 283 284 sp<IBinder> getToken() const; 285 getId()286 int32_t getId() const { return mInfo.id; } 287 getApplicationToken()288 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; } 289 getName()290 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; } 291 getDispatchingTimeout(std::chrono::nanoseconds defaultValue)292 inline std::chrono::nanoseconds getDispatchingTimeout( 293 std::chrono::nanoseconds defaultValue) const { 294 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue; 295 } 296 297 /** 298 * Updates from another input window handle. 299 */ 300 void updateFrom(const sp<WindowInfoHandle> handle); 301 302 /** 303 * Releases the channel used by the associated information when it is 304 * no longer needed. 305 */ 306 void releaseChannel(); 307 308 // Not override since this class is not derrived from Parcelable. 309 status_t readFromParcel(const android::Parcel* parcel); 310 status_t writeToParcel(android::Parcel* parcel) const; 311 312 protected: 313 virtual ~WindowInfoHandle(); 314 315 WindowInfo mInfo; 316 }; 317 } // namespace android::gui 318