summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2012-11-25 08:05:59 -0500
committerDvTonder <david.vantonder@gmail.com>2012-11-25 08:05:59 -0500
commit2f0ded7678df235b850339cefff1bb10021690c7 (patch)
treeb665832c4bde16cd71fbdf0dbc7314691fe9af2e
parent31d93bf306ceb46b4f6cfdc86c0497a4a2565123 (diff)
downloadpackages_apps_settings-2f0ded7678df235b850339cefff1bb10021690c7.zip
packages_apps_settings-2f0ded7678df235b850339cefff1bb10021690c7.tar.gz
packages_apps_settings-2f0ded7678df235b850339cefff1bb10021690c7.tar.bz2
Settings: Forward port Performance settings
Change-Id: Ib510b35fc2763c6942737afa33873aa5d349a173
-rw-r--r--AndroidManifest.xml89
-rw-r--r--res/drawable-hdpi/ic_settings_performance.pngbin0 -> 1343 bytes
-rw-r--r--res/drawable-mdpi/ic_settings_performance.pngbin0 -> 800 bytes
-rw-r--r--res/drawable-xhdpi/ic_settings_performance.pngbin0 -> 1719 bytes
-rw-r--r--res/values/arrays.xml27
-rw-r--r--res/values/strings.xml59
-rw-r--r--res/xml/ioscheduler_settings.xml32
-rw-r--r--res/xml/memory_management.xml40
-rw-r--r--res/xml/performance_settings.xml53
-rw-r--r--res/xml/processor_settings.xml48
-rw-r--r--res/xml/settings_headers.xml7
-rw-r--r--src/com/android/settings/Utils.java43
-rw-r--r--src/com/android/settings/cyanogenmod/BootReceiver.java143
-rw-r--r--src/com/android/settings/cyanogenmod/IOScheduler.java124
-rw-r--r--src/com/android/settings/cyanogenmod/MemoryManagement.java137
-rw-r--r--src/com/android/settings/cyanogenmod/PerformanceSettings.java113
-rw-r--r--src/com/android/settings/cyanogenmod/Processor.java247
17 files changed, 1121 insertions, 41 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 688facc..f55d7d3 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -61,6 +61,7 @@
<uses-permission android:name="android.permission.MANAGE_USERS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="@string/settings_label"
android:icon="@mipmap/ic_launcher_settings"
@@ -138,14 +139,6 @@
android:resource="@id/wifi_settings" />
</activity>
- <activity android:name="Settings$AnonymousStatsActivity"
- android:label="@string/anonymous_statistics_title"
- android:configChanges="orientation|keyboardHidden|screenSize"
- android:clearTaskOnLaunch="true">
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.cmstats.AnonymousStats" />
- </activity>
-
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name=".wifi.WifiSettings"
android:taskAffinity="com.android.settings"
@@ -1459,37 +1452,13 @@
android:theme="@style/CryptKeeperBlankTheme"
/>
- <!-- Pseudo-activity used to provide an intent-filter entry point to encryption settings -->
- <activity android:name="Settings$CryptKeeperSettingsActivity"
- android:label="@string/crypt_keeper_encrypt_title">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <action android:name="android.app.action.START_ENCRYPTION" />
- <category android:name="android.intent.category.DEFAULT" /> />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.CryptKeeperSettings" />
- <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
- android:resource="@id/security_settings" />
- </activity>
+ <!-- CyanogenMod activities Start -->
+ <activity android:name=".cyanogenmod.PowerWidget" />
- <activity android:name="Settings$DataUsageSummaryActivity"
- android:label="@string/data_usage_summary_title"
- android:uiOptions="none"
- android:taskAffinity=""
- android:excludeFromRecents="true">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.DataUsageSummary" />
- <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
- android:resource="@id/wireless_settings" />
- </activity>
+ <activity android:name=".cyanogenmod.SystemSettings" />
+
+ <activity android:name=".cyanogenmod.PerformanceSettings" />
- <!-- CyanogenMod activities Start -->
<activity android:name=".profiles.ProfilesSettings" />
<activity android:name=".profiles.ProfileConfig" />
@@ -1519,9 +1488,13 @@
<activity android:name=".notificationlight.BatteryLightSettings" />
- <activity android:name=".cyanogenmod.SystemSettings" />
-
- <activity android:name=".cyanogenmod.PowerWidget" />
+ <activity android:name="Settings$AnonymousStatsActivity"
+ android:label="@string/anonymous_statistics_title"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:clearTaskOnLaunch="true">
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.cmstats.AnonymousStats" />
+ </activity>
<activity android:name=".cyanogenmod.ChangeLog" android:label="@string/changelog_title">
<intent-filter>
@@ -1531,6 +1504,36 @@
<!-- CyanogenMod activities End -->
+ <!-- Pseudo-activity used to provide an intent-filter entry point to encryption settings -->
+ <activity android:name="Settings$CryptKeeperSettingsActivity"
+ android:label="@string/crypt_keeper_encrypt_title">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <action android:name="android.app.action.START_ENCRYPTION" />
+ <category android:name="android.intent.category.DEFAULT" /> />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.CryptKeeperSettings" />
+ <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
+ android:resource="@id/security_settings" />
+ </activity>
+
+ <activity android:name="Settings$DataUsageSummaryActivity"
+ android:label="@string/data_usage_summary_title"
+ android:uiOptions="none"
+ android:taskAffinity=""
+ android:excludeFromRecents="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="com.android.settings.SHORTCUT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.DataUsageSummary" />
+ <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
+ android:resource="@id/wireless_settings" />
+ </activity>
+
<receiver android:name=".widget.SettingsAppWidgetProvider"
android:label="@string/gadget_title"
android:exported="true"
@@ -1554,6 +1557,12 @@
</intent-filter>
</receiver>
+ <receiver android:name=".cyanogenmod.BootReceiver" android:enabled="true">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+ </receiver>
+
<!-- Watch for ContactsContract.Profile changes and update the user's photo. -->
<receiver android:name=".users.ProfileUpdateReceiver">
<intent-filter>
diff --git a/res/drawable-hdpi/ic_settings_performance.png b/res/drawable-hdpi/ic_settings_performance.png
new file mode 100644
index 0000000..d569419
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_performance.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_performance.png b/res/drawable-mdpi/ic_settings_performance.png
new file mode 100644
index 0000000..a97d54e
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_performance.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_settings_performance.png b/res/drawable-xhdpi/ic_settings_performance.png
new file mode 100644
index 0000000..aa61cf5
--- /dev/null
+++ b/res/drawable-xhdpi/ic_settings_performance.png
Binary files differ
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 6a7da58..65a8f7f 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -820,6 +820,33 @@
<item>3</item>
</string-array>
+ <!-- Performance settings -->
+ <string-array name="pref_zram_size_entries">
+ <item>Disabled</item>
+ <item>10%</item>
+ <item>18% (default)</item>
+ <item>26%</item>
+ </string-array>
+
+ <string-array name="pref_zram_size_values" translatable="false">
+ <item>0</item>
+ <item>10</item>
+ <item>18</item>
+ <item>26</item>
+ </string-array>
+
+ <string-array name="dithering_entries" translatable="false">
+ <item>@string/dithering_no_dither</item>
+ <item>@string/dithering_color_banding</item>
+ <item>@string/dithering_blur_effect</item>
+ </string-array>
+
+ <string-array name="dithering_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
+
<!-- Profile mode options. -->
<string-array name="profile_entries">
<item>On</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ad64a91..da65ba2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4612,6 +4612,64 @@
<string name="toggleLockScreen">Lock Screen</string>
<string name="toggleWimax">WiMAX</string>
+ <!-- Performance settings -->
+ <string name="performance_settings_title">Performance</string>
+
+ <!-- Performance Settings : Warning dialog -->
+ <string name="performance_settings_warning_title">Proceed with Caution</string>
+ <string name="performance_settings_warning">These settings are included for experimentation and any changes made to them have the potential to cause instability, crashes, data loss or hardware failures.\n\nWe request you do not file bug reports if any of these settings have been changed from the defaults.</string>
+
+ <!-- Performance Settings : Processor Settings -->
+ <!-- Performance Settings : Processor settings title -->
+ <string name="processor_title">Processor</string>
+ <!-- Performance Settings : Processor settings summary. -->
+ <string name="processor_summary">Change CPU governor and clock speed</string>
+
+ <!-- Performance Settings : Processor settings sub items -->
+ <string name="cpu_cur_freq_title">Current CPU frequency</string>
+ <string name="cpu_governors_title">CPU governor</string>
+ <string name="cpu_governors_summary">%S</string>
+ <string name="cpu_min_freq_title">Minimum CPU frequency</string>
+ <string name="cpu_min_freq_summary">%s</string>
+ <string name="cpu_max_freq_title">Maximum CPU frequency</string>
+ <string name="cpu_max_freq_summary">%s</string>
+ <string name="cpu_set_on_boot">Set on boot</string>
+ <string name="cpu_set_on_boot_summary">Restore the processor settings on boot</string>
+
+ <!-- Performance Settings : I/O scheduler settings title -->
+ <string name="io_scheds_title">I/O scheduler</string>
+ <!-- Performance Settings : I/O scheduler settings summary. -->
+ <string name="io_scheds_summary">Change I/O scheduler</string>
+
+ <!-- Performance Settings : I/O scheduler settings sub items -->
+ <string name="io_sched_title">I/O scheduler</string>
+ <string name="io_sched_summary">%S</string>
+ <string name="io_sched_set_on_boot">Set on boot</string>
+ <string name="io_sched_set_on_boot_summary">Restore the I/O scheduler settings on boot</string>
+
+ <!-- Memory Management -->
+ <string name="memory_management_title">Memory management</string>
+ <string name="memory_management_summary">Customize the usage of memory to alter system performance</string>
+ <!-- zRam -->
+ <string name="pref_zram_title">zRam</string>
+ <string name="pref_zram_summary">Compress memory for increased virtual capacity (requires reboot)</string>
+ <!-- KSM -->
+ <string name="pref_ksm_title">Kernel samepage merging</string>
+ <string name="pref_ksm_summary">KSM reduces physical memory requirements and improves performance</string>
+ <!-- Purgeable Assets -->
+ <string name="pref_purgeable_assets_title">Allow purging of assets</string>
+ <string name="pref_purgeable_assets_summary">Purging of bitmap memory assets allows the freeing of more RAM when needed (requires reboot)</string>
+
+ <!-- Performance Settings : Dithering -->
+ <string name="pref_use_dithering_title">Surface improvement</string>
+ <string name="dithering_no_dither">Disable dithering</string>
+ <string name="dithering_color_banding">Fix color banding (default)</string>
+ <string name="dithering_blur_effect">Fix color banding and blur effect</string>
+
+ <!-- Performance Settings : 16bpp Alpha -->
+ <string name="pref_use_16bpp_alpha_title">16bit transparency</string>
+ <string name="pref_use_16bpp_alpha_summary">Better graphics performance, but lower quality and may cause visual artifacts (requires reboot)</string>
+
<string name="increasing_ring_title">Ascending ringtone</string>
<!-- Sound settings screen, the caption of the checkbox for making incoming calls increase in volume -->
<string name="checkbox_increasing_ring">Enable</string>
@@ -4690,7 +4748,6 @@
<string name="silent_mode_title">Silent mode</string>
<string name="volume_ring_only_description">Ringtone</string>
-
<!-- Power Widget -->
<string name="power_widget_title">Power widget</string>
<string name="title_expanded_widget">Power widget</string>
diff --git a/res/xml/ioscheduler_settings.xml b/res/xml/ioscheduler_settings.xml
new file mode 100644
index 0000000..e8eb267
--- /dev/null
+++ b/res/xml/ioscheduler_settings.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/io_scheds_title"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <ListPreference
+ android:key="pref_io_sched"
+ android:dialogTitle="@string/io_sched_title"
+ android:title="@string/io_sched_title" />
+
+ <CheckBoxPreference
+ android:key="pref_io_sched_set_on_boot"
+ android:title="@string/io_sched_set_on_boot"
+ android:summary="@string/io_sched_set_on_boot_summary"/>
+
+</PreferenceScreen>
diff --git a/res/xml/memory_management.xml b/res/xml/memory_management.xml
new file mode 100644
index 0000000..187c815
--- /dev/null
+++ b/res/xml/memory_management.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/memory_management_title"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <ListPreference
+ android:key="pref_zram_size"
+ android:dialogTitle="@string/pref_zram_title"
+ android:title="@string/pref_zram_title"
+ android:summary="@string/pref_zram_summary"
+ android:entries="@array/pref_zram_size_entries"
+ android:entryValues="@array/pref_zram_size_values" />
+
+ <CheckBoxPreference
+ android:key="pref_purgeable_assets"
+ android:title="@string/pref_purgeable_assets_title"
+ android:summary="@string/pref_purgeable_assets_summary" />
+
+ <CheckBoxPreference
+ android:key="pref_ksm"
+ android:title="@string/pref_ksm_title"
+ android:summary="@string/pref_ksm_summary" />
+
+</PreferenceScreen>
diff --git a/res/xml/performance_settings.xml b/res/xml/performance_settings.xml
new file mode 100644
index 0000000..8644a70
--- /dev/null
+++ b/res/xml/performance_settings.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/performance_settings_title"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <PreferenceScreen
+ android:key="processor"
+ android:fragment="com.android.settings.cyanogenmod.Processor"
+ android:title="@string/processor_title"
+ android:summary="@string/processor_summary" />
+
+ <PreferenceScreen
+ android:key="ioscheduler"
+ android:fragment="com.android.settings.cyanogenmod.IOScheduler"
+ android:title="@string/io_scheds_title"
+ android:summary="@string/io_scheds_summary" />
+
+ <PreferenceScreen
+ android:key="memory_management"
+ android:fragment="com.android.settings.cyanogenmod.MemoryManagement"
+ android:title="@string/memory_management_title"
+ android:summary="@string/memory_management_summary" />
+
+ <CheckBoxPreference
+ android:key="pref_use_16bpp_alpha"
+ android:title="@string/pref_use_16bpp_alpha_title"
+ android:summary="@string/pref_use_16bpp_alpha_summary" />
+
+ <ListPreference
+ android:key="pref_use_dithering"
+ android:persistent="false"
+ android:dialogTitle="@string/pref_use_dithering_title"
+ android:title="@string/pref_use_dithering_title"
+ android:entries="@array/dithering_entries"
+ android:entryValues="@array/dithering_values"/>
+
+</PreferenceScreen>
diff --git a/res/xml/processor_settings.xml b/res/xml/processor_settings.xml
new file mode 100644
index 0000000..7d0b0ee
--- /dev/null
+++ b/res/xml/processor_settings.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/processor_title"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <Preference
+ android:key="pref_cpu_freq_cur"
+ style="?android:preferenceInformationStyle"
+ android:title="@string/cpu_cur_freq_title"
+ android:selectable="false" />
+
+ <ListPreference
+ android:key="pref_cpu_gov"
+ android:dialogTitle="@string/cpu_governors_title"
+ android:title="@string/cpu_governors_title" />
+
+ <ListPreference
+ android:key="pref_cpu_freq_min"
+ android:dialogTitle="@string/cpu_min_freq_title"
+ android:title="@string/cpu_min_freq_title" />
+
+ <ListPreference
+ android:key="pref_cpu_freq_max"
+ android:dialogTitle="@string/cpu_max_freq_title"
+ android:title="@string/cpu_max_freq_title" />
+
+ <CheckBoxPreference
+ android:key="pref_cpu_set_on_boot"
+ android:title="@string/cpu_set_on_boot"
+ android:summary="@string/cpu_set_on_boot_summary"/>
+
+</PreferenceScreen>
diff --git a/res/xml/settings_headers.xml b/res/xml/settings_headers.xml
index 821aa9d..05cc2be 100644
--- a/res/xml/settings_headers.xml
+++ b/res/xml/settings_headers.xml
@@ -226,6 +226,13 @@
android:icon="@drawable/ic_settings_development"
android:title="@string/development_settings_title" />
+ <!-- Performance -->
+ <header
+ android:id="@+id/performance_settings"
+ android:fragment="com.android.settings.cyanogenmod.PerformanceSettings"
+ android:icon="@drawable/ic_settings_performance"
+ android:title="@string/performance_settings_title" />
+
<!-- About Device -->
<header
android:id="@+id/about_settings"
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 29dcbf4..dcd37d1 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -67,6 +67,10 @@ import android.widget.TabWidget;
import com.android.settings.users.ProfileUpdateReceiver;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -77,6 +81,8 @@ import java.util.Locale;
public class Utils {
+ private static final String TAG = "Utils";
+
/**
* Set the preference's title to the matching activity's label.
*/
@@ -482,6 +488,43 @@ public class Utils {
}
}
+ public static boolean fileExists(String filename) {
+ return new File(filename).exists();
+ }
+
+ public static String fileReadOneLine(String fname) {
+ BufferedReader br;
+ String line = null;
+
+ try {
+ br = new BufferedReader(new FileReader(fname), 512);
+ try {
+ line = br.readLine();
+ } finally {
+ br.close();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "IO Exception when reading /sys/ file", e);
+ }
+ return line;
+ }
+
+ public static boolean fileWriteOneLine(String fname, String value) {
+ try {
+ FileWriter fw = new FileWriter(fname);
+ try {
+ fw.write(value);
+ } finally {
+ fw.close();
+ }
+ } catch (IOException e) {
+ String Error = "Error writing to " + fname + ". Exception: ";
+ Log.e(TAG, Error, e);
+ return false;
+ }
+ return true;
+ }
+
/* Used by UserSettings as well. Call this on a non-ui thread. */
public static boolean copyMeProfilePhoto(Context context, UserInfo user) {
Uri contactUri = Profile.CONTENT_URI;
diff --git a/src/com/android/settings/cyanogenmod/BootReceiver.java b/src/com/android/settings/cyanogenmod/BootReceiver.java
new file mode 100644
index 0000000..0704a66
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/BootReceiver.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.cyanogenmod;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.SystemProperties;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+import com.android.settings.Utils;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class BootReceiver extends BroadcastReceiver {
+
+ private static final String TAG = "BootReceiver";
+
+ private static final String CPU_SETTINGS_PROP = "sys.cpufreq.restored";
+ private static final String IOSCHED_SETTINGS_PROP = "sys.iosched.restored";
+ private static final String KSM_SETTINGS_PROP = "sys.ksm.restored";
+
+ @Override
+ public void onReceive(Context ctx, Intent intent) {
+ if (SystemProperties.getBoolean(CPU_SETTINGS_PROP, false) == false
+ && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ SystemProperties.set(CPU_SETTINGS_PROP, "true");
+ configureCPU(ctx);
+ } else {
+ SystemProperties.set(CPU_SETTINGS_PROP, "false");
+ }
+
+ if (SystemProperties.getBoolean(IOSCHED_SETTINGS_PROP, false) == false
+ && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ SystemProperties.set(IOSCHED_SETTINGS_PROP, "true");
+ configureIOSched(ctx);
+ } else {
+ SystemProperties.set(IOSCHED_SETTINGS_PROP, "false");
+ }
+
+ if (Utils.fileExists(MemoryManagement.KSM_RUN_FILE)) {
+ if (SystemProperties.getBoolean(KSM_SETTINGS_PROP, false) == false
+ && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
+ SystemProperties.set(KSM_SETTINGS_PROP, "true");
+ configureKSM(ctx);
+ } else {
+ SystemProperties.set(KSM_SETTINGS_PROP, "false");
+ }
+ }
+ }
+
+ private void configureCPU(Context ctx) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
+
+ if (prefs.getBoolean(Processor.SOB_PREF, false) == false) {
+ Log.i(TAG, "Restore disabled by user preference.");
+ return;
+ }
+
+ String governor = prefs.getString(Processor.GOV_PREF, null);
+ String minFrequency = prefs.getString(Processor.FREQ_MIN_PREF, null);
+ String maxFrequency = prefs.getString(Processor.FREQ_MAX_PREF, null);
+ String availableFrequenciesLine = Utils.fileReadOneLine(Processor.FREQ_LIST_FILE);
+ String availableGovernorsLine = Utils.fileReadOneLine(Processor.GOV_LIST_FILE);
+ boolean noSettings = ((availableGovernorsLine == null) || (governor == null)) &&
+ ((availableFrequenciesLine == null) || ((minFrequency == null) && (maxFrequency == null)));
+ List<String> frequencies = null;
+ List<String> governors = null;
+
+ if (noSettings) {
+ Log.d(TAG, "No CPU settings saved. Nothing to restore.");
+ } else {
+ if (availableGovernorsLine != null){
+ governors = Arrays.asList(availableGovernorsLine.split(" "));
+ }
+ if (availableFrequenciesLine != null){
+ frequencies = Arrays.asList(availableFrequenciesLine.split(" "));
+ }
+ if (governor != null && governors != null && governors.contains(governor)) {
+ Utils.fileWriteOneLine(Processor.GOV_FILE, governor);
+ }
+ if (maxFrequency != null && frequencies != null && frequencies.contains(maxFrequency)) {
+ Utils.fileWriteOneLine(Processor.FREQ_MAX_FILE, maxFrequency);
+ }
+ if (minFrequency != null && frequencies != null && frequencies.contains(minFrequency)) {
+ Utils.fileWriteOneLine(Processor.FREQ_MIN_FILE, minFrequency);
+ }
+ Log.d(TAG, "CPU settings restored.");
+ }
+ }
+
+ private void configureIOSched(Context ctx) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
+
+ if (prefs.getBoolean(IOScheduler.SOB_PREF, false) == false) {
+ Log.i(TAG, "Restore disabled by user preference.");
+ return;
+ }
+
+ String ioscheduler = prefs.getString(IOScheduler.IOSCHED_PREF, null);
+ String availableIOSchedulersLine = Utils.fileReadOneLine(IOScheduler.IOSCHED_LIST_FILE);
+ boolean noSettings = ((availableIOSchedulersLine == null) || (ioscheduler == null));
+ List<String> ioschedulers = null;
+
+ if (noSettings) {
+ Log.d(TAG, "No I/O scheduler settings saved. Nothing to restore.");
+ } else {
+ if (availableIOSchedulersLine != null){
+ ioschedulers = Arrays.asList(availableIOSchedulersLine.replace("[", "").replace("]", "").split(" "));
+ }
+ if (ioscheduler != null && ioschedulers != null && ioschedulers.contains(ioscheduler)) {
+ Utils.fileWriteOneLine(IOScheduler.IOSCHED_LIST_FILE, ioscheduler);
+ }
+ Log.d(TAG, "I/O scheduler settings restored.");
+ }
+ }
+
+ private void configureKSM(Context ctx) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
+
+ boolean ksm = prefs.getBoolean(MemoryManagement.KSM_PREF, false);
+
+ Utils.fileWriteOneLine(MemoryManagement.KSM_RUN_FILE, ksm ? "1" : "0");
+ Log.d(TAG, "KSM settings restored.");
+ }
+}
diff --git a/src/com/android/settings/cyanogenmod/IOScheduler.java b/src/com/android/settings/cyanogenmod/IOScheduler.java
new file mode 100644
index 0000000..68142c5
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/IOScheduler.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.cyanogenmod;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+//
+// I/O Scheduler Related Settings
+//
+public class IOScheduler extends SettingsPreferenceFragment implements
+ Preference.OnPreferenceChangeListener {
+
+ public static final String IOSCHED_PREF = "pref_io_sched";
+ public static final String IOSCHED_LIST_FILE = "/sys/block/mmcblk0/queue/scheduler";
+
+ public static final String SOB_PREF = "pref_io_sched_set_on_boot";
+
+ private static final String TAG = "IOScheduler";
+
+ private String mIOSchedulerFormat;
+
+ private ListPreference mIOSchedulerPref;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mIOSchedulerFormat = getString(R.string.io_sched_summary);
+
+ String[] availableIOSchedulers = new String[0];
+ String availableIOSchedulersLine;
+ int bropen, brclose;
+ String currentIOScheduler = null;
+
+ addPreferencesFromResource(R.xml.ioscheduler_settings);
+
+ PreferenceScreen prefScreen = getPreferenceScreen();
+
+ mIOSchedulerPref = (ListPreference) prefScreen.findPreference(IOSCHED_PREF);
+
+ /* I/O scheduler
+ Some systems might not use I/O schedulers */
+ if (!Utils.fileExists(IOSCHED_LIST_FILE) ||
+ (availableIOSchedulersLine = Utils.fileReadOneLine(IOSCHED_LIST_FILE)) == null) {
+ prefScreen.removePreference(mIOSchedulerPref);
+
+ } else {
+ availableIOSchedulers = availableIOSchedulersLine.replace("[", "").replace("]", "").split(" ");
+ bropen = availableIOSchedulersLine.indexOf("[");
+ brclose = availableIOSchedulersLine.lastIndexOf("]");
+ if (bropen >= 0 && brclose >= 0)
+ currentIOScheduler = availableIOSchedulersLine.substring(bropen + 1, brclose);
+
+ mIOSchedulerPref.setEntryValues(availableIOSchedulers);
+ mIOSchedulerPref.setEntries(availableIOSchedulers);
+ if (currentIOScheduler != null)
+ mIOSchedulerPref.setValue(currentIOScheduler);
+ mIOSchedulerPref.setSummary(String.format(mIOSchedulerFormat, currentIOScheduler));
+ mIOSchedulerPref.setOnPreferenceChangeListener(this);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ String availableIOSchedulersLine;
+ int bropen, brclose;
+ String currentIOScheduler;
+
+ super.onResume();
+
+ if (Utils.fileExists(IOSCHED_LIST_FILE) &&
+ (availableIOSchedulersLine = Utils.fileReadOneLine(IOSCHED_LIST_FILE)) != null) {
+ bropen = availableIOSchedulersLine.indexOf("[");
+ brclose = availableIOSchedulersLine.lastIndexOf("]");
+ if (bropen >= 0 && brclose >= 0) {
+ currentIOScheduler = availableIOSchedulersLine.substring(bropen + 1, brclose);
+ mIOSchedulerPref.setSummary(String.format(mIOSchedulerFormat, currentIOScheduler));
+ }
+ }
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String fname = "";
+
+ if (newValue != null) {
+ if (preference == mIOSchedulerPref) {
+ fname = IOSCHED_LIST_FILE;
+ }
+
+ if (Utils.fileWriteOneLine(fname, (String) newValue)) {
+ if (preference == mIOSchedulerPref) {
+ mIOSchedulerPref.setSummary(String.format(mIOSchedulerFormat, (String) newValue));
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/com/android/settings/cyanogenmod/MemoryManagement.java b/src/com/android/settings/cyanogenmod/MemoryManagement.java
new file mode 100644
index 0000000..8626b06
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/MemoryManagement.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.cyanogenmod;
+
+import java.io.File;
+
+import android.os.Bundle;
+import android.os.SystemProperties;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+public class MemoryManagement extends SettingsPreferenceFragment implements
+ OnPreferenceChangeListener {
+
+ public static final String KSM_RUN_FILE = "/sys/kernel/mm/ksm/run";
+
+ public static final String KSM_PREF = "pref_ksm";
+
+ public static final String KSM_PREF_DISABLED = "0";
+
+ public static final String KSM_PREF_ENABLED = "1";
+
+ private static final String ZRAM_PREF = "pref_zram_size";
+
+ private static final String ZRAM_PERSIST_PROP = "persist.service.zram"; // was compcache
+
+ private static final String ZRAM_DEFAULT = SystemProperties.get("ro.zram.default"); // was compcache
+
+ private static final String PURGEABLE_ASSETS_PREF = "pref_purgeable_assets";
+
+ private static final String PURGEABLE_ASSETS_PERSIST_PROP = "persist.sys.purgeable_assets";
+
+ private static final String PURGEABLE_ASSETS_DEFAULT = "0";
+
+ private ListPreference mzRAM;
+
+ private CheckBoxPreference mPurgeableAssetsPref;
+
+ private CheckBoxPreference mKSMPref;
+
+ private int swapAvailable = -1;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getPreferenceManager() != null) {
+
+ addPreferencesFromResource(R.xml.memory_management);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+
+ mzRAM = (ListPreference) prefSet.findPreference(ZRAM_PREF);
+ mPurgeableAssetsPref = (CheckBoxPreference) prefSet.findPreference(PURGEABLE_ASSETS_PREF);
+ mKSMPref = (CheckBoxPreference) prefSet.findPreference(KSM_PREF);
+
+ if (isSwapAvailable()) {
+ if (SystemProperties.get(ZRAM_PERSIST_PROP) == "1")
+ SystemProperties.set(ZRAM_PERSIST_PROP, ZRAM_DEFAULT);
+ mzRAM.setValue(SystemProperties.get(ZRAM_PERSIST_PROP, ZRAM_DEFAULT));
+ mzRAM.setOnPreferenceChangeListener(this);
+ } else {
+ prefSet.removePreference(mzRAM);
+ }
+
+ if (Utils.fileExists(KSM_RUN_FILE)) {
+ mKSMPref.setChecked(KSM_PREF_ENABLED.equals(Utils.fileReadOneLine(KSM_RUN_FILE)));
+ } else {
+ prefSet.removePreference(mKSMPref);
+ }
+
+ String purgeableAssets = SystemProperties.get(PURGEABLE_ASSETS_PERSIST_PROP,
+ PURGEABLE_ASSETS_DEFAULT);
+ mPurgeableAssetsPref.setChecked("1".equals(purgeableAssets));
+
+ }
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+
+ if (preference == mPurgeableAssetsPref) {
+ SystemProperties.set(PURGEABLE_ASSETS_PERSIST_PROP,
+ mPurgeableAssetsPref.isChecked() ? "1" : "0");
+ return true;
+ }
+
+ if (preference == mKSMPref) {
+ Utils.fileWriteOneLine(KSM_RUN_FILE, mKSMPref.isChecked() ? "1" : "0");
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mzRAM) {
+ if (newValue != null) {
+ SystemProperties.set(ZRAM_PERSIST_PROP, (String) newValue);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Check if swap support is available on the system
+ */
+ private boolean isSwapAvailable() {
+ if (swapAvailable < 0) {
+ swapAvailable = new File("/proc/swaps").exists() ? 1 : 0;
+ }
+ return swapAvailable > 0;
+ }
+}
diff --git a/src/com/android/settings/cyanogenmod/PerformanceSettings.java b/src/com/android/settings/cyanogenmod/PerformanceSettings.java
new file mode 100644
index 0000000..0c100e5
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/PerformanceSettings.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.cyanogenmod;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.SystemProperties;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.ListPreference;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+/**
+ * Performance Settings
+ */
+public class PerformanceSettings extends SettingsPreferenceFragment
+ implements Preference.OnPreferenceChangeListener {
+ private static final String TAG = "PerformanceSettings";
+
+ private static final String USE_DITHERING_PREF = "pref_use_dithering";
+
+ private static final String USE_DITHERING_PERSIST_PROP = "persist.sys.use_dithering";
+
+ private static final String USE_DITHERING_DEFAULT = "1";
+
+ private static final String USE_16BPP_ALPHA_PREF = "pref_use_16bpp_alpha";
+
+ private static final String USE_16BPP_ALPHA_PROP = "persist.sys.use_16bpp_alpha";
+
+ private ListPreference mUseDitheringPref;
+
+ private CheckBoxPreference mUse16bppAlphaPref;
+
+ private AlertDialog alertDialog;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getPreferenceManager() != null) {
+
+ addPreferencesFromResource(R.xml.performance_settings);
+
+ PreferenceScreen prefSet = getPreferenceScreen();
+
+ String useDithering = SystemProperties.get(USE_DITHERING_PERSIST_PROP, USE_DITHERING_DEFAULT);
+ mUseDitheringPref = (ListPreference) prefSet.findPreference(USE_DITHERING_PREF);
+ mUseDitheringPref.setOnPreferenceChangeListener(this);
+ mUseDitheringPref.setValue(useDithering);
+ mUseDitheringPref.setSummary(mUseDitheringPref.getEntry());
+
+ mUse16bppAlphaPref = (CheckBoxPreference) prefSet.findPreference(USE_16BPP_ALPHA_PREF);
+ String use16bppAlpha = SystemProperties.get(USE_16BPP_ALPHA_PROP, "0");
+ mUse16bppAlphaPref.setChecked("1".equals(use16bppAlpha));
+
+ /* Display the warning dialog */
+ alertDialog = new AlertDialog.Builder(getActivity()).create();
+ alertDialog.setTitle(R.string.performance_settings_warning_title);
+ alertDialog.setMessage(getResources().getString(R.string.performance_settings_warning));
+ alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
+ getResources().getString(com.android.internal.R.string.ok),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ return;
+ }
+ });
+
+ alertDialog.show();
+ }
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ if (preference == mUse16bppAlphaPref) {
+ SystemProperties.set(USE_16BPP_ALPHA_PROP,
+ mUse16bppAlphaPref.isChecked() ? "1" : "0");
+ } else {
+ // If we didn't handle it, let preferences handle it.
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+
+ return true;
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mUseDitheringPref) {
+ String newVal = (String) newValue;
+ int index = mUseDitheringPref.findIndexOfValue(newVal);
+ SystemProperties.set(USE_DITHERING_PERSIST_PROP, newVal);
+ mUseDitheringPref.setSummary(mUseDitheringPref.getEntries()[index]);
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/android/settings/cyanogenmod/Processor.java b/src/com/android/settings/cyanogenmod/Processor.java
new file mode 100644
index 0000000..ce2c404
--- /dev/null
+++ b/src/com/android/settings/cyanogenmod/Processor.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2012 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.cyanogenmod;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+//
+// CPU Related Settings
+//
+public class Processor extends SettingsPreferenceFragment implements
+ Preference.OnPreferenceChangeListener {
+
+ public static final String FREQ_CUR_PREF = "pref_cpu_freq_cur";
+ public static final String SCALE_CUR_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq";
+ public static final String FREQINFO_CUR_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq";
+ private static String FREQ_CUR_FILE = SCALE_CUR_FILE;
+ public static final String GOV_PREF = "pref_cpu_gov";
+ public static final String GOV_LIST_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors";
+ public static final String GOV_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor";
+ public static final String FREQ_MIN_PREF = "pref_cpu_freq_min";
+ public static final String FREQ_MAX_PREF = "pref_cpu_freq_max";
+ public static final String FREQ_LIST_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies";
+ public static final String FREQ_MAX_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq";
+ public static final String FREQ_MIN_FILE = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq";
+ public static final String SOB_PREF = "pref_cpu_set_on_boot";
+
+ private static final String TAG = "CPUSettings";
+
+ private String mGovernorFormat;
+ private String mMinFrequencyFormat;
+ private String mMaxFrequencyFormat;
+
+ private Preference mCurFrequencyPref;
+ private ListPreference mGovernorPref;
+ private ListPreference mMinFrequencyPref;
+ private ListPreference mMaxFrequencyPref;
+
+ private class CurCPUThread extends Thread {
+ private boolean mInterrupt = false;
+
+ public void interrupt() {
+ mInterrupt = true;
+ }
+
+ @Override
+ public void run() {
+ try {
+ while (!mInterrupt) {
+ sleep(500);
+ final String curFreq = Utils.fileReadOneLine(FREQ_CUR_FILE);
+ if (curFreq != null)
+ mCurCPUHandler.sendMessage(mCurCPUHandler.obtainMessage(0, curFreq));
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+ };
+
+ private CurCPUThread mCurCPUThread = new CurCPUThread();
+
+ private Handler mCurCPUHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ mCurFrequencyPref.setSummary(toMHz((String) msg.obj));
+ }
+ };
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mGovernorFormat = getString(R.string.cpu_governors_summary);
+ mMinFrequencyFormat = getString(R.string.cpu_min_freq_summary);
+ mMaxFrequencyFormat = getString(R.string.cpu_max_freq_summary);
+
+ String[] availableFrequencies = new String[0];
+ String[] availableGovernors = new String[0];
+ String[] frequencies;
+ String availableGovernorsLine;
+ String availableFrequenciesLine;
+ String temp;
+
+ addPreferencesFromResource(R.xml.processor_settings);
+
+ PreferenceScreen prefScreen = getPreferenceScreen();
+
+ mGovernorPref = (ListPreference) prefScreen.findPreference(GOV_PREF);
+ mCurFrequencyPref = (Preference) prefScreen.findPreference(FREQ_CUR_PREF);
+ mMinFrequencyPref = (ListPreference) prefScreen.findPreference(FREQ_MIN_PREF);
+ mMaxFrequencyPref = (ListPreference) prefScreen.findPreference(FREQ_MAX_PREF);
+
+ /* Governor
+ Some systems might not use governors */
+ if (!Utils.fileExists(GOV_LIST_FILE) || !Utils.fileExists(GOV_FILE) || (temp = Utils.fileReadOneLine(GOV_FILE)) == null || (availableGovernorsLine = Utils.fileReadOneLine(GOV_LIST_FILE)) == null) {
+ prefScreen.removePreference(mGovernorPref);
+
+ } else {
+ availableGovernors = availableGovernorsLine.split(" ");
+
+ mGovernorPref.setEntryValues(availableGovernors);
+ mGovernorPref.setEntries(availableGovernors);
+ mGovernorPref.setValue(temp);
+ mGovernorPref.setSummary(String.format(mGovernorFormat, temp));
+ mGovernorPref.setOnPreferenceChangeListener(this);
+ }
+
+ // Disable the min/max list if we dont have a list file
+ if (!Utils.fileExists(FREQ_LIST_FILE) || (availableFrequenciesLine = Utils.fileReadOneLine(FREQ_LIST_FILE)) == null) {
+ mMinFrequencyPref.setEnabled(false);
+ mMaxFrequencyPref.setEnabled(false);
+
+ } else {
+ availableFrequencies = availableFrequenciesLine.split(" ");
+
+ frequencies = new String[availableFrequencies.length];
+ for (int i = 0; i < frequencies.length; i++) {
+ frequencies[i] = toMHz(availableFrequencies[i]);
+ }
+
+ // Min frequency
+ if (!Utils.fileExists(FREQ_MIN_FILE) || (temp = Utils.fileReadOneLine(FREQ_MIN_FILE)) == null) {
+ mMinFrequencyPref.setEnabled(false);
+
+ } else {
+ mMinFrequencyPref.setEntryValues(availableFrequencies);
+ mMinFrequencyPref.setEntries(frequencies);
+ mMinFrequencyPref.setValue(temp);
+ mMinFrequencyPref.setSummary(String.format(mMinFrequencyFormat, toMHz(temp)));
+ mMinFrequencyPref.setOnPreferenceChangeListener(this);
+ }
+
+ // Max frequency
+ if (!Utils.fileExists(FREQ_MAX_FILE) || (temp = Utils.fileReadOneLine(FREQ_MAX_FILE)) == null) {
+ mMaxFrequencyPref.setEnabled(false);
+
+ } else {
+ mMaxFrequencyPref.setEntryValues(availableFrequencies);
+ mMaxFrequencyPref.setEntries(frequencies);
+ mMaxFrequencyPref.setValue(temp);
+ mMaxFrequencyPref.setSummary(String.format(mMaxFrequencyFormat, toMHz(temp)));
+ mMaxFrequencyPref.setOnPreferenceChangeListener(this);
+ }
+ }
+
+ // Cur frequency
+ if (!Utils.fileExists(FREQ_CUR_FILE)) {
+ FREQ_CUR_FILE = FREQINFO_CUR_FILE;
+ }
+
+ if (!Utils.fileExists(FREQ_CUR_FILE) || (temp = Utils.fileReadOneLine(FREQ_CUR_FILE)) == null) {
+ mCurFrequencyPref.setEnabled(false);
+
+ } else {
+ mCurFrequencyPref.setSummary(toMHz(temp));
+
+ mCurCPUThread.start();
+ }
+ }
+
+ @Override
+ public void onResume() {
+ String temp;
+
+ super.onResume();
+
+ if (Utils.fileExists(FREQ_MIN_FILE) && (temp = Utils.fileReadOneLine(FREQ_MIN_FILE)) != null) {
+ mMinFrequencyPref.setValue(temp);
+ mMinFrequencyPref.setSummary(String.format(mMinFrequencyFormat, toMHz(temp)));
+ }
+
+ if (Utils.fileExists(FREQ_MAX_FILE) && (temp = Utils.fileReadOneLine(FREQ_MAX_FILE)) != null) {
+ mMaxFrequencyPref.setValue(temp);
+ mMaxFrequencyPref.setSummary(String.format(mMaxFrequencyFormat, toMHz(temp)));
+ }
+
+ if (Utils.fileExists(GOV_FILE) && (temp = Utils.fileReadOneLine(GOV_FILE)) != null) {
+ mGovernorPref.setSummary(String.format(mGovernorFormat, temp));
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mCurCPUThread.interrupt();
+ try {
+ mCurCPUThread.join();
+ } catch (InterruptedException e) {
+ }
+ }
+
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String fname = "";
+
+ if (newValue != null) {
+ if (preference == mGovernorPref) {
+ fname = GOV_FILE;
+ } else if (preference == mMinFrequencyPref) {
+ fname = FREQ_MIN_FILE;
+ } else if (preference == mMaxFrequencyPref) {
+ fname = FREQ_MAX_FILE;
+ }
+
+ if (Utils.fileWriteOneLine(fname, (String) newValue)) {
+ if (preference == mGovernorPref) {
+ mGovernorPref.setSummary(String.format(mGovernorFormat, (String) newValue));
+ } else if (preference == mMinFrequencyPref) {
+ mMinFrequencyPref.setSummary(String.format(mMinFrequencyFormat,
+ toMHz((String) newValue)));
+ } else if (preference == mMaxFrequencyPref) {
+ mMaxFrequencyPref.setSummary(String.format(mMaxFrequencyFormat,
+ toMHz((String) newValue)));
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ private String toMHz(String mhzString) {
+ return new StringBuilder().append(Integer.valueOf(mhzString) / 1000).append(" MHz")
+ .toString();
+ }
+} \ No newline at end of file