package O1;

import Q4.a0;
import Z6.AbstractC0385z;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.Log;
import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import n4.u0;

/* JADX INFO: renamed from: O1.m, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class ServiceConnectionC0237m implements ServiceConnection {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ int f5054q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final /* synthetic */ Object f5055r;

    public /* synthetic */ ServiceConnectionC0237m(int i, Object obj) {
        this.f5054q = i;
        this.f5055r = obj;
    }

    @Override // android.content.ServiceConnection
    public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        InterfaceC0231g interfaceC0231g;
        Object obj = this.f5055r;
        switch (this.f5054q) {
            case u0.f15495q /* 0 */:
                P6.g.e(componentName, "name");
                P6.g.e(iBinder, "service");
                int i = BinderC0239o.f5066f;
                IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface(InterfaceC0231g.f5035b);
                if (iInterfaceQueryLocalInterface == null || !(iInterfaceQueryLocalInterface instanceof InterfaceC0231g)) {
                    C0230f c0230f = new C0230f();
                    c0230f.f5034e = iBinder;
                    interfaceC0231g = c0230f;
                } else {
                    interfaceC0231g = (InterfaceC0231g) iInterfaceQueryLocalInterface;
                }
                C0238n c0238n = (C0238n) obj;
                c0238n.f5062g = interfaceC0231g;
                try {
                    c0238n.f5061f = interfaceC0231g.z(c0238n.f5064j, c0238n.f5056a);
                } catch (RemoteException e8) {
                    Log.w("ROOM", "Cannot register multi-instance invalidation callback", e8);
                    return;
                }
                break;
            default:
                StringBuilder sb = new StringBuilder("Connected to SessionLifecycleService. Queue size ");
                C2.a aVar = (C2.a) obj;
                sb.append(((LinkedBlockingDeque) aVar.f1159t).size());
                Log.d("SessionLifecycleClient", sb.toString());
                aVar.f1157r = new Messenger(iBinder);
                ArrayList arrayList = new ArrayList();
                ((LinkedBlockingDeque) aVar.f1159t).drainTo(arrayList);
                AbstractC0385z.r(AbstractC0385z.b((E6.i) aVar.f1158s), null, new a0(aVar, arrayList, null), 3);
                break;
        }
    }

    @Override // android.content.ServiceConnection
    public final void onServiceDisconnected(ComponentName componentName) {
        switch (this.f5054q) {
            case u0.f15495q /* 0 */:
                P6.g.e(componentName, "name");
                ((C0238n) this.f5055r).f5062g = null;
                break;
            default:
                Log.d("SessionLifecycleClient", "Disconnected from SessionLifecycleService");
                C2.a aVar = (C2.a) this.f5055r;
                aVar.f1157r = null;
                aVar.getClass();
                break;
        }
    }
}
