Search in sources :

Example 16 with MagiskManager

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

the class ShowUI method magiskInstallDialog.

public static void magiskInstallDialog(Activity activity) {
    MagiskManager mm = Utils.getMagiskManager(activity);
    String filename = Utils.fmt("Magisk-v%s(%d).zip", mm.remoteMagiskVersionString, mm.remoteMagiskVersionCode);
    new AlertDialogBuilder(activity).setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk))).setMessage(mm.getString(R.string.repo_install_msg, filename)).setCancelable(true).setPositiveButton(R.string.install, (d, i) -> {
        List<String> options = new ArrayList<>();
        options.add(mm.getString(R.string.download_zip_only));
        options.add(mm.getString(R.string.patch_boot_file));
        if (Shell.rootAccess()) {
            options.add(mm.getString(R.string.direct_install));
        }
        String s = Utils.cmd("echo $SLOT");
        if (s != null) {
            options.add(mm.getString(R.string.install_second_slot));
        }
        char[] slot = s == null ? null : s.toCharArray();
        new AlertDialog.Builder(activity).setTitle(R.string.select_method).setItems(options.toArray(new String[0]), (dialog, idx) -> {
            String boot;
            DownloadReceiver receiver = null;
            switch(idx) {
                case 1:
                    if (mm.remoteMagiskVersionCode < 1400) {
                        MagiskManager.toast(R.string.no_boot_file_patch_support, Toast.LENGTH_LONG);
                        return;
                    }
                    MagiskManager.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("*/*");
                    ((com.topjohnwu.magisk.components.Activity) activity).startActivityForResult(intent, Const.ID.SELECT_BOOT, (requestCode, resultCode, data) -> {
                        if (requestCode == Const.ID.SELECT_BOOT && resultCode == Activity.RESULT_OK && data != null) {
                            Utils.dlAndReceive(activity, new DownloadReceiver() {

                                @Override
                                public void onDownloadDone(Uri uri) {
                                    Intent intent = new Intent(mm, FlashActivity.class);
                                    intent.setData(uri).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(Const.Key.FLASH_SET_BOOT, data.getData()).putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT);
                                    mm.startActivity(intent);
                                }
                            }, mm.magiskLink, filename);
                        }
                    });
                    return;
                case 0:
                    receiver = new DownloadReceiver() {

                        @Override
                        public void onDownloadDone(Uri uri) {
                            Utils.showUriSnack(activity, uri);
                        }
                    };
                    break;
                case 2:
                    boot = mm.bootBlock;
                    if (boot == null)
                        return;
                    receiver = new DownloadReceiver() {

                        @Override
                        public void onDownloadDone(Uri uri) {
                            Intent intent = new Intent(mm, FlashActivity.class);
                            intent.setData(uri).putExtra(Const.Key.FLASH_SET_BOOT, boot).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
                            activity.startActivity(intent);
                        }
                    };
                    break;
                case 3:
                    assert (slot != null);
                    // Choose the other slot
                    if (slot[1] == 'a')
                        slot[1] = 'b';
                    else
                        slot[1] = 'a';
                    // Then find the boot image again
                    boot = Utils.cmd("SLOT=" + String.valueOf(slot) + "; find_boot_image;" + "echo \"$BOOTIMAGE\"");
                    Shell.Async.su("mount_partitions");
                    if (boot == null)
                        return;
                    receiver = new DownloadReceiver() {

                        @Override
                        public void onDownloadDone(Uri uri) {
                            Intent intent = new Intent(mm, FlashActivity.class);
                            intent.setData(uri).putExtra(Const.Key.FLASH_SET_BOOT, boot).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
                            activity.startActivity(intent);
                        }
                    };
                default:
            }
            Utils.dlAndReceive(activity, receiver, mm.magiskLink, filename);
        }).show();
    }).setNeutralButton(R.string.release_notes, (d, i) -> {
        if (mm.releaseNoteLink != null) {
            Intent openLink = new Intent(Intent.ACTION_VIEW, Uri.parse(mm.releaseNoteLink));
            openLink.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mm.startActivity(openLink);
        }
    }).setNegativeButton(R.string.no_thanks, null).show();
}
Also used : Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) Uri(android.net.Uri) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) FlashActivity(com.topjohnwu.magisk.FlashActivity) RebootReceiver(com.topjohnwu.magisk.receivers.RebootReceiver) Shell(com.topjohnwu.superuser.Shell) ManagerUpdate(com.topjohnwu.magisk.receivers.ManagerUpdate) ArrayList(java.util.ArrayList) R(com.topjohnwu.magisk.R) ShellUtils(com.topjohnwu.superuser.ShellUtils) Manifest(android.Manifest) Handler(android.os.Handler) Toast(android.widget.Toast) MagiskManager(com.topjohnwu.magisk.MagiskManager) SplashActivity(com.topjohnwu.magisk.SplashActivity) RestoreImages(com.topjohnwu.magisk.asyncs.RestoreImages) NotificationManager(android.app.NotificationManager) DownloadReceiver(com.topjohnwu.magisk.receivers.DownloadReceiver) IOException(java.io.IOException) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) NotificationCompat(android.support.v4.app.NotificationCompat) Activity(android.app.Activity) InputStream(java.io.InputStream) FlashActivity(com.topjohnwu.magisk.FlashActivity) MagiskManager(com.topjohnwu.magisk.MagiskManager) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) FlashActivity(com.topjohnwu.magisk.FlashActivity) SplashActivity(com.topjohnwu.magisk.SplashActivity) Activity(android.app.Activity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) DownloadReceiver(com.topjohnwu.magisk.receivers.DownloadReceiver) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with MagiskManager

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

the class ShowUI method managerInstallDialog.

public static void managerInstallDialog(Activity activity) {
    MagiskManager mm = Utils.getMagiskManager(activity);
    String filename = Utils.fmt("MagiskManager-v%s(%d).apk", mm.remoteManagerVersionString, mm.remoteManagerVersionCode);
    new AlertDialogBuilder(activity).setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name))).setMessage(mm.getString(R.string.repo_install_msg, filename)).setCancelable(true).setPositiveButton(R.string.install, (d, i) -> {
        Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
            Intent intent = new Intent(mm, ManagerUpdate.class);
            intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
            intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename);
            mm.sendBroadcast(intent);
        });
    }).setNegativeButton(R.string.no_thanks, null).show();
}
Also used : AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) MagiskManager(com.topjohnwu.magisk.MagiskManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 18 with MagiskManager

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

the class ShowUI method dtboPatchedNotification.

public static void dtboPatchedNotification() {
    MagiskManager mm = MagiskManager.get();
    Intent intent = new Intent(mm, RebootReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
    builder.setSmallIcon(R.drawable.ic_magisk).setContentTitle(mm.getString(R.string.dtbo_patched_title)).setContentText(mm.getString(R.string.dtbo_patched_reboot)).setVibrate(new long[] { 0, 100, 100, 100 }).addAction(R.drawable.ic_refresh, mm.getString(R.string.reboot), pendingIntent);
    NotificationManager notificationManager = (NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Const.ID.DTBO_NOTIFICATION_ID, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) MagiskManager(com.topjohnwu.magisk.MagiskManager) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 19 with MagiskManager

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

the class ShowUI method managerUpdateNotification.

public static void managerUpdateNotification() {
    MagiskManager mm = MagiskManager.get();
    String filename = Utils.fmt("MagiskManager-v%s(%d).apk", mm.remoteManagerVersionString, mm.remoteManagerVersionCode);
    Intent intent = new Intent(mm, ManagerUpdate.class);
    intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
    intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, Const.ID.APK_UPDATE_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mm, Const.ID.NOTIFICATION_CHANNEL);
    builder.setSmallIcon(R.drawable.ic_magisk).setContentTitle(mm.getString(R.string.manager_update_title)).setContentText(mm.getString(R.string.manager_download_install)).setVibrate(new long[] { 0, 100, 100, 100 }).setAutoCancel(true).setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) mm.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Const.ID.APK_UPDATE_NOTIFICATION_ID, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) MagiskManager(com.topjohnwu.magisk.MagiskManager) AlertDialogBuilder(com.topjohnwu.magisk.components.AlertDialogBuilder) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 20 with MagiskManager

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

the class Utils method dumpPrefs.

public static void dumpPrefs() {
    MagiskManager mm = MagiskManager.get();
    // Flush prefs to disk
    mm.prefs.edit().commit();
    File xml = new File(mm.getFilesDir().getParent() + "/shared_prefs", mm.getPackageName() + "_preferences.xml");
    Shell.Sync.su(fmt("for usr in /data/user/*; do cat %s > ${usr}/%s; done", xml, Const.MANAGER_CONFIGS));
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager) SuFile(com.topjohnwu.superuser.io.SuFile) File(java.io.File)

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