Skip to content

Commit

Permalink
Rename autoLogAppEventsEnabled to autoLogAppEventsEnabledLocally
Browse files Browse the repository at this point in the history
Summary:
**Context**
Given that we introduce a new way to set Auto Log App Events on Developer Platform center and store the setting in our server, we rename the current autoLogAppEventsEnabled to autoLogAppEventsEnabledLocally to better describe the flag in FBSDK.
This variable stores the setting overridden by the dev using setter inside FBSDK.

**Change in this diff**
- Remove the flag unset warning for auto log app events in manifest file, we are not encouraging the dev to set the value in manifest. Using the server side config is the better way.
- Rename autoLogAppEventsEnabled to autoLogAppEventsEnabledLocally

Reviewed By: xta0

Differential Revision: D51375181

fbshipit-source-id: 6b44a100fa405885ba6c3fe5f2642df7ac003cf7
  • Loading branch information
Xinzhu Cai authored and facebook-github-bot committed Nov 17, 2023
1 parent 8381639 commit b881f01
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions facebook-core/src/main/java/com/facebook/UserSettingsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal object UserSettingsManager {
private const val ADVERTISER_ID_KEY = "advertiser_id"
private const val APPLICATION_FIELDS = GraphRequest.FIELDS_PARAM
private val autoInitEnabled = UserSetting(true, FacebookSdk.AUTO_INIT_ENABLED_PROPERTY)
private val autoLogAppEventsEnabled =
private val autoLogAppEventsEnabledLocally =
UserSetting(true, FacebookSdk.AUTO_LOG_APP_EVENTS_ENABLED_PROPERTY)
private val advertiserIDCollectionEnabled =
UserSetting(true, FacebookSdk.ADVERTISER_ID_COLLECTION_ENABLED_PROPERTY)
Expand All @@ -56,12 +56,6 @@ internal object UserSettingsManager {
private const val VALUE = "value"

// Warning message for App Event Flags
private const val AUTOLOG_APPEVENT_NOT_SET_WARNING =
("Please set a value for AutoLogAppEventsEnabled. Set the flag to TRUE if you want " +
"to collect app install, app launch and in-app purchase events automatically. To " +
"request user consent before collecting data, set the flag value to FALSE, then " +
"change to TRUE once user consent is received. " +
"Learn more: https://developers.facebook.com/docs/app-events/getting-started-app-events-android#disable-auto-events.")
private const val ADVERTISERID_COLLECTION_NOT_SET_WARNING =
("You haven't set a value for AdvertiserIDCollectionEnabled. Set the flag to TRUE " +
"if you want to collect Advertiser ID for better advertising and analytics " +
Expand All @@ -87,7 +81,7 @@ internal object UserSettingsManager {
userSettingPref =
FacebookSdk.getApplicationContext()
.getSharedPreferences(USER_SETTINGS, Context.MODE_PRIVATE)
initializeUserSetting(autoLogAppEventsEnabled, advertiserIDCollectionEnabled, autoInitEnabled)
initializeUserSetting(autoLogAppEventsEnabledLocally, advertiserIDCollectionEnabled, autoInitEnabled)
initializeCodelessSetupEnabledAsync()
logWarnings()
logIfSDKSettingsChanged()
Expand Down Expand Up @@ -202,9 +196,6 @@ internal object UserSettingsManager {
val ai = ctx.packageManager.getApplicationInfo(ctx.packageName, PackageManager.GET_META_DATA)
if (ai?.metaData != null) {
// Log warnings for App Event Flags
if (!ai.metaData.containsKey(FacebookSdk.AUTO_LOG_APP_EVENTS_ENABLED_PROPERTY)) {
Log.w(TAG, AUTOLOG_APPEVENT_NOT_SET_WARNING)
}
if (!ai.metaData.containsKey(FacebookSdk.ADVERTISER_ID_COLLECTION_ENABLED_PROPERTY)) {
Log.w(TAG, ADVERTISERID_COLLECTION_NOT_SET_WARNING)
}
Expand All @@ -228,7 +219,7 @@ internal object UserSettingsManager {
var bitmask = 0
var bit = 0
bitmask = bitmask or ((if (autoInitEnabled.getValue()) 1 else 0) shl bit++)
bitmask = bitmask or ((if (autoLogAppEventsEnabled.getValue()) 1 else 0) shl bit++)
bitmask = bitmask or ((if (autoLogAppEventsEnabledLocally.getValue()) 1 else 0) shl bit++)
bitmask = bitmask or ((if (advertiserIDCollectionEnabled.getValue()) 1 else 0) shl bit++)
bitmask = bitmask or ((if (monitorEnabled.getValue()) 1 else 0) shl bit++)
val previousBitmask = userSettingPref.getInt(USER_SETTINGS_BITMASK, 0)
Expand Down Expand Up @@ -313,10 +304,10 @@ internal object UserSettingsManager {

@JvmStatic
fun setAutoLogAppEventsEnabled(flag: Boolean) {
autoLogAppEventsEnabled.value = flag
autoLogAppEventsEnabled.lastTS = System.currentTimeMillis()
autoLogAppEventsEnabledLocally.value = flag
autoLogAppEventsEnabledLocally.lastTS = System.currentTimeMillis()
if (isInitialized.get()) {
writeSettingToCache(autoLogAppEventsEnabled)
writeSettingToCache(autoLogAppEventsEnabledLocally)
} else {
initializeIfNotInitialized()
}
Expand All @@ -325,7 +316,7 @@ internal object UserSettingsManager {
@JvmStatic
fun getAutoLogAppEventsEnabled(): Boolean {
initializeIfNotInitialized()
return autoLogAppEventsEnabled.getValue()
return autoLogAppEventsEnabledLocally.getValue()
}

@JvmStatic
Expand Down

0 comments on commit b881f01

Please sign in to comment.