Skip to content

Commit a9de2f4

Browse files
mmimeaultrogerhu
authored andcommitted
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
1 parent 5b4b16b commit a9de2f4

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Parse/src/main/java/com/parse/GcmBroadcastReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import android.content.BroadcastReceiver;
1212
import android.content.Context;
1313
import android.content.Intent;
14+
import android.support.annotation.CallSuper;
1415

1516
/**
1617
* @exclude
1718
*/
1819
public class GcmBroadcastReceiver extends BroadcastReceiver {
1920
@Override
20-
public final void onReceive(Context context, Intent intent) {
21+
@CallSuper
22+
public void onReceive(Context context, Intent intent) {
2123
ServiceUtils.runWakefulIntentInService(context, intent, PushService.class);
2224
}
2325
}

Parse/src/main/java/com/parse/ManifestInfo.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,34 +416,32 @@ private static boolean hasGrantedPermissions(Context context, String... permissi
416416
return true;
417417
}
418418

419-
private static boolean checkResolveInfo(Class<? extends BroadcastReceiver> clazz, List<ResolveInfo> infoList) {
419+
private static boolean checkResolveInfo(Class<? extends BroadcastReceiver> clazz, List<ResolveInfo> infoList, String permission) {
420420
for (ResolveInfo info : infoList) {
421-
if (info.activityInfo != null && clazz.getCanonicalName().equals(info.activityInfo.name)) {
422-
return true;
421+
if (info.activityInfo != null) {
422+
final Class resolveInfoClass;
423+
try {
424+
resolveInfoClass = Class.forName(info.activityInfo.name);
425+
} catch (ClassNotFoundException e) {
426+
break;
427+
}
428+
if (clazz.isAssignableFrom(resolveInfoClass) && (permission == null || permission.equals(info.activityInfo.permission))) {
429+
return true;
430+
}
423431
}
424432
}
425433

426434
return false;
427435
}
428436

429-
private static boolean checkReceiver(Class<? extends BroadcastReceiver> clazz, String permission, Intent[] intents) {
430-
ActivityInfo receiver = getReceiverInfo(clazz);
431-
432-
if (receiver == null) {
433-
return false;
434-
}
435-
436-
if (permission != null && !permission.equals(receiver.permission)) {
437-
return false;
438-
}
439-
437+
private static boolean checkReceiver(Class<? extends BroadcastReceiver> clazz, String permission, Intent[] intents) {
440438
for (Intent intent : intents) {
441439
List<ResolveInfo> receivers = getPackageManager().queryBroadcastReceivers(intent, 0);
442440
if (receivers.isEmpty()) {
443441
return false;
444442
}
445443

446-
if (!checkResolveInfo(clazz, receivers)) {
444+
if (!checkResolveInfo(clazz, receivers, permission)) {
447445
return false;
448446
}
449447
}

0 commit comments

Comments
 (0)