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

import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import java.io.File;
import java.security.GeneralSecurityException;
import java.util.HashSet;

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

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

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

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

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

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

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

    public gi1(Context context, zzbch zzbchVar, uh1 uh1Var, boolean z10) {
        this.f11758e = false;
        this.f11754a = context;
        this.f11756c = Integer.toString(zzbchVar.zza());
        this.f11755b = context.getSharedPreferences("pcvmspf", 0);
        this.f11757d = uh1Var;
        this.f11758e = z10;
    }

    public static String d(si siVar) {
        vi viVarI = wi.I();
        String strB = siVar.B().B();
        viVarI.c();
        ((wi) viVarI.f8617b).K(strB);
        String strC = siVar.B().C();
        viVarI.c();
        ((wi) viVarI.f8617b).L(strC);
        long jE = siVar.B().E();
        viVarI.c();
        ((wi) viVarI.f8617b).N(jE);
        long jF = siVar.B().F();
        viVarI.c();
        ((wi) viVarI.f8617b).O(jF);
        long jD = siVar.B().D();
        viVarI.c();
        ((wi) viVarI.f8617b).M(jD);
        return i8.f.a(((wi) viVarI.e()).b());
    }

    @Nullable
    private final wi zzk(int i10) {
        ua2 ua2VarB;
        String str = this.f11756c;
        SharedPreferences sharedPreferences = this.f11755b;
        String string = i10 == 1 ? sharedPreferences.getString("LATMTD".concat(String.valueOf(str)), null) : sharedPreferences.getString("FBAMTD".concat(String.valueOf(str)), null);
        if (string == null) {
            return null;
        }
        long jCurrentTimeMillis = System.currentTimeMillis();
        try {
            byte[] bArrB = i8.f.b(string);
            zzian zzianVarW = zzian.w(0, bArrB.length, bArrB);
            if (this.f11758e) {
                ua2 ua2Var = ua2.f17195b;
                int i11 = fa2.f11138a;
                ua2VarB = ua2.f17196c;
            } else {
                ua2VarB = ua2.b();
            }
            return wi.H(zzianVarW, ua2VarB);
        } catch (zzicg unused) {
            return null;
        } catch (NullPointerException unused2) {
            e(2029, jCurrentTimeMillis);
            return null;
        } catch (RuntimeException unused3) {
            e(2032, jCurrentTimeMillis);
            return null;
        }
    }

    public final boolean a(si siVar) {
        long jCurrentTimeMillis = System.currentTimeMillis();
        synchronized (f11753f) {
            try {
                if (!ih1.h0(new File(c(siVar.B().B()), "pcbc"), siVar.D().z())) {
                    e(4020, jCurrentTimeMillis);
                    return false;
                }
                String strD = d(siVar);
                SharedPreferences.Editor editorEdit = this.f11755b.edit();
                editorEdit.putString("LATMTD".concat(String.valueOf(this.f11756c)), strD);
                boolean zCommit = editorEdit.commit();
                if (zCommit) {
                    e(5015, jCurrentTimeMillis);
                } else {
                    e(4021, jCurrentTimeMillis);
                }
                return zCommit;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final boolean b() {
        long jCurrentTimeMillis = System.currentTimeMillis();
        synchronized (f11753f) {
            try {
                wi wiVarZzk = zzk(1);
                if (wiVarZzk == null) {
                    e(4025, jCurrentTimeMillis);
                    return false;
                }
                File fileC = c(wiVarZzk.B());
                if (!new File(fileC, "pcam.jar").exists()) {
                    e(4026, jCurrentTimeMillis);
                    return false;
                }
                if (new File(fileC, "pcbc").exists()) {
                    e(5019, jCurrentTimeMillis);
                    return true;
                }
                e(4027, jCurrentTimeMillis);
                return false;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final File c(String str) {
        return new File(new File(this.f11754a.getDir("pccache", 0), this.f11756c), str);
    }

    public final void e(int i10, long j10) {
        this.f11757d.zza(i10, j10);
    }

    /* JADX WARN: Code restructure failed: missing block: B:44:0x00e8, code lost:
    
        if (com.google.android.gms.internal.ads.bh1.a(r6) == false) goto L45;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean zza(@NonNull si siVar, @Nullable fi1 fi1Var) {
        File fileC;
        long jCurrentTimeMillis = System.currentTimeMillis();
        synchronized (f11753f) {
            try {
                wi wiVarZzk = zzk(1);
                String strB = siVar.B().B();
                if (wiVarZzk != null && wiVarZzk.B().equals(strB)) {
                    e(4014, jCurrentTimeMillis);
                    return false;
                }
                long jCurrentTimeMillis2 = System.currentTimeMillis();
                File fileC2 = c(strB);
                if (fileC2.exists()) {
                    String str = true != fileC2.isDirectory() ? SessionDescription.SUPPORTED_SDP_VERSION : "1";
                    String str2 = true != fileC2.isFile() ? SessionDescription.SUPPORTED_SDP_VERSION : "1";
                    StringBuilder sb = new StringBuilder(7);
                    sb.append("d:");
                    sb.append(str);
                    sb.append(",f:");
                    sb.append(str2);
                    this.f11757d.zzb(4023, jCurrentTimeMillis2, sb.toString());
                    e(4015, jCurrentTimeMillis2);
                } else if (!fileC2.mkdirs()) {
                    this.f11757d.zzb(4024, jCurrentTimeMillis2, "cw:".concat(true != fileC2.canWrite() ? SessionDescription.SUPPORTED_SDP_VERSION : "1"));
                    e(4015, jCurrentTimeMillis2);
                    return false;
                }
                fileC = c(strB);
                File file = new File(fileC, "pcam.jar");
                File file2 = new File(fileC, "pcbc");
                if (!ih1.h0(file, siVar.C().z())) {
                    e(4016, jCurrentTimeMillis);
                    return false;
                }
                if (!ih1.h0(file2, siVar.D().z())) {
                    e(4017, jCurrentTimeMillis);
                    return false;
                }
                if (fi1Var != null) {
                    try {
                        ((bh1) ((ru) fi1Var).f16225b).getClass();
                    } catch (GeneralSecurityException unused) {
                    }
                }
                String strD = d(siVar);
                long jCurrentTimeMillis3 = System.currentTimeMillis();
                SharedPreferences sharedPreferences = this.f11755b;
                String string = sharedPreferences.getString("LATMTD".concat(String.valueOf(this.f11756c)), null);
                SharedPreferences.Editor editorEdit = sharedPreferences.edit();
                editorEdit.putString("LATMTD".concat(String.valueOf(this.f11756c)), strD);
                if (string != null) {
                    editorEdit.putString("FBAMTD".concat(String.valueOf(this.f11756c)), string);
                }
                if (!editorEdit.commit()) {
                    e(4019, jCurrentTimeMillis3);
                    return false;
                }
                HashSet hashSet = new HashSet();
                wi wiVarZzk2 = zzk(1);
                if (wiVarZzk2 != null) {
                    hashSet.add(wiVarZzk2.B());
                }
                wi wiVarZzk3 = zzk(2);
                if (wiVarZzk3 != null) {
                    hashSet.add(wiVarZzk3.B());
                }
                for (File file3 : new File(this.f11754a.getDir("pccache", 0), this.f11756c).listFiles()) {
                    if (!hashSet.contains(file3.getName())) {
                        ih1.M0(file3);
                    }
                }
                e(5014, jCurrentTimeMillis);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
        e(4018, jCurrentTimeMillis);
        ih1.M0(fileC);
        return false;
    }

    @Nullable
    public final bi1 zzc(int i10) {
        long jCurrentTimeMillis = System.currentTimeMillis();
        synchronized (f11753f) {
            try {
                wi wiVarZzk = zzk(1);
                if (wiVarZzk == null) {
                    e(4022, jCurrentTimeMillis);
                    return null;
                }
                File fileC = c(wiVarZzk.B());
                File file = new File(fileC, "pcam.jar");
                if (!file.exists()) {
                    file = new File(fileC, "pcam");
                }
                File file2 = new File(fileC, "pcbc");
                File file3 = new File(fileC, "pcopt");
                e(5016, jCurrentTimeMillis);
                return new bi1(wiVarZzk, file, file2, file3);
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
