am cd958154: Merge "Refactor a little bit and do the validation on also default.prop."

* commit 'cd958154a5bdb753274a338e799c3ece96ea9c5c':
  Refactor a little bit and do the validation on also default.prop.
This commit is contained in:
Ying Wang 2014-03-07 02:29:21 +00:00 committed by Android Git Automerger
commit 2bdf5e97bc

View file

@ -16,32 +16,17 @@
import sys import sys
# See PROP_VALUE_MAX system_properties.h.
# PROP_VALUE_MAX in system_properties.h includes the termination NUL,
# so we decrease it by 1 here.
PROP_VALUE_MAX = 91
# Put the modifications that you need to make into the /system/build.prop into this # Put the modifications that you need to make into the /system/build.prop into this
# function. The prop object has get(name) and put(name,value) methods. # function. The prop object has get(name) and put(name,value) methods.
def mangle_build_prop(prop): def mangle_build_prop(prop):
buildprops=prop.buildprops pass
check_pass=True
for key in buildprops:
# Check build properties' length.
# Terminator(\0) added into the provided value of properties
# Total length (including terminator) will be no greater that PROP_VALUE_MAX(92).
if len(buildprops[key]) > 91:
# If dev build, show a warning message, otherwise fail the build with error message
if prop.get("ro.build.version.incremental").startswith("eng"):
sys.stderr.write("warning: " + key + " exceeds 91 symbols: ")
sys.stderr.write(buildprops[key])
sys.stderr.write("(" + str(len(buildprops[key])) + ") \n")
sys.stderr.write("warning: This will cause the " + key + " ")
sys.stderr.write("property return as empty at runtime\n")
else:
check_pass=False
sys.stderr.write("error: " + key + " cannot exceed 91 symbols: ")
sys.stderr.write(buildprops[key])
sys.stderr.write("(" + str(len(buildprops[key])) + ") \n")
if not check_pass:
sys.exit(1)
# Put the modifications that you need to make into the /system/build.prop into this # Put the modifications that you need to make into the /default.prop into this
# function. The prop object has get(name) and put(name,value) methods. # function. The prop object has get(name) and put(name,value) methods.
def mangle_default_prop(prop): def mangle_default_prop(prop):
# If ro.debuggable is 1, then enable adb on USB by default # If ro.debuggable is 1, then enable adb on USB by default
@ -59,20 +44,47 @@ def mangle_default_prop(prop):
if not prop.get("persist.sys.usb.config"): if not prop.get("persist.sys.usb.config"):
prop.put("persist.sys.usb.config", "none"); prop.put("persist.sys.usb.config", "none");
def validate(prop):
"""Validate the properties.
Returns:
True if nothing is wrong.
"""
check_pass = True
buildprops = prop.to_dict()
dev_build = buildprops.get("ro.build.version.incremental",
"").startswith("eng")
for key, value in buildprops.iteritems():
# Check build properties' length.
if len(value) > PROP_VALUE_MAX:
# If dev build, show a warning message, otherwise fail the
# build with error message
if dev_build:
sys.stderr.write("warning: %s exceeds %d bytes: " %
(key, PROP_VALUE_MAX))
sys.stderr.write("%s (%d)\n" % (value, len(value)))
sys.stderr.write("warning: This will cause the %s " % key)
sys.stderr.write("property return as empty at runtime\n")
else:
check_pass = False
sys.stderr.write("error: %s cannot exceed %d bytes: " %
(key, PROP_VALUE_MAX))
sys.stderr.write("%s (%d)\n" % (value, len(value)))
return check_pass
class PropFile: class PropFile:
buildprops={}
def __init__(self, lines): def __init__(self, lines):
self.lines = [s[:-1] for s in lines] self.lines = [s.strip() for s in lines]
def to_dict(self):
props = {}
for line in self.lines: for line in self.lines:
line=line.strip() if not line or line.startswith("#"):
if not line.strip() or line.startswith("#"):
continue continue
index=line.find("=") key, value = line.split("=", 1)
key=line[0:index] props[key] = value
value=line[index+1:] return props
self.buildprops[key]=value
def get(self, name): def get(self, name):
key = name + "=" key = name + "="
@ -100,6 +112,7 @@ def main(argv):
f.close() f.close()
properties = PropFile(lines) properties = PropFile(lines)
if filename.endswith("/build.prop"): if filename.endswith("/build.prop"):
mangle_build_prop(properties) mangle_build_prop(properties)
elif filename.endswith("/default.prop"): elif filename.endswith("/default.prop"):
@ -108,6 +121,9 @@ def main(argv):
sys.stderr.write("bad command line: " + str(argv) + "\n") sys.stderr.write("bad command line: " + str(argv) + "\n")
sys.exit(1) sys.exit(1)
if not validate(properties):
sys.exit(1)
f = open(filename, 'w+') f = open(filename, 'w+')
properties.write(f) properties.write(f)
f.close() f.close()