package androidx.room;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import androidx.room.b;
import androidx.room.c;
import androidx.room.d;
import androidx.room.e;
import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import kotlin.jvm.internal.t;

/* loaded from: classes.dex */
public final class e {

    /* renamed from: a, reason: collision with root package name */
    private final String f5554a;

    /* renamed from: b, reason: collision with root package name */
    private final d f5555b;

    /* renamed from: c, reason: collision with root package name */
    private final Executor f5556c;

    /* renamed from: d, reason: collision with root package name */
    private final Context f5557d;

    /* renamed from: e, reason: collision with root package name */
    private int f5558e;

    /* renamed from: f, reason: collision with root package name */
    public d.c f5559f;

    /* renamed from: g, reason: collision with root package name */
    private androidx.room.c f5560g;

    /* renamed from: h, reason: collision with root package name */
    private final androidx.room.b f5561h;

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

    /* renamed from: j, reason: collision with root package name */
    private final ServiceConnection f5563j;

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

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

    /* loaded from: classes.dex */
    public static final class a extends d.c {
        a(String[] strArr) {
            super(strArr);
        }

        @Override // androidx.room.d.c
        public boolean b() {
            return true;
        }

        @Override // androidx.room.d.c
        public void c(Set tables) {
            t.g(tables, "tables");
            if (e.this.j().get()) {
                return;
            }
            try {
                androidx.room.c h10 = e.this.h();
                if (h10 != null) {
                    h10.N(e.this.c(), (String[]) tables.toArray(new String[0]));
                }
            } catch (RemoteException e10) {
                Log.w("ROOM", "Cannot broadcast invalidation", e10);
            }
        }
    }

    /* loaded from: classes.dex */
    public static final class b extends b.a {
        b() {
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final void W(e this$0, String[] tables) {
            t.g(this$0, "this$0");
            t.g(tables, "$tables");
            this$0.e().m((String[]) Arrays.copyOf(tables, tables.length));
        }

        @Override // androidx.room.b
        public void h(final String[] tables) {
            t.g(tables, "tables");
            Executor d10 = e.this.d();
            final e eVar = e.this;
            d10.execute(new Runnable() { // from class: f5.p
                @Override // java.lang.Runnable
                public final void run() {
                    e.b.W(androidx.room.e.this, tables);
                }
            });
        }
    }

    /* loaded from: classes.dex */
    public static final class c implements ServiceConnection {
        c() {
        }

        @Override // android.content.ServiceConnection
        public void onServiceConnected(ComponentName name, IBinder service) {
            t.g(name, "name");
            t.g(service, "service");
            e.this.m(c.a.U(service));
            e.this.d().execute(e.this.i());
        }

        @Override // android.content.ServiceConnection
        public void onServiceDisconnected(ComponentName name) {
            t.g(name, "name");
            e.this.d().execute(e.this.g());
            e.this.m(null);
        }
    }

    public e(Context context, String name, Intent serviceIntent, d invalidationTracker, Executor executor) {
        t.g(context, "context");
        t.g(name, "name");
        t.g(serviceIntent, "serviceIntent");
        t.g(invalidationTracker, "invalidationTracker");
        t.g(executor, "executor");
        this.f5554a = name;
        this.f5555b = invalidationTracker;
        this.f5556c = executor;
        Context applicationContext = context.getApplicationContext();
        this.f5557d = applicationContext;
        this.f5561h = new b();
        this.f5562i = new AtomicBoolean(false);
        c cVar = new c();
        this.f5563j = cVar;
        this.f5564k = new Runnable() { // from class: f5.n
            @Override // java.lang.Runnable
            public final void run() {
                androidx.room.e.n(androidx.room.e.this);
            }
        };
        this.f5565l = new Runnable() { // from class: f5.o
            @Override // java.lang.Runnable
            public final void run() {
                androidx.room.e.k(androidx.room.e.this);
            }
        };
        l(new a((String[]) invalidationTracker.k().keySet().toArray(new String[0])));
        applicationContext.bindService(serviceIntent, cVar, 1);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void k(e this$0) {
        t.g(this$0, "this$0");
        this$0.f5555b.p(this$0.f());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void n(e this$0) {
        t.g(this$0, "this$0");
        try {
            androidx.room.c cVar = this$0.f5560g;
            if (cVar != null) {
                this$0.f5558e = cVar.k(this$0.f5561h, this$0.f5554a);
                this$0.f5555b.c(this$0.f());
            }
        } catch (RemoteException e10) {
            Log.w("ROOM", "Cannot register multi-instance invalidation callback", e10);
        }
    }

    public final int c() {
        return this.f5558e;
    }

    public final Executor d() {
        return this.f5556c;
    }

    public final d e() {
        return this.f5555b;
    }

    public final d.c f() {
        d.c cVar = this.f5559f;
        if (cVar != null) {
            return cVar;
        }
        t.y("observer");
        return null;
    }

    public final Runnable g() {
        return this.f5565l;
    }

    public final androidx.room.c h() {
        return this.f5560g;
    }

    public final Runnable i() {
        return this.f5564k;
    }

    public final AtomicBoolean j() {
        return this.f5562i;
    }

    public final void l(d.c cVar) {
        t.g(cVar, "<set-?>");
        this.f5559f = cVar;
    }

    public final void m(androidx.room.c cVar) {
        this.f5560g = cVar;
    }
}
