Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1078)

Unified Diff: build/android/managed_install.py

Issue 1291793007: GN(android): Add scripts & runtime logic for installing _managed apks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-managed-install
Patch Set: javadoc & faster managed_install.py when --device specified Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/managed_install.py
diff --git a/build/android/managed_install.py b/build/android/managed_install.py
new file mode 100755
index 0000000000000000000000000000000000000000..9165d0413735d07205b7458d53d7240b70605993
--- /dev/null
+++ b/build/android/managed_install.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+#
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Install *_managed.apk targets as well as their dependent files."""
+
+import argparse
+import glob
+import logging
+import os
+import posixpath
+import sys
+
+from pylib import constants
+from pylib.device import device_errors
+from pylib.device import device_utils
+from pylib.utils import apk_helper
+
+
+def main():
+ logging.basicConfig(level=logging.INFO,
+ format='%(asctime)s %(message)s')
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument('apk_path',
+ help='The path to the APK to install.',
+ )
jbudorick 2015/08/23 02:01:28 ?
agrieve 2015/08/26 00:22:40 Done.
+ parser.add_argument('--split',
+ action='append',
+ dest='splits',
+ help='A glob matching the apk splits. '
+ 'Can be specified multiple times.')
+ parser.add_argument('--lib-dir',
+ help='Path to native libraries directory.')
+ parser.add_argument('-d', '--device', dest='device',
+ help='Target device for apk to install on.')
+ parser.add_argument('--uninstall',
+ action='store_true',
+ default=False,
+ help='Remove the app and all side-loaded files.')
+
+ args = parser.parse_args()
+
+ constants.SetBuildType('Debug')
+
+ if args.device:
+ devices = [device_utils.DeviceUtils(args.device)]
+ if not devices:
+ raise device_errors.DeviceUnreachableError(args.device)
+ else:
+ devices = device_utils.DeviceUtils.HealthyDevices()
+ if not devices:
+ raise device_errors.NoDevicesError()
+ elif len(devices) > 1:
+ raise Exception('More than one device available.\n'
+ 'Use --device=SERIAL to select a device.')
+ device = devices[0]
+ device.default_retries = 0
jbudorick 2015/08/23 02:01:28 - Why no retries? - Why not pass this to the const
agrieve 2015/08/26 00:22:40 Since this is for local dev, and can sometimes fai
+
+ apk_package = apk_helper.ApkHelper(args.apk_path).GetPackageName()
+ device_managed_dir = '/data/local/tmp/managed-app-%s' % apk_package
+
+ if args.uninstall:
+ logging.info('Uninstalling .apk')
+ device.Uninstall(apk_package)
+ logging.info('Removing side-loaded files')
+ device.RunShellCommand(['rm', '-rf', device_managed_dir], check_return=True)
+ return
+
+ # Install .apk(s) if any of them have changed.apk
+ logging.info('Installing .apk')
+ if args.splits:
+ splits = []
+ for split_glob in args.splits:
+ splits.extend((f for f in glob.glob(split_glob)))
+ device.InstallSplitApk(args.apk_path, splits, reinstall=True)
+ else:
+ device.Install(args.apk_path, reinstall=True)
+
+ # Push .so files to the device (if they have changed).
+ if args.lib_dir:
+ logging.info('Pushing libraries')
+ device_lib_dir = posixpath.join(device_managed_dir, 'lib')
+ device.PushChangedFiles([(args.lib_dir, device_lib_dir)],
+ delete_device_stale=True)
+
+
+if __name__ == '__main__':
+ sys.exit(main())
+

Powered by Google App Engine
This is Rietveld 408576698