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

Unified Diff: build/android/pylib/device/device_utils.py

Issue 776303002: Migrate DeviceUtils.SetJavaAsserts to adb_wrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils.py
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index 805df6517eb6580ebd43d9d2091a8401935709fa..c6b50cbe15a670a86c361e1800ff46a3d93bf629 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -103,6 +103,9 @@ class DeviceUtils(object):
_MAX_ADB_COMMAND_LENGTH = 512
_VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')
+ # Property in /data/local.prop that controls Java assertions.
+ JAVA_ASSERT_PROPERTY = 'dalvik.vm.enableassertions'
+
def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT,
default_retries=_DEFAULT_RETRIES):
"""DeviceUtils constructor.
@@ -1038,7 +1041,43 @@ class DeviceUtils(object):
Raises:
CommandTimeoutError on timeout.
"""
- return self.old_interface.SetJavaAssertsEnabled(enabled)
+ def find_property(lines, property_name):
+ for index, line in enumerate(lines):
+ key, value = (s.strip() for s in line.split('=', 1))
+ if key == property_name:
+ return index, value
+ return None, ''
+
+ new_value = 'all' if enabled else ''
+
+ # First ensure the desired property is persisted.
+ try:
+ properties = self.ReadFile(
+ constants.DEVICE_LOCAL_PROPERTIES_PATH).splitlines()
+ except device_errors.CommandFailedError:
+ properties = []
+ index, value = find_property(properties, self.JAVA_ASSERT_PROPERTY)
+ if new_value != value:
+ if new_value:
+ new_line = '%s=%s' % (self.JAVA_ASSERT_PROPERTY, new_value)
+ if index is None:
+ properties.append(new_line)
+ else:
+ properties[index] = new_line
+ else:
+ assert index is not None # since new_value == '' and new_value != value
+ properties.pop(index)
+ self.WriteFile(constants.DEVICE_LOCAL_PROPERTIES_PATH,
+ _JoinLines(properties))
+
+ # Next, check the current runtime value is what we need, and
+ # if not, set it and report that a reboot is required.
+ value = self.GetProp(self.JAVA_ASSERT_PROPERTY)
+ if new_value != value:
+ self.SetProp(self.JAVA_ASSERT_PROPERTY, new_value)
+ return True
+ else:
+ return False
@property
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698