package defpackage;

import android.accounts.Account;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.zzsg;
import com.google.android.gms.internal.measurement.zzsi;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.regex.Pattern;

/* JADX INFO: renamed from: ʾˈᵗʒ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0238 extends AbstractC4253 {

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

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public String f1783;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final Object f1781 = new Object();

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C4591 f1780 = new C4591();

    public C0238(C1711 c1711) {
        this.f1782 = c1711.f6834;
    }

    @Override // defpackage.InterfaceC4309
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final boolean mo1412(Uri uri) throws zzsg {
        if (m1417(uri)) {
            throw new zzsg("Android backend cannot perform remote operations without a remote backend");
        }
        return ᵿᵽᵤ.ᵶˇᵱ(mo1413(uri)).exists();
    }

    @Override // defpackage.AbstractC4253
    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final Uri mo1413(Uri uri) throws zzsg, zzsi {
        if (m1417(uri)) {
            throw new zzsi("Operation across authorities is not allowed.");
        }
        File fileMo1414 = mo1414(uri);
        Uri.Builder builderPath = new Uri.Builder().scheme("file").authority("").path("/");
        C3975 c3975M9561 = AbstractC4509.m9561();
        builderPath.path(fileMo1414.getAbsolutePath());
        C2598 c2598M8718 = c3975M9561.m8718();
        Pattern pattern = AbstractC4408.f16718;
        return builderPath.encodedFragment(c2598M8718.isEmpty() ? null : "transform=".concat(new C2571("+").m6300(c2598M8718))).build();
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0131  */
    @Override // defpackage.InterfaceC4309
    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final File mo1414(Uri uri) throws zzsg, zzsi {
        File externalFilesDir;
        Account account;
        String str;
        if (m1417(uri)) {
            C1685.m4568("operation is not permitted in other authorities.");
            return null;
        }
        Context context = this.f1782;
        if (!uri.getScheme().equals("android")) {
            throw new zzsi("Scheme must be 'android'");
        }
        if (uri.getPathSegments().isEmpty()) {
            throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
        }
        if (!TextUtils.isEmpty(uri.getQuery())) {
            throw new zzsi("Did not expect uri to have query");
        }
        ArrayList arrayList = new ArrayList(uri.getPathSegments());
        String str2 = (String) arrayList.get(0);
        switch (str2.hashCode()) {
            case -1820761141:
                if (str2.equals("external")) {
                    externalFilesDir = context.getExternalFilesDir(null);
                    File file = new File(externalFilesDir, TextUtils.join(File.separator, arrayList.subList(1, arrayList.size())));
                    if (!AbstractC0837.m2978(context)) {
                        synchronized (this.f1781) {
                            try {
                                if (this.f1783 == null) {
                                    this.f1783 = ᵹˊᵫˋ.ᵸˆˁ(context.createDeviceProtectedStorageContext()).getParentFile().getAbsolutePath();
                                }
                                str = this.f1783;
                            } finally {
                            }
                            break;
                        }
                        if (!file.getAbsolutePath().startsWith(str)) {
                            throw new zzsg("Cannot access credential-protected data from direct boot");
                        }
                    }
                    return file;
                }
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
            case 94416770:
                if (str2.equals("cache")) {
                    externalFilesDir = context.getCacheDir();
                    File file2 = new File(externalFilesDir, TextUtils.join(File.separator, arrayList.subList(1, arrayList.size())));
                    if (!AbstractC0837.m2978(context)) {
                    }
                    return file2;
                }
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
            case 97434231:
                if (str2.equals("files")) {
                    externalFilesDir = ᵹˊᵫˋ.ᵸˆˁ(context);
                    File file22 = new File(externalFilesDir, TextUtils.join(File.separator, arrayList.subList(1, arrayList.size())));
                    if (!AbstractC0837.m2978(context)) {
                    }
                    return file22;
                }
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
            case 835260319:
                if (str2.equals("managed")) {
                    File file3 = new File(ᵹˊᵫˋ.ᵸˆˁ(context), "managed");
                    if (arrayList.size() >= 3) {
                        try {
                            String str3 = (String) arrayList.get(2);
                            Account account2 = AbstractC3188.f12096;
                            if ("shared".equals(str3)) {
                                account = AbstractC3188.f12096;
                            } else {
                                int iIndexOf = str3.indexOf(58);
                                ᵘᵞʿⁱ.ˁˌᵩ(iIndexOf >= 0, "Malformed account", new Object[0]);
                                account = new Account(str3.substring(iIndexOf + 1), str3.substring(0, iIndexOf));
                            }
                            if (!AbstractC3188.f12096.equals(account)) {
                                throw new zzsi("AccountManager cannot be null");
                            }
                        } catch (IllegalArgumentException e) {
                            throw new zzsi(e);
                        }
                    }
                    externalFilesDir = file3;
                    File file222 = new File(externalFilesDir, TextUtils.join(File.separator, arrayList.subList(1, arrayList.size())));
                    if (!AbstractC0837.m2978(context)) {
                    }
                    return file222;
                }
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
            case 988548496:
                if (str2.equals("directboot-cache")) {
                    int i = Build.VERSION.SDK_INT;
                    if (i < 24) {
                        throw new zzsi(AbstractC2704.m6517(i, "Direct boot only exists on N or greater: current SDK "));
                    }
                    externalFilesDir = context.createDeviceProtectedStorageContext().getCacheDir();
                    File file2222 = new File(externalFilesDir, TextUtils.join(File.separator, arrayList.subList(1, arrayList.size())));
                    if (!AbstractC0837.m2978(context)) {
                    }
                    return file2222;
                }
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
            case 991565957:
                if (str2.equals("directboot-files")) {
                    int i2 = Build.VERSION.SDK_INT;
                    if (i2 < 24) {
                        throw new zzsi(AbstractC2704.m6517(i2, "Direct boot only exists on N or greater: current SDK "));
                    }
                    externalFilesDir = context.createDeviceProtectedStorageContext().getFilesDir();
                    File file22222 = new File(externalFilesDir, TextUtils.join(File.separator, arrayList.subList(1, arrayList.size())));
                    if (!AbstractC0837.m2978(context)) {
                    }
                    return file22222;
                }
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
            default:
                throw new zzsi(String.format("Path must start with a valid logical location: %s", uri));
        }
    }

    @Override // defpackage.InterfaceC4309
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C3641 mo1415(Uri uri) throws zzsg {
        if (m1417(uri)) {
            throw new zzsg("Android backend cannot perform remote operations without a remote backend");
        }
        File file = ᵿᵽᵤ.ᵶˇᵱ(mo1413(uri));
        return new C3641(new FileInputStream(file), file);
    }

    @Override // defpackage.InterfaceC4309
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final String mo1416() {
        return "android";
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final boolean m1417(Uri uri) {
        return (TextUtils.isEmpty(uri.getAuthority()) || this.f1782.getPackageName().equals(uri.getAuthority())) ? false : true;
    }
}
