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

Side by Side Diff: build/android/gyp/apk_install.py

Issue 1166113002: Add InstallSplitApk function to device utils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Installs an APK. 7 """Installs an APK.
8 8
9 """ 9 """
10 10
11 import optparse 11 import optparse
12 import os 12 import os
13 import re 13 import re
14 import sys 14 import sys
15 15
16 from util import build_device 16 from util import build_device
17 from util import build_utils 17 from util import build_utils
18 from util import md5_check 18 from util import md5_check
19 19
20 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') 20 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
21 sys.path.append(BUILD_ANDROID_DIR) 21 sys.path.append(BUILD_ANDROID_DIR)
22 22
23 from pylib import constants 23 from pylib import constants
24 from pylib.utils import apk_helper 24 from pylib.utils import apk_helper
25 25
26 _DPI_TO_DENSITY = {
27 120: 'ldpi',
28 160: 'mdpi',
29 240: 'hdpi',
30 320: 'xhdpi',
31 480: 'xxhdpi',
32 }
33
34
35 def RetrieveDeviceConfig(device):
36 """Probes the given device for its split-select config.
37
38 For example: en-rUS-xhdpi:armeabi-v7a
39 Run "split-select --help" for more info about the format.
40 """
41 language = device.GetProp('persist.sys.language')
42 country = device.GetProp('persist.sys.country')
43 density_dpi = int(device.GetProp('ro.sf.lcd_density'))
44 density = _DPI_TO_DENSITY.get(density_dpi, 'tvdpi')
45 abi = device.product_cpu_abi
46 return '%s-r%s-%s:%s' % (language, country, density, abi)
47
48 26
49 def GetNewMetadata(device, apk_package): 27 def GetNewMetadata(device, apk_package):
50 """Gets the metadata on the device for the apk_package apk.""" 28 """Gets the metadata on the device for the apk_package apk."""
51 output = device.RunShellCommand('ls -l /data/app/') 29 output = device.RunShellCommand('ls -l /data/app/')
52 # Matches lines like: 30 # Matches lines like:
53 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 31 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
54 # org.chromium.chrome.shell.apk 32 # org.chromium.chrome.shell.apk
55 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 33 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
56 # org.chromium.chrome.shell-1.apk 34 # org.chromium.chrome.shell-1.apk
57 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s) 35 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 85
108 serial_number = device.GetSerialNumber() 86 serial_number = device.GetSerialNumber()
109 apk_package = apk_helper.GetPackageName(options.apk_path) 87 apk_package = apk_helper.GetPackageName(options.apk_path)
110 88
111 metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number) 89 metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number)
112 90
113 # If the APK on the device does not match the one that was last installed by 91 # If the APK on the device does not match the one that was last installed by
114 # the build, then the APK has to be installed (regardless of the md5 record). 92 # the build, then the APK has to be installed (regardless of the md5 record).
115 force_install = HasInstallMetadataChanged(device, apk_package, metadata_path) 93 force_install = HasInstallMetadataChanged(device, apk_package, metadata_path)
116 94
117 def SelectSplits(target_config, base_apk, split_apks, android_sdk_tools):
118 cmd = [os.path.join(android_sdk_tools, 'split-select'),
119 '--target', target_config,
120 '--base', base_apk,
121 ]
122 for split in split_apks:
123 cmd.extend(('--split', split))
124
125 # split-select outputs one path per line and a blank line at the end.
126 output = build_utils.CheckOutput(cmd)
127 return [x for x in output.split('\n') if x]
128 95
129 def Install(): 96 def Install():
130 if options.split_apk_path: 97 if options.split_apk_path:
131 requiredSdkVersion = constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP 98 device.InstallSplitApk(options.apk_path, options.split_apk_path)
132 actualSdkVersion = device.device.build_version_sdk
133 if actualSdkVersion < requiredSdkVersion:
134 raise Exception(('--split-apk-path requires sdk version %s. Device has '
135 'version %s') % (requiredSdkVersion, actualSdkVersion))
136 device_config = RetrieveDeviceConfig(device.device)
137 active_splits = SelectSplits(
138 device_config,
139 options.apk_path,
140 options.split_apk_path,
141 options.android_sdk_tools)
142
143 all_apks = [options.apk_path] + active_splits
144 device.device.adb.InstallMultiple(all_apks, reinstall=True)
145 else: 99 else:
146 device.Install(options.apk_path, reinstall=True) 100 device.Install(options.apk_path, reinstall=True)
147 101
148 RecordInstallMetadata(device, apk_package, metadata_path) 102 RecordInstallMetadata(device, apk_package, metadata_path)
149 build_utils.Touch(options.install_record) 103 build_utils.Touch(options.install_record)
150 104
151 105
152 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) 106 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number)
153 md5_check.CallAndRecordIfStale( 107 md5_check.CallAndRecordIfStale(
154 Install, 108 Install,
155 record_path=record_path, 109 record_path=record_path,
156 input_paths=[options.apk_path], 110 input_paths=[options.apk_path],
157 force=force_install) 111 force=force_install)
158 112
159 if options.stamp: 113 if options.stamp:
160 build_utils.Touch(options.stamp) 114 build_utils.Touch(options.stamp)
161 115
162 116
163 if __name__ == '__main__': 117 if __name__ == '__main__':
164 sys.exit(main()) 118 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/android/gyp/util/build_device.py » ('j') | build/android/pylib/device/device_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698