package com.google.firebase.remoteconfig; import android.content.Context; import com.google.android.gms.tasks.SuccessContinuation; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; import com.google.firebase.FirebaseApp; import com.google.firebase.abt.AbtException; import com.google.firebase.abt.FirebaseABTesting; import com.google.firebase.installations.FirebaseInstallationsApi; import com.google.firebase.remoteconfig.internal.ConfigCacheClient; import com.google.firebase.remoteconfig.internal.ConfigContainer; import com.google.firebase.remoteconfig.internal.ConfigFetchHandler; import com.google.firebase.remoteconfig.internal.ConfigGetParameterHandler; import com.google.firebase.remoteconfig.internal.ConfigMetadataClient; import com.google.firebase.remoteconfig.internal.DefaultsXmlParser; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes.dex */ public class FirebaseRemoteConfig { public static final byte[] DEFAULT_VALUE_FOR_BYTE_ARRAY = new byte[0]; private final ConfigCacheClient activatedConfigsCache; private final Context context; private final ConfigCacheClient defaultConfigsCache; private final Executor executor; private final ConfigFetchHandler fetchHandler; private final ConfigCacheClient fetchedConfigsCache; private final FirebaseABTesting firebaseAbt; private final FirebaseApp firebaseApp; private final FirebaseInstallationsApi firebaseInstallations; private final ConfigMetadataClient frcMetadata; private final ConfigGetParameterHandler getHandler; public static FirebaseRemoteConfig getInstance() { return getInstance(FirebaseApp.getInstance()); } public static FirebaseRemoteConfig getInstance(FirebaseApp firebaseApp) { return ((RemoteConfigComponent) firebaseApp.get(RemoteConfigComponent.class)).getDefault(); } public FirebaseRemoteConfig(Context context, FirebaseApp firebaseApp, FirebaseInstallationsApi firebaseInstallationsApi, FirebaseABTesting firebaseABTesting, Executor executor, ConfigCacheClient configCacheClient, ConfigCacheClient configCacheClient2, ConfigCacheClient configCacheClient3, ConfigFetchHandler configFetchHandler, ConfigGetParameterHandler configGetParameterHandler, ConfigMetadataClient configMetadataClient) { this.context = context; this.firebaseApp = firebaseApp; this.firebaseInstallations = firebaseInstallationsApi; this.firebaseAbt = firebaseABTesting; this.executor = executor; this.fetchedConfigsCache = configCacheClient; this.activatedConfigsCache = configCacheClient2; this.defaultConfigsCache = configCacheClient3; this.fetchHandler = configFetchHandler; this.getHandler = configGetParameterHandler; this.frcMetadata = configMetadataClient; } public Task fetchAndActivate() { return fetch().onSuccessTask(this.executor, FirebaseRemoteConfig$$Lambda$3.lambdaFactory$(this)); } public Task activate() { Task task = this.fetchedConfigsCache.get(); Task task2 = this.activatedConfigsCache.get(); return Tasks.whenAllComplete((Task[]) new Task[]{task, task2}).continueWithTask(this.executor, FirebaseRemoteConfig$$Lambda$4.lambdaFactory$(this, task, task2)); } public static /* synthetic */ Task lambda$activate$2(FirebaseRemoteConfig firebaseRemoteConfig, Task task, Task task2, Task task3) throws Exception { boolean isSuccessful = task.isSuccessful(); Boolean bool = Boolean.FALSE; if (!isSuccessful || task.getResult() == null) { return Tasks.forResult(bool); } ConfigContainer configContainer = (ConfigContainer) task.getResult(); if (task2.isSuccessful() && !isFetchedFresh(configContainer, (ConfigContainer) task2.getResult())) { return Tasks.forResult(bool); } return firebaseRemoteConfig.activatedConfigsCache.put(configContainer).continueWith(firebaseRemoteConfig.executor, FirebaseRemoteConfig$$Lambda$10.lambdaFactory$(firebaseRemoteConfig)); } public Task fetch() { SuccessContinuation successContinuation; Task fetch = this.fetchHandler.fetch(); successContinuation = FirebaseRemoteConfig$$Lambda$5.instance; return fetch.onSuccessTask(successContinuation); } public String getString(String str) { return this.getHandler.getString(str); } public Task setConfigSettingsAsync(FirebaseRemoteConfigSettings firebaseRemoteConfigSettings) { return Tasks.call(this.executor, FirebaseRemoteConfig$$Lambda$7.lambdaFactory$(this, firebaseRemoteConfigSettings)); } public static /* synthetic */ Void lambda$setConfigSettingsAsync$5(FirebaseRemoteConfig firebaseRemoteConfig, FirebaseRemoteConfigSettings firebaseRemoteConfigSettings) throws Exception { firebaseRemoteConfig.frcMetadata.setConfigSettings(firebaseRemoteConfigSettings); return null; } public Task setDefaultsAsync(int i) { return setDefaultsWithStringsMapAsync(DefaultsXmlParser.getDefaultsFromXml(this.context, i)); } public void startLoadingConfigsFromDisk() { this.activatedConfigsCache.get(); this.defaultConfigsCache.get(); this.fetchedConfigsCache.get(); } public boolean processActivatePutTask(Task task) { if (!task.isSuccessful()) { return false; } this.fetchedConfigsCache.clear(); if (task.getResult() == null) { return true; } updateAbtWithActivatedExperiments(task.getResult().getAbtExperiments()); return true; } private Task setDefaultsWithStringsMapAsync(Map map) { SuccessContinuation successContinuation; try { Task put = this.defaultConfigsCache.put(ConfigContainer.newBuilder().replaceConfigsWith(map).build()); successContinuation = FirebaseRemoteConfig$$Lambda$9.instance; return put.onSuccessTask(successContinuation); } catch (JSONException unused) { return Tasks.forResult(null); } } void updateAbtWithActivatedExperiments(JSONArray jSONArray) { if (this.firebaseAbt == null) { return; } try { this.firebaseAbt.replaceAllExperiments(toExperimentInfoMaps(jSONArray)); } catch (AbtException | JSONException unused) { } } static List> toExperimentInfoMaps(JSONArray jSONArray) throws JSONException { ArrayList arrayList = new ArrayList(); for (int i = 0; i < jSONArray.length(); i++) { HashMap hashMap = new HashMap(); JSONObject jSONObject = jSONArray.getJSONObject(i); Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); hashMap.put(next, jSONObject.getString(next)); } arrayList.add(hashMap); } return arrayList; } private static boolean isFetchedFresh(ConfigContainer configContainer, ConfigContainer configContainer2) { return configContainer2 == null || !configContainer.getFetchTime().equals(configContainer2.getFetchTime()); } }