package com.vungle.ads.internal.privacy; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import androidx.annotation.VisibleForTesting; import com.vungle.ads.ServiceLocator; import com.vungle.ads.internal.ConfigManager; import com.vungle.ads.internal.model.ConfigPayload; import com.vungle.ads.internal.model.Cookie; import com.vungle.ads.internal.persistence.FilePreferences; import com.vungle.ads.internal.util.Logger; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import kotlin.NoWhenBranchMatchedException; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes4.dex */ public final class PrivacyManager { private static PrivacyConsent ccpaConsent; private static FilePreferences filePreferences; private static String gdprConsent; private static String gdprConsentMessageVersion; private static String gdprConsentSource; private static Long gdprConsentTimestamp; private static SharedPreferences sharedPreferences; public static final PrivacyManager INSTANCE = new PrivacyManager(); private static final AtomicReference disableAdId = new AtomicReference<>(); private static final AtomicReference coppaStatus = new AtomicReference<>(); private static final AtomicBoolean initialized = new AtomicBoolean(false); public enum DeviceIdAllowed { ALLOW_ID, DISABLE_ID, FALLBACK } public /* synthetic */ class WhenMappings { public static final /* synthetic */ int[] $EnumSwitchMapping$0; public static final /* synthetic */ int[] $EnumSwitchMapping$1; static { int[] iArr = new int[DeviceIdAllowed.values().length]; iArr[DeviceIdAllowed.DISABLE_ID.ordinal()] = 1; iArr[DeviceIdAllowed.FALLBACK.ordinal()] = 2; iArr[DeviceIdAllowed.ALLOW_ID.ordinal()] = 3; $EnumSwitchMapping$0 = iArr; int[] iArr2 = new int[ConfigPayload.IABSettings.TcfStatus.values().length]; iArr2[ConfigPayload.IABSettings.TcfStatus.DISABLE_ID.ordinal()] = 1; iArr2[ConfigPayload.IABSettings.TcfStatus.ALLOW_ID.ordinal()] = 2; iArr2[ConfigPayload.IABSettings.TcfStatus.LEGACY.ordinal()] = 3; $EnumSwitchMapping$1 = iArr2; } } public final String getConsentMessageVersion() { String str = gdprConsentMessageVersion; return str == null ? "" : str; } public final String getConsentSource() { String str = gdprConsentSource; return str == null ? "no_interaction" : str; } public final String getConsentStatus() { String str = gdprConsent; return str == null ? "unknown" : str; } public final SharedPreferences getSharedPreferences() { return sharedPreferences; } public final void setSharedPreferences(SharedPreferences sharedPreferences2) { sharedPreferences = sharedPreferences2; } private PrivacyManager() { } public final String getPreviousTcfToken() { FilePreferences filePreferences2 = filePreferences; if (filePreferences2 != null) { return filePreferences2.getString("previous_tcf_token", ""); } return null; } public final void setPreviousTcfToken(String str) { FilePreferences filePreferences2; FilePreferences put; if (str == null || str.length() == 0 || (filePreferences2 = filePreferences) == null || (put = filePreferences2.put("previous_tcf_token", str)) == null) { return; } put.apply(); } public final synchronized void init(Context context) { Intrinsics.checkNotNullParameter(context, "context"); AtomicBoolean atomicBoolean = initialized; if (atomicBoolean.get()) { Logger.Companion.w("PrivacyManager", "PrivacyManager already initialized"); return; } sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); FilePreferences filePreferences2 = (FilePreferences) ServiceLocator.Companion.getInstance(context).getService(FilePreferences.class); filePreferences = filePreferences2; AtomicReference atomicReference = disableAdId; Boolean bool = atomicReference.get(); if (bool != null) { saveDisableAdId(bool.booleanValue()); } else { Boolean bool2 = filePreferences2.getBoolean(Cookie.COPPA_DISABLE_AD_ID); if (bool2 != null) { atomicReference.set(Boolean.valueOf(bool2.booleanValue())); } } String str = gdprConsent; if (str != null) { String str2 = gdprConsentSource; if (str2 == null) { str2 = ""; } String str3 = str2; String str4 = gdprConsentMessageVersion; if (str4 == null) { str4 = ""; } String str5 = str4; Long l = gdprConsentTimestamp; saveGdprConsent(str, str3, str5, l != null ? l.longValue() : 0L); } else { String string = filePreferences2.getString(Cookie.GDPR_CONSENT_STATUS); PrivacyConsent privacyConsent = PrivacyConsent.OPT_IN; if (Intrinsics.areEqual(string, privacyConsent.getValue())) { string = privacyConsent.getValue(); } else { PrivacyConsent privacyConsent2 = PrivacyConsent.OPT_OUT; if (Intrinsics.areEqual(string, privacyConsent2.getValue())) { string = privacyConsent2.getValue(); } } gdprConsent = string; gdprConsentSource = filePreferences2.getString(Cookie.GDPR_CONSENT_SOURCE); gdprConsentMessageVersion = filePreferences2.getString(Cookie.GDPR_CONSENT_MESSAGE_VERSION); gdprConsentTimestamp = Long.valueOf(filePreferences2.getLong(Cookie.GDPR_CONSENT_TIMESTAMP, 0L)); } PrivacyConsent privacyConsent3 = ccpaConsent; if (privacyConsent3 != null) { saveCcpaConsent(privacyConsent3); } else { String string2 = filePreferences2.getString(Cookie.CCPA_CONSENT_STATUS); PrivacyConsent privacyConsent4 = PrivacyConsent.OPT_OUT; if (!Intrinsics.areEqual(privacyConsent4.getValue(), string2)) { privacyConsent4 = PrivacyConsent.OPT_IN; } ccpaConsent = privacyConsent4; } AtomicReference atomicReference2 = coppaStatus; Boolean bool3 = atomicReference2.get(); if (bool3 != null) { saveCoppaConsent(bool3.booleanValue()); } else { Boolean bool4 = filePreferences2.getBoolean(Cookie.COPPA_STATUS_KEY); if (bool4 != null) { atomicReference2.set(Boolean.valueOf(bool4.booleanValue())); } } atomicBoolean.set(true); } public final void updateGdprConsent(String consent, String source, String str) { Intrinsics.checkNotNullParameter(consent, "consent"); Intrinsics.checkNotNullParameter(source, "source"); gdprConsent = consent; gdprConsentSource = source; gdprConsentMessageVersion = str; long currentTimeMillis = System.currentTimeMillis() / 1000; gdprConsentTimestamp = Long.valueOf(currentTimeMillis); String str2 = gdprConsentMessageVersion; if (str2 == null) { str2 = ""; } saveGdprConsent(consent, source, str2, currentTimeMillis); } private final void saveGdprConsent(String str, String str2, String str3, long j) { FilePreferences put; FilePreferences put2; FilePreferences put3; FilePreferences put4; FilePreferences filePreferences2 = filePreferences; if (filePreferences2 == null || (put = filePreferences2.put(Cookie.GDPR_CONSENT_STATUS, str)) == null || (put2 = put.put(Cookie.GDPR_CONSENT_SOURCE, str2)) == null || (put3 = put2.put(Cookie.GDPR_CONSENT_MESSAGE_VERSION, str3)) == null || (put4 = put3.put(Cookie.GDPR_CONSENT_TIMESTAMP, j)) == null) { return; } put4.apply(); } public final void updateCcpaConsent(PrivacyConsent consent) { Intrinsics.checkNotNullParameter(consent, "consent"); ccpaConsent = consent; saveCcpaConsent(consent); } public final String getCcpaStatus() { String value; PrivacyConsent privacyConsent = ccpaConsent; return (privacyConsent == null || (value = privacyConsent.getValue()) == null) ? PrivacyConsent.OPT_IN.getValue() : value; } private final void saveCcpaConsent(PrivacyConsent privacyConsent) { FilePreferences put; FilePreferences filePreferences2 = filePreferences; if (filePreferences2 == null || (put = filePreferences2.put(Cookie.CCPA_CONSENT_STATUS, privacyConsent.getValue())) == null) { return; } put.apply(); } public final void updateCoppaConsent(boolean z) { coppaStatus.set(Boolean.valueOf(z)); saveCoppaConsent(z); } private final void saveCoppaConsent(boolean z) { FilePreferences put; FilePreferences filePreferences2 = filePreferences; if (filePreferences2 == null || (put = filePreferences2.put(Cookie.COPPA_STATUS_KEY, z)) == null) { return; } put.apply(); } public final void updateDisableAdId(boolean z) { disableAdId.set(Boolean.valueOf(z)); saveDisableAdId(z); } @VisibleForTesting public final void saveDisableAdId(boolean z) { FilePreferences put; FilePreferences filePreferences2 = filePreferences; if (filePreferences2 == null || (put = filePreferences2.put(Cookie.COPPA_DISABLE_AD_ID, z)) == null) { return; } put.apply(); } public final long getConsentTimestamp() { Long l = gdprConsentTimestamp; if (l != null) { return l.longValue(); } return 0L; } public final COPPA getCoppaStatus() { AtomicReference atomicReference = coppaStatus; if (atomicReference.get() == null) { return COPPA.COPPA_NOTSET; } if (Intrinsics.areEqual(atomicReference.get(), Boolean.TRUE)) { return COPPA.COPPA_ENABLED; } if (Intrinsics.areEqual(atomicReference.get(), Boolean.FALSE)) { return COPPA.COPPA_DISABLED; } return COPPA.COPPA_NOTSET; } public final boolean shouldSendAdIds() { int i = WhenMappings.$EnumSwitchMapping$0[allowDeviceIDFromTCF().ordinal()]; if (i == 1) { return false; } if (i == 2 || i == 3) { Boolean bool = disableAdId.get(); return (bool == null || bool.booleanValue()) ? false : true; } throw new NoWhenBranchMatchedException(); } public final Boolean getGdprAppliesFromPreferences() { SharedPreferences sharedPreferences2 = sharedPreferences; Integer valueOf = sharedPreferences2 != null ? Integer.valueOf(sharedPreferences2.getInt(Cookie.IABTCF_GDPR_APPLIES, -1)) : null; if (valueOf != null && valueOf.intValue() == 1) { return Boolean.TRUE; } if (valueOf != null && valueOf.intValue() == 0) { return Boolean.FALSE; } return null; } public final String getIABTCFString() { SharedPreferences sharedPreferences2 = sharedPreferences; String string = sharedPreferences2 != null ? sharedPreferences2.getString("IABTCF_TCString", "") : null; return string == null ? "" : string; } public final DeviceIdAllowed allowDeviceIDFromTCF() { Boolean gdprAppliesFromPreferences = getGdprAppliesFromPreferences(); if (!Intrinsics.areEqual(gdprAppliesFromPreferences, Boolean.TRUE)) { if (gdprAppliesFromPreferences == null) { return DeviceIdAllowed.FALLBACK; } return DeviceIdAllowed.ALLOW_ID; } ConfigPayload.IABSettings.TcfStatus tcfStatus = ConfigManager.INSTANCE.getTcfStatus(); int i = tcfStatus == null ? -1 : WhenMappings.$EnumSwitchMapping$1[tcfStatus.ordinal()]; if (i != -1) { if (i == 1) { return DeviceIdAllowed.DISABLE_ID; } if (i == 2) { return DeviceIdAllowed.ALLOW_ID; } if (i != 3) { throw new NoWhenBranchMatchedException(); } } return DeviceIdAllowed.FALLBACK; } public final boolean shouldReturnTrueForLegacy$vungle_ads_release() { String iABTCFString = getIABTCFString(); if (Intrinsics.areEqual(getPreviousTcfToken(), iABTCFString)) { return false; } setPreviousTcfToken(iABTCFString); return true; } public final boolean shouldSendTCFString() { if (!Intrinsics.areEqual(getGdprAppliesFromPreferences(), Boolean.TRUE)) { return false; } ConfigPayload.IABSettings.TcfStatus tcfStatus = ConfigManager.INSTANCE.getTcfStatus(); int i = tcfStatus == null ? -1 : WhenMappings.$EnumSwitchMapping$1[tcfStatus.ordinal()]; if (i != -1) { if (i == 1 || i == 2) { return true; } if (i != 3) { throw new NoWhenBranchMatchedException(); } } return shouldReturnTrueForLegacy$vungle_ads_release(); } }