Skip to content

Commit d1e2907

Browse files
committed
Merge pull request #136 from ParsePlatform/grantland.push
Clean up Push warnings
2 parents 0e03ceb + b829180 commit d1e2907

File tree

3 files changed

+40
-48
lines changed

3 files changed

+40
-48
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ public Task<Void> registerAsync() {
9696
final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
9797
// Check whether we need to send registration request, if installation does not
9898
// have device token or local device token is stale, we need to send request.
99-
Task<Boolean> checkTask = installation.getDeviceToken() == null ? Task.forResult(true) :
100-
isLocalDeviceTokenStaleAsync();
99+
Task<Boolean> checkTask = installation.getDeviceToken() == null
100+
? Task.forResult(true)
101+
: isLocalDeviceTokenStaleAsync();
101102
return checkTask.onSuccessTask(new Continuation<Boolean, Task<Void>>() {
102103
@Override
103104
public Task<Void> then(Task<Boolean> task) throws Exception {

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

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.content.pm.ServiceInfo;
2323
import android.os.Build;
2424
import android.os.Bundle;
25+
import android.util.Log;
2526

2627
import java.io.File;
2728
import java.util.ArrayList;
@@ -217,50 +218,48 @@ public static PushType getPushType() {
217218
&& hasRequiredPpnsDeclarations
218219
&& (!hasAnyGcmSpecificDeclaration || !isGooglePlayServicesAvailable)) {
219220
pushType = PushType.PPNS;
221+
222+
if (isGooglePlayServicesAvailable) {
223+
Log.w(TAG, "Using PPNS for push even though Google Play Services is available." +
224+
" Please " + getGcmManifestMessage());
225+
}
220226
} else {
221227
pushType = PushType.NONE;
222228

223-
// Emit warnings if the client doesn't get push due to misconfiguration of the manifest.
224-
if (hasAnyGcmSpecificDeclaration && !hasRequiredGcmDeclarations) {
229+
if (hasAnyGcmSpecificDeclaration) {
230+
if (!hasPushBroadcastReceiver) {
231+
/* Throw an error if someone migrated from an old SDK and hasn't yet started using
232+
* ParsePushBroadcastReceiver. */
233+
PLog.e(TAG, "Push is currently disabled. This is probably because you migrated " +
234+
"from an older version of Parse. This version of Parse requires your app to " +
235+
"have a BroadcastReceiver that handles " +
236+
ParsePushBroadcastReceiver.ACTION_PUSH_RECEIVE + ", " +
237+
ParsePushBroadcastReceiver.ACTION_PUSH_OPEN + ", and " +
238+
ParsePushBroadcastReceiver.ACTION_PUSH_DELETE + ". You can do this by adding " +
239+
"these lines to your AndroidManifest.xml:\n\n" +
240+
" <receiver android:name=\"com.parse.ParsePushBroadcastReceiver\"\n" +
241+
" android:exported=false>\n" +
242+
" <intent-filter>\n" +
243+
" <action android:name=\"com.parse.push.intent.RECEIVE\" />\n" +
244+
" <action android:name=\"com.parse.push.intent.OPEN\" />\n" +
245+
" <action android:name=\"com.parse.push.intent.DELETE\" />\n" +
246+
" </intent-filter>\n" +
247+
" </receiver>");
248+
}
249+
if (!isGooglePlayServicesAvailable) {
250+
PLog.e(TAG, "Cannot use GCM for push on this device because Google Play " +
251+
"Services is not available. Install Google Play Services from the Play Store.");
252+
}
253+
// Emit warnings if the client doesn't get push due to misconfiguration of the manifest.
254+
if (!hasRequiredGcmDeclarations) {
225255
/*
226256
* If we detect that the app has some GCM-specific declarations, but not all required
227257
* declarations for GCM, then most likely the client means to use GCM but misconfigured
228258
* their manifest. Log an error in this case.
229259
*/
230-
PLog.e(TAG, "Cannot use GCM for push because the app manifest is missing some " +
231-
"required declarations. Please " + getGcmManifestMessage());
232-
} else if (!hasPushBroadcastReceiver &&
233-
(hasRequiredGcmDeclarations || hasRequiredPpnsDeclarations)) {
234-
/* Throw an error if someone migrated from an old SDK and hasn't yet started using
235-
* ParsePushBroadcastReceiver. */
236-
PLog.e(TAG, "Push is currently disabled. This is probably because you migrated from " +
237-
"an older version of Parse. This version of Parse requires your app to have a " +
238-
"BroadcastReceiver that handles " + ParsePushBroadcastReceiver.ACTION_PUSH_RECEIVE +
239-
", " + ParsePushBroadcastReceiver.ACTION_PUSH_OPEN + ", and " +
240-
ParsePushBroadcastReceiver.ACTION_PUSH_DELETE + ". You can do this by adding " +
241-
"these lines to your AndroidManifest.xml:\n\n" +
242-
" <receiver android:name=\"com.parse.ParsePushBroadcastReceiver\"\n" +
243-
" android:exported=false>\n" +
244-
" <intent-filter>\n" +
245-
" <action android:name=\"com.parse.push.intent.RECEIVE\" />\n" +
246-
" <action android:name=\"com.parse.push.intent.OPEN\" />\n" +
247-
" <action android:name=\"com.parse.push.intent.DELETE\" />\n" +
248-
" </intent-filter>\n" +
249-
" </receiver>");
250-
} else if (hasPushBroadcastReceiver
251-
&& hasRequiredGcmDeclarations
252-
&& !isGooglePlayServicesAvailable) {
253-
PLog.e(TAG, "Cannot use GCM for push on this device because Google Play " +
254-
"Services is not installed. Install Google Play Service from the Play Store, " +
255-
"or enable PPNS as a fallback push service." +
256-
"\nTo enable PPNS as a fallback push service on devices without Google Play " +
257-
"Service support, please include PPNS.jar in your application and " +
258-
getPpnsManifestMessage());
259-
} else if (hasPushBroadcastReceiver
260-
&& hasRequiredPpnsDeclarations
261-
&& !isPPNSAvailable) {
262-
PLog.e(TAG, "Cannot use PPNS for push on this device because PPNS is not available. " +
263-
"Include PPNS.jar in your application to use PPNS.");
260+
PLog.e(TAG, "Cannot use GCM for push because the app manifest is missing some " +
261+
"required declarations. Please " + getGcmManifestMessage());
262+
}
264263
}
265264
}
266265

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,15 @@
6666
* <pre>
6767
* &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
6868
* &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
69-
* &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
7069
* &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
7170
* &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
7271
* </pre>
7372
* <p/>
74-
* Also, make sure that {@link ParseBroadcastReceiver}, {@link PushService}, and
75-
* {@link ParsePushBroadcastReceiver} are declared as children of the
76-
* <code>&lt;application&gt;</code> element:
73+
* Also, make sure that {@link PushService} and {@link ParsePushBroadcastReceiver} are declared as
74+
* children of the <code>&lt;application&gt;</code> element:
7775
* <p/>
7876
* <pre>
7977
* &lt;service android:name="com.parse.PushService" /&gt;
80-
* &lt;receiver android:name="com.parse.ParseBroadcastReceiver"&gt;
81-
* &lt;intent-filter&gt;
82-
* &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
83-
* &lt;action android:name="android.intent.action.USER_PRESENT" /&gt;
84-
* &lt;/intent-filter&gt;
85-
* &lt;/receiver&gt;
8678
* &lt;receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported=false&gt;
8779
* &lt;intent-filter&gt;
8880
* &lt;action android:name="com.parse.push.intent.RECEIVE" /&gt;

0 commit comments

Comments
 (0)