package defpackage;

import android.content.Context;
import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.os.Build;
import android.os.HandlerThread;
import android.os.Trace;
import android.view.Surface;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.ILoggerFactory;

/* renamed from: ᵭːᵴ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4118 implements InterfaceC2147, ILoggerFactory {

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public static volatile C4118 f15380;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public boolean f15381;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final /* synthetic */ int f15382;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public Object f15383;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public Object f15384;

    public C4118(int i) {
        this.f15382 = i;
        switch (i) {
            case C1339.DOUBLE_FIELD_NUMBER /* 7 */:
                this.f15381 = false;
                this.f15384 = new HashMap();
                this.f15383 = new LinkedBlockingQueue();
                break;
            case C1339.BYTES_FIELD_NUMBER /* 8 */:
            case 9:
            default:
                this.f15384 = Collections.newSetFromMap(new WeakHashMap());
                this.f15383 = new HashSet();
                break;
            case 10:
                this.f15384 = new Object();
                break;
        }
    }

    public /* synthetic */ C4118(int i, boolean z) {
        this.f15382 = i;
    }

    public C4118(Context context) {
        this.f15382 = 0;
        this.f15383 = new HashSet();
        C0262 c0262 = new C0262(new C4081(context, 2));
        C5532 c5532 = new C5532(this);
        this.f15384 = Build.VERSION.SDK_INT >= 24 ? new C4549(c0262, c5532) : new C3669(context, c0262, c5532);
    }

    public C4118(InterfaceC1731 interfaceC1731) {
        this.f15382 = 2;
        this.f15384 = interfaceC1731;
        this.f15383 = new ᵼᵫᵧˀ(18);
    }

    public C4118(ᐧﾞ r1) {
        this.f15382 = 3;
        this.f15384 = new Object();
        this.f15383 = new ArrayList();
    }

    public C4118(C4118 c4118, C0377[] c0377Arr, boolean z) {
        this.f15382 = 9;
        this.f15383 = c4118;
        this.f15384 = c0377Arr;
        boolean z2 = false;
        if (c0377Arr != null && z) {
            z2 = true;
        }
        this.f15381 = z2;
    }

    public C4118(C5135 c5135, C5135 c51352) {
        this.f15382 = 1;
        this.f15384 = c5135;
        this.f15383 = c51352;
        this.f15381 = true;
    }

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public static void m9021(C2503 c2503, TextView textView) {
        C2718 c2718 = c2503.f9763;
        if (textView == c2503.f9766) {
            if (c2718.f10535 != null) {
                c2718.f10535 = textView.getText();
                return;
            } else {
                c2718.f10545 = textView.getText();
                return;
            }
        }
        if (textView == c2503.f9761) {
            if (c2718.f10536 != null) {
                c2718.f10536 = textView.getText();
            } else {
                c2718.f10537 = textView.getText();
            }
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static C4118 m9022() {
        C4118 c4118 = new C4118(8, false);
        c4118.f15381 = true;
        return c4118;
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public static C4118 m9023(Context context) {
        if (f15380 == null) {
            synchronized (C4118.class) {
                try {
                    if (f15380 == null) {
                        f15380 = new C4118(context.getApplicationContext());
                    }
                } finally {
                }
            }
        }
        return f15380;
    }

    public String toString() {
        switch (this.f15382) {
            case C1339.STRING_SET_FIELD_NUMBER /* 6 */:
                StringBuilder sb = new StringBuilder();
                sb.append(super.toString());
                sb.append("{numRequests=");
                sb.append(((Set) this.f15384).size());
                sb.append(", isPaused=");
                return AbstractC1327.m4090(sb, this.f15381, "}");
            default:
                return super.toString();
        }
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public void m9024(View view) {
        if (this.f15381) {
            this.f15381 = false;
            ((InputMethodManager) view.getContext().getSystemService("input_method")).hideSoftInputFromWindow(view.getWindowToken(), 0);
            ((C1356) this.f15383).f5584.m9228(false);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:50:0x0044, code lost:
    
        r3 = 0;
     */
    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void m9025(defpackage.C5195 r12, android.widget.TextView r13) {
        /*
            r11 = this;
            ᵘˆʞᵶ r0 = r12.m10750(r13)
            m9021(r0, r13)
            ᵮˋˑᵲ r1 = r12.f19393
            if (r1 == 0) goto L10
            ᵛʨ r2 = r0.f9763
            r1.mo4195(r2)
        L10:
            java.lang.Object r1 = r11.f15383
            ˊᵡ r1 = (defpackage.C1356) r1
            ᵛʨ r2 = r0.f9763
            ᵯˇ r1 = r1.f5584
            long r1 = r1.m9226(r2)
            ˈˎᵛᵱ r3 = r12.f19385
            r4 = 0
            r5 = 1
            r3.m3407(r0, r4, r5)
            r6 = -3
            int r3 = (r1 > r6 ? 1 : (r1 == r6 ? 0 : -1))
            if (r3 == 0) goto Lb5
            ᵛʨ r3 = r0.f9763
            long r6 = r3.f10539
            int r6 = (r1 > r6 ? 1 : (r1 == r6 ? 0 : -1))
            if (r6 == 0) goto Lb5
            r6 = -2
            int r6 = (r1 > r6 ? 1 : (r1 == r6 ? 0 : -1))
            if (r6 != 0) goto L43
            java.util.ArrayList r7 = r12.f19392
            int r3 = r7.indexOf(r3)
            if (r3 >= 0) goto L41
            goto Lb5
        L41:
            int r3 = r3 + r5
            goto L44
        L43:
            r3 = r4
        L44:
            java.util.ArrayList r7 = r12.f19392
            int r8 = r7.size()
            if (r6 != 0) goto L5f
        L4c:
            if (r3 >= r8) goto L70
            java.lang.Object r9 = r7.get(r3)
            ᵛʨ r9 = (defpackage.C2718) r9
            int r9 = r9.f10533
            r10 = 32
            r9 = r9 & r10
            if (r9 != r10) goto L5c
            goto L70
        L5c:
            int r3 = r3 + 1
            goto L4c
        L5f:
            if (r3 >= r8) goto L70
            java.lang.Object r9 = r7.get(r3)
            ᵛʨ r9 = (defpackage.C2718) r9
            long r9 = r9.f10539
            int r9 = (r9 > r1 ? 1 : (r9 == r1 ? 0 : -1))
            if (r9 == 0) goto L70
            int r3 = r3 + 1
            goto L5f
        L70:
            if (r3 >= r8) goto L95
            ˈˎᵛᵱ r1 = r12.f19385
            androidx.leanback.widget.VerticalGridView r1 = r1.f4538
            ᵕᵲᵝ r1 = r1.m597(r3, r4)
            ᵘˆʞᵶ r1 = (defpackage.C2503) r1
            if (r1 == 0) goto Lb5
            android.view.View r13 = r1.f9071
            ᵛʨ r0 = r1.f9763
            int r0 = r0.f10544
            if (r0 == r5) goto L91
            r2 = 2
            if (r0 != r2) goto L8a
            goto L91
        L8a:
            r11.m9024(r13)
            r13.requestFocus()
            return
        L91:
            r11.m9031(r12, r1)
            return
        L95:
            java.lang.Object r3 = r11.f15384
            java.util.ArrayList r3 = (java.util.ArrayList) r3
            r7 = r4
        L9a:
            int r8 = r3.size()
            if (r7 >= r8) goto Lb2
            java.lang.Object r8 = r3.get(r7)
            android.util.Pair r8 = (android.util.Pair) r8
            java.lang.Object r9 = r8.first
            if (r9 != r12) goto Laf
            java.lang.Object r12 = r8.second
            ᵻːᵽ r12 = (defpackage.C5195) r12
            goto Lb3
        Laf:
            int r7 = r7 + 1
            goto L9a
        Lb2:
            r12 = 0
        Lb3:
            if (r12 != 0) goto L43
        Lb5:
            r11.m9024(r13)
            android.view.View r11 = r0.f9071
            r11.requestFocus()
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C4118.m9025(ᵻːᵽ, android.widget.TextView):void");
    }

    @Override // defpackage.InterfaceC2147
    /* renamed from: ˏˋٴ, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public C2137 mo5726(C3460 c3460) throws Exception {
        MediaCodec mediaCodecCreateByCodecName;
        int i;
        InterfaceC4919 c3993;
        C2137 c2137;
        String str = ((C0381) c3460.f12987).f2185;
        C2137 c21372 = null;
        try {
            Trace.beginSection("createCodec:" + str);
            mediaCodecCreateByCodecName = MediaCodec.createByCodecName(str);
            try {
                i = 0;
                if (!this.f15381 || Build.VERSION.SDK_INT < 36) {
                    c3993 = new C3993(mediaCodecCreateByCodecName, (HandlerThread) ((C5135) this.f15383).get());
                } else {
                    c3993 = new C4457(i, mediaCodecCreateByCodecName);
                    i = 4;
                }
                c2137 = new C2137(mediaCodecCreateByCodecName, (HandlerThread) ((C5135) this.f15384).get(), c3993, (C2443) c3460.f12989);
            } catch (Exception e) {
                e = e;
            }
            try {
                Trace.endSection();
                Surface surface = (Surface) c3460.f12988;
                if (surface == null && ((C0381) c3460.f12987).f2189 && Build.VERSION.SDK_INT >= 35) {
                    i |= 8;
                }
                C2137.m5742(c2137, (MediaFormat) c3460.f12991, surface, (MediaCrypto) c3460.f12986, i);
                return c2137;
            } catch (Exception e2) {
                e = e2;
                c21372 = c2137;
                if (c21372 != null) {
                    c21372.mo5752();
                } else if (mediaCodecCreateByCodecName != null) {
                    mediaCodecCreateByCodecName.release();
                }
                throw e;
            }
        } catch (Exception e3) {
            e = e3;
            mediaCodecCreateByCodecName = null;
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public boolean m9027(InterfaceC3230 interfaceC3230) {
        boolean z = true;
        if (interfaceC3230 == null) {
            return true;
        }
        boolean zRemove = ((Set) this.f15384).remove(interfaceC3230);
        if (!((HashSet) this.f15383).remove(interfaceC3230) && !zRemove) {
            z = false;
        }
        if (z) {
            interfaceC3230.clear();
        }
        return z;
    }

    @Override // org.slf4j.ILoggerFactory
    /* renamed from: ᵝᵵᵺ */
    public synchronized InterfaceC0567 mo1014(String str) {
        C4411 c4411;
        c4411 = (C4411) ((HashMap) this.f15384).get(str);
        if (c4411 == null) {
            c4411 = new C4411(str, (LinkedBlockingQueue) this.f15383, this.f15381);
            ((HashMap) this.f15384).put(str, c4411);
        }
        return c4411;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public C4118 m9028() {
        ᵩʛʽ.ˏᵙ("execute parameter required", ((InterfaceC0816) this.f15384) != null);
        return new C4118(this, (C0377[]) this.f15383, this.f15381);
    }

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public void m9029(C3921 c3921) {
        InterfaceC4897 interfaceC4897;
        synchronized (this.f15384) {
            if (((ArrayDeque) this.f15383) != null && !this.f15381) {
                this.f15381 = true;
                while (true) {
                    synchronized (this.f15384) {
                        try {
                            interfaceC4897 = (InterfaceC4897) ((ArrayDeque) this.f15383).poll();
                            if (interfaceC4897 == null) {
                                this.f15381 = false;
                                return;
                            }
                        } finally {
                        }
                    }
                    interfaceC4897.mo6879(c3921);
                }
            }
        }
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public void m9030(InterfaceC4897 interfaceC4897) {
        synchronized (this.f15384) {
            try {
                if (((ArrayDeque) this.f15383) == null) {
                    this.f15383 = new ArrayDeque();
                }
                ((ArrayDeque) this.f15383).add(interfaceC4897);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public void m9031(C5195 c5195, C2503 c2503) {
        c5195.f19385.m3407(c2503, true, true);
        int i = c2503.f9765;
        View view = i != 1 ? i != 2 ? i != 3 ? null : c2503.f9764 : c2503.f9766 : c2503.f9761;
        if (view != null) {
            if (i == 1 || i == 2) {
                InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService("input_method");
                view.setFocusable(true);
                view.requestFocus();
                inputMethodManager.showSoftInput(view, 0);
                if (this.f15381) {
                    return;
                }
                this.f15381 = true;
                ((C1356) this.f15383).f5584.m9228(true);
            }
        }
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public void m9032(C5195 c5195, TextView textView) {
        C2503 c2503M10750 = c5195.m10750(textView);
        m9021(c2503M10750, textView);
        C4263 c4263 = ((C1356) this.f15383).f5584;
        c5195.f19385.m3407(c2503M10750, false, true);
        m9024(textView);
        c2503M10750.f9071.requestFocus();
    }
}
