diff --git a/messaging/src/android/cpp/messaging.cc b/messaging/src/android/cpp/messaging.cc index 43c8035d7..0a0b3671e 100644 --- a/messaging/src/android/cpp/messaging.cc +++ b/messaging/src/android/cpp/messaging.cc @@ -724,6 +724,11 @@ static void InstallationsGetToken() { result.OnCompletion( [](const Future& result, void* voidptr) { + if (g_registration_token_mutex) { + MutexLock lock(*g_registration_token_mutex); + g_registration_token_received = true; + HandlePendingSubscriptions(); + } NotifyListenerOnTokenReceived(result.result()->c_str()); }, nullptr); @@ -868,6 +873,9 @@ static const char kErrorMessageNoRegistrationToken[] = "Cannot update subscription when SetTokenRegistrationOnInitEnabled is set " "to false."; +static const char kErrorMessageSubscriptionUnknown[] = + "Cannot update subscription for unknown reason."; + Future Subscribe(const char* topic) { FIREBASE_ASSERT_MESSAGE_RETURN(Future(), internal::IsInitialized(), kMessagingNotInitializedError); @@ -882,6 +890,11 @@ Future Subscribe(const char* topic) { kErrorMessageNoRegistrationToken); } else if (g_pending_subscriptions) { g_pending_subscriptions->push_back(PendingTopic(topic, handle)); + } else { + // This shouldn't happen, since g_pending_subscriptions should be valid if + // here, but handle it to prevent abandoning the Future in case something + // happens. + api->Complete(handle, kErrorUnknown, kErrorMessageSubscriptionUnknown); } return MakeFuture(api, handle); } @@ -907,6 +920,11 @@ Future Unsubscribe(const char* topic) { kErrorMessageNoRegistrationToken); } else if (g_pending_unsubscriptions) { g_pending_unsubscriptions->push_back(PendingTopic(topic, handle)); + } else { + // This shouldn't happen, since g_pending_unsubscriptions should be valid if + // here, but handle it to prevent abandoning the Future in case something + // happens. + api->Complete(handle, kErrorUnknown, kErrorMessageSubscriptionUnknown); } return MakeFuture(api, handle); } diff --git a/release_build_files/readme.md b/release_build_files/readme.md index f823d3e5b..1d52fae82 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -664,6 +664,8 @@ code. library and to the firebase::ump namespace. The version in the GMA library (in firebase::gma::ump) has been deprecated and will be removed soon. + - Messaging (Android): Fix issue with the Subscribe Future not completing + when a cached token is available. ### 12.7.0 - Changes