Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 1 | /* |
| 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 Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 20 | #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 Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 25 | |
| 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 Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 35 | namespace aidl::android::hardware::confirmationui { |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 36 | |
Rajesh Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 37 | using std::shared_ptr; |
| 38 | using std::string; |
| 39 | using std::vector; |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 40 | |
Rajesh Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 41 | using ::aidl::android::hardware::security::keymint::HardwareAuthToken; |
Tri Vo | abd86f8 | 2021-02-19 22:09:22 -0800 | [diff] [blame] | 42 | using ::android::trusty::confirmationui::TrustyApp; |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 43 | |
Rajesh Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 44 | class TrustyConfirmationUI : public BnConfirmationUI { |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 45 | public: |
| 46 | TrustyConfirmationUI(); |
| 47 | virtual ~TrustyConfirmationUI(); |
Rajesh Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 48 | // Methods from ::aidl::android::hardware::confirmationui::IConfirmationUI |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 49 | // follow. |
Rajesh Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 50 | ::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 Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 58 | |
| 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 Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 84 | int prompt_result_; |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 85 | 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 Nyamagoud | 9f22d4f | 2022-09-22 20:25:52 +0000 | [diff] [blame^] | 94 | } // namespace aidl::android::hardware::confirmationui |
Janis Danisevskis | 8fe0cfb | 2020-01-13 14:24:32 -0800 | [diff] [blame] | 95 | |
| 96 | #endif // ANDROID_HARDWARE_CONFIRMATIONUI_V1_0_TRUSTY_CONFIRMATIONUI_H |