Search in sources :

Example 1 with Shell

use of com.topjohnwu.superuser.Shell in project MagiskManager by topjohnwu.

the class MagiskManager method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Shell.setFlags(Shell.FLAG_MOUNT_MASTER);
    Shell.verboseLogging(BuildConfig.DEBUG);
    BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
    Shell.setInitializer(new Shell.Initializer() {

        @Override
        public void onRootShellInit(@NonNull Shell shell) {
            try (InputStream utils = getAssets().open(Const.UTIL_FUNCTIONS);
                InputStream sudb = getResources().openRawResource(R.raw.sudb)) {
                shell.loadInputStream(null, null, utils);
                shell.loadInputStream(null, null, sudb);
            } catch (IOException e) {
                e.printStackTrace();
            }
            shell.run(null, null, "mount_partitions", "run_migrations");
        }
    });
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Handle duplicate package
    if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
        try {
            getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0);
            Intent intent = getPackageManager().getLaunchIntentForPackage(Const.ORIG_PKG_NAME);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            return;
        } catch (PackageManager.NameNotFoundException ignored) {
        /* Expected */
        }
    }
    suDB = SuDatabaseHelper.getInstance(this);
    String pkg = suDB.getStrings(Const.Key.SU_REQUESTER, Const.ORIG_PKG_NAME);
    if (getPackageName().equals(Const.ORIG_PKG_NAME) && !pkg.equals(Const.ORIG_PKG_NAME)) {
        suDB.setStrings(Const.Key.SU_REQUESTER, null);
        Utils.uninstallPkg(pkg);
        suDB = SuDatabaseHelper.getInstance(this);
    }
    repoDB = new RepoDatabaseHelper(this);
    defaultLocale = Locale.getDefault();
    setLocale();
    loadConfig();
}
Also used : Shell(com.topjohnwu.superuser.Shell) PackageManager(android.content.pm.PackageManager) RepoDatabaseHelper(com.topjohnwu.magisk.database.RepoDatabaseHelper) InputStream(java.io.InputStream) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File)

Aggregations

Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 RepoDatabaseHelper (com.topjohnwu.magisk.database.RepoDatabaseHelper)1 Shell (com.topjohnwu.superuser.Shell)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1