package p138.p176.p291.p320;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
import android.util.Log;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p252.C4306;
import p138.p176.p177.p242.p246.p253.p254.ThreadFactoryC4317;
import p138.p176.p177.p242.p270.AbstractC5062;
import p138.p176.p177.p242.p270.C5074;
import p138.p176.p177.p242.p270.C5085;
import p138.p176.p177.p242.p270.InterfaceC5058;

/* JADX INFO: renamed from: ދ.ހ.ށ.ވ.ޞ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class ServiceConnectionC5937 implements ServiceConnection {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Context f16742;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Intent f16743;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final ScheduledExecutorService f16744;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final Queue<C5936> f16745;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public BinderC5934 f16746;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public boolean f16747;

    public ServiceConnectionC5937(Context context, String str) {
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(0, new ThreadFactoryC4317("Firebase-FirebaseInstanceIdServiceConnection"));
        this.f16745 = new ArrayDeque();
        this.f16747 = false;
        this.f16742 = context.getApplicationContext();
        this.f16743 = new Intent(str).setPackage(this.f16742.getPackageName());
        this.f16744 = scheduledThreadPoolExecutor;
    }

    @Override // android.content.ServiceConnection
    public final synchronized void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        if (Log.isLoggable("FirebaseInstanceId", 3)) {
            String strValueOf = String.valueOf(componentName);
            StringBuilder sb = new StringBuilder(strValueOf.length() + 20);
            sb.append("onServiceConnected: ");
            sb.append(strValueOf);
            Log.d("FirebaseInstanceId", sb.toString());
        }
        this.f16747 = false;
        if (iBinder instanceof BinderC5934) {
            this.f16746 = (BinderC5934) iBinder;
            m9286();
            return;
        }
        String strValueOf2 = String.valueOf(iBinder);
        StringBuilder sb2 = new StringBuilder(strValueOf2.length() + 28);
        sb2.append("Invalid service connection: ");
        sb2.append(strValueOf2);
        Log.e("FirebaseInstanceId", sb2.toString());
        m9287();
    }

    @Override // android.content.ServiceConnection
    public final void onServiceDisconnected(ComponentName componentName) {
        if (Log.isLoggable("FirebaseInstanceId", 3)) {
            String strValueOf = String.valueOf(componentName);
            StringBuilder sb = new StringBuilder(strValueOf.length() + 23);
            sb.append("onServiceDisconnected: ");
            sb.append(strValueOf);
            Log.d("FirebaseInstanceId", sb.toString());
        }
        m9286();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized AbstractC5062<Void> m9285(Intent intent) {
        final C5936 c5936;
        if (Log.isLoggable("FirebaseInstanceId", 3)) {
            Log.d("FirebaseInstanceId", "new intent queued in the bind-strategy delivery");
        }
        c5936 = new C5936(intent);
        ScheduledExecutorService scheduledExecutorService = this.f16744;
        final ScheduledFuture<?> scheduledFutureSchedule = scheduledExecutorService.schedule(new Runnable(c5936) { // from class: ދ.ހ.ށ.ވ.ޠ

            /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
            public final C5936 f16749;

            {
                this.f16749 = c5936;
            }

            @Override // java.lang.Runnable
            public final void run() {
                C5936 c59362 = this.f16749;
                String action = c59362.f16740.getAction();
                StringBuilder sb = new StringBuilder(C2803.m4895(action, 61));
                sb.append("Service took too long to process intent: ");
                sb.append(action);
                sb.append(" App may get closed.");
                Log.w("FirebaseInstanceId", sb.toString());
                c59362.m9284();
            }
        }, 9000L, TimeUnit.MILLISECONDS);
        C5085<Void> c5085 = c5936.f16741.f15214;
        c5085.f15257.m8560(new C5074(scheduledExecutorService, new InterfaceC5058(scheduledFutureSchedule) { // from class: ދ.ހ.ށ.ވ.ޟ

            /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
            public final ScheduledFuture f16748;

            {
                this.f16748 = scheduledFutureSchedule;
            }

            @Override // p138.p176.p177.p242.p270.InterfaceC5058
            /* JADX INFO: renamed from: ֏ */
            public final void mo8539(AbstractC5062 abstractC5062) {
                this.f16748.cancel(false);
            }
        }));
        c5085.m8566();
        this.f16745.add(c5936);
        m9286();
        return c5936.f16741.f15214;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final synchronized void m9286() {
        if (Log.isLoggable("FirebaseInstanceId", 3)) {
            Log.d("FirebaseInstanceId", "flush queue called");
        }
        if (this.f16745.isEmpty()) {
            return;
        }
        if (Log.isLoggable("FirebaseInstanceId", 3)) {
            Log.d("FirebaseInstanceId", "found intent to be delivered");
        }
        if (this.f16746 != null && this.f16746.isBinderAlive()) {
            if (Log.isLoggable("FirebaseInstanceId", 3)) {
                Log.d("FirebaseInstanceId", "binder is alive, sending the intent.");
            }
            C5936 c5936Poll = this.f16745.poll();
            if (this.f16746 == null) {
                throw null;
            }
            if (Binder.getCallingUid() != Process.myUid()) {
                throw new SecurityException("Binding only allowed within app");
            }
            if (Log.isLoggable("FirebaseInstanceId", 3)) {
                Log.d("FirebaseInstanceId", "service received new intent via bind strategy");
            }
            Intent intent = c5936Poll.f16740;
            throw null;
        }
        if (Log.isLoggable("FirebaseInstanceId", 3)) {
            boolean z = !this.f16747;
            StringBuilder sb = new StringBuilder(39);
            sb.append("binder is dead. start connection? ");
            sb.append(z);
            Log.d("FirebaseInstanceId", sb.toString());
        }
        if (!this.f16747) {
            this.f16747 = true;
            try {
                if (C4306.m7206().m7207(this.f16742, this.f16743, this, 65)) {
                    return;
                } else {
                    Log.e("FirebaseInstanceId", "binding to the service failed");
                }
            } catch (SecurityException e) {
                Log.e("FirebaseInstanceId", "Exception while binding the service", e);
            }
            this.f16747 = false;
            m9287();
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m9287() {
        while (!this.f16745.isEmpty()) {
            this.f16745.poll().m9284();
        }
    }
}
