From d510224e2ac1703fcca9bda5690eed9d2146943c Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 3 Dec 2018 02:24:07 -0500 Subject: [PATCH] Use notifications for hiding manager --- .../com/topjohnwu/magisk/asyncs/PatchAPK.java | 24 +++++++++---------- .../magisk/fragments/SettingsFragment.java | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java index 8920fb07e..9133774a2 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java @@ -1,7 +1,5 @@ package com.topjohnwu.magisk.asyncs; -import android.app.Activity; -import android.app.ProgressDialog; import android.os.AsyncTask; import android.widget.Toast; @@ -10,6 +8,7 @@ import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.components.Notifications; import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.ShellUtils; @@ -24,6 +23,9 @@ import java.nio.CharBuffer; import java.security.SecureRandom; import java.util.jar.JarEntry; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; + public class PatchAPK { public static final String LOWERALPHA = "abcdefghijklmnopqrstuvwxyz"; @@ -125,18 +127,16 @@ public class PatchAPK { return true; } - public static void hideManager(Activity activity) { - ProgressDialog dialog = ProgressDialog.show(activity, - activity.getString(R.string.hide_manager_title), - activity.getString(R.string.hide_manager_msg)); + public static void hideManager() { AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + MagiskManager mm = Data.MM(); + NotificationCompat.Builder progress = + Notifications.progress(mm.getString(R.string.hide_manager_title)); + NotificationManagerCompat mgr = NotificationManagerCompat.from(mm); + mgr.notify(Const.ID.DOWNLOAD_PROGRESS_ID, progress.build()); boolean b = patchAndHide(); - Data.mainHandler.post(() -> { - dialog.cancel(); - if (!b) { - Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG); - } - }); + mgr.cancel(Const.ID.DOWNLOAD_PROGRESS_ID); + if (!b) Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG); }); } } diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java index 2763afe3c..332acfcc5 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java @@ -77,7 +77,7 @@ public class SettingsFragment extends PreferenceFragmentCompat PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser"); Preference hideManager = findPreference("hide"); hideManager.setOnPreferenceClickListener(pref -> { - PatchAPK.hideManager(requireActivity()); + PatchAPK.hideManager(); return true; }); Preference restoreManager = findPreference("restore");