private void restore(DataJsonImporter dje, boolean inclAutoloadConfig) throws JSONException {
   Context ctx = cb.getContext();
   CpuTunerProvider.deleteAllTables(ctx, inclAutoloadConfig);
   synchronized (ModelAccess.virtgovCacheMutex) {
     synchronized (ModelAccess.profileCacheMutex) {
       synchronized (ModelAccess.triggerCacheMutex) {
         loadVirtualGovernors(dje);
         loadCpuProfiles(dje);
         loadTriggers(dje);
         if (inclAutoloadConfig) {
           loadAutoloadConfig(dje);
         }
       }
     }
   }
   ModelAccess.getInstace(cb.getContext()).clearCache();
 }
 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;
 }
 private void backup(File storagePath) {
   if (!storagePath.isDirectory()) {
     storagePath.mkdir();
   }
   // ModelAccess.getInstace(cb.getContext()).applyDelayedTriggerUpdates();
   SQLiteDatabase db = new CpuTunerOpenHelper(cb.getContext()).getWritableDatabase();
   ExportConfig config = new ExportConfig(db, DB.DATABASE_NAME, storagePath, ExportType.JSON);
   config.setExcludeTable(DB.SwitchLogDB.TABLE_NAME);
   ExportDataTask exportDataTask = new ExportDataTask(cb);
   exportDataTask.execute(new ExportConfig[] {config});
 }
 public void backupConfiguration(String name) {
   synchronized (MUTEX) {
     if (name == null) {
       return;
     }
     File storagePath = new File(getStoragePath(cb.getContext(), DIRECTORY_CONFIGURATIONS), name);
     if (!storagePath.isDirectory()) {
       storagePath.mkdirs();
     }
     backup(storagePath);
   }
 }
 public BackupRestoreHelper(BackupRestoreCallback cb) {
   super();
   this.cb = cb;
   this.contentResolver = cb.getContext().getContentResolver();
 }