private void fixProfiles() { SettingsStorage settings = SettingsStorage.getInstance(); ContentValues values = new ContentValues(2); int maxFreq = settings.getMaxFrequencyDefault(); values.put(DB.CpuProfile.NAME_FREQUENCY_MAX, maxFreq); int minFreq = settings.getMinFrequencyDefault(); values.put(DB.CpuProfile.NAME_FREQUENCY_MIN, minFreq); Logger.i("Changing frequencies of default profile to min " + minFreq + " and max " + maxFreq); Cursor c = null; try { c = contentResolver.query( DB.CpuProfile.CONTENT_URI, DB.CpuProfile.PROJECTION_DEFAULT, null, null, null); while (c.moveToNext()) { contentResolver.update( DB.CpuProfile.CONTENT_URI, values, DB.SELECTION_BY_ID, new String[] {Long.toString(c.getLong(DB.INDEX_ID))}); } } finally { if (c != null) { c.close(); c = null; } } }
public int getPulseInitalDelay() { try { return Integer.parseInt(getPreferences().getString("prefKeyInitialPulseDelay", "0")); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyInitialPulseDelay as int", e); return 0; } }
public int getNetworkStateOnWifi() { try { return Integer.parseInt(getPreferences().getString("prefKeyNetworkModeOnWifiConnected", "0")); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyNetworkModeOnWifiConnected as int", e); return 0; } }
public int getMinimumSensibeFrequency() { try { return Integer.parseInt(getPreferences().getString("prefKeyMinSensibleFrequency", "400")); } catch (NumberFormatException e) { Logger.w("Error parsing fot MinimumSensibeFrequency ", e); return 400; } }
public int isUseMulticoreCode() { try { return Integer.parseInt(getPreferences().getString("prefKeyMulticore", "2")); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyMulticore as int", e); return 2; } }
public void restoreConfiguration(String name, boolean isUserConfig, boolean restoreAutoload) throws Exception { synchronized (MUTEX) { if (name == null) { return; } Logger.i("Loading configuration " + name); Context context = cb.getContext(); try { CpuTunerProvider.setNotifyChanges(false); if (isUserConfig) { File file = new File(getStoragePath(context, DIRECTORY_CONFIGURATIONS), name); DataJsonImporter dje = new DataJsonImporter(DB.DATABASE_NAME, file); restore(dje, restoreAutoload); } else { String fileName = DIRECTORY_CONFIGURATIONS + "/" + name + "/" + DB.DATABASE_NAME + JsonConstants.FILE_NAME; InputStream is = context.getAssets().open(fileName); DataJsonImporter dje = new DataJsonImporter(DB.DATABASE_NAME, is); restore(dje, restoreAutoload); fixGovernors(); fixProfiles(); InstallHelper.updateProfilesFromVirtGovs(context); } PowerProfiles.getInstance(context).reapplyProfile(true); cb.hasFinished(true); } catch (Exception e) { Logger.e("Cannot restore configuration", e); cb.hasFinished(false); throw new Exception("Cannot restore configuration", e); } finally { CpuTunerProvider.setNotifyChanges(true); StringBuilder msg = new StringBuilder(context.getString(R.string.msg_config_loaded)).append(" "); msg.append(name.replaceFirst("\\d+_", "")); msg.append(" ").append(context.getString(R.string.msg_config)); SwitchLog.addToLog(context, msg.toString()); } } }
private String getTranslatedName(String resString) { Context ctx = cb.getContext(); try { int id = ctx.getResources().getIdentifier(resString, "string", ctx.getPackageName()); return ctx.getString(id); } catch (Exception e) { Logger.w("no translated name found looking for " + resString, e); } return null; }
public int getTrackCurrentType() { if (trackCurrent < 0) { String trackCurrentStr = getPreferences().getString("prefKeyCalcPowerUsageType", "1"); try { trackCurrent = Integer.parseInt(trackCurrentStr); } catch (Exception e) { Logger.w("Cannot parse prefKeyCalcPowerUsage as int", e); trackCurrent = 1; } } return trackCurrent; }
public int getUserLevel() { if (!checkUserLevel) { checkUserLevel = true; try { userLevel = Integer.parseInt(getPreferences().getString(PREF_KEY_USER_LEVEL, "2")); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyUserLevel as int", e); userLevel = 2; } } return userLevel; }
public boolean isPowerStrongerThanScreenoff() { if (!checkedPowerStrongerThanScreenoff) { checkedPowerStrongerThanScreenoff = true; try { powerStrongerThanScreenoff = getPreferences().getBoolean("prefKeyPowerStrongerThanScreenoff", true); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyProfileSwitchLogSize as int", e); } } return powerStrongerThanScreenoff; }
public int getMaxFrequencyDefault() { if (!isBeginnerUser()) { try { int ret = Integer.parseInt(getPreferences().getString(PREF_KEY_MAX_FREQ, "-1")); if (ret > 0) { return ret; } } catch (NumberFormatException e) { Logger.w("Cannot parse PREF_KEY_MAX_FREQ as int", e); } } return getPreferences().getInt(PREF_KEY_MAX_FREQ_DEFAULT, -1); }
public int getProfileSwitchLogSize() { if (!checkedProfileSwitchLogSize) { checkedProfileSwitchLogSize = true; try { profileSwitchLogSize = Integer.parseInt(getPreferences().getString("prefKeyProfileSwitchLogSize", "10")); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyProfileSwitchLogSize as int", e); profileSwitchLogSize = 10; } } return profileSwitchLogSize; }
public long getPulseDelayOff() { if (!checkedPulseDelayOff) { checkedPulseDelayOff = true; try { pulseDelayOff = Long.parseLong(getPreferences().getString("prefKeyPulseDelayOff", "30")); } catch (NumberFormatException e) { Logger.w("Cannot parse pulseDelayOn as int", e); pulseDelayOff = 1; } } return pulseDelayOff; }
public int getBatteryHotTemp() { if (!checkBatteryHotTemp) { checkBatteryHotTemp = true; try { batteryHotTemp = Integer.parseInt( getPreferences().getString("prefKeyBatteryHotTemp", NO_BATTERY_HOT_TEMP + "")); } catch (NumberFormatException e) { Logger.w("Cannot parse prefKeyUserLevel as int", e); batteryHotTemp = NO_BATTERY_HOT_TEMP; } } return batteryHotTemp; }
private void fixGovernors() { Cursor c = null; String[] availCpuGov = CpuHandler.getInstance().getAvailCpuGov(); TreeMap<String, Boolean> availGovs = new TreeMap<String, Boolean>(); for (String gov : availCpuGov) { availGovs.put(gov, Boolean.TRUE); } try { c = contentResolver.query( DB.VirtualGovernor.CONTENT_URI, DB.VirtualGovernor.PROJECTION_DEFAULT, null, null, null); while (c.moveToNext()) { String govs = c.getString(DB.VirtualGovernor.INDEX_REAL_GOVERNOR); String[] govitems = govs.split("\\|"); boolean found = false; for (String gov : govitems) { Boolean avail = availGovs.get(gov); if (avail != null && avail) { Logger.i("Using " + gov); ContentValues values = new ContentValues(1); values.put(DB.VirtualGovernor.NAME_REAL_GOVERNOR, gov); // check for thresholds GovernorConfig governorConfig = GovernorConfigHelper.getGovernorConfig(gov); if (!governorConfig.hasThreshholdUpFeature()) { values.put(DB.VirtualGovernor.NAME_GOVERNOR_THRESHOLD_UP, -1); } if (!governorConfig.hasThreshholdDownFeature()) { values.put(DB.VirtualGovernor.NAME_GOVERNOR_THRESHOLD_DOWN, -1); } if (contentResolver.update( DB.VirtualGovernor.CONTENT_URI, values, DB.SELECTION_BY_ID, new String[] {Long.toString(c.getLong(DB.INDEX_ID))}) > 0) { found = true; break; } } } if (!found) { // we did not find a compatible gov so use none ContentValues values = new ContentValues(1); values.put(DB.VirtualGovernor.NAME_REAL_GOVERNOR, RootHandler.NOT_AVAILABLE); contentResolver.update( DB.VirtualGovernor.CONTENT_URI, values, DB.SELECTION_BY_ID, new String[] {Long.toString(c.getLong(DB.INDEX_ID))}); } } } finally { if (c != null) { c.close(); c = null; } } }