From f0f87c8eb95955ff2d98096b6b0fa4de8f07bda7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 2 Dec 2018 16:53:00 -0500 Subject: [PATCH] Reduce BroadcastReceivers --- app/src/full/AndroidManifest.xml | 12 +-- app/src/full/java/a/h.java | 4 +- app/src/full/java/a/i.java | 4 +- app/src/full/java/a/j.java | 4 +- app/src/full/java/a/k.java | 4 +- app/src/full/java/a/l.java | 19 ++++- app/src/full/java/a/m.java | 4 +- app/src/full/java/a/n.java | 7 -- app/src/full/java/a/o.java | 22 ------ app/src/full/java/a/p.java | 7 -- .../full/java/com/topjohnwu/magisk/Const.java | 2 + .../full/java/com/topjohnwu/magisk/Data.java | 20 ++--- .../magisk/receivers/BootReceiver.java | 43 ---------- .../magisk/receivers/GeneralReceiver.java | 78 +++++++++++++++++++ .../magisk/receivers/ManagerUpdate.java | 18 ----- .../magisk/receivers/PackageReceiver.java | 32 -------- .../magisk/receivers/RebootReceiver.java | 14 ---- .../topjohnwu/magisk/utils/Notifications.java | 9 ++- .../com/topjohnwu/magisk/utils/Utils.java | 5 +- app/src/full/res/layout/activity_about.xml | 12 +-- app/src/full/res/layout/activity_donation.xml | 4 +- 21 files changed, 133 insertions(+), 191 deletions(-) delete mode 100644 app/src/full/java/a/n.java delete mode 100644 app/src/full/java/a/o.java delete mode 100644 app/src/full/java/a/p.java delete mode 100644 app/src/full/java/com/topjohnwu/magisk/receivers/BootReceiver.java create mode 100644 app/src/full/java/com/topjohnwu/magisk/receivers/GeneralReceiver.java delete mode 100644 app/src/full/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java delete mode 100644 app/src/full/java/com/topjohnwu/magisk/receivers/PackageReceiver.java delete mode 100644 app/src/full/java/com/topjohnwu/magisk/receivers/RebootReceiver.java diff --git a/app/src/full/AndroidManifest.xml b/app/src/full/AndroidManifest.xml index 19d20fd89..8be908fa6 100644 --- a/app/src/full/AndroidManifest.xml +++ b/app/src/full/AndroidManifest.xml @@ -48,7 +48,7 @@ - - - - - + @@ -88,11 +84,11 @@ diff --git a/app/src/full/java/a/h.java b/app/src/full/java/a/h.java index 91fff83fb..672e85503 100644 --- a/app/src/full/java/a/h.java +++ b/app/src/full/java/a/h.java @@ -1,7 +1,7 @@ package a; -import com.topjohnwu.magisk.receivers.BootReceiver; +import com.topjohnwu.magisk.receivers.GeneralReceiver; -public class h extends BootReceiver { +public class h extends GeneralReceiver { /* stub */ } diff --git a/app/src/full/java/a/i.java b/app/src/full/java/a/i.java index 17feccd01..f4d38f50d 100644 --- a/app/src/full/java/a/i.java +++ b/app/src/full/java/a/i.java @@ -1,7 +1,7 @@ package a; -import com.topjohnwu.magisk.receivers.PackageReceiver; +import com.topjohnwu.magisk.receivers.ShortcutReceiver; -public class i extends PackageReceiver { +public class i extends ShortcutReceiver { /* stub */ } diff --git a/app/src/full/java/a/j.java b/app/src/full/java/a/j.java index 0feec80eb..8585eaf01 100644 --- a/app/src/full/java/a/j.java +++ b/app/src/full/java/a/j.java @@ -1,7 +1,7 @@ package a; -import com.topjohnwu.magisk.receivers.ManagerUpdate; +import com.topjohnwu.magisk.services.OnBootService; -public class j extends ManagerUpdate { +public class j extends OnBootService { /* stub */ } diff --git a/app/src/full/java/a/k.java b/app/src/full/java/a/k.java index af3140a29..f29cb69be 100644 --- a/app/src/full/java/a/k.java +++ b/app/src/full/java/a/k.java @@ -1,7 +1,7 @@ package a; -import com.topjohnwu.magisk.receivers.RebootReceiver; +import com.topjohnwu.magisk.services.UpdateCheckService; -public class k extends RebootReceiver { +public class k extends UpdateCheckService { /* stub */ } diff --git a/app/src/full/java/a/l.java b/app/src/full/java/a/l.java index a7cd44c3b..8cd9df563 100644 --- a/app/src/full/java/a/l.java +++ b/app/src/full/java/a/l.java @@ -1,7 +1,22 @@ package a; -import com.topjohnwu.magisk.receivers.ShortcutReceiver; +import android.content.Context; +import android.util.AttributeSet; -public class l extends ShortcutReceiver { +import com.topjohnwu.magisk.components.AboutCardRow; + +public class l extends AboutCardRow { /* stub */ + + public l(Context context) { + super(context); + } + + public l(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public l(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } } diff --git a/app/src/full/java/a/m.java b/app/src/full/java/a/m.java index eb114751c..d879fcd72 100644 --- a/app/src/full/java/a/m.java +++ b/app/src/full/java/a/m.java @@ -1,7 +1,7 @@ package a; -import com.topjohnwu.magisk.services.OnBootService; +import com.topjohnwu.magisk.SuRequestActivity; -public class m extends OnBootService { +public class m extends SuRequestActivity { /* stub */ } diff --git a/app/src/full/java/a/n.java b/app/src/full/java/a/n.java deleted file mode 100644 index ad8fa0f07..000000000 --- a/app/src/full/java/a/n.java +++ /dev/null @@ -1,7 +0,0 @@ -package a; - -import com.topjohnwu.magisk.services.UpdateCheckService; - -public class n extends UpdateCheckService { - /* stub */ -} diff --git a/app/src/full/java/a/o.java b/app/src/full/java/a/o.java deleted file mode 100644 index 38f990a2a..000000000 --- a/app/src/full/java/a/o.java +++ /dev/null @@ -1,22 +0,0 @@ -package a; - -import android.content.Context; -import android.util.AttributeSet; - -import com.topjohnwu.magisk.components.AboutCardRow; - -public class o extends AboutCardRow { - /* stub */ - - public o(Context context) { - super(context); - } - - public o(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public o(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } -} diff --git a/app/src/full/java/a/p.java b/app/src/full/java/a/p.java deleted file mode 100644 index 479de2a43..000000000 --- a/app/src/full/java/a/p.java +++ /dev/null @@ -1,7 +0,0 @@ -package a; - -import com.topjohnwu.magisk.SuRequestActivity; - -public class p extends SuRequestActivity { - /* stub */ -} diff --git a/app/src/full/java/com/topjohnwu/magisk/Const.java b/app/src/full/java/com/topjohnwu/magisk/Const.java index f770cbe3a..ecfd4bfbc 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Const.java +++ b/app/src/full/java/com/topjohnwu/magisk/Const.java @@ -100,6 +100,8 @@ public class Const { public static final String INTENT_SET_LINK = "link"; public static final String FLASH_ACTION = "action"; public static final String FLASH_SET_BOOT = "boot"; + public static final String BROADCAST_MANAGER_UPDATE = "manager_update"; + public static final String BROADCAST_REBOOT = "reboot"; // others public static final String CHECK_UPDATES = "check_update"; diff --git a/app/src/full/java/com/topjohnwu/magisk/Data.java b/app/src/full/java/com/topjohnwu/magisk/Data.java index af6ce3efb..93607aa3b 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Data.java +++ b/app/src/full/java/com/topjohnwu/magisk/Data.java @@ -6,10 +6,7 @@ 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.GeneralReceiver; import com.topjohnwu.magisk.receivers.ShortcutReceiver; import com.topjohnwu.magisk.services.OnBootService; import com.topjohnwu.magisk.services.UpdateCheckService; @@ -75,15 +72,12 @@ public class Data { 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); - classMap.put(SuRequestActivity.class, a.p.class); + classMap.put(GeneralReceiver.class, a.h.class); + classMap.put(ShortcutReceiver.class, a.i.class); + classMap.put(OnBootService.class, a.j.class); + classMap.put(UpdateCheckService.class, a.k.class); + classMap.put(AboutCardRow.class, a.l.class); + classMap.put(SuRequestActivity.class, a.m.class); } diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/BootReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/BootReceiver.java deleted file mode 100644 index c5cc42ad8..000000000 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/BootReceiver.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.topjohnwu.magisk.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.text.TextUtils; - -import com.topjohnwu.magisk.Data; -import com.topjohnwu.magisk.SuRequestActivity; -import com.topjohnwu.magisk.services.OnBootService; -import com.topjohnwu.magisk.utils.SuConnector; - -public class BootReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - if (intent == null) - return; - if (TextUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) { - String action = intent.getStringExtra("action"); - if (action == null) - action = "boot"; - switch (action) { - case "request": - Intent i = new Intent(context, Data.classMap.get(SuRequestActivity.class)) - .putExtra("socket", intent.getStringExtra("socket")) - .putExtra("version", 2) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); - break; - case "log": - SuConnector.handleLogs(intent, 2); - break; - case "notify": - SuConnector.handleNotify(intent); - break; - case "boot": - OnBootService.enqueueWork(context); - break; - } - } - } -} diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/GeneralReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/GeneralReceiver.java new file mode 100644 index 000000000..1a9329227 --- /dev/null +++ b/app/src/full/java/com/topjohnwu/magisk/receivers/GeneralReceiver.java @@ -0,0 +1,78 @@ +package com.topjohnwu.magisk.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.topjohnwu.magisk.Const; +import com.topjohnwu.magisk.Data; +import com.topjohnwu.magisk.MagiskManager; +import com.topjohnwu.magisk.SuRequestActivity; +import com.topjohnwu.magisk.services.OnBootService; +import com.topjohnwu.magisk.utils.DlInstallManager; +import com.topjohnwu.magisk.utils.Logger; +import com.topjohnwu.magisk.utils.SuConnector; +import com.topjohnwu.superuser.Shell; + +public class GeneralReceiver extends BroadcastReceiver { + + private String getPkg(Intent i) { + return i.getData() == null ? "" : i.getData().getEncodedSchemeSpecificPart(); + } + + @Override + public void onReceive(Context context, Intent intent) { + MagiskManager mm = Data.MM(); + if (intent == null) + return; + String action = intent.getAction(); + if (action == null) + return; + Logger.debug(action); + switch (action) { + case Intent.ACTION_BOOT_COMPLETED: + String bootAction = intent.getStringExtra("action"); + if (bootAction == null) + bootAction = "boot"; + switch (bootAction) { + case "request": + Intent i = new Intent(mm, Data.classMap.get(SuRequestActivity.class)) + .putExtra("socket", intent.getStringExtra("socket")) + .putExtra("version", 2) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mm.startActivity(i); + break; + case "log": + SuConnector.handleLogs(intent, 2); + break; + case "notify": + SuConnector.handleNotify(intent); + break; + case "boot": + default: + /* The actual on-boot trigger */ + OnBootService.enqueueWork(mm); + break; + } + break; + case Intent.ACTION_PACKAGE_REPLACED: + // This will only work pre-O + if (mm.prefs.getBoolean(Const.Key.SU_REAUTH, false)) { + mm.mDB.deletePolicy(getPkg(intent)); + } + break; + case Intent.ACTION_PACKAGE_FULLY_REMOVED: + String pkg = getPkg(intent); + mm.mDB.deletePolicy(pkg); + Shell.su("magiskhide --rm " + pkg).submit(); + break; + case Const.Key.BROADCAST_MANAGER_UPDATE: + Data.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK); + DlInstallManager.upgrade(intent.getStringExtra(Const.Key.INTENT_SET_NAME)); + break; + case Const.Key.BROADCAST_REBOOT: + Shell.su("/system/bin/reboot").submit(); + break; + } + } +} diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java b/app/src/full/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java deleted file mode 100644 index f0d0a4428..000000000 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.topjohnwu.magisk.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.Data; -import com.topjohnwu.magisk.utils.DlInstallManager; - -public class ManagerUpdate extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - Data.managerLink = intent.getStringExtra(Const.Key.INTENT_SET_LINK); - DlInstallManager.upgrade(intent.getStringExtra(Const.Key.INTENT_SET_NAME)); - } -} diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/PackageReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/PackageReceiver.java deleted file mode 100644 index 153858071..000000000 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/PackageReceiver.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.topjohnwu.magisk.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.Data; -import com.topjohnwu.magisk.MagiskManager; -import com.topjohnwu.superuser.Shell; - -public class PackageReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - MagiskManager mm = Data.MM(); - - String pkg = intent.getData().getEncodedSchemeSpecificPart(); - - switch (intent.getAction()) { - case Intent.ACTION_PACKAGE_REPLACED: - // This will only work pre-O - if (mm.prefs.getBoolean(Const.Key.SU_REAUTH, false)) { - mm.mDB.deletePolicy(pkg); - } - break; - case Intent.ACTION_PACKAGE_FULLY_REMOVED: - mm.mDB.deletePolicy(pkg); - Shell.su("magiskhide --rm " + pkg).submit(); - break; - } - } -} diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/RebootReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/RebootReceiver.java deleted file mode 100644 index 078128388..000000000 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/RebootReceiver.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.topjohnwu.magisk.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -import com.topjohnwu.superuser.Shell; - -public class RebootReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - Shell.su("/system/bin/reboot").submit(); - } -} diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/Notifications.java b/app/src/full/java/com/topjohnwu/magisk/utils/Notifications.java index 2c7795a19..c6f6bed56 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/Notifications.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/Notifications.java @@ -12,8 +12,7 @@ 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 com.topjohnwu.magisk.receivers.GeneralReceiver; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; @@ -63,7 +62,8 @@ public class Notifications { String name = Utils.fmt("MagiskManager v%s(%d)", Data.remoteManagerVersionString, Data.remoteManagerVersionCode); - Intent intent = new Intent(mm, Data.classMap.get(ManagerUpdate.class)); + Intent intent = new Intent(mm, Data.classMap.get(GeneralReceiver.class)); + intent.setAction(Const.Key.BROADCAST_MANAGER_UPDATE); intent.putExtra(Const.Key.INTENT_SET_LINK, Data.managerLink); intent.putExtra(Const.Key.INTENT_SET_NAME, name); PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, @@ -84,7 +84,8 @@ public class Notifications { public static void dtboPatched() { MagiskManager mm = Data.MM(); - Intent intent = new Intent(mm, Data.classMap.get(RebootReceiver.class)); + Intent intent = new Intent(mm, Data.classMap.get(GeneralReceiver.class)) + .setAction(Const.Key.BROADCAST_REBOOT); PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java index 29f4f874c..05a735e82 100644 --- a/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/full/java/com/topjohnwu/magisk/utils/Utils.java @@ -23,14 +23,13 @@ import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.ValueSortedMap; +import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.io.SuFile; import java.util.Locale; import java.util.Map; -import a.n; - public class Utils { public static int getPrefsInt(SharedPreferences prefs, String key, int def) { @@ -84,7 +83,7 @@ public class Utils { if (mm.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) { if (scheduler.getAllPendingJobs().isEmpty() || Const.UPDATE_SERVICE_VER > mm.prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) { - ComponentName service = new ComponentName(mm, n.class); + ComponentName service = new ComponentName(mm, Data.classMap.get(UpdateCheckService.class)); JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setPersisted(true) diff --git a/app/src/full/res/layout/activity_about.xml b/app/src/full/res/layout/activity_about.xml index 5b35c3900..1957b1e36 100644 --- a/app/src/full/res/layout/activity_about.xml +++ b/app/src/full/res/layout/activity_about.xml @@ -54,42 +54,42 @@ android:textAppearance="@style/TextAppearance.AppCompat.Headline"/> - - - - - - - -