Search in sources :

Example 1 with FailedExecuteCommand

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

the class Device method readDeviceInfos.

/*    public boolean downloadUtils(final Context mContext) {

        final File archive = new File(Const.PathToUtils, mName + EXT_ZIP);

        final AlertDialog.Builder mAlertDialog = new AlertDialog.Builder(mContext);
        mAlertDialog
                .setTitle(R.string.warning)
                .setMessage(R.string.download_utils);
        if (mName.equals("montblanc") || mName.equals("c6602") || mName.equals("yuga")) {
            if (!archive.exists()) {
                mAlertDialog.setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            URL url = new URL(Const.UTILS_URL + "/" + archive.getName());
                            DownloadDialog downloader = new DownloadDialog(mContext, url, archive);
                            downloader.setOnDownloadListener(new DownloadDialog.OnDownloadListener() {
                                @Override
                                public void success(File file) {
                                    Unzipper.unzip(archive, new File(Const.PathToUtils, mName));
                                }

                                @Override
                                public void failed(Exception e) {

                                }
                            });
                        } catch (MalformedURLException ignored) {}
                    }
                });
                mAlertDialog.show();
                return true;
            } else {
                Unzipper.unzip(archive, new File(Const.PathToUtils, mName));
                return false;
            }
        }
        return false;
    }*/
private void readDeviceInfos() {
    for (File i : KernelList) {
        if (mKernelPath.equals("")) {
            /**
                 * Partition doesn't exist LOLLIPOP (File.exists() returns always
                 * false if file is in hidden FS. Lollipop marks /dev/.... as hidden)
                 * Check over RootShell (if throws exception partition not found check next
                 */
            try {
                RashrApp.SHELL.execCommand("ls " + i.getAbsolutePath(), true, false);
                mKernelPath = i.getAbsolutePath();
                break;
            } catch (FailedExecuteCommand ignore) {
            }
        }
    }
    for (File i : RecoveryList) {
        if (mRecoveryPath.equals("")) {
            try {
                /**
                     * Partition doesn't exist LOLLIPOP (File.exists() returns always
                     * false if file is in hidden FS. Lollipop marks /dev/.... as hidden)
                     * Check over RootShell (if throws exception partition not found check next
                     */
                RashrApp.SHELL.execCommand("ls " + i.getAbsolutePath(), true, false);
                mRecoveryPath = i.getAbsolutePath();
                //}
                break;
            } catch (FailedExecuteCommand ignore) {
            }
        }
    }
    if (RashrActivity.LastLogExists) {
        readLastLog();
    }
    if (mRecoveryPath.equals("")) {
        //      ASUS DEVICEs + Same
        if (mName.equals("a66") || mName.equals("c5133") || mName.equals("c5170") || mName.equals("raybst"))
            mRecoveryPath = "/dev/block/mmcblk0p15";
        //	    Samsung DEVICEs + Same
        if (mName.equals("d2att") || mName.equals("d2tmo") || mName.equals("d2mtr") || mName.equals("d2vzw") || mName.equals("d2spr") || mName.equals("d2usc") || mName.equals("d2can") || mName.equals("d2cri") || mName.equals("d2vmu") || mName.equals("sch-i929") || mName.equals("e6710") || mName.equals("expresslte") || mName.equals("goghcri") || mName.equals("p710") || mName.equals("im-a810s") || mName.equals("hmh") || mName.equals("ef65l") || mName.equals("pantechp9070"))
            mRecoveryPath = "/dev/block/mmcblk0p18";
        if (mName.equals("i9300") || mName.equals("galaxys2") || mName.equals("n8013") || mName.equals("p3113") || mName.equals("p3110") || mName.equals("p6200") || mName.equals("n8000") || mName.equals("sph-d710vmub") || mName.equals("p920") || mName.equals("konawifi") || mName.equals("t03gctc") || mName.equals("cosmopolitan") || mName.equals("s2vep") || mName.equals("gt-p6810") || mName.equals("baffin") || mName.equals("ivoryss") || mName.equals("crater") || mName.equals("kyletdcmcc"))
            mRecoveryPath = "/dev/block/mmcblk0p6";
        if (mName.equals("t03g") || mName.equals("tf700t") || mName.equals("t0lte") || mName.equals("t0lteatt") || mName.equals("t0ltecan") || mName.equals("t0ltektt") || mName.equals("t0lteskt") || mName.equals("t0ltespr") || mName.equals("t0lteusc") || mName.equals("t0ltevzw") || mName.equals("t0lteatt") || mName.equals("t0ltetmo") || mName.equals("m3") || mName.equals("otter2") || mName.equals("p4notelte"))
            mRecoveryPath = "/dev/block/mmcblk0p9";
        if (mName.equals("golden") || mName.equals("villec2") || mName.equals("vivo") || mName.equals("vivow") || mName.equals("kingdom") || mName.equals("vision") || mName.equals("mystul") || mName.equals("jflteatt") || mName.equals("jfltespi") || mName.equals("jfltecan") || mName.equals("jfltecri") || mName.equals("jfltexx") || mName.equals("jfltespr") || mName.equals("jfltetmo") || mName.equals("jflteusc") || mName.equals("jfltevzw") || mName.equals("i9500") || mName.equals("flyer") || mName.equals("saga") || mName.equals("shooteru") || mName.equals("golfu") || mName.equals("glacier") || mName.equals("runnymede") || mName.equals("protou") || mName.equals("codinametropcs") || mName.equals("codinatmo") || mName.equals("skomer") || mName.equals("magnids"))
            mRecoveryPath = "/dev/block/mmcblk0p21";
        if (mName.equals("jena") || mName.equals("kylessopen") || mName.equals("kyleopen"))
            mRecoveryPath = "/dev/block/mmcblk0p12";
        if (mName.equals("GT-I9103") || mName.equals("mevlana"))
            mRecoveryPath = "/dev/block/mmcblk0p8";
        //      LG DEVICEs + Same
        if (mName.equals("e610") || mName.equals("fx3") || mName.equals("hws7300u") || mName.equals("vee3e") || mName.equals("victor") || mName.equals("ef34k") || mName.equals("aviva"))
            mRecoveryPath = "/dev/block/mmcblk0p17";
        if (mName.equals("vs930") || mName.equals("l0") || mName.equals("ca201l") || mName.equals("ef49k") || mName.equals("ot-930") || mName.equals("fx1") || mName.equals("ef47s") || mName.equals("ef46l") || mName.equals("l1v"))
            mRecoveryPath = "/dev/block/mmcblk0p19";
        //	    HTC DEVICEs + Same
        if (mName.equals("t6wl"))
            mRecoveryPath = "/dev/block/mmcblk0p38";
        if (mName.equals("holiday") || mName.equals("vigor") || mName.equals("a68"))
            mRecoveryPath = "/dev/block/mmcblk0p23";
        if (mName.equals("m7") || mName.equals("obakem") || mName.equals("obake") || mName.equals("ovation"))
            mRecoveryPath = "/dev/block/mmcblk0p34";
        if (mName.equals("m7wls"))
            mRecoveryPath = "/dev/block/mmcblk0p36";
        if (mName.equals("endeavoru") || mName.equals("enrc2b") || mName.equals("p999") || mName.equals("us9230e1") || mName.equals("evitareul") || mName.equals("otter") || mName.equals("e2001_v89_gq2008s"))
            mRecoveryPath = "/dev/block/mmcblk0p5";
        if (mName.equals("ace") || mName.equals("primou"))
            mRecoveryPath = "/dev/block/platform/msm_sdcc.2/mmcblk0p21";
        if (mName.equals("pyramid"))
            mRecoveryPath = "/dev/block/platform/msm_sdcc.1/mmcblk0p21";
        if (mName.equals("ville") || mName.equals("evita") || mName.equals("skyrocket") || mName.equals("fireball") || mName.equals("jewel") || mName.equals("shooter"))
            mRecoveryPath = "/dev/block/mmcblk0p22";
        if (mName.equals("dlxub1") || mName.equals("dlx") || mName.equals("dlxj") || mName.equals("im-a840sp") || mName.equals("im-a840s") || mName.equals("taurus"))
            mRecoveryPath = "/dev/block/mmcblk0p20";
        if (mName.equals("arubaslim"))
            mKernelPath = "/dev/block/mmcblk0p8";
        //	    Motorola DEVICEs + Same
        if (mName.equals("qinara") || mName.equals("f02e") || mName.equals("vanquish_u") || mName.equals("xt897") || mName.equals("solstice") || mName.equals("smq_u"))
            mRecoveryPath = "/dev/block/mmcblk0p32";
        if (mName.equals("pasteur"))
            mRecoveryPath = "/dev/block/mmcblk1p12";
        if (mName.equals("dinara_td"))
            mRecoveryPath = "/dev/block/mmcblk1p14";
        if (mName.equals("e975") || mName.equals("e988"))
            mRecoveryPath = "/dev/block/mmcblk0p28";
        if (mName.equals("shadow") || mName.equals("edison") || mName.equals("venus2"))
            mRecoveryPath = "/dev/block/mmcblk1p16";
        if (mName.equals("spyder") || mName.equals("maserati"))
            mRecoveryPath = "/dev/block/mmcblk1p15";
        if (mName.equals("olympus") || mName.equals("ja3g") || mName.equals("ja3gchnduos") || mName.equals("daytona") || mName.equals("konalteatt") || mName.equals("lc1810") || mName.equals("lt02wifi") || mName.equals("lt013g"))
            mRecoveryPath = "/dev/block/mmcblk0p10";
        //	    Sony DEVICEs + Same
        if (mName.equals("nozomi"))
            mRecoveryPath = "/dev/block/mmcblk0p3";
        //	    LG DEVICEs + Same
        if (mName.equals("p990") || mName.equals("tf300t"))
            mRecoveryPath = "/dev/block/mmcblk0p7";
        if (mName.equals("x3") || mName.equals("picasso") || mName.equals("picasso_m") || mName.equals("enterprise_ru"))
            mRecoveryPath = "/dev/block/mmcblk0p1";
        if (mName.equals("m3s") || mName.equals("bryce") || mName.equals("melius3g") || mName.equals("meliuslte") || mName.equals("serranolte"))
            mRecoveryPath = "/dev/block/mmcblk0p14";
        if (mName.equals("p970") || mName.equals("u2") || mName.equals("p760") || mName.equals("p768"))
            mRecoveryPath = "/dev/block/mmcblk0p4";
        //	    ZTE DEVICEs + Same
        if (mName.equals("warp2") || mName.equals("hwc8813") || mName.equals("galaxysplus") || mName.equals("cayman") || mName.equals("ancora_tmo") || mName.equals("c8812e") || mName.equals("batman_skt") || mName.equals("u8833") || mName.equals("i_vzw") || mName.equals("armani_row") || mName.equals("hwu8825-1") || mName.equals("ad685g") || mName.equals("audi") || mName.equals("a111") || mName.equals("ancora") || mName.equals("arubaslim"))
            mRecoveryPath = "/dev/block/mmcblk0p13";
        if (mName.equals("elden") || mName.equals("hayes") || mName.equals("quantum") || mName.equals("coeus") || mName.equals("c_4"))
            mRecoveryPath = "/dev/block/mmcblk0p16";
    }
    if (!isRecoverySupported()) {
        if (mRecoveryPath.contains("/dev/block")) {
            mRecoveryType = PARTITION_TYPE_DD;
        }
    }
    if (!isKernelSupported()) {
        if (mKernelPath.contains("/dev/block")) {
            mKernelType = PARTITION_TYPE_DD;
        }
    }
    if (!isRecoverySupported() || !isKernelSupported()) {
        readPartLayouts();
    }
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 2 with FailedExecuteCommand

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

the class Shell method execCommand.

public String execCommand(String Command, boolean waitForFinish, boolean logCommand) throws FailedExecuteCommand {
    final SimpleCommand command = new SimpleCommand(Command);
    try {
        Log.i(TAG, Command);
        if (waitForFinish) {
            this.add(command).waitForFinish();
        } else {
            this.add(command);
        }
        String output = command.getOutput();
        if (logCommand)
            logCommand(command);
        Log.i(TAG, output);
        if (command.getExitCode() != 0) {
            throw new Exception("Exit-Code not 0");
        }
        return output;
    } catch (Exception e) {
        if (logCommand)
            logCommand(command);
        Log.i(TAG, "Failed: " + command.getOutput());
        throw new FailedExecuteCommand(command);
    }
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand) IOException(java.io.IOException) RootAccessDeniedException(org.sufficientlysecure.rootcommands.util.RootAccessDeniedException)

Example 3 with FailedExecuteCommand

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

the class Device method readLastLog.

/**
     * The lastLogs file in Android contains the logs of the last booted RecoverySystem.
     * Using the lastLogs we can find out which recovery system and version the user has
     * installed and the used boot (kernel partition) and recovery (recovery partition) paths.
     */
private void readLastLog() {
    try {
        String line;
        File LogCopy = new File(Const.FilesDir, Const.LastLog.getName() + ".txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(LogCopy)));
        while ((line = br.readLine()) != null) {
            line = line.replace("\"", "");
            line = line.replace("\'", "");
            /*
                 * If the Recovery System and Version could not defined so try it with the next line
                 */
            if (mRecoveryVersion.equals(RECOVERY_VERSION_NOT_RECONGNIZED)) {
                if (line.contains("ClockworkMod Recovery") || line.contains("CWM")) {
                    mRecoveryVersion = line;
                } else if (line.contains("TWRP") && line.contains("Loading settings")) {
                    line = line.replace("Starting ", "");
                    line = line.split(" on")[0];
                    mRecoveryVersion = line;
                } else if (line.contains("ro.twrp.version")) {
                    line = line.replace("ro.twrp.version=", "");
                    mRecoveryVersion = "TWRP " + line;
                } else if (line.contains("PhilZ")) {
                    mRecoveryVersion = line;
                } else if (line.contains("4EXT")) {
                    line = line.split("4EXT")[1];
                    mRecoveryVersion = line;
                }
            } else if ((!mKernelPath.equals("") || isKernelMTD()) && (!mRecoveryPath.equals("") || isRecoveryMTD())) {
                /*
                     * Break if the recovery system and version could be defined and partitions for
                     * recovery and kernel found.
                     */
                break;
            }
            /*
                 * KernelPath not found so try it with this line
                 */
            if (mKernelPath.equals("")) {
                if (line.contains("/boot") && !line.contains("/bootloader")) {
                    if (line.contains("mtd")) {
                        mKernelType = PARTITION_TYPE_MTD;
                    } else if (line.contains("/dev/")) {
                        for (String split : line.split(" ")) {
                            if (split.startsWith("/dev")) {
                                try {
                                    RashrApp.SHELL.execCommand("ls " + split, true, false);
                                    mKernelPath = split;
                                    break;
                                } catch (FailedExecuteCommand e) {
                                    e.printStackTrace();
                                /*
                                         * Partition doesn't exist LOLLIPOP Workaround
                                         * File.exists() returns always false if file is in hidden FS
                                         * Lollipop marks /dev/.... as hidden
                                         */
                                }
                            }
                        }
                    }
                }
            }
            /**
                 * RecoveryPath not found so try it with this line
                 */
            if (mRecoveryPath.equals("")) {
                if (line.contains("/recovery")) {
                    if (line.contains("mtd")) {
                        mRecoveryType = PARTITION_TYPE_MTD;
                    } else if (line.contains("/dev/")) {
                        for (String split : line.split(" ")) {
                            if (split.startsWith("/dev") || split.startsWith("/system")) {
                                try {
                                    RashrApp.SHELL.execCommand("ls " + split, true, false);
                                    mRecoveryPath = split;
                                    break;
                                } catch (FailedExecuteCommand ignore) {
                                /**
                                         * Partition doesn't exist LOLLIPOP Workaround
                                         * File.exists() returns always false if file is in hidden FS
                                         * Lollipop marks /dev/.... as hidden
                                         */
                                }
                            }
                        }
                    }
                }
            }
        }
        br.close();
    } catch (Exception e) {
        RashrApp.ERRORS.add(Const.DEVICE_TAG + " Could not read LastLog.txt: " + e);
    }
/*
        if (mRecoveryVersion.equals(RECOVERY_VERSION_NOT_RECONGNIZED)) {
            try {
                File tmpVersionFile = new File(Const.FilesDir, ".version");
                mShell.execCommand("ls /cache/recovery/.version");
                mShell.execCommand("cp /cache/recovery/.version " + tmpVersionFile);
                mShell.execCommand("chmod 777 " + tmpVersionFile);
                BufferedReader br = new BufferedReader(new FileReader(tmpVersionFile));
                String line = "";
                while ((line = br.readLine()) != null) {

                }
            } catch (Exception ignore) {
                /**
                 * TWRP is not runned so .version cannot found or listed.
                 */
//    }
//}
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) ZipFile(java.util.zip.ZipFile) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 4 with FailedExecuteCommand

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

the class Command method addedToShell.

/**
     * This is called from Shell after adding it
     *
     * @param shell
     * @param id
     */
public void addedToShell(Shell shell, int id) throws FailedExecuteCommand {
    this.shell = shell;
    this.id = id;
    if (exitCode != 0)
        throw new FailedExecuteCommand(this);
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand)

Example 5 with FailedExecuteCommand

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

the class FlashUtil method onPreExecute.

protected void onPreExecute() {
    pDialog = new ProgressDialog(mContext);
    try {
        RashrApp.TOOLBOX.remount("/system", "rw");
        if (!isJobXZDual()) {
            if ((isJobRecovery() && RashrApp.DEVICE.isRecoveryMTD()) || isJobKernel() && RashrApp.DEVICE.isKernelMTD()) {
                RashrApp.SHELL.execCommand(Const.Busybox + " chmod 755 " + flash_image);
                RashrApp.SHELL.execCommand(Const.Busybox + " chmod 755 " + dump_image);
            }
        }
    } catch (FailedExecuteCommand e) {
        RashrApp.ERRORS.add(Const.FLASH_UTIL_TAG + " Failed to set permissions to flash_image and dump_image before flashing: " + e);
    }
    if (isJobFlash()) {
        pDialog.setTitle(R.string.flashing);
    } else if (isJobBackup()) {
        pDialog.setTitle(R.string.creating_bak);
    } else if (isJobRestore()) {
        pDialog.setTitle(R.string.restoring);
    } else if (isJobXZDual()) {
        pDialog.setTitle(R.string.installing_xzdual);
    }
    if (isJobBackup() && (isJobRecovery() ? RashrApp.DEVICE.isRecoveryDD() : RashrApp.DEVICE.isKernelDD())) {
        pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pDialog.setMax(getSizeOfFile(mPartition));
    } else {
        pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }
    pDialog.setMessage(mCustomIMG.getName());
    pDialog.setCancelable(false);
    pDialog.show();
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) ProgressDialog(android.app.ProgressDialog)

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