Skip to content

Commit 06bd6a2

Browse files
committed
Add Android utility CallAfterEnsureMethodsCached
This utility function is used internally to ensure the callback is triggered when all necessary Java classes and methods are cached.
1 parent 99994e6 commit 06bd6a2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

app/src/app_android.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,14 @@ bool App::IsDataCollectionDefaultEnabled() const {
573573

574574
const char* App::GetUserAgent() { return app_common::GetUserAgent(); }
575575

576+
void util::CallAfterEnsureMethodsCached(JNIEnv* env, jobject activity,
577+
std::function<void()> callback) {
578+
if (CacheMethods(env, activity)) {
579+
callback();
580+
ReleaseClasses(env);
581+
}
582+
}
583+
576584
JavaVM* App::java_vm() const { return internal_->java_vm(); }
577585

578586
jobject App::GetPlatformApp() const { return internal_->GetLocalRef(); }

app/src/util_android.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,12 @@ jint AttachCurrentThread(JavaVM* java_vm, JNIEnv** env);
11271127
// App. If there is no instantiated App, returns nullptr.
11281128
JNIEnv* GetJNIEnvFromApp();
11291129

1130+
// Make sure the Java classes and methods are cached before triggering the
1131+
// the callback. Can be slow if this is called BEFORE any Firebase App is
1132+
// created.
1133+
void CallAfterEnsureMethodsCached(JNIEnv* env, jobject activity,
1134+
std::function<void()> callback);
1135+
11301136
} // namespace util
11311137
// NOLINTNEXTLINE - allow namespace overridden
11321138
} // namespace firebase

0 commit comments

Comments
 (0)