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 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(); }