use of org.infobip.mobile.messaging.mobile.common.MRetryableTask in project mobile-messaging-sdk-android by infobip.
the class RegistrationSynchronizer method reportCloudToken.
private void reportCloudToken(final String cloudToken) {
if (StringUtils.isBlank(cloudToken)) {
return;
}
new MRetryableTask<String, Registration>() {
@Override
public Registration run(String[] params) {
String cloudToken = params.length > 0 ? params[0] : null;
MobileMessagingLogger.v("REGISTRATION >>>", cloudToken);
RegistrationResponse registrationResponse = mobileApiRegistration.upsert(cloudToken, null);
MobileMessagingLogger.v("REGISTRATION <<<", registrationResponse);
return new Registration(cloudToken, registrationResponse.getDeviceApplicationInstanceId(), registrationResponse.getPushRegistrationEnabled());
}
@Override
public void after(Registration registration) {
setPushRegistrationEnabled(registration.enabled);
setPushRegistrationId(registration.registrationId);
setRegistrationIdReported(true);
MobileMessagingCore.getInstance(context).reportSystemData();
broadcaster.registrationCreated(registration.cloudToken, registration.registrationId);
}
@Override
public void error(Throwable error) {
MobileMessagingLogger.e("MobileMessaging API returned error (registration)!");
setRegistrationIdReported(false);
mobileMessagingCore.setLastHttpException(error);
stats.reportError(MobileMessagingStatsError.PUSH_REGISTRATION_STATUS_UPDATE_ERROR);
broadcaster.error(MobileMessagingError.createFrom(error));
}
}.retryWith(retryPolicyProvider.DEFAULT()).execute(executor, cloudToken);
}
Aggregations