From a727f906374215652d0df7e542173fa5cc231d25 Mon Sep 17 00:00:00 2001 From: a-maurice Date: Wed, 28 May 2025 17:20:46 -0700 Subject: [PATCH 1/2] [Messaging] Fix subscription not completing --- messaging/src/android/cpp/messaging.cc | 16 ++++++++++++++++ release_build_files/readme.md | 2 ++ 2 files changed, 18 insertions(+) diff --git a/messaging/src/android/cpp/messaging.cc b/messaging/src/android/cpp/messaging.cc index 43c8035d7..7ce666947 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,10 @@ 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 +919,10 @@ 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 From e4ce188833012539bf9fba5bcfbb54d7c134194b Mon Sep 17 00:00:00 2001 From: a-maurice Date: Wed, 28 May 2025 17:21:00 -0700 Subject: [PATCH 2/2] Update messaging.cc --- messaging/src/android/cpp/messaging.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/messaging/src/android/cpp/messaging.cc b/messaging/src/android/cpp/messaging.cc index 7ce666947..0a0b3671e 100644 --- a/messaging/src/android/cpp/messaging.cc +++ b/messaging/src/android/cpp/messaging.cc @@ -874,7 +874,7 @@ static const char kErrorMessageNoRegistrationToken[] = "to false."; static const char kErrorMessageSubscriptionUnknown[] = -"Cannot update subscription for unknown reason."; + "Cannot update subscription for unknown reason."; Future Subscribe(const char* topic) { FIREBASE_ASSERT_MESSAGE_RETURN(Future(), internal::IsInitialized(), @@ -891,8 +891,9 @@ Future Subscribe(const char* topic) { } 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. + // 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); @@ -920,8 +921,9 @@ Future Unsubscribe(const char* topic) { } 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. + // 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);