blob: b92dedaf997328d983018204eead48d14fdc9caa [file] [log] [blame]
David Zeuthenc6eb7cd2017-11-27 11:33:55 -05001/*
2 * Copyright (C) 2017 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#ifndef KEYSTORE_CONFIRMATION_MANAGER_H_
18#define KEYSTORE_CONFIRMATION_MANAGER_H_
19
20#include <android/hardware/confirmationui/1.0/IConfirmationUI.h>
21#include <android/hardware/confirmationui/1.0/types.h>
22#include <binder/Binder.h>
23#include <binder/IBinder.h>
24#include <binder/Status.h>
25#include <keystore/keymaster_types.h>
26#include <map>
27#include <mutex>
28#include <utils/LruCache.h>
29#include <utils/StrongPointer.h>
30#include <vector>
31
32namespace keystore {
33
34using android::binder::Status;
35using android::hardware::confirmationui::V1_0::IConfirmationResultCallback;
36using ConfirmationResponseCode = android::hardware::confirmationui::V1_0::ResponseCode;
37
38class ConfirmationManager;
39
40class ConfirmationManager : public android::hardware::hidl_death_recipient,
41 public IConfirmationResultCallback {
42 public:
43 explicit ConfirmationManager(android::IBinder::DeathRecipient* deathRecipient);
44
45 // Calls into the confirmationui HAL to start a new prompt.
46 //
47 // Returns OperationPending if another application is already
48 // showing a confirmation. Otherwise returns the return code from
49 // the HAL.
50 Status presentConfirmationPrompt(const android::sp<android::IBinder>& listener,
51 const android::String16& promptText,
52 const hidl_vec<uint8_t>& extraData,
53 const android::String16& locale, int uiOptionsAsFlags,
54 int32_t* aidl_return);
55
56 // Calls into the confirmationui HAL to cancel displaying a
57 // prompt.
58 //
59 // Returns OperatingPending if another application is showing a
60 // confirmation. Otherwise returns the return code from the HAL.
61 Status cancelConfirmationPrompt(const android::sp<android::IBinder>& listener,
62 int32_t* aidl_return);
63
David Zeuthen1a492312018-02-26 11:00:30 -050064 // Checks if the confirmationUI HAL is available.
65 Status isConfirmationPromptSupported(bool* aidl_return);
66
David Zeuthenc6eb7cd2017-11-27 11:33:55 -050067 // Gets the latest confirmation token received from the ConfirmationUI HAL.
68 hidl_vec<uint8_t> getLatestConfirmationToken();
69
70 // Called by KeyStoreService when a client binder has died.
71 void binderDied(const android::wp<android::IBinder>& who);
72
73 // hidl_death_recipient overrides:
74 virtual void serviceDied(uint64_t cookie,
75 const android::wp<android::hidl::base::V1_0::IBase>& who) override;
76
77 // IConfirmationResultCallback overrides:
78 android::hardware::Return<void> result(ConfirmationResponseCode responseCode,
79 const hidl_vec<uint8_t>& dataThatWasConfirmed,
80 const hidl_vec<uint8_t>& confirmationToken) override;
81
82 private:
83 friend class ConfirmationResultCallback;
84
85 void finalizeTransaction(ConfirmationResponseCode responseCode,
86 hidl_vec<uint8_t> dataThatWasConfirmed, bool callAbortOnHal);
87
88 // This mutex protects all data below it.
89 std::mutex mMutex;
90
91 // The mCurrentListener and mCurrentConfirmationUI fields are set
92 // if and only if a prompt is currently showing.
93 android::sp<android::IBinder> mCurrentListener;
94 android::sp<android::hardware::confirmationui::V1_0::IConfirmationUI> mCurrentConfirmationUI;
95 android::IBinder::DeathRecipient* mDeathRecipient;
96 hidl_vec<uint8_t> mLatestConfirmationToken;
97};
98
99} // namespace keystore
100
101#endif // KEYSTORE_CONFIRMATION_MANAGER_H_