package p138.p176.p177.p242.p265.p266;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.RemoteException;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p242.p246.C4191;
import p138.p176.p177.p242.p246.p249.AbstractC4251;
import p138.p176.p177.p242.p246.p252.C4306;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ބ.֏.ໂ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class ServiceConnectionC4991 implements ServiceConnection, AbstractC4251.InterfaceC4252, AbstractC4251.InterfaceC4253 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public volatile boolean f15102;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public volatile C4802 f15103;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final /* synthetic */ C4987 f15104;

    public ServiceConnectionC4991(C4987 c4987) {
        this.f15104 = c4987;
    }

    @Override // android.content.ServiceConnection
    public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        InterfaceC4823 c4948;
        C0567.m1918("MeasurementServiceConnection.onServiceConnected");
        synchronized (this) {
            if (iBinder == null) {
                this.f15102 = false;
                this.f15104.mo8165().f14444.m8034("Service connected with null binder");
                return;
            }
            try {
                String interfaceDescriptor = iBinder.getInterfaceDescriptor();
                if ("com.google.android.gms.measurement.internal.IMeasurementService".equals(interfaceDescriptor)) {
                    IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.measurement.internal.IMeasurementService");
                    c4948 = iInterfaceQueryLocalInterface instanceof InterfaceC4823 ? (InterfaceC4823) iInterfaceQueryLocalInterface : new C4948(iBinder);
                    try {
                        this.f15104.mo8165().f14452.m8034("Bound to IMeasurementService interface");
                    } catch (RemoteException unused) {
                        this.f15104.mo8165().f14444.m8034("Service connect failed to get IMeasurementService");
                    }
                } else {
                    this.f15104.mo8165().f14444.m8035("Got binder with a wrong descriptor", interfaceDescriptor);
                    c4948 = null;
                }
            } catch (RemoteException unused2) {
                c4948 = null;
            }
            if (c4948 == null) {
                this.f15102 = false;
                try {
                    C4306 c4306M7206 = C4306.m7206();
                    Context context = this.f15104.f14588.f15009;
                    ServiceConnectionC4991 serviceConnectionC4991 = this.f15104.f15083;
                    if (c4306M7206 == null) {
                        throw null;
                    }
                    context.unbindService(serviceConnectionC4991);
                } catch (IllegalArgumentException unused3) {
                }
            } else {
                C4771 c4771Mo8163 = this.f15104.mo8163();
                RunnableC4985 runnableC4985 = new RunnableC4985(this, c4948);
                c4771Mo8163.m8482();
                C0567.m1910(runnableC4985);
                c4771Mo8163.m8005(new C4894<>(c4771Mo8163, runnableC4985, "Task exception on worker thread"));
            }
        }
    }

    @Override // android.content.ServiceConnection
    public final void onServiceDisconnected(ComponentName componentName) {
        C0567.m1918("MeasurementServiceConnection.onServiceDisconnected");
        this.f15104.mo8165().f14451.m8034("Service disconnected");
        C4771 c4771Mo8163 = this.f15104.mo8163();
        RunnableC4992 runnableC4992 = new RunnableC4992(this, componentName);
        c4771Mo8163.m8482();
        C0567.m1910(runnableC4992);
        c4771Mo8163.m8005(new C4894<>(c4771Mo8163, runnableC4992, "Task exception on worker thread"));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8525() {
        this.f15104.mo8008();
        Context context = this.f15104.f14588.f15009;
        synchronized (this) {
            if (this.f15102) {
                this.f15104.mo8165().f14452.m8034("Connection attempt already in progress");
                return;
            }
            if (this.f15103 != null && (this.f15103.m6922() || this.f15103.m6917())) {
                this.f15104.mo8165().f14452.m8034("Already awaiting connection attempt");
                return;
            }
            this.f15103 = new C4802(context, Looper.getMainLooper(), this, this);
            this.f15104.mo8165().f14452.m8034("Connecting to remote service");
            this.f15102 = true;
            this.f15103.m6926();
        }
    }

    @Override // p138.p176.p177.p242.p246.p249.AbstractC4251.InterfaceC4252
    /* JADX INFO: renamed from: ֏ */
    public final void mo6935(int i) {
        C0567.m1918("MeasurementServiceConnection.onConnectionSuspended");
        this.f15104.mo8165().f14451.m8034("Service connection suspended");
        C4771 c4771Mo8163 = this.f15104.mo8163();
        RunnableC4782 runnableC4782 = new RunnableC4782(this);
        c4771Mo8163.m8482();
        C0567.m1910(runnableC4782);
        c4771Mo8163.m8005(new C4894<>(c4771Mo8163, runnableC4782, "Task exception on worker thread"));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8526(Intent intent) {
        this.f15104.mo8008();
        Context context = this.f15104.f14588.f15009;
        C4306 c4306M7206 = C4306.m7206();
        synchronized (this) {
            if (this.f15102) {
                this.f15104.mo8165().f14452.m8034("Connection attempt already in progress");
                return;
            }
            this.f15104.mo8165().f14452.m8034("Using local app measurement service");
            this.f15102 = true;
            ServiceConnectionC4991 serviceConnectionC4991 = this.f15104.f15083;
            if (c4306M7206 == null) {
                throw null;
            }
            context.getClass().getName();
            c4306M7206.m7208(context, intent, serviceConnectionC4991, 129);
        }
    }

    @Override // p138.p176.p177.p242.p246.p249.AbstractC4251.InterfaceC4253
    /* JADX INFO: renamed from: ֏ */
    public final void mo6937(C4191 c4191) {
        C0567.m1918("MeasurementServiceConnection.onConnectionFailed");
        C4974 c4974 = this.f15104.f14588;
        C4794 c4794 = c4974.f15017;
        C4794 c47942 = (c4794 == null || !c4794.m8485()) ? null : c4974.f15017;
        if (c47942 != null) {
            c47942.f14447.m8035("Service connection failed", c4191);
        }
        synchronized (this) {
            this.f15102 = false;
            this.f15103 = null;
        }
        C4771 c4771Mo8163 = this.f15104.mo8163();
        RunnableC4877 runnableC4877 = new RunnableC4877(this);
        c4771Mo8163.m8482();
        C0567.m1910(runnableC4877);
        c4771Mo8163.m8005(new C4894<>(c4771Mo8163, runnableC4877, "Task exception on worker thread"));
    }

    @Override // p138.p176.p177.p242.p246.p249.AbstractC4251.InterfaceC4252
    /* JADX INFO: renamed from: ؠ */
    public final void mo6936(Bundle bundle) {
        C0567.m1918("MeasurementServiceConnection.onConnected");
        synchronized (this) {
            try {
                this.f15104.mo8163().m8004(new RunnableC4975(this, this.f15103.m6930()));
            } catch (DeadObjectException | IllegalStateException unused) {
                this.f15103 = null;
                this.f15102 = false;
            }
        }
    }
}
