Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2009 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import sys |
| 18 | |
| 19 | # Put the modifications that you need to make into the /system/build.prop into this |
| 20 | # function. The prop object has get(name) and put(name,value) methods. |
| 21 | def mangle_build_prop(prop): |
Yu Liu | 115c66b | 2014-02-10 19:20:36 -0800 | [diff] [blame^] | 22 | buildprops=prop.buildprops |
| 23 | check_pass=True |
| 24 | for key in buildprops: |
| 25 | # Check build properties' length. |
| 26 | # Terminator(\0) added into the provided value of properties |
| 27 | # Total length (including terminator) will be no greater that PROP_VALUE_MAX(92). |
| 28 | if len(buildprops[key]) > 91: |
| 29 | # If dev build, show a warning message, otherwise fail the build with error message |
| 30 | if prop.get("ro.build.version.incremental").startswith("eng"): |
| 31 | sys.stderr.write("warning: " + key + " exceeds 91 symbols: ") |
| 32 | sys.stderr.write(buildprops[key]) |
| 33 | sys.stderr.write("(" + str(len(buildprops[key])) + ") \n") |
| 34 | sys.stderr.write("warning: This will cause the " + key + " ") |
| 35 | sys.stderr.write("property return as empty at runtime\n") |
| 36 | else: |
| 37 | check_pass=False |
| 38 | sys.stderr.write("error: " + key + " cannot exceed 91 symbols: ") |
| 39 | sys.stderr.write(buildprops[key]) |
| 40 | sys.stderr.write("(" + str(len(buildprops[key])) + ") \n") |
| 41 | if not check_pass: |
| 42 | sys.exit(1) |
Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 43 | |
Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 44 | # Put the modifications that you need to make into the /system/build.prop into this |
| 45 | # function. The prop object has get(name) and put(name,value) methods. |
| 46 | def mangle_default_prop(prop): |
| 47 | # If ro.debuggable is 1, then enable adb on USB by default |
| 48 | # (this is for userdebug builds) |
| 49 | if prop.get("ro.debuggable") == "1": |
| 50 | val = prop.get("persist.sys.usb.config") |
| 51 | if val == "": |
| 52 | val = "adb" |
| 53 | else: |
| 54 | val = val + ",adb" |
| 55 | prop.put("persist.sys.usb.config", val) |
Joe Onorato | 8ad4bb1 | 2012-05-02 14:36:57 -0700 | [diff] [blame] | 56 | # UsbDeviceManager expects a value here. If it doesn't get it, it will |
| 57 | # default to "adb". That might not the right policy there, but it's better |
| 58 | # to be explicit. |
| 59 | if not prop.get("persist.sys.usb.config"): |
| 60 | prop.put("persist.sys.usb.config", "none"); |
Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 61 | |
| 62 | class PropFile: |
Yu Liu | 115c66b | 2014-02-10 19:20:36 -0800 | [diff] [blame^] | 63 | |
| 64 | buildprops={} |
| 65 | |
Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 66 | def __init__(self, lines): |
| 67 | self.lines = [s[:-1] for s in lines] |
Yu Liu | 115c66b | 2014-02-10 19:20:36 -0800 | [diff] [blame^] | 68 | for line in self.lines: |
| 69 | line=line.strip() |
| 70 | if not line.strip() or line.startswith("#"): |
| 71 | continue |
| 72 | index=line.find("=") |
| 73 | key=line[0:index] |
| 74 | value=line[index+1:] |
| 75 | self.buildprops[key]=value |
Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 76 | |
| 77 | def get(self, name): |
| 78 | key = name + "=" |
| 79 | for line in self.lines: |
| 80 | if line.startswith(key): |
| 81 | return line[len(key):] |
| 82 | return "" |
| 83 | |
| 84 | def put(self, name, value): |
| 85 | key = name + "=" |
| 86 | for i in range(0,len(self.lines)): |
| 87 | if self.lines[i].startswith(key): |
| 88 | self.lines[i] = key + value |
| 89 | return |
| 90 | self.lines.append(key + value) |
| 91 | |
| 92 | def write(self, f): |
| 93 | f.write("\n".join(self.lines)) |
| 94 | f.write("\n") |
| 95 | |
| 96 | def main(argv): |
| 97 | filename = argv[1] |
| 98 | f = open(filename) |
| 99 | lines = f.readlines() |
| 100 | f.close() |
| 101 | |
| 102 | properties = PropFile(lines) |
| 103 | if filename.endswith("/build.prop"): |
| 104 | mangle_build_prop(properties) |
| 105 | elif filename.endswith("/default.prop"): |
| 106 | mangle_default_prop(properties) |
| 107 | else: |
| 108 | sys.stderr.write("bad command line: " + str(argv) + "\n") |
| 109 | sys.exit(1) |
| 110 | |
Mike Lockwood | 5b65ee4 | 2011-06-08 19:06:43 -0700 | [diff] [blame] | 111 | f = open(filename, 'w+') |
| 112 | properties.write(f) |
Joe Onorato | 9197a48 | 2011-06-08 16:04:14 -0700 | [diff] [blame] | 113 | f.close() |
| 114 | |
| 115 | if __name__ == "__main__": |
| 116 | main(sys.argv) |