Skip to content

Commit 1c71573

Browse files
authored
Merge branch 'main' into tomandersen/or_query
2 parents a232d50 + 8fecdb9 commit 1c71573

File tree

57 files changed

+1070
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1070
-556
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ if(DESKTOP)
264264

265265
if(FIREBASE_USE_BORINGSSL)
266266
# Use BoringSSL instead of OpenSSL.
267-
set(BORINGSSL_ROOT_DIR ${PROJECT_BINARY_DIR}/external/src/boringssl/src CACHE STRING "" FORCE)
267+
set(BORINGSSL_ROOT_DIR ${PROJECT_BINARY_DIR}/external/src/boringssl CACHE STRING "" FORCE)
268268
set(BORINGSSL_BINARY_DIR ${PROJECT_BINARY_DIR}/external/src/boringssl-build CACHE STRING "" FORCE)
269269
set(OPENSSL_ROOT_DIR ${BORINGSSL_ROOT_DIR} CACHE STRING "" FORCE)
270270

app/src/util.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,21 @@ std::vector<std::string> SplitString(const std::string& s,
342342
return split_parts;
343343
}
344344

345+
// Id used as part of the logic to make unique api identifiers.
346+
static int g_api_identifier_count = 0;
347+
348+
std::string CreateApiIdentifier(const char* api_id, void* object) {
349+
std::string created;
350+
const char* format = "%s0x%016llx_%d";
351+
unsigned long long object_ptr = // NOLINT
352+
static_cast<unsigned long long>( // NOLINT
353+
reinterpret_cast<intptr_t>(object));
354+
int extra_id = g_api_identifier_count++;
355+
int size = snprintf(nullptr, 0, format, api_id, object_ptr, extra_id) + 1;
356+
created.reserve(size);
357+
snprintf(&(created[0]), size, format, api_id, object_ptr, extra_id);
358+
return created;
359+
}
360+
345361
// NOLINTNEXTLINE - allow namespace overridden
346362
} // namespace firebase

app/src/util.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ class StaticFutureData {
238238
// delimiter. Returns a vector of constituent parts.
239239
std::vector<std::string> SplitString(const std::string& s, char delimiter);
240240

241-
// NOLINTNEXTLINE - allow namespace overridden
241+
// Helper function to combine a string and other object into a unique
242+
// identifier. Primarily used to manage listening to JNI Tasks on Android.
243+
// Note that repeated calls are expected to return different values.
244+
std::string CreateApiIdentifier(const char* api_id, void* object);
245+
242246
} // namespace firebase
243247

244248
#endif // FIREBASE_APP_SRC_UTIL_H_

app/src/util_android.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,14 @@ METHOD_LOOKUP_DECLARATION(activity, ACTIVITY_METHODS)
491491
// Used to setup the cache of Bundle class method IDs to reduce time spent
492492
// looking up methods by string.
493493
// clang-format off
494-
#define BUNDLE_METHODS(X) \
495-
X(Constructor, "<init>", "()V"), \
496-
X(GetString, "getString", "(Ljava/lang/String;)Ljava/lang/String;"), \
497-
X(KeySet, "keySet", "()Ljava/util/Set;"), \
498-
X(PutFloat, "putFloat", "(Ljava/lang/String;F)V"), \
499-
X(PutLong, "putLong", "(Ljava/lang/String;J)V"), \
500-
X(PutString, "putString", "(Ljava/lang/String;Ljava/lang/String;)V")
494+
#define BUNDLE_METHODS(X) \
495+
X(Constructor, "<init>", "()V"), \
496+
X(GetString, "getString", "(Ljava/lang/String;)Ljava/lang/String;"), \
497+
X(KeySet, "keySet", "()Ljava/util/Set;"), \
498+
X(PutFloat, "putFloat", "(Ljava/lang/String;F)V"), \
499+
X(PutLong, "putLong", "(Ljava/lang/String;J)V"), \
500+
X(PutString, "putString", "(Ljava/lang/String;Ljava/lang/String;)V"), \
501+
X(PutBundle, "putBundle", "(Ljava/lang/String;Landroid/os/Bundle;)V")
501502
// clang-format on
502503
METHOD_LOOKUP_DECLARATION(bundle, BUNDLE_METHODS)
503504

@@ -1125,6 +1126,7 @@ jint AttachCurrentThread(JavaVM* java_vm, JNIEnv** env);
11251126
// firebase::App, either the default App (if it exists) or any valid
11261127
// App. If there is no instantiated App, returns nullptr.
11271128
JNIEnv* GetJNIEnvFromApp();
1129+
11281130
} // namespace util
11291131
// NOLINTNEXTLINE - allow namespace overridden
11301132
} // namespace firebase

app/tests/util_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,17 @@ TEST(UtilTest, SplitStringDelimetersOnly) {
5454
EXPECT_THAT(SplitString("///", '/'), IsEmpty());
5555
}
5656

57+
TEST(UtilTest, CreateApiIdentifierUnique) {
58+
int v1, v2;
59+
EXPECT_STRNE(CreateApiIdentifier("Test", &v1).c_str(),
60+
CreateApiIdentifier("Test", &v2).c_str());
61+
}
62+
63+
TEST(UtilTest, CreateApiIdentifierReallyUnique) {
64+
int v1;
65+
EXPECT_STRNE(CreateApiIdentifier("Test", &v1).c_str(),
66+
CreateApiIdentifier("Test", &v1).c_str());
67+
}
68+
5769
} // namespace
5870
} // namespace firebase

app_check/src/android/app_check_android.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "app/src/include/firebase/future.h"
2222
#include "app/src/include/firebase/internal/mutex.h"
2323
#include "app/src/reference_counted_future_impl.h"
24+
#include "app/src/util.h"
2425
#include "app/src/util_android.h"
2526
#include "app_check/app_check_resources.h"
2627
#include "app_check/src/android/common_android.h"
@@ -135,8 +136,6 @@ static const JNINativeMethod kNativeJniAppCheckListenerMethods[] = {
135136
reinterpret_cast<void*>(JniAppCheckListener_nativeOnAppCheckTokenChanged)},
136137
};
137138

138-
static const char* kApiIdentifier = "AppCheck";
139-
140139
static AppCheckProviderFactory* g_provider_factory = nullptr;
141140
static int g_initialized_count = 0;
142141

@@ -306,6 +305,9 @@ AppCheckInternal::AppCheckInternal(App* app) : app_(app) {
306305
g_initialized_count++;
307306
}
308307

308+
static const char* kApiIdentifier = "AppCheck";
309+
jni_task_id_ = CreateApiIdentifier(kApiIdentifier, this);
310+
309311
// Create the FirebaseAppCheck class in Java.
310312
jobject platform_app = app->GetPlatformApp();
311313
jobject j_app_check_local = env->CallStaticObjectMethod(
@@ -364,6 +366,7 @@ AppCheckInternal::~AppCheckInternal() {
364366
JNIEnv* env = app_->GetJNIEnv();
365367
app_ = nullptr;
366368
listeners_.clear();
369+
util::CancelCallbacks(env, jni_task_id_.c_str());
367370

368371
if (j_app_check_listener_ != nullptr) {
369372
env->CallVoidMethod(
@@ -393,7 +396,6 @@ AppCheckInternal::~AppCheckInternal() {
393396
FIREBASE_ASSERT(g_initialized_count);
394397
g_initialized_count--;
395398
if (g_initialized_count == 0) {
396-
util::CancelCallbacks(env, kApiIdentifier);
397399
ReleaseClasses(env);
398400
util::Terminate(env);
399401
}
@@ -435,7 +437,7 @@ Future<AppCheckToken> AppCheckInternal::GetAppCheckToken(bool force_refresh) {
435437
auto data_handle = new FutureDataHandle(future(), handle);
436438
util::RegisterCallbackOnTask(env, j_task, TokenResultCallback,
437439
reinterpret_cast<void*>(data_handle),
438-
kApiIdentifier);
440+
jni_task_id_.c_str());
439441
} else {
440442
AppCheckToken empty_token;
441443
future()->CompleteWithResult(handle, kAppCheckErrorUnknown, error.c_str(),

app_check/src/android/app_check_android.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef FIREBASE_APP_CHECK_SRC_ANDROID_APP_CHECK_ANDROID_H_
1616
#define FIREBASE_APP_CHECK_SRC_ANDROID_APP_CHECK_ANDROID_H_
1717

18+
#include <string>
1819
#include <vector>
1920

2021
#include "app/src/future_manager.h"
@@ -70,6 +71,9 @@ class AppCheckInternal {
7071
Mutex listeners_mutex_;
7172

7273
FutureManager future_manager_;
74+
75+
// String to be used when registering for JNI task callbacks.
76+
std::string jni_task_id_;
7377
};
7478

7579
} // namespace internal

app_check/src/android/common_android.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string>
1818

1919
#include "app/src/app_common.h"
20+
#include "app/src/util.h"
2021
#include "app/src/util_android.h"
2122
#include "app_check/src/include/firebase/app_check.h"
2223

@@ -45,8 +46,6 @@ METHOD_LOOKUP_DEFINITION(app_check_token,
4546
"com/google/firebase/appcheck/AppCheckToken",
4647
APP_CHECK_TOKEN_METHODS)
4748

48-
static const char* kApiIdentifier = "AppCheckProvider";
49-
5049
bool CacheCommonAndroidMethodIds(JNIEnv* env, jobject activity) {
5150
// Cache the token and provider classes.
5251
if (!(app_check_token::CacheMethodIds(env, activity) &&
@@ -124,12 +123,15 @@ void TokenResultCallback(JNIEnv* env, jobject result,
124123

125124
AndroidAppCheckProvider::AndroidAppCheckProvider(jobject local_provider)
126125
: android_provider_(nullptr) {
126+
static const char* kApiIdentifier = "AppCheckProvider";
127+
jni_task_id_ = CreateApiIdentifier(kApiIdentifier, this);
127128
JNIEnv* env = GetJniEnv();
128129
android_provider_ = env->NewGlobalRef(local_provider);
129130
}
130131

131132
AndroidAppCheckProvider::~AndroidAppCheckProvider() {
132133
JNIEnv* env = GetJniEnv();
134+
util::CancelCallbacks(env, jni_task_id_.c_str());
133135
if (env != nullptr && android_provider_ != nullptr) {
134136
env->DeleteGlobalRef(android_provider_);
135137
}
@@ -150,7 +152,8 @@ void AndroidAppCheckProvider::GetToken(
150152
new TokenResultCallbackData(completion_callback);
151153
util::RegisterCallbackOnTask(
152154
env, j_task, TokenResultCallback,
153-
reinterpret_cast<void*>(completion_callback_data), kApiIdentifier);
155+
reinterpret_cast<void*>(completion_callback_data),
156+
jni_task_id_.c_str());
154157
} else {
155158
AppCheckToken empty_token;
156159
completion_callback(empty_token, kAppCheckErrorUnknown, error.c_str());

app_check/src/android/common_android.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class AndroidAppCheckProvider : public AppCheckProvider {
6161

6262
private:
6363
jobject android_provider_;
64+
65+
// String to be used when registering for JNI task callbacks.
66+
std::string jni_task_id_;
6467
};
6568

6669
} // namespace internal

auth/src/android/credential_android.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ void PhoneAuthProvider::VerifyPhoneNumber(
955955
jobject timeout = env->NewObject(
956956
util::long_class::GetClass(),
957957
util::long_class::GetMethodId(util::long_class::kConstructor),
958-
options.timeout_milliseconds);
958+
static_cast<jlong>(options.timeout_milliseconds));
959959
if (util::CheckAndClearJniExceptions(env)) {
960960
listener->OnVerificationFailed(
961961
"VerifyPhoneNumber: couldn't convert timeout to java.lang.Long.");
@@ -988,7 +988,7 @@ void PhoneAuthProvider::VerifyPhoneNumber(
988988
if (util::CheckAndClearJniExceptions(env)) {
989989
env->DeleteLocalRef(builder);
990990
listener->OnVerificationFailed(
991-
"VerifyPhoneNumber: builder faild to create PhoneAuhtOptions");
991+
"VerifyPhoneNumber: builder failed to create PhoneAuthOptions");
992992
return;
993993
}
994994
env->DeleteLocalRef(builder);
@@ -1003,7 +1003,7 @@ void PhoneAuthProvider::VerifyPhoneNumber(
10031003
// If an error occurred with the call to verifyPhoneNumber, inform the
10041004
// listener that it failed.
10051005
listener->OnVerificationFailed(
1006-
"VerifyPhoneNumber: Android to verify the given phone number");
1006+
"VerifyPhoneNumber: Android failed to verify the given phone number");
10071007
}
10081008

10091009
env->DeleteLocalRef(phone_auth_options);

auth/src/auth.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,8 @@ Auth::Auth(App* app, void* auth_impl) : auth_data_(new AuthData) {
111111
auth_data_->user_impl = nullptr;
112112
InitPlatformAuth(auth_data_);
113113

114-
std::string* future_id = &auth_data_->future_api_id;
115114
static const char* kApiIdentifier = "Auth";
116-
future_id->reserve(strlen(kApiIdentifier) +
117-
16 /* hex characters in the pointer */ +
118-
1 /* null terminator */);
119-
snprintf(&((*future_id)[0]), future_id->capacity(), "%s0x%016llx",
120-
kApiIdentifier,
121-
static_cast<unsigned long long>( // NOLINT
122-
reinterpret_cast<intptr_t>(this)));
115+
auth_data_->future_api_id = CreateApiIdentifier(kApiIdentifier, this);
123116

124117
// Cleanup this object if app is destroyed.
125118
CleanupNotifier* notifier = CleanupNotifier::FindByOwner(app);

cmake/external/boringssl.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ if(TARGET boringssl OR NOT DOWNLOAD_BORINGSSL)
1818
return()
1919
endif()
2020

21-
set(patch_file
22-
${CMAKE_CURRENT_LIST_DIR}/../../scripts/git/patches/boringssl/0001-disable-warnings.patch)
21+
set(patch_file ${CMAKE_CURRENT_LIST_DIR}/../../scripts/git/patches/boringssl/0001-disable-warnings.patch)
2322

24-
set(boringssl_commit_tag 83da28a68f32023fd3b95a8ae94991a07b1f6c62)
23+
set(boringssl_commit_tag fips-20220613)
2524

2625
ExternalProject_Add(
2726
boringssl

cmake/external_rules.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ function(download_external_sources)
112112
if (FIREBASE_USE_BORINGSSL)
113113
# CMake's find_package(OpenSSL) doesn't quite work right with BoringSSL
114114
# unless the header file contains OPENSSL_VERSION_NUMBER.
115-
file(READ ${PROJECT_BINARY_DIR}/external/src/boringssl/src/include/openssl/opensslv.h TMP_HEADER_CONTENTS)
115+
file(READ ${PROJECT_BINARY_DIR}/external/src/boringssl/include/openssl/opensslv.h TMP_HEADER_CONTENTS)
116116
if (NOT TMP_HEADER_CONTENTS MATCHES OPENSSL_VERSION_NUMBER)
117-
file(APPEND ${PROJECT_BINARY_DIR}/external/src/boringssl/src/include/openssl/opensslv.h
117+
file(APPEND ${PROJECT_BINARY_DIR}/external/src/boringssl/include/openssl/opensslv.h
118118
"\n#ifndef OPENSSL_VERSION_NUMBER\n# define OPENSSL_VERSION_NUMBER 0x10010107L\n#endif\n")
119119
endif()
120120
# Also add an #include <stdlib.h> since openssl has it and boringssl
121121
# doesn't, and some of our code depends on the transitive dependency (this
122122
# is a bug).
123-
file(READ ${PROJECT_BINARY_DIR}/external/src/boringssl/src/include/openssl/rand.h TMP_HEADER2_CONTENTS)
123+
file(READ ${PROJECT_BINARY_DIR}/external/src/boringssl/include/openssl/rand.h TMP_HEADER2_CONTENTS)
124124
if (NOT TMP_HEADER2_CONTENTS MATCHES "<stdlib.h>")
125-
file(APPEND ${PROJECT_BINARY_DIR}/external/src/boringssl/src/include/openssl/rand.h
125+
file(APPEND ${PROJECT_BINARY_DIR}/external/src/boringssl/include/openssl/rand.h
126126
"\n#include <stdlib.h>\n")
127127
endif()
128128
endif()
@@ -241,7 +241,7 @@ function(build_external_dependencies)
241241
if(NOT ANDROID AND NOT IOS)
242242
if (FIREBASE_USE_BORINGSSL)
243243
execute_process(
244-
COMMAND ${ENV_COMMAND} cmake -DOPENSSL_NO_ASM=TRUE ${CMAKE_SUB_CONFIGURE_OPTIONS} ../boringssl/src
244+
COMMAND ${ENV_COMMAND} cmake -DOPENSSL_NO_ASM=TRUE ${CMAKE_SUB_CONFIGURE_OPTIONS} ../boringssl
245245
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external/src/boringssl-build
246246
RESULT_VARIABLE boringssl_configure_status
247247
)

database/src/android/database_android.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "app/src/include/firebase/internal/common.h"
2525
#include "app/src/include/firebase/log.h"
2626
#include "app/src/reference_counted_future_impl.h"
27+
#include "app/src/util.h"
2728
#include "app/src/util_android.h"
2829
#include "database/database_resources.h"
2930
#include "database/src/android/data_snapshot_android.h"
@@ -172,6 +173,7 @@ DatabaseInternal::DatabaseInternal(App* app)
172173
app_ = nullptr;
173174
if (!Initialize(app)) return;
174175
app_ = app;
176+
jni_task_id_ = CreateApiIdentifier(kApiIdentifier, this);
175177

176178
JNIEnv* env = app_->GetJNIEnv();
177179
jobject platform_app = app->GetPlatformApp();
@@ -198,6 +200,7 @@ DatabaseInternal::DatabaseInternal(App* app, const char* url)
198200
app_ = nullptr;
199201
if (!Initialize(app)) return;
200202
app_ = app;
203+
jni_task_id_ = CreateApiIdentifier(kApiIdentifier, this);
201204

202205
JNIEnv* env = app_->GetJNIEnv();
203206
jobject url_string = env->NewStringUTF(url);
@@ -399,6 +402,7 @@ DatabaseInternal::~DatabaseInternal() {
399402
cleanup_.CleanupAll();
400403

401404
JNIEnv* env = app_->GetJNIEnv();
405+
util::CancelCallbacks(env, jni_task_id_.c_str());
402406
{
403407
// If there are any pending listeners, delete their pointers.
404408
MutexLock lock(listener_mutex_);

database/src/android/database_android.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <map>
2121
#include <set>
22+
#include <string>
2223
#include <vector>
2324

2425
#include "app/src/cleanup_notifier.h"
@@ -42,10 +43,6 @@ namespace internal {
4243
// For constructing, copying or moving DatabaseReferences atomically.
4344
extern Mutex g_database_reference_constructor_mutex;
4445

45-
// Used for registering global callbacks. See
46-
// firebase::util::RegisterCallbackOnTask for context.
47-
extern const char kApiIdentifier[];
48-
4946
// This is the Android implementation of Database.
5047
class DatabaseInternal {
5148
public:
@@ -183,6 +180,10 @@ class DatabaseInternal {
183180

184181
Logger* logger() { return &logger_; }
185182

183+
// Used for registering global callbacks. See
184+
// firebase::util::RegisterCallbackOnTask for context.
185+
const char* jni_task_id() { return jni_task_id_.c_str(); }
186+
186187
private:
187188
static bool Initialize(App* app);
188189
static void ReleaseClasses(App* app);
@@ -222,6 +223,9 @@ class DatabaseInternal {
222223
std::string constructor_url_;
223224

224225
Logger logger_;
226+
227+
// String to be used when registering for JNI task callbacks.
228+
std::string jni_task_id_;
225229
};
226230

227231
} // namespace internal

0 commit comments

Comments
 (0)