xref: /aosp_15_r20/frameworks/native/services/inputflinger/tests/FakePointerController.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright 2022 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 <PointerControllerInterface.h>
20 #include <input/DisplayViewport.h>
21 #include <input/Input.h>
22 #include <utils/BitSet.h>
23 #include <unordered_set>
24 
25 namespace android {
26 
27 struct SpriteIcon {
28     PointerIconStyle style;
29 };
30 
31 class FakePointerController : public PointerControllerInterface {
32 public:
FakePointerController()33     FakePointerController() : FakePointerController(/*enabled=*/true) {}
FakePointerController(bool enabled)34     FakePointerController(bool enabled) : mEnabled(enabled) {}
35 
~FakePointerController()36     virtual ~FakePointerController() {}
37 
38     void setBounds(float minX, float minY, float maxX, float maxY);
39     void clearBounds();
40     const std::map<ui::LogicalDisplayId, std::vector<int32_t>>& getSpots();
41 
42     void setPosition(float x, float y) override;
43     vec2 getPosition() const override;
44     ui::LogicalDisplayId getDisplayId() const override;
45     void setDisplayViewport(const DisplayViewport& viewport) override;
46     void updatePointerIcon(PointerIconStyle iconId) override;
47     void setCustomPointerIcon(const SpriteIcon& icon) override;
48     void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) override;
49     void clearSkipScreenshotFlags() override;
50     void fade(Transition) override;
51     ui::Transform getDisplayTransform() const override;
52 
53     void assertViewportSet(ui::LogicalDisplayId displayId);
54     void assertViewportNotSet();
55     void assertPosition(float x, float y);
56     void assertSpotCount(ui::LogicalDisplayId displayId, int32_t count);
57     void assertPointerIconSet(PointerIconStyle iconId);
58     void assertPointerIconNotSet();
59     void assertCustomPointerIconSet(PointerIconStyle iconId);
60     void assertCustomPointerIconNotSet();
61     void assertIsSkipScreenshotFlagSet(ui::LogicalDisplayId displayId);
62     void assertIsSkipScreenshotFlagNotSet(ui::LogicalDisplayId displayId);
63     void assertSkipScreenshotFlagChanged();
64     void assertSkipScreenshotFlagNotChanged();
65     bool isPointerShown();
66 
67 private:
dump()68     std::string dump() override { return ""; }
69     vec2 move(float deltaX, float deltaY) override;
70     void unfade(Transition) override;
setPresentation(Presentation)71     void setPresentation(Presentation) override {}
72     void setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
73                   ui::LogicalDisplayId displayId) override;
74     void clearSpots() override;
75 
76     const bool mEnabled;
77     bool mHaveBounds{false};
78     float mMinX{0}, mMinY{0}, mMaxX{0}, mMaxY{0};
79     float mX{0}, mY{0};
80     std::optional<ui::LogicalDisplayId> mDisplayId;
81     bool mIsPointerShown{false};
82     std::optional<PointerIconStyle> mIconStyle;
83     std::optional<PointerIconStyle> mCustomIconStyle;
84 
85     std::map<ui::LogicalDisplayId, std::vector<int32_t>> mSpotsByDisplay;
86     std::unordered_set<ui::LogicalDisplayId> mDisplaysToSkipScreenshot;
87     bool mDisplaysToSkipScreenshotFlagChanged{false};
88 };
89 
90 } // namespace android
91