package k4;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.work.u;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import l4.e;
import m4.h;

/* JADX INFO: loaded from: classes.dex */
public final class d implements l4.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final l4.c[] f29066a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f29067b;

    @Nullable
    private final c mCallback;

    static {
        u.e("WorkConstraintsTracker");
    }

    public d(@NonNull Context context, @NonNull p4.a aVar, @Nullable c cVar) {
        Context applicationContext = context.getApplicationContext();
        this.mCallback = cVar;
        this.f29066a = new l4.c[]{new l4.a(applicationContext, aVar, 0), new l4.a(applicationContext, aVar, 1), new l4.a(applicationContext, aVar, 4), new l4.a(applicationContext, aVar, 2), new l4.a(applicationContext, aVar, 3), new e(h.a(applicationContext, aVar).f30378c), new l4.d(h.a(applicationContext, aVar).f30378c)};
        this.f29067b = new Object();
    }

    public final boolean a(String str) {
        synchronized (this.f29067b) {
            try {
                for (l4.c cVar : this.f29066a) {
                    Object obj = cVar.f30114b;
                    if (obj != null && cVar.b(obj) && cVar.f30113a.contains(str)) {
                        u uVarC = u.c();
                        String.format("Work %s constrained by %s", str, cVar.getClass().getSimpleName());
                        uVarC.a(new Throwable[0]);
                        return false;
                    }
                }
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void b(ArrayList arrayList) {
        synchronized (this.f29067b) {
            try {
                ArrayList arrayList2 = new ArrayList();
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    String str = (String) it.next();
                    if (a(str)) {
                        u uVarC = u.c();
                        String.format("Constraints met for %s", str);
                        uVarC.a(new Throwable[0]);
                        arrayList2.add(str);
                    }
                }
                c cVar = this.mCallback;
                if (cVar != null) {
                    cVar.e(arrayList2);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void c(ArrayList arrayList) {
        synchronized (this.f29067b) {
            c cVar = this.mCallback;
            if (cVar != null) {
                cVar.d(arrayList);
            }
        }
    }

    public final void d(Collection collection) {
        synchronized (this.f29067b) {
            try {
                for (l4.c cVar : this.f29066a) {
                    cVar.setCallback(null);
                }
                for (l4.c cVar2 : this.f29066a) {
                    cVar2.c(collection);
                }
                for (l4.c cVar3 : this.f29066a) {
                    cVar3.setCallback(this);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void e() {
        synchronized (this.f29067b) {
            try {
                for (l4.c cVar : this.f29066a) {
                    ArrayList arrayList = cVar.f30113a;
                    if (!arrayList.isEmpty()) {
                        arrayList.clear();
                        cVar.f30115c.b(cVar);
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @VisibleForTesting
    public d(@Nullable c cVar, l4.c[] cVarArr) {
        this.mCallback = cVar;
        this.f29066a = cVarArr;
        this.f29067b = new Object();
    }
}
