package d3;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.os.Build;
import androidx.annotation.Nullable;
import androidx.core.view.q;
import java.io.File;
import java.io.IOException;

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

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

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

    @Nullable
    private static l sCompilationStatus = null;

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

    public static l b() {
        l lVar = new l();
        sCompilationStatus = lVar;
        f24968a.set(lVar);
        return sCompilationStatus;
    }

    /* JADX WARN: Removed duplicated region for block: B:103:0x00f7 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:113:0x00a8 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:20:0x002b  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x002d  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x006f  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x00b2  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x00c3  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x00c5  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x00c8  */
    /* JADX WARN: Removed duplicated region for block: B:85:0x00e7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void c(Context context, boolean z10) {
        int i10;
        boolean z11;
        int i11;
        long length;
        long length2;
        File file;
        k kVarA;
        k kVar;
        int i12;
        AssetFileDescriptor assetFileDescriptorOpenFd;
        if (z10 || sCompilationStatus == null) {
            synchronized (f24969b) {
                if (z10) {
                    i10 = 0;
                    assetFileDescriptorOpenFd = context.getAssets().openFd("dexopt/baseline.prof");
                    if (assetFileDescriptorOpenFd.getLength() <= 0) {
                    }
                    assetFileDescriptorOpenFd.close();
                    i11 = Build.VERSION.SDK_INT;
                    if (i11 >= 28) {
                        File file2 = new File(new File("/data/misc/profiles/ref/", context.getPackageName()), "primary.prof");
                        length = file2.length();
                        if (file2.exists()) {
                            File file3 = new File(new File("/data/misc/profiles/cur/0/", context.getPackageName()), "primary.prof");
                            length2 = file3.length();
                            if (file3.exists()) {
                                long jA = a(context);
                                file = new File(context.getFilesDir(), "profileInstalled");
                                if (file.exists()) {
                                }
                                if (kVarA == null) {
                                    if (z11) {
                                    }
                                }
                                if (z10) {
                                    i10 = 2;
                                }
                                kVar = new k(1, (kVarA == null && kVarA.f24965b == 2 && i10 == 1 && length < kVarA.f24967d) ? 3 : i10, jA, length2);
                                if (kVarA != null) {
                                    kVar.b(file);
                                }
                                b();
                                return;
                            }
                        }
                    }
                    b();
                    return;
                }
                if (sCompilationStatus != null) {
                    return;
                }
                i10 = 0;
                try {
                    assetFileDescriptorOpenFd = context.getAssets().openFd("dexopt/baseline.prof");
                    try {
                        z11 = assetFileDescriptorOpenFd.getLength() <= 0;
                        assetFileDescriptorOpenFd.close();
                    } finally {
                    }
                } catch (IOException unused) {
                    z11 = false;
                }
                i11 = Build.VERSION.SDK_INT;
                if (i11 >= 28 && i11 != 30) {
                    File file22 = new File(new File("/data/misc/profiles/ref/", context.getPackageName()), "primary.prof");
                    length = file22.length();
                    boolean z12 = !file22.exists() && length > 0;
                    File file32 = new File(new File("/data/misc/profiles/cur/0/", context.getPackageName()), "primary.prof");
                    length2 = file32.length();
                    boolean z13 = !file32.exists() && length2 > 0;
                    try {
                        long jA2 = a(context);
                        file = new File(context.getFilesDir(), "profileInstalled");
                        if (file.exists()) {
                            kVarA = null;
                        } else {
                            try {
                                kVarA = k.a(file);
                            } catch (IOException unused2) {
                                b();
                                return;
                            }
                        }
                        if (kVarA == null && kVarA.f24966c == jA2 && (i12 = kVarA.f24965b) != 2) {
                            i10 = i12;
                        } else if (z11) {
                            i10 = 327680;
                        } else if (z12) {
                            i10 = 1;
                        } else if (z13) {
                            i10 = 2;
                        }
                        if (z10 && z13 && i10 != 1) {
                            i10 = 2;
                        }
                        kVar = new k(1, (kVarA == null && kVarA.f24965b == 2 && i10 == 1 && length < kVarA.f24967d) ? 3 : i10, jA2, length2);
                        if (kVarA != null || !kVarA.equals(kVar)) {
                            try {
                                kVar.b(file);
                            } catch (IOException unused3) {
                            }
                        }
                        b();
                        return;
                    } catch (PackageManager.NameNotFoundException unused4) {
                        b();
                        return;
                    }
                }
                b();
                return;
            }
        }
    }
}
