package o;

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 org.json.JSONArray;
import org.json.JSONObject;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.bq, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final /* synthetic */ class CallableC0850bq implements Callable {
    public final /* synthetic */ int a;
    public final /* synthetic */ C0945cq b;

    public /* synthetic */ CallableC0850bq(C0945cq c0945cq, int i) {
        this.a = i;
        this.b = c0945cq;
    }

    @Override // java.util.concurrent.Callable
    public final Object call() {
        String string;
        int i = this.a;
        C0945cq c0945cq = this.b;
        switch (i) {
            case 0:
                synchronized (c0945cq) {
                    try {
                        PE pe = (PE) c0945cq.a.get();
                        ArrayList arrayListA = pe.a();
                        synchronized (pe) {
                            pe.a.a(new S1(9, pe));
                        }
                        JSONArray jSONArray = new JSONArray();
                        for (int i2 = 0; i2 < arrayListA.size(); i2++) {
                            C0468Sb c0468Sb = (C0468Sb) arrayListA.get(i2);
                            JSONObject jSONObject = new JSONObject();
                            jSONObject.put("agent", c0468Sb.a);
                            jSONObject.put("dates", new JSONArray((Collection) c0468Sb.b));
                            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;
            default:
                synchronized (c0945cq) {
                    PE pe2 = (PE) c0945cq.a.get();
                    long jCurrentTimeMillis = System.currentTimeMillis();
                    String strA = ((C0224Iq) c0945cq.c.get()).a();
                    synchronized (pe2) {
                        pe2.a.a(new C1035dn(pe2, pe2.b(jCurrentTimeMillis), strA, new C1770lY(strA), 2));
                    }
                }
                return null;
        }
    }
}
