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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Install *_managed.apk targets as well as their dependent files."""
8
9 import argparse
10 import glob
11 import logging
12 import os
13 import posixpath
14 import sys
15
16 from pylib import constants
17 from pylib.device import device_errors
18 from pylib.device import device_utils
19 from pylib.utils import apk_helper
20
21
22 def main():
23 logging.basicConfig(level=logging.INFO,
24 format='%(asctime)s %(message)s')
25 parser = argparse.ArgumentParser()
26
27 parser.add_argument('apk_path',
28 help='The path to the APK to install.',
29 )
jbudorick 2015/08/23 02:01:28 ?
agrieve 2015/08/26 00:22:40 Done.
30 parser.add_argument('--split',
31 action='append',
32 dest='splits',
33 help='A glob matching the apk splits. '
34 'Can be specified multiple times.')
35 parser.add_argument('--lib-dir',
36 help='Path to native libraries directory.')
37 parser.add_argument('-d', '--device', dest='device',
38 help='Target device for apk to install on.')
39 parser.add_argument('--uninstall',
40 action='store_true',
41 default=False,
42 help='Remove the app and all side-loaded files.')
43
44 args = parser.parse_args()
45
46 constants.SetBuildType('Debug')
47
48 if args.device:
49 devices = [device_utils.DeviceUtils(args.device)]
50 if not devices:
51 raise device_errors.DeviceUnreachableError(args.device)
52 else:
53 devices = device_utils.DeviceUtils.HealthyDevices()
54 if not devices:
55 raise device_errors.NoDevicesError()
56 elif len(devices) > 1:
57 raise Exception('More than one device available.\n'
58 'Use --device=SERIAL to select a device.')
59 device = devices[0]
60 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
61
62 apk_package = apk_helper.ApkHelper(args.apk_path).GetPackageName()
63 device_managed_dir = '/data/local/tmp/managed-app-%s' % apk_package
64
65 if args.uninstall:
66 logging.info('Uninstalling .apk')
67 device.Uninstall(apk_package)
68 logging.info('Removing side-loaded files')
69 device.RunShellCommand(['rm', '-rf', device_managed_dir], check_return=True)
70 return
71
72 # Install .apk(s) if any of them have changed.apk
73 logging.info('Installing .apk')
74 if args.splits:
75 splits = []
76 for split_glob in args.splits:
77 splits.extend((f for f in glob.glob(split_glob)))
78 device.InstallSplitApk(args.apk_path, splits, reinstall=True)
79 else:
80 device.Install(args.apk_path, reinstall=True)
81
82 # Push .so files to the device (if they have changed).
83 if args.lib_dir:
84 logging.info('Pushing libraries')
85 device_lib_dir = posixpath.join(device_managed_dir, 'lib')
86 device.PushChangedFiles([(args.lib_dir, device_lib_dir)],
87 delete_device_stale=True)
88
89
90 if __name__ == '__main__':
91 sys.exit(main())
92
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698