Skip to content

Commit 5feac86

Browse files
committed
Add more log for push
1 parent a7f3f9b commit 5feac86

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ public Task<Void> handleRegistrationIntentAsync(Intent intent) {
182182
String registrationId = intent.getStringExtra(REGISTRATION_ID_EXTRA);
183183

184184
if (registrationId != null && registrationId.length() > 0) {
185+
PLog.v(TAG, "Get deviceToken " + registrationId + " from GCM.");
186+
185187
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
186188
// Compare the new deviceToken with the old deviceToken, we only update the
187189
// deviceToken if the new one is different from the old one. This does not follow google

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

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public static PushType getPushType() {
200200
boolean isGooglePlayServicesAvailable = isGooglePlayServicesAvailable();
201201
boolean isPPNSAvailable = PPNSUtil.isPPNSAvailable();
202202
boolean hasAnyGcmSpecificDeclaration = hasAnyGcmSpecificDeclaration();
203+
boolean hasAnyPPNSSpecificDeclaration = hasAnyPPNSSpecificDeclaration();
203204
ManifestCheckResult gcmSupportLevel = gcmSupportLevel();
204205
ManifestCheckResult ppnsSupportLevel = ppnsSupportLevel();
205206

@@ -260,6 +261,40 @@ public static PushType getPushType() {
260261
PLog.e(TAG, "Cannot use GCM for push because the app manifest is missing some " +
261262
"required declarations. Please " + getGcmManifestMessage());
262263
}
264+
} else if (hasAnyPPNSSpecificDeclaration) {
265+
PLog.w(TAG, "We find you have some PPNS specific declarations. If you are not intend " +
266+
"to use PPNS, we highly recommend you to use GCM for push. Please check the push " +
267+
"tutorial in our website.");
268+
if (!hasPushBroadcastReceiver) {
269+
/* Throw an error if someone migrated from an old SDK and hasn't yet started using
270+
* ParsePushBroadcastReceiver. */
271+
PLog.e(TAG, "Push is currently disabled. This is probably because you migrated " +
272+
"from an older version of Parse. This version of Parse requires your app to " +
273+
"have a BroadcastReceiver that handles " +
274+
ParsePushBroadcastReceiver.ACTION_PUSH_RECEIVE + ", " +
275+
ParsePushBroadcastReceiver.ACTION_PUSH_OPEN + ", and " +
276+
ParsePushBroadcastReceiver.ACTION_PUSH_DELETE + ". You can do this by adding " +
277+
"these lines to your AndroidManifest.xml:\n\n" +
278+
" <receiver android:name=\"com.parse.ParsePushBroadcastReceiver\"\n" +
279+
" android:exported=false>\n" +
280+
" <intent-filter>\n" +
281+
" <action android:name=\"com.parse.push.intent.RECEIVE\" />\n" +
282+
" <action android:name=\"com.parse.push.intent.OPEN\" />\n" +
283+
" <action android:name=\"com.parse.push.intent.DELETE\" />\n" +
284+
" </intent-filter>\n" +
285+
" </receiver>");
286+
}
287+
if (!isPPNSAvailable) {
288+
PLog.e(TAG, "Cannot use PPNS for push on this device. Make sure you add PPNS.jar as" +
289+
" your dependency.");
290+
}
291+
if (!hasRequiredPpnsDeclarations) {
292+
PLog.e(TAG, "Cannot use PPNS for push because the app manifest is missing some " +
293+
"required declarations. Please " + getPpnsManifestMessage());
294+
}
295+
} else {
296+
PLog.e(TAG, "Push is currently disabled. If you want to use push, please check the " +
297+
"push tutorial in our website.");
263298
}
264299
}
265300

@@ -269,16 +304,14 @@ public static PushType getPushType() {
269304
* If we selected gcm/ppns but the manifest is missing some optional declarations, warn so
270305
* the user knows how to add those optional declarations.
271306
*/
272-
if (Parse.getLogLevel() <= Parse.LOG_LEVEL_WARNING) {
273-
if (pushType == PushType.GCM && gcmSupportLevel == ManifestCheckResult.MISSING_OPTIONAL_DECLARATIONS) {
274-
PLog.w(TAG, "Using GCM for Parse Push, but the app manifest is missing some optional " +
275-
"declarations that should be added for maximum reliability. Please " +
276-
getGcmManifestMessage());
277-
} else if (pushType == PushType.PPNS && ppnsSupportLevel == ManifestCheckResult.MISSING_OPTIONAL_DECLARATIONS) {
278-
PLog.w(TAG, "Using PPNS for push, but the app manifest is missing some optional " +
279-
"declarations that should be added for maximum reliability. Please " +
280-
getPpnsManifestMessage());
281-
}
307+
if (pushType == PushType.GCM && gcmSupportLevel == ManifestCheckResult.MISSING_OPTIONAL_DECLARATIONS) {
308+
PLog.w(TAG, "Using GCM for Parse Push, but the app manifest is missing some optional " +
309+
"declarations that should be added for maximum reliability. Please " +
310+
getGcmManifestMessage());
311+
} else if (pushType == PushType.PPNS && ppnsSupportLevel == ManifestCheckResult.MISSING_OPTIONAL_DECLARATIONS) {
312+
PLog.w(TAG, "Using PPNS for push, but the app manifest is missing some optional " +
313+
"declarations that should be added for maximum reliability. Please " +
314+
getPpnsManifestMessage());
282315
}
283316
}
284317
}
@@ -459,6 +492,16 @@ private static boolean hasAnyGcmSpecificDeclaration() {
459492
return false;
460493
}
461494

495+
private static boolean hasAnyPPNSSpecificDeclaration() {
496+
Context context = getContext();
497+
if (hasRequestedPermissions(context, "android.permission.RECEIVE_BOOT_COMPLETED") ||
498+
getReceiverInfo(ParseBroadcastReceiver.class) != null) {
499+
return true;
500+
}
501+
502+
return false;
503+
}
504+
462505
private static boolean isGooglePlayServicesAvailable() {
463506
return Build.VERSION.SDK_INT >= 8 && getPackageInfo("com.google.android.gsf") != null;
464507
}
@@ -546,7 +589,7 @@ private static String getGcmManifestMessage() {
546589
String packageName = getContext().getPackageName();
547590
String gcmPackagePermission = packageName + ".permission.C2D_MESSAGE";
548591
return "make sure that these permissions are declared as children " +
549-
"of the root <manifest> element:\n" +
592+
"of the root <manifest> element:\n" +
550593
"\n" +
551594
"<uses-permission android:name=\"android.permission.INTERNET\" />\n" +
552595
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />\n" +

0 commit comments

Comments
 (0)