blob: 9d697360644a40077ddbe9d71281506501031e99 [file] [log] [blame]
Joe Onorato9197a482011-06-08 16:04:14 -07001#!/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
17import 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.
21def mangle_build_prop(prop):
22 pass
23
Joe Onorato9197a482011-06-08 16:04:14 -070024# 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.
26def 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)
Joe Onorato8ad4bb12012-05-02 14:36:57 -070036 # 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");
Joe Onorato9197a482011-06-08 16:04:14 -070041
42class 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
65def 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
Mike Lockwood5b65ee42011-06-08 19:06:43 -070080 f = open(filename, 'w+')
81 properties.write(f)
Joe Onorato9197a482011-06-08 16:04:14 -070082 f.close()
83
84if __name__ == "__main__":
85 main(sys.argv)