Search in sources :

Example 1 with MagiskManager

use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.

the class FlashZip method doInBackground.

@Override
protected Integer doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    try {
        console.add("- Copying zip to temp directory");
        mCachedFile.delete();
        try (InputStream in = mm.getContentResolver().openInputStream(mUri);
            OutputStream out = new BufferedOutputStream(new FileOutputStream(mCachedFile))) {
            if (in == null)
                throw new FileNotFoundException();
            InputStream buf = new BufferedInputStream(in);
            ShellUtils.pump(buf, out);
        } catch (FileNotFoundException e) {
            console.add("! Invalid Uri");
            throw e;
        } catch (IOException e) {
            console.add("! Cannot copy to cache");
            throw e;
        }
        if (!unzipAndCheck())
            return 0;
        console.add("- Installing " + Utils.getNameFromUri(mm, mUri));
        Shell.Sync.su(console, logs, "cd " + mCachedFile.getParent(), "BOOTMODE=true sh update-binary dummy 1 " + mCachedFile + " || echo 'Failed!'");
        if (TextUtils.equals(console.get(console.size() - 1), "Failed!"))
            return -1;
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
    console.add("- All done!");
    return 1;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) MagiskManager(com.topjohnwu.magisk.MagiskManager) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with MagiskManager

use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.

the class HideManager method doInBackground.

@Override
protected Boolean doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    // Generate a new unhide app with random package name
    SuFile repack = new SuFile("/data/local/tmp/repack.apk", true);
    String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length());
    try {
        // Read whole APK into memory
        JarMap apk = new JarMap(new FileInputStream(mm.getPackageCodePath()));
        JarEntry je = new JarEntry(Const.ANDROID_MANIFEST);
        byte[] xml = apk.getRawData(je);
        if (!findAndPatch(xml, Const.ORIG_PKG_NAME, pkg))
            return false;
        if (!findAndPatch(xml, Const.ORIG_PKG_NAME + ".provider", pkg + ".provider"))
            return false;
        // Write in changes
        apk.getOutputStream(je).write(xml);
        // Sign the APK
        ZipUtils.signZip(apk, new SuFileOutputStream(repack));
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    // Install the application
    if (!ShellUtils.fastCmdResult(Shell.getShell(), "pm install " + repack))
        return false;
    repack.delete();
    mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
    Utils.dumpPrefs();
    Utils.uninstallPkg(Const.ORIG_PKG_NAME);
    return true;
}
Also used : JarMap(com.topjohnwu.utils.JarMap) MagiskManager(com.topjohnwu.magisk.MagiskManager) SuFileOutputStream(com.topjohnwu.superuser.io.SuFileOutputStream) SuFile(com.topjohnwu.superuser.io.SuFile) JarEntry(java.util.jar.JarEntry) FileInputStream(java.io.FileInputStream)

Example 3 with MagiskManager

use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.

the class CheckUpdates method doInBackground.

@Override
protected Void doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    String jsonStr = "";
    switch(mm.updateChannel) {
        case Const.Value.STABLE_CHANNEL:
            jsonStr = WebService.getString(Const.Url.STABLE_URL);
            break;
        case Const.Value.BETA_CHANNEL:
            jsonStr = WebService.getString(Const.Url.BETA_URL);
            break;
        case Const.Value.CUSTOM_CHANNEL:
            jsonStr = WebService.getString(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, ""));
            break;
    }
    try {
        JSONObject json = new JSONObject(jsonStr);
        JSONObject magisk = json.getJSONObject("magisk");
        mm.remoteMagiskVersionString = magisk.getString("version");
        mm.remoteMagiskVersionCode = magisk.getInt("versionCode");
        mm.magiskLink = magisk.getString("link");
        mm.releaseNoteLink = magisk.getString("note");
        JSONObject manager = json.getJSONObject("app");
        mm.remoteManagerVersionString = manager.getString("version");
        mm.remoteManagerVersionCode = manager.getInt("versionCode");
        mm.managerLink = manager.getString("link");
    } catch (JSONException ignored) {
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) MagiskManager(com.topjohnwu.magisk.MagiskManager) JSONException(org.json.JSONException)

Example 4 with MagiskManager

use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.

the class LoadModules method doInBackground.

@Override
protected Void doInBackground(Void... voids) {
    MagiskManager mm = MagiskManager.get();
    mm.moduleMap = new ValueSortedMap<>();
    for (String path : getModList()) {
        Module module = new Module(path);
        mm.moduleMap.put(module.getId(), module);
    }
    return null;
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager) Module(com.topjohnwu.magisk.container.Module)

Example 5 with MagiskManager

use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.

the class Activity method onRequestPermissionsResult.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    MagiskManager mm = getMagiskManager();
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        if (mm.permissionGrantCallback != null) {
            mm.permissionGrantCallback.run();
        }
    }
    mm.permissionGrantCallback = null;
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager)

Aggregations

MagiskManager (com.topjohnwu.magisk.MagiskManager)21 IOException (java.io.IOException)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 AlertDialogBuilder (com.topjohnwu.magisk.components.AlertDialogBuilder)6 InputStream (java.io.InputStream)6 NotificationManager (android.app.NotificationManager)5 NotificationCompat (android.support.v4.app.NotificationCompat)5 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)5 SuFile (com.topjohnwu.superuser.io.SuFile)4 Activity (android.app.Activity)3 Shell (com.topjohnwu.superuser.Shell)3 ShellUtils (com.topjohnwu.superuser.ShellUtils)3 BufferedInputStream (java.io.BufferedInputStream)3 BufferedOutputStream (java.io.BufferedOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 Manifest (android.Manifest)2