Skip to content

Commit a06d206

Browse files
authored
[Messaging] Fix subscription not completing sometimes (#1718)
* [Messaging] Fix subscription not completing * Update messaging.cc
1 parent eef9328 commit a06d206

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

messaging/src/android/cpp/messaging.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,11 @@ static void InstallationsGetToken() {
724724

725725
result.OnCompletion(
726726
[](const Future<std::string>& result, void* voidptr) {
727+
if (g_registration_token_mutex) {
728+
MutexLock lock(*g_registration_token_mutex);
729+
g_registration_token_received = true;
730+
HandlePendingSubscriptions();
731+
}
727732
NotifyListenerOnTokenReceived(result.result()->c_str());
728733
},
729734
nullptr);
@@ -868,6 +873,9 @@ static const char kErrorMessageNoRegistrationToken[] =
868873
"Cannot update subscription when SetTokenRegistrationOnInitEnabled is set "
869874
"to false.";
870875

876+
static const char kErrorMessageSubscriptionUnknown[] =
877+
"Cannot update subscription for unknown reason.";
878+
871879
Future<void> Subscribe(const char* topic) {
872880
FIREBASE_ASSERT_MESSAGE_RETURN(Future<void>(), internal::IsInitialized(),
873881
kMessagingNotInitializedError);
@@ -882,6 +890,11 @@ Future<void> Subscribe(const char* topic) {
882890
kErrorMessageNoRegistrationToken);
883891
} else if (g_pending_subscriptions) {
884892
g_pending_subscriptions->push_back(PendingTopic(topic, handle));
893+
} else {
894+
// This shouldn't happen, since g_pending_subscriptions should be valid if
895+
// here, but handle it to prevent abandoning the Future in case something
896+
// happens.
897+
api->Complete(handle, kErrorUnknown, kErrorMessageSubscriptionUnknown);
885898
}
886899
return MakeFuture(api, handle);
887900
}
@@ -907,6 +920,11 @@ Future<void> Unsubscribe(const char* topic) {
907920
kErrorMessageNoRegistrationToken);
908921
} else if (g_pending_unsubscriptions) {
909922
g_pending_unsubscriptions->push_back(PendingTopic(topic, handle));
923+
} else {
924+
// This shouldn't happen, since g_pending_unsubscriptions should be valid if
925+
// here, but handle it to prevent abandoning the Future in case something
926+
// happens.
927+
api->Complete(handle, kErrorUnknown, kErrorMessageSubscriptionUnknown);
910928
}
911929
return MakeFuture(api, handle);
912930
}

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ code.
664664
library and to the firebase::ump namespace. The version in the
665665
GMA library (in firebase::gma::ump) has been deprecated and will
666666
be removed soon.
667+
- Messaging (Android): Fix issue with the Subscribe Future not completing
668+
when a cached token is available.
667669

668670
### 12.7.0
669671
- Changes

0 commit comments

Comments
 (0)