package com.google.firebase.remoteconfig; import android.content.Context; import android.util.Log; import com.google.android.gms.tasks.Continuation; 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.concurrent.FirebaseExecutors; 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.ConfigRealtimeHandler; import com.google.firebase.remoteconfig.internal.rollouts.RolloutsStateSubscriptionsHandler; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.Executor; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes3.dex */ public class FirebaseRemoteConfig { public static final byte[] DEFAULT_VALUE_FOR_BYTE_ARRAY = new byte[0]; public final ConfigCacheClient activatedConfigsCache; public final ConfigRealtimeHandler configRealtimeHandler; public final Context context; public final ConfigCacheClient defaultConfigsCache; public final Executor executor; public final ConfigFetchHandler fetchHandler; public final ConfigCacheClient fetchedConfigsCache; public final FirebaseABTesting firebaseAbt; public final FirebaseApp firebaseApp; public final FirebaseInstallationsApi firebaseInstallations; public final ConfigMetadataClient frcMetadata; public final ConfigGetParameterHandler getHandler; public final RolloutsStateSubscriptionsHandler rolloutsStateSubscriptionsHandler; public RolloutsStateSubscriptionsHandler getRolloutsStateSubscriptionsHandler() { return this.rolloutsStateSubscriptionsHandler; } 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, ConfigRealtimeHandler configRealtimeHandler, RolloutsStateSubscriptionsHandler rolloutsStateSubscriptionsHandler) { 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; this.configRealtimeHandler = configRealtimeHandler; this.rolloutsStateSubscriptionsHandler = rolloutsStateSubscriptionsHandler; } public Task fetchAndActivate() { return fetch().onSuccessTask(this.executor, new SuccessContinuation() { // from class: com.google.firebase.remoteconfig.FirebaseRemoteConfig$$ExternalSyntheticLambda1 @Override // com.google.android.gms.tasks.SuccessContinuation public final Task then(Object obj) { Task lambda$fetchAndActivate$1; lambda$fetchAndActivate$1 = FirebaseRemoteConfig.this.lambda$fetchAndActivate$1((Void) obj); return lambda$fetchAndActivate$1; } }); } public final /* synthetic */ Task lambda$fetchAndActivate$1(Void r1) { return activate(); } public Task activate() { final Task task = this.fetchedConfigsCache.get(); final Task task2 = this.activatedConfigsCache.get(); return Tasks.whenAllComplete((Task[]) new Task[]{task, task2}).continueWithTask(this.executor, new Continuation() { // from class: com.google.firebase.remoteconfig.FirebaseRemoteConfig$$ExternalSyntheticLambda3 @Override // com.google.android.gms.tasks.Continuation public final Object then(Task task3) { Task lambda$activate$2; lambda$activate$2 = FirebaseRemoteConfig.this.lambda$activate$2(task, task2, task3); return lambda$activate$2; } }); } public final /* synthetic */ Task lambda$activate$2(Task task, Task task2, Task task3) { if (!task.isSuccessful() || task.getResult() == null) { return Tasks.forResult(Boolean.FALSE); } ConfigContainer configContainer = (ConfigContainer) task.getResult(); if (task2.isSuccessful() && !isFetchedFresh(configContainer, (ConfigContainer) task2.getResult())) { return Tasks.forResult(Boolean.FALSE); } return this.activatedConfigsCache.put(configContainer).continueWith(this.executor, new Continuation() { // from class: com.google.firebase.remoteconfig.FirebaseRemoteConfig$$ExternalSyntheticLambda4 @Override // com.google.android.gms.tasks.Continuation public final Object then(Task task4) { boolean processActivatePutTask; processActivatePutTask = FirebaseRemoteConfig.this.processActivatePutTask(task4); return Boolean.valueOf(processActivatePutTask); } }); } public Task fetch() { return this.fetchHandler.fetch().onSuccessTask(FirebaseExecutors.directExecutor(), new SuccessContinuation() { // from class: com.google.firebase.remoteconfig.FirebaseRemoteConfig$$ExternalSyntheticLambda2 @Override // com.google.android.gms.tasks.SuccessContinuation public final Task then(Object obj) { Task lambda$fetch$3; lambda$fetch$3 = FirebaseRemoteConfig.lambda$fetch$3((ConfigFetchHandler.FetchResponse) obj); return lambda$fetch$3; } }); } public static /* synthetic */ Task lambda$fetch$3(ConfigFetchHandler.FetchResponse fetchResponse) { return Tasks.forResult(null); } public String getString(String str) { return this.getHandler.getString(str); } public boolean getBoolean(String str) { return this.getHandler.getBoolean(str); } public double getDouble(String str) { return this.getHandler.getDouble(str); } public Map getAll() { return this.getHandler.getAll(); } public FirebaseRemoteConfigInfo getInfo() { return this.frcMetadata.getInfo(); } public Task setConfigSettingsAsync(final FirebaseRemoteConfigSettings firebaseRemoteConfigSettings) { return Tasks.call(this.executor, new Callable() { // from class: com.google.firebase.remoteconfig.FirebaseRemoteConfig$$ExternalSyntheticLambda0 @Override // java.util.concurrent.Callable public final Object call() { Void lambda$setConfigSettingsAsync$5; lambda$setConfigSettingsAsync$5 = FirebaseRemoteConfig.this.lambda$setConfigSettingsAsync$5(firebaseRemoteConfigSettings); return lambda$setConfigSettingsAsync$5; } }); } public final /* synthetic */ Void lambda$setConfigSettingsAsync$5(FirebaseRemoteConfigSettings firebaseRemoteConfigSettings) { this.frcMetadata.setConfigSettings(firebaseRemoteConfigSettings); return null; } public void startLoadingConfigsFromDisk() { this.activatedConfigsCache.get(); this.defaultConfigsCache.get(); this.fetchedConfigsCache.get(); } public final boolean processActivatePutTask(Task task) { if (!task.isSuccessful()) { return false; } this.fetchedConfigsCache.clear(); ConfigContainer configContainer = (ConfigContainer) task.getResult(); if (configContainer != null) { updateAbtWithActivatedExperiments(configContainer.getAbtExperiments()); this.rolloutsStateSubscriptionsHandler.publishActiveRolloutsState(configContainer); return true; } Log.e("FirebaseRemoteConfig", "Activated configs written to disk are null."); return true; } public void updateAbtWithActivatedExperiments(JSONArray jSONArray) { if (this.firebaseAbt == null) { return; } try { this.firebaseAbt.replaceAllExperiments(toExperimentInfoMaps(jSONArray)); } catch (AbtException e) { Log.w("FirebaseRemoteConfig", "Could not update ABT experiments.", e); } catch (JSONException e2) { Log.e("FirebaseRemoteConfig", "Could not parse ABT experiments from the JSON response.", e2); } } public void setConfigUpdateBackgroundState(boolean z) { this.configRealtimeHandler.setBackgroundState(z); } public static List toExperimentInfoMaps(JSONArray jSONArray) { 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; } public static boolean isFetchedFresh(ConfigContainer configContainer, ConfigContainer configContainer2) { return configContainer2 == null || !configContainer.getFetchTime().equals(configContainer2.getFetchTime()); } }