1 /*
2 * Copyright (C) 2024 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 #include "VehicleServer.grpc.pb.h"
18 #include "VehicleServer.pb.h"
19
20 #include <android-base/logging.h>
21 #include <grpc++/grpc++.h>
22 #include "common/libs/utils/flag_parser.h"
23 #include "host/libs/vhal_proxy_server/vhal_proxy_server_eth_addr.h"
24
25 namespace {
26
27 using ::android::hardware::automotive::vehicle::proto::DumpOptions;
28 using ::android::hardware::automotive::vehicle::proto::DumpResult;
29 using ::android::hardware::automotive::vehicle::proto::VehicleServer;
30 using ::cuttlefish::Flag;
31 using ::cuttlefish::FlagAliasMode;
32 using ::cuttlefish::GflagsCompatFlag;
33 using ::cuttlefish::vhal_proxy_server::kDefaultEthPort;
34 using ::cuttlefish::vhal_proxy_server::kEthAddr;
35 using ::grpc::ClientContext;
36 using ::grpc::CreateChannel;
37 using ::grpc::InsecureChannelCredentials;
38 using ::grpc::Status;
39
40 } // namespace
41
42 // A GRPC server for VHAL running on the guest Android.
43 // argv[1]: Config directory path containing property config file (e.g.
44 // DefaultProperties.json).
45 // argv[2]: The vsock port number used by this server.
main(int argc,char * argv[])46 int main(int argc, char* argv[]) {
47 std::vector<std::string> args;
48 for (int i = 1; i < argc; i++) {
49 args.push_back(std::string(argv[i]));
50 }
51
52 int32_t eth_port = kDefaultEthPort;
53 std::vector<Flag> flags{GflagsCompatFlag("port", eth_port)};
54 CHECK(cuttlefish::ConsumeFlags(flags, args).ok()) << "Failed to parse flags";
55
56 DumpOptions dump_options;
57 // The rest of the arguments are commands passed to VHAL.
58 for (const auto& arg : args) {
59 dump_options.add_options(arg);
60 }
61
62 auto eth_addr = fmt::format("{}:{}", kEthAddr, eth_port);
63
64 auto channel = CreateChannel(eth_addr, InsecureChannelCredentials());
65 auto stub = VehicleServer::NewStub(channel);
66 ClientContext context;
67 DumpResult result;
68 auto status = stub->Dump(&context, dump_options, &result);
69 CHECK(status.ok()) << "Failed to call Dump on VHAL proxy server, error: "
70 << status.error_message();
71
72 std::cout << "Debug command finished, result: \n" << result.buffer();
73 return 0;
74 }
75