Android-cuttlefish cvd tool
session.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 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
21#include <atomic>
22#include <chrono>
23#include <memory>
24#include <string>
25#include <vector>
26
28
34
35namespace cuttlefish {
36namespace confui {
37
45class Session {
46 public:
47 Session(const std::string& session_name, uint32_t display_num,
48 ConfUiRenderer& host_renderer, HostModeCtrl& host_mode_ctrl,
49 const std::string& locale = "en");
50
51 std::string GetId() { return session_id_; }
52
54
55 MainLoopState Transition(SharedFD& hal_cli, FsmInput fsm_input,
56 const ConfUiMessage& conf_ui_message);
57
61 bool Suspend(SharedFD hal_cli);
62
66 bool Restore(SharedFD hal_cli);
67
68 // abort session
69 void Abort();
70
71 // client on the host wants to abort
72 // should let the guest know it
73 void UserAbort(SharedFD hal_cli);
74
75 bool IsSuspended() const;
76 void CleanUp();
77
78 bool IsConfirm(const int x, const int y) {
79 return renderer_.IsInConfirm(x, y);
80 }
81
82 bool IsCancel(const int x, const int y) { return renderer_.IsInCancel(x, y); }
83
84 // tell if grace period has passed
85 bool IsReadyForUserInput() const;
86
87 private:
88 bool IsUserInput(const FsmInput fsm_input) {
89 return fsm_input == FsmInput::kUserEvent;
90 }
91
96 bool RenderDialog();
97
98 // transition actions on each state per input
99 // the new state will be save to the state_ at the end of each call
100 //
101 // when false is returned, the FSM must terminate
102 // and, no need to let the guest know
103 bool HandleInit(SharedFD hal_cli, FsmInput fsm_input,
104 const ConfUiMessage& conf_ui_message);
105
106 bool HandleWaitStop(SharedFD hal_cli, FsmInput fsm_input);
107
108 bool HandleInSession(SharedFD hal_cli, FsmInput fsm_input,
109 const ConfUiMessage& conf_ui_msg);
110
111 // report with an error ack to HAL, and reset the FSM
112 bool ReportErrorToHal(SharedFD hal_cli, const std::string& msg);
113
114 void ScheduleToTerminate();
115
116 const std::string session_id_;
117 const uint32_t display_num_;
120
121 // only context to save
122 std::string prompt_text_;
123 std::string locale_;
124 std::vector<teeui::UIOption> ui_options_;
125 std::vector<uint8_t> extra_data_;
126 // the second argument for resultCB of promptUserConfirmation
127 std::vector<uint8_t> signed_confirmation_;
128 std::vector<uint8_t> message_;
129
130 std::unique_ptr<Cbor> cbor_;
131
132 // effectively, this variables are shared with webRTC thread
133 // the input demuxer will check the confirmation UI mode based on this
134 std::atomic<MainLoopState> state_;
135 MainLoopState saved_state_; // for restore/suspend
136 using Clock = std::chrono::steady_clock;
137 using TimePoint = std::chrono::time_point<Clock>;
138 std::unique_ptr<TimePoint> start_time_;
139};
140} // end of namespace confui
141} // end of namespace cuttlefish
Definition: host_mode_ctrl.h:39
Definition: shared_fd.h:124
Definition: protocol_types.h:75
Definition: host_renderer.h:64
bool IsInCancel(uint32_t x, uint32_t y)
Definition: host_renderer.cc:438
bool IsInConfirm(uint32_t x, uint32_t y)
Definition: host_renderer.cc:432
Definition: session.h:45
std::string GetId()
Definition: session.h:51
bool IsUserInput(const FsmInput fsm_input)
Definition: session.h:88
std::chrono::time_point< Clock > TimePoint
Definition: session.h:137
void Abort()
Definition: session.cc:131
bool IsReadyForUserInput() const
Definition: session.cc:57
std::string prompt_text_
Definition: session.h:122
bool Suspend(SharedFD hal_cli)
MainLoopState GetState()
Definition: session.h:53
std::vector< uint8_t > extra_data_
Definition: session.h:125
std::vector< uint8_t > message_
Definition: session.h:128
bool IsCancel(const int x, const int y)
Definition: session.h:82
bool RenderDialog()
Definition: session.cc:65
void ScheduleToTerminate()
Definition: session.cc:117
std::vector< teeui::UIOption > ui_options_
Definition: session.h:124
bool HandleInit(SharedFD hal_cli, FsmInput fsm_input, const ConfUiMessage &conf_ui_message)
Definition: session.cc:143
void UserAbort(SharedFD hal_cli)
Definition: session.cc:136
std::unique_ptr< TimePoint > start_time_
Definition: session.h:138
std::vector< uint8_t > signed_confirmation_
Definition: session.h:127
std::unique_ptr< Cbor > cbor_
Definition: session.h:130
HostModeCtrl & host_mode_ctrl_
Definition: session.h:119
const std::string session_id_
Definition: session.h:116
bool HandleWaitStop(SharedFD hal_cli, FsmInput fsm_input)
Definition: session.cc:259
const uint32_t display_num_
Definition: session.h:117
Session(const std::string &session_name, uint32_t display_num, ConfUiRenderer &host_renderer, HostModeCtrl &host_mode_ctrl, const std::string &locale="en")
Definition: session.cc:34
ConfUiRenderer & renderer_
Definition: session.h:118
void CleanUp()
Definition: session.cc:108
std::atomic< MainLoopState > state_
Definition: session.h:134
MainLoopState saved_state_
Definition: session.h:135
std::string locale_
Definition: session.h:123
bool IsConfirm(const int x, const int y)
Definition: session.h:78
bool ReportErrorToHal(SharedFD hal_cli, const std::string &msg)
Definition: session.cc:122
bool Restore(SharedFD hal_cli)
MainLoopState Transition(SharedFD &hal_cli, FsmInput fsm_input, const ConfUiMessage &conf_ui_message)
Definition: session.cc:75
std::chrono::steady_clock Clock
Definition: session.h:136
bool HandleInSession(SharedFD hal_cli, FsmInput fsm_input, const ConfUiMessage &conf_ui_msg)
Definition: session.cc:208
FsmInput
Definition: server_common.h:41
MainLoopState
Definition: server_common.h:29
Definition: alloc_driver.h:20