Reduce BroadcastReceivers

This commit is contained in:
topjohnwu 2018-12-02 16:53:00 -05:00
parent 80dad54119
commit f0f87c8eb9
21 changed files with 133 additions and 191 deletions

View File

@ -48,7 +48,7 @@
<!-- Superuser --> <!-- Superuser -->
<activity <activity
android:name="a.p" android:name="a.m"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:launchMode="singleTask" android:launchMode="singleTask"
android:taskAffinity="internal.superuser" android:taskAffinity="internal.superuser"
@ -69,17 +69,13 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
</receiver>
<receiver android:name="a.i">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" /> <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<data android:scheme="package" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name="a.j" /> <receiver android:name="a.i">
<receiver android:name="a.k" />
<receiver android:name="a.l">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" /> <action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter> </intent-filter>
@ -88,11 +84,11 @@
<!-- Service --> <!-- Service -->
<service <service
android:name="a.m" android:name="a.j"
android:exported="true" android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" />
<service <service
android:name="a.n" android:name="a.k"
android:exported="true" android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" />

View File

@ -1,7 +1,7 @@
package a; 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 */ /* stub */
} }

View File

@ -1,7 +1,7 @@
package a; 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 */ /* stub */
} }

View File

@ -1,7 +1,7 @@
package a; 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 */ /* stub */
} }

View File

@ -1,7 +1,7 @@
package a; 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 */ /* stub */
} }

View File

@ -1,7 +1,22 @@
package a; 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 */ /* 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);
}
} }

View File

@ -1,7 +1,7 @@
package a; package a;
import com.topjohnwu.magisk.services.OnBootService; import com.topjohnwu.magisk.SuRequestActivity;
public class m extends OnBootService { public class m extends SuRequestActivity {
/* stub */ /* stub */
} }

View File

@ -1,7 +0,0 @@
package a;
import com.topjohnwu.magisk.services.UpdateCheckService;
public class n extends UpdateCheckService {
/* stub */
}

View File

@ -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);
}
}

View File

@ -1,7 +0,0 @@
package a;
import com.topjohnwu.magisk.SuRequestActivity;
public class p extends SuRequestActivity {
/* stub */
}

View File

@ -100,6 +100,8 @@ public class Const {
public static final String INTENT_SET_LINK = "link"; public static final String INTENT_SET_LINK = "link";
public static final String FLASH_ACTION = "action"; public static final String FLASH_ACTION = "action";
public static final String FLASH_SET_BOOT = "boot"; 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 // others
public static final String CHECK_UPDATES = "check_update"; public static final String CHECK_UPDATES = "check_update";

View File

@ -6,10 +6,7 @@ import android.os.Looper;
import android.util.Xml; import android.util.Xml;
import com.topjohnwu.magisk.components.AboutCardRow; import com.topjohnwu.magisk.components.AboutCardRow;
import com.topjohnwu.magisk.receivers.BootReceiver; import com.topjohnwu.magisk.receivers.GeneralReceiver;
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.receivers.ShortcutReceiver;
import com.topjohnwu.magisk.services.OnBootService; import com.topjohnwu.magisk.services.OnBootService;
import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.services.UpdateCheckService;
@ -75,15 +72,12 @@ public class Data {
classMap.put(DonationActivity.class, a.e.class); classMap.put(DonationActivity.class, a.e.class);
classMap.put(FlashActivity.class, a.f.class); classMap.put(FlashActivity.class, a.f.class);
classMap.put(NoUIActivity.class, a.g.class); classMap.put(NoUIActivity.class, a.g.class);
classMap.put(BootReceiver.class, a.h.class); classMap.put(GeneralReceiver.class, a.h.class);
classMap.put(PackageReceiver.class, a.i.class); classMap.put(ShortcutReceiver.class, a.i.class);
classMap.put(ManagerUpdate.class, a.j.class); classMap.put(OnBootService.class, a.j.class);
classMap.put(RebootReceiver.class, a.k.class); classMap.put(UpdateCheckService.class, a.k.class);
classMap.put(ShortcutReceiver.class, a.l.class); classMap.put(AboutCardRow.class, a.l.class);
classMap.put(OnBootService.class, a.m.class); classMap.put(SuRequestActivity.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);
} }

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}

View File

@ -12,8 +12,7 @@ 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.SplashActivity; import com.topjohnwu.magisk.SplashActivity;
import com.topjohnwu.magisk.receivers.ManagerUpdate; import com.topjohnwu.magisk.receivers.GeneralReceiver;
import com.topjohnwu.magisk.receivers.RebootReceiver;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
@ -63,7 +62,8 @@ public class Notifications {
String name = Utils.fmt("MagiskManager v%s(%d)", String name = Utils.fmt("MagiskManager v%s(%d)",
Data.remoteManagerVersionString, Data.remoteManagerVersionCode); 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_LINK, Data.managerLink);
intent.putExtra(Const.Key.INTENT_SET_NAME, name); intent.putExtra(Const.Key.INTENT_SET_NAME, name);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mm, PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
@ -84,7 +84,8 @@ public class Notifications {
public static void dtboPatched() { public static void dtboPatched() {
MagiskManager mm = Data.MM(); 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, PendingIntent pendingIntent = PendingIntent.getBroadcast(mm,
Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -23,14 +23,13 @@ import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.container.Module; import com.topjohnwu.magisk.container.Module;
import com.topjohnwu.magisk.container.ValueSortedMap; import com.topjohnwu.magisk.container.ValueSortedMap;
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.io.SuFile; import com.topjohnwu.superuser.io.SuFile;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import a.n;
public class Utils { public class Utils {
public static int getPrefsInt(SharedPreferences prefs, String key, int def) { 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 (mm.prefs.getBoolean(Const.Key.CHECK_UPDATES, true)) {
if (scheduler.getAllPendingJobs().isEmpty() || if (scheduler.getAllPendingJobs().isEmpty() ||
Const.UPDATE_SERVICE_VER > mm.prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) { 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) JobInfo info = new JobInfo.Builder(Const.ID.UPDATE_SERVICE_ID, service)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPersisted(true) .setPersisted(true)

View File

@ -54,42 +54,42 @@
android:textAppearance="@style/TextAppearance.AppCompat.Headline"/> android:textAppearance="@style/TextAppearance.AppCompat.Headline"/>
</LinearLayout> </LinearLayout>
<a.o <a.l
android:id="@+id/app_version_info" android:id="@+id/app_version_info"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_info_outline" app:icon="@drawable/ic_info_outline"
app:text="@string/app_version"/> app:text="@string/app_version"/>
<a.o <a.l
android:id="@+id/app_changelog" android:id="@+id/app_changelog"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_history" app:icon="@drawable/ic_history"
app:text="@string/app_changelog"/> app:text="@string/app_changelog"/>
<a.o <a.l
android:id="@+id/app_translators" android:id="@+id/app_translators"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_language" app:icon="@drawable/ic_language"
app:text="@string/app_translators"/> app:text="@string/app_translators"/>
<a.o <a.l
android:id="@+id/follow_twitter" android:id="@+id/follow_twitter"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_twitter" app:icon="@drawable/ic_twitter"
app:text="@string/follow_twitter"/> app:text="@string/follow_twitter"/>
<a.o <a.l
android:id="@+id/app_source_code" android:id="@+id/app_source_code"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_github" app:icon="@drawable/ic_github"
app:text="@string/app_source_code"/> app:text="@string/app_source_code"/>
<a.o <a.l
android:id="@+id/support_thread" android:id="@+id/support_thread"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -40,14 +40,14 @@
android:text="@string/donation" android:text="@string/donation"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"/> android:textAppearance="@style/TextAppearance.AppCompat.Headline"/>
<a.o <a.l
android:id="@+id/paypal" android:id="@+id/paypal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_paypal" app:icon="@drawable/ic_paypal"
app:text="PayPal"/> app:text="PayPal"/>
<a.o <a.l
android:id="@+id/patreon" android:id="@+id/patreon"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"