From a9de2f44ce5d54038c70c7b5f1d6aa4ecc629f72 Mon Sep 17 00:00:00 2001 From: Michael Mimeault Date: Sun, 30 Apr 2017 04:14:18 -0400 Subject: [PATCH] Allow the GcmBroadcastReceiver to be subclassed (#638) * Allow the GcmBroadcastReceiver to act as a composite so we can extend its functionnality * Rollback composite and remove final with call super annotation * Proper formatting * Change the validation to support BroadcastReceiver subclasses --- .../java/com/parse/GcmBroadcastReceiver.java | 4 ++- .../src/main/java/com/parse/ManifestInfo.java | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Parse/src/main/java/com/parse/GcmBroadcastReceiver.java b/Parse/src/main/java/com/parse/GcmBroadcastReceiver.java index e876618f9..a55f9d89a 100644 --- a/Parse/src/main/java/com/parse/GcmBroadcastReceiver.java +++ b/Parse/src/main/java/com/parse/GcmBroadcastReceiver.java @@ -11,13 +11,15 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.support.annotation.CallSuper; /** * @exclude */ public class GcmBroadcastReceiver extends BroadcastReceiver { @Override - public final void onReceive(Context context, Intent intent) { + @CallSuper + public void onReceive(Context context, Intent intent) { ServiceUtils.runWakefulIntentInService(context, intent, PushService.class); } } diff --git a/Parse/src/main/java/com/parse/ManifestInfo.java b/Parse/src/main/java/com/parse/ManifestInfo.java index 7862ed792..e650d4203 100644 --- a/Parse/src/main/java/com/parse/ManifestInfo.java +++ b/Parse/src/main/java/com/parse/ManifestInfo.java @@ -416,34 +416,32 @@ private static boolean hasGrantedPermissions(Context context, String... permissi return true; } - private static boolean checkResolveInfo(Class clazz, List infoList) { + private static boolean checkResolveInfo(Class clazz, List infoList, String permission) { for (ResolveInfo info : infoList) { - if (info.activityInfo != null && clazz.getCanonicalName().equals(info.activityInfo.name)) { - return true; + if (info.activityInfo != null) { + final Class resolveInfoClass; + try { + resolveInfoClass = Class.forName(info.activityInfo.name); + } catch (ClassNotFoundException e) { + break; + } + if (clazz.isAssignableFrom(resolveInfoClass) && (permission == null || permission.equals(info.activityInfo.permission))) { + return true; + } } } return false; } - private static boolean checkReceiver(Class clazz, String permission, Intent[] intents) { - ActivityInfo receiver = getReceiverInfo(clazz); - - if (receiver == null) { - return false; - } - - if (permission != null && !permission.equals(receiver.permission)) { - return false; - } - + private static boolean checkReceiver(Class clazz, String permission, Intent[] intents) { for (Intent intent : intents) { List receivers = getPackageManager().queryBroadcastReceivers(intent, 0); if (receivers.isEmpty()) { return false; } - if (!checkResolveInfo(clazz, receivers)) { + if (!checkResolveInfo(clazz, receivers, permission)) { return false; } }