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