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

Commit 437516ea authored by Jeff Pu's avatar Jeff Pu
Browse files

Inform framework of lockout right when the failed attempts reaches threshold

Bug: b/277780293
Test: atest FakeLockoutTrackerTest
Change-Id: Iefe88f3ab492773844b18c525ddbf37218227256
parent fd1e1e58
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -195,16 +195,7 @@ void FakeFingerprintEngine::onAuthenticateFingerDown(ISessionCallback* cb,
    }

    // got lockout?
    FakeLockoutTracker::LockoutMode lockoutMode = mLockoutTracker.getMode();
    if (lockoutMode == FakeLockoutTracker::LockoutMode::kPermanent) {
        LOG(ERROR) << "Fail: lockout permanent";
        cb->onLockoutPermanent();
        return;
    } else if (lockoutMode == FakeLockoutTracker::LockoutMode::kTimed) {
        int64_t timeLeft = mLockoutTracker.getLockoutTimeLeft();
        LOG(ERROR) << "Fail: lockout timed " << timeLeft;
        cb->onLockoutTimed(timeLeft);
    }
    if (checkSensorLockout(cb)) return;

    int i = 0;
    do {
@@ -256,6 +247,7 @@ void FakeFingerprintEngine::onAuthenticateFingerDown(ISessionCallback* cb,
        LOG(ERROR) << "Fail: fingerprint not enrolled";
        cb->onAuthenticationFailed();
        mLockoutTracker.addFailedAttempt();
        checkSensorLockout(cb);
    }
}

@@ -563,4 +555,18 @@ int32_t FakeFingerprintEngine::getRandomInRange(int32_t bound1, int32_t bound2)
    return dist(mRandom);
}

bool FakeFingerprintEngine::checkSensorLockout(ISessionCallback* cb) {
    FakeLockoutTracker::LockoutMode lockoutMode = mLockoutTracker.getMode();
    if (lockoutMode == FakeLockoutTracker::LockoutMode::kPermanent) {
        LOG(ERROR) << "Fail: lockout permanent";
        cb->onLockoutPermanent();
        return true;
    } else if (lockoutMode == FakeLockoutTracker::LockoutMode::kTimed) {
        int64_t timeLeft = mLockoutTracker.getLockoutTimeLeft();
        LOG(ERROR) << "Fail: lockout timed " << timeLeft;
        cb->onLockoutTimed(timeLeft);
        return true;
    }
    return false;
}
}  // namespace aidl::android::hardware::biometrics::fingerprint
+6 −2
Original line number Diff line number Diff line
@@ -67,9 +67,13 @@ int64_t FakeLockoutTracker::getLockoutTimeLeft() {
    int64_t res = 0;

    if (mLockoutTimedStart > 0) {
        int32_t lockoutTimedDuration =
                FingerprintHalProperties::lockout_timed_duration().value_or(10 * 100);
        auto now = Util::getSystemNanoTime();
        auto left = now - mLockoutTimedStart;
        res = (left > 0) ? (left / 1000000LL) : 0;
        auto elapsed = (now - mLockoutTimedStart) / 1000000LL;
        res = lockoutTimedDuration - elapsed;
        LOG(INFO) << "xxxxxx: elapsed=" << elapsed << " now = " << now
                  << " mLockoutTimedStart=" << mLockoutTimedStart << " res=" << res;
    }

    return res;
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ class FakeFingerprintEngine {
    bool parseEnrollmentCaptureSingle(const std::string& str,
                                      std::vector<std::vector<int32_t>>& res);
    int32_t getRandomInRange(int32_t bound1, int32_t bound2);
    bool checkSensorLockout(ISessionCallback*);

    FakeLockoutTracker mLockoutTracker;
};
+1 −3
Original line number Diff line number Diff line
@@ -375,9 +375,7 @@ TEST_F(FakeFingerprintEngineTest, InteractionDetectAcquired) {
TEST_F(FakeFingerprintEngineTest, EnumerateEnrolled) {
    FingerprintHalProperties::enrollments({2, 4, 8});
    mEngine.enumerateEnrollmentsImpl(mCallback.get());
    ASSERT_EQ(
            4,
            mCallback->mLastEnrollmentEnumerated.size());  // Due to workaround. TODO (b/243129174)
    ASSERT_EQ(3, mCallback->mLastEnrollmentEnumerated.size());
    for (auto id : FingerprintHalProperties::enrollments()) {
        ASSERT_TRUE(std::find(mCallback->mLastEnrollmentEnumerated.begin(),
                              mCallback->mLastEnrollmentEnumerated.end(),
+2 −2
Original line number Diff line number Diff line
@@ -65,11 +65,11 @@ TEST_F(FakeLockoutTrackerTest, addFailedAttemptLockoutTimed) {
    ASSERT_EQ(mLockoutTracker.getMode(), FakeLockoutTracker::LockoutMode::kTimed);
    // time left
    int N = 5;
    int64_t prevTimeLeft = INT_MIN;
    int64_t prevTimeLeft = INT_MAX;
    for (int i = 0; i < N; i++) {
        SLEEP_MS(LOCKOUT_TIMED_DURATION / N + 1);
        int64_t currTimeLeft = mLockoutTracker.getLockoutTimeLeft();
        ASSERT_TRUE(currTimeLeft > prevTimeLeft);
        ASSERT_TRUE(currTimeLeft < prevTimeLeft);
        prevTimeLeft = currTimeLeft;
    }
    ASSERT_EQ(mLockoutTracker.getMode(), FakeLockoutTracker::LockoutMode::kNone);