Skip to content

Commit 0f92f7b

Browse files
committed
Integrate Latest @ 205171267
Changes to auth/testapp ... - Fix crash that can occur when updating the phone number credentials. This occurs because updatePhoneNumber returns a Task<void>, so no result will ever get set. The function probably return a future<void>, but that would be a breaking change we can't make right now. - Update Firebase cpp/Unity Auth readmes to include push notification configuration. Changes to dynamic_links/testapp ... - Add firebase-core dependency back to Firebase C++ testapp Invites/Dynamic Links build.gradle files. Changes to functions/testapp ... - Update Firebase C++/Unity to use Firebase Android M29. Changes to invites/testapp ... - Add firebase-core dependency back to Firebase C++ testapp Invites/Dynamic Links build.gradle files. Changes to messaging/testapp ... - Updated Subscribe and Unsubscribe to return Futures. - Update Firebase C++/Unity to use Firebase Android M29. CL: 205171267
1 parent bb39ca5 commit 0f92f7b

File tree

5 files changed

+82
-27
lines changed

5 files changed

+82
-27
lines changed

auth/testapp/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Building and Running the testapp
7575
Select the "Build Settings" tab, and click "All" to see all
7676
the build settings. Scroll down to "Search Paths", and add
7777
your path to "Framework Search Paths".
78+
- Configure the XCode project for push messaging.
79+
- Select the `Capabilities` tab in the XCode project.
80+
- Switch `Push Notifications` to `On`.
7881
- In XCode, build & run the sample on an iOS device or simulator.
7982
- Phone authentication needs to launch a webview and return the results to the
8083
application. To do this it requires you configure a URL type to handle the

auth/testapp/src/common_main.cc

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ using ::firebase::auth::PlayGamesAuthProvider;
4444
using ::firebase::auth::SignInResult;
4545
using ::firebase::auth::TwitterAuthProvider;
4646
using ::firebase::auth::User;
47-
using ::firebase::auth::UserMetadata;
4847
using ::firebase::auth::UserInfoInterface;
48+
using ::firebase::auth::UserMetadata;
4949

5050
// Set this to true, and set the email/password, to test a custom email address.
5151
static const bool kTestCustomEmail = false;
@@ -197,16 +197,14 @@ static void LogVariantMap(const std::map<Variant, Variant>& variant_map,
197197
int indent);
198198

199199
// Log a vector of variants.
200-
static void LogVariantVector(const std::vector<Variant>& variants,
201-
int indent) {
200+
static void LogVariantVector(const std::vector<Variant>& variants, int indent) {
202201
std::string indent_string(indent * 2, ' ');
203202
LogMessage("%s[", indent_string.c_str());
204203
for (auto it = variants.begin(); it != variants.end(); ++it) {
205204
const Variant& item = *it;
206205
if (item.is_fundamental_type()) {
207206
const Variant& string_value = item.AsString();
208-
LogMessage("%s %s,", indent_string.c_str(),
209-
string_value.string_value());
207+
LogMessage("%s %s,", indent_string.c_str(), string_value.string_value());
210208
} else if (item.is_vector()) {
211209
LogVariantVector(item.vector(), indent + 2);
212210
} else if (item.is_map()) {
@@ -228,12 +226,10 @@ static void LogVariantMap(const std::map<Variant, Variant>& variant_map,
228226
const Variant& value = it->second;
229227
if (value.is_fundamental_type()) {
230228
const Variant& string_value = value.AsString();
231-
LogMessage("%s%s: %s,", indent_string.c_str(),
232-
key_string.string_value(),
229+
LogMessage("%s%s: %s,", indent_string.c_str(), key_string.string_value(),
233230
string_value.string_value());
234231
} else {
235-
LogMessage("%s%s:", indent_string.c_str(),
236-
key_string.string_value());
232+
LogMessage("%s%s:", indent_string.c_str(), key_string.string_value());
237233
if (value.is_vector()) {
238234
LogVariantVector(value.vector(), indent + 1);
239235
} else if (value.is_map()) {
@@ -636,6 +632,16 @@ extern "C" int common_main(int argc, const char* argv[]) {
636632
WaitForSignInFuture(phone_future,
637633
"Auth::SignInWithCredential() phone credential",
638634
kAuthErrorNone, auth);
635+
if (phone_future.error() == kAuthErrorNone) {
636+
User* user = *phone_future.result();
637+
Future<User*> update_future =
638+
user->UpdatePhoneNumberCredential(phone_credential);
639+
WaitForSignInFuture(
640+
update_future,
641+
"user->UpdatePhoneNumberCredential(phone_credential)",
642+
kAuthErrorNone, auth);
643+
}
644+
639645
} else {
640646
LogMessage("ERROR: SMS auto-detect time out did not occur.");
641647
}
@@ -744,7 +750,6 @@ extern "C" int common_main(int argc, const char* argv[]) {
744750
}
745751
}
746752

747-
748753
// Sign in anonymously, link an email credential, reauthenticate with the
749754
// credential, unlink the credential and finally sign out.
750755
{
@@ -754,8 +759,8 @@ extern "C" int common_main(int argc, const char* argv[]) {
754759
if (sign_in_anonymously_future.error() == kAuthErrorNone) {
755760
User* user = *sign_in_anonymously_future.result();
756761
std::string email = CreateNewEmail();
757-
Credential credential = EmailAuthProvider::GetCredential(
758-
email.c_str(), kTestPassword);
762+
Credential credential =
763+
EmailAuthProvider::GetCredential(email.c_str(), kTestPassword);
759764
// Link with an email / password credential.
760765
Future<SignInResult> link_future =
761766
user->LinkAndRetrieveDataWithCredential(credential);
@@ -773,10 +778,10 @@ extern "C" int common_main(int argc, const char* argv[]) {
773778
LogSignInResult(*reauth_future.result());
774779
}
775780
// Unlink email / password from credential.
776-
Future<User*> unlink_future = user->Unlink(
777-
credential.provider().c_str());
778-
WaitForSignInFuture(unlink_future, "User::Unlink",
779-
kAuthErrorNone, auth);
781+
Future<User*> unlink_future =
782+
user->Unlink(credential.provider().c_str());
783+
WaitForSignInFuture(unlink_future, "User::Unlink", kAuthErrorNone,
784+
auth);
780785
}
781786
auth->SignOut();
782787
}
@@ -838,19 +843,22 @@ extern "C" int common_main(int argc, const char* argv[]) {
838843
auth->SignInAndRetrieveDataWithCredential(email_cred);
839844
WaitForSignInFuture(sign_in_future,
840845
"Auth::SignInAndRetrieveDataWithCredential "
841-
"existing email", kAuthErrorNone, auth);
842-
ExpectTrue("SignInAndRetrieveDataWithCredentialLastResult matches "
843-
"returned Future",
844-
sign_in_future ==
845-
auth->SignInAndRetrieveDataWithCredentialLastResult());
846+
"existing email",
847+
kAuthErrorNone, auth);
848+
ExpectTrue(
849+
"SignInAndRetrieveDataWithCredentialLastResult matches "
850+
"returned Future",
851+
sign_in_future ==
852+
auth->SignInAndRetrieveDataWithCredentialLastResult());
846853
if (sign_in_future.error() == kAuthErrorNone) {
847854
const SignInResult* sign_in_result = sign_in_future.result();
848855
if (sign_in_result != nullptr && sign_in_result->user) {
849856
LogMessage("SignInAndRetrieveDataWithCredential");
850857
LogSignInResult(*sign_in_result);
851858
} else {
852-
LogMessage("ERROR: SignInAndRetrieveDataWithCredential returned no "
853-
"result");
859+
LogMessage(
860+
"ERROR: SignInAndRetrieveDataWithCredential returned no "
861+
"result");
854862
}
855863
}
856864
}

functions/testapp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ android {
9494
dependencies {
9595
compile 'com.google.firebase:firebase-core:16.0.1'
9696
compile 'com.google.firebase:firebase-auth:16.0.2'
97-
compile 'com.google.firebase:firebase-functions:16.0.1'
97+
compile 'com.google.firebase:firebase-functions:16.1.0'
9898
}
9999

100100
apply plugin: 'com.google.gms.google-services'

messaging/testapp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ repositories {
9999
dependencies {
100100
compile 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar'
101101
compile 'com.google.firebase:firebase-core:16.0.1'
102-
compile 'com.google.firebase:firebase-messaging:17.0.0'
102+
compile 'com.google.firebase:firebase-messaging:17.1.0'
103103
compile 'com.google.firebase:firebase-common:16.0.0'
104104
}
105105

messaging/testapp/src/common_main.cc

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,51 @@
1313
// limitations under the License.
1414

1515
#include "firebase/app.h"
16+
#include "firebase/future.h"
1617
#include "firebase/messaging.h"
1718
#include "firebase/util.h"
1819

1920
// Thin OS abstraction layer.
2021
#include "main.h" // NOLINT
2122

23+
// Don't return until `future` is complete.
24+
// Print a message for whether the result mathes our expectations.
25+
// Returns true if the application should exit.
26+
static bool WaitForFuture(const ::firebase::FutureBase& future, const char* fn,
27+
::firebase::messaging::Error expected_error,
28+
bool log_error = true) {
29+
// Note if the future has not be started properly.
30+
if (future.status() == ::firebase::kFutureStatusInvalid) {
31+
LogMessage("ERROR: Future for %s is invalid", fn);
32+
return false;
33+
}
34+
35+
// Wait for future to complete.
36+
LogMessage(" %s...", fn);
37+
while (future.status() == ::firebase::kFutureStatusPending) {
38+
if (ProcessEvents(100)) return true;
39+
}
40+
41+
// Log error result.
42+
if (log_error) {
43+
const ::firebase::messaging::Error error =
44+
static_cast<::firebase::messaging::Error>(future.error());
45+
if (error == expected_error) {
46+
const char* error_message = future.error_message();
47+
if (error_message) {
48+
LogMessage("%s completed as expected", fn);
49+
} else {
50+
LogMessage("%s completed as expected, error: %d '%s'", fn, error,
51+
error_message);
52+
}
53+
} else {
54+
LogMessage("ERROR: %s completed with error: %d, `%s`", fn, error,
55+
future.error_message());
56+
}
57+
}
58+
return false;
59+
}
60+
2261
// Execute all methods of the C++ Firebase Cloud Messaging API.
2362
extern "C" int common_main(int argc, const char* argv[]) {
2463
::firebase::App* app;
@@ -79,8 +118,13 @@ extern "C" int common_main(int argc, const char* argv[]) {
79118
LogMessage("Finished checking for permission.");
80119
}
81120

82-
::firebase::messaging::Subscribe("TestTopic");
83-
LogMessage("Subscribed to TestTopic");
121+
// Subscribe to topics.
122+
WaitForFuture(::firebase::messaging::Subscribe("TestTopic"),
123+
"::firebase::messaging::Subscribe(\"TestTopic\")",
124+
::firebase::messaging::kErrorNone);
125+
WaitForFuture(::firebase::messaging::Subscribe("!@#$%^&*()"),
126+
"::firebase::messaging::Subscribe(\"!@#$%^&*()\")",
127+
::firebase::messaging::kErrorInvalidTopicName);
84128

85129
bool done = false;
86130
while (!done) {

0 commit comments

Comments
 (0)