Skip to content

Commit a727f90

Browse files
committed
[Messaging] Fix subscription not completing
1 parent eef9328 commit a727f90

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

messaging/src/android/cpp/messaging.cc

Lines changed: 16 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,10 @@ 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 here,
895+
// but handle it to prevent abandoning the Future in case something happens.
896+
api->Complete(handle, kErrorUnknown, kErrorMessageSubscriptionUnknown);
885897
}
886898
return MakeFuture(api, handle);
887899
}
@@ -907,6 +919,10 @@ Future<void> Unsubscribe(const char* topic) {
907919
kErrorMessageNoRegistrationToken);
908920
} else if (g_pending_unsubscriptions) {
909921
g_pending_unsubscriptions->push_back(PendingTopic(topic, handle));
922+
} else {
923+
// This shouldn't happen, since g_pending_unsubscriptions should be valid if here,
924+
// but handle it to prevent abandoning the Future in case something happens.
925+
api->Complete(handle, kErrorUnknown, kErrorMessageSubscriptionUnknown);
910926
}
911927
return MakeFuture(api, handle);
912928
}

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)