1 /* 2 * Copyright 2019, 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 <stdint.h> 20 #include <sys/types.h> 21 22 #include <memory> 23 #include <vector> 24 25 #include <layouts/layout.h> 26 27 #include <teeui/error.h> 28 #include <teeui/utils.h> 29 30 #include <lib/secure_fb/secure_fb.h> 31 32 #include <secure_input/secure_input_proto.h> 33 34 #include <device_layout.h> 35 36 class TrustyConfirmationUI { 37 public: 38 TrustyConfirmationUI() = default; 39 40 /** 41 * Renders and displays the dialog. 42 * prompt: The message that is to be confirmed. 43 * lang_id: The locale to use. Selects the language used for the button 44 * texts and instructions. inverted: If set, the inverted color scheme is 45 * used. magnified: If set, the magnified font profile is used. 46 * 47 * Returns ResponseCode::OK if the UI was successfully start. 48 * Returns ResponseCode::UIError if the secure display could not be enabled 49 * or if the framebuffer topology is off. Returns 50 * ResponseCode::UIErrorMissingGlyph if the font rendering failed. Returns 51 * ResponseCode::UIErrorMessageTooLong if the any of the strings could not 52 * be fully rendered on the screen. 53 */ 54 teeui::ResponseCode start(const char* promt, 55 const char* lang_id, 56 bool inverted, 57 bool magnified); 58 /** 59 * Toggles the color profile of the buttons/button labels indicating to the 60 * user that input enabled (enable == true) or disabled (enabled == false). 61 * 62 * Returns ResponseCode::OK if the UI was successfully updated. 63 * Returns ResponseCode::UIError if the secure framebuffer could not be 64 * flipped. Other errors same as start() above. 65 */ 66 teeui::ResponseCode showInstructions(bool enable); 67 68 /** 69 * Stops the secure display and frees up all of the related resources. 70 */ 71 void stop(); 72 73 // TrustyConfirmationUI not copyable 74 TrustyConfirmationUI& operator=(const TrustyConfirmationUI&) = delete; 75 76 TrustyConfirmationUI& operator=(TrustyConfirmationUI&& other) { 77 fb_info_ = other.fb_info_; 78 return *this; 79 } 80 81 private: 82 teeui::Error updateTranslations(uint32_t idx); 83 teeui::ResponseCode renderAndSwap(uint32_t idx); 84 85 std::vector<secure_fb_info> fb_info_; 86 std::vector<secure_fb_handle_t> secure_fb_handle_; 87 88 bool inverted_; 89 bool enabled_; 90 91 std::vector<std::unique_ptr<teeui::layouts::ILayout>> layout_; 92 }; 93