Skip to content

Commit

Permalink
Parse MigratedAutoLogValues from the server
Browse files Browse the repository at this point in the history
Summary:
**Context**
Auto Log App Events will be able to be set up in Developer Platform Center.
We need to pass the setting down to FBSDK.

**Change in this diff**
- Introduce two new server-side flags: `auto_log_app_events_default` and `auto_log_app_events_enabled`
- Parse and store these flags in the configuration

Reviewed By: xta0

Differential Revision: D51265952

fbshipit-source-id: 4d9b7f894734984e47d413d0ef298daff393dccf
  • Loading branch information
Xinzhu Cai authored and facebook-github-bot committed Nov 17, 2023
1 parent ed8afd4 commit 8381639
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class FetchedAppSettings(
val suggestedEventsSetting: String?,
val restrictiveDataSetting: String?,
val protectedModeStandardParamsSetting: JSONArray?,
val MACARuleMatchingSetting: JSONArray?
val MACARuleMatchingSetting: JSONArray?,
val migratedAutoLogValues: Map<String, Boolean>?
) {

fun supportsImplicitLogging(): Boolean = supportsImplicitLogging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.facebook.core.BuildConfig
import com.facebook.internal.FetchedAppGateKeepersManager.queryAppGateKeepers
import com.facebook.internal.InternalSettings.isUnityApp
import com.facebook.internal.SmartLoginOption.Companion.parseOptions
import com.facebook.internal.Utility.isNullOrEmpty
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -68,6 +67,9 @@ object FetchedAppSettingsManager {
private const val STANDARD_PARAMS_KEY = "standard_params"
private const val MACA_RULES_KEY = "maca_rules"

private const val AUTO_LOG_APP_EVENTS_DEFAULT_FIELD = "auto_log_app_events_default"
private const val AUTO_LOG_APP_EVENT_ENABLED_FIELD = "auto_log_app_events_enabled"

private val APP_SETTING_FIELDS =
listOf(
APP_SETTING_SUPPORTS_IMPLICIT_SDK_LOGGING,
Expand All @@ -84,7 +86,9 @@ object FetchedAppSettingsManager {
APP_SETTING_RESTRICTIVE_EVENT_FILTER_FIELD,
APP_SETTING_APP_EVENTS_AAM_RULE,
SUGGESTED_EVENTS_SETTING,
PROTECTED_MODE_RULES)
PROTECTED_MODE_RULES,
AUTO_LOG_APP_EVENTS_DEFAULT_FIELD,
AUTO_LOG_APP_EVENT_ENABLED_FIELD)
private const val APPLICATION_FIELDS = GraphRequest.FIELDS_PARAM
private val fetchedAppSettings: MutableMap<String, FetchedAppSettings> = ConcurrentHashMap()
private val loadingState = AtomicReference(FetchAppSettingState.NOT_LOADED)
Expand Down Expand Up @@ -266,7 +270,8 @@ object FetchedAppSettingsManager {
settingsJSON.optString(SUGGESTED_EVENTS_SETTING),
settingsJSON.optString(APP_SETTING_RESTRICTIVE_EVENT_FILTER_FIELD),
parseProtectedModeRules(settingsJSON.optJSONObject(PROTECTED_MODE_RULES), STANDARD_PARAMS_KEY),
parseProtectedModeRules(settingsJSON.optJSONObject(PROTECTED_MODE_RULES), MACA_RULES_KEY),
parseProtectedModeRules(settingsJSON.optJSONObject(PROTECTED_MODE_RULES), MACA_RULES_KEY),
parseMigratedAutoLogValues(settingsJSON),
)
fetchedAppSettings[applicationId] = result
return result
Expand Down Expand Up @@ -333,6 +338,34 @@ object FetchedAppSettingsManager {
}
return rule
}

private fun parseMigratedAutoLogValues(settingsJSON: JSONObject?): Map<String, Boolean>? {
if (settingsJSON == null) {
return null
}

var values: MutableMap<String, Boolean> = HashMap()
if (!settingsJSON?.isNull(AUTO_LOG_APP_EVENTS_DEFAULT_FIELD)) {
try {
values[AUTO_LOG_APP_EVENTS_DEFAULT_FIELD] = settingsJSON?.getBoolean(AUTO_LOG_APP_EVENTS_DEFAULT_FIELD)
} catch (je: JSONException) {
Utility.logd(Utility.LOG_TAG, je)
}
}
if (!settingsJSON?.isNull(AUTO_LOG_APP_EVENT_ENABLED_FIELD)) {
try {
values[AUTO_LOG_APP_EVENT_ENABLED_FIELD] = settingsJSON?.getBoolean(AUTO_LOG_APP_EVENT_ENABLED_FIELD)
} catch (je: JSONException) {
Utility.logd(Utility.LOG_TAG, je)
}
}

return if (values.isEmpty()) {
null
} else {
values
}
}

internal enum class FetchAppSettingState {
NOT_LOADED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ProtectedModeManagerTest : FacebookPowerMockTestCase() {
restrictiveDataSetting = "",
protectedModeStandardParamsSetting = mockStandardParams,
MACARuleMatchingSetting = emptyJSONArray,
migratedAutoLogValues = null,
)
PowerMockito.mockStatic(FetchedAppSettingsManager::class.java)
whenever(FetchedAppSettingsManager.queryAppSettings(mockAppID, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class FetchedAppSettingsManagerTest : FacebookPowerMockTestCase() {
" \"seamless_login\": 1,\n" +
" \"smart_login_bookmark_icon_url\": \"swag\",\n" +
" \"smart_login_menu_icon_url\": \"yolo\",\n" +
" \"android_dialog_configs\": \"garbage\"\n" +
" \"android_dialog_configs\": \"garbage\",\n" +
" \"auto_log_app_events_default\": true,\n" +
" \"auto_log_app_events_enabled\": true\n" +
"}"

private val invalidValueTypesJson =
Expand All @@ -52,6 +54,9 @@ class FetchedAppSettingsManagerTest : FacebookPowerMockTestCase() {
assertEquals("swag", result.smartLoginBookmarkIconURL)
assertEquals("yolo", result.smartLoginMenuIconURL)
assertThat(result.dialogConfigurations.isEmpty()).isTrue
assertThat(result.migratedAutoLogValues).isNotEmpty
assertThat(result.migratedAutoLogValues?.get("auto_log_app_events_default")).isTrue
assertThat(result.migratedAutoLogValues?.get("auto_log_app_events_enabled")).isTrue

// defaults
assertThat(result.nuxEnabled).isFalse
Expand Down

0 comments on commit 8381639

Please sign in to comment.