Home | History | Annotate | Download | only in tools
      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):
     22   pass
     23 
     24 # Put the modifications that you need to make into the /system/build.prop into this
     25 # function. The prop object has get(name) and put(name,value) methods.
     26 def mangle_default_prop(prop):
     27   # If ro.debuggable is 1, then enable adb on USB by default
     28   # (this is for userdebug builds)
     29   if prop.get("ro.debuggable") == "1":
     30     val = prop.get("persist.sys.usb.config")
     31     if val == "":
     32       val = "adb"
     33     else:
     34       val = val + ",adb"
     35     prop.put("persist.sys.usb.config", val)
     36   # UsbDeviceManager expects a value here.  If it doesn't get it, it will
     37   # default to "adb". That might not the right policy there, but it's better
     38   # to be explicit.
     39   if not prop.get("persist.sys.usb.config"):
     40     prop.put("persist.sys.usb.config", "none");
     41 
     42 class PropFile:
     43   def __init__(self, lines):
     44     self.lines = [s[:-1] for s in lines]
     45 
     46   def get(self, name):
     47     key = name + "="
     48     for line in self.lines:
     49       if line.startswith(key):
     50         return line[len(key):]
     51     return ""
     52 
     53   def put(self, name, value):
     54     key = name + "="
     55     for i in range(0,len(self.lines)):
     56       if self.lines[i].startswith(key):
     57         self.lines[i] = key + value
     58         return
     59     self.lines.append(key + value)
     60 
     61   def write(self, f):
     62     f.write("\n".join(self.lines))
     63     f.write("\n")
     64 
     65 def main(argv):
     66   filename = argv[1]
     67   f = open(filename)
     68   lines = f.readlines()
     69   f.close()
     70 
     71   properties = PropFile(lines)
     72   if filename.endswith("/build.prop"):
     73     mangle_build_prop(properties)
     74   elif filename.endswith("/default.prop"):
     75     mangle_default_prop(properties)
     76   else:
     77     sys.stderr.write("bad command line: " + str(argv) + "\n")
     78     sys.exit(1)
     79 
     80   f = open(filename, 'w+')
     81   properties.write(f)
     82   f.close()
     83 
     84 if __name__ == "__main__":
     85   main(sys.argv)
     86