blob: 6e85704b61c7c80e0464694579fb764690b5d152 [file] [log] [blame]
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -08001/*
2 * Copyright 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#ifndef ANDROID_HARDWARE_CONFIRMATIONUI_V1_0_TRUSTY_CONFIRMATIONUI_H
18#define ANDROID_HARDWARE_CONFIRMATIONUI_V1_0_TRUSTY_CONFIRMATIONUI_H
19
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000020#include <aidl/android/hardware/confirmationui/BnConfirmationUI.h>
21#include <aidl/android/hardware/confirmationui/IConfirmationResultCallback.h>
22#include <aidl/android/hardware/confirmationui/UIOption.h>
23#include <aidl/android/hardware/security/keymint/HardwareAuthToken.h>
24#include <android/binder_manager.h>
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080025
26#include <atomic>
27#include <condition_variable>
28#include <memory>
29#include <mutex>
30#include <teeui/generic_messages.h>
31#include <thread>
32
33#include "TrustyApp.h"
34
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000035namespace aidl::android::hardware::confirmationui {
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080036
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000037using std::shared_ptr;
38using std::string;
39using std::vector;
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080040
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000041using ::aidl::android::hardware::security::keymint::HardwareAuthToken;
Tri Voabd86f82021-02-19 22:09:22 -080042using ::android::trusty::confirmationui::TrustyApp;
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080043
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000044class TrustyConfirmationUI : public BnConfirmationUI {
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080045 public:
46 TrustyConfirmationUI();
47 virtual ~TrustyConfirmationUI();
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000048 // Methods from ::aidl::android::hardware::confirmationui::IConfirmationUI
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080049 // follow.
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000050 ::ndk::ScopedAStatus
51 promptUserConfirmation(const shared_ptr<IConfirmationResultCallback>& resultCB,
52 const vector<uint8_t>& promptText, const vector<uint8_t>& extraData,
53 const string& locale, const vector<UIOption>& uiOptions) override;
54 ::ndk::ScopedAStatus
55 deliverSecureInputEvent(const HardwareAuthToken& secureInputToken) override;
56
57 ::ndk::ScopedAStatus abort() override;
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080058
59 private:
60 std::weak_ptr<TrustyApp> app_;
61 std::thread callback_thread_;
62
63 enum class ListenerState : uint32_t {
64 None,
65 Starting,
66 SetupDone,
67 Interactive,
68 Terminating,
69 };
70
71 /*
72 * listener_state is protected by listener_state_lock. It makes transitions between phases
73 * of the confirmation operation atomic.
74 * (See TrustyConfirmationUI.cpp#promptUserConfirmation_ for details about operation phases)
75 */
76 ListenerState listener_state_;
77 /*
78 * abort_called_ is also protected by listener_state_lock_ and indicates that the HAL user
79 * called abort.
80 */
81 bool abort_called_;
82 std::mutex listener_state_lock_;
83 std::condition_variable listener_state_condv_;
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000084 int prompt_result_;
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080085 bool secureInputDelivered_;
86
87 std::tuple<teeui::ResponseCode, teeui::MsgVector<uint8_t>, teeui::MsgVector<uint8_t>>
88 promptUserConfirmation_(const teeui::MsgString& promptText,
89 const teeui::MsgVector<uint8_t>& extraData,
90 const teeui::MsgString& locale,
91 const teeui::MsgVector<teeui::UIOption>& uiOptions);
92};
93
Rajesh Nyamagoud9f22d4f2022-09-22 20:25:52 +000094} // namespace aidl::android::hardware::confirmationui
Janis Danisevskis8fe0cfb2020-01-13 14:24:32 -080095
96#endif // ANDROID_HARDWARE_CONFIRMATIONUI_V1_0_TRUSTY_CONFIRMATIONUI_H