trusty: gatekeeper: Add device option
Add commandline option to specify the trusty device to use.
Bug: 300338484
Test: VtsHalGatekeeperTargetTest
Change-Id: Ib2ef34dfc104c65119a98937280ae9db74417766
diff --git a/trusty/gatekeeper/service.cpp b/trusty/gatekeeper/service.cpp
index d09804f..59366b8 100644
--- a/trusty/gatekeeper/service.cpp
+++ b/trusty/gatekeeper/service.cpp
@@ -18,12 +18,66 @@
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
+#include <getopt.h>
#include "trusty_gatekeeper.h"
+#include "trusty_gatekeeper_ipc.h"
using aidl::android::hardware::gatekeeper::TrustyGateKeeperDevice;
-int main() {
+static const char* _sopts = "hD:";
+static const struct option _lopts[] = {
+ {"help", no_argument, 0, 'h'},
+ {"dev", required_argument, 0, 'D'},
+ {0, 0, 0, 0},
+};
+
+static const char* usage =
+ "Usage: %s [options]\n"
+ "\n"
+ "options:\n"
+ " -h, --help prints this message and exit\n"
+ " -D, --dev name Trusty device name\n"
+ "\n";
+
+static const char* usage_long = "\n";
+
+static void print_usage_and_exit(const char* prog, int code, bool verbose) {
+ fprintf(stderr, usage, prog);
+ if (verbose) {
+ fprintf(stderr, "%s", usage_long);
+ }
+ exit(code);
+}
+
+static void parse_options(int argc, char** argv) {
+ int c;
+ int oidx = 0;
+
+ while (1) {
+ c = getopt_long(argc, argv, _sopts, _lopts, &oidx);
+ if (c == -1) {
+ break; /* done */
+ }
+
+ switch (c) {
+ case 'D':
+ trusty_gatekeeper_set_dev_name(optarg);
+ break;
+
+ case 'h':
+ print_usage_and_exit(argv[0], EXIT_SUCCESS, true);
+ break;
+
+ default:
+ print_usage_and_exit(argv[0], EXIT_FAILURE, false);
+ }
+ }
+}
+
+int main(int argc, char** argv) {
+ parse_options(argc, argv);
+
ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<TrustyGateKeeperDevice> gatekeeper =