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

Commit a63ee07a authored by Jeff Pu's avatar Jeff Pu Committed by Automerger Merge Worker
Browse files

Merge "Wait for HAL service death signal before trying to connect it again"...

Merge "Wait for HAL service death signal before trying to connect it again" into main am: 511e2f67

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/3478782



Change-Id: I157efe5d432b35a93de410ccab31f1b0135aac5e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5bf43c06 511e2f67
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -138,6 +138,11 @@ class SessionCallback : public BnSessionCallback {
};

class Fingerprint : public testing::TestWithParam<std::string> {
    static void HalServiceDied(void* cookie) {
        auto halDeathPromise = static_cast<std::promise<void>*>(cookie);
        halDeathPromise->set_value();
    }

  protected:
    void SetUp() override {
        // Prepare the callback.
@@ -157,8 +162,24 @@ class Fingerprint : public testing::TestWithParam<std::string> {
            ASSERT_NE(binder, nullptr);
            mHal = IFingerprint::fromBinder(ndk::SpAIBinder(binder));

            // Create HAL service death notifier
            auto halDeathPromise = std::make_shared<std::promise<void>>();
            mHalDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(
                    AIBinder_DeathRecipient_new(&HalServiceDied));
            ASSERT_EQ(STATUS_OK, AIBinder_linkToDeath(binder, mHalDeathRecipient.get(),
                                                      static_cast<void*>(halDeathPromise.get())));

            // Create a session.
            isOk = mHal->createSession(kSensorId, kUserId, mCb, &mSession).isOk();

            if (!isOk) {
                // Failed to create session on first attempt, it is likely that the HAL service
                //   is dying or dead. Wait for its death notification signal before next try
                auto future = halDeathPromise->get_future();
                auto status = future.wait_for(std::chrono::milliseconds(500));
                EXPECT_EQ(status, std::future_status::ready);
            }

            ++retries;
        } while (!isOk && retries < 2);

@@ -177,6 +198,7 @@ class Fingerprint : public testing::TestWithParam<std::string> {
    std::shared_ptr<IFingerprint> mHal;
    std::shared_ptr<SessionCallback> mCb;
    std::shared_ptr<ISession> mSession;
    ::ndk::ScopedAIBinder_DeathRecipient mHalDeathRecipient;
};

TEST_P(Fingerprint, GetSensorPropsWorksTest) {