• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include "host/libs/config/fastboot/fastboot.h"
17 
18 #include <utility>
19 #include <vector>
20 
21 #include "common/libs/utils/result.h"
22 #include "host/commands/kernel_log_monitor/utils.h"
23 #include "host/libs/config/command_source.h"
24 #include "host/libs/config/cuttlefish_config.h"
25 #include "host/libs/config/known_paths.h"
26 
27 namespace cuttlefish {
28 namespace {
29 
30 class FastbootProxy : public CommandSource {
31  public:
INJECT(FastbootProxy (const CuttlefishConfig::InstanceSpecific & instance,const FastbootConfig & fastboot_config))32   INJECT(FastbootProxy(const CuttlefishConfig::InstanceSpecific& instance,
33                        const FastbootConfig& fastboot_config))
34       : instance_(instance),
35         fastboot_config_(fastboot_config) {}
36 
Commands()37   Result<std::vector<MonitorCommand>> Commands() override {
38     const std::string ethernet_host = instance_.ethernet_ipv6() + "%" +
39                                       instance_.ethernet_bridge_name();
40 
41     Command tunnel(SocketVsockProxyBinary());
42     tunnel.AddParameter("--server_type=", "tcp");
43     tunnel.AddParameter("--server_tcp_port=", instance_.fastboot_host_port());
44     tunnel.AddParameter("--client_type=", "tcp");
45     tunnel.AddParameter("--client_tcp_host=", ethernet_host);
46     tunnel.AddParameter("--client_tcp_port=", "5554");
47     tunnel.AddParameter("--label=", "fastboot");
48 
49     std::vector<MonitorCommand> commands;
50     commands.emplace_back(std::move(tunnel));
51     return commands;
52   }
53 
Name() const54   std::string Name() const override { return "FastbootProxy"; }
Enabled() const55   bool Enabled() const override {
56     return instance_.boot_flow() == CuttlefishConfig::InstanceSpecific::BootFlow::Android &&
57            fastboot_config_.ProxyFastboot();
58   }
59 
60  private:
Dependencies() const61   std::unordered_set<SetupFeature*> Dependencies() const override {
62     return {};
63   }
64 
Setup()65   bool Setup() override {
66     return true;
67   }
68 
69   const CuttlefishConfig::InstanceSpecific& instance_;
70   const FastbootConfig& fastboot_config_;
71 };
72 
73 }  // namespace
74 
75 fruit::Component<fruit::Required<const CuttlefishConfig::InstanceSpecific,
76                                  const FastbootConfig>>
LaunchFastbootComponent()77 LaunchFastbootComponent() {
78   return fruit::createComponent()
79       .addMultibinding<CommandSource, FastbootProxy>()
80       .addMultibinding<SetupFeature, FastbootProxy>();
81 }
82 
83 }  // namespace cuttlefish
84