Exemplo n.º 1
0
 private static Intent getLogIntent(String msg, boolean flush) {
   Intent intent = new Intent(SwitchLog.ACTION_ADD_TO_LOG);
   intent.putExtra(SwitchLog.EXTRA_LOG_ENTRY, msg);
   if (flush) {
     intent.putExtra(SwitchLog.EXTRA_FLUSH_LOG, flush);
   }
   PowerProfiles powerProfiles = PowerProfiles.getInstance();
   if (powerProfiles != null) {
     intent.putExtra(DB.SwitchLogDB.NAME_TRIGGER, powerProfiles.getCurrentTriggerName());
     intent.putExtra(DB.SwitchLogDB.NAME_PROFILE, powerProfiles.getCurrentProfileName());
     intent.putExtra(DB.SwitchLogDB.NAME_VIRTGOV, powerProfiles.getCurrentVirtGovName());
     intent.putExtra(DB.SwitchLogDB.NAME_AC, powerProfiles.isAcPower() ? 1 : 0);
     intent.putExtra(DB.SwitchLogDB.NAME_BATTERY, powerProfiles.getBatteryLevel());
     intent.putExtra(DB.SwitchLogDB.NAME_CALL, powerProfiles.isCallInProgress() ? 1 : 0);
     intent.putExtra(DB.SwitchLogDB.NAME_HOT, powerProfiles.isBatteryHot() ? 1 : 0);
     intent.putExtra(DB.SwitchLogDB.NAME_LOCKED, powerProfiles.isScreenOff() ? 1 : 0);
   }
   return intent;
 }
 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());
     }
   }
 }