package io.flutter.embedding.android;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.DisplayCutout;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewStructure;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeProvider;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.textservice.SpellCheckerSession;
import android.view.textservice.TextServicesManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.measurement.internal.u1;
import com.google.firebase.messaging.Constants$ScionAnalytics$MessageType;
import io.flutter.embedding.android.FlutterImageView;
import io.flutter.embedding.engine.FlutterJNI;
import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorView;
import io.flutter.embedding.engine.renderer.FlutterRenderer$DisplayFeatureState;
import io.flutter.embedding.engine.renderer.FlutterRenderer$DisplayFeatureType;
import io.flutter.embedding.engine.systemchannels.SettingsChannel$PlatformBrightness;
import io.flutter.plugin.platform.PlatformOverlayView;
import io.flutter.plugin.platform.PlatformViewWrapper;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.locks.ReentrantLock;
import kotlinx.coroutines.y0;

/* JADX INFO: loaded from: classes.dex */
public class FlutterView extends FrameLayout implements io.flutter.plugin.mouse.a, b0 {

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final /* synthetic */ int f27855j = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashSet f27856a;

    @Nullable
    private io.flutter.view.j accessibilityBridge;

    @Nullable
    private b androidTouchProcessor;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f27857b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final HashSet f27858c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final io.flutter.embedding.engine.renderer.i f27859d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final s f27860e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final v0.a f27861f;

    @Nullable
    private xc.c flutterEngine;

    @Nullable
    private FlutterImageView flutterImageView;

    @Nullable
    private FlutterSurfaceView flutterSurfaceView;

    @Nullable
    private FlutterTextureView flutterTextureView;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final f f27862g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public androidx.fragment.app.g0 f27863h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public u f27864i;

    @Nullable
    private c0 keyboardManager;

    @Nullable
    private fd.b localizationPlugin;

    @Nullable
    private io.flutter.plugin.mouse.b mouseCursorPlugin;

    @Nullable
    private io.flutter.embedding.engine.renderer.l previousRenderSurface;

    @Nullable
    @VisibleForTesting
    io.flutter.embedding.engine.renderer.l renderSurface;

    @Nullable
    private io.flutter.plugin.editing.h scribePlugin;

    @Nullable
    private io.flutter.plugin.editing.i spellCheckPlugin;

    @Nullable
    private io.flutter.plugin.editing.m textInputPlugin;

    @Nullable
    private TextServicesManager textServicesManager;

    @Nullable
    private h0 windowInfoRepo;

    /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
    /* JADX WARN: Unknown enum class pattern. Please report as an issue! */
    @VisibleForTesting
    public static final class ZeroSides {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public static final ZeroSides f27865a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final ZeroSides f27866b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static final ZeroSides f27867c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static final ZeroSides f27868d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public static final /* synthetic */ ZeroSides[] f27869e;

        static {
            ZeroSides zeroSides = new ZeroSides("NONE", 0);
            f27865a = zeroSides;
            ZeroSides zeroSides2 = new ZeroSides("LEFT", 1);
            f27866b = zeroSides2;
            ZeroSides zeroSides3 = new ZeroSides("RIGHT", 2);
            f27867c = zeroSides3;
            ZeroSides zeroSides4 = new ZeroSides("BOTH", 3);
            f27868d = zeroSides4;
            f27869e = new ZeroSides[]{zeroSides, zeroSides2, zeroSides3, zeroSides4};
        }

        public static ZeroSides valueOf(String str) {
            return (ZeroSides) Enum.valueOf(ZeroSides.class, str);
        }

        public static ZeroSides[] values() {
            return (ZeroSides[]) f27869e.clone();
        }
    }

    public FlutterView(@NonNull Context context) {
        this(context, (AttributeSet) null, new FlutterSurfaceView(context));
    }

    public static View h(int i10, View view) {
        int i11;
        Method declaredMethod;
        try {
            i11 = 0;
            declaredMethod = View.class.getDeclaredMethod("getAccessibilityViewId", new Class[0]);
            declaredMethod.setAccessible(true);
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
        }
        if (declaredMethod.invoke(view, new Object[0]).equals(Integer.valueOf(i10))) {
            return view;
        }
        if (view instanceof ViewGroup) {
            while (true) {
                ViewGroup viewGroup = (ViewGroup) view;
                if (i11 >= viewGroup.getChildCount()) {
                    break;
                }
                View viewH = h(i10, viewGroup.getChildAt(i11));
                if (viewH != null) {
                    return viewH;
                }
                i11++;
            }
        }
        return null;
    }

    @Override // android.view.View
    public final void autofill(SparseArray sparseArray) {
        this.textInputPlugin.e(sparseArray);
    }

    public final boolean c() {
        FlutterImageView flutterImageView = this.flutterImageView;
        if (flutterImageView != null) {
            return flutterImageView.c();
        }
        return false;
    }

    @Override // android.view.View
    public final boolean checkInputConnectionProxy(View view) {
        xc.c cVar = this.flutterEngine;
        return cVar != null ? cVar.f34778r.checkInputConnectionProxy(view) : super.checkInputConnectionProxy(view);
    }

    public final void d(PlatformOverlayView platformOverlayView) {
        xc.c cVar = this.flutterEngine;
        if (cVar != null) {
            platformOverlayView.a(cVar.f34762b);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final boolean dispatchKeyEvent(KeyEvent keyEvent) {
        if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
            getKeyDispatcherState().startTracking(keyEvent, this);
        } else if (keyEvent.getAction() == 1) {
            getKeyDispatcherState().handleUpEvent(keyEvent);
        }
        return (j() && this.keyboardManager.a(keyEvent)) || super.dispatchKeyEvent(keyEvent);
    }

    public final void e(xc.c cVar) {
        Objects.toString(cVar);
        if (j()) {
            if (cVar == this.flutterEngine) {
                return;
            } else {
                g();
            }
        }
        this.flutterEngine = cVar;
        io.flutter.embedding.engine.renderer.j jVar = cVar.f34762b;
        this.f27857b = jVar.f28051c;
        this.renderSurface.a(jVar);
        FlutterJNI flutterJNI = jVar.f28049a;
        f fVar = this.f27862g;
        flutterJNI.addIsDisplayingFlutterUiListener(fVar);
        if (jVar.f28051c) {
            fVar.d();
        }
        this.mouseCursorPlugin = new io.flutter.plugin.mouse.b(this, this.flutterEngine.f34768h);
        xc.c cVar2 = this.flutterEngine;
        this.textInputPlugin = new io.flutter.plugin.editing.m(this, cVar2.f34777q, cVar2.f34773m, cVar2.f34778r);
        try {
            TextServicesManager textServicesManager = (TextServicesManager) getContext().getSystemService("textservices");
            this.textServicesManager = textServicesManager;
            this.spellCheckPlugin = new io.flutter.plugin.editing.i(textServicesManager, this.flutterEngine.f34775o);
        } catch (Exception unused) {
        }
        this.scribePlugin = new io.flutter.plugin.editing.h(this, this.textInputPlugin.f28167b, this.flutterEngine.f34773m);
        this.localizationPlugin = this.flutterEngine.f34765e;
        this.keyboardManager = new c0(this);
        int i10 = 0;
        this.androidTouchProcessor = new b(this.flutterEngine.f34762b, false);
        io.flutter.view.j jVar2 = new io.flutter.view.j(this, cVar.f34766f, (AccessibilityManager) getContext().getSystemService("accessibility"), getContext().getContentResolver(), this.flutterEngine.f34778r);
        this.accessibilityBridge = jVar2;
        jVar2.setOnAccessibilityChangeListener(this.f27860e);
        m(this.accessibilityBridge.f28409c.isEnabled(), this.accessibilityBridge.f28409c.isTouchExplorationEnabled());
        this.flutterEngine.f34778r.f28237f.setAccessibilityBridge(this.accessibilityBridge);
        xc.c cVar3 = this.flutterEngine;
        io.flutter.plugin.platform.r rVar = cVar3.f34778r;
        rVar.getClass();
        rVar.f28233b = new b(cVar3.f34762b, true);
        this.textInputPlugin.f28167b.restartInput(this);
        o();
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor("show_password"), false, this.f27861f);
        p();
        io.flutter.plugin.platform.r rVar2 = cVar.f34778r;
        rVar2.f28235d = this;
        int i11 = 0;
        while (true) {
            SparseArray sparseArray = rVar2.f28243l;
            if (i11 >= sparseArray.size()) {
                break;
            }
            rVar2.f28235d.addView((PlatformViewWrapper) sparseArray.valueAt(i11));
            i11++;
        }
        int i12 = 0;
        while (true) {
            SparseArray sparseArray2 = rVar2.f28241j;
            if (i12 >= sparseArray2.size()) {
                break;
            }
            rVar2.f28235d.addView((FlutterMutatorView) sparseArray2.valueAt(i12));
            i12++;
        }
        while (true) {
            SparseArray sparseArray3 = rVar2.f28240i;
            if (i10 >= sparseArray3.size()) {
                break;
            }
            ((io.flutter.plugin.platform.i) sparseArray3.valueAt(i10)).onFlutterViewAttached(rVar2.f28235d);
            i10++;
        }
        Iterator it = this.f27858c.iterator();
        if (it.hasNext()) {
            u1.x(it.next());
            throw null;
        }
        if (this.f27857b) {
            fVar.d();
        }
    }

    public final void f() {
        this.renderSurface.pause();
        FlutterImageView flutterImageView = this.flutterImageView;
        if (flutterImageView == null) {
            FlutterImageView flutterImageView2 = new FlutterImageView(getContext(), getWidth(), getHeight(), FlutterImageView.SurfaceKind.f27847a);
            this.flutterImageView = flutterImageView2;
            addView(flutterImageView2);
        } else {
            flutterImageView.e(getWidth(), getHeight());
        }
        this.previousRenderSurface = this.renderSurface;
        FlutterImageView flutterImageView3 = this.flutterImageView;
        this.renderSurface = flutterImageView3;
        xc.c cVar = this.flutterEngine;
        if (cVar != null) {
            flutterImageView3.a(cVar.f34762b);
        }
    }

    @Nullable
    @SuppressLint({"SoonBlockedPrivateApi"})
    public View findViewByAccessibilityIdTraversal(int i10) {
        if (Build.VERSION.SDK_INT < 29) {
            return h(i10, this);
        }
        try {
            Method declaredMethod = View.class.getDeclaredMethod("findViewByAccessibilityIdTraversal", Integer.TYPE);
            declaredMethod.setAccessible(true);
            return (View) declaredMethod.invoke(this, Integer.valueOf(i10));
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
            return null;
        }
    }

    public final void g() {
        SparseArray sparseArray;
        Objects.toString(this.flutterEngine);
        if (j()) {
            Iterator it = this.f27858c.iterator();
            if (it.hasNext()) {
                u1.x(it.next());
                throw null;
            }
            getContext().getContentResolver().unregisterContentObserver(this.f27861f);
            io.flutter.plugin.platform.r rVar = this.flutterEngine.f34778r;
            int i10 = 0;
            while (true) {
                SparseArray sparseArray2 = rVar.f28243l;
                if (i10 >= sparseArray2.size()) {
                    break;
                }
                rVar.f28235d.removeView((PlatformViewWrapper) sparseArray2.valueAt(i10));
                i10++;
            }
            int i11 = 0;
            while (true) {
                SparseArray sparseArray3 = rVar.f28241j;
                if (i11 >= sparseArray3.size()) {
                    break;
                }
                rVar.f28235d.removeView((FlutterMutatorView) sparseArray3.valueAt(i11));
                i11++;
            }
            rVar.k();
            if (rVar.f28235d != null) {
                int i12 = 0;
                while (true) {
                    sparseArray = rVar.f28242k;
                    if (i12 >= sparseArray.size()) {
                        break;
                    }
                    rVar.f28235d.removeView((View) sparseArray.valueAt(i12));
                    i12++;
                }
                sparseArray.clear();
            }
            rVar.f28235d = null;
            rVar.f28245n = false;
            int i13 = 0;
            while (true) {
                SparseArray sparseArray4 = rVar.f28240i;
                if (i13 >= sparseArray4.size()) {
                    break;
                }
                ((io.flutter.plugin.platform.i) sparseArray4.valueAt(i13)).onFlutterViewDetached();
                i13++;
            }
            this.flutterEngine.f34778r.f28237f.setAccessibilityBridge(null);
            io.flutter.view.j jVar = this.accessibilityBridge;
            jVar.f28422p = true;
            ((io.flutter.plugin.platform.r) jVar.f28411e).f28237f.setAccessibilityBridge(null);
            jVar.setOnAccessibilityChangeListener(null);
            AccessibilityManager accessibilityManager = jVar.f28409c;
            accessibilityManager.removeAccessibilityStateChangeListener(jVar.f28424r);
            accessibilityManager.removeTouchExplorationStateChangeListener(jVar.f28425s);
            jVar.f28412f.unregisterContentObserver(jVar.f28426t);
            jVar.f28408b.setAccessibilityMessageHandler(null);
            this.accessibilityBridge = null;
            this.textInputPlugin.f28167b.restartInput(this);
            this.textInputPlugin.h();
            int size = this.keyboardManager.f27893b.size();
            if (size > 0) {
                String.valueOf(size);
            }
            io.flutter.plugin.editing.i iVar = this.spellCheckPlugin;
            if (iVar != null) {
                iVar.f28151a.setSpellCheckMethodHandler(null);
                SpellCheckerSession spellCheckerSession = iVar.f28153c;
                if (spellCheckerSession != null) {
                    spellCheckerSession.close();
                }
            }
            io.flutter.plugin.mouse.b bVar = this.mouseCursorPlugin;
            if (bVar != null) {
                bVar.f28179b.setMethodHandler(null);
            }
            io.flutter.embedding.engine.renderer.j jVar2 = this.flutterEngine.f34762b;
            this.f27857b = false;
            jVar2.f28049a.removeIsDisplayingFlutterUiListener(this.f27862g);
            jVar2.h();
            jVar2.f28049a.setSemanticsEnabled(false);
            io.flutter.embedding.engine.renderer.l lVar = this.previousRenderSurface;
            if (lVar != null && this.renderSurface == this.flutterImageView) {
                this.renderSurface = lVar;
            }
            this.renderSurface.b();
            l();
            this.previousRenderSurface = null;
            this.flutterEngine = null;
        }
    }

    @Override // android.view.View
    @Nullable
    public AccessibilityNodeProvider getAccessibilityNodeProvider() {
        io.flutter.view.j jVar = this.accessibilityBridge;
        if (jVar == null || !jVar.f28409c.isEnabled()) {
            return null;
        }
        return this.accessibilityBridge;
    }

    @Nullable
    @VisibleForTesting
    public xc.c getAttachedFlutterEngine() {
        return this.flutterEngine;
    }

    @Override // io.flutter.embedding.android.b0
    public ed.i getBinaryMessenger() {
        return this.flutterEngine.f34763c;
    }

    @VisibleForTesting
    public FlutterImageView getCurrentImageSurface() {
        return this.flutterImageView;
    }

    @VisibleForTesting
    public io.flutter.embedding.engine.renderer.i getViewportMetrics() {
        return this.f27859d;
    }

    public final void i() {
        FlutterSurfaceView flutterSurfaceView = this.flutterSurfaceView;
        if (flutterSurfaceView != null) {
            addView(flutterSurfaceView);
        } else {
            FlutterTextureView flutterTextureView = this.flutterTextureView;
            if (flutterTextureView != null) {
                addView(flutterTextureView);
            } else {
                addView(this.flutterImageView);
            }
        }
        setFocusable(true);
        setFocusableInTouchMode(true);
        if (Build.VERSION.SDK_INT >= 26) {
            setImportantForAutofill(1);
        }
    }

    public final boolean j() {
        xc.c cVar = this.flutterEngine;
        return cVar != null && cVar.f34762b == this.renderSurface.getAttachedRenderer();
    }

    public final boolean k(KeyEvent keyEvent) {
        return this.textInputPlugin.i(keyEvent);
    }

    public final void l() {
        FlutterImageView flutterImageView = this.flutterImageView;
        if (flutterImageView != null) {
            flutterImageView.f27844a.close();
            removeView(this.flutterImageView);
            this.flutterImageView = null;
        }
    }

    public final void m(boolean z10, boolean z11) {
        boolean z12 = false;
        if (this.flutterEngine.f34762b.f28049a.getIsSoftwareRenderingEnabled()) {
            setWillNotDraw(false);
            return;
        }
        if (!z10 && !z11) {
            z12 = true;
        }
        setWillNotDraw(z12);
    }

    public final void n(y.a aVar) {
        io.flutter.embedding.engine.renderer.l lVar;
        FlutterImageView flutterImageView = this.flutterImageView;
        if (flutterImageView == null || (lVar = this.previousRenderSurface) == null) {
            return;
        }
        this.renderSurface = lVar;
        this.previousRenderSurface = null;
        io.flutter.embedding.engine.renderer.j jVar = this.flutterEngine.f34762b;
        if (jVar == null) {
            flutterImageView.b();
            l();
            aVar.run();
        } else {
            lVar.resume();
            t tVar = new t(this, jVar, aVar);
            jVar.f28049a.addIsDisplayingFlutterUiListener(tVar);
            if (jVar.f28051c) {
                tVar.d();
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x003e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void o() {
        boolean z10;
        SettingsChannel$PlatformBrightness settingsChannel$PlatformBrightness = (getResources().getConfiguration().uiMode & 48) == 32 ? SettingsChannel$PlatformBrightness.dark : SettingsChannel$PlatformBrightness.light;
        TextServicesManager textServicesManager = this.textServicesManager;
        if (textServicesManager == null) {
            z10 = false;
        } else {
            if (Build.VERSION.SDK_INT >= 31) {
                boolean zAnyMatch = textServicesManager.getEnabledSpellCheckerInfos().stream().anyMatch(new r());
                if (!this.textServicesManager.isSpellCheckerEnabled() || !zAnyMatch) {
                }
            }
            z10 = true;
        }
        dd.g0 g0Var = new dd.g0(this.flutterEngine.f34774n.f25119a);
        g0Var.f25117b.put("textScaleFactor", Float.valueOf(getResources().getConfiguration().fontScale));
        g0Var.b(getResources().getDisplayMetrics());
        g0Var.f25117b.put("nativeSpellCheckServiceDefined", Boolean.valueOf(z10));
        g0Var.f25117b.put("brieflyShowPassword", Boolean.valueOf(Settings.System.getInt(getContext().getContentResolver(), "show_password", 1) == 1));
        g0Var.f25117b.put("alwaysUse24HourFormat", Boolean.valueOf(DateFormat.is24HourFormat(getContext())));
        g0Var.f25117b.put("platformBrightness", settingsChannel$PlatformBrightness.name);
        g0Var.a();
    }

    /* JADX WARN: Removed duplicated region for block: B:56:0x0189  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x01a3  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x01a5  */
    @Override // android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        WindowInsets windowInsets2;
        int systemWindowInsetBottom;
        DisplayCutout displayCutout;
        WindowInsets windowInsetsOnApplyWindowInsets = super.onApplyWindowInsets(windowInsets);
        int i10 = Build.VERSION.SDK_INT;
        io.flutter.embedding.engine.renderer.i iVar = this.f27859d;
        if (i10 == 29) {
            Insets systemGestureInsets = windowInsets.getSystemGestureInsets();
            iVar.f28042l = systemGestureInsets.top;
            iVar.f28043m = systemGestureInsets.right;
            iVar.f28044n = systemGestureInsets.bottom;
            iVar.f28045o = systemGestureInsets.left;
        }
        boolean z10 = (getWindowSystemUiVisibility() & 4) == 0;
        boolean z11 = (getWindowSystemUiVisibility() & 2) == 0;
        if (i10 >= 30) {
            Insets insets = windowInsets.getInsets(WindowInsets.Type.systemBars());
            iVar.f28034d = insets.top;
            iVar.f28035e = insets.right;
            iVar.f28036f = insets.bottom;
            iVar.f28037g = insets.left;
            Insets insets2 = windowInsets.getInsets(WindowInsets.Type.ime());
            iVar.f28038h = insets2.top;
            iVar.f28039i = insets2.right;
            iVar.f28040j = insets2.bottom;
            iVar.f28041k = insets2.left;
            Insets insets3 = windowInsets.getInsets(WindowInsets.Type.systemGestures());
            iVar.f28042l = insets3.top;
            iVar.f28043m = insets3.right;
            iVar.f28044n = insets3.bottom;
            iVar.f28045o = insets3.left;
            DisplayCutout displayCutout2 = windowInsets.getDisplayCutout();
            if (displayCutout2 != null) {
                Insets waterfallInsets = displayCutout2.getWaterfallInsets();
                iVar.f28034d = Math.max(Math.max(iVar.f28034d, waterfallInsets.top), displayCutout2.getSafeInsetTop());
                iVar.f28035e = Math.max(Math.max(iVar.f28035e, waterfallInsets.right), displayCutout2.getSafeInsetRight());
                iVar.f28036f = Math.max(Math.max(iVar.f28036f, waterfallInsets.bottom), displayCutout2.getSafeInsetBottom());
                iVar.f28037g = Math.max(Math.max(iVar.f28037g, waterfallInsets.left), displayCutout2.getSafeInsetLeft());
            }
            windowInsets2 = windowInsetsOnApplyWindowInsets;
        } else {
            ZeroSides zeroSides = ZeroSides.f27865a;
            ZeroSides zeroSides2 = ZeroSides.f27866b;
            ZeroSides zeroSides3 = ZeroSides.f27867c;
            ZeroSides zeroSides4 = ZeroSides.f27868d;
            if (!z11) {
                Context context = getContext();
                if (context.getResources().getConfiguration().orientation == 2) {
                    int rotation = ((DisplayManager) context.getSystemService(Constants$ScionAnalytics$MessageType.DISPLAY_NOTIFICATION)).getDisplay(0).getRotation();
                    if (rotation == 1) {
                        zeroSides = zeroSides3;
                    } else if (rotation == 3) {
                        zeroSides = zeroSides2;
                    } else if (rotation == 0 || rotation == 2) {
                        zeroSides = zeroSides4;
                    }
                }
            }
            iVar.f28034d = z10 ? windowInsets.getSystemWindowInsetTop() : 0;
            iVar.f28035e = (zeroSides == zeroSides3 || zeroSides == zeroSides4) ? 0 : windowInsets.getSystemWindowInsetRight();
            if (z11) {
                windowInsets2 = windowInsetsOnApplyWindowInsets;
                if (windowInsets.getSystemWindowInsetBottom() < ((double) getRootView().getHeight()) * 0.18d || windowInsets.getSystemWindowInsetBottom() == 0) {
                    systemWindowInsetBottom = windowInsets.getSystemWindowInsetBottom();
                }
                iVar.f28036f = systemWindowInsetBottom;
                iVar.f28037g = (zeroSides != zeroSides2 || zeroSides == zeroSides4) ? 0 : windowInsets.getSystemWindowInsetLeft();
                iVar.f28038h = 0;
                iVar.f28039i = 0;
                iVar.f28040j = ((double) windowInsets.getSystemWindowInsetBottom()) >= ((double) getRootView().getHeight()) * 0.18d ? 0 : windowInsets.getSystemWindowInsetBottom();
                iVar.f28041k = 0;
            } else {
                windowInsets2 = windowInsetsOnApplyWindowInsets;
            }
            systemWindowInsetBottom = 0;
            iVar.f28036f = systemWindowInsetBottom;
            if (zeroSides != zeroSides2) {
                iVar.f28037g = (zeroSides != zeroSides2 || zeroSides == zeroSides4) ? 0 : windowInsets.getSystemWindowInsetLeft();
                iVar.f28038h = 0;
                iVar.f28039i = 0;
                iVar.f28040j = ((double) windowInsets.getSystemWindowInsetBottom()) >= ((double) getRootView().getHeight()) * 0.18d ? 0 : windowInsets.getSystemWindowInsetBottom();
                iVar.f28041k = 0;
            }
        }
        ArrayList arrayList = new ArrayList();
        if (i10 >= 28 && (displayCutout = windowInsets.getDisplayCutout()) != null) {
            for (Rect rect : displayCutout.getBoundingRects()) {
                rect.toString();
                arrayList.add(new io.flutter.embedding.engine.renderer.b(rect, FlutterRenderer$DisplayFeatureType.CUTOUT, FlutterRenderer$DisplayFeatureState.UNKNOWN));
            }
        }
        ArrayList arrayList2 = iVar.f28048r;
        arrayList2.clear();
        arrayList2.addAll(arrayList);
        if (Build.VERSION.SDK_INT >= 35) {
            u uVar = this.f27864i;
            Context context2 = getContext();
            uVar.getClass();
            u.a(context2, iVar);
        }
        p();
        return windowInsets2;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        h0 h0Var;
        super.onAttachedToWindow();
        try {
            androidx.window.layout.j jVar = androidx.window.layout.k.f4484a;
            Context context = getContext();
            jVar.getClass();
            h0Var = new h0(new b4.a(androidx.window.layout.j.a(context)));
        } catch (NoClassDefFoundError unused) {
            h0Var = null;
        }
        this.windowInfoRepo = h0Var;
        Activity activity = id.e.getActivity(getContext());
        h0 h0Var2 = this.windowInfoRepo;
        if (h0Var2 == null || activity == null) {
            return;
        }
        this.f27863h = new androidx.fragment.app.g0(this, 2);
        Context context2 = getContext();
        Object obj = g0.d.f26125a;
        Executor executorH = Build.VERSION.SDK_INT >= 28 ? m.d.h(context2) : new m0.f(0, new Handler(context2.getMainLooper()));
        androidx.fragment.app.g0 g0Var = this.f27863h;
        b4.a aVar = h0Var2.f27909a;
        aVar.getClass();
        nb.g.i(executorH, "executor");
        nb.g.i(g0Var, "consumer");
        aVar.f4720c.a(executorH, g0Var, aVar.f4719b.a(activity));
    }

    @Override // android.view.View
    public final void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        if (this.flutterEngine != null) {
            this.localizationPlugin.b(configuration);
            o();
            id.e.calculateMaximumDisplayMetrics(getContext(), this.flutterEngine);
        }
    }

    @Override // android.view.View
    @Nullable
    public InputConnection onCreateInputConnection(@NonNull EditorInfo editorInfo) {
        return !j() ? super.onCreateInputConnection(editorInfo) : this.textInputPlugin.createInputConnection(this, this.keyboardManager, editorInfo);
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        androidx.fragment.app.g0 g0Var;
        h0 h0Var = this.windowInfoRepo;
        if (h0Var != null && (g0Var = this.f27863h) != null) {
            b4.a aVar = h0Var.f27909a;
            aVar.getClass();
            androidx.window.java.core.a aVar2 = aVar.f4720c;
            aVar2.getClass();
            ReentrantLock reentrantLock = aVar2.f4441a;
            reentrantLock.lock();
            LinkedHashMap linkedHashMap = aVar2.f4442b;
            try {
                y0 y0Var = (y0) linkedHashMap.get(g0Var);
                if (y0Var != null) {
                    y0Var.e(null);
                }
            } finally {
                reentrantLock.unlock();
            }
        }
        this.f27863h = null;
        this.windowInfoRepo = null;
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public final boolean onGenericMotionEvent(MotionEvent motionEvent) {
        if (j()) {
            b bVar = this.androidTouchProcessor;
            Context context = getContext();
            bVar.getClass();
            boolean zIsFromSource = motionEvent.isFromSource(2);
            boolean z10 = motionEvent.getActionMasked() == 7 || motionEvent.getActionMasked() == 8;
            if (zIsFromSource && z10) {
                int iB = b.b(motionEvent.getActionMasked());
                ByteBuffer byteBufferAllocateDirect = ByteBuffer.allocateDirect(motionEvent.getPointerCount() * 288);
                byteBufferAllocateDirect.order(ByteOrder.LITTLE_ENDIAN);
                bVar.a(motionEvent, motionEvent.getActionIndex(), iB, 0, b.f27886f, byteBufferAllocateDirect, context);
                if (byteBufferAllocateDirect.position() % 288 != 0) {
                    throw new AssertionError("Packet position is not on field boundary.");
                }
                bVar.f27887a.f28049a.dispatchPointerDataPacket(byteBufferAllocateDirect, byteBufferAllocateDirect.position());
                return true;
            }
        }
        return super.onGenericMotionEvent(motionEvent);
    }

    @Override // android.view.View
    public final boolean onHoverEvent(MotionEvent motionEvent) {
        return !j() ? super.onHoverEvent(motionEvent) : this.accessibilityBridge.g(motionEvent, false);
    }

    @Override // android.view.View
    public final void onProvideAutofillVirtualStructure(ViewStructure viewStructure, int i10) {
        super.onProvideAutofillVirtualStructure(viewStructure, i10);
        this.textInputPlugin.l(viewStructure);
    }

    @Override // android.view.View
    public final void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        io.flutter.embedding.engine.renderer.i iVar = this.f27859d;
        iVar.f28032b = i10;
        iVar.f28033c = i11;
        p();
    }

    @Override // android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        if (!j()) {
            return super.onTouchEvent(motionEvent);
        }
        requestUnbufferedDispatch(motionEvent);
        this.androidTouchProcessor.d(motionEvent, b.f27886f);
        return true;
    }

    public final void p() {
        if (j()) {
            float f10 = getResources().getDisplayMetrics().density;
            io.flutter.embedding.engine.renderer.i iVar = this.f27859d;
            iVar.f28031a = f10;
            iVar.f28046p = ViewConfiguration.get(getContext()).getScaledTouchSlop();
            io.flutter.embedding.engine.renderer.j jVar = this.flutterEngine.f34762b;
            jVar.getClass();
            if (iVar.f28032b <= 0 || iVar.f28033c <= 0 || iVar.f28031a <= 0.0f) {
                return;
            }
            ArrayList arrayList = iVar.f28047q;
            arrayList.size();
            ArrayList arrayList2 = iVar.f28048r;
            arrayList2.size();
            int size = arrayList2.size() + arrayList.size();
            int[] iArr = new int[size * 4];
            int[] iArr2 = new int[size];
            int[] iArr3 = new int[size];
            for (int i10 = 0; i10 < arrayList.size(); i10++) {
                io.flutter.embedding.engine.renderer.b bVar = (io.flutter.embedding.engine.renderer.b) arrayList.get(i10);
                int i11 = i10 * 4;
                Rect rect = bVar.f28014a;
                iArr[i11] = rect.left;
                iArr[i11 + 1] = rect.top;
                iArr[i11 + 2] = rect.right;
                iArr[i11 + 3] = rect.bottom;
                iArr2[i10] = bVar.f28015b.encodedValue;
                iArr3[i10] = bVar.f28016c.encodedValue;
            }
            int size2 = arrayList.size() * 4;
            for (int i12 = 0; i12 < arrayList2.size(); i12++) {
                io.flutter.embedding.engine.renderer.b bVar2 = (io.flutter.embedding.engine.renderer.b) arrayList2.get(i12);
                int i13 = (i12 * 4) + size2;
                Rect rect2 = bVar2.f28014a;
                iArr[i13] = rect2.left;
                iArr[i13 + 1] = rect2.top;
                iArr[i13 + 2] = rect2.right;
                iArr[i13 + 3] = rect2.bottom;
                iArr2[arrayList.size() + i12] = bVar2.f28015b.encodedValue;
                iArr3[arrayList.size() + i12] = bVar2.f28016c.encodedValue;
            }
            jVar.f28049a.setViewportMetrics(iVar.f28031a, iVar.f28032b, iVar.f28033c, iVar.f28034d, iVar.f28035e, iVar.f28036f, iVar.f28037g, iVar.f28038h, iVar.f28039i, iVar.f28040j, iVar.f28041k, iVar.f28042l, iVar.f28043m, iVar.f28044n, iVar.f28045o, iVar.f28046p, iArr, iArr2, iArr3);
        }
    }

    @VisibleForTesting
    public void setDelegate(@NonNull u uVar) {
        this.f27864i = uVar;
    }

    @Override // android.view.View
    public void setVisibility(int i10) {
        super.setVisibility(i10);
        io.flutter.embedding.engine.renderer.l lVar = this.renderSurface;
        if (lVar instanceof FlutterSurfaceView) {
            ((FlutterSurfaceView) lVar).setVisibility(i10);
        }
    }

    @TargetApi(28)
    public void setWindowInfoListenerDisplayFeatures(androidx.window.layout.n nVar) {
        List<androidx.window.layout.a> list = nVar.f4487a;
        ArrayList arrayList = new ArrayList();
        for (androidx.window.layout.a aVar : list) {
            androidx.window.layout.h hVar = (androidx.window.layout.h) aVar;
            hVar.f4475a.c().toString();
            boolean z10 = aVar instanceof androidx.window.layout.f;
            FlutterRenderer$DisplayFeatureState flutterRenderer$DisplayFeatureState = FlutterRenderer$DisplayFeatureState.UNKNOWN;
            if (z10) {
                androidx.window.layout.h hVar2 = (androidx.window.layout.h) ((androidx.window.layout.f) aVar);
                androidx.window.core.b bVar = hVar2.f4475a;
                int iB = bVar.b();
                androidx.window.layout.c cVar = androidx.window.layout.c.f4464c;
                FlutterRenderer$DisplayFeatureType flutterRenderer$DisplayFeatureType = ((iB == 0 || bVar.a() == 0) ? androidx.window.layout.c.f4463b : cVar) == cVar ? FlutterRenderer$DisplayFeatureType.HINGE : FlutterRenderer$DisplayFeatureType.FOLD;
                androidx.window.layout.e eVar = androidx.window.layout.e.f4469b;
                androidx.window.layout.e eVar2 = hVar2.f4477c;
                if (eVar2 == eVar) {
                    flutterRenderer$DisplayFeatureState = FlutterRenderer$DisplayFeatureState.POSTURE_FLAT;
                } else if (eVar2 == androidx.window.layout.e.f4470c) {
                    flutterRenderer$DisplayFeatureState = FlutterRenderer$DisplayFeatureState.POSTURE_HALF_OPENED;
                }
                arrayList.add(new io.flutter.embedding.engine.renderer.b(hVar.f4475a.c(), flutterRenderer$DisplayFeatureType, flutterRenderer$DisplayFeatureState));
            } else {
                arrayList.add(new io.flutter.embedding.engine.renderer.b(hVar.f4475a.c(), FlutterRenderer$DisplayFeatureType.UNKNOWN, flutterRenderer$DisplayFeatureState));
            }
        }
        ArrayList arrayList2 = this.f27859d.f28047q;
        arrayList2.clear();
        arrayList2.addAll(arrayList);
        p();
    }

    public FlutterView(Context context, FlutterSurfaceView flutterSurfaceView) {
        this(context, (AttributeSet) null, flutterSurfaceView);
    }

    public FlutterView(Context context, FlutterTextureView flutterTextureView) {
        this(context, (AttributeSet) null, flutterTextureView);
    }

    public FlutterView(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, new FlutterSurfaceView(context));
    }

    private FlutterView(@NonNull Context context, @Nullable AttributeSet attributeSet, @NonNull FlutterSurfaceView flutterSurfaceView) {
        super(context, attributeSet);
        this.f27856a = new HashSet();
        this.f27858c = new HashSet();
        this.f27859d = new io.flutter.embedding.engine.renderer.i();
        this.f27860e = new s(this);
        this.f27861f = new v0.a(this, new Handler(Looper.getMainLooper()), 5);
        this.f27862g = new f(this, 2);
        this.f27864i = new u();
        this.flutterSurfaceView = flutterSurfaceView;
        this.renderSurface = flutterSurfaceView;
        i();
    }

    private FlutterView(@NonNull Context context, @Nullable AttributeSet attributeSet, @NonNull FlutterTextureView flutterTextureView) {
        super(context, attributeSet);
        this.f27856a = new HashSet();
        this.f27858c = new HashSet();
        this.f27859d = new io.flutter.embedding.engine.renderer.i();
        this.f27860e = new s(this);
        this.f27861f = new v0.a(this, new Handler(Looper.getMainLooper()), 5);
        this.f27862g = new f(this, 2);
        this.f27864i = new u();
        this.flutterTextureView = flutterTextureView;
        this.renderSurface = flutterTextureView;
        i();
    }

    private FlutterView(@NonNull Context context, @Nullable AttributeSet attributeSet, @NonNull FlutterImageView flutterImageView) {
        super(context, attributeSet);
        this.f27856a = new HashSet();
        this.f27858c = new HashSet();
        this.f27859d = new io.flutter.embedding.engine.renderer.i();
        this.f27860e = new s(this);
        this.f27861f = new v0.a(this, new Handler(Looper.getMainLooper()), 5);
        this.f27862g = new f(this, 2);
        this.f27864i = new u();
        this.flutterImageView = flutterImageView;
        this.renderSurface = flutterImageView;
        i();
    }
}
