Skip to content

Commit

Permalink
fix settings not sticking on reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
Androguide committed Mar 2, 2014
1 parent 45fc711 commit 9c0c0c4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
5 changes: 2 additions & 3 deletions PimpMyZ1/res/values-ja/strings.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 Louis Teboul (a.k.a Androguide)
admin@pimpmyrom.org || louisteboul@gmail.com
Expand All @@ -19,7 +19,6 @@
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->

<resources>
Expand Down
Expand Up @@ -21,6 +21,7 @@

package com.androguide.honamicontrol;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
Expand All @@ -38,13 +39,17 @@ public void onCreate(Bundle savedInstanceState) {

final SwitchPreference setOnBoot = (SwitchPreference) findPreference("setOnBoot");
assert setOnBoot != null;
final SharedPreferences prefs = getSharedPreferences("BOOT_PREFS", 0);
setOnBoot.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
if (setOnBoot.isChecked())
if (setOnBoot.isChecked()) {
setOnBoot.setChecked(false);
else
prefs.edit().putBoolean("SET_ON_BOOT", false).commit();
} else {
setOnBoot.setChecked(true);
prefs.edit().putBoolean("SET_ON_BOOT", true).commit();
}
return true;
}
});
Expand Down
Expand Up @@ -51,9 +51,10 @@ public static void generateScriptFromPrefs(SharedPreferences prefs) {
String core2Governor = prefs.getString("CORE2_GOVERNOR", "intellidemand");
String core3Governor = prefs.getString("CORE3_GOVERNOR", "intellidemand");
String gpuGovernor = prefs.getString("GPU_GOVERNOR", "msm-adreno-tz");
String SC_HEADPHONE_PA = prefs.getString("SC_HEADPHONE", "38 38 179");
String ioScheduler = prefs.getString("IO_SCHEDULER", "row");
String SC_MIC = prefs.getString("SC_MIC", "0 0 255");
String SC_CAM_MIC = prefs.getString("SC_CAM_MIC", "0 0 255");
String SC_HEADPHONE_PA = prefs.getString(SoundControlInterface.FAUX_SC_HEADPHONE_POWERAMP.replaceAll("/", "_"), "38 38 179");
String SC_HEADPHONE = prefs.getString(SoundControlInterface.FAUX_SC_HEADPHONE.replaceAll("/", "_"), "0 0 255");
String SC_SPEAKER = prefs.getString(SoundControlInterface.FAUX_SC_SPEAKER.replaceAll("/", "_"), "0 0 255");

Expand All @@ -66,40 +67,44 @@ public static void generateScriptFromPrefs(SharedPreferences prefs) {
String applyCore2Governor = "busybox echo " + core2Governor + " > " + CPUInterface.GOVERNOR3;
String applyCore3Governor = "busybox echo " + core3Governor + " > " + CPUInterface.GOVERNOR4;
String applyGpuGovernor = "busybox echo " + gpuGovernor + " > " + GPUInterface.currGovernor;
String applyIOScheduler = "busybox echo " + ioScheduler + " > " + CPUInterface.IO_SCHEDULER;
String applySchedMcLevel = "busybox echo " + SCHED_MC_LEVEL + " > " + PowerManagementInterface.SCHED_MC_POWER_SAVINGS;
String applyDynamicFsync = "busybox echo " + getIntFromBoolean(DYNAMIC_FSYNC) + " > " + IOTweaksInterface.DYNAMIC_FSYNC_TOGGLE;
String applyIntelliPlug = "busybox echo " + getIntFromBoolean(INTELLI_PLUG) + " > " + PowerManagementInterface.INTELLI_PLUG_TOGGLE;
String applyIntelliPlugEco = "busybox echo " + getIntFromBoolean(INTELLI_PLUG_ECO) + " > " + PowerManagementInterface.INTELLI_PLUG_ECO_MODE;
String applyPowerSuspend = "busybox echo " + getIntFromBoolean(POWER_SUSPEND) + " > " + PowerManagementInterface.POWER_SUSPEND_TOGGLE;
String applyPenMode = "busybox echo " + getIntFromBoolean(PEN_MODE) + " > " + TouchScreenInterface.PEN_MODE;
String applyGloveMode = "busybox echo " + getIntFromBoolean(GLOVE_MODE) + " > " + TouchScreenInterface.GLOVE_MODE;
String applyPenMode = "chown system:system " + TouchScreenInterface.PEN_MODE + " && busybox echo " + getIntFromBoolean(PEN_MODE) + " > " + TouchScreenInterface.PEN_MODE;
String applyGloveMode = "chown system:system " + TouchScreenInterface.PEN_MODE + " && busybox echo " + getIntFromBoolean(GLOVE_MODE) + " > " + TouchScreenInterface.GLOVE_MODE;
String applyScHeadphone = "busybox echo " + SC_HEADPHONE + " > " + SoundControlInterface.FAUX_SC_HEADPHONE;
String applyScHeadphonePa = "busybox echo " + SC_HEADPHONE_PA + " > " + SoundControlInterface.FAUX_SC_HEADPHONE_POWERAMP;
String applyScSpeaker = "busybox echo " + SC_SPEAKER + " > " + SoundControlInterface.FAUX_SC_SPEAKER;
String applyScMic = "busybox echo " + SC_MIC + " > " + SoundControlInterface.FAUX_SC_MIC;
String applyScCamMic = "busybox echo " + SC_CAM_MIC + " > " + SoundControlInterface.FAUX_SC_CAM_MIC;

Helpers.CMDProcessorWrapper.runSuCommand("" +
applyMaxCpuFreq + " && " +
applyMinCpuFreq + " && " +
applyMaxGpuFreq + " && " +
applyMinGpuFreq + " && " +
applyCore0Governor + " && " +
applyCore1Governor + " && " +
applyCore2Governor + " && " +
applyCore3Governor + " && " +
applyGpuGovernor + " && " +
applyScHeadphone + " && " +
applyScHeadphonePa + " && " +
applyScSpeaker + " && " +
applyScMic + " && " +
applyScCamMic + " && " +
applySchedMcLevel + " && " +
applyDynamicFsync + " && " +
applyIntelliPlug + " && " +
applyIntelliPlugEco + " && " +
applyPowerSuspend + " && " +
applyPenMode + " && " +
Helpers.CMDProcessorWrapper.runSuCommand(
applyMaxCpuFreq + "\n" +
applyMinCpuFreq + "\n" +
applyMaxGpuFreq + "\n" +
applyMinGpuFreq + "\n" +
applyCore0Governor + "\n" +
// applyCore1Governor + "\n" +
// applyCore2Governor + "\n" +
// applyCore3Governor + "\n" +
applyIOScheduler + "\n" +
applyGpuGovernor + "\n" +
"echo 0 > " + SoundControlInterface.FAUX_SC_LOCKED + "\n" +
applyScHeadphone + "\n" +
applyScHeadphonePa + "\n" +
applyScSpeaker + "\n" +
applyScMic + "\n" +
applyScCamMic + "\n" +
applySchedMcLevel + "\n" +
"echo 0 > " + SoundControlInterface.FAUX_SC_LOCKED + "\n" +
applyDynamicFsync + "\n" +
applyIntelliPlug + "\n" +
applyIntelliPlugEco + "\n" +
applyPowerSuspend + "\n" +
applyPenMode + "\n" +
applyGloveMode
);
}
Expand Down
Expand Up @@ -24,11 +24,14 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
BootHelper.generateScriptFromPrefs(context.getSharedPreferences("BOOT_PREFS", 0));
SharedPreferences prefs = context.getSharedPreferences("BOOT_PREFS", 0);
if (prefs.getBoolean("SET_ON_BOOT", false))
BootHelper.generateScriptFromPrefs(prefs);
}
}
Expand Up @@ -42,7 +42,7 @@

public class CardDoubleSeekBar extends Card implements SoundControlInterface {

private SharedPreferences prefs, soundPrefs;
private SharedPreferences prefs, soundPrefs, bootPrefs;
private Boolean isLinked = true;
private String location;

Expand Down Expand Up @@ -74,8 +74,9 @@ public View getCardContent(Context context) {
valueLeft.setText(seekBarProgress - 30 + unit);
valueRight.setText(seekBarProgress2 - 30 + unit);

prefs = fa.getSharedPreferences(prop.replaceAll("/", ""), 0);
prefs = fa.getSharedPreferences(prop.replaceAll("/", "_"), 0);
soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);
isLinked = soundPrefs.getBoolean("LINKED", true);

seekBarLeft.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
Expand Down Expand Up @@ -187,7 +188,7 @@ public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
);
SharedPreferences bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);
bootPrefs.edit().putString(
prop.replaceAll("/", "_"), toApplyLeft + " " + toApplyRight + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
prop.replaceAll("/", "_"), toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
).commit();
actionMode.finish();
break;
Expand Down
Expand Up @@ -76,7 +76,7 @@ public View getCardContent(Context context) {
valueLeft.setText(getSeekbarLabel(seekBarProgress) + unit);
valueRight.setText(getSeekbarLabel(seekBarProgress2) + unit);

prefs = fa.getSharedPreferences(prop.replaceAll("/", ""), 0);
prefs = fa.getSharedPreferences(prop.replaceAll("/", "_"), 0);
soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
isLinked = soundPrefs.getBoolean("LINKED", true);

Expand Down Expand Up @@ -127,6 +127,10 @@ public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
+ Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + location + " && "
+ "busybox echo 1 > " + FAUX_SC_LOCKED
);
SharedPreferences bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);
bootPrefs.edit().putString(
prop.replaceAll("/", "_"), toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
).commit();
actionMode.finish();
break;
}
Expand Down Expand Up @@ -189,7 +193,7 @@ public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
);
SharedPreferences bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);
bootPrefs.edit().putString(
"SC_HEADPHONE_PA", toApplyLeft + " " + toApplyRight + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
prop.replaceAll("/", "_"), toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
).commit();
actionMode.finish();
break;
Expand Down
Expand Up @@ -90,8 +90,6 @@ public void onPrepareOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
fa.startActivity(new Intent(fa, SettingsActivity.class));
case R.id.link_seekbars:
SharedPreferences soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
if (item.isChecked()) {
Expand Down
Expand Up @@ -119,11 +119,10 @@ public void onNothingSelected(AdapterView<?> adapterView) {
public void onCheckedChanged(CompoundButton compoundButton, boolean isOn) {
isIntelliPlugOn = isOn;
bootPrefs.edit().putBoolean("INTELLI_PLUG", isOn).commit();
if (isOn)
Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 1 > " + INTELLI_PLUG_TOGGLE);
else {
Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + INTELLI_PLUG_TOGGLE);
Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + INTELLI_PLUG_ECO_MODE);
if (isOn) {
Helpers.CMDProcessorWrapper.runSuCommand("stop mpdecision && busybox echo 1 > " + INTELLI_PLUG_TOGGLE);
} else {
Helpers.CMDProcessorWrapper.runSuCommand("start mpdecision && busybox echo 0 > " + INTELLI_PLUG_TOGGLE);
if (ecoModeSwitch != null)
ecoModeSwitch.setChecked(false);
}
Expand Down

0 comments on commit 9c0c0c4

Please sign in to comment.