|
21 | 21 | #include "app/src/include/firebase/future.h" |
22 | 22 | #include "app/src/include/firebase/internal/mutex.h" |
23 | 23 | #include "app/src/reference_counted_future_impl.h" |
| 24 | +#include "app/src/util.h" |
24 | 25 | #include "app/src/util_android.h" |
25 | 26 | #include "app_check/app_check_resources.h" |
26 | 27 | #include "app_check/src/android/common_android.h" |
@@ -135,8 +136,6 @@ static const JNINativeMethod kNativeJniAppCheckListenerMethods[] = { |
135 | 136 | reinterpret_cast<void*>(JniAppCheckListener_nativeOnAppCheckTokenChanged)}, |
136 | 137 | }; |
137 | 138 |
|
138 | | -static const char* kApiIdentifier = "AppCheck"; |
139 | | - |
140 | 139 | static AppCheckProviderFactory* g_provider_factory = nullptr; |
141 | 140 | static int g_initialized_count = 0; |
142 | 141 |
|
@@ -306,6 +305,9 @@ AppCheckInternal::AppCheckInternal(App* app) : app_(app) { |
306 | 305 | g_initialized_count++; |
307 | 306 | } |
308 | 307 |
|
| 308 | + static const char* kApiIdentifier = "AppCheck"; |
| 309 | + jni_task_id_ = CreateApiIdentifier(kApiIdentifier, this); |
| 310 | + |
309 | 311 | // Create the FirebaseAppCheck class in Java. |
310 | 312 | jobject platform_app = app->GetPlatformApp(); |
311 | 313 | jobject j_app_check_local = env->CallStaticObjectMethod( |
@@ -364,6 +366,7 @@ AppCheckInternal::~AppCheckInternal() { |
364 | 366 | JNIEnv* env = app_->GetJNIEnv(); |
365 | 367 | app_ = nullptr; |
366 | 368 | listeners_.clear(); |
| 369 | + util::CancelCallbacks(env, jni_task_id_.c_str()); |
367 | 370 |
|
368 | 371 | if (j_app_check_listener_ != nullptr) { |
369 | 372 | env->CallVoidMethod( |
@@ -393,7 +396,6 @@ AppCheckInternal::~AppCheckInternal() { |
393 | 396 | FIREBASE_ASSERT(g_initialized_count); |
394 | 397 | g_initialized_count--; |
395 | 398 | if (g_initialized_count == 0) { |
396 | | - util::CancelCallbacks(env, kApiIdentifier); |
397 | 399 | ReleaseClasses(env); |
398 | 400 | util::Terminate(env); |
399 | 401 | } |
@@ -435,7 +437,7 @@ Future<AppCheckToken> AppCheckInternal::GetAppCheckToken(bool force_refresh) { |
435 | 437 | auto data_handle = new FutureDataHandle(future(), handle); |
436 | 438 | util::RegisterCallbackOnTask(env, j_task, TokenResultCallback, |
437 | 439 | reinterpret_cast<void*>(data_handle), |
438 | | - kApiIdentifier); |
| 440 | + jni_task_id_.c_str()); |
439 | 441 | } else { |
440 | 442 | AppCheckToken empty_token; |
441 | 443 | future()->CompleteWithResult(handle, kAppCheckErrorUnknown, error.c_str(), |
|
0 commit comments