package com.vungle.ads.internal.persistence; import androidx.annotation.VisibleForTesting; import com.vungle.ads.internal.util.CollectionsConcurrencyUtil; import com.vungle.ads.internal.util.FileUtility; import com.vungle.ads.internal.util.PathProvider; import java.io.File; import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes4.dex */ public final class FilePreferences { public static final String FILENAME = "settings_vungle"; public static final String TPAT_FAILED_FILENAME = "failedTpats"; private final File file; private final Executor ioExecutor; private final ConcurrentHashMap values; public static final Companion Companion = new Companion(null); private static final ConcurrentHashMap filePreferenceMap = new ConcurrentHashMap<>(); public /* synthetic */ FilePreferences(Executor executor, PathProvider pathProvider, String str, DefaultConstructorMarker defaultConstructorMarker) { this(executor, pathProvider, str); } public static final synchronized FilePreferences get(Executor executor, PathProvider pathProvider, String str) { FilePreferences filePreferences; synchronized (FilePreferences.class) { filePreferences = Companion.get(executor, pathProvider, str); } return filePreferences; } private FilePreferences(Executor executor, PathProvider pathProvider, String str) { this.ioExecutor = executor; File file = new File(pathProvider.getSharedPrefsDir(), str); this.file = file; ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap<>(); this.values = concurrentHashMap; Object readSerializable = FileUtility.readSerializable(file); if (readSerializable instanceof HashMap) { concurrentHashMap.putAll((HashMap) readSerializable); } } public /* synthetic */ FilePreferences(Executor executor, PathProvider pathProvider, String str, int i, DefaultConstructorMarker defaultConstructorMarker) { this(executor, pathProvider, (i & 4) != 0 ? FILENAME : str); } public final void apply() { final HashMap hashMap = new HashMap(this.values); this.ioExecutor.execute(new Runnable() { // from class: com.vungle.ads.internal.persistence.FilePreferences$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { FilePreferences.m3947apply$lambda0(FilePreferences.this, hashMap); } }); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: apply$lambda-0, reason: not valid java name */ public static final void m3947apply$lambda0(FilePreferences this$0, Serializable serializable) { Intrinsics.checkNotNullParameter(this$0, "this$0"); Intrinsics.checkNotNullParameter(serializable, "$serializable"); FileUtility.writeSerializable(this$0.file, serializable); } public final FilePreferences put(String key, boolean z) { Intrinsics.checkNotNullParameter(key, "key"); this.values.put(key, Boolean.valueOf(z)); return this; } public final boolean getBoolean(String key, boolean z) { Intrinsics.checkNotNullParameter(key, "key"); Object obj = this.values.get(key); return obj instanceof Boolean ? ((Boolean) obj).booleanValue() : z; } public final Boolean getBoolean(String key) { Intrinsics.checkNotNullParameter(key, "key"); Object obj = this.values.get(key); if (obj instanceof Boolean) { return (Boolean) obj; } return null; } public final FilePreferences put(String key, String value) { Intrinsics.checkNotNullParameter(key, "key"); Intrinsics.checkNotNullParameter(value, "value"); this.values.put(key, value); return this; } public final FilePreferences remove(String key) { Intrinsics.checkNotNullParameter(key, "key"); if (this.values.containsKey(key)) { this.values.remove(key); } return this; } public final String getString(String key, String defaultValue) { Intrinsics.checkNotNullParameter(key, "key"); Intrinsics.checkNotNullParameter(defaultValue, "defaultValue"); Object obj = this.values.get(key); return obj instanceof String ? (String) obj : defaultValue; } public final String getString(String key) { Intrinsics.checkNotNullParameter(key, "key"); Object obj = this.values.get(key); if (obj instanceof String) { return (String) obj; } return null; } public final FilePreferences put(String key, int i) { Intrinsics.checkNotNullParameter(key, "key"); this.values.put(key, Integer.valueOf(i)); return this; } public final int getInt(String key, int i) { Intrinsics.checkNotNullParameter(key, "key"); Object obj = this.values.get(key); return obj instanceof Integer ? ((Number) obj).intValue() : i; } public final FilePreferences put(String key, HashSet hashSet) { Intrinsics.checkNotNullParameter(key, "key"); this.values.put(key, CollectionsConcurrencyUtil.getNewHashSet(hashSet)); return this; } public final HashSet getStringSet(String key, HashSet defaultValue) { Intrinsics.checkNotNullParameter(key, "key"); Intrinsics.checkNotNullParameter(defaultValue, "defaultValue"); Object obj = this.values.get(key); return obj instanceof HashSet ? CollectionsConcurrencyUtil.getNewHashSet((HashSet) obj) : defaultValue; } public final FilePreferences put(String key, long j) { Intrinsics.checkNotNullParameter(key, "key"); this.values.put(key, Long.valueOf(j)); return this; } public final long getLong(String key, long j) { Intrinsics.checkNotNullParameter(key, "key"); Object obj = this.values.get(key); return obj instanceof Long ? ((Number) obj).longValue() : j; } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } @VisibleForTesting public static /* synthetic */ void getFILENAME$annotations() { } private Companion() { } public static /* synthetic */ FilePreferences get$default(Companion companion, Executor executor, PathProvider pathProvider, String str, int i, Object obj) { if ((i & 4) != 0) { str = FilePreferences.FILENAME; } return companion.get(executor, pathProvider, str); } public final synchronized FilePreferences get(Executor ioExecutor, PathProvider pathProvider, String filename) { Object obj; Object putIfAbsent; try { Intrinsics.checkNotNullParameter(ioExecutor, "ioExecutor"); Intrinsics.checkNotNullParameter(pathProvider, "pathProvider"); Intrinsics.checkNotNullParameter(filename, "filename"); ConcurrentHashMap concurrentHashMap = FilePreferences.filePreferenceMap; obj = concurrentHashMap.get(filename); if (obj == null && (putIfAbsent = concurrentHashMap.putIfAbsent(filename, (obj = new FilePreferences(ioExecutor, pathProvider, filename, null)))) != null) { obj = putIfAbsent; } Intrinsics.checkNotNullExpressionValue(obj, "filePreferenceMap.getOrP…, filename)\n }"); } catch (Throwable th) { throw th; } return (FilePreferences) obj; } } }