package com.google.android.gms.internal.ads;

import android.app.Activity;
import android.content.Context;
import android.util.Base64;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.media3.common.PlaybackException;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: loaded from: classes2.dex */
public final class ai1 implements eh1 {

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ch1 f8712d;

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

    public ai1(Object obj, bi1 bi1Var, ji1 ji1Var, ch1 ch1Var, boolean z10) {
        this.f8709a = obj;
        this.f8710b = bi1Var;
        this.f8711c = ji1Var;
        this.f8712d = ch1Var;
        this.f8713e = z10;
    }

    @Nullable
    private static String zzi(byte[] bArr) {
        if (bArr == null) {
            return null;
        }
        bg bgVarB = cg.B();
        bgVarB.c();
        ((cg) bgVarB.f8617b).F(5);
        zzian zzianVarW = zzian.w(0, bArr.length, bArr);
        bgVarB.c();
        ((cg) bgVarB.f8617b).C(zzianVarW);
        return Base64.encodeToString(((cg) bgVarB.e()).b(), 11);
    }

    @Nullable
    private final synchronized byte[] zzj(Map map, Map map2) {
        Object obj;
        long jCurrentTimeMillis = System.currentTimeMillis();
        try {
            obj = this.f8709a;
        } catch (Exception e10) {
            this.f8712d.c(PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED, System.currentTimeMillis() - jCurrentTimeMillis, e10);
            return null;
        }
        return (byte[]) obj.getClass().getDeclaredMethod("xss", Map.class, Map.class).invoke(obj, null, map2);
    }

    public final synchronized void a(MotionEvent motionEvent) {
        try {
            long jCurrentTimeMillis = System.currentTimeMillis();
            HashMap mapZze = this.f8711c.zze();
            mapZze.put("aid", null);
            mapZze.put("evt", motionEvent);
            Object obj = this.f8709a;
            obj.getClass().getDeclaredMethod("he", Map.class).invoke(obj, mapZze);
            this.f8712d.b(PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED, System.currentTimeMillis() - jCurrentTimeMillis);
        } catch (Exception e10) {
            throw new zzfwz(PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND, e10);
        }
    }

    public final synchronized boolean b() {
        Object obj;
        try {
            obj = this.f8709a;
        } catch (Exception e10) {
            throw new zzfwz(PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED, e10);
        }
        return ((Boolean) obj.getClass().getDeclaredMethod("init", new Class[0]).invoke(obj, new Object[0])).booleanValue();
    }

    public final synchronized void c() {
        try {
            long jCurrentTimeMillis = System.currentTimeMillis();
            Object obj = this.f8709a;
            obj.getClass().getDeclaredMethod("close", new Class[0]).invoke(obj, new Object[0]);
            this.f8712d.b(PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED, System.currentTimeMillis() - jCurrentTimeMillis);
        } catch (Exception e10) {
            throw new zzfwz(PlaybackException.ERROR_CODE_IO_INVALID_HTTP_CONTENT_TYPE, e10);
        }
    }

    public final synchronized int d() {
        Object obj;
        try {
            obj = this.f8709a;
        } catch (Exception e10) {
            throw new zzfwz(PlaybackException.ERROR_CODE_IO_NO_PERMISSION, e10);
        }
        return ((Integer) obj.getClass().getDeclaredMethod("lcs", new Class[0]).invoke(obj, new Object[0])).intValue();
    }

    @Nullable
    public final synchronized String zza(Context context, String str) {
        byte[] bArrZzj;
        try {
            HashMap mapZzb = this.f8711c.zzb();
            mapZzb.put("f", "q");
            mapZzb.put("ctx", context);
            mapZzb.put("aid", null);
            bArrZzj = zzj(null, mapZzb);
            if (this.f8713e) {
                mapZzb.clear();
            }
        } catch (Throwable th) {
            throw th;
        }
        return zzi(bArrZzj);
    }

    @Nullable
    public final synchronized String zzb(Context context, String str, View view, Activity activity) {
        byte[] bArrZzj;
        try {
            HashMap mapZzc = this.f8711c.zzc();
            mapZzc.put("f", "v");
            mapZzc.put("ctx", context);
            mapZzc.put("aid", null);
            mapZzc.put("view", view);
            mapZzc.put("act", activity);
            bArrZzj = zzj(null, mapZzc);
            if (this.f8713e) {
                mapZzc.clear();
            }
        } catch (Throwable th) {
            throw th;
        }
        return zzi(bArrZzj);
    }

    @Nullable
    public final synchronized String zzc(Context context, String str, String str2, View view, Activity activity) {
        byte[] bArrZzj;
        try {
            HashMap mapZzd = this.f8711c.zzd();
            mapZzd.put("f", "c");
            mapZzd.put("ctx", context);
            mapZzd.put("cs", str2);
            mapZzd.put("aid", null);
            mapZzd.put("view", view);
            mapZzd.put("act", activity);
            bArrZzj = zzj(null, mapZzd);
            if (this.f8713e) {
                mapZzd.clear();
            }
        } catch (Throwable th) {
            throw th;
        }
        return zzi(bArrZzj);
    }
}
