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

Side by Side Diff: build/android/device_status_check.py

Issue 10583044: Revert 143261 - Upstreaming android build tools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
« no previous file with comments | « build/android/cmd_helper.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """A class to keep track of devices across builds and report state."""
8
9 import optparse
10 import os
11 import sys
12
13 from android_commands import GetAttachedDevices
14 from cmd_helper import GetCmdOutput
15
16
17 def DeviceInfo(serial):
18 """Gathers info on a device via various adb calls.
19
20 Args:
21 serial: The serial of the attached device to construct info about.
22
23 Returns:
24 Tuple of device type, build id and report as a string.
25 """
26
27 def AdbShellCmd(cmd):
28 return GetCmdOutput('adb -s %s shell %s' % (serial, cmd),
29 shell=True).strip()
30
31 device_type = AdbShellCmd('getprop ro.build.product')
32 device_build = AdbShellCmd('getprop ro.build.id')
33
34 report = ['Device %s (%s)' % (serial, device_type),
35 ' Build: %s (%s)' % (device_build,
36 AdbShellCmd('getprop ro.build.fingerprint')),
37 ' Battery: %s%%' % AdbShellCmd('dumpsys battery | grep level '
38 "| awk '{print $2}'"),
39 ' Battery temp: %s' % AdbShellCmd('dumpsys battery'
40 '| grep temp '
41 "| awk '{print $2}'"),
42 ' IMEI slice: %s' % AdbShellCmd('dumpsys iphonesubinfo '
43 '| grep Device'
44 "| awk '{print $4}'")[-6:],
45 ' Wifi IP: %s' % AdbShellCmd('getprop dhcp.wlan0.ipaddress'),
46 '']
47
48 return device_type, device_build, '\n'.join(report)
49
50
51 def CheckForMissingDevices(options, adb_online_devs):
52 """Uses file of previous online devices to detect broken phones.
53
54 Args:
55 options: out_dir parameter of options argument is used as the base
56 directory to load and update the cache file.
57 adb_online_devs: A list of serial numbers of the currently visible
58 and online attached devices.
59 """
60
61 last_devices_path = os.path.abspath(os.path.join(options.out_dir,
62 '.last_devices'))
63 last_devices = []
64 try:
65 with open(last_devices_path) as f:
66 last_devices = f.read().splitlines()
67 except IOError:
68 # Ignore error, file might not exist
69 pass
70
71 missing_devs = list(set(last_devices) - set(adb_online_devs))
72 if missing_devs:
73 print '@@@STEP_WARNINGS@@@'
74 print '@@@STEP_SUMMARY_TEXT@%s not detected.@@@' % missing_devs
75 print 'Current online devices: %s' % adb_online_devs
76 print '%s are no longer visible. Were they removed?\n' % missing_devs
77 print 'SHERIFF: See go/chrome_device_monitor'
78 print 'Cache file: %s\n\n' % last_devices_path
79 print 'adb devices'
80 print GetCmdOutput(['adb', 'devices'])
81 else:
82 new_devs = set(adb_online_devs) - set(last_devices)
83 if new_devs:
84 print '@@@STEP_WARNINGS@@@'
85 print '@@@STEP_SUMMARY_TEXT@New devices detected :-)@@@'
86 print ('New devices detected %s. And now back to your '
87 'regularly scheduled program.' % list(new_devs))
88
89 # Write devices currently visible plus devices previously seen.
90 with open(last_devices_path, 'w') as f:
91 f.write('\n'.join(set(adb_online_devs + last_devices)))
92
93
94 def main():
95 parser = optparse.OptionParser()
96 parser.add_option('', '--out-dir',
97 help='Directory where the device path is stored',
98 default=os.path.join(os.path.dirname(__file__), '..',
99 '..', 'out'))
100
101 options, args = parser.parse_args()
102 if args:
103 parser.error('Unknown options %s' % args)
104 devices = GetAttachedDevices()
105
106 types, builds, reports = [], [], []
107 if devices:
108 types, builds, reports = zip(*[DeviceInfo(dev) for dev in devices])
109
110 unique_types = list(set(types))
111 unique_builds = list(set(builds))
112
113 print ('@@@BUILD_STEP Device Status Check - '
114 '%d online devices, types %s, builds %s@@@'
115 % (len(devices), unique_types, unique_builds))
116 print '\n'.join(reports)
117 CheckForMissingDevices(options, devices)
118
119 if __name__ == '__main__':
120 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/cmd_helper.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698