Merge "Inform framework of lockout right when the failed attempts reaches threshold" into udc-qpr-dev

This commit is contained in:
Jeff Pu
2023-06-29 19:36:40 +00:00
committed by Android (Google) Code Review
5 changed files with 26 additions and 17 deletions

View File

@@ -195,16 +195,7 @@ void FakeFingerprintEngine::onAuthenticateFingerDown(ISessionCallback* cb,
} }
// got lockout? // got lockout?
FakeLockoutTracker::LockoutMode lockoutMode = mLockoutTracker.getMode(); if (checkSensorLockout(cb)) return;
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);
}
int i = 0; int i = 0;
do { do {
@@ -256,6 +247,7 @@ void FakeFingerprintEngine::onAuthenticateFingerDown(ISessionCallback* cb,
LOG(ERROR) << "Fail: fingerprint not enrolled"; LOG(ERROR) << "Fail: fingerprint not enrolled";
cb->onAuthenticationFailed(); cb->onAuthenticationFailed();
mLockoutTracker.addFailedAttempt(); mLockoutTracker.addFailedAttempt();
checkSensorLockout(cb);
} }
} }
@@ -563,4 +555,18 @@ int32_t FakeFingerprintEngine::getRandomInRange(int32_t bound1, int32_t bound2)
return dist(mRandom); 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 } // namespace aidl::android::hardware::biometrics::fingerprint

View File

@@ -67,9 +67,13 @@ int64_t FakeLockoutTracker::getLockoutTimeLeft() {
int64_t res = 0; int64_t res = 0;
if (mLockoutTimedStart > 0) { if (mLockoutTimedStart > 0) {
int32_t lockoutTimedDuration =
FingerprintHalProperties::lockout_timed_duration().value_or(10 * 100);
auto now = Util::getSystemNanoTime(); auto now = Util::getSystemNanoTime();
auto left = now - mLockoutTimedStart; auto elapsed = (now - mLockoutTimedStart) / 1000000LL;
res = (left > 0) ? (left / 1000000LL) : 0; res = lockoutTimedDuration - elapsed;
LOG(INFO) << "xxxxxx: elapsed=" << elapsed << " now = " << now
<< " mLockoutTimedStart=" << mLockoutTimedStart << " res=" << res;
} }
return res; return res;

View File

@@ -113,6 +113,7 @@ class FakeFingerprintEngine {
bool parseEnrollmentCaptureSingle(const std::string& str, bool parseEnrollmentCaptureSingle(const std::string& str,
std::vector<std::vector<int32_t>>& res); std::vector<std::vector<int32_t>>& res);
int32_t getRandomInRange(int32_t bound1, int32_t bound2); int32_t getRandomInRange(int32_t bound1, int32_t bound2);
bool checkSensorLockout(ISessionCallback*);
FakeLockoutTracker mLockoutTracker; FakeLockoutTracker mLockoutTracker;
}; };

View File

@@ -375,9 +375,7 @@ TEST_F(FakeFingerprintEngineTest, InteractionDetectAcquired) {
TEST_F(FakeFingerprintEngineTest, EnumerateEnrolled) { TEST_F(FakeFingerprintEngineTest, EnumerateEnrolled) {
FingerprintHalProperties::enrollments({2, 4, 8}); FingerprintHalProperties::enrollments({2, 4, 8});
mEngine.enumerateEnrollmentsImpl(mCallback.get()); mEngine.enumerateEnrollmentsImpl(mCallback.get());
ASSERT_EQ( ASSERT_EQ(3, mCallback->mLastEnrollmentEnumerated.size());
4,
mCallback->mLastEnrollmentEnumerated.size()); // Due to workaround. TODO (b/243129174)
for (auto id : FingerprintHalProperties::enrollments()) { for (auto id : FingerprintHalProperties::enrollments()) {
ASSERT_TRUE(std::find(mCallback->mLastEnrollmentEnumerated.begin(), ASSERT_TRUE(std::find(mCallback->mLastEnrollmentEnumerated.begin(),
mCallback->mLastEnrollmentEnumerated.end(), mCallback->mLastEnrollmentEnumerated.end(),

View File

@@ -65,11 +65,11 @@ TEST_F(FakeLockoutTrackerTest, addFailedAttemptLockoutTimed) {
ASSERT_EQ(mLockoutTracker.getMode(), FakeLockoutTracker::LockoutMode::kTimed); ASSERT_EQ(mLockoutTracker.getMode(), FakeLockoutTracker::LockoutMode::kTimed);
// time left // time left
int N = 5; int N = 5;
int64_t prevTimeLeft = INT_MIN; int64_t prevTimeLeft = INT_MAX;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
SLEEP_MS(LOCKOUT_TIMED_DURATION / N + 1); SLEEP_MS(LOCKOUT_TIMED_DURATION / N + 1);
int64_t currTimeLeft = mLockoutTracker.getLockoutTimeLeft(); int64_t currTimeLeft = mLockoutTracker.getLockoutTimeLeft();
ASSERT_TRUE(currTimeLeft > prevTimeLeft); ASSERT_TRUE(currTimeLeft < prevTimeLeft);
prevTimeLeft = currTimeLeft; prevTimeLeft = currTimeLeft;
} }
ASSERT_EQ(mLockoutTracker.getMode(), FakeLockoutTracker::LockoutMode::kNone); ASSERT_EQ(mLockoutTracker.getMode(), FakeLockoutTracker::LockoutMode::kNone);