package r3; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.IInterface; import android.os.RemoteException; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; /* loaded from: classes2.dex */ public final class s0 { /* renamed from: o, reason: collision with root package name */ private static final Map f13682o = new HashMap(); /* renamed from: a, reason: collision with root package name */ private final Context f13683a; /* renamed from: b, reason: collision with root package name */ private final h0 f13684b; /* renamed from: c, reason: collision with root package name */ private final String f13685c; /* renamed from: g, reason: collision with root package name */ private boolean f13689g; /* renamed from: h, reason: collision with root package name */ private final Intent f13690h; /* renamed from: l, reason: collision with root package name */ private ServiceConnection f13694l; /* renamed from: m, reason: collision with root package name */ private IInterface f13695m; /* renamed from: n, reason: collision with root package name */ private final q3.b f13696n; /* renamed from: d, reason: collision with root package name */ private final List f13686d = new ArrayList(); /* renamed from: e, reason: collision with root package name */ private final Set f13687e = new HashSet(); /* renamed from: f, reason: collision with root package name */ private final Object f13688f = new Object(); /* renamed from: j, reason: collision with root package name */ private final IBinder.DeathRecipient f13692j = new IBinder.DeathRecipient() { // from class: r3.j0 @Override // android.os.IBinder.DeathRecipient public final void binderDied() { s0.j(s0.this); } }; /* renamed from: k, reason: collision with root package name */ private final AtomicInteger f13693k = new AtomicInteger(0); /* renamed from: i, reason: collision with root package name */ private final WeakReference f13691i = new WeakReference(null); public s0(Context context, h0 h0Var, String str, Intent intent, q3.b bVar, n0 n0Var) { this.f13683a = context; this.f13684b = h0Var; this.f13685c = str; this.f13690h = intent; this.f13696n = bVar; } public static /* synthetic */ void j(s0 s0Var) { s0Var.f13684b.d("reportBinderDeath", new Object[0]); androidx.appcompat.app.m.a(s0Var.f13691i.get()); s0Var.f13684b.d("%s : Binder has died.", s0Var.f13685c); Iterator it = s0Var.f13686d.iterator(); while (it.hasNext()) { ((i0) it.next()).c(s0Var.v()); } s0Var.f13686d.clear(); synchronized (s0Var.f13688f) { s0Var.w(); } } static /* bridge */ /* synthetic */ void n(final s0 s0Var, final TaskCompletionSource taskCompletionSource) { s0Var.f13687e.add(taskCompletionSource); taskCompletionSource.getTask().addOnCompleteListener(new OnCompleteListener() { // from class: r3.k0 @Override // com.google.android.gms.tasks.OnCompleteListener public final void onComplete(Task task) { s0.this.t(taskCompletionSource, task); } }); } static /* bridge */ /* synthetic */ void p(s0 s0Var, i0 i0Var) { if (s0Var.f13695m != null || s0Var.f13689g) { if (!s0Var.f13689g) { i0Var.run(); return; } else { s0Var.f13684b.d("Waiting to bind to the service.", new Object[0]); s0Var.f13686d.add(i0Var); return; } } s0Var.f13684b.d("Initiate binding to the service.", new Object[0]); s0Var.f13686d.add(i0Var); r0 r0Var = new r0(s0Var, null); s0Var.f13694l = r0Var; s0Var.f13689g = true; if (s0Var.f13683a.bindService(s0Var.f13690h, r0Var, 1)) { return; } s0Var.f13684b.d("Failed to bind to the service.", new Object[0]); s0Var.f13689g = false; Iterator it = s0Var.f13686d.iterator(); while (it.hasNext()) { ((i0) it.next()).c(new b()); } s0Var.f13686d.clear(); } static /* bridge */ /* synthetic */ void q(s0 s0Var) { s0Var.f13684b.d("linkToDeath", new Object[0]); try { s0Var.f13695m.asBinder().linkToDeath(s0Var.f13692j, 0); } catch (RemoteException e10) { s0Var.f13684b.c(e10, "linkToDeath failed", new Object[0]); } } static /* bridge */ /* synthetic */ void r(s0 s0Var) { s0Var.f13684b.d("unlinkToDeath", new Object[0]); s0Var.f13695m.asBinder().unlinkToDeath(s0Var.f13692j, 0); } private final RemoteException v() { return new RemoteException(String.valueOf(this.f13685c).concat(" : Binder has died.")); } /* JADX INFO: Access modifiers changed from: private */ public final void w() { Iterator it = this.f13687e.iterator(); while (it.hasNext()) { ((TaskCompletionSource) it.next()).trySetException(v()); } this.f13687e.clear(); } public final Handler c() { Handler handler; Map map = f13682o; synchronized (map) { if (!map.containsKey(this.f13685c)) { HandlerThread handlerThread = new HandlerThread(this.f13685c, 10); handlerThread.start(); map.put(this.f13685c, new Handler(handlerThread.getLooper())); } handler = (Handler) map.get(this.f13685c); } return handler; } public final IInterface e() { return this.f13695m; } public final void s(i0 i0Var, TaskCompletionSource taskCompletionSource) { c().post(new l0(this, i0Var.b(), taskCompletionSource, i0Var)); } final /* synthetic */ void t(TaskCompletionSource taskCompletionSource, Task task) { synchronized (this.f13688f) { this.f13687e.remove(taskCompletionSource); } } public final void u(TaskCompletionSource taskCompletionSource) { synchronized (this.f13688f) { this.f13687e.remove(taskCompletionSource); } c().post(new m0(this)); } }