APKPure.apk(点击下载) / g.java


package e.l.c.t;

import android.net.TrafficStats;
import android.text.TextUtils;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.installations.FirebaseInstallationsException;
import com.tencent.raft.codegenmeta.utils.Constants;
import e.l.c.h;
import e.l.c.q.j;
import e.l.c.t.p.a;
import e.l.c.t.p.b;
import e.l.c.t.p.c;
import e.l.c.t.p.d;
import e.l.c.t.q.b;
import e.l.c.t.q.c;
import e.l.c.t.q.d;
import e.l.c.t.q.f;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import org.json.JSONException;
import org.json.JSONObject;

public class g implements h {

    /* renamed from: m  reason: collision with root package name */
    public static final Object f10067m = new Object();

    /* renamed from: n  reason: collision with root package name */
    public static final ThreadFactory f10068n = new a();

    /* renamed from: a  reason: collision with root package name */
    public final h f10069a;
    public final c b;
    public final e.l.c.t.p.c c;
    public final n d;

    /* renamed from: e  reason: collision with root package name */
    public final b f10070e;

    /* renamed from: f  reason: collision with root package name */
    public final l f10071f;

    /* renamed from: g  reason: collision with root package name */
    public final Object f10072g = new Object();

    /* renamed from: h  reason: collision with root package name */
    public final ExecutorService f10073h;

    /* renamed from: i  reason: collision with root package name */
    public final ExecutorService f10074i;

    /* renamed from: j  reason: collision with root package name */
    public String f10075j;

    /* renamed from: k  reason: collision with root package name */
    public Set<e.l.c.t.o.a> f10076k = new HashSet();

    /* renamed from: l  reason: collision with root package name */
    public final List<m> f10077l = new ArrayList();

    public class a implements ThreadFactory {
        public final AtomicInteger b = new AtomicInteger(1);

        public Thread newThread(Runnable runnable) {
            return new Thread(runnable, String.format("firebase-installations-executor-%d", Integer.valueOf(this.b.getAndIncrement())));
        }
    }

    public g(h hVar, e.l.c.s.b<j> bVar) {
        TimeUnit timeUnit = TimeUnit.SECONDS;
        LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue();
        ThreadFactory threadFactory = f10068n;
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, 30, timeUnit, linkedBlockingQueue, threadFactory);
        hVar.a();
        c cVar = new c(hVar.f9624a, bVar);
        e.l.c.t.p.c cVar2 = new e.l.c.t.p.c(hVar);
        n c2 = n.c();
        b bVar2 = new b(hVar);
        l lVar = new l();
        this.f10069a = hVar;
        this.b = cVar;
        this.c = cVar2;
        this.d = c2;
        this.f10070e = bVar2;
        this.f10071f = lVar;
        this.f10073h = threadPoolExecutor;
        this.f10074i = new ThreadPoolExecutor(0, 1, 30, timeUnit, new LinkedBlockingQueue(), threadFactory);
    }

    public static g g() {
        h b2 = h.b();
        Preconditions.checkArgument(true, "Null is not a valid value of FirebaseApp.");
        b2.a();
        return (g) b2.d.a(h.class);
    }

    @Override // e.l.c.t.h
    public Task<k> a(boolean z) {
        i();
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        i iVar = new i(this.d, taskCompletionSource);
        synchronized (this.f10072g) {
            this.f10077l.add(iVar);
        }
        Task<k> task = taskCompletionSource.getTask();
        this.f10073h.execute(new c(this, z));
        return task;
    }

    public final void b(boolean z) {
        d c2;
        synchronized (f10067m) {
            h hVar = this.f10069a;
            hVar.a();
            f a2 = f.a(hVar.f9624a, "generatefid.lock");
            try {
                c2 = this.c.c();
                if (c2.i()) {
                    String j2 = j(c2);
                    e.l.c.t.p.c cVar = this.c;
                    a.b bVar = (a.b) c2.k();
                    bVar.f10086a = j2;
                    bVar.b(c.a.UNREGISTERED);
                    c2 = bVar.a();
                    cVar.b(c2);
                }
            } finally {
                if (a2 != null) {
                    a2.b();
                }
            }
        }
        if (z) {
            a.b bVar2 = (a.b) c2.k();
            bVar2.c = null;
            c2 = bVar2.a();
        }
        m(c2);
        this.f10074i.execute(new a(this, z));
    }

    @Override // e.l.c.t.h
    public Task<String> c() {
        String str;
        i();
        synchronized (this) {
            str = this.f10075j;
        }
        if (str != null) {
            return Tasks.forResult(str);
        }
        TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
        j jVar = new j(taskCompletionSource);
        synchronized (this.f10072g) {
            this.f10077l.add(jVar);
        }
        Task<String> task = taskCompletionSource.getTask();
        this.f10073h.execute(new b(this));
        return task;
    }

    public final d d(d dVar) throws FirebaseInstallationsException {
        f f2;
        f.a a2;
        f.b bVar;
        FirebaseInstallationsException.a aVar = FirebaseInstallationsException.a.UNAVAILABLE;
        e.l.c.t.q.c cVar = this.b;
        String e2 = e();
        e.l.c.t.p.a aVar2 = (e.l.c.t.p.a) dVar;
        String str = aVar2.b;
        String h2 = h();
        String str2 = aVar2.f10082e;
        if (cVar.c.a()) {
            URL a3 = cVar.a(String.format("projects/%s/installations/%s/authTokens:generate", h2, str));
            for (int i2 = 0; i2 <= 1; i2++) {
                TrafficStats.setThreadStatsTag(32771);
                HttpURLConnection c2 = cVar.c(a3, e2);
                try {
                    c2.setRequestMethod("POST");
                    c2.addRequestProperty("Authorization", "FIS_v2 " + str2);
                    c2.setDoOutput(true);
                    cVar.h(c2);
                    int responseCode = c2.getResponseCode();
                    cVar.c.b(responseCode);
                    if (responseCode >= 200 && responseCode < 300) {
                        f2 = cVar.f(c2);
                    } else {
                        e.l.c.t.q.c.b(c2, null, e2, h2);
                        if (responseCode == 401) {
                            a2 = f.a();
                            bVar = f.b.AUTH_ERROR;
                        } else if (responseCode == 404) {
                            a2 = f.a();
                            bVar = f.b.AUTH_ERROR;
                        } else if (responseCode == 429) {
                            throw new FirebaseInstallationsException("Firebase servers have received too many requests from this client in a short period of time. Please try again later.", FirebaseInstallationsException.a.TOO_MANY_REQUESTS);
                        } else if (responseCode < 500 || responseCode >= 600) {
                            a2 = f.a();
                            bVar = f.b.BAD_CONFIG;
                        } else {
                            c2.disconnect();
                            TrafficStats.clearThreadStatsTag();
                        }
                        b.C0216b bVar2 = (b.C0216b) a2;
                        bVar2.c = bVar;
                        f2 = bVar2.a();
                    }
                    c2.disconnect();
                    TrafficStats.clearThreadStatsTag();
                    e.l.c.t.q.b bVar3 = (e.l.c.t.q.b) f2;
                    int ordinal = bVar3.c.ordinal();
                    if (ordinal == 0) {
                        String str3 = bVar3.f10098a;
                        long j2 = bVar3.b;
                        long b2 = this.d.b();
                        a.b bVar4 = (a.b) dVar.k();
                        bVar4.c = str3;
                        bVar4.f10087e = Long.valueOf(j2);
                        bVar4.f10088f = Long.valueOf(b2);
                        return bVar4.a();
                    } else if (ordinal == 1) {
                        a.b bVar5 = (a.b) dVar.k();
                        bVar5.f10089g = "BAD CONFIG";
                        bVar5.b(c.a.REGISTER_ERROR);
                        return bVar5.a();
                    } else if (ordinal == 2) {
                        synchronized (this) {
                            this.f10075j = null;
                        }
                        d.a k2 = dVar.k();
                        k2.b(c.a.NOT_GENERATED);
                        return k2.a();
                    } else {
                        throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", aVar);
                    }
                } catch (IOException | AssertionError unused) {
                } catch (Throwable th) {
                    c2.disconnect();
                    TrafficStats.clearThreadStatsTag();
                    throw th;
                }
            }
            throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", aVar);
        }
        throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", aVar);
    }

    public String e() {
        h hVar = this.f10069a;
        hVar.a();
        return hVar.c.f9632a;
    }

    public String f() {
        h hVar = this.f10069a;
        hVar.a();
        return hVar.c.b;
    }

    public String h() {
        h hVar = this.f10069a;
        hVar.a();
        return hVar.c.f9635g;
    }

    public final void i() {
        Preconditions.checkNotEmpty(f(), "Please set your Application ID. A valid Firebase App ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.");
        Preconditions.checkNotEmpty(h(), "Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.");
        Preconditions.checkNotEmpty(e(), "Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options.");
        String f2 = f();
        Pattern pattern = n.c;
        Preconditions.checkArgument(f2.contains(Constants.KEY_INDEX_FILE_SEPARATOR), "Please set your Application ID. A valid Firebase App ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options.");
        Preconditions.checkArgument(n.c.matcher(e()).matches(), "Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options.");
    }

    public final String j(d dVar) {
        String string;
        h hVar = this.f10069a;
        hVar.a();
        if (hVar.b.equals("CHIME_ANDROID_SDK") || this.f10069a.g()) {
            if (((e.l.c.t.p.a) dVar).c == c.a.ATTEMPT_MIGRATION) {
                e.l.c.t.p.b bVar = this.f10070e;
                synchronized (bVar.f10090a) {
                    synchronized (bVar.f10090a) {
                        string = bVar.f10090a.getString("|S|id", null);
                    }
                    if (string == null) {
                        string = bVar.a();
                    }
                }
                return TextUtils.isEmpty(string) ? this.f10071f.a() : string;
            }
        }
        return this.f10071f.a();
    }

    /* JADX INFO: finally extract failed */
    public final d k(d dVar) throws FirebaseInstallationsException {
        e.l.c.t.q.d e2;
        FirebaseInstallationsException.a aVar = FirebaseInstallationsException.a.UNAVAILABLE;
        e.l.c.t.p.a aVar2 = (e.l.c.t.p.a) dVar;
        String str = aVar2.b;
        String str2 = null;
        if (str != null && str.length() == 11) {
            e.l.c.t.p.b bVar = this.f10070e;
            synchronized (bVar.f10090a) {
                String[] strArr = e.l.c.t.p.b.c;
                int length = strArr.length;
                int i2 = 0;
                while (true) {
                    if (i2 >= length) {
                        break;
                    }
                    String str3 = strArr[i2];
                    String str4 = bVar.b;
                    String string = bVar.f10090a.getString("|T|" + str4 + "|" + str3, null);
                    if (string == null || string.isEmpty()) {
                        i2++;
                    } else if (string.startsWith("{")) {
                        try {
                            str2 = new JSONObject(string).getString("token");
                        } catch (JSONException unused) {
                        }
                    } else {
                        str2 = string;
                    }
                }
            }
        }
        e.l.c.t.q.c cVar = this.b;
        String e3 = e();
        String str5 = aVar2.b;
        String h2 = h();
        String f2 = f();
        if (cVar.c.a()) {
            URL a2 = cVar.a(String.format("projects/%s/installations", h2));
            for (int i3 = 0; i3 <= 1; i3++) {
                TrafficStats.setThreadStatsTag(32769);
                HttpURLConnection c2 = cVar.c(a2, e3);
                try {
                    c2.setRequestMethod("POST");
                    c2.setDoOutput(true);
                    if (str2 != null) {
                        c2.addRequestProperty("x-goog-fis-android-iid-migration-auth", str2);
                    }
                    cVar.g(c2, str5, f2);
                    int responseCode = c2.getResponseCode();
                    cVar.c.b(responseCode);
                    if (responseCode >= 200 && responseCode < 300) {
                        e2 = cVar.e(c2);
                        c2.disconnect();
                        TrafficStats.clearThreadStatsTag();
                    } else {
                        try {
                            e.l.c.t.q.c.b(c2, f2, e3, h2);
                            if (responseCode == 429) {
                                throw new FirebaseInstallationsException("Firebase servers have received too many requests from this client in a short period of time. Please try again later.", FirebaseInstallationsException.a.TOO_MANY_REQUESTS);
                            } else if (responseCode < 500 || responseCode >= 600) {
                                e.l.c.t.q.a aVar3 = new e.l.c.t.q.a(null, null, null, null, d.a.BAD_CONFIG, null);
                                c2.disconnect();
                                TrafficStats.clearThreadStatsTag();
                                e2 = aVar3;
                            } else {
                                c2.disconnect();
                                TrafficStats.clearThreadStatsTag();
                            }
                        } catch (IOException | AssertionError unused2) {
                        }
                    }
                    e.l.c.t.q.a aVar4 = (e.l.c.t.q.a) e2;
                    int ordinal = aVar4.f10097e.ordinal();
                    if (ordinal == 0) {
                        String str6 = aVar4.b;
                        String str7 = aVar4.c;
                        long b2 = this.d.b();
                        String c3 = aVar4.d.c();
                        long d2 = aVar4.d.d();
                        a.b bVar2 = (a.b) dVar.k();
                        bVar2.f10086a = str6;
                        bVar2.b(c.a.REGISTERED);
                        bVar2.c = c3;
                        bVar2.d = str7;
                        bVar2.f10087e = Long.valueOf(d2);
                        bVar2.f10088f = Long.valueOf(b2);
                        return bVar2.a();
                    } else if (ordinal == 1) {
                        a.b bVar3 = (a.b) dVar.k();
                        bVar3.f10089g = "BAD CONFIG";
                        bVar3.b(c.a.REGISTER_ERROR);
                        return bVar3.a();
                    } else {
                        throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", aVar);
                    }
                } catch (Throwable th) {
                    c2.disconnect();
                    TrafficStats.clearThreadStatsTag();
                    throw th;
                }
            }
            throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", aVar);
        }
        throw new FirebaseInstallationsException("Firebase Installations Service is unavailable. Please try again later.", aVar);
    }

    public final void l(Exception exc) {
        synchronized (this.f10072g) {
            Iterator<m> it = this.f10077l.iterator();
            while (it.hasNext()) {
                if (it.next().a(exc)) {
                    it.remove();
                }
            }
        }
    }

    public final void m(e.l.c.t.p.d dVar) {
        synchronized (this.f10072g) {
            Iterator<m> it = this.f10077l.iterator();
            while (it.hasNext()) {
                if (it.next().b(dVar)) {
                    it.remove();
                }
            }
        }
    }
}