Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4601c17f authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Automerger Merge Worker
Browse files

Merge changes from topics "presubmit-am-e1ccffb4201944be9e638acb9f6f4dfc",...

Merge changes from topics "presubmit-am-e1ccffb4201944be9e638acb9f6f4dfc", "presubmit-am-e6236e948fb14688bc4afb3adb9e745b" into tm-dev am: dd2c72a6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17351976



Change-Id: Iacf94fba3ce56091fd83f274dae1195dedbd726f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 785a118f dd2c72a6
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -75,8 +75,15 @@ public abstract class InputManagerInternal {
    /**
    /**
     * Sets the display id that the MouseCursorController will be forced to target. Pass
     * Sets the display id that the MouseCursorController will be forced to target. Pass
     * {@link android.view.Display#INVALID_DISPLAY} to clear the override.
     * {@link android.view.Display#INVALID_DISPLAY} to clear the override.
     *
     * Note: This method generally blocks until the pointer display override has propagated.
     * When setting a new override, the caller should ensure that an input device that can control
     * the mouse pointer is connected. If a new override is set when no such input device is
     * connected, the caller may be blocked for an arbitrary period of time.
     *
     * @return true if the pointer displayId was set successfully, or false if it fails.
     */
     */
    public abstract void setVirtualMousePointerDisplayId(int pointerDisplayId);
    public abstract boolean setVirtualMousePointerDisplayId(int pointerDisplayId);


    /**
    /**
     * Gets the display id that the MouseCursorController is being forced to target. Returns
     * Gets the display id that the MouseCursorController is being forced to target. Returns
+7 −0
Original line number Original line Diff line number Diff line
@@ -106,6 +106,7 @@ PointerController::PointerController(const sp<PointerControllerPolicyInterface>&
PointerController::~PointerController() {
PointerController::~PointerController() {
    mDisplayInfoListener->onPointerControllerDestroyed();
    mDisplayInfoListener->onPointerControllerDestroyed();
    mUnregisterWindowInfosListener(mDisplayInfoListener);
    mUnregisterWindowInfosListener(mDisplayInfoListener);
    mContext.getPolicy()->onPointerDisplayIdChanged(ADISPLAY_ID_NONE, 0, 0);
}
}


std::mutex& PointerController::getLock() const {
std::mutex& PointerController::getLock() const {
@@ -255,6 +256,12 @@ void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
        getAdditionalMouseResources = true;
        getAdditionalMouseResources = true;
    }
    }
    mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
    mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
    if (viewport.displayId != mLocked.pointerDisplayId) {
        float xPos, yPos;
        mCursorController.getPosition(&xPos, &yPos);
        mContext.getPolicy()->onPointerDisplayIdChanged(viewport.displayId, xPos, yPos);
        mLocked.pointerDisplayId = viewport.displayId;
    }
}
}


void PointerController::updatePointerIcon(int32_t iconId) {
void PointerController::updatePointerIcon(int32_t iconId) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -104,6 +104,7 @@ private:


    struct Locked {
    struct Locked {
        Presentation presentation;
        Presentation presentation;
        int32_t pointerDisplayId = ADISPLAY_ID_NONE;


        std::vector<gui::DisplayInfo> mDisplayInfos;
        std::vector<gui::DisplayInfo> mDisplayInfos;
        std::unordered_map<int32_t /* displayId */, TouchSpotController> spotControllers;
        std::unordered_map<int32_t /* displayId */, TouchSpotController> spotControllers;
+1 −0
Original line number Original line Diff line number Diff line
@@ -79,6 +79,7 @@ public:
            std::map<int32_t, PointerAnimation>* outAnimationResources, int32_t displayId) = 0;
            std::map<int32_t, PointerAnimation>* outAnimationResources, int32_t displayId) = 0;
    virtual int32_t getDefaultPointerIconId() = 0;
    virtual int32_t getDefaultPointerIconId() = 0;
    virtual int32_t getCustomPointerIconId() = 0;
    virtual int32_t getCustomPointerIconId() = 0;
    virtual void onPointerDisplayIdChanged(int32_t displayId, float xPos, float yPos) = 0;
};
};


/*
/*
+37 −3
Original line number Original line Diff line number Diff line
@@ -56,9 +56,11 @@ public:
            std::map<int32_t, PointerAnimation>* outAnimationResources, int32_t displayId) override;
            std::map<int32_t, PointerAnimation>* outAnimationResources, int32_t displayId) override;
    virtual int32_t getDefaultPointerIconId() override;
    virtual int32_t getDefaultPointerIconId() override;
    virtual int32_t getCustomPointerIconId() override;
    virtual int32_t getCustomPointerIconId() override;
    virtual void onPointerDisplayIdChanged(int32_t displayId, float xPos, float yPos) override;


    bool allResourcesAreLoaded();
    bool allResourcesAreLoaded();
    bool noResourcesAreLoaded();
    bool noResourcesAreLoaded();
    std::optional<int32_t> getLastReportedPointerDisplayId() { return latestPointerDisplayId; }


private:
private:
    void loadPointerIconForType(SpriteIcon* icon, int32_t cursorType);
    void loadPointerIconForType(SpriteIcon* icon, int32_t cursorType);
@@ -66,6 +68,7 @@ private:
    bool pointerIconLoaded{false};
    bool pointerIconLoaded{false};
    bool pointerResourcesLoaded{false};
    bool pointerResourcesLoaded{false};
    bool additionalMouseResourcesLoaded{false};
    bool additionalMouseResourcesLoaded{false};
    std::optional<int32_t /*displayId*/> latestPointerDisplayId;
};
};


void MockPointerControllerPolicyInterface::loadPointerIcon(SpriteIcon* icon, int32_t) {
void MockPointerControllerPolicyInterface::loadPointerIcon(SpriteIcon* icon, int32_t) {
@@ -126,12 +129,19 @@ void MockPointerControllerPolicyInterface::loadPointerIconForType(SpriteIcon* ic
    icon->hotSpotX = hotSpot.first;
    icon->hotSpotX = hotSpot.first;
    icon->hotSpotY = hotSpot.second;
    icon->hotSpotY = hotSpot.second;
}
}

void MockPointerControllerPolicyInterface::onPointerDisplayIdChanged(int32_t displayId,
                                                                     float /*xPos*/,
                                                                     float /*yPos*/) {
    latestPointerDisplayId = displayId;
}

class PointerControllerTest : public Test {
class PointerControllerTest : public Test {
protected:
protected:
    PointerControllerTest();
    PointerControllerTest();
    ~PointerControllerTest();
    ~PointerControllerTest();


    void ensureDisplayViewportIsSet();
    void ensureDisplayViewportIsSet(int32_t displayId = ADISPLAY_ID_DEFAULT);


    sp<MockSprite> mPointerSprite;
    sp<MockSprite> mPointerSprite;
    sp<MockPointerControllerPolicyInterface> mPolicy;
    sp<MockPointerControllerPolicyInterface> mPolicy;
@@ -168,9 +178,9 @@ PointerControllerTest::~PointerControllerTest() {
    mThread.join();
    mThread.join();
}
}


void PointerControllerTest::ensureDisplayViewportIsSet() {
void PointerControllerTest::ensureDisplayViewportIsSet(int32_t displayId) {
    DisplayViewport viewport;
    DisplayViewport viewport;
    viewport.displayId = ADISPLAY_ID_DEFAULT;
    viewport.displayId = displayId;
    viewport.logicalRight = 1600;
    viewport.logicalRight = 1600;
    viewport.logicalBottom = 1200;
    viewport.logicalBottom = 1200;
    viewport.physicalRight = 800;
    viewport.physicalRight = 800;
@@ -255,6 +265,30 @@ TEST_F(PointerControllerTest, doesNotGetResourcesBeforeSettingViewport) {
    ensureDisplayViewportIsSet();
    ensureDisplayViewportIsSet();
}
}


TEST_F(PointerControllerTest, notifiesPolicyWhenPointerDisplayChanges) {
    EXPECT_FALSE(mPolicy->getLastReportedPointerDisplayId())
            << "A pointer display change does not occur when PointerController is created.";

    ensureDisplayViewportIsSet(ADISPLAY_ID_DEFAULT);

    const auto lastReportedPointerDisplayId = mPolicy->getLastReportedPointerDisplayId();
    ASSERT_TRUE(lastReportedPointerDisplayId)
            << "The policy is notified of a pointer display change when the viewport is first set.";
    EXPECT_EQ(ADISPLAY_ID_DEFAULT, *lastReportedPointerDisplayId)
            << "Incorrect pointer display notified.";

    ensureDisplayViewportIsSet(42);

    EXPECT_EQ(42, *mPolicy->getLastReportedPointerDisplayId())
            << "The policy is notified when the pointer display changes.";

    // Release the PointerController.
    mPointerController = nullptr;

    EXPECT_EQ(ADISPLAY_ID_NONE, *mPolicy->getLastReportedPointerDisplayId())
            << "The pointer display changes to invalid when PointerController is destroyed.";
}

class PointerControllerWindowInfoListenerTest : public Test {};
class PointerControllerWindowInfoListenerTest : public Test {};


class TestPointerController : public PointerController {
class TestPointerController : public PointerController {
Loading