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 <ui/LogicalDisplayId.h> 27 #include <ui/Rect.h> 28 #include <ui/Region.h> 29 #include <ui/Size.h> 30 #include <ui/Transform.h> 31 #include <utils/RefBase.h> 32 #include <utils/Timers.h> 33 34 #include "InputApplication.h" 35 36 namespace android::gui { 37 38 /* 39 * Describes the properties of a window that can receive input. 40 */ 41 struct WindowInfo : public Parcelable { 42 WindowInfo() = 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 }; 79 80 // Window types from WindowManager.LayoutParams 81 enum class Type : int32_t { 82 UNKNOWN = 0, 83 FIRST_APPLICATION_WINDOW = 1, 84 BASE_APPLICATION = 1, 85 APPLICATION = 2, 86 APPLICATION_STARTING = 3, 87 LAST_APPLICATION_WINDOW = 99, 88 FIRST_SUB_WINDOW = 1000, 89 APPLICATION_PANEL = FIRST_SUB_WINDOW, 90 APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1, 91 APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2, 92 APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3, 93 APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4, 94 LAST_SUB_WINDOW = 1999, 95 96 #define FIRST_SYSTEM_WINDOW_ 2000 97 98 STATUS_BAR = FIRST_SYSTEM_WINDOW_, 99 SEARCH_BAR = FIRST_SYSTEM_WINDOW_ + 1, 100 PHONE = FIRST_SYSTEM_WINDOW_ + 2, 101 SYSTEM_ALERT = FIRST_SYSTEM_WINDOW_ + 3, 102 KEYGUARD = FIRST_SYSTEM_WINDOW_ + 4, 103 TOAST = FIRST_SYSTEM_WINDOW_ + 5, 104 SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW_ + 6, 105 PRIORITY_PHONE = FIRST_SYSTEM_WINDOW_ + 7, 106 SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW_ + 8, 107 KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW_ + 9, 108 SYSTEM_ERROR = FIRST_SYSTEM_WINDOW_ + 10, 109 INPUT_METHOD = FIRST_SYSTEM_WINDOW_ + 11, 110 INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW_ + 12, 111 WALLPAPER = FIRST_SYSTEM_WINDOW_ + 13, 112 STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW_ + 14, 113 SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW_ + 15, 114 DRAG = FIRST_SYSTEM_WINDOW_ + 16, 115 STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW_ + 17, 116 POINTER = FIRST_SYSTEM_WINDOW_ + 18, 117 NAVIGATION_BAR = FIRST_SYSTEM_WINDOW_ + 19, 118 VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW_ + 20, 119 BOOT_PROGRESS = FIRST_SYSTEM_WINDOW_ + 21, 120 INPUT_CONSUMER = FIRST_SYSTEM_WINDOW_ + 22, 121 NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW_ + 24, 122 MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW_ + 27, 123 ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW_ + 32, 124 DOCK_DIVIDER = FIRST_SYSTEM_WINDOW_ + 34, 125 ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW_ + 39, 126 NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW_ + 40, 127 128 FIRST_SYSTEM_WINDOW = FIRST_SYSTEM_WINDOW_, 129 LAST_SYSTEM_WINDOW = 2999, 130 131 #undef FIRST_SYSTEM_WINDOW_ 132 133 // Small range to limit LUT size. 134 ftl_first = FIRST_SYSTEM_WINDOW, 135 ftl_last = FIRST_SYSTEM_WINDOW + 15 136 }; 137 138 // Flags used to determine configuration of this input window. 139 // This is a conversion of os::InputConfig to an enum backed by an unsigned 140 // type. This indicates that they are flags, so it can be used with ftl/enum.h. 141 enum class InputConfig : uint32_t { 142 // clang-format off 143 DEFAULT = 144 static_cast<uint32_t>(os::InputConfig::DEFAULT), 145 NO_INPUT_CHANNEL = 146 static_cast<uint32_t>(os::InputConfig::NO_INPUT_CHANNEL), 147 NOT_VISIBLE = 148 static_cast<uint32_t>(os::InputConfig::NOT_VISIBLE), 149 NOT_FOCUSABLE = 150 static_cast<uint32_t>(os::InputConfig::NOT_FOCUSABLE), 151 NOT_TOUCHABLE = 152 static_cast<uint32_t>(os::InputConfig::NOT_TOUCHABLE), 153 PREVENT_SPLITTING = 154 static_cast<uint32_t>(os::InputConfig::PREVENT_SPLITTING), 155 DUPLICATE_TOUCH_TO_WALLPAPER = 156 static_cast<uint32_t>(os::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER), 157 IS_WALLPAPER = 158 static_cast<uint32_t>(os::InputConfig::IS_WALLPAPER), 159 PAUSE_DISPATCHING = 160 static_cast<uint32_t>(os::InputConfig::PAUSE_DISPATCHING), 161 TRUSTED_OVERLAY = 162 static_cast<uint32_t>(os::InputConfig::TRUSTED_OVERLAY), 163 WATCH_OUTSIDE_TOUCH = 164 static_cast<uint32_t>(os::InputConfig::WATCH_OUTSIDE_TOUCH), 165 SLIPPERY = 166 static_cast<uint32_t>(os::InputConfig::SLIPPERY), 167 DISABLE_USER_ACTIVITY = 168 static_cast<uint32_t>(os::InputConfig::DISABLE_USER_ACTIVITY), 169 DROP_INPUT = 170 static_cast<uint32_t>(os::InputConfig::DROP_INPUT), 171 DROP_INPUT_IF_OBSCURED = 172 static_cast<uint32_t>(os::InputConfig::DROP_INPUT_IF_OBSCURED), 173 SPY = 174 static_cast<uint32_t>(os::InputConfig::SPY), 175 INTERCEPTS_STYLUS = 176 static_cast<uint32_t>(os::InputConfig::INTERCEPTS_STYLUS), 177 CLONE = 178 static_cast<uint32_t>(os::InputConfig::CLONE), 179 GLOBAL_STYLUS_BLOCKS_TOUCH = 180 static_cast<uint32_t>(os::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH), 181 SENSITIVE_FOR_PRIVACY = 182 static_cast<uint32_t>(os::InputConfig::SENSITIVE_FOR_PRIVACY), 183 // clang-format on 184 }; 185 186 /* These values are filled in by the WM and passed through SurfaceFlinger 187 * unless specified otherwise. 188 */ 189 // This value should NOT be used to uniquely identify the window. There may be different 190 // input windows that have the same token. 191 sp<IBinder> token; 192 193 // The token that identifies which client window this WindowInfo was created for. 194 sp<IBinder> windowToken; 195 196 // This uniquely identifies the input window. 197 int32_t id = -1; 198 std::string name; 199 std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5); 200 201 /* These values are filled in by SurfaceFlinger. */ 202 Rect frame = Rect::INVALID_RECT; 203 204 // The real size of the content, excluding any crop. If no buffer is rendered, this is 0,0 205 ui::Size contentSize = ui::Size(0, 0); 206 207 /* 208 * SurfaceFlinger consumes this value to shrink the computed frame. This is 209 * different from shrinking the touchable region in that it DOES shift the coordinate 210 * space where-as the touchable region does not and is more like "cropping". This 211 * is used for window shadows. 212 */ 213 int32_t surfaceInset = 0; 214 215 // A global scaling factor for all windows. Unlike windowScaleX/Y this results 216 // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis. 217 float globalScaleFactor = 1.0f; 218 219 // The opacity of this window, from 0.0 to 1.0 (inclusive). 220 // An alpha of 1.0 means fully opaque and 0.0 means fully transparent. 221 float alpha; 222 223 // Transform applied to individual windows. 224 ui::Transform transform; 225 226 /* 227 * This is filled in by the WM relative to the frame and then translated 228 * to absolute coordinates by SurfaceFlinger once the frame is computed. 229 */ 230 Region touchableRegion; 231 232 TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED; 233 Pid ownerPid = Pid::INVALID; 234 Uid ownerUid = Uid::INVALID; 235 std::string packageName; 236 ftl::Flags<InputConfig> inputConfig; 237 ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID; 238 InputApplicationInfo applicationInfo; 239 bool replaceTouchableRegionWithCrop = false; 240 wp<IBinder> touchableRegionCropHandle; 241 242 // The window's layout params flags and type set by WM. 243 Type layoutParamsType = Type::UNKNOWN; 244 ftl::Flags<Flag> layoutParamsFlags; 245 246 // The input token for the window to which focus should be transferred when this input window 247 // can be successfully focused. If null, this input window will not transfer its focus to 248 // any other window. 249 sp<IBinder> focusTransferTarget; 250 251 // Sets a property on this window indicating that its visible region should be considered when 252 // computing TrustedPresentation Thresholds. 253 bool canOccludePresentation = false; 254 255 void setInputConfig(ftl::Flags<InputConfig> config, bool value); 256 257 void addTouchableRegion(const Rect& region); 258 259 bool supportsSplitTouch() const; 260 261 bool isSpy() const; 262 263 bool interceptsStylus() const; 264 265 bool overlaps(const WindowInfo* other) const; 266 267 bool operator==(const WindowInfo& inputChannel) const; 268 269 status_t writeToParcel(android::Parcel* parcel) const override; 270 271 status_t readFromParcel(const android::Parcel* parcel) override; 272 }; 273 274 std::ostream& operator<<(std::ostream& out, const WindowInfo& window); 275 276 /* 277 * Handle for a window that can receive input. 278 * 279 * Used by the native input dispatcher to indirectly refer to the window manager objects 280 * that describe a window. 281 */ 282 class WindowInfoHandle : public RefBase { 283 public: 284 explicit WindowInfoHandle(); 285 WindowInfoHandle(const WindowInfoHandle& other); 286 WindowInfoHandle(const WindowInfo& other); 287 getInfo()288 inline const WindowInfo* getInfo() const { return &mInfo; } editInfo()289 inline WindowInfo* editInfo() { return &mInfo; } 290 291 sp<IBinder> getToken() const; 292 getId()293 int32_t getId() const { return mInfo.id; } 294 getApplicationToken()295 sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; } 296 getName()297 inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; } 298 getDispatchingTimeout(std::chrono::nanoseconds defaultValue)299 inline std::chrono::nanoseconds getDispatchingTimeout( 300 std::chrono::nanoseconds defaultValue) const { 301 return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue; 302 } 303 304 /** 305 * Updates from another input window handle. 306 */ 307 void updateFrom(const sp<WindowInfoHandle> handle); 308 309 /** 310 * Releases the channel used by the associated information when it is 311 * no longer needed. 312 */ 313 void releaseChannel(); 314 315 // Not override since this class is not derrived from Parcelable. 316 status_t readFromParcel(const android::Parcel* parcel); 317 status_t writeToParcel(android::Parcel* parcel) const; 318 319 protected: 320 virtual ~WindowInfoHandle(); 321 322 WindowInfo mInfo; 323 }; 324 325 std::ostream& operator<<(std::ostream& out, const WindowInfoHandle& window); 326 327 } // namespace android::gui 328