- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
181 lines
6.9 KiB
Java
181 lines
6.9 KiB
Java
package com.google.firebase.remoteconfig.internal;
|
|
|
|
import android.util.Log;
|
|
import com.google.android.gms.common.util.BiConsumer;
|
|
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
|
|
import java.nio.charset.Charset;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.regex.Pattern;
|
|
import org.json.JSONException;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class ConfigGetParameterHandler {
|
|
public final ConfigCacheClient activatedConfigsCache;
|
|
public final ConfigCacheClient defaultConfigsCache;
|
|
public final Executor executor;
|
|
public final Set listeners = new HashSet();
|
|
public static final Charset FRC_BYTE_ARRAY_ENCODING = Charset.forName("UTF-8");
|
|
public static final Pattern TRUE_REGEX = Pattern.compile("^(1|true|t|yes|y|on)$", 2);
|
|
public 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 boolean getBoolean(String str) {
|
|
String stringFromCache = getStringFromCache(this.activatedConfigsCache, str);
|
|
if (stringFromCache != null) {
|
|
if (TRUE_REGEX.matcher(stringFromCache).matches()) {
|
|
callListeners(str, getConfigsFromCache(this.activatedConfigsCache));
|
|
return true;
|
|
}
|
|
if (FALSE_REGEX.matcher(stringFromCache).matches()) {
|
|
callListeners(str, getConfigsFromCache(this.activatedConfigsCache));
|
|
return false;
|
|
}
|
|
}
|
|
String stringFromCache2 = getStringFromCache(this.defaultConfigsCache, str);
|
|
if (stringFromCache2 != null) {
|
|
if (TRUE_REGEX.matcher(stringFromCache2).matches()) {
|
|
return true;
|
|
}
|
|
if (FALSE_REGEX.matcher(stringFromCache2).matches()) {
|
|
return false;
|
|
}
|
|
}
|
|
logParameterValueDoesNotExist(str, "Boolean");
|
|
return false;
|
|
}
|
|
|
|
public double getDouble(String str) {
|
|
Double doubleFromCache = getDoubleFromCache(this.activatedConfigsCache, str);
|
|
if (doubleFromCache != null) {
|
|
callListeners(str, getConfigsFromCache(this.activatedConfigsCache));
|
|
return doubleFromCache.doubleValue();
|
|
}
|
|
Double doubleFromCache2 = getDoubleFromCache(this.defaultConfigsCache, str);
|
|
if (doubleFromCache2 != null) {
|
|
return doubleFromCache2.doubleValue();
|
|
}
|
|
logParameterValueDoesNotExist(str, "Double");
|
|
return 0.0d;
|
|
}
|
|
|
|
public FirebaseRemoteConfigValue getValue(String str) {
|
|
String stringFromCache = getStringFromCache(this.activatedConfigsCache, str);
|
|
if (stringFromCache != null) {
|
|
callListeners(str, getConfigsFromCache(this.activatedConfigsCache));
|
|
return new FirebaseRemoteConfigValueImpl(stringFromCache, 2);
|
|
}
|
|
String stringFromCache2 = getStringFromCache(this.defaultConfigsCache, str);
|
|
if (stringFromCache2 != null) {
|
|
return new FirebaseRemoteConfigValueImpl(stringFromCache2, 1);
|
|
}
|
|
logParameterValueDoesNotExist(str, "FirebaseRemoteConfigValue");
|
|
return new FirebaseRemoteConfigValueImpl("", 0);
|
|
}
|
|
|
|
public Map getAll() {
|
|
HashSet<String> hashSet = new HashSet();
|
|
hashSet.addAll(getKeySetFromCache(this.activatedConfigsCache));
|
|
hashSet.addAll(getKeySetFromCache(this.defaultConfigsCache));
|
|
HashMap hashMap = new HashMap();
|
|
for (String str : hashSet) {
|
|
hashMap.put(str, getValue(str));
|
|
}
|
|
return hashMap;
|
|
}
|
|
|
|
public void addListener(BiConsumer biConsumer) {
|
|
synchronized (this.listeners) {
|
|
this.listeners.add(biConsumer);
|
|
}
|
|
}
|
|
|
|
public final void callListeners(final String str, final ConfigContainer configContainer) {
|
|
if (configContainer == null) {
|
|
return;
|
|
}
|
|
synchronized (this.listeners) {
|
|
try {
|
|
for (final BiConsumer biConsumer : this.listeners) {
|
|
this.executor.execute(new Runnable() { // from class: com.google.firebase.remoteconfig.internal.ConfigGetParameterHandler$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
BiConsumer.this.accept(str, configContainer);
|
|
}
|
|
});
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public 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;
|
|
}
|
|
}
|
|
|
|
public static Double getDoubleFromCache(ConfigCacheClient configCacheClient, String str) {
|
|
ConfigContainer configsFromCache = getConfigsFromCache(configCacheClient);
|
|
if (configsFromCache == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
return Double.valueOf(configsFromCache.getConfigs().getDouble(str));
|
|
} catch (JSONException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static Set getKeySetFromCache(ConfigCacheClient configCacheClient) {
|
|
HashSet hashSet = new HashSet();
|
|
ConfigContainer configsFromCache = getConfigsFromCache(configCacheClient);
|
|
if (configsFromCache == null) {
|
|
return hashSet;
|
|
}
|
|
Iterator<String> keys = configsFromCache.getConfigs().keys();
|
|
while (keys.hasNext()) {
|
|
hashSet.add(keys.next());
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
public static ConfigContainer getConfigsFromCache(ConfigCacheClient configCacheClient) {
|
|
return configCacheClient.getBlocking();
|
|
}
|
|
|
|
public static void logParameterValueDoesNotExist(String str, String str2) {
|
|
Log.w("FirebaseRemoteConfig", String.format("No value of type '%s' exists for parameter key '%s'.", str2, str));
|
|
}
|
|
}
|