Skip to content

Allow the GcmBroadcastReceiver to be subclassed #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Parse/src/main/java/com/parse/GcmBroadcastReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
28 changes: 13 additions & 15 deletions Parse/src/main/java/com/parse/ManifestInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,34 +416,32 @@ private static boolean hasGrantedPermissions(Context context, String... permissi
return true;
}

private static boolean checkResolveInfo(Class<? extends BroadcastReceiver> clazz, List<ResolveInfo> infoList) {
private static boolean checkResolveInfo(Class<? extends BroadcastReceiver> clazz, List<ResolveInfo> 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<? extends BroadcastReceiver> 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<? extends BroadcastReceiver> clazz, String permission, Intent[] intents) {
for (Intent intent : intents) {
List<ResolveInfo> receivers = getPackageManager().queryBroadcastReceivers(intent, 0);
if (receivers.isEmpty()) {
return false;
}

if (!checkResolveInfo(clazz, receivers)) {
if (!checkResolveInfo(clazz, receivers, permission)) {
return false;
}
}
Expand Down