package defpackage;

import android.util.Log;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Random;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONException;
import org.json.JSONObject;

/* renamed from: ˇᵰ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0975 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public Object f4338;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public Object f4339;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public Object f4340;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public Object f4341;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public Object f4342;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public Object f4343;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public Object f4344;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public Object f4345;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public Object f4346;

    /* JADX WARN: Removed duplicated region for block: B:128:0x0429  */
    /* JADX WARN: Removed duplicated region for block: B:161:0x040f A[SYNTHETIC] */
    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void m3320(defpackage.C5456 r48, int r49) {
        /*
            Method dump skipped, instructions count: 1196
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C0975.m3320(ᵾᵶᵙ, int):void");
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public synchronized void m3321(int i) {
        ((ˊᵻ) this.f4345).getClass();
        ((C4093) this.f4342).m8971(new Date(new Date(System.currentTimeMillis()).getTime() + (i * 1000)));
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public synchronized void m3322() {
        Iterator it = ((LinkedHashSet) this.f4343).iterator();
        while (it.hasNext()) {
            ((C3583) it.next()).m8191();
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public C4767 m3323() {
        return (C4767) ((AtomicReference) this.f4345).get();
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public void m3324(long j, int i) {
        if (i == 0) {
            new FirebaseRemoteConfigServerException("Unable to fetch the latest version of the template.");
            m3322();
        } else {
            ((ScheduledExecutorService) this.f4340).schedule(new RunnableC3695(this, i, j), ((Random) this.f4339).nextInt(4), TimeUnit.SECONDS);
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public C4767 m3325(int i) throws Throwable {
        try {
            if (AbstractC1327.m4108(2, i)) {
                return null;
            }
            JSONObject jSONObjectM8347 = ((C3718) this.f4338).m8347();
            if (jSONObjectM8347 == null) {
                Log.isLoggable("FirebaseCrashlytics", 3);
                return null;
            }
            ˑᵽʾʦ r5 = (ˑᵽʾʦ) this.f4341;
            r5.getClass();
            C4767 c4767M8916 = (jSONObjectM8347.getInt("settings_version") != 3 ? new ᵥᵵ(18) : new ᵬˆˀᵣ(7)).m8916((ˎᵖᵗ) r5.ᵢˇᵭ, jSONObjectM8347);
            jSONObjectM8347.toString();
            Log.isLoggable("FirebaseCrashlytics", 3);
            ((ˎᵖᵗ) this.f4346).getClass();
            long jCurrentTimeMillis = System.currentTimeMillis();
            if (!AbstractC1327.m4108(3, i) && c4767M8916.f17716 < jCurrentTimeMillis) {
                Log.isLoggable("FirebaseCrashlytics", 2);
                return null;
            }
            try {
                Log.isLoggable("FirebaseCrashlytics", 2);
                return c4767M8916;
            } catch (Exception unused) {
                return c4767M8916;
            }
        } catch (Exception unused2) {
            return null;
        }
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public void m3326(InputStream inputStream) throws JSONException, IOException {
        JSONObject jSONObject;
        boolean zIsEmpty;
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
        String strConcat = "";
        while (true) {
            String line = bufferedReader.readLine();
            if (line == null) {
                break;
            }
            strConcat = strConcat.concat(line);
            if (line.contains("}")) {
                int iIndexOf = strConcat.indexOf(123);
                int iLastIndexOf = strConcat.lastIndexOf(125);
                strConcat = (iIndexOf < 0 || iLastIndexOf < 0 || iIndexOf >= iLastIndexOf) ? "" : strConcat.substring(iIndexOf, iLastIndexOf + 1);
                if (!strConcat.isEmpty()) {
                    try {
                        jSONObject = new JSONObject(strConcat);
                    } catch (JSONException e) {
                        new FirebaseRemoteConfigClientException("Unable to parse config update message.", e.getCause());
                        m3322();
                    }
                    if (jSONObject.has("featureDisabled") && jSONObject.getBoolean("featureDisabled")) {
                        C3583 c3583 = (C3583) this.f4338;
                        new FirebaseRemoteConfigServerException("The server is temporarily unavailable. Try again in a few minutes.");
                        c3583.m8191();
                        break;
                    }
                    synchronized (this) {
                        zIsEmpty = ((LinkedHashSet) this.f4343).isEmpty();
                    }
                    if (zIsEmpty) {
                        break;
                    }
                    if (jSONObject.has("latestTemplateVersionNumber")) {
                        long j = ((C4995) this.f4341).f18537.f15298.getLong("last_template_version", 0L);
                        long j2 = jSONObject.getLong("latestTemplateVersionNumber");
                        if (j2 > j) {
                            m3324(j2, 3);
                        }
                    }
                    if (jSONObject.has("retryIntervalSeconds")) {
                        m3321(jSONObject.getInt("retryIntervalSeconds"));
                    }
                    strConcat = "";
                } else {
                    continue;
                }
            }
        }
        bufferedReader.close();
    }
}
