package androidx.lifecycle; import androidx.lifecycle.e; import java.util.Map; import k.b; /* loaded from: classes.dex */ public abstract class LiveData { /* renamed from: k, reason: collision with root package name */ static final Object f2038k = new Object(); /* renamed from: a, reason: collision with root package name */ final Object f2039a = new Object(); /* renamed from: b, reason: collision with root package name */ private k.b f2040b = new k.b(); /* renamed from: c, reason: collision with root package name */ int f2041c = 0; /* renamed from: d, reason: collision with root package name */ private boolean f2042d; /* renamed from: e, reason: collision with root package name */ private volatile Object f2043e; /* renamed from: f, reason: collision with root package name */ volatile Object f2044f; /* renamed from: g, reason: collision with root package name */ private int f2045g; /* renamed from: h, reason: collision with root package name */ private boolean f2046h; /* renamed from: i, reason: collision with root package name */ private boolean f2047i; /* renamed from: j, reason: collision with root package name */ private final Runnable f2048j; class LifecycleBoundObserver extends androidx.lifecycle.LiveData.c implements g { /* renamed from: e, reason: collision with root package name */ final LifecycleOwner f2049e; LifecycleBoundObserver(LifecycleOwner lifecycleOwner, Observer observer) { super(observer); this.f2049e = lifecycleOwner; } void b() { this.f2049e.getLifecycle().c(this); } boolean c(LifecycleOwner lifecycleOwner) { return this.f2049e == lifecycleOwner; } boolean d() { return this.f2049e.getLifecycle().b().a(e.c.STARTED); } @Override // androidx.lifecycle.g public void onStateChanged(LifecycleOwner lifecycleOwner, e.b bVar) { e.c b10 = this.f2049e.getLifecycle().b(); if (b10 == e.c.DESTROYED) { LiveData.this.m(this.f2053a); return; } e.c cVar = null; while (cVar != b10) { a(d()); cVar = b10; b10 = this.f2049e.getLifecycle().b(); } } } class a implements Runnable { a() { } @Override // java.lang.Runnable public void run() { Object obj; synchronized (LiveData.this.f2039a) { obj = LiveData.this.f2044f; LiveData.this.f2044f = LiveData.f2038k; } LiveData.this.n(obj); } } private class b extends c { b(Observer observer) { super(observer); } @Override // androidx.lifecycle.LiveData.c boolean d() { return true; } } private abstract class c { /* renamed from: a, reason: collision with root package name */ final Observer f2053a; /* renamed from: b, reason: collision with root package name */ boolean f2054b; /* renamed from: c, reason: collision with root package name */ int f2055c = -1; c(Observer observer) { this.f2053a = observer; } void a(boolean z10) { if (z10 == this.f2054b) { return; } this.f2054b = z10; LiveData.this.c(z10 ? 1 : -1); if (this.f2054b) { LiveData.this.e(this); } } void b() { } boolean c(LifecycleOwner lifecycleOwner) { return false; } abstract boolean d(); } public LiveData() { Object obj = f2038k; this.f2044f = obj; this.f2048j = new a(); this.f2043e = obj; this.f2045g = -1; } static void b(String str) { if (j.a.e().b()) { return; } throw new IllegalStateException("Cannot invoke " + str + " on a background thread"); } private void d(c cVar) { if (cVar.f2054b) { if (!cVar.d()) { cVar.a(false); return; } int i10 = cVar.f2055c; int i11 = this.f2045g; if (i10 >= i11) { return; } cVar.f2055c = i11; cVar.f2053a.onChanged(this.f2043e); } } void c(int i10) { int i11 = this.f2041c; this.f2041c = i10 + i11; if (this.f2042d) { return; } this.f2042d = true; while (true) { try { int i12 = this.f2041c; if (i11 == i12) { return; } boolean z10 = i11 == 0 && i12 > 0; boolean z11 = i11 > 0 && i12 == 0; if (z10) { j(); } else if (z11) { k(); } i11 = i12; } finally { this.f2042d = false; } } } void e(c cVar) { if (this.f2046h) { this.f2047i = true; return; } this.f2046h = true; do { this.f2047i = false; if (cVar != null) { d(cVar); cVar = null; } else { b.d c10 = this.f2040b.c(); while (c10.hasNext()) { d((c) ((Map.Entry) c10.next()).getValue()); if (this.f2047i) { break; } } } } while (this.f2047i); this.f2046h = false; } public Object f() { Object obj = this.f2043e; if (obj != f2038k) { return obj; } return null; } public boolean g() { return this.f2041c > 0; } public void h(LifecycleOwner lifecycleOwner, Observer observer) { b("observe"); if (lifecycleOwner.getLifecycle().b() == e.c.DESTROYED) { return; } LifecycleBoundObserver lifecycleBoundObserver = new LifecycleBoundObserver(lifecycleOwner, observer); c cVar = (c) this.f2040b.f(observer, lifecycleBoundObserver); if (cVar != null && !cVar.c(lifecycleOwner)) { throw new IllegalArgumentException("Cannot add the same observer with different lifecycles"); } if (cVar != null) { return; } lifecycleOwner.getLifecycle().a(lifecycleBoundObserver); } public void i(Observer observer) { b("observeForever"); b bVar = new b(observer); c cVar = (c) this.f2040b.f(observer, bVar); if (cVar instanceof LifecycleBoundObserver) { throw new IllegalArgumentException("Cannot add the same observer with different lifecycles"); } if (cVar != null) { return; } bVar.a(true); } protected void j() { } protected void k() { } protected void l(Object obj) { boolean z10; synchronized (this.f2039a) { z10 = this.f2044f == f2038k; this.f2044f = obj; } if (z10) { j.a.e().c(this.f2048j); } } public void m(Observer observer) { b("removeObserver"); c cVar = (c) this.f2040b.g(observer); if (cVar == null) { return; } cVar.b(); cVar.a(false); } protected void n(Object obj) { b("setValue"); this.f2045g++; this.f2043e = obj; e(null); } }