package defpackage;

import android.os.Bundle;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import com.google.firebase.abt.AbtException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.ParseException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;

/* JADX INFO: renamed from: ʽˁ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0081 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public Integer f1284 = null;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final InterfaceC5081 f1285;

    public C0081(InterfaceC5081 interfaceC5081) {
        this.f1285 = interfaceC5081;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static boolean m1127(ArrayList arrayList, C3194 c3194) {
        String str = c3194.f12126;
        String str2 = c3194.f12123;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            C3194 c31942 = (C3194) obj;
            if (c31942.f12126.equals(str) && c31942.f12123.equals(str2)) {
                return true;
            }
        }
        return false;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final ArrayList m1128() {
        C2342 c2342 = (C2342) ((InterfaceC5129) this.f1285.get());
        c2342.getClass();
        ArrayList arrayList = new ArrayList();
        for (Bundle bundle : c2342.f9202.f1029.m7050("frc", "")) {
            AbstractC5291 abstractC5291 = AbstractC3048.f11675;
            ᵘᵞʿⁱ.ᵶᵥᵝ(bundle);
            C4556 c4556 = new C4556();
            String str = (String) ᵷˆᵣ.ᵜᵪʾ(bundle, "origin", String.class, (Object) null);
            ᵘᵞʿⁱ.ᵶᵥᵝ(str);
            c4556.f17319 = str;
            String str2 = (String) ᵷˆᵣ.ᵜᵪʾ(bundle, "name", String.class, (Object) null);
            ᵘᵞʿⁱ.ᵶᵥᵝ(str2);
            c4556.f17310 = str2;
            c4556.f17313 = ᵷˆᵣ.ᵜᵪʾ(bundle, "value", Object.class, (Object) null);
            c4556.f17322 = (String) ᵷˆᵣ.ᵜᵪʾ(bundle, "trigger_event_name", String.class, (Object) null);
            c4556.f17315 = ((Long) ᵷˆᵣ.ᵜᵪʾ(bundle, "trigger_timeout", Long.class, 0L)).longValue();
            c4556.f17324 = (String) ᵷˆᵣ.ᵜᵪʾ(bundle, "timed_out_event_name", String.class, (Object) null);
            c4556.f17320 = (Bundle) ᵷˆᵣ.ᵜᵪʾ(bundle, "timed_out_event_params", Bundle.class, (Object) null);
            c4556.f17311 = (String) ᵷˆᵣ.ᵜᵪʾ(bundle, "triggered_event_name", String.class, (Object) null);
            c4556.f17323 = (Bundle) ᵷˆᵣ.ᵜᵪʾ(bundle, "triggered_event_params", Bundle.class, (Object) null);
            c4556.f17318 = ((Long) ᵷˆᵣ.ᵜᵪʾ(bundle, "time_to_live", Long.class, 0L)).longValue();
            c4556.f17321 = (String) ᵷˆᵣ.ᵜᵪʾ(bundle, "expired_event_name", String.class, (Object) null);
            c4556.f17317 = (Bundle) ᵷˆᵣ.ᵜᵪʾ(bundle, "expired_event_params", Bundle.class, (Object) null);
            c4556.f17312 = ((Boolean) ᵷˆᵣ.ᵜᵪʾ(bundle, "active", Boolean.class, Boolean.FALSE)).booleanValue();
            c4556.f17314 = ((Long) ᵷˆᵣ.ᵜᵪʾ(bundle, "creation_timestamp", Long.class, 0L)).longValue();
            c4556.f17316 = ((Long) ᵷˆᵣ.ᵜᵪʾ(bundle, "triggered_timestamp", Long.class, 0L)).longValue();
            arrayList.add(c4556);
        }
        return arrayList;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:116:0x02da  */
    /* JADX WARN: Removed duplicated region for block: B:136:0x032e  */
    /* JADX WARN: Removed duplicated region for block: B:139:0x0337  */
    /* JADX WARN: Removed duplicated region for block: B:142:0x033e  */
    /* JADX WARN: Removed duplicated region for block: B:145:0x034e  */
    /* JADX WARN: Removed duplicated region for block: B:148:0x0357  */
    /* JADX WARN: Removed duplicated region for block: B:151:0x0360  */
    /* JADX WARN: Removed duplicated region for block: B:154:0x0369  */
    /* JADX WARN: Removed duplicated region for block: B:157:0x0379  */
    /* JADX WARN: Removed duplicated region for block: B:160:0x0382  */
    /* JADX WARN: Removed duplicated region for block: B:90:0x0279  */
    /* JADX WARN: Type inference failed for: r0v15 */
    /* JADX WARN: Type inference failed for: r0v16 */
    /* JADX WARN: Type inference failed for: r0v54 */
    /* JADX WARN: Type inference failed for: r12v0 */
    /* JADX WARN: Type inference failed for: r12v1, types: [java.io.ObjectOutputStream] */
    /* JADX WARN: Type inference failed for: r12v19 */
    /* JADX WARN: Type inference failed for: r12v20 */
    /* JADX WARN: Type inference failed for: r12v21 */
    /* JADX WARN: Type inference failed for: r13v0 */
    /* JADX WARN: Type inference failed for: r13v1, types: [java.io.ObjectInputStream] */
    /* JADX WARN: Type inference failed for: r13v15 */
    /* JADX WARN: Type inference failed for: r13v2 */
    /* JADX WARN: Type inference failed for: r22v0, types: [android.os.Bundle, java.lang.String] */
    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m1129(ArrayList arrayList) throws AbtException {
        ?? r13;
        ?? r12;
        ?? r0;
        String str;
        String str2;
        String str3;
        String str4;
        Object obj;
        String str5;
        String str6;
        Bundle bundle;
        String str7;
        Bundle bundle2;
        String str8;
        Bundle bundle3;
        InterfaceC5081 interfaceC5081 = this.f1285;
        if (interfaceC5081.get() == null) {
            throw new AbtException("The Analytics SDK is not available. Please check that the Analytics SDK is included in your app dependencies.");
        }
        ArrayList arrayList2 = new ArrayList();
        int size = arrayList.size();
        int i = 0;
        int i2 = 0;
        while (true) {
            if (i2 >= size) {
                Object obj2 = null;
                if (arrayList2.isEmpty()) {
                    if (interfaceC5081.get() == null) {
                        throw new AbtException("The Analytics SDK is not available. Please check that the Analytics SDK is included in your app dependencies.");
                    }
                    ArrayList arrayListM1128 = m1128();
                    int size2 = arrayListM1128.size();
                    while (i < size2) {
                        Object obj3 = arrayListM1128.get(i);
                        i++;
                        String str9 = ((C4556) obj3).f17310;
                        C2957 c2957 = ((C2342) ((InterfaceC5129) interfaceC5081.get())).f9202.f1029;
                        c2957.m7046(new C3102(c2957, str9, null, null, 0));
                    }
                    return;
                }
                if (interfaceC5081.get() == null) {
                    throw new AbtException("The Analytics SDK is not available. Please check that the Analytics SDK is included in your app dependencies.");
                }
                ArrayList arrayListM11282 = m1128();
                ArrayList arrayList3 = new ArrayList();
                int size3 = arrayListM11282.size();
                int i3 = 0;
                while (i3 < size3) {
                    Object obj4 = arrayListM11282.get(i3);
                    i3++;
                    C4556 c4556 = (C4556) obj4;
                    String[] strArr = C3194.f12122;
                    String str10 = c4556.f17322;
                    arrayList3.add(new C3194(c4556.f17310, String.valueOf(c4556.f17313), str10 != null ? str10 : "", new Date(c4556.f17314), c4556.f17315, c4556.f17318));
                    size3 = size3;
                    obj2 = obj2;
                }
                ?? r22 = obj2;
                ArrayList arrayList4 = new ArrayList();
                int size4 = arrayList3.size();
                int i4 = 0;
                while (i4 < size4) {
                    Object obj5 = arrayList3.get(i4);
                    i4++;
                    C3194 c3194 = (C3194) obj5;
                    if (!m1127(arrayList2, c3194)) {
                        arrayList4.add(c3194.m7308());
                    }
                }
                int size5 = arrayList4.size();
                int i5 = 0;
                while (i5 < size5) {
                    Object obj6 = arrayList4.get(i5);
                    i5++;
                    String str11 = ((C4556) obj6).f17310;
                    C2957 c29572 = ((C2342) ((InterfaceC5129) interfaceC5081.get())).f9202.f1029;
                    c29572.m7046(new C3102(c29572, str11, r22, r22, 0));
                }
                ArrayList arrayList5 = new ArrayList();
                int size6 = arrayList2.size();
                int i6 = 0;
                while (i6 < size6) {
                    Object obj7 = arrayList2.get(i6);
                    i6++;
                    C3194 c31942 = (C3194) obj7;
                    if (!m1127(arrayList3, c31942)) {
                        arrayList5.add(c31942);
                    }
                }
                ArrayDeque arrayDeque = new ArrayDeque(m1128());
                if (this.f1284 == null) {
                    this.f1284 = Integer.valueOf(((C2342) ((InterfaceC5129) interfaceC5081.get())).f9202.f1029.m7045("frc"));
                }
                int iIntValue = this.f1284.intValue();
                int size7 = arrayList5.size();
                int i7 = 0;
                while (i7 < size7) {
                    int i8 = i7 + 1;
                    C3194 c31943 = (C3194) arrayList5.get(i7);
                    while (arrayDeque.size() >= iIntValue) {
                        String str12 = ((C4556) arrayDeque.pollFirst()).f17310;
                        C2957 c29573 = ((C2342) ((InterfaceC5129) interfaceC5081.get())).f9202.f1029;
                        c29573.m7046(new C3102(c29573, str12, r22, r22, 0));
                    }
                    C4556 c4556M7308 = c31943.m7308();
                    C2342 c2342 = (C2342) ((InterfaceC5129) interfaceC5081.get());
                    c2342.getClass();
                    AbstractC5291 abstractC5291 = AbstractC3048.f11675;
                    String str13 = c4556M7308.f17319;
                    if (!str13.isEmpty()) {
                        Object obj8 = c4556M7308.f17313;
                        if (obj8 != null) {
                            try {
                                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                                ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
                                try {
                                    objectOutputStream.writeObject(obj8);
                                    objectOutputStream.flush();
                                    ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
                                    try {
                                        Object object = objectInputStream.readObject();
                                        try {
                                            objectOutputStream.close();
                                            objectInputStream.close();
                                            r0 = object;
                                        } catch (IOException | ClassNotFoundException unused) {
                                            r0 = r22;
                                        }
                                        if (r0 != 0) {
                                            if (!AbstractC3048.f11673.contains(str13)) {
                                                String str14 = c4556M7308.f17310;
                                                if ("_ce1".equals(str14) || "_ce2".equals(str14)) {
                                                    if (str13.equals("fcm") || str13.equals("frc")) {
                                                        str = c4556M7308.f17321;
                                                        if ((str != null || (AbstractC3048.m7147(str, c4556M7308.f17317) && AbstractC3048.m7146(str13, c4556M7308.f17321, c4556M7308.f17317))) && (((str2 = c4556M7308.f17311) == null || (AbstractC3048.m7147(str2, c4556M7308.f17323) && AbstractC3048.m7146(str13, c4556M7308.f17311, c4556M7308.f17323))) && ((str3 = c4556M7308.f17324) == null || (AbstractC3048.m7147(str3, c4556M7308.f17320) && AbstractC3048.m7146(str13, c4556M7308.f17324, c4556M7308.f17320))))) {
                                                            AppMeasurementSdk appMeasurementSdk = c2342.f9202;
                                                            Bundle bundle4 = new Bundle();
                                                            bundle4.putString("origin", c4556M7308.f17319);
                                                            str4 = c4556M7308.f17310;
                                                            if (str4 != null) {
                                                                bundle4.putString("name", str4);
                                                            }
                                                            obj = c4556M7308.f17313;
                                                            if (obj != null) {
                                                                ᵷˆᵣ.ˊᵨᵧ(bundle4, obj);
                                                            }
                                                            str5 = c4556M7308.f17322;
                                                            if (str5 != null) {
                                                                bundle4.putString("trigger_event_name", str5);
                                                            }
                                                            bundle4.putLong("trigger_timeout", c4556M7308.f17315);
                                                            str6 = c4556M7308.f17324;
                                                            if (str6 != null) {
                                                                bundle4.putString("timed_out_event_name", str6);
                                                            }
                                                            bundle = c4556M7308.f17320;
                                                            if (bundle != null) {
                                                                bundle4.putBundle("timed_out_event_params", bundle);
                                                            }
                                                            str7 = c4556M7308.f17311;
                                                            if (str7 != null) {
                                                                bundle4.putString("triggered_event_name", str7);
                                                            }
                                                            bundle2 = c4556M7308.f17323;
                                                            if (bundle2 != null) {
                                                                bundle4.putBundle("triggered_event_params", bundle2);
                                                            }
                                                            bundle4.putLong("time_to_live", c4556M7308.f17318);
                                                            str8 = c4556M7308.f17321;
                                                            if (str8 != null) {
                                                                bundle4.putString("expired_event_name", str8);
                                                            }
                                                            bundle3 = c4556M7308.f17317;
                                                            if (bundle3 != null) {
                                                                bundle4.putBundle("expired_event_params", bundle3);
                                                            }
                                                            bundle4.putLong("creation_timestamp", c4556M7308.f17314);
                                                            bundle4.putBoolean("active", c4556M7308.f17312);
                                                            bundle4.putLong("triggered_timestamp", c4556M7308.f17316);
                                                            C2957 c29574 = appMeasurementSdk.f1029;
                                                            c29574.m7046(new C4924(c29574, bundle4));
                                                        }
                                                    }
                                                } else if ("_ln".equals(str14)) {
                                                    if (str13.equals("fcm") || str13.equals("fiam")) {
                                                    }
                                                } else if (!AbstractC3048.f11674.contains(str14)) {
                                                    C2598 c2598 = AbstractC3048.f11677;
                                                    int i9 = c2598.f10050;
                                                    int i10 = 0;
                                                    while (i10 < i9) {
                                                        boolean zMatches = str14.matches((String) c2598.get(i10));
                                                        i10++;
                                                        if (zMatches) {
                                                            break;
                                                        }
                                                    }
                                                    str = c4556M7308.f17321;
                                                    if (str != null) {
                                                        AppMeasurementSdk appMeasurementSdk2 = c2342.f9202;
                                                        Bundle bundle42 = new Bundle();
                                                        bundle42.putString("origin", c4556M7308.f17319);
                                                        str4 = c4556M7308.f17310;
                                                        if (str4 != null) {
                                                        }
                                                        obj = c4556M7308.f17313;
                                                        if (obj != null) {
                                                        }
                                                        str5 = c4556M7308.f17322;
                                                        if (str5 != null) {
                                                        }
                                                        bundle42.putLong("trigger_timeout", c4556M7308.f17315);
                                                        str6 = c4556M7308.f17324;
                                                        if (str6 != null) {
                                                        }
                                                        bundle = c4556M7308.f17320;
                                                        if (bundle != null) {
                                                        }
                                                        str7 = c4556M7308.f17311;
                                                        if (str7 != null) {
                                                        }
                                                        bundle2 = c4556M7308.f17323;
                                                        if (bundle2 != null) {
                                                        }
                                                        bundle42.putLong("time_to_live", c4556M7308.f17318);
                                                        str8 = c4556M7308.f17321;
                                                        if (str8 != null) {
                                                        }
                                                        bundle3 = c4556M7308.f17317;
                                                        if (bundle3 != null) {
                                                        }
                                                        bundle42.putLong("creation_timestamp", c4556M7308.f17314);
                                                        bundle42.putBoolean("active", c4556M7308.f17312);
                                                        bundle42.putLong("triggered_timestamp", c4556M7308.f17316);
                                                        C2957 c295742 = appMeasurementSdk2.f1029;
                                                        c295742.m7046(new C4924(c295742, bundle42));
                                                    } else {
                                                        AppMeasurementSdk appMeasurementSdk22 = c2342.f9202;
                                                        Bundle bundle422 = new Bundle();
                                                        bundle422.putString("origin", c4556M7308.f17319);
                                                        str4 = c4556M7308.f17310;
                                                        if (str4 != null) {
                                                        }
                                                        obj = c4556M7308.f17313;
                                                        if (obj != null) {
                                                        }
                                                        str5 = c4556M7308.f17322;
                                                        if (str5 != null) {
                                                        }
                                                        bundle422.putLong("trigger_timeout", c4556M7308.f17315);
                                                        str6 = c4556M7308.f17324;
                                                        if (str6 != null) {
                                                        }
                                                        bundle = c4556M7308.f17320;
                                                        if (bundle != null) {
                                                        }
                                                        str7 = c4556M7308.f17311;
                                                        if (str7 != null) {
                                                        }
                                                        bundle2 = c4556M7308.f17323;
                                                        if (bundle2 != null) {
                                                        }
                                                        bundle422.putLong("time_to_live", c4556M7308.f17318);
                                                        str8 = c4556M7308.f17321;
                                                        if (str8 != null) {
                                                        }
                                                        bundle3 = c4556M7308.f17317;
                                                        if (bundle3 != null) {
                                                        }
                                                        bundle422.putLong("creation_timestamp", c4556M7308.f17314);
                                                        bundle422.putBoolean("active", c4556M7308.f17312);
                                                        bundle422.putLong("triggered_timestamp", c4556M7308.f17316);
                                                        C2957 c2957422 = appMeasurementSdk22.f1029;
                                                        c2957422.m7046(new C4924(c2957422, bundle422));
                                                    }
                                                }
                                            }
                                        }
                                    } catch (Throwable th) {
                                        th = th;
                                        r12 = objectOutputStream;
                                        r13 = objectInputStream;
                                        if (r12 != 0) {
                                            r12.close();
                                        }
                                        if (r13 != 0) {
                                            r13.close();
                                        }
                                        throw th;
                                    }
                                } catch (Throwable th2) {
                                    th = th2;
                                    r13 = r22;
                                    r12 = objectOutputStream;
                                }
                            } catch (Throwable th3) {
                                th = th3;
                                ?? r122 = r22;
                                r13 = r122;
                                r12 = r122;
                            }
                        }
                    }
                    arrayDeque.offer(c4556M7308);
                    i7 = i8;
                }
                return;
            }
            Object obj9 = arrayList.get(i2);
            i2++;
            Map map = (Map) obj9;
            String[] strArr2 = C3194.f12122;
            ArrayList arrayList6 = new ArrayList();
            String[] strArr3 = C3194.f12122;
            for (int i11 = 0; i11 < 5; i11++) {
                String str15 = strArr3[i11];
                if (!map.containsKey(str15)) {
                    arrayList6.add(str15);
                }
            }
            if (!arrayList6.isEmpty()) {
                throw new AbtException(String.format("The following keys are missing from the experiment info map: %s", arrayList6));
            }
            try {
                arrayList2.add(new C3194((String) map.get("experimentId"), (String) map.get("variantId"), map.containsKey("triggerEvent") ? (String) map.get("triggerEvent") : "", C3194.f12121.parse((String) map.get("experimentStartTime")), Long.parseLong((String) map.get("triggerTimeoutMillis")), Long.parseLong((String) map.get("timeToLiveMillis"))));
            } catch (NumberFormatException e) {
                throw new AbtException("Could not process experiment: one of the durations could not be converted into a long.", e);
            } catch (ParseException e2) {
                throw new AbtException("Could not process experiment: parsing experiment start time failed.", e2);
            }
        }
    }
}
