1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "FakeLockoutTracker.h" 18 #include <fingerprint.sysprop.h> 19 #include "util/Util.h" 20 21 using namespace ::android::fingerprint::virt; 22 23 namespace aidl::android::hardware::biometrics::fingerprint { 24 reset()25void FakeLockoutTracker::reset() { 26 mFailedCount = 0; 27 mLockoutTimedStart = 0; 28 mCurrentMode = LockoutMode::kNone; 29 } 30 addFailedAttempt()31void FakeLockoutTracker::addFailedAttempt() { 32 bool enabled = FingerprintHalProperties::lockout_enable().value_or(false); 33 if (enabled) { 34 mFailedCount++; 35 int32_t lockoutTimedThreshold = 36 FingerprintHalProperties::lockout_timed_threshold().value_or(5); 37 int32_t lockoutPermanetThreshold = 38 FingerprintHalProperties::lockout_permanent_threshold().value_or(20); 39 if (mFailedCount >= lockoutPermanetThreshold) { 40 mCurrentMode = LockoutMode::kPermanent; 41 FingerprintHalProperties::lockout(true); 42 } else if (mFailedCount >= lockoutTimedThreshold) { 43 if (mCurrentMode == LockoutMode::kNone) { 44 mCurrentMode = LockoutMode::kTimed; 45 mLockoutTimedStart = Util::getSystemNanoTime(); 46 } 47 } 48 } else { 49 reset(); 50 } 51 } 52 getMode()53FakeLockoutTracker::LockoutMode FakeLockoutTracker::getMode() { 54 if (mCurrentMode == LockoutMode::kTimed) { 55 int32_t lockoutTimedDuration = 56 FingerprintHalProperties::lockout_timed_duration().value_or(10 * 100); 57 if (Util::hasElapsed(mLockoutTimedStart, lockoutTimedDuration)) { 58 mCurrentMode = LockoutMode::kNone; 59 mLockoutTimedStart = 0; 60 } 61 } 62 63 return mCurrentMode; 64 } 65 getLockoutTimeLeft()66int64_t FakeLockoutTracker::getLockoutTimeLeft() { 67 int64_t res = 0; 68 69 if (mLockoutTimedStart > 0) { 70 int32_t lockoutTimedDuration = 71 FingerprintHalProperties::lockout_timed_duration().value_or(10 * 100); 72 auto now = Util::getSystemNanoTime(); 73 auto elapsed = (now - mLockoutTimedStart) / 1000000LL; 74 res = lockoutTimedDuration - elapsed; 75 LOG(INFO) << "xxxxxx: elapsed=" << elapsed << " now = " << now 76 << " mLockoutTimedStart=" << mLockoutTimedStart << " res=" << res; 77 } 78 79 return res; 80 } 81 } // namespace aidl::android::hardware::biometrics::fingerprint 82