blob: bf92719471e0988e8fe790a62c6744cb965824c8 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Set up ADB auth with ARC.
A test ADB key is pre-installed in ARC on CrOS test image (go/tast-adb-key).
This script installs the private ADB key (paired with the pre-installed key)
to local ADB server.
"""
import os
from pathlib import Path
import subprocess
import sys
THIS_FILE = Path(__file__).resolve()
SOURCE_ROOT = THIS_FILE.parents[2]
TRADEFED_PATH = SOURCE_ROOT / "src/third_party/autotest/files/server/cros/tradefed"
def main(argv):
# We import tradefed_constants.py and use private ADB key in it.
sys.path.append(str(TRADEFED_PATH))
import tradefed_constants # pylint: disable=import-error
print("INFO: Installing private ADB key to ~/.android/arc_adbkey")
android_path = Path("~/.android").expanduser()
android_path.mkdir(exist_ok=True)
adbkey_path = android_path / "arc_adbkey"
adbkey_path.write_text(tradefed_constants.PRIVATE_KEY, encoding="utf-8")
print("INFO: Restarting ADB server with the new key path.")
os.environ["ADB_VENDOR_KEYS"] = str(adbkey_path)
subprocess.call(["adb", "kill-server"])
subprocess.call(["adb", "start-server"])
print("INFO: ADB set up complete. You are ready to run adb connect.")
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))