|
20 | 20 | #include "firestore/src/android/field_path_android.h" |
21 | 21 | #include "firestore/src/android/field_value_android.h" |
22 | 22 | #include "firestore/src/android/firebase_firestore_exception_android.h" |
23 | | -#include "firestore/src/android/firebase_firestore_settings_android.h" |
24 | 23 | #include "firestore/src/android/geo_point_android.h" |
25 | 24 | #include "firestore/src/android/lambda_event_listener.h" |
26 | 25 | #include "firestore/src/android/lambda_transaction_function.h" |
|
30 | 29 | #include "firestore/src/android/query_snapshot_android.h" |
31 | 30 | #include "firestore/src/android/server_timestamp_behavior_android.h" |
32 | 31 | #include "firestore/src/android/set_options_android.h" |
| 32 | +#include "firestore/src/android/settings_android.h" |
33 | 33 | #include "firestore/src/android/snapshot_metadata_android.h" |
34 | 34 | #include "firestore/src/android/source_android.h" |
35 | 35 | #include "firestore/src/android/timestamp_android.h" |
|
52 | 52 | namespace firebase { |
53 | 53 | namespace firestore { |
54 | 54 |
|
| 55 | +using jni::Env; |
| 56 | +using jni::Local; |
| 57 | + |
55 | 58 | const char kApiIdentifier[] = "Firestore"; |
56 | 59 |
|
57 | 60 | // clang-format off |
@@ -163,7 +166,6 @@ bool FirestoreInternal::Initialize(App* app) { |
163 | 166 | // Call Initialize on each Firestore internal class. |
164 | 167 | FieldValueInternal::Initialize(app) && |
165 | 168 | FirebaseFirestoreExceptionInternal::Initialize(app) && |
166 | | - FirebaseFirestoreSettingsInternal::Initialize(app) && |
167 | 169 | GeoPointInternal::Initialize(app) && |
168 | 170 | ListenerRegistrationInternal::Initialize(app) && |
169 | 171 | QueryInternal::Initialize(app) && |
@@ -200,6 +202,7 @@ bool FirestoreInternal::Initialize(App* app) { |
200 | 202 | MetadataChangesInternal::Initialize(loader); |
201 | 203 | ServerTimestampBehaviorInternal::Initialize(loader); |
202 | 204 | SetOptionsInternal::Initialize(loader); |
| 205 | + SettingsInternal::Initialize(loader); |
203 | 206 | SnapshotMetadataInternal::Initialize(loader); |
204 | 207 | SourceInternal::Initialize(loader); |
205 | 208 | if (!loader.ok()) { |
@@ -251,7 +254,6 @@ void FirestoreInternal::ReleaseClasses(App* app) { |
251 | 254 | EventListenerInternal::Terminate(app); |
252 | 255 | FieldValueInternal::Terminate(app); |
253 | 256 | FirebaseFirestoreExceptionInternal::Terminate(app); |
254 | | - FirebaseFirestoreSettingsInternal::Terminate(app); |
255 | 257 | GeoPointInternal::Terminate(app); |
256 | 258 | ListenerRegistrationInternal::Terminate(app); |
257 | 259 | QueryInternal::Terminate(app); |
@@ -363,27 +365,20 @@ Query FirestoreInternal::CollectionGroup(const char* collection_id) const { |
363 | 365 | } |
364 | 366 |
|
365 | 367 | Settings FirestoreInternal::settings() const { |
366 | | - JNIEnv* env = app_->GetJNIEnv(); |
367 | | - jobject settings = env->CallObjectMethod( |
| 368 | + Env env = GetEnv(); |
| 369 | + Local<SettingsInternal> settings = env.Call<SettingsInternal>( |
368 | 370 | obj_, firebase_firestore::GetMethodId(firebase_firestore::kGetSettings)); |
369 | | - FIREBASE_ASSERT(settings != nullptr); |
| 371 | + FIREBASE_ASSERT(settings); |
370 | 372 |
|
371 | | - Settings result = |
372 | | - FirebaseFirestoreSettingsInternal::JavaSettingToSetting(env, settings); |
373 | | - env->DeleteLocalRef(settings); |
374 | | - CheckAndClearJniExceptions(env); |
375 | | - return result; |
| 373 | + return settings.ToPublic(env); |
376 | 374 | } |
377 | 375 |
|
378 | 376 | void FirestoreInternal::set_settings(Settings settings) { |
379 | | - JNIEnv* env = app_->GetJNIEnv(); |
380 | | - jobject settings_jobj = |
381 | | - FirebaseFirestoreSettingsInternal::SettingToJavaSetting(env, settings); |
382 | | - env->CallVoidMethod( |
| 377 | + Env env = GetEnv(); |
| 378 | + auto java_settings = SettingsInternal::Create(env, settings); |
| 379 | + env.Call<void>( |
383 | 380 | obj_, firebase_firestore::GetMethodId(firebase_firestore::kSetSettings), |
384 | | - settings_jobj); |
385 | | - env->DeleteLocalRef(settings_jobj); |
386 | | - CheckAndClearJniExceptions(env); |
| 381 | + java_settings); |
387 | 382 | } |
388 | 383 |
|
389 | 384 | WriteBatch FirestoreInternal::batch() const { |
@@ -556,6 +551,15 @@ void FirestoreInternal::UnregisterListenerRegistration( |
556 | 551 | } |
557 | 552 | } |
558 | 553 |
|
| 554 | +jni::Env FirestoreInternal::GetEnv() const { |
| 555 | + // TODO(mcg): Investigate whether or not this method can be made static. |
| 556 | + // This will depend on whether or not we need to flag the current Firestore |
| 557 | + // instance as somehow broken in response to an exception. |
| 558 | + jni::Env env; |
| 559 | + env.SetUnhandledExceptionHandler(GlobalUnhandledExceptionHandler, nullptr); |
| 560 | + return env; |
| 561 | +} |
| 562 | + |
559 | 563 | CollectionReference FirestoreInternal::NewCollectionReference( |
560 | 564 | jni::Env& env, const jni::Object& reference) { |
561 | 565 | if (!env.ok() || !reference) return {}; |
|
0 commit comments