-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathapp_android.cc
More file actions
595 lines (540 loc) · 24.5 KB
/
Copy pathapp_android.cc
File metadata and controls
595 lines (540 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/*
* Copyright 2016 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app/src/app_android.h"
#include <jni.h>
#include <string.h>
#include <cassert>
#include <string>
#include <vector>
#include "app/src/app_common.h"
#include "app/src/assert.h"
#include "app/src/google_play_services/availability_android.h"
#include "app/src/include/firebase/app.h"
#include "app/src/include/firebase/version.h"
#include "app/src/jobject_reference.h"
#include "app/src/log.h"
#include "app/src/util.h"
#include "app/src/util_android.h"
namespace firebase {
DEFINE_FIREBASE_VERSION_STRING(Firebase);
namespace internal {
JOBJECT_REFERENCE(AppInternal);
} // namespace internal
// Namespace and class for FirebaseApp.
// java/com/google/android/gmscore/*/client/firebase-common/src/com/google/\
// firebase/FirebaseApp.java
// clang-format off
#define FIREBASE_APP_METHODS(X) \
X(InitializeApp, "initializeApp", \
"(Landroid/content/Context;Lcom/google/firebase/FirebaseOptions;" \
"Ljava/lang/String;)Lcom/google/firebase/FirebaseApp;", \
util::kMethodTypeStatic), \
X(InitializeDefaultApp, "initializeApp", \
"(Landroid/content/Context;Lcom/google/firebase/FirebaseOptions;)" \
"Lcom/google/firebase/FirebaseApp;", \
util::kMethodTypeStatic), \
X(GetInstance, "getInstance", "()Lcom/google/firebase/FirebaseApp;", \
util::kMethodTypeStatic), \
X(GetInstanceByName, "getInstance", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseApp;", \
util::kMethodTypeStatic), \
X(GetName, "getName", "()Ljava/lang/String;", util::kMethodTypeInstance), \
X(GetOptions, "getOptions", "()Lcom/google/firebase/FirebaseOptions;", \
util::kMethodTypeInstance), \
X(Delete, "delete", "()V", util::kMethodTypeInstance), \
X(IsDataCollectionDefaultEnabled, "isDataCollectionDefaultEnabled", \
"()Z", util::kMethodTypeInstance, util::kMethodOptional), \
X(SetDataCollectionDefaultEnabled, "setDataCollectionDefaultEnabled", \
"(Z)V", util::kMethodTypeInstance, util::kMethodOptional)
// clang-format on
METHOD_LOOKUP_DECLARATION(app, FIREBASE_APP_METHODS)
METHOD_LOOKUP_DEFINITION(app,
PROGUARD_KEEP_CLASS "com/google/firebase/FirebaseApp",
FIREBASE_APP_METHODS)
// clang-format off
#define FIREBASE_OPTIONS_BUILDER_METHODS(X) \
X(Constructor, "<init>", "()V", util::kMethodTypeInstance), \
X(SetApiKey, "setApiKey", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseOptions$Builder;", \
util::kMethodTypeInstance), \
X(SetDatabaseUrl, "setDatabaseUrl", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseOptions$Builder;", \
util::kMethodTypeInstance), \
X(SetApplicationId, "setApplicationId", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseOptions$Builder;", \
util::kMethodTypeInstance), \
X(SetGcmSenderId, "setGcmSenderId", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseOptions$Builder;", \
util::kMethodTypeInstance), \
X(SetStorageBucket, "setStorageBucket", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseOptions$Builder;", \
util::kMethodTypeInstance), \
X(SetProjectId, "setProjectId", \
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseOptions$Builder;", \
util::kMethodTypeInstance, util::kMethodOptional), \
X(Build, "build", \
"()Lcom/google/firebase/FirebaseOptions;")
// clang-format on
METHOD_LOOKUP_DECLARATION(options_builder, FIREBASE_OPTIONS_BUILDER_METHODS)
METHOD_LOOKUP_DEFINITION(options_builder,
PROGUARD_KEEP_CLASS
"com/google/firebase/FirebaseOptions$Builder",
FIREBASE_OPTIONS_BUILDER_METHODS)
// clang-format off
#define FIREBASE_OPTIONS_METHODS(X) \
X(FromResource, "fromResource", \
"(Landroid/content/Context;)Lcom/google/firebase/FirebaseOptions;", \
util::kMethodTypeStatic), \
X(GetApiKey, "getApiKey", "()Ljava/lang/String;", \
util::kMethodTypeInstance), \
X(GetApplicationId, "getApplicationId", "()Ljava/lang/String;", \
util::kMethodTypeInstance), \
X(GetDatabaseUrl, "getDatabaseUrl", "()Ljava/lang/String;", \
util::kMethodTypeInstance), \
X(GetGcmSenderId, "getGcmSenderId", "()Ljava/lang/String;", \
util::kMethodTypeInstance), \
X(GetStorageBucket, "getStorageBucket", "()Ljava/lang/String;", \
util::kMethodTypeInstance), \
X(GetProjectId, "getProjectId", "()Ljava/lang/String;", \
util::kMethodTypeInstance)
// clang-format on
METHOD_LOOKUP_DECLARATION(options, FIREBASE_OPTIONS_METHODS)
METHOD_LOOKUP_DEFINITION(options,
PROGUARD_KEEP_CLASS
"com/google/firebase/FirebaseOptions",
FIREBASE_OPTIONS_METHODS)
// clang-format off
#define GLOBAL_LIBRARY_VERSION_REGISTAR_METHODS(X) \
X(GetInstance, "getInstance", \
"()Lcom/google/firebase/platforminfo/GlobalLibraryVersionRegistrar;", \
util::kMethodTypeStatic), \
X(RegisterVersion, "registerVersion", \
"(Ljava/lang/String;Ljava/lang/String;)V", \
util::kMethodTypeInstance), \
X(GetRegisteredVersions, "getRegisteredVersions", "()Ljava/util/Set;", \
util::kMethodTypeInstance)
// clang-format on
METHOD_LOOKUP_DECLARATION(version_registrar,
GLOBAL_LIBRARY_VERSION_REGISTAR_METHODS)
METHOD_LOOKUP_DEFINITION(
version_registrar,
PROGUARD_KEEP_CLASS
"com/google/firebase/platforminfo/GlobalLibraryVersionRegistrar",
GLOBAL_LIBRARY_VERSION_REGISTAR_METHODS)
namespace {
static int g_methods_cached_count = 0;
static bool g_initialized_google_play_services = false;
void ReleaseClasses(JNIEnv* env);
// Cache FirebaseApp and FirebaseOptions method IDs.
bool CacheMethods(JNIEnv* env, jobject activity) {
bool initialize = g_methods_cached_count == 0;
g_methods_cached_count++;
if (initialize) {
if (!util::Initialize(env, activity)) {
g_methods_cached_count = 0;
return false;
}
if (!(app::CacheMethodIds(env, activity) &&
options_builder::CacheMethodIds(env, activity) &&
options::CacheMethodIds(env, activity) &&
version_registrar::CacheMethodIds(env, activity))) {
ReleaseClasses(env);
return false;
}
if (google_play_services::Initialize(env, activity)) {
g_initialized_google_play_services = true;
}
}
return true;
}
void ReleaseClasses(JNIEnv* env) {
FIREBASE_ASSERT(g_methods_cached_count);
g_methods_cached_count--;
if (g_methods_cached_count == 0) {
app::ReleaseClass(env);
options_builder::ReleaseClass(env);
options::ReleaseClass(env);
version_registrar::ReleaseClass(env);
if (g_initialized_google_play_services) {
google_play_services::Terminate(env);
g_initialized_google_play_services = false;
}
util::Terminate(env);
}
}
static void PlatformOptionsBuilderSetString(JNIEnv* jni_env, jobject builder,
const char* value,
options_builder::Method setter_id) {
jstring string_value = jni_env->NewStringUTF(value);
jobject builder_discard = jni_env->CallObjectMethod(
builder, options_builder::GetMethodId(setter_id), string_value);
util::LogException(jni_env, kLogLevelWarning, "Failed to set AppOption");
if (builder_discard) jni_env->DeleteLocalRef(builder_discard);
jni_env->DeleteLocalRef(string_value);
}
// Returns a reference to a new FirebaseOptions class.
static jobject AppOptionsToPlatformOptions(JNIEnv* jni_env,
const AppOptions& app_options) {
// Create a new android.net.Uri.Builder.
jobject builder;
builder = jni_env->NewObject(
options_builder::GetClass(),
options_builder::GetMethodId(options_builder::kConstructor));
PlatformOptionsBuilderSetString(jni_env, builder, app_options.api_key(),
options_builder::kSetApiKey);
if (strlen(app_options.database_url())) {
PlatformOptionsBuilderSetString(jni_env, builder,
app_options.database_url(),
options_builder::kSetDatabaseUrl);
}
if (strlen(app_options.app_id())) {
PlatformOptionsBuilderSetString(jni_env, builder, app_options.app_id(),
options_builder::kSetApplicationId);
}
if (strlen(app_options.messaging_sender_id())) {
PlatformOptionsBuilderSetString(jni_env, builder,
app_options.messaging_sender_id(),
options_builder::kSetGcmSenderId);
}
if (strlen(app_options.storage_bucket())) {
PlatformOptionsBuilderSetString(jni_env, builder,
app_options.storage_bucket(),
options_builder::kSetStorageBucket);
}
if (strlen(app_options.project_id())) {
PlatformOptionsBuilderSetString(jni_env, builder, app_options.project_id(),
options_builder::kSetProjectId);
}
// Call builder.build() and release the builder.
jobject firebase_options = jni_env->CallObjectMethod(
builder, options_builder::GetMethodId(options_builder::kBuild));
// An exception occurred and has been logged.
bool failed = util::LogException(jni_env, kLogLevelError,
"Could not initialize Firebase App Options");
jni_env->DeleteLocalRef(builder);
// Return the jobject. The caller is responsible for calling DeleteLocalRef().
return failed ? nullptr : firebase_options;
}
// Convert Android SDK FirebaseOptions into AppOptions for all fields that are
// not populated in AppOptions.
static void PlatformOptionsToAppOptions(JNIEnv* jni_env,
jobject firebase_options,
AppOptions* app_options) {
if (!strlen(app_options->api_key())) {
jobject api_key = jni_env->CallObjectMethod(
firebase_options, options::GetMethodId(options::kGetApiKey));
if (!util::CheckAndClearJniExceptions(jni_env)) {
app_options->set_api_key(
util::JniStringToString(jni_env, api_key).c_str());
}
}
if (!strlen(app_options->app_id())) {
jobject app_id = jni_env->CallObjectMethod(
firebase_options, options::GetMethodId(options::kGetApplicationId));
if (!util::CheckAndClearJniExceptions(jni_env)) {
app_options->set_app_id(util::JniStringToString(jni_env, app_id).c_str());
}
}
if (!strlen(app_options->database_url())) {
jobject database_url = jni_env->CallObjectMethod(
firebase_options, options::GetMethodId(options::kGetDatabaseUrl));
if (!util::CheckAndClearJniExceptions(jni_env)) {
app_options->set_database_url(
util::JniStringToString(jni_env, database_url).c_str());
}
}
if (!strlen(app_options->messaging_sender_id())) {
jobject gcm_sender_id = jni_env->CallObjectMethod(
firebase_options, options::GetMethodId(options::kGetGcmSenderId));
if (!util::CheckAndClearJniExceptions(jni_env)) {
app_options->set_messaging_sender_id(
util::JniStringToString(jni_env, gcm_sender_id).c_str());
}
}
if (!strlen(app_options->storage_bucket())) {
jobject storage_bucket = jni_env->CallObjectMethod(
firebase_options, options::GetMethodId(options::kGetStorageBucket));
if (!util::CheckAndClearJniExceptions(jni_env)) {
app_options->set_storage_bucket(
util::JniStringToString(jni_env, storage_bucket).c_str());
}
}
if (!strlen(app_options->project_id())) {
jobject project_id = jni_env->CallObjectMethod(
firebase_options, options::GetMethodId(options::kGetProjectId));
if (!util::CheckAndClearJniExceptions(jni_env)) {
app_options->set_project_id(
util::JniStringToString(jni_env, project_id).c_str());
}
}
}
// Find an Android SDK FirebaseApp instance by name.
// Returns a local jobject reference if successful, nullptr otherwise.
static jobject GetPlatformAppByName(JNIEnv* jni_env, const char* name) {
jobject platform_app;
if (app_common::IsDefaultAppName(name)) {
platform_app = jni_env->CallStaticObjectMethod(
app::GetClass(), app::GetMethodId(app::kGetInstance));
} else {
jobject name_string = jni_env->NewStringUTF(name);
platform_app = jni_env->CallStaticObjectMethod(
app::GetClass(), app::GetMethodId(app::kGetInstanceByName),
name_string);
jni_env->DeleteLocalRef(name_string);
}
if (jni_env->ExceptionCheck()) {
// Explicitly set `platform_app` to `NULL` if an exception was thrown
// because on KitKat (API 19) `CallStaticObjectMethod()` may return garbage
// instead of `NULL` if an exception was thrown, and callers of this
// function expect `NULL` to be returned if the app was not found.
platform_app = NULL; // NOLINT
}
jni_env->ExceptionClear();
return platform_app;
}
// Get options from an Android SDK FirebaseApp instance.
static void GetAppOptionsFromPlatformApp(JNIEnv* jni_env, jobject platform_app,
AppOptions* app_options) {
jobject platform_options = jni_env->CallObjectMethod(
platform_app, app::GetMethodId(app::kGetOptions));
util::CheckAndClearJniExceptions(jni_env);
assert(platform_options);
PlatformOptionsToAppOptions(jni_env, platform_options, app_options);
jni_env->DeleteLocalRef(platform_options);
}
// Create an Android SDK FirebaseApp instance.
static jobject CreatePlatformApp(JNIEnv* jni_env, const AppOptions& options,
const char* name, jobject activity) {
jobject platform_app = nullptr;
jobject platform_options = AppOptionsToPlatformOptions(jni_env, options);
if (platform_options != nullptr) {
if (app_common::IsDefaultAppName(name)) {
platform_app = jni_env->CallStaticObjectMethod(
app::GetClass(), app::GetMethodId(app::kInitializeDefaultApp),
activity, platform_options);
} else {
jstring app_name = jni_env->NewStringUTF(name);
platform_app = jni_env->CallStaticObjectMethod(
app::GetClass(), app::GetMethodId(app::kInitializeApp), activity,
platform_options, app_name);
jni_env->DeleteLocalRef(app_name);
}
jni_env->DeleteLocalRef(platform_options);
util::CheckAndClearJniExceptions(jni_env);
}
return platform_app;
}
// Create or get an Android SDK FirebaseApp instance.
// Returns local jobject reference to the Android SDK app if successful,
// nullptr otherwise.
static jobject CreateOrGetPlatformApp(JNIEnv* jni_env,
const AppOptions& options,
const char* name, jobject activity) {
jobject platform_app = GetPlatformAppByName(jni_env, name);
if (platform_app) {
AppOptions options_to_compare = options;
// Package name isn't available in the platform app's options so ignore it.
options_to_compare.set_package_name("");
// If a FirebaseApp exists, make sure it has the requested options.
AppOptions existing_options;
GetAppOptionsFromPlatformApp(jni_env, platform_app, &existing_options);
if (options_to_compare != existing_options) {
LogWarning(
"Existing instance of App %s found and options do not match "
"the requested options. Deleting %s to attempt recreation "
"with requested options.",
name, name);
// Delete this FirebaseApp instance.
jni_env->CallVoidMethod(platform_app, app::GetMethodId(app::kDelete));
util::CheckAndClearJniExceptions(jni_env);
jni_env->DeleteLocalRef(platform_app);
platform_app = nullptr;
}
}
if (!platform_app) {
AppOptions options_with_defaults = options;
if (options_with_defaults.PopulateRequiredWithDefaults(jni_env, activity)) {
platform_app =
CreatePlatformApp(jni_env, options_with_defaults, name, activity);
}
}
return platform_app;
}
} // namespace
AppOptions* AppOptions::LoadDefault(AppOptions* app_options, JNIEnv* jni_env,
jobject activity) {
if (CacheMethods(jni_env, activity)) {
// Read the options from the embedded resources.
jobject platform_options = jni_env->CallStaticObjectMethod(
options::GetClass(), options::GetMethodId(options::kFromResource),
activity);
if (jni_env->ExceptionCheck() || !platform_options) {
jni_env->ExceptionClear();
platform_options = nullptr;
app_options = nullptr;
}
if (platform_options) {
// Get the package name.
jobject package_name = jni_env->CallObjectMethod(
activity, util::context::GetMethodId(util::context::kGetPackageName));
if (util::CheckAndClearJniExceptions(jni_env)) {
app_options = nullptr;
} else {
// Populate the C++ structure.
app_options = app_options ? app_options : new AppOptions();
PlatformOptionsToAppOptions(jni_env, platform_options, app_options);
app_options->set_package_name(
util::JniStringToString(jni_env, package_name).c_str());
}
jni_env->DeleteLocalRef(platform_options);
}
ReleaseClasses(jni_env);
}
return app_options;
}
void App::Initialize() {}
App::~App() {
app_common::RemoveApp(this);
JNIEnv* env = GetJNIEnv();
delete internal_;
internal_ = nullptr;
if (activity_) {
env->DeleteGlobalRef(reinterpret_cast<jobject>(activity_));
activity_ = nullptr;
}
ReleaseClasses(env);
}
App* App::Create(JNIEnv* jni_env, jobject activity) {
App* app = nullptr;
if (CacheMethods(jni_env, activity)) {
AppOptions options;
if (AppOptions::LoadDefault(&options, jni_env, activity)) {
app = Create(options, jni_env, activity);
} else {
LogError(
"Failed to read Firebase options from the app's resources. "
"Either make sure google-services.json is included in your "
"build or specify options explicitly.");
}
ReleaseClasses(jni_env);
}
return app;
}
App* App::Create(const AppOptions& options, JNIEnv* jni_env, jobject activity) {
return Create(options, kDefaultAppName, jni_env, activity);
}
App* App::Create(const AppOptions& options, const char* name, JNIEnv* jni_env,
jobject activity) {
// If the app has already been initialize log an error.
App* app = GetInstance(name);
if (app) {
LogError("App %s already created, options will not be applied.", name);
return app;
}
LogDebug("Creating Firebase App %s for %s", name, kFirebaseVersionString);
if (CacheMethods(jni_env, activity)) {
// Register C++ user-agents before creating Android app.
app_common::RegisterSdkUsage(jni_env);
// Try to get or create a new FirebaseApp object.
jobject platform_app =
CreateOrGetPlatformApp(jni_env, options, name, activity);
if (platform_app) {
app = new App();
app->name_ = name;
app->activity_ = jni_env->NewGlobalRef(activity);
GetAppOptionsFromPlatformApp(jni_env, platform_app, &app->options_);
app->internal_ = new internal::AppInternal(
internal::AppInternal::FromLocalReference(jni_env, platform_app));
app = app_common::AddApp(app, &app->init_results_);
} else {
ReleaseClasses(jni_env);
}
}
return app;
}
App* App::GetInstance() { return app_common::GetDefaultApp(); }
App* App::GetInstance(const char* name) {
return app_common::FindAppByName(name);
}
std::vector<App*> App::GetApps() { return app_common::GetAllApps(); }
JNIEnv* App::GetJNIEnv() const { return util::GetThreadsafeJNIEnv(java_vm()); }
static void RegisterLibraryWithVersionRegistrar(JNIEnv* env,
const char* library,
const char* version) {
jobject registrar = env->CallStaticObjectMethod(
version_registrar::GetClass(),
version_registrar::GetMethodId(version_registrar::kGetInstance));
util::CheckAndClearJniExceptions(env);
FIREBASE_ASSERT(registrar != nullptr);
jstring library_string = env->NewStringUTF(library);
jstring version_string = env->NewStringUTF(version);
env->CallVoidMethod(
registrar,
version_registrar::GetMethodId(version_registrar::kRegisterVersion),
library_string, version_string);
util::CheckAndClearJniExceptions(env);
env->DeleteLocalRef(version_string);
env->DeleteLocalRef(library_string);
env->DeleteLocalRef(registrar);
}
void App::RegisterLibrary(const char* library, const char* version,
void* platform_resource) {
FIREBASE_ASSERT(platform_resource);
// Always relies on platform_resource to get reference to JNIEnv* to reduce
// complexity.
RegisterLibraryWithVersionRegistrar(
reinterpret_cast<JNIEnv*>(platform_resource), library, version);
app_common::RegisterLibrary(library, version);
}
void App::SetDefaultConfigPath(const char* /* path */) {}
void App::SetDataCollectionDefaultEnabled(bool enabled) {
if (!app::GetMethodId(app::kSetDataCollectionDefaultEnabled)) {
LogError(
"App::SetDataCollectionDefaultEnabled() is not supported by this "
"version of the Firebase Android library. Please update your project's "
"Firebase Android dependencies to firebase-core:16.0.0 or higher and "
"try again.");
return;
}
JNIEnv* env = GetJNIEnv();
env->CallVoidMethod(**internal_,
app::GetMethodId(app::kSetDataCollectionDefaultEnabled),
enabled ? JNI_TRUE : JNI_FALSE);
util::CheckAndClearJniExceptions(env);
}
bool App::IsDataCollectionDefaultEnabled() const {
if (!app::GetMethodId(app::kIsDataCollectionDefaultEnabled)) {
// By default, if this feature isn't supported, data collection must be
// enabled.
return true;
}
JNIEnv* env = GetJNIEnv();
jboolean result = env->CallBooleanMethod(
**internal_, app::GetMethodId(app::kIsDataCollectionDefaultEnabled));
util::CheckAndClearJniExceptions(env);
return result != JNI_FALSE;
}
const char* App::GetUserAgent() { return app_common::GetUserAgent(); }
JavaVM* App::java_vm() const { return internal_->java_vm(); }
jobject App::GetPlatformApp() const { return internal_->GetLocalRef(); }
void CallAfterEnsureMethodsCached(JNIEnv* env, jobject activity,
std::function<void()> callback) {
if (CacheMethods(env, activity)) {
callback();
ReleaseClasses(env);
}
}
} // namespace firebase