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