Skip to content

Instantly share code, notes, and snippets.

@JBirdVegas
Created December 4, 2012 20:32
Show Gist options
  • Save JBirdVegas/4208382 to your computer and use it in GitHub Desktop.
Save JBirdVegas/4208382 to your computer and use it in GitHub Desktop.
Refactoring of VoltageControlTables com.aokp.romcontrol.performance.VoltageControlTable I just narrowed the scope of some Objects, and moved finding the location to the Class initialization. This way we don't overly expose variables used by the class in
package com.jbirdvegas.example;
import android.util.Log;
import java.io.File;
public class VoltageControlTable {
private final String TAG = getClass().getSimpleName();
private String mTable = null;
public VoltageControlTable() {
File file = null;
String[] possibleLocations = {
"UV_mV_table",
"vdd_levels",
"vdd_sysfs_levels" };
for (int i = 0; i < 3; i++) {
file = new File("/sys/devices/system/cpu/cpu0/cpufreq/" + possibleLocations[i]);
if (file.exists()) {
Log.d(TAG, "/sys/devices/system/cpu/cpu0/cpufreq/" + possibleLocations[i] + " is found and being used");
mTable = possibleLocations[i];
break;
} else {
Log.d(TAG, possibleLocations[i] + " kernel voltage implementation not found");
mTable = null;
}
}
}
/**
* added this incase we ever need to know the location
* @return the location of the voltage control directory
*/
public String getVoltageControlLocation() {
if (mTable == null) {
// meh we could return null here but thats up to you
return "no_voltage_table_found";
}
return mTable;
}
public String getTable(int tableNumber) {
if (mTable == null) {
// again we could return null here but thats up to you
return "no_voltage_table_found";
}
return "/sys/devices/system/cpu/cpu" + tableNumber + "/cpufreq/" + mTable;
}
}
@championswimmer
Copy link

we cannot return null, ROM Control FC's with that :P

@championswimmer
Copy link

and given that this was literally my first attempt to write more than 3 lines of original java code, i won't hate anyone who would help me out with better examples

so thank you a lot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment