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