80 lines
3.0 KiB
Java
80 lines
3.0 KiB
Java
package com.google.firebase.remoteconfig.internal;
|
|
|
|
import com.google.android.gms.common.util.BiConsumer;
|
|
import java.nio.charset.Charset;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.regex.Pattern;
|
|
import org.json.JSONException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ConfigGetParameterHandler {
|
|
private final ConfigCacheClient activatedConfigsCache;
|
|
private final ConfigCacheClient defaultConfigsCache;
|
|
private final Executor executor;
|
|
private final Set<BiConsumer<String, ConfigContainer>> listeners = new HashSet();
|
|
public static final Charset FRC_BYTE_ARRAY_ENCODING = Charset.forName("UTF-8");
|
|
static final Pattern TRUE_REGEX = Pattern.compile("^(1|true|t|yes|y|on)$", 2);
|
|
static final Pattern FALSE_REGEX = Pattern.compile("^(0|false|f|no|n|off|)$", 2);
|
|
|
|
public ConfigGetParameterHandler(Executor executor, ConfigCacheClient configCacheClient, ConfigCacheClient configCacheClient2) {
|
|
this.executor = executor;
|
|
this.activatedConfigsCache = configCacheClient;
|
|
this.defaultConfigsCache = configCacheClient2;
|
|
}
|
|
|
|
public String getString(String str) {
|
|
String stringFromCache = getStringFromCache(this.activatedConfigsCache, str);
|
|
if (stringFromCache != null) {
|
|
callListeners(str, getConfigsFromCache(this.activatedConfigsCache));
|
|
return stringFromCache;
|
|
}
|
|
String stringFromCache2 = getStringFromCache(this.defaultConfigsCache, str);
|
|
if (stringFromCache2 != null) {
|
|
return stringFromCache2;
|
|
}
|
|
logParameterValueDoesNotExist(str, "String");
|
|
return "";
|
|
}
|
|
|
|
public void addListener(BiConsumer<String, ConfigContainer> biConsumer) {
|
|
synchronized (this.listeners) {
|
|
this.listeners.add(biConsumer);
|
|
}
|
|
}
|
|
|
|
private void callListeners(String str, ConfigContainer configContainer) {
|
|
if (configContainer == null) {
|
|
return;
|
|
}
|
|
synchronized (this.listeners) {
|
|
Iterator<BiConsumer<String, ConfigContainer>> it = this.listeners.iterator();
|
|
while (it.hasNext()) {
|
|
this.executor.execute(ConfigGetParameterHandler$$Lambda$1.lambdaFactory$(it.next(), str, configContainer));
|
|
}
|
|
}
|
|
}
|
|
|
|
private static String getStringFromCache(ConfigCacheClient configCacheClient, String str) {
|
|
ConfigContainer configsFromCache = getConfigsFromCache(configCacheClient);
|
|
if (configsFromCache == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
return configsFromCache.getConfigs().getString(str);
|
|
} catch (JSONException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static ConfigContainer getConfigsFromCache(ConfigCacheClient configCacheClient) {
|
|
return configCacheClient.getBlocking();
|
|
}
|
|
|
|
private static void logParameterValueDoesNotExist(String str, String str2) {
|
|
new Object[]{str2, str};
|
|
}
|
|
}
|