diff --git a/app-core/src/main/java/com/topjohnwu/magisk/App.java b/app-core/src/main/java/com/topjohnwu/magisk/App.java index aaf3d52bb..43de3d1bb 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/App.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/App.java @@ -3,6 +3,7 @@ package com.topjohnwu.magisk; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.os.AsyncTask; import android.preference.PreferenceManager; import com.topjohnwu.magisk.core.BuildConfig; @@ -14,10 +15,13 @@ import com.topjohnwu.net.Networking; import com.topjohnwu.superuser.ContainerApp; import com.topjohnwu.superuser.Shell; +import java.util.concurrent.ThreadPoolExecutor; + public class App extends ContainerApp { public static App self; public boolean init = false; + public static ThreadPoolExecutor THREAD_POOL; // Global resources public SharedPreferences prefs; @@ -29,6 +33,7 @@ public class App extends ContainerApp { Shell.Config.verboseLogging(BuildConfig.DEBUG); Shell.Config.addInitializers(RootUtils.class); Shell.Config.setTimeout(2); + THREAD_POOL = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR; } @Override diff --git a/app-core/src/main/java/com/topjohnwu/magisk/tasks/FlashZip.java b/app-core/src/main/java/com/topjohnwu/magisk/tasks/FlashZip.java index 68353face..265a9d761 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/tasks/FlashZip.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/tasks/FlashZip.java @@ -1,7 +1,6 @@ package com.topjohnwu.magisk.tasks; import android.net.Uri; -import android.os.AsyncTask; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Const; @@ -70,7 +69,7 @@ public abstract class FlashZip { } public void exec() { - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + App.THREAD_POOL.execute(() -> { boolean success = false; try { success = flash(); diff --git a/app-core/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java b/app-core/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java index 9dbb683f2..c5c47e4f9 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java @@ -1,7 +1,6 @@ package com.topjohnwu.magisk.tasks; import android.net.Uri; -import android.os.AsyncTask; import android.os.Build; import android.text.TextUtils; @@ -308,7 +307,7 @@ public abstract class MagiskInstaller { protected abstract void onResult(boolean success); public void exec() { - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + App.THREAD_POOL.execute(() -> { boolean b = operations(); UiThreadHandler.run(() -> onResult(b)); }); diff --git a/app-core/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java b/app-core/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java index 34b97d7da..bb62dad26 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java @@ -1,7 +1,6 @@ package com.topjohnwu.magisk.tasks; import android.database.Cursor; -import android.os.AsyncTask; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; @@ -142,7 +141,7 @@ public class UpdateRepos { public void exec(boolean force) { Topic.reset(Topic.REPO_LOAD_DONE); - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + App.THREAD_POOL.execute(() -> { cached = Collections.synchronizedSet(app.repoDB.getRepoIDSet()); threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE); diff --git a/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java index fec2b70b1..d2cb23f54 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -8,7 +8,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; -import android.os.AsyncTask; import android.os.Build; import android.provider.OpenableColumns; import android.widget.Toast; @@ -97,7 +96,7 @@ public class Utils { public static void loadModules() { Topic.reset(Topic.MODULE_LOAD_DONE); - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + App.THREAD_POOL.execute(() -> { Map moduleMap = new ValueSortedMap<>(); SuFile path = new SuFile(Const.MAGISK_PATH); SuFile[] modules = path.listFiles( diff --git a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java index e04a88680..3a38ebd51 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.text.TextUtils; import com.topjohnwu.magisk.components.BaseActivity; -import com.topjohnwu.magisk.tasks.CheckUpdates; import com.topjohnwu.magisk.tasks.UpdateRepos; import com.topjohnwu.magisk.uicomponents.Notifications; import com.topjohnwu.magisk.uicomponents.Shortcuts; diff --git a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index e24b99299..f23c5561e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -151,7 +151,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter { - /* Devices with DTBO might want to patch dtbo.img. - * However, that is not possible if Magisk is installed by - * patching boot image with Magisk Manager and flashed via - * fastboot, since at that time we do not have root. - * Check for dtbo status every boot time, and prompt user - * to reboot if dtbo wasn't patched and patched by Magisk Manager. - * */ - if (Shell.rootAccess() && ShellUtils.fastCmdResult("mm_patch_dtbo")) + /* Devices with DTBO might want to patch dtbo.img. + * However, that is not possible if Magisk is installed by + * patching boot image with Magisk Manager and flashed via + * fastboot, since at that time we do not have root. + * Check for dtbo status every boot time, and prompt user + * to reboot if dtbo wasn't patched and patched by Magisk Manager. + * */ + Shell.su("mm_patch_dtbo").submit(result -> { + if (result.isSuccess()) Notifications.dtboPatched(); }); break; diff --git a/app/src/full/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java b/app/src/full/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java index 7be9ed69f..61748bc8e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java +++ b/app/src/full/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java @@ -5,12 +5,10 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.os.AsyncTask; import android.view.LayoutInflater; import android.view.View; import com.caverock.androidsvg.SVG; -import com.caverock.androidsvg.SVGParseException; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Utils; @@ -22,6 +20,7 @@ import com.topjohnwu.superuser.ShellUtils; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.concurrent.Callable; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -72,32 +71,29 @@ public class MarkDownWindow { @Override public void load(@NonNull String url, @NonNull AsyncDrawable asyncDrawable) { - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + App.THREAD_POOL.submit((Callable) () -> { InputStream is = Networking.get(url).execForInputStream().getResult(); if (is == null) - return; + return null; ByteArrayStream buf = new ByteArrayStream(); buf.readFrom(is); // First try default drawables Drawable drawable = Drawable.createFromStream(buf.getInputStream(), ""); if (drawable == null) { // SVG - try { - SVG svg = SVG.getFromInputStream(buf.getInputStream()); - int width = Utils.dpInPx((int) svg.getDocumentWidth()); - int height = Utils.dpInPx((int) svg.getDocumentHeight()); - final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); - final Canvas canvas = new Canvas(bitmap); - float density = App.self.getResources().getDisplayMetrics().density; - canvas.scale(density, density); - svg.renderToCanvas(canvas); - drawable = new BitmapDrawable(App.self.getResources(), bitmap); - } catch (SVGParseException ignored) {} - } - if (drawable != null) { - drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); - asyncDrawable.setResult(drawable); + SVG svg = SVG.getFromInputStream(buf.getInputStream()); + int width = Utils.dpInPx((int) svg.getDocumentWidth()); + int height = Utils.dpInPx((int) svg.getDocumentHeight()); + final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); + final Canvas canvas = new Canvas(bitmap); + float density = App.self.getResources().getDisplayMetrics().density; + canvas.scale(density, density); + svg.renderToCanvas(canvas); + drawable = new BitmapDrawable(App.self.getResources(), bitmap); } + drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); + asyncDrawable.setResult(drawable); + return null; }); } diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java b/app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java index f053166bb..4c418b4da 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java @@ -1,7 +1,5 @@ package com.topjohnwu.magisk.utils; -import android.os.AsyncTask; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Config; @@ -32,7 +30,7 @@ public class DownloadApp { ProgressNotification progress = new ProgressNotification(name); listener.progress = progress; Networking.get(Config.managerLink) - .setExecutor(AsyncTask.THREAD_POOL_EXECUTOR) + .setExecutor(App.THREAD_POOL) .setDownloadProgressListener(progress) .setErrorHandler((conn, e) -> progress.dlFail()) .getAsFile(apk, listener); diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/PatchAPK.java b/app/src/full/java/com/topjohnwu/magisk/utils/PatchAPK.java index 379b24358..f3863643e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/PatchAPK.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/PatchAPK.java @@ -1,6 +1,5 @@ package com.topjohnwu.magisk.utils; -import android.os.AsyncTask; import android.widget.Toast; import com.topjohnwu.magisk.App; @@ -136,14 +135,14 @@ public class PatchAPK { } public static void hideManager() { - AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> { + App.THREAD_POOL.execute(() -> { App app = App.self; NotificationCompat.Builder progress = Notifications.progress(app.getString(R.string.hide_manager_title)); Notifications.mgr.notify(Const.ID.HIDE_MANAGER_NOTIFICATION_ID, progress.build()); - boolean b = patchAndHide(); + if(!patchAndHide()) + Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG); Notifications.mgr.cancel(Const.ID.HIDE_MANAGER_NOTIFICATION_ID); - if (!b) Utils.toast(R.string.hide_manager_fail_toast, Toast.LENGTH_LONG); }); } }