Add get_props to adb.py's AndroidDevice.

Saves adb shell roundtrips if multiple properties are needed.

Change-Id: I3a9fc0354b6eb0ee5389984e3f345c380404658c
This commit is contained in:
Josh Gao
2015-09-22 11:41:13 -07:00
parent cac4e977bb
commit 87df6ff2c8

View File

@@ -411,6 +411,22 @@ class AndroidDevice(object):
def wait(self):
return self._simple_call(['wait-for-device'])
def get_props(self):
result = {}
output, _ = self.shell(['getprop'])
output = output.splitlines()
pattern = re.compile(r'^\[([^]]+)\]: \[(.*)\]')
for line in output:
match = pattern.match(line)
if match is None:
raise RuntimeError('invalid getprop line: "{}"'.format(line))
key = match.group(1)
value = match.group(2)
if key in result:
raise RuntimeError('duplicate getprop key: "{}"'.format(key))
result[key] = value
return result
def get_prop(self, prop_name):
output = self.shell(['getprop', prop_name])[0].splitlines()
if len(output) != 1: