Commit d510224e authored by topjohnwu's avatar topjohnwu

Use notifications for hiding manager

parent e658f929
package com.topjohnwu.magisk.asyncs; package com.topjohnwu.magisk.asyncs;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.widget.Toast; import android.widget.Toast;
...@@ -10,6 +8,7 @@ import com.topjohnwu.magisk.Const; ...@@ -10,6 +8,7 @@ import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.components.Notifications;
import com.topjohnwu.magisk.utils.RootUtils; import com.topjohnwu.magisk.utils.RootUtils;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.ShellUtils; import com.topjohnwu.superuser.ShellUtils;
...@@ -24,6 +23,9 @@ import java.nio.CharBuffer; ...@@ -24,6 +23,9 @@ import java.nio.CharBuffer;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class PatchAPK { public class PatchAPK {
public static final String LOWERALPHA = "abcdefghijklmnopqrstuvwxyz"; public static final String LOWERALPHA = "abcdefghijklmnopqrstuvwxyz";
...@@ -125,18 +127,16 @@ public class PatchAPK { ...@@ -125,18 +127,16 @@ public class PatchAPK {
return true; return true;
} }
public static void hideManager(Activity activity) { public static void hideManager() {
ProgressDialog dialog = ProgressDialog.show(activity,
activity.getString(R.string.hide_manager_title),
activity.getString(R.string.hide_manager_msg));
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { 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(); boolean b = patchAndHide();
Data.mainHandler.post(() -> { mgr.cancel(Const.ID.DOWNLOAD_PROGRESS_ID);
dialog.cancel(); if (!b) Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
if (!b) {
Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG);
}
});
}); });
} }
} }
...@@ -77,7 +77,7 @@ public class SettingsFragment extends PreferenceFragmentCompat ...@@ -77,7 +77,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser"); PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
Preference hideManager = findPreference("hide"); Preference hideManager = findPreference("hide");
hideManager.setOnPreferenceClickListener(pref -> { hideManager.setOnPreferenceClickListener(pref -> {
PatchAPK.hideManager(requireActivity()); PatchAPK.hideManager();
return true; return true;
}); });
Preference restoreManager = findPreference("restore"); Preference restoreManager = findPreference("restore");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment