Search in sources :

Example 1 with Toolbox

use of org.sufficientlysecure.rootcommands.Toolbox 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)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1 Resources (android.content.res.Resources)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)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 File (java.io.File)1 IOException (java.io.IOException)1 Toolbox (org.sufficientlysecure.rootcommands.Toolbox)1 FailedExecuteCommand (org.sufficientlysecure.rootcommands.util.FailedExecuteCommand)1