Skip to content

Commit

Permalink
fix(app, android): require default firebase.json boolean key (#4791)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mikehardy authored Jan 18, 2021
1 parent b4fb976 commit 483d9d3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/admob/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/app/android/firebase-json.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down

1 comment on commit 483d9d3

@vercel
Copy link

@vercel vercel bot commented on 483d9d3 Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.