133 lines
6.6 KiB
Java
133 lines
6.6 KiB
Java
package com.google.firebase.heartbeatinfo;
|
|
|
|
import K.k;
|
|
import android.content.Context;
|
|
import android.util.Base64OutputStream;
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import com.google.firebase.FirebaseApp;
|
|
import com.google.firebase.annotations.concurrent.Background;
|
|
import com.google.firebase.components.Component;
|
|
import com.google.firebase.components.ComponentContainer;
|
|
import com.google.firebase.components.Dependency;
|
|
import com.google.firebase.components.Qualified;
|
|
import com.google.firebase.heartbeatinfo.HeartBeatInfo;
|
|
import com.google.firebase.inject.Provider;
|
|
import com.google.firebase.platforminfo.UserAgentPublisher;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.zip.GZIPOutputStream;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class DefaultHeartBeatController implements HeartBeatController, HeartBeatInfo {
|
|
private final Context applicationContext;
|
|
private final Executor backgroundExecutor;
|
|
private final Set<HeartBeatConsumer> consumers;
|
|
private final Provider<HeartBeatInfoStorage> storageProvider;
|
|
private final Provider<UserAgentPublisher> userAgentProvider;
|
|
|
|
private DefaultHeartBeatController(Context context, String str, Set<HeartBeatConsumer> set, Provider<UserAgentPublisher> provider, Executor executor) {
|
|
this(new com.google.firebase.a(context, str), set, executor, provider, context);
|
|
}
|
|
|
|
public static Component<DefaultHeartBeatController> component() {
|
|
Qualified qualified = Qualified.qualified(Background.class, Executor.class);
|
|
return Component.builder(DefaultHeartBeatController.class, HeartBeatController.class, HeartBeatInfo.class).add(Dependency.required((Class<?>) Context.class)).add(Dependency.required((Class<?>) FirebaseApp.class)).add(Dependency.setOf((Class<?>) HeartBeatConsumer.class)).add(Dependency.requiredProvider((Class<?>) UserAgentPublisher.class)).add(Dependency.required((Qualified<?>) qualified)).factory(new b(qualified, 0)).build();
|
|
}
|
|
|
|
public static /* synthetic */ DefaultHeartBeatController lambda$component$3(Qualified qualified, ComponentContainer componentContainer) {
|
|
return new DefaultHeartBeatController((Context) componentContainer.get(Context.class), ((FirebaseApp) componentContainer.get(FirebaseApp.class)).getPersistenceKey(), (Set<HeartBeatConsumer>) componentContainer.setOf(HeartBeatConsumer.class), (Provider<UserAgentPublisher>) componentContainer.getProvider(UserAgentPublisher.class), (Executor) componentContainer.get(qualified));
|
|
}
|
|
|
|
public /* synthetic */ String lambda$getHeartBeatsHeader$1() throws Exception {
|
|
String byteArrayOutputStream;
|
|
synchronized (this) {
|
|
try {
|
|
HeartBeatInfoStorage heartBeatInfoStorage = this.storageProvider.get();
|
|
List<HeartBeatResult> allHeartBeats = heartBeatInfoStorage.getAllHeartBeats();
|
|
heartBeatInfoStorage.deleteAllHeartBeats();
|
|
JSONArray jSONArray = new JSONArray();
|
|
for (int i = 0; i < allHeartBeats.size(); i++) {
|
|
HeartBeatResult heartBeatResult = allHeartBeats.get(i);
|
|
JSONObject jSONObject = new JSONObject();
|
|
jSONObject.put("agent", heartBeatResult.getUserAgent());
|
|
jSONObject.put("dates", new JSONArray((Collection) heartBeatResult.getUsedDates()));
|
|
jSONArray.put(jSONObject);
|
|
}
|
|
JSONObject jSONObject2 = new JSONObject();
|
|
jSONObject2.put("heartbeats", jSONArray);
|
|
jSONObject2.put("version", "2");
|
|
ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
|
|
Base64OutputStream base64OutputStream = new Base64OutputStream(byteArrayOutputStream2, 11);
|
|
try {
|
|
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(base64OutputStream);
|
|
try {
|
|
gZIPOutputStream.write(jSONObject2.toString().getBytes("UTF-8"));
|
|
gZIPOutputStream.close();
|
|
base64OutputStream.close();
|
|
byteArrayOutputStream = byteArrayOutputStream2.toString("UTF-8");
|
|
} finally {
|
|
}
|
|
} catch (Throwable th) {
|
|
try {
|
|
base64OutputStream.close();
|
|
} catch (Throwable th2) {
|
|
th.addSuppressed(th2);
|
|
}
|
|
throw th;
|
|
}
|
|
} catch (Throwable th3) {
|
|
throw th3;
|
|
}
|
|
}
|
|
return byteArrayOutputStream;
|
|
}
|
|
|
|
public static /* synthetic */ HeartBeatInfoStorage lambda$new$2(Context context, String str) {
|
|
return new HeartBeatInfoStorage(context, str);
|
|
}
|
|
|
|
public /* synthetic */ Void lambda$registerHeartBeat$0() throws Exception {
|
|
synchronized (this) {
|
|
this.storageProvider.get().storeHeartBeat(System.currentTimeMillis(), this.userAgentProvider.get().getUserAgent());
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // com.google.firebase.heartbeatinfo.HeartBeatInfo
|
|
public synchronized HeartBeatInfo.HeartBeat getHeartBeatCode(String str) {
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
HeartBeatInfoStorage heartBeatInfoStorage = this.storageProvider.get();
|
|
if (!heartBeatInfoStorage.shouldSendGlobalHeartBeat(currentTimeMillis)) {
|
|
return HeartBeatInfo.HeartBeat.NONE;
|
|
}
|
|
heartBeatInfoStorage.postHeartBeatCleanUp();
|
|
return HeartBeatInfo.HeartBeat.GLOBAL;
|
|
}
|
|
|
|
@Override // com.google.firebase.heartbeatinfo.HeartBeatController
|
|
public Task<String> getHeartBeatsHeader() {
|
|
return !k.a(this.applicationContext) ? Tasks.forResult("") : Tasks.call(this.backgroundExecutor, new a(this, 0));
|
|
}
|
|
|
|
public Task<Void> registerHeartBeat() {
|
|
if (this.consumers.size() > 0 && k.a(this.applicationContext)) {
|
|
return Tasks.call(this.backgroundExecutor, new a(this, 1));
|
|
}
|
|
return Tasks.forResult(null);
|
|
}
|
|
|
|
public DefaultHeartBeatController(Provider<HeartBeatInfoStorage> provider, Set<HeartBeatConsumer> set, Executor executor, Provider<UserAgentPublisher> provider2, Context context) {
|
|
this.storageProvider = provider;
|
|
this.consumers = set;
|
|
this.backgroundExecutor = executor;
|
|
this.userAgentProvider = provider2;
|
|
this.applicationContext = context;
|
|
}
|
|
}
|