package androidx.room;

import androidx.lifecycle.a0;
import androidx.room.d;
import f5.l;
import f5.r;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import kotlin.jvm.internal.t;

/* loaded from: classes.dex */
public final class f extends a0 {

    /* renamed from: l, reason: collision with root package name */
    private final r f5569l;

    /* renamed from: m, reason: collision with root package name */
    private final l f5570m;

    /* renamed from: n, reason: collision with root package name */
    private final boolean f5571n;

    /* renamed from: o, reason: collision with root package name */
    private final Callable f5572o;

    /* renamed from: p, reason: collision with root package name */
    private final d.c f5573p;

    /* renamed from: q, reason: collision with root package name */
    private final AtomicBoolean f5574q;

    /* renamed from: r, reason: collision with root package name */
    private final AtomicBoolean f5575r;

    /* renamed from: s, reason: collision with root package name */
    private final AtomicBoolean f5576s;

    /* renamed from: t, reason: collision with root package name */
    private final Runnable f5577t;

    /* renamed from: u, reason: collision with root package name */
    private final Runnable f5578u;

    /* loaded from: classes.dex */
    public static final class a extends d.c {

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ f f5579b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(String[] strArr, f fVar) {
            super(strArr);
            this.f5579b = fVar;
        }

        @Override // androidx.room.d.c
        public void c(Set tables) {
            t.g(tables, "tables");
            p.c.h().b(this.f5579b.t());
        }
    }

    public f(r database, l container, boolean z10, Callable computeFunction, String[] tableNames) {
        t.g(database, "database");
        t.g(container, "container");
        t.g(computeFunction, "computeFunction");
        t.g(tableNames, "tableNames");
        this.f5569l = database;
        this.f5570m = container;
        this.f5571n = z10;
        this.f5572o = computeFunction;
        this.f5573p = new a(tableNames, this);
        this.f5574q = new AtomicBoolean(true);
        this.f5575r = new AtomicBoolean(false);
        this.f5576s = new AtomicBoolean(false);
        this.f5577t = new Runnable() { // from class: f5.v
            @Override // java.lang.Runnable
            public final void run() {
                androidx.room.f.w(androidx.room.f.this);
            }
        };
        this.f5578u = new Runnable() { // from class: f5.w
            @Override // java.lang.Runnable
            public final void run() {
                androidx.room.f.v(androidx.room.f.this);
            }
        };
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void v(f this$0) {
        t.g(this$0, "this$0");
        boolean h10 = this$0.h();
        if (this$0.f5574q.compareAndSet(false, true) && h10) {
            this$0.u().execute(this$0.f5577t);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void w(f this$0) {
        boolean z10;
        t.g(this$0, "this$0");
        if (this$0.f5576s.compareAndSet(false, true)) {
            this$0.f5569l.m().d(this$0.f5573p);
        }
        do {
            if (this$0.f5575r.compareAndSet(false, true)) {
                Object obj = null;
                z10 = false;
                while (this$0.f5574q.compareAndSet(true, false)) {
                    try {
                        try {
                            obj = this$0.f5572o.call();
                            z10 = true;
                        } catch (Exception e10) {
                            throw new RuntimeException("Exception while computing database live data.", e10);
                        }
                    } finally {
                        this$0.f5575r.set(false);
                    }
                }
                if (z10) {
                    this$0.n(obj);
                }
            } else {
                z10 = false;
            }
            if (!z10) {
                return;
            }
        } while (this$0.f5574q.get());
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.a0
    public void l() {
        super.l();
        l lVar = this.f5570m;
        t.e(this, "null cannot be cast to non-null type androidx.lifecycle.LiveData<kotlin.Any>");
        lVar.b(this);
        u().execute(this.f5577t);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.a0
    public void m() {
        super.m();
        l lVar = this.f5570m;
        t.e(this, "null cannot be cast to non-null type androidx.lifecycle.LiveData<kotlin.Any>");
        lVar.c(this);
    }

    public final Runnable t() {
        return this.f5578u;
    }

    public final Executor u() {
        return this.f5571n ? this.f5569l.r() : this.f5569l.o();
    }
}
