package C4;

import android.util.Base64OutputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.zip.GZIPOutputStream;
import n4.u0;
import org.json.JSONArray;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public final /* synthetic */ class d implements Callable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f1327a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ e f1328b;

    public /* synthetic */ d(e eVar, int i) {
        this.f1327a = i;
        this.f1328b = eVar;
    }

    private final Object a() {
        String string;
        e eVar = this.f1328b;
        synchronized (eVar) {
            try {
                j jVar = (j) eVar.f1329a.get();
                ArrayList arrayListC = jVar.c();
                jVar.b();
                JSONArray jSONArray = new JSONArray();
                for (int i = 0; i < arrayListC.size(); i++) {
                    a aVar = (a) arrayListC.get(i);
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put("agent", aVar.f1320a);
                    jSONObject.put("dates", new JSONArray((Collection) aVar.f1321b));
                    jSONArray.put(jSONObject);
                }
                JSONObject jSONObject2 = new JSONObject();
                jSONObject2.put("heartbeats", jSONArray);
                jSONObject2.put("version", "2");
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                Base64OutputStream base64OutputStream = new Base64OutputStream(byteArrayOutputStream, 11);
                try {
                    GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(base64OutputStream);
                    try {
                        gZIPOutputStream.write(jSONObject2.toString().getBytes("UTF-8"));
                        gZIPOutputStream.close();
                        base64OutputStream.close();
                        string = byteArrayOutputStream.toString("UTF-8");
                    } finally {
                    }
                } finally {
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return string;
    }

    @Override // java.util.concurrent.Callable
    public final Object call() {
        switch (this.f1327a) {
            case u0.f15495q /* 0 */:
                return a();
            default:
                e eVar = this.f1328b;
                synchronized (eVar) {
                    j jVar = (j) eVar.f1329a.get();
                    long jCurrentTimeMillis = System.currentTimeMillis();
                    K4.b bVar = (K4.b) eVar.f1331c.get();
                    K4.c cVar = bVar.f3601b;
                    boolean zIsEmpty = cVar.y().isEmpty();
                    String str = bVar.f3600a;
                    if (!zIsEmpty) {
                        str = str + ' ' + K4.b.a(cVar.y());
                    }
                    jVar.g(jCurrentTimeMillis, str);
                    break;
                }
                return null;
        }
    }
}
