• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
20 
21 #include "common/libs/confui/confui.h"
22 #include "host/libs/confui/host_mode_ctrl.h"
23 #include "host/libs/confui/host_renderer.h"
24 #include "host/libs/confui/server_common.h"
25 #include "host/libs/confui/session.h"
26 #include "host/libs/screen_connector/screen_connector.h"
27 
28 namespace cuttlefish {
29 namespace confui {
30 
31 /**
32  * Confirmation UI Session
33  *
34  * E.g. Two guest apps could drive confirmation UI respectively,
35  * and both are alive at the moment. Each needs one session
36  *
37  */
38 class Session {
39  public:
40   Session(const std::string& session_id, const std::uint32_t display_num,
41           ConfUiRenderer& host_renderer, HostModeCtrl& host_mode_ctrl,
42           ScreenConnectorFrameRenderer& screen_connector,
43           const std::string& locale = "en");
44 
45   bool IsConfUiActive() const;
46 
GetId()47   std::string GetId() { return session_id_; }
48 
GetState()49   MainLoopState GetState() { return state_; }
50 
51   MainLoopState Transition(const bool is_user_input, SharedFD& hal_cli,
52                            const FsmInput fsm_input,
53                            const std::string& additional_info);
54 
55   /**
56    * this make a transition from kWaitStop or kInSession to kSuspend
57    */
58   bool Suspend(SharedFD hal_cli);
59 
60   /**
61    * this make a transition from kRestore to the saved state
62    */
63   bool Restore(SharedFD hal_cli);
64 
65   // abort session
66   bool Abort(SharedFD hal_cli);
67 
68   bool IsSuspended() const;
69   void CleanUp();
70 
71  private:
72   /** create a frame, and render it on the vnc/webRTC client
73    *
74    * note that this does not check host_ctrl_mode_
75    */
76   bool RenderDialog(const std::string& msg, const std::string& locale);
77 
78   // transition actions on each state per input
79   // the new state will be save to the state_ at the end of each call
80   void HandleInit(const bool is_user_input, SharedFD hal_cli,
81                   const FsmInput fsm_input, const std::string& additional_info);
82 
83   void HandleWaitStop(const bool is_user_input, SharedFD hal_cli,
84                       const FsmInput fsm_input);
85 
86   void HandleInSession(const bool is_user_input, SharedFD hal_cli,
87                        const FsmInput fsm_input);
88 
89   bool Kill(SharedFD hal_cli, const std::string& response_msg);
90 
91   // report with an error ack to HAL, and reset the FSM
92   void ReportErrorToHal(SharedFD hal_cli, const std::string& msg);
93 
94   const std::string session_id_;
95   const std::uint32_t display_num_;
96   // host renderer is shared across sessions
97   ConfUiRenderer& renderer_;
98   HostModeCtrl& host_mode_ctrl_;
99   ScreenConnectorFrameRenderer& screen_connector_;
100 
101   // only context to save
102   std::string prompt_;
103   std::string locale_;
104 
105   // effectively, this variables are shared with vnc, webRTC thread
106   // the input demuxer will check the confirmation UI mode based on this
107   std::atomic<MainLoopState> state_;
108   MainLoopState saved_state_;  // for restore/suspend
109 };
110 }  // end of namespace confui
111 }  // end of namespace cuttlefish
112