/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include "common/libs/fs/shared_fd.h" #include "common/libs/utils/json.h" #include "common/libs/utils/result.h" #include "host/commands/run_cvd/launch/webrtc_recorder.h" #include "host/commands/run_cvd/server_loop.h" #include "host/libs/command_util/runner/defs.h" #include "host/libs/command_util/util.h" #include "host/libs/config/command_source.h" #include "host/libs/config/cuttlefish_config.h" #include "host/libs/config/feature.h" #include "host/libs/config/inject.h" #include "host/libs/process_monitor/process_monitor.h" namespace cuttlefish { namespace run_cvd_impl { class ServerLoopImpl : public ServerLoop, public SetupFeature, public LateInjected { public: INJECT(ServerLoopImpl(const CuttlefishConfig& config, const CuttlefishConfig::InstanceSpecific& instance, AutoSnapshotControlFiles::Type& snapshot_control_files, WebRtcRecorder& webrtc_recorder)); Result LateInject(fruit::Injector<>& injector) override; // ServerLoop Result Run() override; // SetupFeature std::string Name() const override { return "ServerLoop"; } enum class DeviceStatus : int { kUnknown = 0, kActive = 1, kSuspended = 2, }; private: bool Enabled() const override { return true; } std::unordered_set Dependencies() const override { return {&snapshot_control_files_}; } Result ResultSetup() override; Result HandleExtended(const LauncherActionInfo& action_info, ProcessMonitor& process_monitor); Result HandleSuspend(ProcessMonitor& process_monitor); Result HandleResume(ProcessMonitor& process_monitor); Result HandleSnapshotTake(const run_cvd::SnapshotTake& snapshot_take); Result HandleStartScreenRecording(); Result HandleStopScreenRecording(); void HandleActionWithNoData(const LauncherAction action, const SharedFD& client, ProcessMonitor& process_monitor); void DeleteFifos(); bool PowerwashFiles(); void RestartRunCvd(int notification_fd); static bool CreateQcowOverlay(const std::string& crosvm_path, const std::string& backing_file, const std::string& output_overlay_path); Result SuspendGuest(); Result ResumeGuest(); static std::unordered_map InitializeVmToControlSockPath(const CuttlefishConfig::InstanceSpecific&); Result VmControlSocket() const; Result TakeGuestSnapshot(VmmMode, const std::string&); Result TakeCrosvmGuestSnapshot(const Json::Value&); const CuttlefishConfig& config_; const CuttlefishConfig::InstanceSpecific& instance_; /* * This is needed to get the run_cvd side socket pair connected to * secure_env. The socket pairs are used to send suspend/resume to * secure_env, and get the responses. */ AutoSnapshotControlFiles::Type& snapshot_control_files_; WebRtcRecorder& webrtc_recorder_; std::vector command_sources_; SharedFD server_; // mapping from the name of vm_manager to control_sock path std::unordered_map vm_name_to_control_sock_; std::atomic device_status_; }; } // namespace run_cvd_impl } // namespace cuttlefish