• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 <getopt.h>
18 #include <string>
19 
20 #include <android-base/logging.h>
21 
22 #include "ShellDriver.h"
23 
24 using namespace std;
25 
26 static constexpr const char* DEFAULT_SOCKET_PATH =
27     "/data/local/tmp/tmp_socket_shell_driver.tmp";
28 
29 // Dumps usage on stderr.
usage()30 static void usage() {
31   fprintf(
32       stderr,
33       "Usage: vts_shell_driver --server_socket_path=<UNIX_domain_socket_path>\n"
34       "\n"
35       "Android Vts Shell Driver v0.1.  To run shell commands on Android system."
36       "\n"
37       "Options:\n"
38       "--help\n"
39       "    Show this message.\n"
40       "--socket_path=<Unix_socket_path>\n"
41       "    Show this message.\n"
42       "\n"
43       "Recording continues until Ctrl-C is hit or the time limit is reached.\n"
44       "\n");
45 }
46 
47 // Parses command args and kicks things off.
main(int argc,char ** argv)48 int main(int argc, char** argv) {
49   android::base::InitLogging(argv, android::base::StderrLogger);
50 
51   static const struct option longOptions[] = {
52       {"help", no_argument, NULL, 'h'},
53       {"server_socket_path", required_argument, NULL, 's'},
54       {NULL, 0, NULL, 0}};
55 
56   string socket_path = DEFAULT_SOCKET_PATH;
57 
58   while (true) {
59     int optionIndex = 0;
60     int ic = getopt_long(argc, argv, "", longOptions, &optionIndex);
61     if (ic == -1) {
62       break;
63     }
64 
65     switch (ic) {
66       case 'h':
67         usage();
68         return 0;
69       case 's':
70         socket_path = string(optarg);
71         break;
72       default:
73         if (ic != '?') {
74           fprintf(stderr, "getopt_long returned unexpected value 0x%x\n", ic);
75         }
76         return 2;
77     }
78   }
79 
80   android::vts::VtsShellDriver shellDriver(socket_path.c_str());
81   return shellDriver.StartListen();
82 }
83