From 45765e292da15d1dcbd74393479bb0db37edeaaa Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 6 Feb 2017 08:16:48 +0800 Subject: [PATCH] Final fixes --- app/src/main/assets/magisk_uninstaller.sh | 1 + .../com/topjohnwu/magisk/InstallFragment.java | 79 ++++++++++--------- .../com/topjohnwu/magisk/SplashActivity.java | 8 +- .../magisk/superuser/SuReceiver.java | 31 ++++---- 4 files changed, 61 insertions(+), 58 deletions(-) diff --git a/app/src/main/assets/magisk_uninstaller.sh b/app/src/main/assets/magisk_uninstaller.sh index 5eec40851..8b205079a 100644 --- a/app/src/main/assets/magisk_uninstaller.sh +++ b/app/src/main/assets/magisk_uninstaller.sh @@ -1,5 +1,6 @@ #!/system/bin/sh +[ -z $BOOTMODE ] && BOOTMODE=false TMPDIR=/tmp ($BOOTMODE) && TMPDIR=/dev/tmp diff --git a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java index cd0cf51c0..de908be9d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java @@ -82,44 +82,49 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi .setNegativeButton(R.string.no_thanks, null) .show(); }); - uninstallButton.setOnClickListener(vi -> { - Utils.getAlertDialogBuilder(getActivity()) - .setTitle("Uninstall Magisk") - .setMessage("This will remove all modules, MagiskSU, and potentially re-encrypt your device\nAre you sure to process?") - .setPositiveButton(R.string.yes, (dialogInterface, i) -> { - try { - InputStream in = getActivity().getAssets().open(UNINSTALLER); - File uninstaller = new File(getActivity().getCacheDir().getAbsolutePath() + "/" + UNINSTALLER); - FileOutputStream out = new FileOutputStream(uninstaller); - byte[] bytes = new byte[1024]; - int read; - while ((read = in.read(bytes)) != -1) - out.write(bytes, 0, read); - in.close(); - out.close(); - ProgressDialog progress = new ProgressDialog(getActivity()); - progress.setTitle(R.string.reboot); - progress.show(); - new CountDownTimer(5000, 1000) { - @Override - public void onTick(long millisUntilFinished) { - progress.setMessage(getString(R.string.reboot_countdown, millisUntilFinished / 1000)); - } + if (Global.Info.magiskVersion < 10.3) { + uninstallButton.setVisibility(View.GONE); + } else { + uninstallButton.setOnClickListener(vi -> { + Utils.getAlertDialogBuilder(getActivity()) + .setTitle("Uninstall Magisk") + .setMessage("This will remove all modules, MagiskSU, and potentially re-encrypt your device\nAre you sure to process?") + .setPositiveButton(R.string.yes, (dialogInterface, i) -> { + try { + InputStream in = getActivity().getAssets().open(UNINSTALLER); + File uninstaller = new File(getActivity().getCacheDir().getAbsolutePath() + "/" + UNINSTALLER); + FileOutputStream out = new FileOutputStream(uninstaller); + byte[] bytes = new byte[1024]; + int read; + while ((read = in.read(bytes)) != -1) + out.write(bytes, 0, read); + in.close(); + out.close(); + ProgressDialog progress = new ProgressDialog(getActivity()); + progress.setTitle(R.string.reboot); + progress.show(); + new CountDownTimer(5000, 1000) { + @Override + public void onTick(long millisUntilFinished) { + progress.setMessage(getString(R.string.reboot_countdown, millisUntilFinished / 1000)); + } + + @Override + public void onFinish() { + progress.setMessage(getString(R.string.reboot_countdown, 0)); + Shell.su(true, "cp -af " + uninstaller + " /cache/" + UNINSTALLER, + "reboot"); + } + }.start(); + } catch (IOException e) { + e.printStackTrace(); + } + }) + .setNegativeButton(R.string.no_thanks, null) + .show(); + }); + } - @Override - public void onFinish() { - progress.setMessage(getString(R.string.reboot_countdown, 0)); - Shell.su(true, "cp -af " + uninstaller + " /cache/" + UNINSTALLER, - "reboot"); - } - }.start(); - } catch (IOException e) { - e.printStackTrace(); - } - }) - .setNegativeButton(R.string.no_thanks, null) - .show(); - }); if (Global.Events.blockDetectionDone.isTriggered) { updateUI(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index d3bf60217..67f3b40f7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -16,14 +16,9 @@ public class SplashActivity extends AppCompatActivity { // Init the info and configs and root shell Global.init(getApplicationContext()); - // Start MagiskHide if not started at boot - if (Global.Configs.magiskHide && !Global.Info.disabled && Global.Info.magiskVersion > 10.3) - new Async.MagiskHide().enable(); - // Now fire all async tasks - new Async.LoadApps(getPackageManager()).exec(); - new Async.GetBootBlocks().exec(); new Async.CheckUpdates().exec(); + new Async.GetBootBlocks().exec(); new Async.LoadModules() { @Override protected void onPostExecute(Void v) { @@ -31,6 +26,7 @@ public class SplashActivity extends AppCompatActivity { new Async.LoadRepos(getApplicationContext()).exec(); } }.exec(); + new Async.LoadApps(getPackageManager()).exec(); // Preparation done, now start main activity Intent intent = new Intent(getApplicationContext(), MainActivity.class); diff --git a/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java b/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java index 26e7ccf1e..a7f7a9a0f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java @@ -44,22 +44,23 @@ public class SuReceiver extends BroadcastReceiver { SuLogEntry log = new SuLogEntry(policy); - if (policy.notification && Global.Configs.suNotificationType == TOAST) { - String message; - switch (action) { - case "allow": - message = context.getString(R.string.su_allow_toast, policy.appName); - log.action = true; - break; - case "deny": - message = context.getString(R.string.su_deny_toast, policy.appName); - log.action = false; - break; - default: - return; - } - Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); + String message; + switch (action) { + case "allow": + message = context.getString(R.string.su_allow_toast, policy.appName); + log.action = true; + break; + case "deny": + message = context.getString(R.string.su_deny_toast, policy.appName); + log.action = false; + break; + default: + return; } + + if (policy.notification && Global.Configs.suNotificationType == TOAST) + Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); + if (policy.logging) { toUid = intent.getIntExtra("to.uid", -1); if (toUid < 0) return;