Search in sources :

Example 6 with FailedExecuteCommand

use of org.sufficientlysecure.rootcommands.util.FailedExecuteCommand in project Rashr by DsLNeXuS.

the class FlashUtil method installXZDual.

private void installXZDual() throws FailedExecuteCommand {
    Unzipper.unzip(mCustomIMG, new File("/tmp"));
    RashrApp.SHELL.execCommand("chmod 755 /tmp/backupstockbinaries.sh");
    try {
        RashrApp.SHELL.execCommand("./tmp/backupstockbinaries.sh");
    } catch (FailedExecuteCommand ignore) {
    }
    RashrApp.SHELL.execCommand("cp " + Const.Busybox + " /system/.XZDualRecovery/busybox");
    RashrApp.SHELL.execCommand("chmod 755 /tmp/tmp/installstock.sh");
    RashrApp.SHELL.execCommand("./tmp/tmp/installstock.sh");
    RashrApp.SHELL.execCommand("chmod 755 /tmp/tmp/installdisableric.sh");
    RashrApp.SHELL.execCommand("./tmp/tmp/installdisableric.sh");
    RashrApp.SHELL.execCommand("chmod 755 /tmp/tmp/installndrutils.sh");
    RashrApp.SHELL.execCommand("./tmp/tmp/installndrutils.sh");
    RashrApp.SHELL.execCommand("chmod 755 /tmp/tmp/setversion.sh");
    RashrApp.SHELL.execCommand("./tmp/tmp/setversion.sh");
    RashrApp.SHELL.execCommand("chmod 644 /system/bin/recovery.cwm.cpio.lzma");
    RashrApp.SHELL.execCommand("chmod 644 /system/bin/recovery.philz.cpio.lzma");
    RashrApp.SHELL.execCommand("chmod 644 /system/bin/recovery.twrp.cpio.lzma");
    RashrApp.SHELL.execCommand("chmod 755 /system/bin/mr");
    RashrApp.SHELL.execCommand("chmod 755 /system/bin/chargemon");
    RashrApp.SHELL.execCommand("chmod 755 /system/bin/dualrecovery.sh");
    RashrApp.SHELL.execCommand("chmod 755 /system/bin/rickiller.sh");
    RashrApp.SHELL.execCommand("chmod 755 /system/xbin/busybox");
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) File(java.io.File)

Example 7 with FailedExecuteCommand

use of org.sufficientlysecure.rootcommands.util.FailedExecuteCommand in project Rashr by DsLNeXuS.

the class RashrActivity method extractFiles.

/**
     * Extract files from APK, the files are stored under RashrApp/src/res/raw
     *
     * @throws IOException Files can't be extracted
     */
private void extractFiles() throws IOException {
    Common.pushFileFromRAW(mContext, Const.RecoveryCollectionFile, R.raw.recovery_links, mVersionChanged);
    Common.pushFileFromRAW(mContext, Const.KernelCollectionFile, R.raw.kernel_sums, mVersionChanged);
    Const.Busybox = new File(mContext.getFilesDir(), "busybox");
    Common.pushFileFromRAW(mContext, Const.Busybox, R.raw.busybox, mVersionChanged);
    try {
        RashrApp.SHELL.execCommand("chmod 777 " + Const.Busybox);
    } catch (FailedExecuteCommand failedExecuteCommand) {
        failedExecuteCommand.printStackTrace();
    }
    File PartLayoutsZip = new File(mContext.getFilesDir(), "partlayouts.zip");
    Common.pushFileFromRAW(mContext, PartLayoutsZip, R.raw.partlayouts, mVersionChanged);
    File flash_image = new File(getFilesDir(), "flash_image");
    Common.pushFileFromRAW(mContext, flash_image, R.raw.flash_image, mVersionChanged);
    File dump_image = new File(getFilesDir(), "dump_image");
    Common.pushFileFromRAW(mContext, dump_image, R.raw.dump_image, mVersionChanged);
    Const.LokiPatch = new File(mContext.getFilesDir(), "loki_patch");
    Common.pushFileFromRAW(mContext, Const.LokiPatch, R.raw.loki_patch, mVersionChanged);
    Const.LokiFlash = new File(mContext.getFilesDir(), "loki_flash");
    Common.pushFileFromRAW(mContext, Const.LokiFlash, R.raw.loki_flash, mVersionChanged);
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) File(java.io.File)

Example 8 with FailedExecuteCommand

use of org.sufficientlysecure.rootcommands.util.FailedExecuteCommand in project Rashr by DsLNeXuS.

the class RashrActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Const.FilesDir = mContext.getFilesDir();
    Const.RashrLog = new File(Const.FilesDir, Const.LOG_NAME);
    //isDark = Common.getBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_DARK_UI);
    setTheme(R.style.Rashr);
    setContentView(R.layout.loading_layout);
    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
    final TextView tvLoading = (TextView) findViewById(R.id.tvLoading);
    final Thread StartThread = new Thread(new Runnable() {

        @Override
        public void run() {
            /* Checking if version has changed */
            final int previous_version = Common.getIntegerPref(mContext, Const.PREF_NAME, Const.PREF_KEY_CUR_VER);
            mVersionChanged = BuildConfig.VERSION_CODE > previous_version;
            Common.setIntegerPref(mContext, Const.PREF_NAME, Const.PREF_KEY_CUR_VER, BuildConfig.VERSION_CODE);
            /* Try to get root access */
            try {
                RashrApp.SHELL = startShell();
                File logs = new File(mContext.getFilesDir(), Const.Logs);
                RashrApp.SHELL.setLogFile(logs);
                RashrApp.TOOLBOX = new Toolbox(RashrApp.SHELL);
            } catch (IOException e) {
                String message;
                if (e.toString() != null) {
                    message = e.toString();
                } else {
                    message = "Shell could not be started.  Error: " + e.toString();
                }
                RashrApp.ERRORS.add(Const.RASHR_TAG + " " + message);
                mActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        setContentView(R.layout.err_layout);
                    }
                });
                return;
            }
            /* Creating needed folder and unpacking files */
            mActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (tvLoading != null)
                        tvLoading.setText(R.string.loading_data);
                }
            });
            if (Const.PathToTmp.exists()) {
                Common.deleteFolder(Const.PathToTmp, true);
            }
            for (File i : Folder) {
                if (!i.exists()) {
                    if (!i.mkdirs()) {
                        RashrApp.ERRORS.add(Const.RASHR_TAG + " " + i + " can't be created!");
                    }
                }
            }
            try {
                extractFiles();
            } catch (IOException e) {
                RashrApp.ERRORS.add("Failed to extract files. Error: " + e);
                mActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(mContext, R.string.failed_unpack_files, Toast.LENGTH_LONG).show();
                    }
                });
            }
            try {
                File LogCopy = new File(mContext.getFilesDir(), Const.LastLog.getName() + ".txt");
                RashrApp.SHELL.execCommand(Const.Busybox + " chmod 777 " + Const.LastLog);
                if (LogCopy.exists())
                    LogCopy.delete();
                RashrApp.SHELL.execCommand(Const.Busybox + " cp " + Const.LastLog + " " + LogCopy);
                RashrApp.SHELL.execCommand(Const.Busybox + " chmod 777 " + LogCopy);
                ApplicationInfo info = getApplicationInfo();
                RashrApp.SHELL.execCommand(Const.Busybox + " chown " + info.uid + ":" + info.uid + " " + LogCopy);
                RashrApp.SHELL.execCommand(Const.Busybox + " chmod 777 " + LogCopy);
                LastLogExists = LogCopy.exists();
            } catch (FailedExecuteCommand e) {
                RashrApp.ERRORS.add(Const.RASHR_TAG + " LastLog not found: " + e);
            }
            mActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    checkAppUpdates();
                    if (tvLoading != null)
                        tvLoading.setText(R.string.reading_device);
                }
            });
            if (!RashrApp.DEVICE.isSetup()) {
                String pref_dev_name = Common.getStringPref(mContext, Const.PREF_NAME, Const.PREF_KEY_DEVICE_NAME);
                RashrApp.DEVICE.setup(pref_dev_name);
            }
            /* If device is not supported, you can report it now or close the App */
            if ((!RashrApp.DEVICE.isRecoverySupported() && !RashrApp.DEVICE.isKernelSupported()) || BuildConfig.DEBUG) {
                mActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        showDeviceNotSupportedDialog();
                    }
                });
            } else {
                Common.setBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_SHOW_UNIFIED, true);
                if (!Common.getBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_FIRST_RUN)) {
                    firstSetup(mContext);
                    mActivity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            showUsageWarning();
                        }
                    });
                }
            }
            mActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        mRoot = (DrawerLayout) View.inflate(mContext, R.layout.activity_rashr, null);
                        mRoot.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.abc_fade_in));
                        setContentView(mRoot);
                        mToolbar = (Toolbar) findViewById(R.id.toolbar);
                        setSupportActionBar(mToolbar);
                        mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
                        mDrawerToggle = new ActionBarDrawerToggle(mActivity, mRoot, mToolbar, R.string.app_name, R.string.app_name);
                        DrawerArrowDrawable coloredArrow = new DrawerArrowDrawable(mContext);
                        TypedValue typedValue = new TypedValue();
                        Resources.Theme theme = getTheme();
                        theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
                        coloredArrow.setColor(typedValue.data);
                        mDrawerToggle.setDrawerArrowDrawable(coloredArrow);
                        mRoot.addDrawerListener(mDrawerToggle);
                        mDrawerToggle.syncState();
                        mNavigationView.setNavigationItemSelectedListener(mActivity);
                        AdView ads = (AdView) findViewById(R.id.ads);
                        if (ads != null) {
                            if (Common.getBooleanPref(mContext, Const.PREF_NAME, Const.PREF_KEY_ADS)) {
                                ads.loadAd(new AdRequest.Builder().addTestDevice("7DE4544A9DF140825046328923A50A91").build());
                            }
                        }
                        if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
                            /* Rashr is opened by other app to flash supported files (.zip) or (.img) */
                            File file = new File(getIntent().getData().getPath());
                            if (file.exists()) {
                                if (file.toString().endsWith(Device.EXT_ZIP)) {
                                    /* If it is a zip file open the ScriptManager */
                                    switchTo(ScriptManagerFragment.newInstance(mActivity, file));
                                } else {
                                    /* If it is a img file open FlashAs to choose mode (recovery or kernel) */
                                    switchTo(FlashAsFragment.newInstance(mActivity, file, true));
                                }
                            }
                        } else {
                            onNavigationItemSelected(mNavigationView.getMenu().getItem(0));
                        }
                    } catch (NullPointerException e) {
                        setContentView(R.layout.err_layout);
                        RashrApp.ERRORS.add("Error while inflating layout:" + e);
                        AppCompatTextView tv = (AppCompatTextView) findViewById(R.id.tvErr);
                        try {
                            if (tv != null) {
                                tv.setText(R.string.failed_setup_layout);
                            }
                        } catch (RuntimeException ex) {
                            RashrApp.ERRORS.add(Const.RASHR_TAG + e);
                            ReportDialog dialog = new ReportDialog(mActivity, e.toString());
                            dialog.show();
                            ex.printStackTrace();
                        }
                        ReportDialog dialog = new ReportDialog(mActivity, e.toString());
                        dialog.show();
                        e.printStackTrace();
                    }
                }
            });
        }
    });
    StartThread.start();
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) ApplicationInfo(android.content.pm.ApplicationInfo) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AppCompatTextView(android.support.v7.widget.AppCompatTextView) IOException(java.io.IOException) AdRequest(com.google.android.gms.ads.AdRequest) Toolbox(org.sufficientlysecure.rootcommands.Toolbox) DrawerArrowDrawable(android.support.v7.graphics.drawable.DrawerArrowDrawable) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) Resources(android.content.res.Resources) AdView(com.google.android.gms.ads.AdView) File(java.io.File) TypedValue(android.util.TypedValue)

Example 9 with FailedExecuteCommand

use of org.sufficientlysecure.rootcommands.util.FailedExecuteCommand in project Rashr by DsLNeXuS.

the class RecoverySystemFragment method flashSupportedRecovery.

/**
     * Flash a Recovery provided by Rashr, like ClockworkMod, TWRP, PhilZ, CM, Stock
     *
     * @param system  String containing the Recovery-System type for example:
     *                clockwork, cm, twrp, philz, stock....
     * @param fileUrl File that will be flashed
     */
public void flashSupportedRecovery(final String system, String fileUrl) {
    /*
         * If there files be needed to flash download it and listing device specified
         * recovery file for example recovery-clockwork-touch-6.0.3.1-grouper.img
         * (read out from RECOVERY_SUMS)
         */
    if (system.equals(Device.REC_SYS_XZDUAL)) {
        AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
        alert.setTitle(R.string.warning);
        if (App.Device.isXZDualInstalled()) {
            alert.setMessage(R.string.xzdual_uninstall_alert);
            alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AlertDialog.Builder abuilder = new AlertDialog.Builder(mContext);
                    abuilder.setTitle(R.string.info);
                    abuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
                    try {
                        FlashUtil.uninstallXZDual();
                        abuilder.setMessage(R.string.xzdual_uninstall_successfull);
                    } catch (FailedExecuteCommand failedExecuteCommand) {
                        abuilder.setMessage(getString(R.string.xzdual_uninstall_failed) + "\n" + failedExecuteCommand.toString());
                        failedExecuteCommand.printStackTrace();
                        App.ERRORS.add(failedExecuteCommand.toString() + " Error uninstalling XZDual");
                    }
                    abuilder.show();
                }
            });
            alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            return;
        }
    }
    String fileName = "";
    if (system.equals(Device.REC_SYS_CM) || system.equals(Device.REC_SYS_TWRP)) {
        fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
    }
    final File recovery = new File(mImagePath, fileName);
    if (!recovery.exists()) {
        try {
            URL url = new URL(fileUrl);
            final Downloader downloader = new Downloader(url, recovery);
            final DownloadDialog RecoveryDownloader = new DownloadDialog(mContext, downloader);
            if (system.equals(Device.REC_SYS_TWRP)) {
                downloader.setReferrer(fileUrl);
            }
            RecoveryDownloader.setOnDownloadListener(new DownloadDialog.OnDownloadListener() {

                @Override
                public void onSuccess(File file) {
                    if (system.equals(Device.REC_SYS_XZDUAL)) {
                        FlashUtil flasher = new FlashUtil(getActivity(), file, FlashUtil.JOB_INSTALL_XZDUAL);
                        flasher.execute();
                        mActivity.onBackPressed();
                    } else {
                        flashRecovery(file);
                    }
                }

                @Override
                public void onFail(Exception e) {
                    if (e != null) {
                        App.ERRORS.add(e.toString());
                        Snackbar.make(mView.getView(), e.getMessage(), Snackbar.LENGTH_SHORT).show();
                    }
                    RecoveryDownloader.retry();
                }
            });
            RecoveryDownloader.setAskBeforeDownload(true);
            downloader.setChecksumFile(App.RecoveryCollectionFile);
            RecoveryDownloader.ask();
        } catch (MalformedURLException ignored) {
        }
    } else {
        flashRecovery(recovery);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) MalformedURLException(java.net.MalformedURLException) DialogInterface(android.content.DialogInterface) Downloader(de.mkrtchyan.utils.Downloader) DownloadDialog(de.mkrtchyan.utils.DownloadDialog) URL(java.net.URL) JSONException(org.json.JSONException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) File(java.io.File)

Aggregations

FailedExecuteCommand (org.sufficientlysecure.rootcommands.util.FailedExecuteCommand)9 File (java.io.File)6 IOException (java.io.IOException)4 ZipFile (java.util.zip.ZipFile)2 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Resources (android.content.res.Resources)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 AlertDialog (android.support.v7.app.AlertDialog)1 DrawerArrowDrawable (android.support.v7.graphics.drawable.DrawerArrowDrawable)1 AppCompatTextView (android.support.v7.widget.AppCompatTextView)1 TypedValue (android.util.TypedValue)1 TextView (android.widget.TextView)1 AdRequest (com.google.android.gms.ads.AdRequest)1 AdView (com.google.android.gms.ads.AdView)1 DownloadDialog (de.mkrtchyan.utils.DownloadDialog)1 Downloader (de.mkrtchyan.utils.Downloader)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1