blob: adda8310f4384f86048803e1fca53b98d44e6d03 [file] [log] [blame]
Ilya Matyukhina9a3c852020-08-18 03:09:41 -07001/*
2 * Copyright (C) 2020 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#pragma once
18
19#include <aidl/android/hardware/biometrics/fingerprint/BnSession.h>
20#include <aidl/android/hardware/biometrics/fingerprint/ISessionCallback.h>
21
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080022#include "FakeFingerprintEngine.h"
23#include "WorkerThread.h"
24
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070025namespace aidl::android::hardware::biometrics::fingerprint {
26
Kevin Chyne33abd62020-09-18 10:31:50 -070027namespace common = aidl::android::hardware::biometrics::common;
28namespace keymaster = aidl::android::hardware::keymaster;
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070029
30class Session : public BnSession {
31 public:
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080032 Session(int sensorId, int userId, std::shared_ptr<ISessionCallback> cb,
33 FakeFingerprintEngine* engine, WorkerThread* worker);
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070034
Ilya Matyukhin3d54f452020-10-15 17:32:09 -070035 ndk::ScopedAStatus generateChallenge(int32_t cookie, int32_t timeoutSec) override;
36
37 ndk::ScopedAStatus revokeChallenge(int32_t cookie, int64_t challenge) override;
38
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070039 ndk::ScopedAStatus enroll(int32_t cookie, const keymaster::HardwareAuthToken& hat,
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080040 std::shared_ptr<common::ICancellationSignal>* out) override;
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070041
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080042 ndk::ScopedAStatus authenticate(int32_t cookie, int64_t operationId,
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080043 std::shared_ptr<common::ICancellationSignal>* out) override;
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070044
Ilya Matyukhin3d54f452020-10-15 17:32:09 -070045 ndk::ScopedAStatus detectInteraction(
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080046 int32_t cookie, std::shared_ptr<common::ICancellationSignal>* out) override;
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070047
48 ndk::ScopedAStatus enumerateEnrollments(int32_t cookie) override;
49
50 ndk::ScopedAStatus removeEnrollments(int32_t cookie,
51 const std::vector<int32_t>& enrollmentIds) override;
52
53 ndk::ScopedAStatus getAuthenticatorId(int32_t cookie) override;
54
Kevin Chyn4d0df262020-11-16 12:39:44 -080055 ndk::ScopedAStatus invalidateAuthenticatorId(int32_t cookie) override;
Kevin Chyn6e862c32020-09-16 18:27:37 -070056
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070057 ndk::ScopedAStatus resetLockout(int32_t cookie,
58 const keymaster::HardwareAuthToken& hat) override;
59
Ilya Matyukhin71005c52021-02-17 12:44:14 -080060 ndk::ScopedAStatus close(int32_t cookie) override;
61
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070062 ndk::ScopedAStatus onPointerDown(int32_t pointerId, int32_t x, int32_t y, float minor,
63 float major) override;
64
65 ndk::ScopedAStatus onPointerUp(int32_t pointerId) override;
66
67 ndk::ScopedAStatus onUiReady() override;
68
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080069 bool isClosed();
70
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070071 private:
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080072 // Crashes the HAL if it's not currently idling because that would be an invalid state machine
73 // transition. Otherwise, sets the scheduled state to the given state.
74 void scheduleStateOrCrash(SessionState state);
75
76 // Crashes the HAL if the provided state doesn't match the previously scheduled state.
77 // Otherwise, transitions into the provided state, clears the scheduled state, and notifies
78 // the client about the transition by calling ISessionCallback#onStateChanged.
79 void enterStateOrCrash(int cookie, SessionState state);
80
81 // Sets the current state to SessionState::IDLING and notifies the client about the transition
82 // by calling ISessionCallback#onStateChanged.
83 void enterIdling(int cookie);
84
85 int32_t mSensorId;
86 int32_t mUserId;
Ilya Matyukhin124e70a2021-02-12 13:00:15 -080087 std::shared_ptr<ISessionCallback> mCb;
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080088 FakeFingerprintEngine* mEngine;
89 WorkerThread* mWorker;
90 SessionState mScheduledState;
91 SessionState mCurrentState;
Ilya Matyukhina9a3c852020-08-18 03:09:41 -070092};
93
94} // namespace aidl::android::hardware::biometrics::fingerprint