package L1;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.os.Build;
import java.io.File;
import java.io.IOException;
import s.l;

/* JADX INFO: loaded from: classes.dex */
public abstract class j {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final l f3971a = new l();

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static C4.f f3973c = null;

    public static long a(Context context) {
        PackageManager packageManager = context.getApplicationContext().getPackageManager();
        return Build.VERSION.SDK_INT >= 33 ? h.a(packageManager, context).lastUpdateTime : packageManager.getPackageInfo(context.getPackageName(), 0).lastUpdateTime;
    }

    public static C4.f b() {
        C4.f fVar = new C4.f(9);
        f3973c = fVar;
        f3971a.j(fVar);
        return f3973c;
    }

    /* JADX WARN: Removed duplicated region for block: B:101:0x00f4 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:109:0x00a8 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:20:0x002c  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x002e  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x006f  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00b2  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00c3  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x00c5  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x00c8  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void c(Context context, boolean z8) {
        int i;
        boolean z9;
        int i5;
        long length;
        File file;
        i iVarA;
        i iVar;
        int i8;
        AssetFileDescriptor assetFileDescriptorOpenFd;
        if (z8 || f3973c == null) {
            synchronized (f3972b) {
                if (z8) {
                    i = 0;
                    assetFileDescriptorOpenFd = context.getAssets().openFd("dexopt/baseline.prof");
                    if (assetFileDescriptorOpenFd.getLength() <= 0) {
                    }
                    assetFileDescriptorOpenFd.close();
                    i5 = Build.VERSION.SDK_INT;
                    if (i5 >= 28) {
                        File file2 = new File(new File("/data/misc/profiles/ref/", context.getPackageName()), "primary.prof");
                        long length2 = file2.length();
                        if (file2.exists()) {
                            File file3 = new File(new File("/data/misc/profiles/cur/0/", context.getPackageName()), "primary.prof");
                            length = file3.length();
                            if (file3.exists()) {
                                long jA = a(context);
                                file = new File(context.getFilesDir(), "profileInstalled");
                                if (file.exists()) {
                                }
                                if (iVarA == null) {
                                    if (z9) {
                                    }
                                }
                                if (z8) {
                                    i = 2;
                                }
                                if (iVarA != null) {
                                    i = 3;
                                }
                                iVar = new i(1, i, jA, length);
                                if (iVarA != null) {
                                    iVar.b(file);
                                }
                                b();
                                return;
                            }
                        }
                    }
                    b();
                    return;
                }
                if (f3973c != null) {
                    return;
                }
                i = 0;
                try {
                    assetFileDescriptorOpenFd = context.getAssets().openFd("dexopt/baseline.prof");
                    try {
                        z9 = assetFileDescriptorOpenFd.getLength() <= 0;
                        assetFileDescriptorOpenFd.close();
                    } finally {
                    }
                } catch (IOException unused) {
                    z9 = false;
                }
                i5 = Build.VERSION.SDK_INT;
                if (i5 >= 28 && i5 != 30) {
                    File file22 = new File(new File("/data/misc/profiles/ref/", context.getPackageName()), "primary.prof");
                    long length22 = file22.length();
                    boolean z10 = !file22.exists() && length22 > 0;
                    File file32 = new File(new File("/data/misc/profiles/cur/0/", context.getPackageName()), "primary.prof");
                    length = file32.length();
                    boolean z11 = !file32.exists() && length > 0;
                    try {
                        long jA2 = a(context);
                        file = new File(context.getFilesDir(), "profileInstalled");
                        if (file.exists()) {
                            iVarA = null;
                        } else {
                            try {
                                iVarA = i.a(file);
                            } catch (IOException unused2) {
                                b();
                                return;
                            }
                        }
                        if (iVarA == null && iVarA.f3969c == jA2 && (i8 = iVarA.f3968b) != 2) {
                            i = i8;
                        } else if (z9) {
                            i = 327680;
                        } else if (z10) {
                            i = 1;
                        } else if (z11) {
                            i = 2;
                        }
                        if (z8 && z11 && i != 1) {
                            i = 2;
                        }
                        if (iVarA != null && iVarA.f3968b == 2 && i == 1 && length22 < iVarA.f3970d) {
                            i = 3;
                        }
                        iVar = new i(1, i, jA2, length);
                        if (iVarA != null || !iVarA.equals(iVar)) {
                            try {
                                iVar.b(file);
                            } catch (IOException unused3) {
                            }
                        }
                        b();
                        return;
                    } catch (PackageManager.NameNotFoundException unused4) {
                        b();
                        return;
                    }
                }
                b();
                return;
            }
        }
    }
}
