Search in sources :

Example 1 with FlashUtil

use of de.mkrtchyan.recoverytools.FlashUtil in project Rashr by DsLNeXuS.

the class FlashFragment method flashKernel.

/**
 * Flashing kernel using FlashUtil
 *
 * @param kernel kernel image (appropriated for this device)
 */
private void flashKernel(final File kernel) {
    if (kernel != null) {
        if (kernel.exists() && kernel.getName().endsWith(App.Device.getKernelExt()) && !kernel.isDirectory()) {
            final FlashUtil flashUtil = new FlashUtil(getContext(), kernel, FlashUtil.JOB_FLASH_KERNEL);
            flashUtil.execute();
        }
    }
}
Also used : FlashUtil(de.mkrtchyan.recoverytools.FlashUtil)

Example 2 with FlashUtil

use of de.mkrtchyan.recoverytools.FlashUtil 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(getContext());
        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_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());
                        View v = getView();
                        if (v == null)
                            return;
                        Snackbar.make(v, e.getMessage(), Snackbar.LENGTH_SHORT).show();
                    }
                    RecoveryDownloader.retry();
                }
            });
            RecoveryDownloader.setAskBeforeDownload(true);
            downloader.setChecksumUrl(fileUrl + ".md5");
            RecoveryDownloader.ask();
        } catch (MalformedURLException ignored) {
        }
    } else {
        flashRecovery(recovery);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) FlashUtil(de.mkrtchyan.recoverytools.FlashUtil) MalformedURLException(java.net.MalformedURLException) DialogInterface(android.content.DialogInterface) Downloader(de.mkrtchyan.utils.Downloader) DownloadDialog(de.mkrtchyan.utils.DownloadDialog) BindView(butterknife.BindView) View(android.view.View) AppCompatImageView(android.support.v7.widget.AppCompatImageView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) ScrollView(android.widget.ScrollView) URL(java.net.URL) JSONException(org.json.JSONException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) File(java.io.File)

Example 3 with FlashUtil

use of de.mkrtchyan.recoverytools.FlashUtil in project Rashr by DsLNeXuS.

the class FlashAsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View fragment = inflater.inflate(R.layout.fragment_flash_as, container, false);
    AppCompatTextView tvFlashAs = fragment.findViewById(R.id.tvFlashAs);
    tvFlashAs.setText(String.format(getString(R.string.flash_as).replace("%", "%%"), mImg.getName()));
    mOptAsRecovery = fragment.findViewById(R.id.optAsRecovery);
    mOptAsKernel = fragment.findViewById(R.id.optAsKernel);
    mButFlashAs = fragment.findViewById(R.id.bFlashAs);
    final AppCompatButton ButCancel = fragment.findViewById(R.id.bCancel);
    ButCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.finish();
        }
    });
    View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (view.getTag().toString().equals("recovery")) {
                mOptAsKernel.setChecked(false);
            } else {
                mOptAsRecovery.setChecked(false);
            }
            mButFlashAs.setEnabled(true);
        }
    };
    mButFlashAs.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mImg.exists()) {
                int job = mOptAsRecovery.isChecked() ? FlashUtil.JOB_FLASH_RECOVERY : FlashUtil.JOB_FLASH_KERNEL;
                final FlashUtil flashUtil = new FlashUtil(mActivity, mImg, job);
                flashUtil.setOnFlashListener(new FlashUtil.OnFlashListener() {

                    @Override
                    public void onSuccess() {
                        flashUtil.showRebootDialog();
                    }

                    @Override
                    public void onFail(Exception e) {
                        App.ERRORS.add(e.toString());
                        AlertDialog.Builder d = new AlertDialog.Builder(mContext);
                        d.setTitle(R.string.flash_error);
                        d.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });
                        if (e instanceof FlashUtil.ImageNotValidException) {
                            d.setMessage(getString(R.string.image_not_valid_message));
                            d.setNeutralButton(R.string.settings, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    mActivity.switchTo(new SettingsFragment());
                                }
                            });
                        } else if (e instanceof FlashUtil.ImageToBigException) {
                            FlashUtil.ImageToBigException exception = (FlashUtil.ImageToBigException) e;
                            // Size in MB
                            int sizeOfImage = exception.getCustomSize() / (1024 * 1024);
                            int sizeOfPart = exception.getPartitionSize() / (1024 * 1024);
                            d.setMessage(String.format(getString(R.string.image_to_big_message), sizeOfImage, sizeOfPart));
                            d.setNeutralButton(R.string.settings, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    mActivity.switchTo(new SettingsFragment());
                                }
                            });
                        } else {
                            d.setMessage(e.getMessage());
                        }
                        d.show();
                    }
                });
                flashUtil.execute();
            } else {
                mActivity.finish();
            }
        }
    });
    mOptAsRecovery.setOnClickListener(listener);
    mOptAsKernel.setOnClickListener(listener);
    ViewGroup parent;
    if (!App.Device.isRecoverySupported()) {
        if ((parent = (ViewGroup) mOptAsRecovery.getParent()) != null) {
            parent.removeView(mOptAsRecovery);
            mOptAsKernel.setChecked(true);
        }
    }
    if (!App.Device.isKernelSupported()) {
        if ((parent = (ViewGroup) mOptAsKernel.getParent()) != null) {
            parent.removeView(mOptAsKernel);
        }
    }
    return fragment;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FlashUtil(de.mkrtchyan.recoverytools.FlashUtil) DialogInterface(android.content.DialogInterface) ViewGroup(android.view.ViewGroup) AppCompatTextView(android.support.v7.widget.AppCompatTextView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) BindView(butterknife.BindView) View(android.view.View) AppCompatButton(android.support.v7.widget.AppCompatButton)

Example 4 with FlashUtil

use of de.mkrtchyan.recoverytools.FlashUtil in project Rashr by DsLNeXuS.

the class FlashFragment method flashRecovery.

/**
 * Flash recovery using FlashUtil
 *
 * @param recovery recovery image (appropriated for this device)
 */
private void flashRecovery(@NonNull final File recovery) {
    /* recovery needs to be a file and ends with the allowed extension */
    if (recovery.exists() && recovery.getName().endsWith(App.Device.getRecoveryExt()) && recovery.isFile()) {
        if (!App.Device.isFOTAFlashed() && !App.Device.isRecoveryOverRecovery()) {
            /* Flash not need to be handled specially */
            final FlashUtil flashUtil = new FlashUtil(mActivity, recovery, FlashUtil.JOB_FLASH_RECOVERY);
            flashUtil.setOnFlashListener(new FlashUtil.OnFlashListener() {

                @Override
                public void onSuccess() {
                }

                @Override
                public void onFail(Exception e) {
                    App.ERRORS.add(e.toString());
                    AlertDialog.Builder d = new AlertDialog.Builder(mContext);
                    d.setTitle(R.string.flash_error);
                    d.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
                    if (e instanceof FlashUtil.ImageNotValidException) {
                        d.setMessage(getString(R.string.image_not_valid_message));
                        d.setNeutralButton(R.string.settings, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                mActivity.switchTo(new SettingsFragment());
                            }
                        });
                    } else if (e instanceof FlashUtil.ImageToBigException) {
                        // Size in MB
                        int sizeOfImage = ((FlashUtil.ImageToBigException) e).getCustomSize() / (1024 * 1024);
                        int sizeOfPart = ((FlashUtil.ImageToBigException) e).getPartitionSize() / (1024 * 1024);
                        d.setMessage(String.format(getString(R.string.image_to_big_message), sizeOfImage, sizeOfPart));
                        d.setNeutralButton(R.string.settings, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                mActivity.switchTo(new SettingsFragment());
                            }
                        });
                    } else {
                        d.setMessage(e.getMessage());
                    }
                    d.show();
                }
            });
            flashUtil.execute();
        } else {
            /* Flashing needs to be handled specially (not standard flash method)*/
            if (App.Device.isFOTAFlashed()) {
                /* Show warning if FOTAKernel will be flashed */
                new AlertDialog.Builder(mContext).setTitle(R.string.warning).setMessage(R.string.fota).setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final FlashUtil flashUtil = new FlashUtil(getContext(), recovery, FlashUtil.JOB_FLASH_RECOVERY);
                        flashUtil.execute();
                    }
                }).setNegativeButton(R.string.negative, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).show();
            } else if (App.Device.isRecoveryOverRecovery()) {
                mActivity.switchTo(ScriptManagerFragment.newInstance(recovery));
            }
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FlashUtil(de.mkrtchyan.recoverytools.FlashUtil) DialogInterface(android.content.DialogInterface) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 5 with FlashUtil

use of de.mkrtchyan.recoverytools.FlashUtil in project Rashr by DsLNeXuS.

the class RecoverySystemFragment method flashRecovery.

/**
 * Flash recovery using FlashUtil
 *
 * @param recovery recovery image (appropriated for this device)
 */
private void flashRecovery(final File recovery) {
    if (recovery != null) {
        if (recovery.exists() && recovery.getName().endsWith(App.Device.getRecoveryExt()) && !recovery.isDirectory()) {
            if (!App.Device.isFOTAFlashed() && !App.Device.isRecoveryOverRecovery()) {
                /* Flash not need to be handled specially */
                final FlashUtil flashUtil = new FlashUtil(mActivity, recovery, FlashUtil.JOB_FLASH_RECOVERY);
                flashUtil.setOnFlashListener(new FlashUtil.OnFlashListener() {

                    @Override
                    public void onSuccess() {
                    }

                    @Override
                    public void onFail(Exception e) {
                        App.ERRORS.add(e.toString());
                        AlertDialog.Builder d = new AlertDialog.Builder(mContext);
                        d.setTitle(R.string.flash_error);
                        d.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });
                        if (e instanceof FlashUtil.ImageNotValidException) {
                            d.setMessage(getString(R.string.image_not_valid_message));
                            d.setNeutralButton(R.string.settings, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    mActivity.switchTo(new SettingsFragment());
                                }
                            });
                        } else if (e instanceof FlashUtil.ImageToBigException) {
                            // Size in MB
                            int sizeOfImage = ((FlashUtil.ImageToBigException) e).getCustomSize() / (1024 * 1024);
                            int sizeOfPart = ((FlashUtil.ImageToBigException) e).getPartitionSize() / (1024 * 1024);
                            d.setMessage(String.format(getString(R.string.image_to_big_message), sizeOfImage, sizeOfPart));
                            d.setNeutralButton(R.string.settings, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    mActivity.switchTo(new SettingsFragment());
                                }
                            });
                        } else {
                            d.setMessage(e.getMessage());
                        }
                        d.show();
                    }
                });
                flashUtil.execute();
            } else {
                /* Flashing needs to be handled specially (not standard flash method)*/
                if (App.Device.isFOTAFlashed()) {
                    /* Show warning if FOTAKernel will be flashed */
                    new AlertDialog.Builder(mContext).setTitle(R.string.warning).setMessage(R.string.fota).setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            final FlashUtil flashUtil = new FlashUtil(mActivity, recovery, FlashUtil.JOB_FLASH_RECOVERY);
                            flashUtil.execute();
                        }
                    }).setNegativeButton(R.string.negative, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).show();
                } else if (App.Device.isRecoveryOverRecovery()) {
                    mActivity.switchTo(ScriptManagerFragment.newInstance(recovery));
                }
            }
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FlashUtil(de.mkrtchyan.recoverytools.FlashUtil) DialogInterface(android.content.DialogInterface) JSONException(org.json.JSONException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

FlashUtil (de.mkrtchyan.recoverytools.FlashUtil)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 AppCompatTextView (android.support.v7.widget.AppCompatTextView)2 View (android.view.View)2 BindView (butterknife.BindView)2 JSONException (org.json.JSONException)2 AppCompatButton (android.support.v7.widget.AppCompatButton)1 AppCompatImageView (android.support.v7.widget.AppCompatImageView)1 ViewGroup (android.view.ViewGroup)1 ScrollView (android.widget.ScrollView)1 DownloadDialog (de.mkrtchyan.utils.DownloadDialog)1 Downloader (de.mkrtchyan.utils.Downloader)1 File (java.io.File)1 URL (java.net.URL)1 FailedExecuteCommand (org.sufficientlysecure.rootcommands.util.FailedExecuteCommand)1