Inform framework of lockout right when the failed attempts reaches threshold

Bug: b/277780293
Test: atest FakeLockoutTrackerTest
Change-Id: Iefe88f3ab492773844b18c525ddbf37218227256
This commit is contained in:
Jeff Pu
2023-06-28 15:21:21 +00:00
parent fd1e1e58fc
commit 437516ea3a
5 changed files with 26 additions and 17 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;
};

View File

@@ -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(),

View File

@@ -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);