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

Commit c79d8ad9 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7761443 from f7f7af94 to sc-v2-release

Change-Id: I6351be8d0f2b532eae415441de6f124044b9f0c2
parents 8aa8f8c9 f7f7af94
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -292,6 +292,17 @@ public:
        return {};
    }

    status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId* displayId) const override {
        Parcel data, reply;
        SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
        SAFE_PARCEL(remote()->transact, BnSurfaceComposer::GET_PRIMARY_PHYSICAL_DISPLAY_ID, data,
                    &reply);
        uint64_t rawId;
        SAFE_PARCEL(reply.readUint64, &rawId);
        *displayId = PhysicalDisplayId(rawId);
        return NO_ERROR;
    }

    sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const override {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@@ -1730,6 +1741,16 @@ status_t BnSurfaceComposer::onTransact(
                           [](PhysicalDisplayId id) { return id.value; });
            return reply->writeUint64Vector(rawIds);
        }
        case GET_PRIMARY_PHYSICAL_DISPLAY_ID: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            PhysicalDisplayId id;
            status_t result = getPrimaryPhysicalDisplayId(&id);
            if (result != NO_ERROR) {
                ALOGE("getPrimaryPhysicalDisplayId: Failed to get id");
                return result;
            }
            return reply->writeUint64(id.value);
        }
        case ADD_REGION_SAMPLING_LISTENER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            Rect samplingArea;
+4 −0
Original line number Diff line number Diff line
@@ -937,6 +937,10 @@ std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
    return ComposerService::getComposerService()->getPhysicalDisplayIds();
}

status_t SurfaceComposerClient::getPrimaryPhysicalDisplayId(PhysicalDisplayId* id) {
    return ComposerService::getComposerService()->getPrimaryPhysicalDisplayId(id);
}

std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
    return ComposerService::getComposerService()->getInternalDisplayId();
}
+3 −0
Original line number Diff line number Diff line
@@ -141,6 +141,8 @@ public:
     */
    virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const = 0;

    virtual status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const = 0;

    // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic.
    std::optional<PhysicalDisplayId> getInternalDisplayId() const {
        const auto displayIds = getPhysicalDisplayIds();
@@ -632,6 +634,7 @@ public:
        REMOVE_TUNNEL_MODE_ENABLED_LISTENER,
        ADD_WINDOW_INFOS_LISTENER,
        REMOVE_WINDOW_INFOS_LISTENER,
        GET_PRIMARY_PHYSICAL_DISPLAY_ID,
        // Always append new enum to the end.
    };

+1 −0
Original line number Diff line number Diff line
@@ -308,6 +308,7 @@ public:

    //! Get stable IDs for connected physical displays
    static std::vector<PhysicalDisplayId> getPhysicalDisplayIds();
    static status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*);
    static std::optional<PhysicalDisplayId> getInternalDisplayId();

    //! Get token for a physical display given its stable ID
+169 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <memory>

#include <android/keycodes.h>
#include <android/native_window.h>

#include <binder/Binder.h>
@@ -120,8 +121,8 @@ public:
        return std::make_unique<InputSurface>(surfaceControl, width, height);
    }

    InputEvent* consumeEvent() {
        waitForEventAvailable();
    InputEvent *consumeEvent(int timeoutMs = 3000) {
        waitForEventAvailable(timeoutMs);

        InputEvent *ev;
        uint32_t seqId;
@@ -178,6 +179,24 @@ public:
        EXPECT_EQ(flags, mev->getFlags() & flags);
    }

    void expectKey(uint32_t keycode) {
        InputEvent *ev = consumeEvent();
        ASSERT_NE(ev, nullptr);
        ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, ev->getType());
        KeyEvent *keyEvent = static_cast<KeyEvent *>(ev);
        EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, keyEvent->getAction());
        EXPECT_EQ(keycode, keyEvent->getKeyCode());
        EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS);

        ev = consumeEvent();
        ASSERT_NE(ev, nullptr);
        ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, ev->getType());
        keyEvent = static_cast<KeyEvent *>(ev);
        EXPECT_EQ(AMOTION_EVENT_ACTION_UP, keyEvent->getAction());
        EXPECT_EQ(keycode, keyEvent->getKeyCode());
        EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS);
    }

    virtual ~InputSurface() {
        mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken());
    }
@@ -215,12 +234,12 @@ public:
    }

private:
    void waitForEventAvailable() {
    void waitForEventAvailable(int timeoutMs) {
        struct pollfd fd;

        fd.fd = mClientChannel->getFd();
        fd.events = POLLIN;
        poll(&fd, 1, 3000);
        poll(&fd, 1, timeoutMs);
    }

    void populateInputInfo(int width, int height) {
@@ -363,6 +382,14 @@ void injectTap(int x, int y) {
    }
}

void injectKey(uint32_t keycode) {
    char *buf1;
    asprintf(&buf1, "%d", keycode);
    if (fork() == 0) {
        execlp("input", "input", "keyevent", buf1, NULL);
    }
}

TEST_F(InputSurfacesTest, can_receive_input) {
    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->showAt(100, 100);
@@ -614,6 +641,9 @@ TEST_F(InputSurfacesTest, can_be_focused) {
    surface->requestFocus();

    surface->assertFocusChange(true);

    injectKey(AKEYCODE_V);
    surface->expectKey(AKEYCODE_V);
}

TEST_F(InputSurfacesTest, rotate_surface) {
@@ -781,4 +811,139 @@ TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_blast) {
    surface->expectTap(1, 1);
}

TEST_F(InputSurfacesTest, strict_unobscured_input_unobscured_window) {
    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->doTransaction(
            [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); });
    surface->showAt(100, 100);

    injectTap(101, 101);

    EXPECT_NE(surface->consumeEvent(), nullptr);
    EXPECT_NE(surface->consumeEvent(), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    surface->expectKey(AKEYCODE_V);
}

TEST_F(InputSurfacesTest, strict_unobscured_input_scaled_without_crop_window) {
    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->doTransaction([&](auto &t, auto &sc) {
        t.setDropInputMode(sc, gui::DropInputMode::OBSCURED);
        t.setMatrix(sc, 2.0, 0, 0, 2.0);
    });
    surface->showAt(100, 100);

    injectTap(101, 101);

    EXPECT_NE(surface->consumeEvent(), nullptr);
    EXPECT_NE(surface->consumeEvent(), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    surface->expectKey(AKEYCODE_V);
}

TEST_F(InputSurfacesTest, strict_unobscured_input_obscured_window) {
    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->mInputInfo.ownerUid = 11111;
    surface->doTransaction(
            [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); });
    surface->showAt(100, 100);
    std::unique_ptr<InputSurface> obscuringSurface = makeSurface(100, 100);
    obscuringSurface->mInputInfo.flags = WindowInfo::Flag::NOT_TOUCHABLE;
    obscuringSurface->mInputInfo.ownerUid = 22222;
    obscuringSurface->showAt(100, 100);
    injectTap(101, 101);
    EXPECT_EQ(surface->consumeEvent(100), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    EXPECT_EQ(surface->consumeEvent(100), nullptr);
}

TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) {
    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->mInputInfo.ownerUid = 11111;
    surface->doTransaction(
            [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); });
    surface->showAt(100, 100);
    std::unique_ptr<InputSurface> obscuringSurface = makeSurface(100, 100);
    obscuringSurface->mInputInfo.flags = WindowInfo::Flag::NOT_TOUCHABLE;
    obscuringSurface->mInputInfo.ownerUid = 22222;
    obscuringSurface->showAt(190, 190);

    injectTap(101, 101);

    EXPECT_EQ(surface->consumeEvent(100), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    EXPECT_EQ(surface->consumeEvent(100), nullptr);
}

TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) {
    std::unique_ptr<InputSurface> parentSurface = makeSurface(300, 300);
    parentSurface->showAt(0, 0, Rect(0, 0, 300, 300));

    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->showAt(100, 100);
    surface->doTransaction([&](auto &t, auto &sc) {
        t.setDropInputMode(sc, gui::DropInputMode::OBSCURED);
        t.reparent(sc, parentSurface->mSurfaceControl);
        t.setAlpha(parentSurface->mSurfaceControl, 0.9f);
    });

    injectTap(101, 101);

    EXPECT_EQ(surface->consumeEvent(100), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    EXPECT_EQ(surface->consumeEvent(100), nullptr);
}

TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) {
    std::unique_ptr<InputSurface> parentSurface = makeSurface(300, 300);
    parentSurface->showAt(0, 0, Rect(0, 0, 300, 300));

    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->doTransaction([&](auto &t, auto &sc) {
        t.setDropInputMode(sc, gui::DropInputMode::OBSCURED);
        t.reparent(sc, parentSurface->mSurfaceControl);
        t.setCrop(parentSurface->mSurfaceControl, Rect(10, 10, 100, 100));
    });
    surface->showAt(100, 100);

    injectTap(111, 111);

    EXPECT_EQ(surface->consumeEvent(100), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    EXPECT_EQ(surface->consumeEvent(100), nullptr);
}

TEST_F(InputSurfacesTest, drop_input_policy) {
    std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
    surface->doTransaction(
            [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::ALL); });
    surface->showAt(100, 100);

    injectTap(101, 101);

    EXPECT_EQ(surface->consumeEvent(100), nullptr);

    surface->requestFocus();
    surface->assertFocusChange(true);
    injectKey(AKEYCODE_V);
    EXPECT_EQ(surface->consumeEvent(100), nullptr);
}
} // namespace android::test
Loading