OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Module containing utilities for apk packages.""" | 5 """Module containing utilities for apk packages.""" |
6 | 6 |
7 import itertools | 7 import itertools |
8 import re | 8 import re |
9 | 9 |
10 from devil import base_error | 10 from devil import base_error |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if len(all_instrumentations) != 1: | 150 if len(all_instrumentations) != 1: |
151 raise base_error.BaseError( | 151 raise base_error.BaseError( |
152 'There is more than one instrumentation. Expected one.') | 152 'There is more than one instrumentation. Expected one.') |
153 else: | 153 else: |
154 return self._ResolveName(all_instrumentations[0]['android:name']) | 154 return self._ResolveName(all_instrumentations[0]['android:name']) |
155 | 155 |
156 def GetAllInstrumentations( | 156 def GetAllInstrumentations( |
157 self, default='android.test.InstrumentationTestRunner'): | 157 self, default='android.test.InstrumentationTestRunner'): |
158 """Returns a list of all Instrumentations in the apk.""" | 158 """Returns a list of all Instrumentations in the apk.""" |
159 try: | 159 try: |
160 return self._GetManifest()['manifest'][0]['instrumentation'] | 160 manifest = self._GetManifest()['manifest'][0] |
| 161 real_instrumentation_values = self._GetRealInstrumentationValue() |
| 162 if real_instrumentation_values: |
| 163 for index, instr in enumerate(manifest['instrumentation']): |
| 164 key = 'incremental-install-real-instrumentation-' + str(index) |
| 165 instr['android:name'] = real_instrumentation_values[key] |
| 166 return manifest['instrumentation'] |
161 except KeyError: | 167 except KeyError: |
162 return [{'android:name': default}] | 168 return [{'android:name': default}] |
163 | 169 |
164 def GetPackageName(self): | 170 def GetPackageName(self): |
165 """Returns the package name of the apk.""" | 171 """Returns the package name of the apk.""" |
166 manifest_info = self._GetManifest() | 172 manifest_info = self._GetManifest() |
167 try: | 173 try: |
168 return manifest_info['manifest'][0]['package'] | 174 return manifest_info['manifest'][0]['package'] |
169 except KeyError: | 175 except KeyError: |
170 raise Exception('Failed to determine package name of %s' % self._apk_path) | 176 raise Exception('Failed to determine package name of %s' % self._apk_path) |
(...skipping 19 matching lines...) Expand all Loading... |
190 manifest_info = self._GetManifest() | 196 manifest_info = self._GetManifest() |
191 try: | 197 try: |
192 applications = manifest_info['manifest'][0].get('application', []) | 198 applications = manifest_info['manifest'][0].get('application', []) |
193 services = itertools.chain( | 199 services = itertools.chain( |
194 *(application.get('service', []) for application in applications)) | 200 *(application.get('service', []) for application in applications)) |
195 return any( | 201 return any( |
196 _ParseNumericKey(s, 'android:isolatedProcess') for s in services) | 202 _ParseNumericKey(s, 'android:isolatedProcess') for s in services) |
197 except KeyError: | 203 except KeyError: |
198 return False | 204 return False |
199 | 205 |
| 206 def _GetRealInstrumentationValue(self): |
| 207 manifest = self._GetManifest()['manifest'][0] |
| 208 real_instrumentation_values = {} |
| 209 if (manifest.get('application') and |
| 210 manifest['application'][0].get('meta-data')): |
| 211 meta_data = manifest.get('application')[0]['meta-data'] |
| 212 for i in meta_data: |
| 213 if 'incremental-install-real-instrumentation' in i['android:name']: |
| 214 real_instrumentation_values[i['android:name']] = i['android:value'] |
| 215 return real_instrumentation_values |
| 216 |
200 def _GetManifest(self): | 217 def _GetManifest(self): |
201 if not self._manifest: | 218 if not self._manifest: |
202 self._manifest = _ParseManifestFromApk(self._apk_path) | 219 self._manifest = _ParseManifestFromApk(self._apk_path) |
203 return self._manifest | 220 return self._manifest |
204 | 221 |
205 def _ResolveName(self, name): | 222 def _ResolveName(self, name): |
206 name = name.lstrip('.') | 223 name = name.lstrip('.') |
207 if '.' not in name: | 224 if '.' not in name: |
208 return '%s.%s' % (self.GetPackageName(), name) | 225 return '%s.%s' % (self.GetPackageName(), name) |
209 return name | 226 return name |
OLD | NEW |