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 | |
| 20 | #include <android/hardware/confirmationui/1.0/IConfirmationUI.h> |
| 21 | #include <android/hardware/keymaster/4.0/types.h> |
| 22 | #include <hidl/Status.h> |
| 23 | |
| 24 | #include <atomic> |
| 25 | #include <condition_variable> |
| 26 | #include <memory> |
| 27 | #include <mutex> |
| 28 | #include <teeui/generic_messages.h> |
| 29 | #include <thread> |
| 30 | |
| 31 | #include "TrustyApp.h" |
| 32 | |
| 33 | namespace android { |
| 34 | namespace hardware { |
| 35 | namespace confirmationui { |
| 36 | namespace V1_0 { |
| 37 | namespace implementation { |
| 38 | |
| 39 | using ::android::sp; |
| 40 | using ::android::hardware::hidl_array; |
| 41 | using ::android::hardware::hidl_string; |
| 42 | using ::android::hardware::hidl_vec; |
| 43 | using ::android::hardware::Return; |
| 44 | using ::android::hardware::Void; |
| 45 | |
| 46 | using ::android::trusty::TrustyApp; |
| 47 | |
| 48 | class TrustyConfirmationUI : public IConfirmationUI { |
| 49 | public: |
| 50 | TrustyConfirmationUI(); |
| 51 | virtual ~TrustyConfirmationUI(); |
| 52 | // Methods from ::android::hardware::confirmationui::V1_0::IConfirmationUI |
| 53 | // follow. |
| 54 | Return<ResponseCode> promptUserConfirmation(const sp<IConfirmationResultCallback>& resultCB, |
| 55 | const hidl_string& promptText, |
| 56 | const hidl_vec<uint8_t>& extraData, |
| 57 | const hidl_string& locale, |
| 58 | const hidl_vec<UIOption>& uiOptions) override; |
| 59 | Return<ResponseCode> deliverSecureInputEvent( |
| 60 | const ::android::hardware::keymaster::V4_0::HardwareAuthToken& secureInputToken) override; |
| 61 | Return<void> abort() override; |
| 62 | |
| 63 | private: |
| 64 | std::weak_ptr<TrustyApp> app_; |
| 65 | std::thread callback_thread_; |
| 66 | |
| 67 | enum class ListenerState : uint32_t { |
| 68 | None, |
| 69 | Starting, |
| 70 | SetupDone, |
| 71 | Interactive, |
| 72 | Terminating, |
| 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * listener_state is protected by listener_state_lock. It makes transitions between phases |
| 77 | * of the confirmation operation atomic. |
| 78 | * (See TrustyConfirmationUI.cpp#promptUserConfirmation_ for details about operation phases) |
| 79 | */ |
| 80 | ListenerState listener_state_; |
| 81 | /* |
| 82 | * abort_called_ is also protected by listener_state_lock_ and indicates that the HAL user |
| 83 | * called abort. |
| 84 | */ |
| 85 | bool abort_called_; |
| 86 | std::mutex listener_state_lock_; |
| 87 | std::condition_variable listener_state_condv_; |
| 88 | ResponseCode prompt_result_; |
| 89 | bool secureInputDelivered_; |
| 90 | |
| 91 | std::tuple<teeui::ResponseCode, teeui::MsgVector<uint8_t>, teeui::MsgVector<uint8_t>> |
| 92 | promptUserConfirmation_(const teeui::MsgString& promptText, |
| 93 | const teeui::MsgVector<uint8_t>& extraData, |
| 94 | const teeui::MsgString& locale, |
| 95 | const teeui::MsgVector<teeui::UIOption>& uiOptions); |
| 96 | }; |
| 97 | |
| 98 | } // namespace implementation |
| 99 | } // namespace V1_0 |
| 100 | } // namespace confirmationui |
| 101 | } // namespace hardware |
| 102 | } // namespace android |
| 103 | |
| 104 | #endif // ANDROID_HARDWARE_CONFIRMATIONUI_V1_0_TRUSTY_CONFIRMATIONUI_H |