Better GCM retry

pull/14/head
Sam Bosley 11 years ago
parent 641ef8b337
commit c33e93f03e

@ -12,6 +12,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gcm.GCMConstants;
import com.google.android.gcm.GCMRegistrar;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
@ -55,6 +56,7 @@ public class GCMIntentService extends GCMBaseIntentService {
public static final String SENDER_ID = "1003855277730"; //$NON-NLS-1$
public static final String PREF_REGISTRATION = "gcm_id";
public static final String PREF_NEEDS_REGISTRATION = "gcm_needs_reg";
public static final String PREF_NEEDS_RETRY = "gcm_needs_retry";
private static final String PREF_LAST_GCM = "c2dm_last";
public static final String PREF_C2DM_REGISTRATION = "c2dm_key";
@ -407,7 +409,10 @@ public class GCMIntentService extends GCMBaseIntentService {
@Override
protected void onError(Context context, String intent) {
// Unrecoverable
if ((GCMConstants.ERROR_AUTHENTICATION_FAILED.equals(intent) || GCMConstants.ERROR_ACCOUNT_MISSING.equals(intent))
&& !Preferences.getBoolean(PREF_NEEDS_RETRY, false)) {
Preferences.setBoolean(PREF_NEEDS_RETRY, true);
}
}
// =========== Migration ============= //

@ -138,6 +138,7 @@ public final class ActFmSyncService {
Preferences.setString(GCMIntentService.PREF_REGISTRATION, regId);
Preferences.setString(GCMIntentService.PREF_C2DM_REGISTRATION, null);
Preferences.setString(GCMIntentService.PREF_NEEDS_REGISTRATION, null);
Preferences.setBoolean(GCMIntentService.PREF_NEEDS_RETRY, false);
} catch (IOException e) {
Preferences.setString(GCMIntentService.PREF_NEEDS_REGISTRATION, regId);
Log.e("gcm", "error-gcm-register", e);

@ -106,6 +106,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
public void updateUserStatus() {
if (Preferences.getStringValue(GCMIntentService.PREF_NEEDS_REGISTRATION) != null) {
actFmSyncService.setGCMRegistration(Preferences.getStringValue(GCMIntentService.PREF_NEEDS_REGISTRATION));
} else if (Preferences.getBoolean(GCMIntentService.PREF_NEEDS_RETRY, false)) {
GCMIntentService.register(ContextManager.getContext());
}
if (Preferences.getBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, false)) {

Loading…
Cancel
Save