blob: 32ce369cc394707281ba84ad8d5430b9d9b49e5b [file] [log] [blame]
Anthony King2890d6b2014-11-07 21:26:48 +00001#!/usr/bin/env python
2#
3# Copyright (C) 2009 The Android Open Source Project
4# Copyright (C) 2014 SlimRoms Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18import os
19import sys
20
21# give us access to import the original post_process_props
22sys.path.append(os.path.join(os.getenv('ANDROID_BUILD_TOP'), 'build/tools'))
23from post_process_props import PropFile, validate
24
25
Lars Greiss6f485242014-12-04 16:41:39 +010026lcd_changer = {"213": "182", "240": "200",
27 "320": "280", "480": "400", "560" : "493"}
Anthony King2890d6b2014-11-07 21:26:48 +000028
29
Anthony King1a52a3b2015-05-08 15:36:45 +010030def mangle_lcd_prop(prop):
31 new_lcd = prop.get('persist.sys.lcd_density')
32 if new_lcd == '':
33 lcd = prop.get('ro.sf.lcd_density')
34 new_lcd = lcd_changer.get(lcd, lcd)
35 if new_lcd != '':
36 prop.put('persist.sys.lcd_density', new_lcd)
37 prop.put('ro.slim.lcd_density', new_lcd)
38
39
Anthony King2890d6b2014-11-07 21:26:48 +000040def mangle_build_prop(prop):
Anthony King1a52a3b2015-05-08 15:36:45 +010041 mangle_lcd_prop(prop)
Anthony King2890d6b2014-11-07 21:26:48 +000042
43
44def mangle_default_prop(prop):
Anthony King1a52a3b2015-05-08 15:36:45 +010045 mangle_lcd_prop(prop)
Anthony King2890d6b2014-11-07 21:26:48 +000046
47
48def main(argv):
49 fn = argv[1]
50 with open(fn) as f:
51 lines = f.readlines()
52 properties = PropFile(lines)
53
54 if fn.endswith('/build.prop'):
55 mangle_build_prop(properties)
56 elif fn.endswith('/default.prop'):
57 mangle_default_prop(properties)
58 else:
59 sys.stderr.write("%s: Unsupported file: %s\n" % (os.path.realpath(__file__), fn))
60 sys.exit(1)
61
62 if not validate(properties):
63 # the validate routine prints on error
64 sys.exit(1)
65
66 with open(fn, 'w+') as f:
67 properties.write(f)
68
69if __name__ == '__main__':
70 main(sys.argv)