• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <bitset>
20 #include <set>
21 #include "TouchedWindow.h"
22 
23 namespace android {
24 
25 namespace gui {
26 class WindowInfoHandle;
27 }
28 
29 namespace inputdispatcher {
30 
31 struct TouchState {
32     std::vector<TouchedWindow> windows;
33 
34     TouchState() = default;
35     ~TouchState() = default;
36     TouchState& operator=(const TouchState&) = default;
37 
38     void reset();
39     void clearWindowsWithoutPointers();
40 
41     std::set<int32_t> getActiveDeviceIds() const;
42 
43     bool hasTouchingPointers(int32_t device) const;
44     void removeTouchingPointer(int32_t deviceId, int32_t pointerId);
45     void removeTouchingPointerFromWindow(int32_t deviceId, int32_t pointerId,
46                                          const sp<android::gui::WindowInfoHandle>& windowHandle);
47     void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
48                            ftl::Flags<InputTarget::Flags> targetFlags, int32_t deviceId,
49                            std::bitset<MAX_POINTER_ID + 1> touchingPointerIds,
50                            std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt);
51     void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
52                                     int32_t deviceId, int32_t hoveringPointerId);
53     void removeHoveringPointer(int32_t deviceId, int32_t hoveringPointerId);
54     void clearHoveringPointers();
55 
56     void removeAllPointersForDevice(int32_t deviceId);
57     void removeWindowByToken(const sp<IBinder>& token);
58     void filterNonAsIsTouchWindows();
59 
60     // Cancel pointers for current set of windows except the window with particular binder token.
61     void cancelPointersForWindowsExcept(int32_t deviceId,
62                                         std::bitset<MAX_POINTER_ID + 1> pointerIds,
63                                         const sp<IBinder>& token);
64     // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow
65     // set to false.
66     void cancelPointersForNonPilferingWindows();
67 
68     sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle() const;
69     bool isSlippery() const;
70     sp<android::gui::WindowInfoHandle> getWallpaperWindow() const;
71     const TouchedWindow& getTouchedWindow(
72             const sp<android::gui::WindowInfoHandle>& windowHandle) const;
73     // Whether any of the windows are currently being touched
74     bool isDown() const;
75     bool hasHoveringPointers() const;
76 
77     std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer(
78             int32_t deviceId, int32_t pointerId) const;
79     std::string dump() const;
80 };
81 
82 } // namespace inputdispatcher
83 } // namespace android
84