public static void start(Context ctx) { if (instance == null) { instance = new SwitchLog(ctx); } instance.onReceive(ctx, getLogIntent(ctx.getString(R.string.log_msg_switchlog_start), false)); ctx.registerReceiver(instance, new IntentFilter(Notifier.BROADCAST_PROFILE_CHANGED)); ctx.registerReceiver(instance, new IntentFilter(ACTION_ADD_TO_LOG)); ctx.registerReceiver(instance, new IntentFilter(ACTION_FLUSH_LOG)); }
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()); } } }