package Q4;

import O1.ServiceConnectionC0237m;
import Z6.InterfaceC0382w;
import android.content.Context;
import android.content.Intent;
import android.os.Messenger;
import android.os.Process;
import android.util.Log;
import com.google.android.gms.internal.measurement.C1;
import com.google.firebase.sessions.FirebaseSessionsRegistrar;
import com.google.firebase.sessions.SessionLifecycleService;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/* JADX INFO: renamed from: Q4.o, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0268o extends G6.i implements O6.p {

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f5806u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final /* synthetic */ C0269p f5807v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final /* synthetic */ E6.i f5808w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final /* synthetic */ c0 f5809x;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0268o(C0269p c0269p, E6.i iVar, c0 c0Var, E6.d dVar) {
        super(2, dVar);
        this.f5807v = c0269p;
        this.f5808w = iVar;
        this.f5809x = c0Var;
    }

    @Override // O6.p
    public final Object k(Object obj, Object obj2) {
        return ((C0268o) m((E6.d) obj2, (InterfaceC0382w) obj)).p(A6.n.f457a);
    }

    @Override // G6.a
    public final E6.d m(E6.d dVar, Object obj) {
        return new C0268o(this.f5807v, this.f5808w, this.f5809x, dVar);
    }

    /* JADX WARN: Code restructure failed: missing block: B:24:0x005e, code lost:
    
        if (r10.b(r9) == r0) goto L25;
     */
    @Override // G6.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object p(Object obj) throws Throwable {
        boolean zBooleanValue;
        boolean zBindService;
        F6.a aVar = F6.a.f2580q;
        int i = this.f5806u;
        C0269p c0269p = this.f5807v;
        if (i == 0) {
            C1.N(obj);
            R4.c cVar = R4.c.f6074a;
            this.f5806u = 1;
            obj = cVar.b(this);
            if (obj != aVar) {
            }
            return aVar;
        }
        if (i != 1) {
            if (i != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            C1.N(obj);
            U4.j jVar = c0269p.f5811b;
            Boolean boolB = jVar.f6753a.b();
            if (boolB != null) {
                zBooleanValue = boolB.booleanValue();
            } else {
                Boolean boolB2 = jVar.f6754b.b();
                zBooleanValue = boolB2 != null ? boolB2.booleanValue() : true;
            }
            if (zBooleanValue) {
                E6.i iVar = this.f5808w;
                C2.a aVar2 = new C2.a(iVar);
                c0 c0Var = this.f5809x;
                P6.g.e(c0Var, "sessionLifecycleServiceBinder");
                Messenger messenger = new Messenger(new I0.e(iVar));
                ServiceConnectionC0237m serviceConnectionC0237m = (ServiceConnectionC0237m) aVar2.f1160u;
                P6.g.e(serviceConnectionC0237m, "serviceConnection");
                Context context = c0Var.f5746a;
                Intent intent = new Intent(context, (Class<?>) SessionLifecycleService.class);
                Log.d("LifecycleServiceBinder", "Binding service to application.");
                intent.setAction(String.valueOf(Process.myPid()));
                intent.putExtra("ClientCallbackMessenger", messenger);
                intent.setPackage(context.getPackageName());
                try {
                    zBindService = context.bindService(intent, serviceConnectionC0237m, 65);
                } catch (SecurityException e8) {
                    Log.w("LifecycleServiceBinder", "Failed to bind session lifecycle service to application.", e8);
                    zBindService = false;
                }
                if (!zBindService) {
                    try {
                        context.unbindService(serviceConnectionC0237m);
                    } catch (IllegalArgumentException e9) {
                        Log.w("LifecycleServiceBinder", "Session lifecycle service binding failed.", e9);
                    }
                    Log.i("LifecycleServiceBinder", "Session lifecycle service binding failed.");
                }
                d0.f5756s = aVar2;
                if (d0.f5755r) {
                    d0.f5755r = false;
                    aVar2.K(1);
                }
                I3.y yVar = new I3.y(16);
                W3.f fVar = c0269p.f5810a;
                fVar.a();
                fVar.f7121j.add(yVar);
            } else {
                Log.d(FirebaseSessionsRegistrar.TAG, "Sessions SDK disabled. Not listening to lifecycle events.");
            }
            return A6.n.f457a;
        }
        C1.N(obj);
        Collection collectionValues = ((Map) obj).values();
        if (collectionValues == null || !collectionValues.isEmpty()) {
            Iterator it = collectionValues.iterator();
            while (it.hasNext()) {
                if (((k4.j) it.next()).f13867a.a()) {
                    U4.j jVar2 = c0269p.f5811b;
                    this.f5806u = 2;
                }
            }
        }
        Log.d(FirebaseSessionsRegistrar.TAG, "No Sessions subscribers. Not listening to lifecycle events.");
        return A6.n.f457a;
    }
}
