package xyz.stream.api;

import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.util.Base64;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.f3;
import androidx.core.view.l0;
import androidx.fragment.app.d1;
import androidx.fragment.app.e0;
import androidx.fragment.app.z0;
import com.bytedance.sdk.component.ro.fm.fhx;
import com.bytedance.sdk.component.ro.fm.lb;
import com.bytedance.sdk.component.ro.fm.onz;
import com.bytedance.sdk.component.ro.fm.ro;
import com.bytedance.sdk.openadsdk.api.nativeAd.PAGVideoAdListener;
import com.google.android.gms.internal.measurement.d6;
import com.google.android.gms.internal.measurement.d7;
import com.google.android.gms.internal.measurement.m5;
import com.google.android.gms.internal.measurement.u5;
import com.google.android.gms.internal.measurement.u6;
import com.google.android.gms.internal.measurement.zzik;
import com.google.android.material.button.MaterialButtonGroup;
import com.google.android.material.floatingtoolbar.FloatingToolbarLayout;
import e.u0;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.lang.reflect.InvocationHandler;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import l.u3;
import l.w1;
import org.chromium.support_lib_boundary.JsReplyProxyBoundaryInterface;
import org.chromium.support_lib_boundary.WebMessageBoundaryInterface;
import org.chromium.support_lib_boundary.WebMessageListenerBoundaryInterface;
import tv.danmaku.ijk.media.player.ui.IjkVideoView;
import xyz.netfly.ui.live.tv.LiveActivity;

/* JADX INFO: loaded from: classes3.dex */
public final class a0 implements w1, k.n, j0.o, androidx.emoji2.text.q, androidx.activity.result.c, WebMessageListenerBoundaryInterface, n4.f, u5.a, lb, l7.a, com.google.android.gms.common.internal.f, com.google.android.material.button.a, l0, sa.i, ad.a, dd.l, PAGVideoAdListener, xyz.netfly.ads.g {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static volatile a0 f35756c;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f35757a;

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

    public /* synthetic */ a0(int i10, int i11) {
        this.f35757a = i10;
    }

    public static ByteArrayInputStream g(String str) {
        if (!str.startsWith("data:image")) {
            throw new IllegalArgumentException("Not a valid image data URL.");
        }
        int iIndexOf = str.indexOf(44);
        if (iIndexOf == -1) {
            throw new IllegalArgumentException("Missing comma in data URL.");
        }
        if (str.substring(0, iIndexOf).endsWith(";base64")) {
            return new ByteArrayInputStream(Base64.decode(str.substring(iIndexOf + 1), 0));
        }
        throw new IllegalArgumentException("Not a base64 image data URL.");
    }

    public static a0 h() {
        if (f35756c == null) {
            synchronized (a0.class) {
                try {
                    if (f35756c == null) {
                        int i10 = 0;
                        f35756c = new a0(i10, i10);
                    }
                } finally {
                }
            }
        }
        return f35756c;
    }

    public final void A(int i10, int i11) {
        ((u5) this.f35758b).p(i10, i11);
    }

    public final void B(int i10, long j10) {
        ((u5) this.f35758b).e(i10, j10);
    }

    public final void C(int i10, int i11) {
        ((u5) this.f35758b).d(i10, i11);
    }

    public final void D(int i10, long j10) {
        ((u5) this.f35758b).q(i10, (j10 >> 63) ^ (j10 << 1));
    }

    public final void E(int i10, int i11) {
        ((u5) this.f35758b).y(i10, (i11 >> 31) ^ (i11 << 1));
    }

    public final void F(int i10, long j10) {
        ((u5) this.f35758b).q(i10, j10);
    }

    public final void G(int i10, int i11) {
        ((u5) this.f35758b).y(i10, i11);
    }

    @Override // androidx.emoji2.text.q
    public final void a(androidx.emoji2.text.r rVar) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, 15L, TimeUnit.SECONDS, new LinkedBlockingDeque(), new androidx.emoji2.text.b("EmojiCompatInitializer"));
        threadPoolExecutor.allowCoreThreadTimeOut(true);
        threadPoolExecutor.execute(new androidx.emoji2.text.v(this, rVar, threadPoolExecutor, 0));
    }

    @Override // xyz.netfly.ads.g
    public final void b() {
        IjkVideoView ijkVideoView;
        LiveActivity liveActivity = (LiveActivity) this.f35758b;
        int i10 = LiveActivity.f35467o0;
        if (liveActivity.isFinishing() || liveActivity.isDestroyed() || liveActivity.binding == 0 || liveActivity.f35471c == null || (ijkVideoView = liveActivity.f35479g) == null) {
            return;
        }
        try {
            ijkVideoView.setVolume(1.0f, 1.0f);
            liveActivity.f35479g.setVisibility(0);
            if (liveActivity.f35489l) {
                liveActivity.f35475e.b();
            } else {
                liveActivity.f35471c.f27097c.requestFocus();
            }
            if (liveActivity.f35479g.getPlaybackState() != -1) {
                if (liveActivity.f35479g.getPlaybackState() >= 2) {
                    liveActivity.f35471c.f27113s.setVisibility(8);
                }
            } else {
                Handler handler = liveActivity.f35480g0;
                ve.g gVar = liveActivity.f35482h0;
                handler.removeCallbacks(gVar);
                handler.postDelayed(gVar, 1000L);
            }
        } catch (Throwable th) {
            xyz.stream.utils.h.c("restore tv live volume after ad error: " + th.getMessage());
        }
    }

    @Override // androidx.activity.result.c
    public final void c(Object obj) {
        e0 e0VarFindFragmentByWho;
        androidx.activity.result.b bVar = (androidx.activity.result.b) obj;
        z0 z0Var = (z0) ((d1) this.f35758b).E.pollLast();
        if (z0Var == null || (e0VarFindFragmentByWho = ((d1) this.f35758b).f2368c.findFragmentByWho(z0Var.f2627a)) == null) {
            return;
        }
        e0VarFindFragmentByWho.onActivityResult(z0Var.f2628b, bVar.f505a, bVar.f506b);
    }

    @Override // u5.a
    public final Object d() {
        com.bumptech.glide.load.engine.p pVar = (com.bumptech.glide.load.engine.p) this.f35758b;
        return new com.bumptech.glide.load.engine.u((e5.d) pVar.f5756a, (e5.d) pVar.f5757b, (e5.d) pVar.f5758c, (e5.d) pVar.f5759d, (com.bumptech.glide.load.engine.v) pVar.f5760e, (com.bumptech.glide.load.engine.x) pVar.f5761f, (p0.e) pVar.f5762g);
    }

    @Override // xyz.netfly.ads.g
    public final void e(String str) {
        if (str.equals("STARTED")) {
            ((LiveActivity) this.f35758b).V = System.currentTimeMillis();
        }
    }

    @Override // k.n
    public final boolean f(k.p pVar, MenuItem menuItem) {
        u3 u3Var;
        switch (this.f35757a) {
            case 2:
                break;
            default:
                l.s sVar = ((ActionMenuView) this.f35758b).f632g0;
                if (sVar != null) {
                    xyz.stream.utils.a0 a0Var = (xyz.stream.utils.a0) sVar;
                    if (!((Toolbar) a0Var.f36098a).f823m0.a(menuItem) && ((u3Var = ((Toolbar) a0Var.f36098a).f825o0) == null || !((u0) ((e.y) u3Var).f25365a).f25337b.onMenuItemSelected(0, menuItem))) {
                    }
                }
                break;
        }
        return false;
    }

    @Override // com.bytedance.sdk.component.ro.fm.lb
    public final void fm(ro roVar, IOException iOException) {
        e6.b.b((e6.b) this.f35758b, 30000, iOException.getMessage());
    }

    @Override // org.chromium.support_lib_boundary.FeatureFlagHolderBoundaryInterface
    public final String[] getSupportedFeatures() {
        return new String[]{"WEB_MESSAGE_LISTENER", "WEB_MESSAGE_ARRAY_BUFFER"};
    }

    @Override // androidx.core.view.l0
    public final f3 i(View view, f3 f3Var) {
        Object obj = this.f35758b;
        if (!((FloatingToolbarLayout) obj).f22642a && !((FloatingToolbarLayout) obj).f22644c && !((FloatingToolbarLayout) obj).f22643b && !((FloatingToolbarLayout) obj).f22645d) {
            return f3Var;
        }
        j0.d dVarF = f3Var.f1747a.f(143);
        Object obj2 = this.f35758b;
        ((FloatingToolbarLayout) obj2).f22647f = dVarF.f28505d;
        ((FloatingToolbarLayout) obj2).f22648g = dVarF.f28503b;
        ((FloatingToolbarLayout) obj2).f22650i = dVarF.f28504c;
        ((FloatingToolbarLayout) obj2).f22649h = dVarF.f28502a;
        ((FloatingToolbarLayout) obj2).a();
        return f3Var;
    }

    public final synchronized void j(y4.d dVar) {
        dVar.f36825b = null;
        dVar.f36826c = null;
        ((Queue) this.f35758b).offer(dVar);
    }

    public final void k(double d10, int i10) {
        u5 u5Var = (u5) this.f35758b;
        u5Var.getClass();
        u5Var.e(i10, Double.doubleToRawLongBits(d10));
    }

    @Override // k.n
    public final void l(k.p pVar) {
        switch (this.f35757a) {
            case 2:
                if (((u0) this.f35758b).f25336a.f29883a.p()) {
                    ((u0) this.f35758b).f25337b.onPanelClosed(108, pVar);
                } else if (((u0) this.f35758b).f25337b.onPreparePanel(0, null, pVar)) {
                    ((u0) this.f35758b).f25337b.onMenuOpened(108, pVar);
                }
                break;
            default:
                k.n nVar = ((ActionMenuView) this.f35758b).f627b0;
                if (nVar != null) {
                    nVar.l(pVar);
                }
                break;
        }
    }

    public final void m(float f10, int i10) {
        u5 u5Var = (u5) this.f35758b;
        u5Var.getClass();
        u5Var.d(i10, Float.floatToRawIntBits(f10));
    }

    public final void n(int i10, long j10) {
        ((u5) this.f35758b).e(i10, j10);
    }

    @Override // j0.o
    public final int o(Object obj) {
        return ((i0.g) obj).f26492b;
    }

    @Override // org.chromium.support_lib_boundary.WebMessageListenerBoundaryInterface
    public final void onPostMessage(WebView webView, InvocationHandler invocationHandler, Uri uri, boolean z10, InvocationHandler invocationHandler2) {
        z3.p pVarWebMessageCompatFromBoundaryInterface = a4.e0.webMessageCompatFromBoundaryInterface((WebMessageBoundaryInterface) ee.b.castToSuppLibClass(WebMessageBoundaryInterface.class, invocationHandler));
        if (pVarWebMessageCompatFromBoundaryInterface != null) {
            JsReplyProxyBoundaryInterface jsReplyProxyBoundaryInterface = (JsReplyProxyBoundaryInterface) ee.b.castToSuppLibClass(JsReplyProxyBoundaryInterface.class, invocationHandler2);
            ((z3.a0) this.f35758b).onPostMessage(webView, pVarWebMessageCompatFromBoundaryInterface, uri, z10, (a4.t) jsReplyProxyBoundaryInterface.getOrCreatePeer(new a4.s(jsReplyProxyBoundaryInterface, 0)));
        }
    }

    @Override // com.bytedance.sdk.openadsdk.api.nativeAd.PAGVideoAdListener
    public final void onVideoAdComplete() {
    }

    @Override // com.bytedance.sdk.openadsdk.api.nativeAd.PAGVideoAdListener
    public final void onVideoAdPaused() {
    }

    @Override // com.bytedance.sdk.openadsdk.api.nativeAd.PAGVideoAdListener
    public final void onVideoAdPlay() {
    }

    @Override // com.bytedance.sdk.openadsdk.api.nativeAd.PAGVideoAdListener
    public final void onVideoError() {
    }

    @Override // j0.o
    public final boolean p(Object obj) {
        return ((i0.g) obj).f26493c;
    }

    @Override // sa.i
    public final Object q(String str) {
        return ((sa.k) this.f35758b).b(str, null);
    }

    public final void r(int i10, zzik zzikVar) {
        u5 u5Var = (u5) this.f35758b;
        u5Var.v(i10, 2);
        u5Var.g(zzikVar);
    }

    public final void s(int i10, d7 d7Var, Object obj) {
        u5 u5Var = (u5) this.f35758b;
        u5Var.v(i10, 3);
        d7Var.d((u6) obj, u5Var.f20444d);
        u5Var.v(i10, 4);
    }

    public final void t(int i10, boolean z10) {
        u5 u5Var = (u5) this.f35758b;
        u5Var.v(i10, 0);
        u5Var.b(z10 ? (byte) 1 : (byte) 0);
    }

    public final void u(int i10, int i11) {
        ((u5) this.f35758b).p(i10, i11);
    }

    public final void v(int i10) {
        ((u5) this.f35758b).v(i10, 4);
    }

    public final void w(int i10, int i11) {
        ((u5) this.f35758b).d(i10, i11);
    }

    public final void x(int i10, long j10) {
        ((u5) this.f35758b).q(i10, j10);
    }

    public final void y(int i10, d7 d7Var, Object obj) {
        u5 u5Var = (u5) this.f35758b;
        u6 u6Var = (u6) obj;
        u5Var.v(i10, 2);
        u5Var.u(((m5) u6Var).a(d7Var));
        d7Var.d(u6Var, u5Var.f20444d);
    }

    public final void z(int i10) {
        ((u5) this.f35758b).v(i10, 3);
    }

    public /* synthetic */ a0(Object obj, int i10) {
        this.f35757a = i10;
        this.f35758b = obj;
    }

    @Override // com.bytedance.sdk.component.ro.fm.lb
    public final void fm(ro roVar, onz onzVar) {
        fhx fhxVarAjl;
        long j10;
        boolean z10;
        long length;
        long j11;
        if (onzVar == null) {
            e6.b.b((e6.b) this.f35758b, 30002, "response is empty");
            return;
        }
        InputStream inputStreamLb = null;
        try {
            ((e6.b) this.f35758b).f25503i = onzVar.yz();
            if (((e6.b) this.f35758b).f25503i) {
                fhxVarAjl = onzVar.ajl();
                try {
                    if (((e6.b) this.f35758b).f25503i && fhxVarAjl != null) {
                        ((e6.b) this.f35758b).f25496b = fhxVarAjl.fm() + ((e6.b) this.f35758b).f25500f;
                        inputStreamLb = fhxVarAjl.lb();
                    }
                    if (inputStreamLb == null) {
                        e6.b.b((e6.b) this.f35758b, 30003, "input_stream is empty");
                        if (inputStreamLb != null) {
                            try {
                                inputStreamLb.close();
                            } catch (Throwable unused) {
                                return;
                            }
                        }
                        if (z10) {
                            if (length == j11) {
                                return;
                            } else {
                                return;
                            }
                        }
                        return;
                    }
                    int i10 = o6.b.f31433j;
                    byte[] bArr = new byte[i10];
                    Object obj = this.f35758b;
                    long j12 = ((e6.b) obj).f25500f;
                    long j13 = ((e6.b) obj).f25496b;
                    Object obj2 = this.f35758b;
                    long j14 = ((e6.b) obj2).f25500f;
                    ((e6.b) obj2).f25505k.irt();
                    int i11 = 0;
                    long j15 = 0;
                    int i12 = 0;
                    long j16 = 0;
                    while (true) {
                        int i13 = inputStreamLb.read(bArr, i12, i10 - i12);
                        if (i13 == -1) {
                            break;
                        }
                        i12 += i13;
                        j16 += (long) i13;
                        int i14 = (j16 % ((long) i10) == j15 || j16 == ((e6.b) this.f35758b).f25496b - ((e6.b) this.f35758b).f25500f) ? 1 : i11;
                        long j17 = ((e6.b) this.f35758b).f25496b;
                        long j18 = ((e6.b) this.f35758b).f25506l;
                        if (i14 != 0) {
                            synchronized (((e6.b) this.f35758b).f25497c) {
                                try {
                                    RandomAccessFile randomAccessFile = ((e6.b) this.f35758b).f25504j;
                                    int iIntValue = Long.valueOf(j12).intValue();
                                    ((e6.b) this.f35758b).f25505k.qhl();
                                    try {
                                        randomAccessFile.seek(iIntValue);
                                        randomAccessFile.write(bArr, i11, i12);
                                    } catch (Throwable unused2) {
                                    }
                                    Object obj3 = this.f35758b;
                                    if (!((e6.b) obj3).f25495a || ((e6.b) obj3).f25506l <= -1) {
                                        j10 = j12;
                                    } else {
                                        Object obj4 = this.f35758b;
                                        j10 = j12;
                                        if (((e6.b) obj4).f25500f + j16 >= ((e6.b) obj4).f25506l) {
                                            ((e6.b) this.f35758b).f25497c.notify();
                                        }
                                    }
                                } finally {
                                }
                            }
                            j12 = j10 + ((long) i12);
                            i12 = 0;
                        }
                        i11 = 0;
                        j15 = 0;
                    }
                    Object obj5 = this.f35758b;
                    long j19 = ((e6.b) obj5).f25500f;
                    long j20 = ((e6.b) obj5).f25496b;
                    long j21 = ((e6.b) this.f35758b).f25496b;
                    long j22 = ((e6.b) this.f35758b).f25500f;
                } catch (Throwable th) {
                    th = th;
                    try {
                        e6.b.b((e6.b) this.f35758b, 30001, th.getMessage());
                        if (inputStreamLb != null) {
                            try {
                                inputStreamLb.close();
                            } catch (Throwable unused3) {
                                return;
                            }
                        }
                        if (fhxVarAjl != null) {
                            fhxVarAjl.close();
                        }
                        onzVar.close();
                        if (((e6.b) this.f35758b).f25503i && ((e6.b) this.f35758b).f25498d.length() == ((e6.b) this.f35758b).f25496b) {
                            e6.b.c((e6.b) this.f35758b);
                            return;
                        }
                        return;
                    } finally {
                        if (inputStreamLb != null) {
                            try {
                                inputStreamLb.close();
                            } catch (Throwable unused4) {
                            }
                        }
                        if (fhxVarAjl != null) {
                            fhxVarAjl.close();
                        }
                        onzVar.close();
                        if (((e6.b) this.f35758b).f25503i && ((e6.b) this.f35758b).f25498d.length() == ((e6.b) this.f35758b).f25496b) {
                            e6.b.c((e6.b) this.f35758b);
                        }
                    }
                }
            } else {
                e6.b.b((e6.b) this.f35758b, onzVar.lb(), onzVar.jnr());
                fhxVarAjl = null;
            }
            if (inputStreamLb != null) {
                try {
                    inputStreamLb.close();
                } catch (Throwable unused5) {
                    return;
                }
            }
            if (fhxVarAjl != null) {
                fhxVarAjl.close();
            }
            onzVar.close();
            if (((e6.b) this.f35758b).f25503i && ((e6.b) this.f35758b).f25498d.length() == ((e6.b) this.f35758b).f25496b) {
                e6.b.c((e6.b) this.f35758b);
            }
        } catch (Throwable th2) {
            th = th2;
            fhxVarAjl = null;
        }
    }

    public a0(u5 u5Var) {
        this.f35757a = 19;
        Charset charset = d6.f20163a;
        if (u5Var != null) {
            this.f35758b = u5Var;
            u5Var.f20444d = this;
            return;
        }
        throw new NullPointerException("output");
    }

    public a0() {
        this.f35757a = 6;
        this.f35758b = new AtomicInteger(0);
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ a0(sa.k kVar) {
        this(kVar, 23);
        this.f35757a = 23;
    }

    public a0(Context context) {
        this.f35757a = 7;
        this.f35758b = context.getApplicationContext();
    }

    public a0(int i10) {
        this.f35757a = i10;
        if (i10 != 22) {
            if (i10 != 25) {
                char[] cArr = t5.p.f32977a;
                this.f35758b = new ArrayDeque(0);
            } else {
                this.f35758b = fc.a.f26038e;
            }
        }
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ a0(io.flutter.embedding.engine.loader.f fVar) {
        this(fVar, 26);
        this.f35757a = 26;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ a0(MaterialButtonGroup materialButtonGroup) {
        this(materialButtonGroup, 20);
        this.f35757a = 20;
    }
}
