Add command line interface for adb_utils.py
Change-Id: I3f18343e1495cff43e9a715e5d416f3021a3382b
diff --git a/tools/startup/adb_utils.py b/tools/startup/adb_utils.py
old mode 100644
new mode 100755
index b5e2af2..56ad643
--- a/tools/startup/adb_utils.py
+++ b/tools/startup/adb_utils.py
@@ -3,13 +3,15 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
-from enum import Enum
+import argparse
import os
import subprocess
import sys
import threading
import time
+from enum import Enum
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
@@ -351,3 +353,37 @@
issue_key_event('KEYCODE_MENU', device_id)
screen_state = get_screen_state(device_id)
assert screen_state.is_on_and_unlocked(), 'was %s' % screen_state
+
+def parse_options(argv):
+ result = argparse.ArgumentParser(description='Run adb utils.')
+ result.add_argument('--device-id',
+ help='Device id (e.g., emulator-5554).')
+ result.add_argument('--device-pin',
+ help='Device pin code (e.g., 1234)')
+ result.add_argument('--ensure-screen-off',
+ help='Ensure screen off',
+ action='store_true',
+ default=False)
+ result.add_argument('--get-screen-state',
+ help='Get screen state',
+ action='store_true',
+ default=False)
+ result.add_argument('--unlock',
+ help='Unlock device',
+ action='store_true',
+ default=False)
+ options, args = result.parse_known_args(argv)
+ return options, args
+
+def main(argv):
+ (options, args) = parse_options(argv)
+ if options.ensure_screen_off:
+ ensure_screen_off(options.device_id)
+ elif options.get_screen_state:
+ print(get_screen_state(options.device_id))
+ elif options.unlock:
+ unlock(options.device_id, options.device_pin)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))