1 /*
2  * Copyright 2023 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 <cstdint>
18 #include <cstdlib>
19 #include <iostream>
20 #include <string>
21 
22 #include <android-base/logging.h>
23 #include <gflags/gflags.h>
24 
25 #include "common/libs/utils/result.h"
26 #include "host/libs/metrics/metrics_receiver.h"
27 
28 namespace cuttlefish {
29 namespace {
30 
MetricsLauncherMain()31 Result<void> MetricsLauncherMain() {
32   while (true) {
33     std::cout << "Please choose an action: \n";
34     std::cout << "  start - send start event to cuttlefish metrics client \n";
35     std::cout << "  stop - send stop event to cuttlefish metrics client \n";
36     std::cout << "  boot - send boot event to cuttlefish metrics client\n";
37     std::cout << "  lock - send lock event to cuttlefish metrics client\n";
38     std::cout << "  atest - send launch command to atest metrics client \n";
39     std::cout << "  exit - exit the program \n";
40 
41     std::string command;
42     std::getline(std::cin, command);
43 
44     if (command == "start") {
45       cuttlefish::MetricsReceiver::LogMetricsVMStart();
46     } else if (command == "stop") {
47       cuttlefish::MetricsReceiver::LogMetricsVMStop();
48     } else if (command == "boot") {
49       cuttlefish::MetricsReceiver::LogMetricsDeviceBoot();
50     } else if (command == "lock") {
51       cuttlefish::MetricsReceiver::LogMetricsLockScreen();
52     } else if (command == "exit") {
53       break;
54     } else {
55       LOG(ERROR) << "Unknown command: " << command;
56     }
57   }
58   return {};
59 }
60 
61 }  // namespace
62 }  // namespace cuttlefish
63 
main(int argc,char ** argv)64 int main(int argc, char** argv) {
65   ::android::base::InitLogging(argv, android::base::StderrLogger);
66   google::ParseCommandLineFlags(&argc, &argv, true);
67 
68   cuttlefish::Result<void> result = cuttlefish::MetricsLauncherMain();
69   if (!result.ok()) {
70     LOG(ERROR) << result.error().FormatForEnv();
71     return EXIT_FAILURE;
72   }
73   return EXIT_SUCCESS;
74 }
75