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

Side by Side Diff: build/android/gyp/util/build_device.py

Issue 221823011: [Android] Change object types from AndroidCommands to DeviceUtils in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Frank's comments. Created 6 years, 8 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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 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 """ A simple device interface for build steps. 5 """ A simple device interface for build steps.
6 6
7 """ 7 """
8 8
9 import logging 9 import logging
10 import os 10 import os
11 import re 11 import re
12 import sys 12 import sys
13 13
14 from util import build_utils 14 from util import build_utils
15 15
16 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..', '..') 16 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
17 sys.path.append(BUILD_ANDROID_DIR) 17 sys.path.append(BUILD_ANDROID_DIR)
18 18
19 from pylib import android_commands 19 from pylib import android_commands
20 from pylib.device import device_utils
20 21
21 GetAttachedDevices = android_commands.GetAttachedDevices 22 GetAttachedDevices = android_commands.GetAttachedDevices()
22 23
23 24
24 class BuildDevice(object): 25 class BuildDevice(object):
25 def __init__(self, configuration): 26 def __init__(self, configuration):
26 self.id = configuration['id'] 27 self.id = configuration['id']
27 self.description = configuration['description'] 28 self.description = configuration['description']
28 self.install_metadata = configuration['install_metadata'] 29 self.install_metadata = configuration['install_metadata']
29 self.adb = android_commands.AndroidCommands(self.id) 30 self.device = device_utils.DeviceUtils(self.id)
30 31
31 def RunShellCommand(self, *args, **kwargs): 32 def RunShellCommand(self, *args, **kwargs):
32 return self.adb.RunShellCommand(*args, **kwargs) 33 return self.device.old_interface.RunShellCommand(*args, **kwargs)
33 34
34 def PushIfNeeded(self, *args, **kwargs): 35 def PushIfNeeded(self, *args, **kwargs):
35 return self.adb.PushIfNeeded(*args, **kwargs) 36 return self.device.old_interface.PushIfNeeded(*args, **kwargs)
36 37
37 def GetSerialNumber(self): 38 def GetSerialNumber(self):
38 return self.id 39 return self.id
39 40
40 def Install(self, *args, **kwargs): 41 def Install(self, *args, **kwargs):
41 return self.adb.Install(*args, **kwargs) 42 return self.device.old_interface.Install(*args, **kwargs)
42 43
43 def GetInstallMetadata(self, apk_package): 44 def GetInstallMetadata(self, apk_package):
44 """Gets the metadata on the device for the apk_package apk.""" 45 """Gets the metadata on the device for the apk_package apk."""
45 # Matches lines like: 46 # Matches lines like:
46 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 47 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
47 # org.chromium.chrome.shell.apk 48 # org.chromium.chrome.shell.apk
48 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 49 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
49 # org.chromium.chrome.shell-1.apk 50 # org.chromium.chrome.shell-1.apk
50 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) 51 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s)
51 matches = filter(apk_matcher, self.install_metadata) 52 matches = filter(apk_matcher, self.install_metadata)
52 return matches[0] if matches else None 53 return matches[0] if matches else None
53 54
54 55
55 def GetConfigurationForDevice(device_id): 56 def GetConfigurationForDevice(device_id):
56 adb = android_commands.AndroidCommands(device_id) 57 device = device_utils.DeviceUtils(device_id)
57 configuration = None 58 configuration = None
58 has_root = False 59 has_root = False
59 is_online = adb.IsOnline() 60 is_online = device.old_interface.IsOnline()
60 if is_online: 61 if is_online:
61 cmd = 'ls -l /data/app; getprop ro.build.description' 62 cmd = 'ls -l /data/app; getprop ro.build.description'
62 cmd_output = adb.RunShellCommand(cmd) 63 cmd_output = device.old_interface.RunShellCommand(cmd)
63 has_root = not 'Permission denied' in cmd_output[0] 64 has_root = not 'Permission denied' in cmd_output[0]
64 if not has_root: 65 if not has_root:
65 # Disable warning log messages from EnableAdbRoot() 66 # Disable warning log messages from EnableAdbRoot()
66 logging.getLogger().disabled = True 67 logging.getLogger().disabled = True
67 has_root = adb.EnableAdbRoot() 68 has_root = device.old_interface.EnableAdbRoot()
68 logging.getLogger().disabled = False 69 logging.getLogger().disabled = False
69 cmd_output = adb.RunShellCommand(cmd) 70 cmd_output = device.old_interface.RunShellCommand(cmd)
70 71
71 configuration = { 72 configuration = {
72 'id': device_id, 73 'id': device_id,
73 'description': cmd_output[-1], 74 'description': cmd_output[-1],
74 'install_metadata': cmd_output[:-1], 75 'install_metadata': cmd_output[:-1],
75 } 76 }
76 return configuration, is_online, has_root 77 return configuration, is_online, has_root
77 78
78 79
79 def WriteConfigurations(configurations, path): 80 def WriteConfigurations(configurations, path):
80 # Currently we only support installing to the first device. 81 # Currently we only support installing to the first device.
81 build_utils.WriteJson(configurations[:1], path, only_if_changed=True) 82 build_utils.WriteJson(configurations[:1], path, only_if_changed=True)
82 83
83 84
84 def ReadConfigurations(path): 85 def ReadConfigurations(path):
85 return build_utils.ReadJson(path) 86 return build_utils.ReadJson(path)
86 87
87 88
88 def GetBuildDevice(configurations): 89 def GetBuildDevice(configurations):
89 assert len(configurations) == 1 90 assert len(configurations) == 1
90 return BuildDevice(configurations[0]) 91 return BuildDevice(configurations[0])
91 92
92 93
93 def GetBuildDeviceFromPath(path): 94 def GetBuildDeviceFromPath(path):
94 configurations = ReadConfigurations(path) 95 configurations = ReadConfigurations(path)
95 if len(configurations) > 0: 96 if len(configurations) > 0:
96 return GetBuildDevice(ReadConfigurations(path)) 97 return GetBuildDevice(ReadConfigurations(path))
97 return None 98 return None
98 99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698