what-the-bank/sources/com/google/firebase/abt/FirebaseABTesting.java

132 lines
5.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.firebase.abt;
import android.content.Context;
import com.google.firebase.analytics.connector.AnalyticsConnector;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/* loaded from: classes.dex */
public class FirebaseABTesting {
private final AnalyticsConnector analyticsConnector;
private Integer maxUserProperties = null;
private final String originService;
public FirebaseABTesting(Context context, AnalyticsConnector analyticsConnector, String str) {
this.analyticsConnector = analyticsConnector;
this.originService = str;
}
public void replaceAllExperiments(List<Map<String, String>> list) throws AbtException {
throwAbtExceptionIfAnalyticsIsNull();
if (list == null) {
throw new IllegalArgumentException("The replacementExperiments list is null.");
}
replaceAllExperimentsWith(convertMapsToExperimentInfos(list));
}
public void removeAllExperiments() throws AbtException {
throwAbtExceptionIfAnalyticsIsNull();
removeExperiments(getAllExperimentsInAnalytics());
}
private void replaceAllExperimentsWith(List<AbtExperimentInfo> list) throws AbtException {
if (list.isEmpty()) {
removeAllExperiments();
return;
}
HashSet hashSet = new HashSet();
Iterator<AbtExperimentInfo> it = list.iterator();
while (it.hasNext()) {
hashSet.add(it.next().getExperimentId());
}
List<AnalyticsConnector.ConditionalUserProperty> allExperimentsInAnalytics = getAllExperimentsInAnalytics();
HashSet hashSet2 = new HashSet();
Iterator<AnalyticsConnector.ConditionalUserProperty> it2 = allExperimentsInAnalytics.iterator();
while (it2.hasNext()) {
hashSet2.add(it2.next().name);
}
removeExperiments(getExperimentsToRemove(allExperimentsInAnalytics, hashSet));
addExperiments(getExperimentsToAdd(list, hashSet2));
}
private ArrayList<AnalyticsConnector.ConditionalUserProperty> getExperimentsToRemove(List<AnalyticsConnector.ConditionalUserProperty> list, Set<String> set) {
ArrayList<AnalyticsConnector.ConditionalUserProperty> arrayList = new ArrayList<>();
for (AnalyticsConnector.ConditionalUserProperty conditionalUserProperty : list) {
if (!set.contains(conditionalUserProperty.name)) {
arrayList.add(conditionalUserProperty);
}
}
return arrayList;
}
private ArrayList<AbtExperimentInfo> getExperimentsToAdd(List<AbtExperimentInfo> list, Set<String> set) {
ArrayList<AbtExperimentInfo> arrayList = new ArrayList<>();
for (AbtExperimentInfo abtExperimentInfo : list) {
if (!set.contains(abtExperimentInfo.getExperimentId())) {
arrayList.add(abtExperimentInfo);
}
}
return arrayList;
}
private void addExperiments(List<AbtExperimentInfo> list) {
ArrayDeque arrayDeque = new ArrayDeque(getAllExperimentsInAnalytics());
int maxUserPropertiesInAnalytics = getMaxUserPropertiesInAnalytics();
for (AbtExperimentInfo abtExperimentInfo : list) {
while (arrayDeque.size() >= maxUserPropertiesInAnalytics) {
removeExperimentFromAnalytics(((AnalyticsConnector.ConditionalUserProperty) arrayDeque.pollFirst()).name);
}
AnalyticsConnector.ConditionalUserProperty conditionalUserProperty = abtExperimentInfo.toConditionalUserProperty(this.originService);
addExperimentToAnalytics(conditionalUserProperty);
arrayDeque.offer(conditionalUserProperty);
}
}
private void removeExperiments(Collection<AnalyticsConnector.ConditionalUserProperty> collection) {
Iterator<AnalyticsConnector.ConditionalUserProperty> it = collection.iterator();
while (it.hasNext()) {
removeExperimentFromAnalytics(it.next().name);
}
}
private static List<AbtExperimentInfo> convertMapsToExperimentInfos(List<Map<String, String>> list) throws AbtException {
ArrayList arrayList = new ArrayList();
Iterator<Map<String, String>> it = list.iterator();
while (it.hasNext()) {
arrayList.add(AbtExperimentInfo.fromMap(it.next()));
}
return arrayList;
}
private void addExperimentToAnalytics(AnalyticsConnector.ConditionalUserProperty conditionalUserProperty) {
this.analyticsConnector.setConditionalUserProperty(conditionalUserProperty);
}
private void throwAbtExceptionIfAnalyticsIsNull() throws AbtException {
if (this.analyticsConnector == null) {
throw new AbtException("The Analytics SDK is not available. Please check that the Analytics SDK is included in your app dependencies.");
}
}
private void removeExperimentFromAnalytics(String str) {
this.analyticsConnector.clearConditionalUserProperty(str, null, null);
}
private int getMaxUserPropertiesInAnalytics() {
if (this.maxUserProperties == null) {
this.maxUserProperties = Integer.valueOf(this.analyticsConnector.getMaxUserProperties(this.originService));
}
return this.maxUserProperties.intValue();
}
private List<AnalyticsConnector.ConditionalUserProperty> getAllExperimentsInAnalytics() {
return this.analyticsConnector.getConditionalUserProperties(this.originService, "");
}
}