Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The CyanogenMod Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 17 | import java.io.IOException; |
| 18 | import java.io.BufferedWriter; |
| 19 | import java.io.FileOutputStream; |
| 20 | import java.io.IOException; |
| 21 | import java.io.OutputStreamWriter; |
| 22 | import java.io.Writer; |
| 23 | import java.nio.charset.Charset; |
| 24 | import java.util.ArrayList; |
| 25 | |
| 26 | /** |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 27 | * This is to be run on a live Lineage 12.1 device. |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 28 | */ |
| 29 | public class GenerateExampleSettings { |
| 30 | |
| 31 | private static ArrayList<Setting> androidSystemSettingList = new ArrayList<Setting>(); |
| 32 | private static ArrayList<Setting> androidSecureSettingList = new ArrayList<Setting>(); |
| 33 | private static ArrayList<Setting> androidGlobalSettingList = new ArrayList<Setting>(); |
| 34 | private static ArrayList<Setting> defaultSettings = new ArrayList<Setting>(); |
| 35 | |
| 36 | public static void main(String[] args) throws IOException, ClassNotFoundException { |
| 37 | if (args.length != 1) { |
| 38 | System.err.println("Usage: GenerateExampleSettings [target file]"); |
| 39 | System.exit(-1); |
| 40 | } |
| 41 | |
| 42 | String rootFile = args[0]; |
| 43 | SettingImageCommands androidSettingImage = |
| 44 | new SettingImageCommands(SettingsConstants.SETTINGS_AUTHORITY); |
| 45 | androidSettingImage.addQuery(SettingsConstants.SYSTEM, androidSystemSettingList); |
| 46 | androidSettingImage.addQuery(SettingsConstants.SECURE, androidSecureSettingList); |
| 47 | androidSettingImage.addQuery(SettingsConstants.GLOBAL, androidGlobalSettingList); |
| 48 | androidSettingImage.execute(); |
| 49 | |
| 50 | for (Setting system : androidSystemSettingList) { |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 51 | if (LineageSettings.System.isLegacySetting(system.getKey())) { |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 52 | defaultSettings.add(system); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | for (Setting secure : androidSecureSettingList) { |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 57 | if (LineageSettings.Secure.isLegacySetting(secure.getKey())) { |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 58 | defaultSettings.add(secure); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | for (Setting global : androidGlobalSettingList) { |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 63 | if (LineageSettings.Global.isLegacySetting(global.getKey())) { |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 64 | defaultSettings.add(global); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | Writer out = new BufferedWriter(new OutputStreamWriter( |
| 69 | new FileOutputStream(rootFile), |
| 70 | Charset.forName("US-ASCII"))); |
| 71 | |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 72 | out.write("# Settings which are to be moved to LineageSettings\n"); |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 73 | out.write("# Automatically generated by " + |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 74 | "lineage-sdk/host/migration/src/GenerateExampleSettings" |
Adnan Begovic | d5fdee9 | 2015-11-13 15:28:21 -0800 | [diff] [blame] | 75 | + GenerateExampleSettings.class.getSimpleName() + ".java.\n"); |
| 76 | // Write settings to file for output. |
| 77 | for (int i = 0; i < defaultSettings.size(); i++) { |
| 78 | Setting defaultSetting = defaultSettings.get(i); |
| 79 | // This is the same format as what is spit out by system/bin/content |
| 80 | out.write("Row: " + i + " name=" + defaultSetting.getKey() |
| 81 | + ", type=" + defaultSetting.getKeyType() |
| 82 | + ", value=" + defaultSetting.getValue() |
| 83 | + ", type=" + defaultSetting.getValueType() + "\n"); |
| 84 | } |
| 85 | out.close(); |
| 86 | |
| 87 | System.out.println("Settings written: " + rootFile.toString()); |
| 88 | } |
| 89 | } |