package D2;

import B2.l;
import B2.m;
import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import androidx.window.extensions.layout.FoldingFeature;
import androidx.window.extensions.layout.WindowLayoutInfo;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.o;
import x4.AbstractC3252r;

/* JADX INFO: loaded from: classes.dex */
public abstract class g {
    public static B2.c a(m windowMetrics, FoldingFeature oemFeature) {
        B2.b bVar;
        B2.b bVar2;
        o.h(windowMetrics, "windowMetrics");
        o.h(oemFeature, "oemFeature");
        int type = oemFeature.getType();
        if (type == 1) {
            bVar = B2.b.f458j;
        } else {
            if (type != 2) {
                return null;
            }
            bVar = B2.b.f459k;
        }
        int state = oemFeature.getState();
        if (state == 1) {
            bVar2 = B2.b.f456h;
        } else {
            if (state != 2) {
                return null;
            }
            bVar2 = B2.b.f457i;
        }
        Rect bounds = oemFeature.getBounds();
        o.g(bounds, "getBounds(...)");
        z2.b bVar3 = new z2.b(bounds);
        Rect rectC = windowMetrics.f484a.c();
        if (bVar3.a() == 0 && bVar3.b() == 0) {
            return null;
        }
        if (bVar3.b() != rectC.width() && bVar3.a() != rectC.height()) {
            return null;
        }
        if (bVar3.b() < rectC.width() && bVar3.a() < rectC.height()) {
            return null;
        }
        if (bVar3.b() == rectC.width() && bVar3.a() == rectC.height()) {
            return null;
        }
        Rect bounds2 = oemFeature.getBounds();
        o.g(bounds2, "getBounds(...)");
        return new B2.c(new z2.b(bounds2), bVar, bVar2);
    }

    public static l b(m windowMetrics, WindowLayoutInfo info) {
        o.h(windowMetrics, "windowMetrics");
        o.h(info, "info");
        List<FoldingFeature> displayFeatures = info.getDisplayFeatures();
        o.g(displayFeatures, "getDisplayFeatures(...)");
        ArrayList arrayList = new ArrayList();
        for (FoldingFeature foldingFeature : displayFeatures) {
            B2.c cVarA = foldingFeature instanceof FoldingFeature ? a(windowMetrics, foldingFeature) : null;
            if (cVarA != null) {
                arrayList.add(cVarA);
            }
        }
        return new l(arrayList);
    }

    public static l c(Context context, WindowLayoutInfo info) {
        o.h(info, "info");
        int i6 = Build.VERSION.SDK_INT;
        F2.e eVar = i6 >= 34 ? F2.f.f1488b : F2.c.f1483f;
        AbstractC3252r.x(1, 2, 4, 8, 16, 32, 64, 128);
        F2.g gVar = F2.c.f1484g;
        F2.d dVar = F2.d.f1487c;
        F2.f fVar = F2.f.f1489c;
        if (i6 >= 30) {
            if (i6 >= 34) {
                gVar = fVar;
            } else if (i6 >= 30) {
                gVar = dVar;
            }
            return b(gVar.d(context, eVar), info);
        }
        if (i6 < 29 || !(context instanceof Activity)) {
            throw new UnsupportedOperationException("Display Features are only supported after Q. Display features for non-Activity contexts are not expected to be reported on devices running Q.");
        }
        Activity activity = (Activity) context;
        if (i6 >= 34) {
            gVar = fVar;
        } else if (i6 >= 30) {
            gVar = dVar;
        }
        return b(gVar.b(activity, eVar), info);
    }
}
