package d.h.j;

import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowInsets;
import d.h.j.y;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class h0 {
    public static final h0 a;

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

    @SuppressLint({"SoonBlockedPrivateApi"})
    public static class a {
        public static Field a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static Field f2737b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static Field f2738c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static boolean f2739d;

        static {
            try {
                Field declaredField = View.class.getDeclaredField("mAttachInfo");
                a = declaredField;
                declaredField.setAccessible(true);
                Class<?> cls = Class.forName("android.view.View$AttachInfo");
                Field declaredField2 = cls.getDeclaredField("mStableInsets");
                f2737b = declaredField2;
                declaredField2.setAccessible(true);
                Field declaredField3 = cls.getDeclaredField("mContentInsets");
                f2738c = declaredField3;
                declaredField3.setAccessible(true);
                f2739d = true;
            } catch (ReflectiveOperationException e2) {
                StringBuilder sbF = g.a.a.a.a.F("Failed to get visible insets from AttachInfo ");
                sbF.append(e2.getMessage());
                Log.w("WindowInsetsCompat", sbF.toString(), e2);
            }
        }
    }

    public static class b extends e {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static Field f2740b = null;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static boolean f2741c = false;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static Constructor<WindowInsets> f2742d = null;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public static boolean f2743e = false;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public WindowInsets f2744f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public d.h.d.b f2745g;

        public b() {
            this.f2744f = e();
        }

        public b(h0 h0Var) {
            super(h0Var);
            this.f2744f = h0Var.g();
        }

        public static WindowInsets e() {
            if (!f2741c) {
                try {
                    f2740b = WindowInsets.class.getDeclaredField("CONSUMED");
                } catch (ReflectiveOperationException e2) {
                    Log.i("WindowInsetsCompat", "Could not retrieve WindowInsets.CONSUMED field", e2);
                }
                f2741c = true;
            }
            Field field = f2740b;
            if (field != null) {
                try {
                    WindowInsets windowInsets = (WindowInsets) field.get(null);
                    if (windowInsets != null) {
                        return new WindowInsets(windowInsets);
                    }
                } catch (ReflectiveOperationException e3) {
                    Log.i("WindowInsetsCompat", "Could not get value from WindowInsets.CONSUMED field", e3);
                }
            }
            if (!f2743e) {
                try {
                    f2742d = WindowInsets.class.getConstructor(Rect.class);
                } catch (ReflectiveOperationException e4) {
                    Log.i("WindowInsetsCompat", "Could not retrieve WindowInsets(Rect) constructor", e4);
                }
                f2743e = true;
            }
            Constructor<WindowInsets> constructor = f2742d;
            if (constructor != null) {
                try {
                    return constructor.newInstance(new Rect());
                } catch (ReflectiveOperationException e5) {
                    Log.i("WindowInsetsCompat", "Could not invoke WindowInsets(Rect) constructor", e5);
                }
            }
            return null;
        }

        @Override // d.h.j.h0.e
        public h0 b() {
            a();
            h0 h0VarH = h0.h(this.f2744f);
            h0VarH.f2736b.l(null);
            h0VarH.f2736b.n(this.f2745g);
            return h0VarH;
        }

        @Override // d.h.j.h0.e
        public void c(d.h.d.b bVar) {
            this.f2745g = bVar;
        }

        @Override // d.h.j.h0.e
        public void d(d.h.d.b bVar) {
            WindowInsets windowInsets = this.f2744f;
            if (windowInsets != null) {
                this.f2744f = windowInsets.replaceSystemWindowInsets(bVar.f2648b, bVar.f2649c, bVar.f2650d, bVar.f2651e);
            }
        }
    }

    public static class c extends e {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final WindowInsets.Builder f2746b;

        public c() {
            this.f2746b = new WindowInsets.Builder();
        }

        public c(h0 h0Var) {
            super(h0Var);
            WindowInsets windowInsetsG = h0Var.g();
            this.f2746b = windowInsetsG != null ? new WindowInsets.Builder(windowInsetsG) : new WindowInsets.Builder();
        }

        @Override // d.h.j.h0.e
        public h0 b() {
            a();
            h0 h0VarH = h0.h(this.f2746b.build());
            h0VarH.f2736b.l(null);
            return h0VarH;
        }

        @Override // d.h.j.h0.e
        public void c(d.h.d.b bVar) {
            this.f2746b.setStableInsets(bVar.c());
        }

        @Override // d.h.j.h0.e
        public void d(d.h.d.b bVar) {
            this.f2746b.setSystemWindowInsets(bVar.c());
        }
    }

    public static class d extends c {
        public d() {
        }

        public d(h0 h0Var) {
            super(h0Var);
        }
    }

    public static class e {
        public final h0 a;

        public e() {
            this(new h0((h0) null));
        }

        public e(h0 h0Var) {
            this.a = h0Var;
        }

        public final void a() {
        }

        public h0 b() {
            throw null;
        }

        public void c(d.h.d.b bVar) {
            throw null;
        }

        public void d(d.h.d.b bVar) {
            throw null;
        }
    }

    public static class f extends k {

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static boolean f2747c = false;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static Method f2748d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public static Class<?> f2749e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public static Field f2750f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public static Field f2751g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public final WindowInsets f2752h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public d.h.d.b[] f2753i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        public d.h.d.b f2754j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        public h0 f2755k;

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        public d.h.d.b f2756l;

        public f(h0 h0Var, WindowInsets windowInsets) {
            super(h0Var);
            this.f2754j = null;
            this.f2752h = windowInsets;
        }

        @SuppressLint({"PrivateApi"})
        public static void p() {
            try {
                f2748d = View.class.getDeclaredMethod("getViewRootImpl", new Class[0]);
                Class<?> cls = Class.forName("android.view.View$AttachInfo");
                f2749e = cls;
                f2750f = cls.getDeclaredField("mVisibleInsets");
                f2751g = Class.forName("android.view.ViewRootImpl").getDeclaredField("mAttachInfo");
                f2750f.setAccessible(true);
                f2751g.setAccessible(true);
            } catch (ReflectiveOperationException e2) {
                StringBuilder sbF = g.a.a.a.a.F("Failed to get visible insets. (Reflection error). ");
                sbF.append(e2.getMessage());
                Log.e("WindowInsetsCompat", sbF.toString(), e2);
            }
            f2747c = true;
        }

        @Override // d.h.j.h0.k
        public void d(View view) {
            d.h.d.b bVarO = o(view);
            if (bVarO == null) {
                bVarO = d.h.d.b.a;
            }
            q(bVarO);
        }

        @Override // d.h.j.h0.k
        public boolean equals(Object obj) {
            if (super.equals(obj)) {
                return Objects.equals(this.f2756l, ((f) obj).f2756l);
            }
            return false;
        }

        @Override // d.h.j.h0.k
        public final d.h.d.b h() {
            if (this.f2754j == null) {
                this.f2754j = d.h.d.b.a(this.f2752h.getSystemWindowInsetLeft(), this.f2752h.getSystemWindowInsetTop(), this.f2752h.getSystemWindowInsetRight(), this.f2752h.getSystemWindowInsetBottom());
            }
            return this.f2754j;
        }

        @Override // d.h.j.h0.k
        public h0 i(int i2, int i3, int i4, int i5) {
            h0 h0VarH = h0.h(this.f2752h);
            int i6 = Build.VERSION.SDK_INT;
            e dVar = i6 >= 30 ? new d(h0VarH) : i6 >= 29 ? new c(h0VarH) : new b(h0VarH);
            dVar.d(h0.e(h(), i2, i3, i4, i5));
            dVar.c(h0.e(g(), i2, i3, i4, i5));
            return dVar.b();
        }

        @Override // d.h.j.h0.k
        public boolean k() {
            return this.f2752h.isRound();
        }

        @Override // d.h.j.h0.k
        public void l(d.h.d.b[] bVarArr) {
            this.f2753i = bVarArr;
        }

        @Override // d.h.j.h0.k
        public void m(h0 h0Var) {
            this.f2755k = h0Var;
        }

        public final d.h.d.b o(View view) {
            if (Build.VERSION.SDK_INT >= 30) {
                throw new UnsupportedOperationException("getVisibleInsets() should not be called on API >= 30. Use WindowInsets.isVisible() instead.");
            }
            if (!f2747c) {
                p();
            }
            Method method = f2748d;
            if (method != null && f2749e != null && f2750f != null) {
                try {
                    Object objInvoke = method.invoke(view, new Object[0]);
                    if (objInvoke == null) {
                        Log.w("WindowInsetsCompat", "Failed to get visible insets. getViewRootImpl() returned null from the provided view. This means that the view is either not attached or the method has been overridden", new NullPointerException());
                        return null;
                    }
                    Rect rect = (Rect) f2750f.get(f2751g.get(objInvoke));
                    if (rect != null) {
                        return d.h.d.b.a(rect.left, rect.top, rect.right, rect.bottom);
                    }
                    return null;
                } catch (ReflectiveOperationException e2) {
                    StringBuilder sbF = g.a.a.a.a.F("Failed to get visible insets. (Reflection error). ");
                    sbF.append(e2.getMessage());
                    Log.e("WindowInsetsCompat", sbF.toString(), e2);
                }
            }
            return null;
        }

        public void q(d.h.d.b bVar) {
            this.f2756l = bVar;
        }
    }

    public static class g extends f {

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public d.h.d.b f2757m;

        public g(h0 h0Var, WindowInsets windowInsets) {
            super(h0Var, windowInsets);
            this.f2757m = null;
        }

        @Override // d.h.j.h0.k
        public h0 b() {
            return h0.h(this.f2752h.consumeStableInsets());
        }

        @Override // d.h.j.h0.k
        public h0 c() {
            return h0.h(this.f2752h.consumeSystemWindowInsets());
        }

        @Override // d.h.j.h0.k
        public final d.h.d.b g() {
            if (this.f2757m == null) {
                this.f2757m = d.h.d.b.a(this.f2752h.getStableInsetLeft(), this.f2752h.getStableInsetTop(), this.f2752h.getStableInsetRight(), this.f2752h.getStableInsetBottom());
            }
            return this.f2757m;
        }

        @Override // d.h.j.h0.k
        public boolean j() {
            return this.f2752h.isConsumed();
        }

        @Override // d.h.j.h0.k
        public void n(d.h.d.b bVar) {
            this.f2757m = bVar;
        }
    }

    public static class h extends g {
        public h(h0 h0Var, WindowInsets windowInsets) {
            super(h0Var, windowInsets);
        }

        @Override // d.h.j.h0.k
        public h0 a() {
            return h0.h(this.f2752h.consumeDisplayCutout());
        }

        @Override // d.h.j.h0.k
        public d.h.j.g e() {
            DisplayCutout displayCutout = this.f2752h.getDisplayCutout();
            if (displayCutout == null) {
                return null;
            }
            return new d.h.j.g(displayCutout);
        }

        @Override // d.h.j.h0.f, d.h.j.h0.k
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof h)) {
                return false;
            }
            h hVar = (h) obj;
            return Objects.equals(this.f2752h, hVar.f2752h) && Objects.equals(this.f2756l, hVar.f2756l);
        }

        @Override // d.h.j.h0.k
        public int hashCode() {
            return this.f2752h.hashCode();
        }
    }

    public static class i extends h {

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public d.h.d.b f2758n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public d.h.d.b f2759o;

        /* JADX INFO: renamed from: p, reason: collision with root package name */
        public d.h.d.b f2760p;

        public i(h0 h0Var, WindowInsets windowInsets) {
            super(h0Var, windowInsets);
            this.f2758n = null;
            this.f2759o = null;
            this.f2760p = null;
        }

        @Override // d.h.j.h0.k
        public d.h.d.b f() {
            if (this.f2759o == null) {
                this.f2759o = d.h.d.b.b(this.f2752h.getMandatorySystemGestureInsets());
            }
            return this.f2759o;
        }

        @Override // d.h.j.h0.f, d.h.j.h0.k
        public h0 i(int i2, int i3, int i4, int i5) {
            return h0.h(this.f2752h.inset(i2, i3, i4, i5));
        }

        @Override // d.h.j.h0.g, d.h.j.h0.k
        public void n(d.h.d.b bVar) {
        }
    }

    public static class j extends i {

        /* JADX INFO: renamed from: q, reason: collision with root package name */
        public static final h0 f2761q = h0.h(WindowInsets.CONSUMED);

        public j(h0 h0Var, WindowInsets windowInsets) {
            super(h0Var, windowInsets);
        }

        @Override // d.h.j.h0.f, d.h.j.h0.k
        public final void d(View view) {
        }
    }

    public static class k {
        public static final h0 a;

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

        static {
            int i2 = Build.VERSION.SDK_INT;
            a = (i2 >= 30 ? new d() : i2 >= 29 ? new c() : new b()).b().f2736b.a().f2736b.b().f2736b.c();
        }

        public k(h0 h0Var) {
            this.f2762b = h0Var;
        }

        public h0 a() {
            return this.f2762b;
        }

        public h0 b() {
            return this.f2762b;
        }

        public h0 c() {
            return this.f2762b;
        }

        public void d(View view) {
        }

        public d.h.j.g e() {
            return null;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof k)) {
                return false;
            }
            k kVar = (k) obj;
            return k() == kVar.k() && j() == kVar.j() && d.h.i.b.a(h(), kVar.h()) && d.h.i.b.a(g(), kVar.g()) && d.h.i.b.a(e(), kVar.e());
        }

        public d.h.d.b f() {
            return h();
        }

        public d.h.d.b g() {
            return d.h.d.b.a;
        }

        public d.h.d.b h() {
            return d.h.d.b.a;
        }

        public int hashCode() {
            return d.h.i.b.b(Boolean.valueOf(k()), Boolean.valueOf(j()), h(), g(), e());
        }

        public h0 i(int i2, int i3, int i4, int i5) {
            return a;
        }

        public boolean j() {
            return false;
        }

        public boolean k() {
            return false;
        }

        public void l(d.h.d.b[] bVarArr) {
        }

        public void m(h0 h0Var) {
        }

        public void n(d.h.d.b bVar) {
        }
    }

    static {
        a = Build.VERSION.SDK_INT >= 30 ? j.f2761q : k.a;
    }

    public h0(WindowInsets windowInsets) {
        int i2 = Build.VERSION.SDK_INT;
        this.f2736b = i2 >= 30 ? new j(this, windowInsets) : i2 >= 29 ? new i(this, windowInsets) : i2 >= 28 ? new h(this, windowInsets) : new g(this, windowInsets);
    }

    public h0(h0 h0Var) {
        this.f2736b = new k(this);
    }

    public static d.h.d.b e(d.h.d.b bVar, int i2, int i3, int i4, int i5) {
        int iMax = Math.max(0, bVar.f2648b - i2);
        int iMax2 = Math.max(0, bVar.f2649c - i3);
        int iMax3 = Math.max(0, bVar.f2650d - i4);
        int iMax4 = Math.max(0, bVar.f2651e - i5);
        return (iMax == i2 && iMax2 == i3 && iMax3 == i4 && iMax4 == i5) ? bVar : d.h.d.b.a(iMax, iMax2, iMax3, iMax4);
    }

    public static h0 h(WindowInsets windowInsets) {
        return i(windowInsets, null);
    }

    public static h0 i(WindowInsets windowInsets, View view) {
        Objects.requireNonNull(windowInsets);
        h0 h0Var = new h0(windowInsets);
        if (view != null) {
            AtomicInteger atomicInteger = y.a;
            if (y.f.b(view)) {
                h0Var.f2736b.m(y.i.a(view));
                h0Var.f2736b.d(view.getRootView());
            }
        }
        return h0Var;
    }

    @Deprecated
    public int a() {
        return this.f2736b.h().f2651e;
    }

    @Deprecated
    public int b() {
        return this.f2736b.h().f2648b;
    }

    @Deprecated
    public int c() {
        return this.f2736b.h().f2650d;
    }

    @Deprecated
    public int d() {
        return this.f2736b.h().f2649c;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof h0) {
            return d.h.i.b.a(this.f2736b, ((h0) obj).f2736b);
        }
        return false;
    }

    public boolean f() {
        return this.f2736b.j();
    }

    public WindowInsets g() {
        k kVar = this.f2736b;
        if (kVar instanceof f) {
            return ((f) kVar).f2752h;
        }
        return null;
    }

    public int hashCode() {
        k kVar = this.f2736b;
        if (kVar == null) {
            return 0;
        }
        return kVar.hashCode();
    }
}
