package e3; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.util.Log; import e.g1; import e.m0; import e.o0; import e.z; import h3.f; import j3.d; import j3.e; import java.io.IOException; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; /* compiled from: AutoCloser */ public final class a { @o0 /* renamed from: a reason: collision with root package name */ public e f54346a = null; @m0 /* renamed from: b reason: collision with root package name */ public final Handler f54347b = new Handler(Looper.getMainLooper()); @o0 /* renamed from: c reason: collision with root package name */ public Runnable f54348c = null; @m0 /* renamed from: d reason: collision with root package name */ public final Object f54349d = new Object(); /* renamed from: e reason: collision with root package name */ public final long f54350e; @m0 /* renamed from: f reason: collision with root package name */ public final Executor f54351f; @z("mLock") /* renamed from: g reason: collision with root package name */ public int f54352g = 0; @z("mLock") /* renamed from: h reason: collision with root package name */ public long f54353h = SystemClock.uptimeMillis(); @o0 @z("mLock") /* renamed from: i reason: collision with root package name */ public d f54354i; /* renamed from: j reason: collision with root package name */ public boolean f54355j = false; /* renamed from: k reason: collision with root package name */ public final Runnable f54356k = new RunnableC0441a(); @m0 /* renamed from: l reason: collision with root package name */ public final Runnable f54357l = new b(); /* renamed from: e3.a$a reason: collision with other inner class name */ /* compiled from: AutoCloser */ public class RunnableC0441a implements Runnable { public RunnableC0441a() { } public void run() { a aVar = a.this; aVar.f54351f.execute(aVar.f54357l); } } /* compiled from: AutoCloser */ public class b implements Runnable { public b() { } public void run() { synchronized (a.this.f54349d) { long uptimeMillis = SystemClock.uptimeMillis(); a aVar = a.this; if (uptimeMillis - aVar.f54353h >= aVar.f54350e) { if (aVar.f54352g == 0) { Runnable runnable = aVar.f54348c; if (runnable != null) { runnable.run(); d dVar = a.this.f54354i; if (dVar != null && dVar.isOpen()) { try { a.this.f54354i.close(); } catch (IOException e10) { f.a(e10); } a.this.f54354i = null; } return; } throw new IllegalStateException("mOnAutoCloseCallback is null but it should have been set before use. Please file a bug against Room at: https://issuetracker.google.com/issues/new?component=413107&template=1096568"); } } } } } public a(long j10, @m0 TimeUnit timeUnit, @m0 Executor executor) { this.f54350e = timeUnit.toMillis(j10); this.f54351f = executor; } public void a() throws IOException { synchronized (this.f54349d) { this.f54355j = true; d dVar = this.f54354i; if (dVar != null) { dVar.close(); } this.f54354i = null; } } public void b() { synchronized (this.f54349d) { int i10 = this.f54352g; if (i10 > 0) { int i11 = i10 - 1; this.f54352g = i11; if (i11 == 0) { if (this.f54354i != null) { this.f54347b.postDelayed(this.f54356k, this.f54350e); } else { return; } } return; } throw new IllegalStateException("ref count is 0 or lower but we're supposed to decrement"); } } @o0 public <V> V c(@m0 p.a<d, V> aVar) { try { return aVar.apply(f()); } finally { b(); } } @o0 public d d() { d dVar; synchronized (this.f54349d) { dVar = this.f54354i; } return dVar; } @g1 public int e() { int i10; synchronized (this.f54349d) { i10 = this.f54352g; } return i10; } @m0 public d f() { synchronized (this.f54349d) { this.f54347b.removeCallbacks(this.f54356k); this.f54352g++; if (!this.f54355j) { d dVar = this.f54354i; if (dVar == null || !dVar.isOpen()) { e eVar = this.f54346a; if (eVar != null) { d writableDatabase = eVar.getWritableDatabase(); this.f54354i = writableDatabase; return writableDatabase; } throw new IllegalStateException("AutoCloser has not been initialized. Please file a bug against Room at: https://issuetracker.google.com/issues/new?component=413107&template=1096568"); } return this.f54354i; } throw new IllegalStateException("Attempting to open already closed database."); } } public void g(@m0 e eVar) { if (this.f54346a != null) { Log.e(p2.f54453a, "AutoCloser initialized multiple times. Please file a bug against room at: https://issuetracker.google.com/issues/new?component=413107&template=1096568"); } else { this.f54346a = eVar; } } public boolean h() { return !this.f54355j; } public void i(Runnable runnable) { this.f54348c = runnable; } }