| Index: devil/devil/android/apk_helper.py
|
| diff --git a/devil/devil/android/apk_helper.py b/devil/devil/android/apk_helper.py
|
| index 2cf052a97974d60126130995fbc95a43e0f8c69b..61eeda06c4c0b230eac0276f0d448922d8ad68c3 100644
|
| --- a/devil/devil/android/apk_helper.py
|
| +++ b/devil/devil/android/apk_helper.py
|
| @@ -6,7 +6,6 @@
|
|
|
| import re
|
|
|
| -from devil import base_error
|
| from devil.android.sdk import aapt
|
|
|
|
|
| @@ -55,22 +54,16 @@
|
|
|
| m = _MANIFEST_ELEMENT_RE.match(line[len(indent) * indent_depth:])
|
| if m:
|
| - manifest_key = m.group(1)
|
| - if manifest_key in node:
|
| - node[manifest_key] += [{}]
|
| - else:
|
| - node[manifest_key] = [{}]
|
| - node_stack += [node[manifest_key][-1]]
|
| + if not m.group(1) in node:
|
| + node[m.group(1)] = {}
|
| + node_stack += [node[m.group(1)]]
|
| continue
|
|
|
| m = _MANIFEST_ATTRIBUTE_RE.match(line[len(indent) * indent_depth:])
|
| if m:
|
| - manifest_key = m.group(1)
|
| - if manifest_key in node:
|
| - raise base_error.BaseError(
|
| - "A single attribute should have one key and one value")
|
| - else:
|
| - node[manifest_key] = m.group(2) or m.group(3)
|
| + if not m.group(1) in node:
|
| + node[m.group(1)] = []
|
| + node[m.group(1)].append(m.group(2) or m.group(3))
|
| continue
|
|
|
| return parsed_manifest
|
| @@ -91,8 +84,8 @@
|
| manifest_info = self._GetManifest()
|
| try:
|
| activity = (
|
| - manifest_info['manifest'][0]['application'][0]['activity'][0]
|
| - ['android:name'])
|
| + manifest_info['manifest']['application']['activity']
|
| + ['android:name'][0])
|
| except KeyError:
|
| return None
|
| if '.' not in activity:
|
| @@ -104,34 +97,24 @@
|
| def GetInstrumentationName(
|
| self, default='android.test.InstrumentationTestRunner'):
|
| """Returns the name of the Instrumentation in the apk."""
|
| - all_instrumentations = self.GetAllInstrumentations(default=default)
|
| - if len(all_instrumentations) != 1:
|
| - raise base_error.BaseError(
|
| - 'There is more than one instrumentation. Expected one.')
|
| - else:
|
| - return all_instrumentations[0]
|
| -
|
| - def GetAllInstrumentations(
|
| - self, default='android.test.InstrumentationTestRunner'):
|
| - """Returns a list of all Instrumentations in the apk."""
|
| + manifest_info = self._GetManifest()
|
| try:
|
| - return self._GetManifest()['manifest'][0]['instrumentation']
|
| + return manifest_info['manifest']['instrumentation']['android:name'][0]
|
| except KeyError:
|
| - return [{'android:name': default}]
|
| + return default
|
|
|
| def GetPackageName(self):
|
| """Returns the package name of the apk."""
|
| manifest_info = self._GetManifest()
|
| try:
|
| - return manifest_info['manifest'][0]['package']
|
| + return manifest_info['manifest']['package'][0]
|
| except KeyError:
|
| raise Exception('Failed to determine package name of %s' % self._apk_path)
|
|
|
| def GetPermissions(self):
|
| manifest_info = self._GetManifest()
|
| try:
|
| - return [p['android:name'] for
|
| - p in manifest_info['manifest'][0]['uses-permission']]
|
| + return manifest_info['manifest']['uses-permission']['android:name']
|
| except KeyError:
|
| return []
|
|
|
| @@ -139,17 +122,18 @@
|
| """Returns the name of the split of the apk."""
|
| manifest_info = self._GetManifest()
|
| try:
|
| - return manifest_info['manifest'][0]['split']
|
| + return manifest_info['manifest']['split'][0]
|
| except KeyError:
|
| return None
|
|
|
| def HasIsolatedProcesses(self):
|
| """Returns whether any services exist that use isolatedProcess=true."""
|
| manifest_info = self._GetManifest()
|
| - isolated_services = [
|
| - int(s['service'][0].get('android:isolatedProcess', '0'), 0) for s in
|
| - manifest_info['manifest'][0]['application']]
|
| - return any(isolated_services)
|
| + try:
|
| + services = manifest_info['manifest']['application']['service']
|
| + return any(int(v, 0) for v in services['android:isolatedProcess'])
|
| + except KeyError:
|
| + return False
|
|
|
| def _GetManifest(self):
|
| if not self._manifest:
|
|
|