summaryrefslogtreecommitdiff
path: root/include/input/InputWindow.h
blob: 121be6d963bfe2490edbaa227d29663d10eb4336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _UI_INPUT_WINDOW_H
#define _UI_INPUT_WINDOW_H

#include <android/os/TouchOcclusionMode.h>
#include <binder/Parcel.h>
#include <binder/Parcelable.h>
#include <input/Flags.h>
#include <input/Input.h>
#include <input/InputTransport.h>
#include <ui/Rect.h>
#include <ui/Region.h>
#include <ui/Transform.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>

#include "InputApplication.h"

using android::os::TouchOcclusionMode;

namespace android {

/*
 * Describes the properties of a window that can receive input.
 */
struct InputWindowInfo : public Parcelable {
    InputWindowInfo() = default;

    // Window flags from WindowManager.LayoutParams
    enum class Flag : uint32_t {
        ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
        DIM_BEHIND = 0x00000002,
        BLUR_BEHIND = 0x00000004,
        NOT_FOCUSABLE = 0x00000008,
        NOT_TOUCHABLE = 0x00000010,
        NOT_TOUCH_MODAL = 0x00000020,
        TOUCHABLE_WHEN_WAKING = 0x00000040,
        KEEP_SCREEN_ON = 0x00000080,
        LAYOUT_IN_SCREEN = 0x00000100,
        LAYOUT_NO_LIMITS = 0x00000200,
        FULLSCREEN = 0x00000400,
        FORCE_NOT_FULLSCREEN = 0x00000800,
        DITHER = 0x00001000,
        SECURE = 0x00002000,
        SCALED = 0x00004000,
        IGNORE_CHEEK_PRESSES = 0x00008000,
        LAYOUT_INSET_DECOR = 0x00010000,
        ALT_FOCUSABLE_IM = 0x00020000,
        WATCH_OUTSIDE_TOUCH = 0x00040000,
        SHOW_WHEN_LOCKED = 0x00080000,
        SHOW_WALLPAPER = 0x00100000,
        TURN_SCREEN_ON = 0x00200000,
        DISMISS_KEYGUARD = 0x00400000,
        SPLIT_TOUCH = 0x00800000,
        HARDWARE_ACCELERATED = 0x01000000,
        LAYOUT_IN_OVERSCAN = 0x02000000,
        TRANSLUCENT_STATUS = 0x04000000,
        TRANSLUCENT_NAVIGATION = 0x08000000,
        LOCAL_FOCUS_MODE = 0x10000000,
        SLIPPERY = 0x20000000,
        LAYOUT_ATTACHED_IN_DECOR = 0x40000000,
        DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000,
    }; // Window types from WindowManager.LayoutParams

    enum class Type : int32_t {
        UNKNOWN = 0,
        FIRST_APPLICATION_WINDOW = 1,
        BASE_APPLICATION = 1,
        APPLICATION = 2,
        APPLICATION_STARTING = 3,
        LAST_APPLICATION_WINDOW = 99,
        FIRST_SUB_WINDOW = 1000,
        APPLICATION_PANEL = FIRST_SUB_WINDOW,
        APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1,
        APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2,
        APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3,
        APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4,
        LAST_SUB_WINDOW = 1999,
        FIRST_SYSTEM_WINDOW = 2000,
        STATUS_BAR = FIRST_SYSTEM_WINDOW,
        SEARCH_BAR = FIRST_SYSTEM_WINDOW + 1,
        PHONE = FIRST_SYSTEM_WINDOW + 2,
        SYSTEM_ALERT = FIRST_SYSTEM_WINDOW + 3,
        KEYGUARD = FIRST_SYSTEM_WINDOW + 4,
        TOAST = FIRST_SYSTEM_WINDOW + 5,
        SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 6,
        PRIORITY_PHONE = FIRST_SYSTEM_WINDOW + 7,
        SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW + 8,
        KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW + 9,
        SYSTEM_ERROR = FIRST_SYSTEM_WINDOW + 10,
        INPUT_METHOD = FIRST_SYSTEM_WINDOW + 11,
        INPUT_METHOD_DIALOG = FIRST_SYSTEM_WINDOW + 12,
        WALLPAPER = FIRST_SYSTEM_WINDOW + 13,
        STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW + 14,
        SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW + 15,
        DRAG = FIRST_SYSTEM_WINDOW + 16,
        STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW + 17,
        POINTER = FIRST_SYSTEM_WINDOW + 18,
        NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19,
        VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW + 20,
        BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21,
        INPUT_CONSUMER = FIRST_SYSTEM_WINDOW + 22,
        NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW + 24,
        MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 27,
        ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW + 32,
        DOCK_DIVIDER = FIRST_SYSTEM_WINDOW + 34,
        ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39,
        NOTIFICATION_SHADE = FIRST_SYSTEM_WINDOW + 40,
        LAST_SYSTEM_WINDOW = 2999,
    };

    enum class Feature {
        DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
        NO_INPUT_CHANNEL = 0x00000002,
        DISABLE_USER_ACTIVITY = 0x00000004,
    };

    /* These values are filled in by the WM and passed through SurfaceFlinger
     * unless specified otherwise.
     */
    // This value should NOT be used to uniquely identify the window. There may be different
    // input windows that have the same token.
    sp<IBinder> token;
    // This uniquely identifies the input window.
    int32_t id = -1;
    std::string name;
    Flags<Flag> flags;
    Type type = Type::UNKNOWN;
    std::chrono::nanoseconds dispatchingTimeout = std::chrono::seconds(5);

    /* These values are filled in by SurfaceFlinger. */
    int32_t frameLeft = -1;
    int32_t frameTop = -1;
    int32_t frameRight = -1;
    int32_t frameBottom = -1;

    /*
     * SurfaceFlinger consumes this value to shrink the computed frame. This is
     * different from shrinking the touchable region in that it DOES shift the coordinate
     * space where-as the touchable region does not and is more like "cropping". This
     * is used for window shadows.
     */
    int32_t surfaceInset = 0;

    // A global scaling factor for all windows. Unlike windowScaleX/Y this results
    // in scaling of the TOUCH_MAJOR/TOUCH_MINOR axis.
    float globalScaleFactor = 1.0f;

    // The opacity of this window, from 0.0 to 1.0 (inclusive).
    // An alpha of 1.0 means fully opaque and 0.0 means fully transparent.
    float alpha;

    // Transform applied to individual windows.
    ui::Transform transform;

    // Display size in its natural rotation. Used to rotate raw coordinates for compatibility.
    int32_t displayWidth = AMOTION_EVENT_INVALID_DISPLAY_SIZE;
    int32_t displayHeight = AMOTION_EVENT_INVALID_DISPLAY_SIZE;

    /*
     * This is filled in by the WM relative to the frame and then translated
     * to absolute coordinates by SurfaceFlinger once the frame is computed.
     */
    Region touchableRegion;
    bool visible = false;
    bool focusable = false;
    bool hasWallpaper = false;
    bool paused = false;
    /* This flag is set when the window is of a trusted type that is allowed to silently
     * overlay other windows for the purpose of implementing the secure views feature.
     * Trusted overlays, such as IME windows, can partly obscure other windows without causing
     * motion events to be delivered to them with AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED.
     */
    bool trustedOverlay = false;
    TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED;
    int32_t ownerPid = -1;
    int32_t ownerUid = -1;
    std::string packageName;
    Flags<Feature> inputFeatures;
    int32_t displayId = ADISPLAY_ID_NONE;
    int32_t portalToDisplayId = ADISPLAY_ID_NONE;
    InputApplicationInfo applicationInfo;
    bool replaceTouchableRegionWithCrop = false;
    wp<IBinder> touchableRegionCropHandle;

    void addTouchableRegion(const Rect& region);

    bool touchableRegionContainsPoint(int32_t x, int32_t y) const;

    bool frameContainsPoint(int32_t x, int32_t y) const;

    bool supportsSplitTouch() const;

    bool overlaps(const InputWindowInfo* other) const;

    bool operator==(const InputWindowInfo& inputChannel) const;

    status_t writeToParcel(android::Parcel* parcel) const override;

    status_t readFromParcel(const android::Parcel* parcel) override;
};

/*
 * Handle for a window that can receive input.
 *
 * Used by the native input dispatcher to indirectly refer to the window manager objects
 * that describe a window.
 */
class InputWindowHandle : public RefBase {
public:
    explicit InputWindowHandle();
    InputWindowHandle(const InputWindowHandle& other);
    InputWindowHandle(const InputWindowInfo& other);

    inline const InputWindowInfo* getInfo() const { return &mInfo; }

    sp<IBinder> getToken() const;

    int32_t getId() const { return mInfo.id; }

    sp<IBinder> getApplicationToken() { return mInfo.applicationInfo.token; }

    inline std::string getName() const { return !mInfo.name.empty() ? mInfo.name : "<invalid>"; }

    inline std::chrono::nanoseconds getDispatchingTimeout(
            std::chrono::nanoseconds defaultValue) const {
        return mInfo.token ? std::chrono::nanoseconds(mInfo.dispatchingTimeout) : defaultValue;
    }

    /**
     * Requests that the state of this object be updated to reflect
     * the most current available information about the application.
     * As this class is created as RefBase object, no pure virtual function is allowed.
     *
     * This method should only be called from within the input dispatcher's
     * critical section.
     *
     * Returns true on success, or false if the handle is no longer valid.
     */
    virtual bool updateInfo() { return false; }

    /**
     * Updates from another input window handle.
     */
    void updateFrom(const sp<InputWindowHandle> handle);

    /**
     * Releases the channel used by the associated information when it is
     * no longer needed.
     */
    void releaseChannel();

    // Not override since this class is not derrived from Parcelable.
    status_t readFromParcel(const android::Parcel* parcel);
    status_t writeToParcel(android::Parcel* parcel) const;

protected:
    virtual ~InputWindowHandle();

    InputWindowInfo mInfo;
};
} // namespace android

#endif // _UI_INPUT_WINDOW_H