improve OTA failure messages

Replace OTA script constructs of the form:

   assert(foo);

with

   foo || abort("sensible message");

so that the log and the on-screen display is somewhat more accessible
to non-experts.  (assert() displays the source code of the false
expression 'foo'.)

Change-Id: Ic99448e4466561d305b167cd4d5c1f0f2dbadcce
This commit is contained in:
Doug Zongker
2013-06-03 12:07:12 -07:00
parent 8216f3228f
commit 0d92f1f13a
2 changed files with 25 additions and 15 deletions

View File

@@ -72,24 +72,31 @@ class EdifyGenerator(object):
"""Assert that the current system build fingerprint is one of *fp."""
if not fp:
raise ValueError("must specify some fingerprints")
cmd = ('assert(' +
' ||\0'.join([('file_getprop("/system/build.prop", '
cmd = (
' ||\n '.join([('file_getprop("/system/build.prop", '
'"ro.build.fingerprint") == "%s"')
% i for i in fp]) +
');')
self.script.append(self._WordWrap(cmd))
' ||\n abort("Package expects build fingerprint of %s; this '
'device has " + getprop("ro.build.fingerprint") + ".");'
) % (" or ".join(fp),)
self.script.append(cmd)
def AssertOlderBuild(self, timestamp):
def AssertOlderBuild(self, timestamp, timestamp_text):
"""Assert that the build on the device is older (or the same as)
the given timestamp."""
self.script.append(('assert(!less_than_int(%s, '
'getprop("ro.build.date.utc")));') % (timestamp,))
self.script.append(
('(!less_than_int(%s, getprop("ro.build.date.utc"))) || '
'abort("Can\'t install this package (%s) over newer '
'build (" + getprop("ro.build.date") + ").");'
) % (timestamp, timestamp_text))
def AssertDevice(self, device):
"""Assert that the device identifier is the given string."""
cmd = ('assert(getprop("ro.product.device") == "%s" ||\0'
'getprop("ro.build.product") == "%s");' % (device, device))
self.script.append(self._WordWrap(cmd))
cmd = ('getprop("ro.product.device") == "%s" || '
'abort("This package is for \\"%s\\" devices; '
'this is a \\"" + getprop("ro.product.device") + "\\".");'
) % (device, device)
self.script.append(cmd)
def AssertSomeBootloader(self, *bootloaders):
"""Asert that the bootloader version is one of *bootloaders."""
@@ -115,9 +122,10 @@ class EdifyGenerator(object):
"""Check that the given file (or MTD reference) has one of the
given *sha1 hashes, checking the version saved in cache if the
file does not match."""
self.script.append('assert(apply_patch_check("%s"' % (filename,) +
"".join([', "%s"' % (i,) for i in sha1]) +
'));')
self.script.append(
'apply_patch_check("%s"' % (filename,) +
"".join([', "%s"' % (i,) for i in sha1]) +
') || abort("\\"%s\\" has unexpected contents.");' % (filename,))
def FileCheck(self, filename, *sha1):
"""Check that the given file (or MTD reference) has one of the
@@ -129,7 +137,8 @@ class EdifyGenerator(object):
def CacheFreeSpaceCheck(self, amount):
"""Check that there's at least 'amount' space that can be made
available on /cache."""
self.script.append("assert(apply_patch_space(%d));" % (amount,))
self.script.append(('apply_patch_space(%d) || abort("Not enough free space '
'on /system to apply patches.");') % (amount,))
def Mount(self, mount_point):
"""Mount the partition with the given mount_point."""

View File

@@ -387,7 +387,8 @@ def WriteFullOTAPackage(input_zip, output_zip):
if not OPTIONS.omit_prereq:
ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)
script.AssertOlderBuild(ts)
ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict)
script.AssertOlderBuild(ts, ts_text)
AppendAssertions(script, OPTIONS.info_dict)
device_specific.FullOTA_Assertions()