in sdk/communication/azure-communication-chat/src/main/java/com/azure/android/communication/chat/implementation/notifications/fcm/RegistrationRenewalWorker.java [56:99]
public Result doWork() {
int attempts = getRunAttemptCount();
this.clientLogger.info("RegistrationRenewalWorker execution in background: " + attempts);
// Retry maximum 2 times. Attempts number starts from zero.
if (attempts >= 3) {
this.clientLogger.info("execution retry limit reached");
//Using the exceptionHandler provided by client to handle exception.
RuntimeException exception = new RuntimeException(
"Registration renew request failed after "
+ NotificationUtils.MAX_REGISTRATION_RETRY_COUNT
+ "retries.");
registrationKeyManager.setLastExecutionSucceeded(false);
if (exceptionHandler != null) {
exceptionHandler.accept(exception);
}
return Result.failure();
}
// Registration
Data inputData = getInputData();
String skypeUserToken;
String deviceRegistrationToken = inputData.getString("deviceRegistrationToken");
try {
skypeUserToken = communicationTokenCredential.getToken().get().getToken();
refreshCredentials();
Pair<SecretKey, SecretKey> cryptoKeyToAuthKeyPair = registrationKeyManager.getLastPair();
registrarClient.register(
skypeUserToken,
deviceRegistrationToken,
cryptoKeyToAuthKeyPair.first,
cryptoKeyToAuthKeyPair.second);
} catch (ExecutionException | InterruptedException e) {
this.clientLogger.logThrowableAsError(e);
return Result.retry();
} catch (Throwable throwable) {
this.clientLogger.logThrowableAsError(throwable);
return Result.retry();
}
this.clientLogger.info("RegistrationRenewalWorker execution succeeded");
registrationKeyManager.setLastExecutionSucceeded(true);
return Result.success();
}