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

import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.media3.common.PlaybackException;
import dalvik.system.DexClassLoader;
import java.io.File;
import java.security.GeneralSecurityException;
import java.util.HashMap;

/* JADX INFO: loaded from: classes2.dex */
public final class ii1 {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final HashMap f12528g = new HashMap();

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Object f12534f = new Object();

    @Nullable
    private ai1 zzg;

    public ii1(Context context, ji1 ji1Var, ch1 ch1Var, bh1 bh1Var, boolean z10) {
        this.f12529a = context;
        this.f12530b = ji1Var;
        this.f12531c = ch1Var;
        this.f12532d = bh1Var;
        this.f12533e = z10;
    }

    public final boolean a(bi1 bi1Var) {
        long jCurrentTimeMillis = System.currentTimeMillis();
        try {
            try {
                ai1 ai1Var = new ai1(b(bi1Var).getDeclaredConstructor(Context.class, String.class, byte[].class, Object.class, Bundle.class, Integer.TYPE).newInstance(this.f12529a, "msa-r", bi1Var.a(), null, new Bundle(), 2), bi1Var, this.f12530b, this.f12531c, this.f12533e);
                if (!ai1Var.b()) {
                    throw new zzfwz(4000, "init failed");
                }
                int iD = ai1Var.d();
                if (iD != 0) {
                    StringBuilder sb = new StringBuilder(String.valueOf(iD).length() + 4);
                    sb.append("ci: ");
                    sb.append(iD);
                    throw new zzfwz(PlaybackException.ERROR_CODE_DECODER_INIT_FAILED, sb.toString());
                }
                synchronized (this.f12534f) {
                    ai1 ai1Var2 = this.zzg;
                    if (ai1Var2 != null) {
                        try {
                            ai1Var2.c();
                        } catch (zzfwz e10) {
                            this.f12531c.c(e10.a(), -1L, e10);
                        }
                        this.zzg = ai1Var;
                    } else {
                        this.zzg = ai1Var;
                    }
                }
                this.f12531c.b(3000, System.currentTimeMillis() - jCurrentTimeMillis);
                return true;
            } catch (Exception e11) {
                throw new zzfwz(PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS, e11);
            }
        } catch (zzfwz e12) {
            this.f12531c.c(e12.a(), System.currentTimeMillis() - jCurrentTimeMillis, e12);
            return false;
        } catch (Exception e13) {
            this.f12531c.c(4010, System.currentTimeMillis() - jCurrentTimeMillis, e13);
            return false;
        }
    }

    public final synchronized Class b(bi1 bi1Var) {
        try {
            wi wiVar = bi1Var.f9546a;
            if (wiVar == null) {
                throw new zzfwz(4010, "mc");
            }
            String strB = wiVar.B();
            HashMap map = f12528g;
            Class cls = (Class) map.get(strB);
            if (cls != null) {
                return cls;
            }
            try {
                bh1 bh1Var = this.f12532d;
                File file = bi1Var.f9547b;
                bh1Var.getClass();
                if (!bh1.a(file)) {
                    throw new zzfwz(2026, "VM did not pass signature verification");
                }
                try {
                    File file2 = bi1Var.f9548c;
                    if (!file2.exists()) {
                        file2.mkdirs();
                    }
                    Class<?> clsLoadClass = new DexClassLoader(bi1Var.f9547b.getAbsolutePath(), file2.getAbsolutePath(), null, this.f12529a.getClassLoader()).loadClass("com.google.ccc.abuse.droidguard.DroidGuard");
                    map.put(strB, clsLoadClass);
                    return clsLoadClass;
                } catch (ClassNotFoundException e10) {
                    e = e10;
                    throw new zzfwz(2008, e);
                } catch (IllegalArgumentException e11) {
                    e = e11;
                    throw new zzfwz(2008, e);
                } catch (SecurityException e12) {
                    e = e12;
                    throw new zzfwz(2008, e);
                }
            } catch (GeneralSecurityException e13) {
                throw new zzfwz(2026, e13);
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    @Nullable
    public final eh1 zzb() {
        ai1 ai1Var;
        synchronized (this.f12534f) {
            ai1Var = this.zzg;
        }
        return ai1Var;
    }

    @Nullable
    public final bi1 zzc() {
        synchronized (this.f12534f) {
            try {
                ai1 ai1Var = this.zzg;
                if (ai1Var == null) {
                    return null;
                }
                return ai1Var.f8710b;
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
