InputWindow.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #ifndef _UI_INPUT_WINDOW_H
  17. #define _UI_INPUT_WINDOW_H
  18. #include <input/Input.h>
  19. #include <input/InputTransport.h>
  20. #include <ui/Rect.h>
  21. #include <ui/Region.h>
  22. #include <utils/RefBase.h>
  23. #include <utils/Timers.h>
  24. #include <utils/String8.h>
  25. #include "InputApplication.h"
  26. namespace android {
  27. /*
  28. * Describes the properties of a window that can receive input.
  29. */
  30. struct InputWindowInfo {
  31. // Window flags from WindowManager.LayoutParams
  32. enum {
  33. FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
  34. FLAG_DIM_BEHIND = 0x00000002,
  35. FLAG_BLUR_BEHIND = 0x00000004,
  36. FLAG_NOT_FOCUSABLE = 0x00000008,
  37. FLAG_NOT_TOUCHABLE = 0x00000010,
  38. FLAG_NOT_TOUCH_MODAL = 0x00000020,
  39. FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040,
  40. FLAG_KEEP_SCREEN_ON = 0x00000080,
  41. FLAG_LAYOUT_IN_SCREEN = 0x00000100,
  42. FLAG_LAYOUT_NO_LIMITS = 0x00000200,
  43. FLAG_FULLSCREEN = 0x00000400,
  44. FLAG_FORCE_NOT_FULLSCREEN = 0x00000800,
  45. FLAG_DITHER = 0x00001000,
  46. FLAG_SECURE = 0x00002000,
  47. FLAG_SCALED = 0x00004000,
  48. FLAG_IGNORE_CHEEK_PRESSES = 0x00008000,
  49. FLAG_LAYOUT_INSET_DECOR = 0x00010000,
  50. FLAG_ALT_FOCUSABLE_IM = 0x00020000,
  51. FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000,
  52. FLAG_SHOW_WHEN_LOCKED = 0x00080000,
  53. FLAG_SHOW_WALLPAPER = 0x00100000,
  54. FLAG_TURN_SCREEN_ON = 0x00200000,
  55. FLAG_DISMISS_KEYGUARD = 0x00400000,
  56. FLAG_SPLIT_TOUCH = 0x00800000,
  57. FLAG_SLIPPERY = 0x20000000,
  58. FLAG_NEEDS_MENU_KEY = 0x40000000,
  59. };
  60. // Window types from WindowManager.LayoutParams
  61. enum {
  62. FIRST_APPLICATION_WINDOW = 1,
  63. TYPE_BASE_APPLICATION = 1,
  64. TYPE_APPLICATION = 2,
  65. TYPE_APPLICATION_STARTING = 3,
  66. LAST_APPLICATION_WINDOW = 99,
  67. FIRST_SUB_WINDOW = 1000,
  68. TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW,
  69. TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1,
  70. TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2,
  71. TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3,
  72. TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4,
  73. LAST_SUB_WINDOW = 1999,
  74. FIRST_SYSTEM_WINDOW = 2000,
  75. TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW,
  76. TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1,
  77. TYPE_PHONE = FIRST_SYSTEM_WINDOW+2,
  78. TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3,
  79. TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4,
  80. TYPE_TOAST = FIRST_SYSTEM_WINDOW+5,
  81. TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6,
  82. TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7,
  83. TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8,
  84. TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9,
  85. TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10,
  86. TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11,
  87. TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12,
  88. TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW+13,
  89. TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+14,
  90. TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15,
  91. TYPE_DRAG = FIRST_SYSTEM_WINDOW+16,
  92. TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17,
  93. TYPE_POINTER = FIRST_SYSTEM_WINDOW+18,
  94. TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19,
  95. TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20,
  96. TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21,
  97. TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+22,
  98. LAST_SYSTEM_WINDOW = 2999,
  99. };
  100. enum {
  101. INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
  102. INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002,
  103. INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004,
  104. };
  105. sp<InputChannel> inputChannel;
  106. String8 name;
  107. int32_t layoutParamsFlags;
  108. int32_t layoutParamsType;
  109. nsecs_t dispatchingTimeout;
  110. int32_t frameLeft;
  111. int32_t frameTop;
  112. int32_t frameRight;
  113. int32_t frameBottom;
  114. float scaleFactor;
  115. Region touchableRegion;
  116. bool visible;
  117. bool canReceiveKeys;
  118. bool hasFocus;
  119. bool hasWallpaper;
  120. bool paused;
  121. int32_t layer;
  122. int32_t ownerPid;
  123. int32_t ownerUid;
  124. int32_t inputFeatures;
  125. int32_t displayId;
  126. void addTouchableRegion(const Rect& region);
  127. bool touchableRegionContainsPoint(int32_t x, int32_t y) const;
  128. bool frameContainsPoint(int32_t x, int32_t y) const;
  129. /* Returns true if the window is of a trusted type that is allowed to silently
  130. * overlay other windows for the purpose of implementing the secure views feature.
  131. * Trusted overlays, such as IME windows, can partly obscure other windows without causing
  132. * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED.
  133. */
  134. bool isTrustedOverlay() const;
  135. bool supportsSplitTouch() const;
  136. bool overlaps(const InputWindowInfo* other) const;
  137. };
  138. /*
  139. * Handle for a window that can receive input.
  140. *
  141. * Used by the native input dispatcher to indirectly refer to the window manager objects
  142. * that describe a window.
  143. */
  144. class InputWindowHandle : public RefBase {
  145. public:
  146. const sp<InputApplicationHandle> inputApplicationHandle;
  147. inline const InputWindowInfo* getInfo() const {
  148. return mInfo;
  149. }
  150. inline sp<InputChannel> getInputChannel() const {
  151. return mInfo ? mInfo->inputChannel : NULL;
  152. }
  153. inline String8 getName() const {
  154. return mInfo ? mInfo->name : String8("<invalid>");
  155. }
  156. inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const {
  157. return mInfo ? mInfo->dispatchingTimeout : defaultValue;
  158. }
  159. /**
  160. * Requests that the state of this object be updated to reflect
  161. * the most current available information about the application.
  162. *
  163. * This method should only be called from within the input dispatcher's
  164. * critical section.
  165. *
  166. * Returns true on success, or false if the handle is no longer valid.
  167. */
  168. virtual bool updateInfo() = 0;
  169. /**
  170. * Releases the storage used by the associated information when it is
  171. * no longer needed.
  172. */
  173. void releaseInfo();
  174. protected:
  175. InputWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle);
  176. virtual ~InputWindowHandle();
  177. InputWindowInfo* mInfo;
  178. };
  179. } // namespace android
  180. #endif // _UI_INPUT_WINDOW_H