package defpackage;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Process;
import android.os.StrictMode;
import android.os.UserManager;
import com.google.android.gms.internal.measurement.zzaeh;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.AbstractCollection;
import java.util.List;
import java.util.logging.Level;
import java.util.regex.Pattern;

/* JADX INFO: renamed from: ᵲᐧᵕ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4512 {

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static Boolean f17163;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final Uri f17164;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final String f17165;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C5429 f17166;

    public C4512(C5429 c5429, String str) {
        this.f17166 = c5429;
        this.f17165 = str;
        Context context = c5429.f20598;
        Pattern pattern = AbstractC5091.f19184;
        C2781 c2781 = new C2781(context);
        c2781.m6763("phenotype");
        StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 4);
        sb.append("/");
        sb.append(str);
        sb.append(".pb");
        c2781.m6765(sb.toString());
        this.f17164 = c2781.m6767();
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final boolean m9565() {
        C5432 c5432M9810 = this.f17166.f20603.m9810();
        return c5432M9810.m11057() && ((AbstractCollection) c5432M9810.m11065()).contains(EnumC0526.f2709);
    }

    /* JADX WARN: Removed duplicated region for block: B:80:0x023d  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x0243  */
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C5067 m9566() {
        String strSubstring;
        int i;
        char c;
        C5541 c5541;
        String str;
        String str2;
        C2831 c2831;
        String str3 = this.f17165;
        C5429 c5429 = this.f17166;
        Context context = c5429.f20598;
        InterfaceC5188 interfaceC5188 = c5429.f20606;
        int i2 = Build.VERSION.SDK_INT;
        if (i2 < 24) {
            UserManager userManager = AbstractC0837.f3734;
        } else if (!AbstractC0837.m2977(context)) {
            return new C5067(C3095.m7179(), new C4240(3, 17, 7));
        }
        if (f17163 == null) {
            if (i2 >= 28) {
                f17163 = Boolean.valueOf(Process.isIsolated());
            } else {
                try {
                    Object objInvoke = Process.class.getMethod("isIsolated", null).invoke(Process.class, null);
                    objInvoke.getClass();
                    f17163 = (Boolean) objInvoke;
                } catch (ReflectiveOperationException unused) {
                    f17163 = Boolean.FALSE;
                }
            }
        }
        if (f17163.booleanValue()) {
            return new C5067(C3095.m7179(), new C4240(3, 18, 7));
        }
        C2151 c2151M9809 = c5429.f20603.m9809();
        AbstractC4667 abstractC4667 = c2151M9809.f8536;
        EnumC0526 enumC0526 = EnumC0526.f2709;
        C3310 c3310 = AbstractC4355.f16568;
        int iIndexOf = str3.indexOf("#");
        if (iIndexOf >= 0) {
            strSubstring = str3.substring(0, iIndexOf);
        } else {
            if (str3.contains("@")) {
                ᵕᵩʽᵲ.ᵮᵣᵗˈ("Invalid package name: ".concat(str3));
                return null;
            }
            strSubstring = str3;
        }
        int i3 = 6;
        if (!c2151M9809.f8535) {
            i = 14;
        } else if (!c2151M9809.f8539 || !c2151M9809.f8534.contains(enumC0526)) {
            i = 3;
        } else if (abstractC4667.mo1614() != 0) {
            List list = c2151M9809.f8544;
            i = (list.isEmpty() || list.contains(strSubstring)) ? c2151M9809.f8540.contains(strSubstring) ? 6 : 0 : 5;
        } else {
            i = 4;
        }
        if (i != 0) {
            c5541 = new C5541(null, new C4240(i));
        } else {
            try {
                str = c2151M9809.f8537;
                if (str.isEmpty()) {
                    AbstractC2677 abstractC2677 = (AbstractC2677) c5429.f20599.get();
                    if (abstractC2677.mo1972()) {
                        str = ((ApplicationInfo) abstractC2677.mo1974()).dataDir;
                    } else {
                        ᵽˊᵘᵬ.ᵶˇᵱ(Level.WARNING, c5429.m11045(), (Exception) null, "Unable to get GMS application info, using defaults.", new Object[0]);
                        c5541 = new C5541(C2831.f10855, new C4240(3, 7, 7));
                    }
                }
                str2 = File.separator;
                c = 0;
            } catch (Exception e) {
                e = e;
                c = 0;
            }
            try {
                String str4 = c2151M9809.f8542;
                StringBuilder sb = new StringBuilder(String.valueOf(str).length() + String.valueOf(str2).length() + String.valueOf(str4).length());
                sb.append(str);
                sb.append(str2);
                sb.append(str4);
                String string = sb.toString();
                C5398 c5398 = new C5398(abstractC4667, str3);
                Uri.Builder builderScheme = new Uri.Builder().scheme("file");
                String string2 = c5398.m11015().toString();
                StringBuilder sb2 = new StringBuilder(String.valueOf(str2).length() + string.length() + String.valueOf(str2).length() + string2.length());
                sb2.append(str2);
                sb2.append(string);
                sb2.append(str2);
                sb2.append(string2);
                Uri uriBuild = builderScheme.appendEncodedPath(sb2.toString()).build();
                StrictMode.ThreadPolicy threadPolicy = StrictMode.getThreadPolicy();
                StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(threadPolicy).permitDiskReads().build());
                try {
                    try {
                        c5541 = new C5541((C2831) ((C0355) interfaceC5188.get()).m1676(uriBuild, new C1013(i3, c2151M9809.f8541.m2605())), new C4240(5, 2, 7));
                    } finally {
                        StrictMode.setThreadPolicy(threadPolicy);
                    }
                } catch (zzaeh e2) {
                    ᵽˊᵘᵬ.ᵶˇᵱ(Level.SEVERE, c5429.m11045(), e2, "Failed to parse snapshot from shared storage for %s", new Object[]{str3});
                    c5541 = new C5541(null, new C4240(9));
                } catch (FileNotFoundException unused2) {
                    ᵽˊᵘᵬ.ᵶˇᵱ(Level.INFO, c5429.m11045(), (Exception) null, "Shared storage file not found for %s", new Object[]{str3});
                    c5541 = new C5541(null, new C4240(8));
                }
            } catch (Exception e3) {
                e = e3;
                Level level = Level.WARNING;
                ScheduledExecutorServiceC3721 scheduledExecutorServiceC3721M11045 = c5429.m11045();
                Object[] objArr = new Object[1];
                objArr[c] = str3;
                ᵽˊᵘᵬ.ᵶˇᵱ(level, scheduledExecutorServiceC3721M11045, e, "Failed to read shared file for %s", objArr);
                c5541 = new C5541(C2831.f10855, new C4240(3, 10, 7));
            }
            C4240 c4240 = c5541.f20922;
            c2831 = c5541.f20923;
            if (c2831 == null) {
                return new C5067(c2831, c4240);
            }
            int i4 = c4240.f16171;
            try {
                C0355 c0355 = (C0355) interfaceC5188.get();
                Uri uri = this.f17164;
                InterfaceC0673 interfaceC0673 = (InterfaceC0673) C3095.m7179().mo1186(7);
                C1743 c1743 = C1743.f6982;
                int i5 = AbstractC1986.f7873;
                C1743 c17432 = C1743.f6981;
                InputStream inputStream = ᵻᵪ.ᵵᵬᵽ(c0355.m1675(uri));
                try {
                    AbstractC4729 abstractC4729M7526 = ((C3283) interfaceC0673).m7526(inputStream, c17432);
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    return new C5067((C3095) abstractC4729M7526, new C4240(4, i4, 7));
                } finally {
                }
            } catch (IOException | RuntimeException unused3) {
                Level level2 = Level.INFO;
                ScheduledExecutorServiceC3721 scheduledExecutorServiceC3721M110452 = c5429.m11045();
                Object[] objArr2 = new Object[1];
                objArr2[c] = str3;
                ᵽˊᵘᵬ.ᵶˇᵱ(level2, scheduledExecutorServiceC3721M110452, (Exception) null, "Unable to retrieve flag snapshot for %s, using defaults.", objArr2);
                return m9565() ? new C5067(C2831.f10855, new C4240(3, 16, 7)) : new C5067(C3095.m7179(), new C4240(3, 11, 7));
            }
        }
        c = 0;
        C4240 c42402 = c5541.f20922;
        c2831 = c5541.f20923;
        if (c2831 == null) {
        }
    }
}
