protected void onPreExecute() { pDialog = new ProgressDialog(mContext); pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pDialog.setTitle(R.string.installing); pDialog.setMax(8); pDialog.setCancelable(false); pDialog.show(); Log.i(TAG, "Preparing installation"); try { Common.pushFileFromRAW(mContext, busybox, R.raw.busybox, true); Common.chmod(mShell, busybox, "741"); } catch (Exception e) { e.printStackTrace(); } }
@Override protected Boolean doInBackground(Boolean... options) { try { publishProgress(R.string.mount, 1); Log.i(TAG, mContext.getString(R.string.mount)); Common.mountDir(AOSPBrowserInstaller.SystemApps, "RW"); publishProgress(R.string.backup, 2); if (!AOSPBrowserInstaller.bppapkold.exists() && AOSPBrowserInstaller.bppapk.exists()) { Log.i(TAG, mContext.getString(R.string.backup)); move(AOSPBrowserInstaller.bppapk, AOSPBrowserInstaller.bppapkold); } if (!AOSPBrowserInstaller.bppodexold.exists() && AOSPBrowserInstaller.bppodex.exists()) { Log.i(TAG, mContext.getString(R.string.backup)); move(AOSPBrowserInstaller.bppodex, AOSPBrowserInstaller.bppodexold); } publishProgress(R.string.pushbrowser, 3); Log.i(TAG, mContext.getString(R.string.pushbrowser)); copy(downloaded_apk, AOSPBrowserInstaller.installed_browser); publishProgress(R.string.setpermissions, 4); Log.i(TAG, mContext.getString(R.string.setpermissions)); Common.chmod(mShell, AOSPBrowserInstaller.installed_browser, "644"); if (options[0] && !AOSPBrowserInstaller.chromesync.exists()) { publishProgress(R.string.unpacksync, 5); Log.i(TAG, mContext.getString(R.string.unpacksync)); Common.pushFileFromRAW(mContext, chromesyncapk, R.raw.chromebookmarkssyncadapter, true); publishProgress(R.string.pushsync, 6); Log.i(TAG, mContext.getString(R.string.pushsync)); move(chromesyncapk, AOSPBrowserInstaller.chromesync); publishProgress(R.string.setpermissions, 7); Log.i(TAG, mContext.getString(R.string.setpermissions)); Common.chmod(mShell, AOSPBrowserInstaller.chromesync, "644"); } publishProgress(R.string.unmount, 8); Log.i(TAG, mContext.getString(R.string.unmount)); Common.mountDir(AOSPBrowserInstaller.SystemApps, "RO"); } catch (Exception e) { Notifyer.showExceptionToast(mContext, TAG, e); Log.i(TAG, e.getMessage()); return false; } return true; }
public void DD() throws FailedExecuteCommand, IOException, InterruptedException { String Command = ""; if (isJobFlash() || isJobRestore()) { if (mDevice.getName().startsWith("g2") && Build.MANUFACTURER.equals("lge") && isJobFlash()) { File aboot = new File("/dev/block/platform/msm_sdcc.1/by-name/aboot"); File extracted_aboot = new File(mContext.getFilesDir(), "aboot.img"); File patched_CustomIMG = new File(mContext.getFilesDir(), CustomIMG.getName() + ".lok"); File loki_patch = new File(mContext.getFilesDir(), "loki_patch"); File loki_flash = new File(mContext.getFilesDir(), "loki_flash"); mShell.execCommand( "dd if=" + aboot.getAbsolutePath() + " of=" + extracted_aboot.getAbsolutePath(), true); mShell.execCommand( loki_patch.getAbsolutePath() + " recovery " + CustomIMG.getAbsolutePath() + " " + patched_CustomIMG.getAbsolutePath() + " || exit 1", true); Command = loki_flash.getAbsolutePath() + " recovery " + patched_CustomIMG.getAbsolutePath() + " || exit 1"; } else { Log.i(TAG, "Flash started!"); Common.copyFile(CustomIMG, tmpFile); Command = busybox.getAbsolutePath() + " dd if=\"" + tmpFile.getAbsolutePath() + "\" " + "of=\"" + CurrentPartition.getAbsolutePath() + "\""; } } else if (isJobBackup()) { Log.i(TAG, "Backup started!"); Command = busybox.getAbsolutePath() + " dd if=\"" + CurrentPartition.getAbsolutePath() + "\" " + "of=\"" + tmpFile.getAbsolutePath() + "\""; } mShell.execCommand(Command, true); if (isJobBackup()) placeImgBack(); }
public void saveHistory() { if (isJobFlash()) { String counter = "", history = ""; if (isJobKernel()) { counter = PREF_KEY_FLASH_KERNEL_COUNTER; history = Rashr.PREF_KEY_KERNEL_HISTORY; } else if (isJobRecovery()) { counter = PREF_KEY_FLASH_RECOVERY_COUNTER; history = Rashr.PREF_KEY_RECOVERY_HISTORY; } switch (Common.getIntegerPref(mContext, Rashr.PREF_NAME, counter)) { case 0: Common.setStringPref( mContext, Rashr.PREF_NAME, history + String.valueOf(Common.getIntegerPref(mContext, Rashr.PREF_NAME, counter)), CustomIMG.getAbsolutePath()); Common.setIntegerPref(mContext, Rashr.PREF_NAME, counter, 1); return; default: Common.setStringPref( mContext, Rashr.PREF_NAME, history + String.valueOf(Common.getIntegerPref(mContext, Rashr.PREF_NAME, counter)), CustomIMG.getAbsolutePath()); Common.setIntegerPref( mContext, Rashr.PREF_NAME, counter, Common.getIntegerPref(mContext, Rashr.PREF_NAME, counter) + 1); if (Common.getIntegerPref(mContext, Rashr.PREF_NAME, counter) == 5) { Common.setIntegerPref(mContext, Rashr.PREF_NAME, counter, 0); } } } }
protected void onPostExecute(Boolean success) { pDialog.dismiss(); if (!success || mException != null) { Notifyer.showExceptionToast(mContext, TAG, mException); } else { if (isJobFlash() || isJobRestore()) { Log.i(TAG, "Flash finished"); if (!Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_HIDE_REBOOT)) { showRebootDialog(); } else { if (!keepAppOpen) { System.exit(0); } } } } tmpFile.delete(); if (RunAtEnd != null) RunAtEnd.run(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = inflater.inflate(R.layout.fragment_script_manager, container, false); mFileNameAdapter = new ArrayAdapter<>(mContext, R.layout.custom_list_item); mFileList = new ArrayList<>(); mQueue = (ListView) mRootView.findViewById(R.id.lvQueue); mQueue.setAdapter(mFileNameAdapter); mQueue.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mFileList.remove(position); mFileNameAdapter.clear(); for (File i : mFileList) { mFileNameAdapter.add(i.getName()); } } }); if (mStartFile != null) { if (mStartFile.exists()) { if (Common.stringEndsWithArray(mStartFile.getName(), mAllowedEXT)) { addFileToQueue(mStartFile); } else { Toast.makeText(mContext, R.string.wrong_format, Toast.LENGTH_SHORT).show(); } } } AppCompatButton AddZip = (AppCompatButton) mRootView.findViewById(R.id.addZip); AddZip.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { mFileChooser = new FileChooserDialog(mContext); File startFolder = new File("/"); if (mFileList.size() > 0) { startFolder = mFileList.get(mFileList.size() - 1); if (startFolder.isFile()) { startFolder = startFolder.getParentFile(); } } mFileChooser.setStartFolder(startFolder); mFileChooser.setOnFileChooseListener( new FileChooserDialog.OnFileChooseListener() { @Override public void OnFileChoose(File file) { addFileToQueue(file); } }); mFileChooser.setAllowedEXT(mAllowedEXT); mFileChooser.setBrowseUpAllowed(true); mFileChooser.setWarn(false); mFileChooser.show(); } }); AppCompatButton FlashZip = (AppCompatButton) mRootView.findViewById(R.id.bFlashZip); FlashZip.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { AppCompatCheckBox cbBakSystem = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupSystem); AppCompatCheckBox cbBakData = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupData); AppCompatCheckBox cbBakCache = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupCache); AppCompatCheckBox cbBakRecovery = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupRecovery); AppCompatCheckBox cbBakBoot = (AppCompatCheckBox) mRootView.findViewById(R.id.cbBackupBoot); AppCompatCheckBox cbSkipMD5 = (AppCompatCheckBox) mRootView.findViewById(R.id.cbSkipMD5); AppCompatEditText etBakName = (AppCompatEditText) mRootView.findViewById(R.id.etBackupName); AppCompatCheckBox cbWipeCache = (AppCompatCheckBox) mRootView.findViewById(R.id.cbWipeCache); AppCompatCheckBox cbWipeDalvik = (AppCompatCheckBox) mRootView.findViewById(R.id.cbWipeDalvik); AppCompatCheckBox cbWipeData = (AppCompatCheckBox) mRootView.findViewById(R.id.cbWipeData); final StringBuilder command = new StringBuilder(); command.append("echo #####Script created by Rashr#####;"); if (cbBakBoot.isChecked() || cbBakCache.isChecked() || cbBakData.isChecked() || cbBakRecovery.isChecked() || cbBakSystem.isChecked()) { command.append("backup "); if (cbBakBoot.isChecked()) command.append("B"); if (cbBakCache.isChecked()) command.append("C"); if (cbBakData.isChecked()) command.append("D"); if (cbBakRecovery.isChecked()) command.append("R"); if (cbBakSystem.isChecked()) command.append("S"); if (cbSkipMD5.isChecked()) command.append("M"); CharSequence BackupName = etBakName.getText(); if (BackupName != null && !BackupName.equals("")) { command.append(" "); command.append(BackupName); } command.append(CMD_END); } if (cbWipeCache.isChecked()) command.append("wipe cache;"); if (cbWipeDalvik.isChecked()) command.append("wipe dalvik;"); if (cbWipeData.isChecked()) command.append("wipe data;"); for (File i : mFileList) { command.append("install "); command.append(i.getAbsolutePath()); command.append(CMD_END); } if (!command.toString().equals("")) { String commands = ""; int index = 0; for (String i : command.toString().split(CMD_END)) { if (!i.equals("")) { if (index > 0) { commands += index++ + ". " + i + "\n"; } else { index++; } } } final AlertDialog.Builder CommandsPreview = new AlertDialog.Builder(mContext); CommandsPreview.setTitle(R.string.recovery_script_review); CommandsPreview.setPositiveButton( R.string.run, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { for (String split : command.toString().split(";")) { if (!split.equals("")) { RashrApp.SHELL.execCommand( "echo " + split + " >> /cache/recovery/openrecoveryscript"); } } RashrApp.TOOLBOX.reboot(Toolbox.REBOOT_RECOVERY); } catch (Exception e) { e.printStackTrace(); } } }); CommandsPreview.setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {} }); CommandsPreview.setMessage(commands); CommandsPreview.show(); } else { Toast.makeText(mContext, "No job to do :)", Toast.LENGTH_LONG).show(); } } }); return mRootView; }
private void placeImgBack() throws IOException, FailedExecuteCommand { mToolbox.setFilePermissions(tmpFile, "666"); Common.copyFile(tmpFile, CustomIMG); }