Skip to content

Commit

Permalink
helper: fix null-values for settingshelper
Browse files Browse the repository at this point in the history
If the user has set cpu governor specific parameters
but not set a default governor, we would skip this part.

Since this is not intended, fix that and also refactoring
the code a bit.

Signed-off-by: Blechd0se <alex.christ@hotmail.de>
  • Loading branch information
Blechd0se committed Oct 3, 2014
1 parent 6f2ae49 commit fc9dc06
Showing 1 changed file with 98 additions and 117 deletions.
215 changes: 98 additions & 117 deletions AeroControl/src/com/aero/control/helpers/settingsHelper.java
Expand Up @@ -398,181 +398,162 @@ private void doBackground(Context context, String Profile) {
}

try {
shellPara.queueWork("sleep 1");

if (mem_ios != null) {

String completeIOSchedulerSettings[] = shellPara.getDirInfo(AeroActivity.files.GOV_IO_PARAMETER, true);
setSubParameters(mem_ios, Profile, gpu_gov);
} catch (NullPointerException e) {
Log.e("Aero", "This shouldn't happen.. Maybe a race condition. ", e);
}
}

/* IO Scheduler Specific Settings at boot */
public void executeDefault() {

for (String b : completeIOSchedulerSettings) {
String[] defaultValues = defaultProfile.toArray(new String[0]);
shell.setRootInfo(defaultValues);

final String ioSettings = prefs.getString(AeroActivity.files.GOV_IO_PARAMETER + "/" + b, null);
defaultProfile.clear();

if (ioSettings != null) {
}

shellPara.queueWork("chmod 0666 " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);
/*
* Fallback-method for getting *old* boolean values
*/
private Boolean getSaveBoolean(final String s) {

if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.GOV_IO_PARAMETER + "/" + b) + " > " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);
try {
return prefs.getString(s, "0").equals("1") ? true : false;
} catch (ClassCastException e) {
return prefs.getBoolean(s, false);
}
}

shellPara.queueWork("echo " + ioSettings + " > " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);

//Log.e("Aero", "Output: " + "echo " + ioSettings + " > " + GOV_IO_PARAMETER + "/" + b);
}
}
}
private void setSubParameters(String mem_ios, String Profile, String gpu_gov) throws NullPointerException {

final String completeVMSettings[] = shellPara.getDirInfo(AeroActivity.files.DALVIK_TWEAK, true);
shellPara.queueWork("sleep 1");
final String completeVMSettings[] = shellPara.getDirInfo(AeroActivity.files.DALVIK_TWEAK, true);
final String cpu_governor = AeroActivity.shell.getInfo(AeroActivity.files.CPU_BASE_PATH + 0 + AeroActivity.files.CURRENT_GOV_AVAILABLE);
final String completeGovernorSettingList[] = shellPara.getDirInfo(AeroActivity.files.CPU_GOV_BASE + cpu_governor, true);

/* VM specific settings at boot */

for (String c : completeVMSettings) {
if (mem_ios != null) {
String completeIOSchedulerSettings[] = shellPara.getDirInfo(AeroActivity.files.GOV_IO_PARAMETER, true);

final String vmSettings = prefs.getString(AeroActivity.files.DALVIK_TWEAK + "/" + c, null);
/* IO Scheduler Specific Settings at boot */
for (String b : completeIOSchedulerSettings) {

if (vmSettings != null) {
final String ioSettings = prefs.getString(AeroActivity.files.GOV_IO_PARAMETER + "/" + b, null);
if (ioSettings != null) {

shellPara.queueWork("chmod 0666 " + AeroActivity.files.DALVIK_TWEAK + "/" + c);
shellPara.queueWork("chmod 0666 " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);

if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.DALVIK_TWEAK + "/" + c) + " > " + AeroActivity.files.DALVIK_TWEAK + "/" + c);

shell.queueWork("echo " + vmSettings + " > " + AeroActivity.files.DALVIK_TWEAK + "/" + c);
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.GOV_IO_PARAMETER + "/" + b) + " > " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);

//Log.e("Aero", "Output: " + "echo " + vmSettings + " > " + DALVIK_TWEAK + "/" + c);
shellPara.queueWork("echo " + ioSettings + " > " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);
Log.e("Aero", "Output: " + "echo " + ioSettings + " > " + AeroActivity.files.GOV_IO_PARAMETER + "/" + b);
}
}
}

if (AeroActivity.genHelper.doesExist(AeroActivity.files.HOTPLUG_PATH)) {
final String completeHotplugSettings[] = shellPara.getDirInfo(AeroActivity.files.HOTPLUG_PATH, true);

/* Hotplug specific settings at boot */

for (String d : completeHotplugSettings) {

final String hotplugSettings = prefs.getString(AeroActivity.files.HOTPLUG_PATH + "/" + d, null);

if (hotplugSettings != null) {

shellPara.queueWork("chmod 0666 " + AeroActivity.files.HOTPLUG_PATH + "/" + d);
/* VM specific settings at boot */
for (String c : completeVMSettings) {

if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.HOTPLUG_PATH + "/" + d) + " > " + AeroActivity.files.HOTPLUG_PATH + "/" + d);
final String vmSettings = prefs.getString(AeroActivity.files.DALVIK_TWEAK + "/" + c, null);
if (vmSettings != null) {
shellPara.queueWork("chmod 0666 " + AeroActivity.files.DALVIK_TWEAK + "/" + c);

shellPara.queueWork("echo " + hotplugSettings + " > " + AeroActivity.files.HOTPLUG_PATH + "/" + d);
if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.DALVIK_TWEAK + "/" + c) + " > " + AeroActivity.files.DALVIK_TWEAK + "/" + c);

//Log.e("Aero", "Output: " + "echo " + hotplugSettings + " > " + PREF_HOTPLUG + "/" + d);
}
}
shell.queueWork("echo " + vmSettings + " > " + AeroActivity.files.DALVIK_TWEAK + "/" + c);
Log.e("Aero", "Output: " + "echo " + vmSettings + " > " + AeroActivity.files.DALVIK_TWEAK + "/" + c);
}
}

if (AeroActivity.genHelper.doesExist(AeroActivity.files.GPU_GOV_PATH)) {
final String completeGPUGovSettings[] = shellPara.getDirInfo(AeroActivity.files.GPU_GOV_PATH, true);

/* GPU Governor specific settings at boot */

for (String e : completeGPUGovSettings) {
if (AeroActivity.genHelper.doesExist(AeroActivity.files.HOTPLUG_PATH)) {
final String completeHotplugSettings[] = shellPara.getDirInfo(AeroActivity.files.HOTPLUG_PATH, true);

final String gpugovSettings = prefs.getString(AeroActivity.files.GPU_GOV_PATH + "/" + e, null);
/* Hotplug specific settings at boot */
for (String d : completeHotplugSettings) {

if (gpugovSettings != null) {
final String hotplugSettings = prefs.getString(AeroActivity.files.HOTPLUG_PATH + "/" + d, null);
if (hotplugSettings != null) {

shellPara.queueWork("chmod 0666 " + AeroActivity.files.GPU_GOV_PATH + "/" + e);
shellPara.queueWork("chmod 0666 " + AeroActivity.files.HOTPLUG_PATH + "/" + d);

if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.GPU_GOV_PATH + "/" + e) + " > " + AeroActivity.files.GPU_GOV_PATH + "/" + e);
if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.HOTPLUG_PATH + "/" + d) + " > " + AeroActivity.files.HOTPLUG_PATH + "/" + d);

shellPara.queueWork("echo " + gpugovSettings + " > " + AeroActivity.files.GPU_GOV_PATH + "/" + e);
shellPara.queueWork("echo " + hotplugSettings + " > " + AeroActivity.files.HOTPLUG_PATH + "/" + d);

//Log.e("Aero", "Output: " + "echo " + gpugovSettings + " > " + PREF_GPU_GOV + "/" + e);
}
Log.e("Aero", "Output: " + "echo " + hotplugSettings + " > " + AeroActivity.files.HOTPLUG_PATH + "/" + d);
}
}
}

if (cpu_gov != null) {

final String completeGovernorSettingList[] = shellPara.getDirInfo(AeroActivity.files.CPU_GOV_BASE + cpu_gov, true);

/* Governor Specific Settings at boot */
if (AeroActivity.genHelper.doesExist(AeroActivity.files.GPU_GOV_PATH)) {
final String completeGPUGovSettings[] = shellPara.getDirInfo(AeroActivity.files.GPU_GOV_PATH, true);

if (completeGovernorSettingList != null) {
/* GPU Governor specific settings at boot */
for (String e : completeGPUGovSettings) {
final String gpugovSettings = prefs.getString(AeroActivity.files.GPU_GOV_PATH + "/" + e, null);
if (gpugovSettings != null) {
shellPara.queueWork("chmod 0666 " + AeroActivity.files.GPU_GOV_PATH + "/" + e);

for (String b : completeGovernorSettingList) {
if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.GPU_GOV_PATH + "/" + e) + " > " + AeroActivity.files.GPU_GOV_PATH + "/" + e);

final String governorSetting = prefs.getString(AeroActivity.files.CPU_GOV_BASE + cpu_gov + "/" + b, null);
shellPara.queueWork("echo " + gpugovSettings + " > " + AeroActivity.files.GPU_GOV_PATH + "/" + e);
Log.e("Aero", "Output: " + "echo " + gpugovSettings + " > " + AeroActivity.files.GPU_GOV_PATH + "/" + e);
}
}
}

if (governorSetting != null) {
/* Governor Specific Settings at boot */

shellPara.queueWork("sleep 1");
shellPara.queueWork("chmod 0666 " + AeroActivity.files.CPU_GOV_BASE + cpu_gov + "/" + b);
if (completeGovernorSettingList != null) {

if (Profile != null) {
defaultProfile.add("sleep 1");
defaultProfile.add("echo " + shell.getInfo(AeroActivity.files.CPU_GOV_BASE + cpu_gov + "/" + b) + " > " + AeroActivity.files.CPU_GOV_BASE + cpu_gov + "/" + b);
}
for (String b : completeGovernorSettingList) {
final String governorSetting = prefs.getString(AeroActivity.files.CPU_GOV_BASE + cpu_governor + "/" + b, null);
if (governorSetting != null) {

shellPara.queueWork("echo " + governorSetting + " > " + AeroActivity.files.CPU_GOV_BASE + cpu_gov + "/" + b);
shellPara.queueWork("sleep 1");
shellPara.queueWork("chmod 0666 " + AeroActivity.files.CPU_GOV_BASE + cpu_governor + "/" + b);

//Log.e("Aero", "Output: " + "echo " + governorSetting + " > " + CPU_GOV_BASE + cpu_gov + "/" + b);
}
if (Profile != null) {
defaultProfile.add("sleep 1");
defaultProfile.add("echo " + shell.getInfo(AeroActivity.files.CPU_GOV_BASE + cpu_governor + "/" + b) + " > " + AeroActivity.files.CPU_GOV_BASE + cpu_governor + "/" + b);
}

shellPara.queueWork("echo " + governorSetting + " > " + AeroActivity.files.CPU_GOV_BASE + cpu_governor + "/" + b);
Log.e("Aero", "Output: " + "echo " + governorSetting + " > " + AeroActivity.files.CPU_GOV_BASE + cpu_governor + "/" + b);
}
}
}

/* GPU Governor Parameters */
if (gpu_gov != null) {

final String completeGPUGovernorSetting[] = shell.getDirInfo(AeroActivity.files.GPU_GOV_BASE + gpu_gov, true);

/* Governor Specific Settings at boot */

for (String b : completeGPUGovernorSetting) {

final String governorSetting = prefs.getString(AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b, null);

if (governorSetting != null) {
/* GPU Governor Parameters */
if (gpu_gov != null) {
final String completeGPUGovernorSetting[] = shell.getDirInfo(AeroActivity.files.GPU_GOV_BASE + gpu_gov, true);

shellPara.queueWork("chmod 0666 " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);
/* Governor Specific Settings at boot */
for (String b : completeGPUGovernorSetting) {
final String governorSetting = prefs.getString(AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b, null);
if (governorSetting != null) {

if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b) + " > " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);
shellPara.queueWork("chmod 0666 " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);

shellPara.queueWork("echo " + governorSetting + " > " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);
if (Profile != null)
defaultProfile.add("echo " + shellPara.getInfo(AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b) + " > " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);

Log.e("Aero", "Output: " + "echo " + governorSetting + " > " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);
}
shellPara.queueWork("echo " + governorSetting + " > " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);
Log.e("Aero", "Output: " + "echo " + governorSetting + " > " + AeroActivity.files.GPU_GOV_BASE + gpu_gov + "/" + b);
}
}

} catch (NullPointerException e) {
Log.e("Aero", "This shouldn't happen.. Maybe a race condition. ", e);
}

// EXECUTE ALL THE COMMANDS COLLECTED
shellPara.execWork();
shellPara.flushWork();
}

public void executeDefault() {

String[] defaultValues = defaultProfile.toArray(new String[0]);
shell.setRootInfo(defaultValues);

defaultProfile.clear();

}

/*
* Fallback-method for getting *old* boolean values
*/
private Boolean getSaveBoolean(final String s) {

try {
return prefs.getString(s, "0").equals("1") ? true : false;
} catch (ClassCastException e) {
return prefs.getBoolean(s, false);
}
}
}

0 comments on commit fc9dc06

Please sign in to comment.