package com.google.firebase.messaging;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.C1;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import r.C0966e;

/* JADX INFO: loaded from: classes.dex */
public final class D {
    public static final long i = TimeUnit.HOURS.toSeconds(8);

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final /* synthetic */ int f5827j = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f5828a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final V1.f f5829b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final A2.p f5830c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final FirebaseMessaging f5831d;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ScheduledThreadPoolExecutor f5833f;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final B f5835h;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final C0966e f5832e = new C0966e(0);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f5834g = false;

    public D(FirebaseMessaging firebaseMessaging, V1.f fVar, B b2, A2.p pVar, Context context, ScheduledThreadPoolExecutor scheduledThreadPoolExecutor) {
        this.f5831d = firebaseMessaging;
        this.f5829b = fVar;
        this.f5835h = b2;
        this.f5830c = pVar;
        this.f5828a = context;
        this.f5833f = scheduledThreadPoolExecutor;
    }

    public static void a(P1.o oVar) throws IOException {
        try {
            try {
                C1.b(oVar, 30L, TimeUnit.SECONDS);
            } catch (TimeoutException e2) {
                e = e2;
                throw new IOException("SERVICE_NOT_AVAILABLE", e);
            }
        } catch (InterruptedException | TimeoutException e6) {
            e = e6;
        } catch (ExecutionException e7) {
            Throwable cause = e7.getCause();
            if (cause instanceof IOException) {
                throw ((IOException) cause);
            }
            if (!(cause instanceof RuntimeException)) {
                throw new IOException(e7);
            }
            throw ((RuntimeException) cause);
        }
    }

    public final void b(String str) throws IOException {
        String strA = this.f5831d.a();
        A2.p pVar = this.f5830c;
        Bundle bundle = new Bundle();
        bundle.putString("gcm.topic", "/topics/" + str);
        a(pVar.k(pVar.p(strA, "/topics/" + str, bundle)));
    }

    public final void c(String str) throws IOException {
        String strA = this.f5831d.a();
        A2.p pVar = this.f5830c;
        Bundle bundle = new Bundle();
        bundle.putString("gcm.topic", "/topics/" + str);
        bundle.putString("delete", "1");
        a(pVar.k(pVar.p(strA, "/topics/" + str, bundle)));
    }

    public final P1.o d(A a5) {
        ArrayDeque arrayDeque;
        B b2 = this.f5835h;
        synchronized (b2) {
            F3.e eVar = b2.f5821a;
            String str = a5.f5819c;
            eVar.getClass();
            if (!TextUtils.isEmpty(str) && !str.contains((String) eVar.f716n)) {
                synchronized (((ArrayDeque) eVar.f717o)) {
                    if (((ArrayDeque) eVar.f717o).add(str)) {
                        ((ScheduledThreadPoolExecutor) eVar.p).execute(new androidx.lifecycle.G(3, eVar));
                    }
                }
            }
        }
        P1.i iVar = new P1.i();
        synchronized (this.f5832e) {
            try {
                String str2 = a5.f5819c;
                if (this.f5832e.containsKey(str2)) {
                    arrayDeque = (ArrayDeque) this.f5832e.get(str2);
                } else {
                    ArrayDeque arrayDeque2 = new ArrayDeque();
                    this.f5832e.put(str2, arrayDeque2);
                    arrayDeque = arrayDeque2;
                }
                arrayDeque.add(iVar);
            } catch (Throwable th) {
                throw th;
            }
        }
        return iVar.f2505a;
    }

    public final synchronized void e(boolean z5) {
        this.f5834g = z5;
    }

    public final void f() {
        boolean z5;
        if (this.f5835h.a() != null) {
            synchronized (this) {
                z5 = this.f5834g;
            }
            if (z5) {
                return;
            }
            h(0L);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:27:0x0050  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final boolean g() throws java.io.IOException {
        /*
            Method dump skipped, instruction units count: 353
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.firebase.messaging.D.g():boolean");
    }

    public final void h(long j5) {
        long jMin = Math.min(Math.max(30L, 2 * j5), i);
        this.f5833f.schedule(new F(this, this.f5828a, this.f5829b, jMin), j5, TimeUnit.SECONDS);
        e(true);
    }
}
