From 47c860142ed333d9a20296694f2380491c8b815f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 16 Sep 2018 00:08:13 -0400 Subject: [PATCH] Use ClassMaps to prevent errors --- .../full/java/com/topjohnwu/magisk/Data.java | 30 +++++++++++++++++++ .../com/topjohnwu/magisk/MainActivity.java | 6 ++-- .../com/topjohnwu/magisk/SplashActivity.java | 7 ++--- .../magisk/asyncs/ProcessRepoZip.java | 3 +- .../components/InstallMethodDialog.java | 7 +++-- .../components/ManagerInstallDialog.java | 4 +-- .../magisk/components/UninstallDialog.java | 3 +- .../magisk/fragments/ModulesFragment.java | 4 ++- .../magisk/receivers/ShortcutReceiver.java | 9 +++--- .../magisk/services/OnBootService.java | 3 +- .../magisk/utils/NotificationMgr.java | 13 ++++---- 11 files changed, 63 insertions(+), 26 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/Data.java b/app/src/full/java/com/topjohnwu/magisk/Data.java index 316babc0c..c73e561a0 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Data.java +++ b/app/src/full/java/com/topjohnwu/magisk/Data.java @@ -5,6 +5,14 @@ import android.os.Handler; import android.os.Looper; import android.util.Xml; +import com.topjohnwu.magisk.components.AboutCardRow; +import com.topjohnwu.magisk.receivers.BootReceiver; +import com.topjohnwu.magisk.receivers.ManagerUpdate; +import com.topjohnwu.magisk.receivers.PackageReceiver; +import com.topjohnwu.magisk.receivers.RebootReceiver; +import com.topjohnwu.magisk.receivers.ShortcutReceiver; +import com.topjohnwu.magisk.services.OnBootService; +import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; @@ -18,11 +26,14 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.io.IOException; import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; public class Data { // Global app instance public static WeakReference weakApp; public static Handler mainHandler = new Handler(Looper.getMainLooper()); + public static Map classMap = new HashMap<>(); // Current status public static String magiskVersionString; @@ -60,6 +71,25 @@ public class Data { public static int updateChannel; public static int repoOrder; + static { + classMap.put(MagiskManager.class, a.a.class); + classMap.put(MainActivity.class, a.b.class); + classMap.put(SplashActivity.class, a.c.class); + classMap.put(AboutActivity.class, a.d.class); + classMap.put(DonationActivity.class, a.e.class); + classMap.put(FlashActivity.class, a.f.class); + classMap.put(NoUIActivity.class, a.g.class); + classMap.put(BootReceiver.class, a.h.class); + classMap.put(PackageReceiver.class, a.i.class); + classMap.put(ManagerUpdate.class, a.j.class); + classMap.put(RebootReceiver.class, a.k.class); + classMap.put(ShortcutReceiver.class, a.l.class); + classMap.put(OnBootService.class, a.m.class); + classMap.put(UpdateCheckService.class, a.n.class); + classMap.put(AboutCardRow.class, a.o.class); + + } + public static void loadMagiskInfo() { try { magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0]; diff --git a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java index 776f7a7b2..2042d3acd 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java @@ -48,7 +48,7 @@ public class MainActivity extends BaseActivity @Override protected void onCreate(final Bundle savedInstanceState) { if (!mm.hasInit) { - startActivity(new Intent(this, a.c.class)); + startActivity(new Intent(this, Data.classMap.get(SplashActivity.class))); finish(); } @@ -194,11 +194,11 @@ public class MainActivity extends BaseActivity displayFragment(new SettingsFragment(), true); break; case R.id.app_about: - startActivity(new Intent(this, a.d.class)); + startActivity(new Intent(this, Data.classMap.get(AboutActivity.class))); mDrawerItem = bak; break; case R.id.donation: - startActivity(new Intent(this, a.e.class)); + startActivity(new Intent(this, Data.classMap.get(DonationActivity.class))); mDrawerItem = bak; break; } diff --git a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java index 4eb1efc70..c49561330 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SplashActivity.java @@ -10,13 +10,12 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.database.RepoDatabaseHelper; +import com.topjohnwu.magisk.receivers.ShortcutReceiver; import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; -import a.l; - public class SplashActivity extends BaseActivity { @Override @@ -45,7 +44,7 @@ public class SplashActivity extends BaseActivity { } // Setup shortcuts - sendBroadcast(new Intent(this, l.class)); + sendBroadcast(new Intent(this, Data.classMap.get(ShortcutReceiver.class))); if (Download.checkNetworkStatus(this)) { // Fire update check @@ -59,7 +58,7 @@ public class SplashActivity extends BaseActivity { mm.hasInit = true; - Intent intent = new Intent(this, a.b.class); + Intent intent = new Intent(this, Data.classMap.get(MainActivity.class)); intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION)); intent.putExtra(BaseActivity.INTENT_PERM, getIntent().getStringExtra(BaseActivity.INTENT_PERM)); startActivity(intent); diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java index 3000bf697..a62f29e96 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java @@ -8,6 +8,7 @@ import android.widget.Toast; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; +import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.components.SnackbarMaker; @@ -140,7 +141,7 @@ public class ProcessRepoZip extends ParallelTask { if (result) { Uri uri = Uri.fromFile(mFile); if (mInstall) { - Intent intent = new Intent(activity, a.f.class); + Intent intent = new Intent(activity, Data.classMap.get(FlashActivity.class)); intent.setData(uri).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP); activity.startActivity(intent); } else { diff --git a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java index 2f16cf791..c88b02fd2 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java @@ -8,6 +8,7 @@ import android.widget.Toast; import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; +import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.utils.Download; @@ -37,7 +38,7 @@ class InstallMethodDialog extends AlertDialog.Builder { (requestCode, resultCode, data) -> { if (requestCode == Const.ID.SELECT_BOOT && resultCode == BaseActivity.RESULT_OK && data != null) { - Intent i = new Intent(activity, a.f.class) + Intent i = new Intent(activity, Data.classMap.get(FlashActivity.class)) .putExtra(Const.Key.FLASH_SET_BOOT, data.getData()) .putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT); activity.startActivity(i); @@ -55,7 +56,7 @@ class InstallMethodDialog extends AlertDialog.Builder { }, Data.magiskLink, filename); break; case 2: - intent = new Intent(activity, a.f.class) + intent = new Intent(activity, Data.classMap.get(FlashActivity.class)) .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK); activity.startActivity(intent); break; @@ -65,7 +66,7 @@ class InstallMethodDialog extends AlertDialog.Builder { .setMessage(R.string.install_inactive_slot_msg) .setCancelable(true) .setPositiveButton(R.string.yes, (d, i) -> { - Intent it = new Intent(activity, a.f.class) + Intent it = new Intent(activity, Data.classMap.get(FlashActivity.class)) .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_INACTIVE_SLOT); activity.startActivity(it); }) diff --git a/app/src/full/java/com/topjohnwu/magisk/components/ManagerInstallDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/ManagerInstallDialog.java index 499a21c5e..d1b395c08 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/ManagerInstallDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/ManagerInstallDialog.java @@ -9,9 +9,9 @@ import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.asyncs.MarkDownWindow; +import com.topjohnwu.magisk.receivers.ManagerUpdate; import com.topjohnwu.magisk.utils.Utils; -import a.j; import androidx.annotation.NonNull; public class ManagerInstallDialog extends CustomAlertDialog { @@ -26,7 +26,7 @@ public class ManagerInstallDialog extends CustomAlertDialog { setCancelable(true); setPositiveButton(R.string.install, (d, i) -> activity.runWithPermission( new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> { - Intent intent = new Intent(mm, j.class); + Intent intent = new Intent(mm, Data.classMap.get(ManagerUpdate.class)); intent.putExtra(Const.Key.INTENT_SET_LINK, Data.managerLink); intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename); mm.sendBroadcast(intent); diff --git a/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java b/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java index 6fe4a116d..23e5fa4ae 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java @@ -10,6 +10,7 @@ import android.widget.Toast; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; +import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.receivers.DownloadReceiver; @@ -44,7 +45,7 @@ public class UninstallDialog extends CustomAlertDialog { Download.receive(activity, new DownloadReceiver() { @Override public void onDownloadDone(Context context, Uri uri) { - Intent intent = new Intent(context, a.f.class) + Intent intent = new Intent(context, Data.classMap.get(FlashActivity.class)) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setData(uri) .putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL); diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java index c6897ee04..51c4c5d68 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java @@ -13,6 +13,8 @@ import android.view.ViewGroup; import android.widget.TextView; import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.Data; +import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.adapters.ModulesAdapter; @@ -90,7 +92,7 @@ public class ModulesFragment extends BaseFragment implements Topic.Subscriber { public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) { // Get the URI of the selected file - Intent intent = new Intent(getActivity(), a.f.class); + Intent intent = new Intent(getActivity(), Data.classMap.get(FlashActivity.class)); intent.setData(data.getData()).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP); startActivity(intent); } diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java index 2e625d17b..b7d58e4eb 100644 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java +++ b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java @@ -12,6 +12,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.SplashActivity; import com.topjohnwu.superuser.Shell; import java.util.ArrayList; @@ -36,7 +37,7 @@ public class ShortcutReceiver extends BroadcastReceiver { Data.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) { shortCuts.add(new ShortcutInfo.Builder(mm, "superuser") .setShortLabel(mm.getString(R.string.superuser)) - .setIntent(new Intent(mm, a.c.class) + .setIntent(new Intent(mm, Data.classMap.get(SplashActivity.class)) .putExtra(Const.Key.OPEN_SECTION, "superuser") .setAction(Intent.ACTION_VIEW) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) @@ -48,7 +49,7 @@ public class ShortcutReceiver extends BroadcastReceiver { && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) { shortCuts.add(new ShortcutInfo.Builder(mm, "magiskhide") .setShortLabel(mm.getString(R.string.magiskhide)) - .setIntent(new Intent(mm, a.c.class) + .setIntent(new Intent(mm, Data.classMap.get(SplashActivity.class)) .putExtra(Const.Key.OPEN_SECTION, "magiskhide") .setAction(Intent.ACTION_VIEW) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) @@ -59,7 +60,7 @@ public class ShortcutReceiver extends BroadcastReceiver { if (!mm.prefs.getBoolean(Const.Key.COREONLY, false) && root && Data.magiskVersionCode >= 0) { shortCuts.add(new ShortcutInfo.Builder(mm, "modules") .setShortLabel(mm.getString(R.string.modules)) - .setIntent(new Intent(mm, a.c.class) + .setIntent(new Intent(mm, Data.classMap.get(SplashActivity.class)) .putExtra(Const.Key.OPEN_SECTION, "modules") .setAction(Intent.ACTION_VIEW) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) @@ -68,7 +69,7 @@ public class ShortcutReceiver extends BroadcastReceiver { .build()); shortCuts.add(new ShortcutInfo.Builder(mm, "downloads") .setShortLabel(mm.getString(R.string.download)) - .setIntent(new Intent(mm, a.c.class) + .setIntent(new Intent(mm, Data.classMap.get(SplashActivity.class)) .putExtra(Const.Key.OPEN_SECTION, "downloads") .setAction(Intent.ACTION_VIEW) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)) diff --git a/app/src/full/java/com/topjohnwu/magisk/services/OnBootService.java b/app/src/full/java/com/topjohnwu/magisk/services/OnBootService.java index b2856e542..d44cf6163 100644 --- a/app/src/full/java/com/topjohnwu/magisk/services/OnBootService.java +++ b/app/src/full/java/com/topjohnwu/magisk/services/OnBootService.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.utils.NotificationMgr; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.ShellUtils; @@ -14,7 +15,7 @@ import androidx.core.app.JobIntentService; public class OnBootService extends JobIntentService { public static void enqueueWork(Context context) { - enqueueWork(context, OnBootService.class, Const.ID.ONBOOT_SERVICE_ID, new Intent()); + enqueueWork(context, Data.classMap.get(OnBootService.class), Const.ID.ONBOOT_SERVICE_ID, new Intent()); } @Override diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/NotificationMgr.java b/app/src/full/java/com/topjohnwu/magisk/utils/NotificationMgr.java index c62a485f2..c41ee3809 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/NotificationMgr.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/NotificationMgr.java @@ -9,9 +9,10 @@ import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.SplashActivity; +import com.topjohnwu.magisk.receivers.ManagerUpdate; +import com.topjohnwu.magisk.receivers.RebootReceiver; -import a.j; -import a.k; import androidx.core.app.NotificationCompat; import androidx.core.app.TaskStackBuilder; @@ -20,10 +21,10 @@ public class NotificationMgr { public static void magiskUpdate() { MagiskManager mm = Data.MM(); - Intent intent = new Intent(mm, a.c.class); + Intent intent = new Intent(mm, Data.classMap.get(SplashActivity.class)); intent.putExtra(Const.Key.OPEN_SECTION, "magisk"); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mm); - stackBuilder.addParentStack(a.c.class); + stackBuilder.addParentStack(Data.classMap.get(SplashActivity.class)); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(Const.ID.MAGISK_UPDATE_NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); @@ -46,7 +47,7 @@ public class NotificationMgr { String filename = Utils.fmt("MagiskManager-v%s(%d).apk", Data.remoteManagerVersionString, Data.remoteManagerVersionCode); - Intent intent = new Intent(mm, j.class); + Intent intent = new Intent(mm, Data.classMap.get(ManagerUpdate.class)); intent.putExtra(Const.Key.INTENT_SET_LINK, Data.managerLink); intent.putExtra(Const.Key.INTENT_SET_FILENAME, filename); PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, @@ -68,7 +69,7 @@ public class NotificationMgr { public static void dtboPatched() { MagiskManager mm = Data.MM(); - Intent intent = new Intent(mm, k.class); + Intent intent = new Intent(mm, Data.classMap.get(RebootReceiver.class)); PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);