Ejemplo n.º 1
0
 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;
     }
   }
 }
Ejemplo n.º 2
0
 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());
     }
   }
 }
Ejemplo n.º 3
0
 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;
     }
   }
 }