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

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

Issue 16831013: [Android] Add an action to check/record attached devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4 """ A simple device interface for build steps.
shashi 2013/06/20 03:16:19 Nit new line between file comment and copyright no
cjhopman 2013/06/25 16:43:11 Done.
5
6 """
7
8 import logging
9 import os
10 import re
11 import sys
12
13 import build_utils
14
15 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
16 sys.path.append(BUILD_ANDROID_DIR)
17
18 from pylib import android_commands
19
20 from pylib.android_commands import GetAttachedDevices
21
22
23 class BuildDevice(object):
24 def __init__(self, configuration):
25 self.id = configuration['id']
26 self.description = configuration['description']
27 self.install_metadata = configuration['install_metadata']
28 self.adb = android_commands.AndroidCommands(self.id)
29
30 def RunShellCommand(self, *args, **kwargs):
31 return self.adb.RunShellCommand(*args, **kwargs)
32
33 def PushIfNeeded(self, *args, **kwargs):
34 return self.adb.PushIfNeeded(*args, **kwargs)
35
36 def GetSerialNumber(self):
37 return self.id
38
39 def Install(self, *args, **kwargs):
40 return self.adb.Install(*args, **kwargs)
41
42 def GetInstallMetadata(self, apk_package):
43 """Gets the metadata on the device for the apk_package apk."""
44 # Matches lines like:
45 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome .testshell.apk
46 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome .testshell-1.apk
47 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s)
48 matches = filter(apk_matcher, self.install_metadata)
49 return matches[0] if matches else None
50
51
52 def GetConfigurationForDevice(id):
53 adb = android_commands.AndroidCommands(id)
54 configuration = None
55 has_root = False
56 is_online = adb.IsOnline()
57 if is_online:
58 cmd = 'ls -l /data/app; getprop ro.build.description'
59 cmd_output = adb.RunShellCommand(cmd)
60 has_root = not 'Permission denied' in cmd_output[0]
61 if not has_root:
62 # Disable warning log messages from EnableAdbRoot()
63 logging.getLogger().disabled = True
64 has_root = adb.EnableAdbRoot()
shashi 2013/06/20 03:16:19 Can we move this to before and always try to enabl
cjhopman 2013/06/25 16:43:11 It is ~200ms per device for every build. A no-op b
shashi 2013/06/25 17:23:31 OK, did not realise it was this slow. On 2013/06/2
65 logging.getLogger().disabled = False
66 cmd_output = adb.RunShellCommand(cmd)
67
68 configuration = {
69 'id': id,
70 'description': cmd_output[-1],
71 'install_metadata': cmd_output[:-1],
72 }
73 return configuration, is_online, has_root
74
75
76 def WriteConfigurations(configurations, path):
77 # Currently we only support installing to the first device.
78 build_utils.WriteJson(configurations[:1], path, only_if_changed=True)
79
80
81 def ReadConfigurations(path):
82 configurations = build_utils.ReadJson(path)
shashi 2013/06/20 03:16:19 nit: return build_utils.ReadJson(path)
cjhopman 2013/06/25 16:43:11 Done.
83 return configurations
84
85
86 def GetBuildDevice(configurations):
87 assert len(configurations) == 1
shashi 2013/06/20 03:16:19 nit: pass a single element of the list instead of
cjhopman 2013/06/25 16:43:11 It is actually important that the list of configur
shashi 2013/06/25 17:23:31 If there is plan in future to support multiple dev
88 return BuildDevice(configurations[0])
89
90
91 def GetBuildDeviceFromPath(path):
92 configurations = ReadConfigurations(path)
93 if len(configurations) > 0:
94 return GetBuildDevice(ReadConfigurations(path))
shashi 2013/06/20 03:16:19 nit: pass configurations[0] here. return GetBuildD
95 return None
96
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698