From 483d9d3655844e4c40cb42f3b0da865ada971515 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Mon, 18 Jan 2021 15:53:55 -0500 Subject: [PATCH] fix(app, android): require default firebase.json boolean key (#4791) This fixes the case where firebase.json existed but the key being query was missing. Previously the config system would silently fail on the missing key and return false even though the default for some keys should be true In particular this caused analytics auto collection to be disabled if you had a firebase.json but no analytics_auto_collection_enabled = true entry, even though the default should have been true Credit to @WadhahEssam for discovery, diagnosis, and general solution --- packages/admob/android/build.gradle | 2 +- packages/analytics/android/build.gradle | 2 +- packages/app/android/firebase-json.gradle | 5 +++-- packages/messaging/android/build.gradle | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/admob/android/build.gradle b/packages/admob/android/build.gradle index 1db5aa6d8e..542b34838e 100644 --- a/packages/admob/android/build.gradle +++ b/packages/admob/android/build.gradle @@ -74,7 +74,7 @@ def firebaseJSONAdmobDelayAppMeasurementInitBool = false if (rootProject.ext.firebaseJson) { firebaseJSONAdmobAppIDString = rootProject.ext.firebaseJson.getStringValue("admob_android_app_id", "") - firebaseJSONAdmobDelayAppMeasurementInitBool = rootProject.ext.firebaseJson.isFlagEnabled("admob_delay_app_measurement_init") + firebaseJSONAdmobDelayAppMeasurementInitBool = rootProject.ext.firebaseJson.isFlagEnabled("admob_delay_app_measurement_init", false) } if (!firebaseJSONAdmobAppIDString) { diff --git a/packages/analytics/android/build.gradle b/packages/analytics/android/build.gradle index 407ca31609..05cff822f3 100644 --- a/packages/analytics/android/build.gradle +++ b/packages/analytics/android/build.gradle @@ -68,7 +68,7 @@ apply from: file("./../../app/android/firebase-json.gradle") def autoCollectionEnabled = "true" if (rootProject.ext && rootProject.ext.firebaseJson) { - if (rootProject.ext.firebaseJson.isFlagEnabled("analytics_auto_collection_enabled") == false) { + if (rootProject.ext.firebaseJson.isFlagEnabled("analytics_auto_collection_enabled", true) == false) { autoCollectionEnabled = "false" } } diff --git a/packages/app/android/firebase-json.gradle b/packages/app/android/firebase-json.gradle index 8a5be94b25..c8c3bb9f6c 100644 --- a/packages/app/android/firebase-json.gradle +++ b/packages/app/android/firebase-json.gradle @@ -32,8 +32,9 @@ if (jsonFile != null && jsonFile.exists()) { rootProject.ext.firebaseJson = [ raw: json[jsonRoot], - isFlagEnabled: { key -> - return json[jsonRoot] != null && json[jsonRoot][key] == true + isFlagEnabled: { key, defaultValue -> + if (json[jsonRoot] == null || json[jsonRoot][key] == null) return defaultValue + return json[jsonRoot][key] == true ? true : false }, getStringValue: { key, defaultValue -> if (json[jsonRoot] == null) return defaultValue diff --git a/packages/messaging/android/build.gradle b/packages/messaging/android/build.gradle index 8f6c99975a..bf261eff96 100644 --- a/packages/messaging/android/build.gradle +++ b/packages/messaging/android/build.gradle @@ -72,7 +72,7 @@ def notificationColor = defaultNotificationColor if (rootProject.ext && rootProject.ext.firebaseJson) { - if (rootProject.ext.firebaseJson.isFlagEnabled("messaging_auto_init_enabled") == false) { + if (rootProject.ext.firebaseJson.isFlagEnabled("messaging_auto_init_enabled", true) == false) { autoInitEnabled = "false" } notificationChannelId = rootProject.ext.firebaseJson.getStringValue("messaging_android_notification_channel_id", "")