package com.facebook.internal; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import android.util.Log; import androidx.lifecycle.LifecycleKt$$ExternalSyntheticBackportWithForwarding0; import com.facebook.FacebookSdk; import com.facebook.GraphRequest; import com.facebook.appevents.codeless.internal.UnityReflection; import com.facebook.appevents.internal.AutomaticAnalyticsLogger; import com.facebook.appevents.internal.Constants; import com.facebook.internal.FacebookRequestErrorClassification; import com.facebook.internal.FetchedAppSettings; import com.facebook.internal.FetchedAppSettingsManager; import com.mbridge.msdk.MBridgeConstans; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicReference; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.StringCompanionObject; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public final class FetchedAppSettingsManager { private static final String APPLICATION_FIELDS = "fields"; private static final String APP_SETTINGS_PREFS_KEY_FORMAT = "com.facebook.internal.APP_SETTINGS.%s"; private static final String APP_SETTINGS_PREFS_STORE = "com.facebook.internal.preferences.APP_SETTINGS"; private static final String APP_SETTING_ANDROID_SDK_ERROR_CATEGORIES = "android_sdk_error_categories"; private static final String APP_SETTING_APP_EVENTS_AAM_RULE = "aam_rules"; private static final String APP_SETTING_APP_EVENTS_EVENT_BINDINGS = "auto_event_mapping_android"; private static final String APP_SETTING_APP_EVENTS_FEATURE_BITMASK = "app_events_feature_bitmask"; private static final String APP_SETTING_APP_EVENTS_SESSION_TIMEOUT = "app_events_session_timeout"; private static final String APP_SETTING_DIALOG_CONFIGS = "android_dialog_configs"; private static final List APP_SETTING_FIELDS; private static final String APP_SETTING_NUX_CONTENT = "gdpv4_nux_content"; private static final String APP_SETTING_NUX_ENABLED = "gdpv4_nux_enabled"; private static final String APP_SETTING_RESTRICTIVE_EVENT_FILTER_FIELD = "restrictive_data_filter_params"; private static final String APP_SETTING_SMART_LOGIN_OPTIONS = "seamless_login"; private static final String APP_SETTING_SUPPORTS_IMPLICIT_SDK_LOGGING = "supports_implicit_sdk_logging"; private static final int AUTOMATIC_LOGGING_ENABLED_BITMASK_FIELD = 8; public static final String AUTO_LOG_APP_EVENTS_DEFAULT_FIELD = "auto_log_app_events_default"; public static final String AUTO_LOG_APP_EVENT_ENABLED_FIELD = "auto_log_app_events_enabled"; private static final String BLOCKLIST_EVENTS_KEY = "blocklist_events"; private static final int CODELESS_EVENTS_ENABLED_BITMASK_FIELD = 32; private static final int IAP_AUTOMATIC_LOGGING_ENABLED_BITMASK_FIELD = 16; private static final String MACA_RULES_KEY = "maca_rules"; private static final int MONITOR_ENABLED_BITMASK_FIELD = 16384; private static final String PROTECTED_MODE_RULES = "protected_mode_rules"; private static final String REDACTED_EVENTS_KEY = "redacted_events"; private static final String SDK_UPDATE_MESSAGE = "sdk_update_message"; private static final String SENSITIVE_PARAMS_KEY = "sensitive_params"; private static final String SMART_LOGIN_BOOKMARK_ICON_URL = "smart_login_bookmark_icon_url"; private static final String SMART_LOGIN_MENU_ICON_URL = "smart_login_menu_icon_url"; private static final String STANDARD_PARAMS_KEY = "standard_params"; private static final String SUGGESTED_EVENTS_SETTING = "suggested_events_setting"; private static final int TRACK_UNINSTALL_ENABLED_BITMASK_FIELD = 256; private static final Map fetchedAppSettings; private static final ConcurrentLinkedQueue fetchedAppSettingsCallbacks; private static boolean isUnityInit; private static final AtomicReference loadingState; private static boolean printedSDKUpdatedMessage; private static JSONArray unityEventBindings; public static final FetchedAppSettingsManager INSTANCE = new FetchedAppSettingsManager(); private static final String TAG = FetchedAppSettingsManager.class.getSimpleName(); public interface FetchedAppSettingsCallback { void onError(); void onSuccess(FetchedAppSettings fetchedAppSettings); } private FetchedAppSettingsManager() { } static { List listOf; listOf = CollectionsKt__CollectionsKt.listOf((Object[]) new String[]{APP_SETTING_SUPPORTS_IMPLICIT_SDK_LOGGING, APP_SETTING_NUX_CONTENT, APP_SETTING_NUX_ENABLED, APP_SETTING_DIALOG_CONFIGS, APP_SETTING_ANDROID_SDK_ERROR_CATEGORIES, APP_SETTING_APP_EVENTS_SESSION_TIMEOUT, APP_SETTING_APP_EVENTS_FEATURE_BITMASK, APP_SETTING_APP_EVENTS_EVENT_BINDINGS, APP_SETTING_SMART_LOGIN_OPTIONS, SMART_LOGIN_BOOKMARK_ICON_URL, SMART_LOGIN_MENU_ICON_URL, APP_SETTING_RESTRICTIVE_EVENT_FILTER_FIELD, APP_SETTING_APP_EVENTS_AAM_RULE, SUGGESTED_EVENTS_SETTING, PROTECTED_MODE_RULES, AUTO_LOG_APP_EVENTS_DEFAULT_FIELD, AUTO_LOG_APP_EVENT_ENABLED_FIELD}); APP_SETTING_FIELDS = listOf; fetchedAppSettings = new ConcurrentHashMap(); loadingState = new AtomicReference<>(FetchAppSettingState.NOT_LOADED); fetchedAppSettingsCallbacks = new ConcurrentLinkedQueue<>(); } public static final void loadAppSettingsAsync() { final Context applicationContext = FacebookSdk.getApplicationContext(); final String applicationId = FacebookSdk.getApplicationId(); if (Utility.isNullOrEmpty(applicationId)) { loadingState.set(FetchAppSettingState.ERROR); INSTANCE.pollCallbacks(); return; } if (fetchedAppSettings.containsKey(applicationId)) { loadingState.set(FetchAppSettingState.SUCCESS); INSTANCE.pollCallbacks(); return; } AtomicReference atomicReference = loadingState; FetchAppSettingState fetchAppSettingState = FetchAppSettingState.NOT_LOADED; FetchAppSettingState fetchAppSettingState2 = FetchAppSettingState.LOADING; if (!LifecycleKt$$ExternalSyntheticBackportWithForwarding0.m(atomicReference, fetchAppSettingState, fetchAppSettingState2) && !LifecycleKt$$ExternalSyntheticBackportWithForwarding0.m(atomicReference, FetchAppSettingState.ERROR, fetchAppSettingState2)) { INSTANCE.pollCallbacks(); return; } StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE; final String format = String.format(APP_SETTINGS_PREFS_KEY_FORMAT, Arrays.copyOf(new Object[]{applicationId}, 1)); Intrinsics.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)"); FacebookSdk.getExecutor().execute(new Runnable() { // from class: com.facebook.internal.FetchedAppSettingsManager$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { FetchedAppSettingsManager.m565loadAppSettingsAsync$lambda0(applicationContext, format, applicationId); } }); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: loadAppSettingsAsync$lambda-0, reason: not valid java name */ public static final void m565loadAppSettingsAsync$lambda0(Context context, String settingsKey, String applicationId) { JSONObject jSONObject; Intrinsics.checkNotNullParameter(context, "$context"); Intrinsics.checkNotNullParameter(settingsKey, "$settingsKey"); Intrinsics.checkNotNullParameter(applicationId, "$applicationId"); SharedPreferences sharedPreferences = context.getSharedPreferences(APP_SETTINGS_PREFS_STORE, 0); FetchedAppSettings fetchedAppSettings2 = null; String string = sharedPreferences.getString(settingsKey, null); if (!Utility.isNullOrEmpty(string)) { if (string == null) { throw new IllegalStateException("Required value was null.".toString()); } try { jSONObject = new JSONObject(string); } catch (JSONException e) { Utility.logd(Utility.LOG_TAG, e); jSONObject = null; } if (jSONObject != null) { fetchedAppSettings2 = INSTANCE.parseAppSettingsFromJSON$facebook_core_release(applicationId, jSONObject); } } FetchedAppSettingsManager fetchedAppSettingsManager = INSTANCE; JSONObject appSettingsQueryResponse = fetchedAppSettingsManager.getAppSettingsQueryResponse(applicationId); if (appSettingsQueryResponse != null) { fetchedAppSettingsManager.parseAppSettingsFromJSON$facebook_core_release(applicationId, appSettingsQueryResponse); sharedPreferences.edit().putString(settingsKey, appSettingsQueryResponse.toString()).apply(); } if (fetchedAppSettings2 != null) { String sdkUpdateMessage = fetchedAppSettings2.getSdkUpdateMessage(); if (!printedSDKUpdatedMessage && sdkUpdateMessage != null && sdkUpdateMessage.length() > 0) { printedSDKUpdatedMessage = true; Log.w(TAG, sdkUpdateMessage); } } FetchedAppGateKeepersManager.queryAppGateKeepers(applicationId, true); AutomaticAnalyticsLogger.logActivateAppEvent(); loadingState.set(fetchedAppSettings.containsKey(applicationId) ? FetchAppSettingState.SUCCESS : FetchAppSettingState.ERROR); fetchedAppSettingsManager.pollCallbacks(); } public static final FetchedAppSettings getAppSettingsWithoutQuery(String str) { if (str != null) { return fetchedAppSettings.get(str); } return null; } public static final void getAppSettingsAsync(FetchedAppSettingsCallback callback) { Intrinsics.checkNotNullParameter(callback, "callback"); fetchedAppSettingsCallbacks.add(callback); loadAppSettingsAsync(); } private final synchronized void pollCallbacks() { FetchAppSettingState fetchAppSettingState = loadingState.get(); if (FetchAppSettingState.NOT_LOADED != fetchAppSettingState && FetchAppSettingState.LOADING != fetchAppSettingState) { final FetchedAppSettings fetchedAppSettings2 = fetchedAppSettings.get(FacebookSdk.getApplicationId()); Handler handler = new Handler(Looper.getMainLooper()); if (FetchAppSettingState.ERROR == fetchAppSettingState) { while (true) { ConcurrentLinkedQueue concurrentLinkedQueue = fetchedAppSettingsCallbacks; if (concurrentLinkedQueue.isEmpty()) { return; } final FetchedAppSettingsCallback poll = concurrentLinkedQueue.poll(); handler.post(new Runnable() { // from class: com.facebook.internal.FetchedAppSettingsManager$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { FetchedAppSettingsManager.FetchedAppSettingsCallback.this.onError(); } }); } } else { while (true) { ConcurrentLinkedQueue concurrentLinkedQueue2 = fetchedAppSettingsCallbacks; if (concurrentLinkedQueue2.isEmpty()) { return; } final FetchedAppSettingsCallback poll2 = concurrentLinkedQueue2.poll(); handler.post(new Runnable() { // from class: com.facebook.internal.FetchedAppSettingsManager$$ExternalSyntheticLambda2 @Override // java.lang.Runnable public final void run() { FetchedAppSettingsManager.FetchedAppSettingsCallback.this.onSuccess(fetchedAppSettings2); } }); } } } } public static final Map getCachedMigratedAutoLogValuesInAppSettings() { JSONObject jSONObject; Context applicationContext = FacebookSdk.getApplicationContext(); String applicationId = FacebookSdk.getApplicationId(); StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE; String format = String.format(APP_SETTINGS_PREFS_KEY_FORMAT, Arrays.copyOf(new Object[]{applicationId}, 1)); Intrinsics.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)"); String string = applicationContext.getSharedPreferences(APP_SETTINGS_PREFS_STORE, 0).getString(format, null); if (!Utility.isNullOrEmpty(string)) { if (string == null) { throw new IllegalStateException("Required value was null.".toString()); } try { jSONObject = new JSONObject(string); } catch (JSONException e) { Utility.logd(Utility.LOG_TAG, e); jSONObject = null; } if (jSONObject != null) { return INSTANCE.parseMigratedAutoLogValues(jSONObject); } } return null; } public static final FetchedAppSettings queryAppSettings(String applicationId, boolean z) { Intrinsics.checkNotNullParameter(applicationId, "applicationId"); if (!z) { Map map = fetchedAppSettings; if (map.containsKey(applicationId)) { return map.get(applicationId); } } FetchedAppSettingsManager fetchedAppSettingsManager = INSTANCE; JSONObject appSettingsQueryResponse = fetchedAppSettingsManager.getAppSettingsQueryResponse(applicationId); if (appSettingsQueryResponse == null) { return null; } FetchedAppSettings parseAppSettingsFromJSON$facebook_core_release = fetchedAppSettingsManager.parseAppSettingsFromJSON$facebook_core_release(applicationId, appSettingsQueryResponse); if (Intrinsics.areEqual(applicationId, FacebookSdk.getApplicationId())) { loadingState.set(FetchAppSettingState.SUCCESS); fetchedAppSettingsManager.pollCallbacks(); } return parseAppSettingsFromJSON$facebook_core_release; } public final FetchedAppSettings parseAppSettingsFromJSON$facebook_core_release(String applicationId, JSONObject settingsJSON) { Intrinsics.checkNotNullParameter(applicationId, "applicationId"); Intrinsics.checkNotNullParameter(settingsJSON, "settingsJSON"); JSONArray optJSONArray = settingsJSON.optJSONArray(APP_SETTING_ANDROID_SDK_ERROR_CATEGORIES); FacebookRequestErrorClassification.Companion companion = FacebookRequestErrorClassification.Companion; FacebookRequestErrorClassification createFromJSON = companion.createFromJSON(optJSONArray); if (createFromJSON == null) { createFromJSON = companion.getDefaultErrorClassification(); } FacebookRequestErrorClassification facebookRequestErrorClassification = createFromJSON; int optInt = settingsJSON.optInt(APP_SETTING_APP_EVENTS_FEATURE_BITMASK, 0); boolean z = (optInt & 8) != 0; boolean z2 = (optInt & 16) != 0; boolean z3 = (optInt & 32) != 0; boolean z4 = (optInt & 256) != 0; boolean z5 = (optInt & 16384) != 0; JSONArray optJSONArray2 = settingsJSON.optJSONArray(APP_SETTING_APP_EVENTS_EVENT_BINDINGS); unityEventBindings = optJSONArray2; if (optJSONArray2 != null && InternalSettings.isUnityApp()) { UnityReflection unityReflection = UnityReflection.INSTANCE; UnityReflection.sendEventMapping(optJSONArray2 == null ? null : optJSONArray2.toString()); } boolean optBoolean = settingsJSON.optBoolean(APP_SETTING_SUPPORTS_IMPLICIT_SDK_LOGGING, false); String optString = settingsJSON.optString(APP_SETTING_NUX_CONTENT, ""); Intrinsics.checkNotNullExpressionValue(optString, "settingsJSON.optString(APP_SETTING_NUX_CONTENT, \"\")"); boolean optBoolean2 = settingsJSON.optBoolean(APP_SETTING_NUX_ENABLED, false); int optInt2 = settingsJSON.optInt(APP_SETTING_APP_EVENTS_SESSION_TIMEOUT, Constants.getDefaultAppEventsSessionTimeoutInSeconds()); EnumSet parseOptions = SmartLoginOption.Companion.parseOptions(settingsJSON.optLong(APP_SETTING_SMART_LOGIN_OPTIONS)); Map> parseDialogConfigurations = parseDialogConfigurations(settingsJSON.optJSONObject(APP_SETTING_DIALOG_CONFIGS)); String optString2 = settingsJSON.optString(SMART_LOGIN_BOOKMARK_ICON_URL); Intrinsics.checkNotNullExpressionValue(optString2, "settingsJSON.optString(SMART_LOGIN_BOOKMARK_ICON_URL)"); String optString3 = settingsJSON.optString(SMART_LOGIN_MENU_ICON_URL); Intrinsics.checkNotNullExpressionValue(optString3, "settingsJSON.optString(SMART_LOGIN_MENU_ICON_URL)"); String optString4 = settingsJSON.optString(SDK_UPDATE_MESSAGE); Intrinsics.checkNotNullExpressionValue(optString4, "settingsJSON.optString(SDK_UPDATE_MESSAGE)"); FetchedAppSettings fetchedAppSettings2 = new FetchedAppSettings(optBoolean, optString, optBoolean2, optInt2, parseOptions, parseDialogConfigurations, z, facebookRequestErrorClassification, optString2, optString3, z2, z3, optJSONArray2, optString4, z4, z5, settingsJSON.optString(APP_SETTING_APP_EVENTS_AAM_RULE), 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), parseMigratedAutoLogValues(settingsJSON), parseProtectedModeRules(settingsJSON.optJSONObject(PROTECTED_MODE_RULES), BLOCKLIST_EVENTS_KEY), parseProtectedModeRules(settingsJSON.optJSONObject(PROTECTED_MODE_RULES), REDACTED_EVENTS_KEY), parseProtectedModeRules(settingsJSON.optJSONObject(PROTECTED_MODE_RULES), SENSITIVE_PARAMS_KEY)); fetchedAppSettings.put(applicationId, fetchedAppSettings2); return fetchedAppSettings2; } public static final void setIsUnityInit(boolean z) { isUnityInit = z; if (unityEventBindings == null || !z) { return; } UnityReflection unityReflection = UnityReflection.INSTANCE; UnityReflection.sendEventMapping(String.valueOf(unityEventBindings)); } private final JSONObject getAppSettingsQueryResponse(String str) { Bundle bundle = new Bundle(); ArrayList arrayList = new ArrayList(); arrayList.addAll(APP_SETTING_FIELDS); bundle.putString("fields", TextUtils.join(",", arrayList)); GraphRequest newGraphPathRequest = GraphRequest.Companion.newGraphPathRequest(null, MBridgeConstans.DYNAMIC_VIEW_WX_APP, null); newGraphPathRequest.setForceApplicationRequest(true); newGraphPathRequest.setParameters(bundle); JSONObject jsonObject = newGraphPathRequest.executeAndWait().getJsonObject(); return jsonObject == null ? new JSONObject() : jsonObject; } private final Map> parseDialogConfigurations(JSONObject jSONObject) { JSONArray optJSONArray; int length; HashMap hashMap = new HashMap(); if (jSONObject != null && (optJSONArray = jSONObject.optJSONArray("data")) != null && (length = optJSONArray.length()) > 0) { int i = 0; while (true) { int i2 = i + 1; FetchedAppSettings.DialogFeatureConfig.Companion companion = FetchedAppSettings.DialogFeatureConfig.Companion; JSONObject optJSONObject = optJSONArray.optJSONObject(i); Intrinsics.checkNotNullExpressionValue(optJSONObject, "dialogConfigData.optJSONObject(i)"); FetchedAppSettings.DialogFeatureConfig parseDialogConfig = companion.parseDialogConfig(optJSONObject); if (parseDialogConfig != null) { String dialogName = parseDialogConfig.getDialogName(); Map map = (Map) hashMap.get(dialogName); if (map == null) { map = new HashMap(); hashMap.put(dialogName, map); } map.put(parseDialogConfig.getFeatureName(), parseDialogConfig); } if (i2 >= length) { break; } i = i2; } } return hashMap; } private final JSONArray parseProtectedModeRules(JSONObject jSONObject, String str) { if (jSONObject != null) { return jSONObject.optJSONArray(str); } return null; } private final Map parseMigratedAutoLogValues(JSONObject jSONObject) { if (jSONObject == null) { return null; } HashMap hashMap = new HashMap(); if (!jSONObject.isNull(AUTO_LOG_APP_EVENTS_DEFAULT_FIELD)) { try { hashMap.put(AUTO_LOG_APP_EVENTS_DEFAULT_FIELD, Boolean.valueOf(jSONObject.getBoolean(AUTO_LOG_APP_EVENTS_DEFAULT_FIELD))); } catch (JSONException e) { Utility.logd(Utility.LOG_TAG, e); } } if (!jSONObject.isNull(AUTO_LOG_APP_EVENT_ENABLED_FIELD)) { try { hashMap.put(AUTO_LOG_APP_EVENT_ENABLED_FIELD, Boolean.valueOf(jSONObject.getBoolean(AUTO_LOG_APP_EVENT_ENABLED_FIELD))); } catch (JSONException e2) { Utility.logd(Utility.LOG_TAG, e2); } } if (hashMap.isEmpty()) { return null; } return hashMap; } public enum FetchAppSettingState { NOT_LOADED, LOADING, SUCCESS, ERROR; /* renamed from: values, reason: to resolve conflict with enum method */ public static FetchAppSettingState[] valuesCustom() { FetchAppSettingState[] valuesCustom = values(); return (FetchAppSettingState[]) Arrays.copyOf(valuesCustom, valuesCustom.length); } } }