package com.google.firebase.remoteconfig; import android.app.Application; import android.content.Context; import androidx.lifecycle.LifecycleKt$$ExternalSyntheticBackportWithForwarding0; import com.google.android.gms.common.api.internal.BackgroundDetector; import com.google.android.gms.common.util.BiConsumer; import com.google.android.gms.common.util.Clock; import com.google.android.gms.common.util.DefaultClock; import com.google.android.gms.tasks.Tasks; import com.google.firebase.FirebaseApp; import com.google.firebase.abt.FirebaseABTesting; import com.google.firebase.analytics.connector.AnalyticsConnector; import com.google.firebase.inject.Provider; 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.ConfigFetchHttpClient; 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.ConfigStorageClient; import com.google.firebase.remoteconfig.internal.Personalization; import com.google.firebase.remoteconfig.internal.rollouts.RolloutsStateFactory; import com.google.firebase.remoteconfig.internal.rollouts.RolloutsStateSubscriptionsHandler; import com.google.firebase.remoteconfig.interop.FirebaseRemoteConfigInterop; import com.google.firebase.remoteconfig.interop.rollouts.RolloutsStateSubscriber; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; import java.util.concurrent.Callable; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes3.dex */ public class RemoteConfigComponent implements FirebaseRemoteConfigInterop { public static final Clock DEFAULT_CLOCK = DefaultClock.getInstance(); public static final Random DEFAULT_RANDOM = new Random(); public static final Map frcNamespaceInstancesStatic = new HashMap(); public final Provider analyticsConnector; public final String appId; public final Context context; public Map customHeaders; public final ScheduledExecutorService executor; public final FirebaseABTesting firebaseAbt; public final FirebaseApp firebaseApp; public final FirebaseInstallationsApi firebaseInstallations; public final Map frcNamespaceInstances; public static /* synthetic */ AnalyticsConnector lambda$getFetchHandler$0() { return null; } public RemoteConfigComponent(Context context, ScheduledExecutorService scheduledExecutorService, FirebaseApp firebaseApp, FirebaseInstallationsApi firebaseInstallationsApi, FirebaseABTesting firebaseABTesting, Provider provider) { this(context, scheduledExecutorService, firebaseApp, firebaseInstallationsApi, firebaseABTesting, provider, true); } public RemoteConfigComponent(Context context, ScheduledExecutorService scheduledExecutorService, FirebaseApp firebaseApp, FirebaseInstallationsApi firebaseInstallationsApi, FirebaseABTesting firebaseABTesting, Provider provider, boolean z) { this.frcNamespaceInstances = new HashMap(); this.customHeaders = new HashMap(); this.context = context; this.executor = scheduledExecutorService; this.firebaseApp = firebaseApp; this.firebaseInstallations = firebaseInstallationsApi; this.firebaseAbt = firebaseABTesting; this.analyticsConnector = provider; this.appId = firebaseApp.getOptions().getApplicationId(); GlobalBackgroundListener.ensureBackgroundListenerIsRegistered(context); if (z) { Tasks.call(scheduledExecutorService, new Callable() { // from class: com.google.firebase.remoteconfig.RemoteConfigComponent$$ExternalSyntheticLambda1 @Override // java.util.concurrent.Callable public final Object call() { return RemoteConfigComponent.this.getDefault(); } }); } } public FirebaseRemoteConfig getDefault() { return get("firebase"); } public synchronized FirebaseRemoteConfig get(String str) { ConfigCacheClient cacheClient; ConfigCacheClient cacheClient2; ConfigCacheClient cacheClient3; ConfigMetadataClient metadataClient; ConfigGetParameterHandler getHandler; try { cacheClient = getCacheClient(str, "fetch"); cacheClient2 = getCacheClient(str, "activate"); cacheClient3 = getCacheClient(str, "defaults"); metadataClient = getMetadataClient(this.context, this.appId, str); getHandler = getGetHandler(cacheClient2, cacheClient3); final Personalization personalization = getPersonalization(this.firebaseApp, str, this.analyticsConnector); if (personalization != null) { getHandler.addListener(new BiConsumer() { // from class: com.google.firebase.remoteconfig.RemoteConfigComponent$$ExternalSyntheticLambda0 @Override // com.google.android.gms.common.util.BiConsumer public final void accept(Object obj, Object obj2) { Personalization.this.logArmActive((String) obj, (ConfigContainer) obj2); } }); } } catch (Throwable th) { throw th; } return get(this.firebaseApp, str, this.firebaseInstallations, this.firebaseAbt, this.executor, cacheClient, cacheClient2, cacheClient3, getFetchHandler(str, cacheClient, metadataClient), getHandler, metadataClient, getRolloutsStateSubscriptionsHandler(cacheClient2, cacheClient3)); } public synchronized FirebaseRemoteConfig get(FirebaseApp firebaseApp, String str, FirebaseInstallationsApi firebaseInstallationsApi, FirebaseABTesting firebaseABTesting, Executor executor, ConfigCacheClient configCacheClient, ConfigCacheClient configCacheClient2, ConfigCacheClient configCacheClient3, ConfigFetchHandler configFetchHandler, ConfigGetParameterHandler configGetParameterHandler, ConfigMetadataClient configMetadataClient, RolloutsStateSubscriptionsHandler rolloutsStateSubscriptionsHandler) { try { if (!this.frcNamespaceInstances.containsKey(str)) { FirebaseRemoteConfig firebaseRemoteConfig = new FirebaseRemoteConfig(this.context, firebaseApp, firebaseInstallationsApi, isAbtSupported(firebaseApp, str) ? firebaseABTesting : null, executor, configCacheClient, configCacheClient2, configCacheClient3, configFetchHandler, configGetParameterHandler, configMetadataClient, getRealtime(firebaseApp, firebaseInstallationsApi, configFetchHandler, configCacheClient2, this.context, str, configMetadataClient), rolloutsStateSubscriptionsHandler); firebaseRemoteConfig.startLoadingConfigsFromDisk(); this.frcNamespaceInstances.put(str, firebaseRemoteConfig); frcNamespaceInstancesStatic.put(str, firebaseRemoteConfig); } } catch (Throwable th) { throw th; } return (FirebaseRemoteConfig) this.frcNamespaceInstances.get(str); } public final ConfigCacheClient getCacheClient(String str, String str2) { return ConfigCacheClient.getInstance(this.executor, ConfigStorageClient.getInstance(this.context, String.format("%s_%s_%s_%s.json", "frc", this.appId, str, str2))); } public ConfigFetchHttpClient getFrcBackendApiClient(String str, String str2, ConfigMetadataClient configMetadataClient) { return new ConfigFetchHttpClient(this.context, this.firebaseApp.getOptions().getApplicationId(), str, str2, configMetadataClient.getFetchTimeoutInSeconds(), configMetadataClient.getFetchTimeoutInSeconds()); } public synchronized ConfigFetchHandler getFetchHandler(String str, ConfigCacheClient configCacheClient, ConfigMetadataClient configMetadataClient) { try { } catch (Throwable th) { throw th; } return new ConfigFetchHandler(this.firebaseInstallations, isPrimaryApp(this.firebaseApp) ? this.analyticsConnector : new Provider() { // from class: com.google.firebase.remoteconfig.RemoteConfigComponent$$ExternalSyntheticLambda2 @Override // com.google.firebase.inject.Provider public final Object get() { AnalyticsConnector lambda$getFetchHandler$0; lambda$getFetchHandler$0 = RemoteConfigComponent.lambda$getFetchHandler$0(); return lambda$getFetchHandler$0; } }, this.executor, DEFAULT_CLOCK, DEFAULT_RANDOM, configCacheClient, getFrcBackendApiClient(this.firebaseApp.getOptions().getApiKey(), str, configMetadataClient), configMetadataClient, this.customHeaders); } public synchronized ConfigRealtimeHandler getRealtime(FirebaseApp firebaseApp, FirebaseInstallationsApi firebaseInstallationsApi, ConfigFetchHandler configFetchHandler, ConfigCacheClient configCacheClient, Context context, String str, ConfigMetadataClient configMetadataClient) { return new ConfigRealtimeHandler(firebaseApp, firebaseInstallationsApi, configFetchHandler, configCacheClient, context, str, configMetadataClient, this.executor); } public final ConfigGetParameterHandler getGetHandler(ConfigCacheClient configCacheClient, ConfigCacheClient configCacheClient2) { return new ConfigGetParameterHandler(this.executor, configCacheClient, configCacheClient2); } public static ConfigMetadataClient getMetadataClient(Context context, String str, String str2) { return new ConfigMetadataClient(context.getSharedPreferences(String.format("%s_%s_%s_%s", "frc", str, str2, "settings"), 0)); } public static Personalization getPersonalization(FirebaseApp firebaseApp, String str, Provider provider) { if (isPrimaryApp(firebaseApp) && str.equals("firebase")) { return new Personalization(provider); } return null; } public final RolloutsStateSubscriptionsHandler getRolloutsStateSubscriptionsHandler(ConfigCacheClient configCacheClient, ConfigCacheClient configCacheClient2) { return new RolloutsStateSubscriptionsHandler(configCacheClient, RolloutsStateFactory.create(configCacheClient, configCacheClient2), this.executor); } public static boolean isAbtSupported(FirebaseApp firebaseApp, String str) { return str.equals("firebase") && isPrimaryApp(firebaseApp); } public static boolean isPrimaryApp(FirebaseApp firebaseApp) { return firebaseApp.getName().equals("[DEFAULT]"); } public static synchronized void notifyRCInstances(boolean z) { synchronized (RemoteConfigComponent.class) { Iterator it = frcNamespaceInstancesStatic.values().iterator(); while (it.hasNext()) { ((FirebaseRemoteConfig) it.next()).setConfigUpdateBackgroundState(z); } } } @Override // com.google.firebase.remoteconfig.interop.FirebaseRemoteConfigInterop public void registerRolloutsStateSubscriber(String str, RolloutsStateSubscriber rolloutsStateSubscriber) { get(str).getRolloutsStateSubscriptionsHandler().registerRolloutsStateSubscriber(rolloutsStateSubscriber); } public static class GlobalBackgroundListener implements BackgroundDetector.BackgroundStateChangeListener { public static final AtomicReference INSTANCE = new AtomicReference(); public static void ensureBackgroundListenerIsRegistered(Context context) { Application application = (Application) context.getApplicationContext(); AtomicReference atomicReference = INSTANCE; if (atomicReference.get() == null) { GlobalBackgroundListener globalBackgroundListener = new GlobalBackgroundListener(); if (LifecycleKt$$ExternalSyntheticBackportWithForwarding0.m(atomicReference, null, globalBackgroundListener)) { BackgroundDetector.initialize(application); BackgroundDetector.getInstance().addListener(globalBackgroundListener); } } } @Override // com.google.android.gms.common.api.internal.BackgroundDetector.BackgroundStateChangeListener public void onBackgroundStateChanged(boolean z) { RemoteConfigComponent.notifyRCInstances(z); } } }