导航菜单

页面标题

页面副标题

Betterhalf.ai v5.1.1 - FileSystemModule.java 源代码

正在查看: Betterhalf.ai v5.1.1 应用的 FileSystemModule.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package expo.modules.filesystem;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.util.Base64;
import android.util.Log;
import androidx.core.content.FileProvider;
import androidx.documentfile.provider.DocumentFile;
import androidx.tracing.Trace;
import com.google.common.net.HttpHeaders;
import com.google.firebase.analytics.FirebaseAnalytics;
import expo.modules.av.player.PlayerData;
import expo.modules.core.errors.ModuleDestroyedException;
import expo.modules.filesystem.FileSystemModule;
import expo.modules.interfaces.filesystem.FilePermissionModuleInterface;
import expo.modules.interfaces.filesystem.Permission;
import expo.modules.interfaces.permissions.PermissionsResponse;
import expo.modules.kotlin.Promise;
import expo.modules.kotlin.events.BasicEventListener;
import expo.modules.kotlin.events.EventListenerWithSenderAndPayload;
import expo.modules.kotlin.events.EventName;
import expo.modules.kotlin.events.OnActivityResultPayload;
import expo.modules.kotlin.exception.Exceptions;
import expo.modules.kotlin.functions.AsyncFunctionComponent;
import expo.modules.kotlin.functions.AsyncFunctionWithPromiseComponent;
import expo.modules.kotlin.modules.Module;
import expo.modules.kotlin.modules.ModuleDefinitionBuilder;
import expo.modules.kotlin.modules.ModuleDefinitionData;
import expo.modules.kotlin.types.AnyType;
import expo.modules.kotlin.types.LazyKType;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.net.CookieHandler;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import kotlin.Metadata;
import kotlin.NoWhenBranchMatchedException;
import kotlin.TuplesKt;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.CoroutineContext;
import kotlin.io.CloseableKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlin.ranges.RangesKt;
import kotlin.reflect.KType;
import kotlin.text.StringsKt;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.CoroutineScopeKt;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Dispatchers;
import okhttp3.Call;
import okhttp3.Headers;
import okhttp3.JavaNetCookieJar;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.ForwardingSource;
import okio.Okio;
import okio.Source;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

@Metadata(d1 = {"\u0000¾\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010%\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0001\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0012\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\t\b\u0016\u0018\u00002\u00020\u0001:\u0005VWXYZB\u0005¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0018\u001a\u00020\u00162\u0006\u0010\u0019\u001a\u00020\u001aH\u0002J \u0010\u001b\u001a\u00020\u001c2\u0006\u0010\u001d\u001a\u00020\u001e2\u0006\u0010\u001f\u001a\u00020 2\u0006\u0010\u0019\u001a\u00020\u001aH\u0002J(\u0010!\u001a\u00020\"2\u0006\u0010#\u001a\u00020\u00122\u0006\u0010$\u001a\u00020\u00122\u0006\u0010\u001d\u001a\u00020\u001e2\u0006\u0010\u001f\u001a\u00020 H\u0002J\b\u0010%\u001a\u00020&H\u0017J\u001b\u0010'\u001a\u0004\u0018\u00010(2\u0006\u0010)\u001a\u00020*H\u0082@ø\u0001\u0000¢\u0006\u0002\u0010+J\u0010\u0010,\u001a\u00020-2\u0006\u0010.\u001a\u00020\u001aH\u0002J\u0018\u0010/\u001a\u00020-2\u0006\u00100\u001a\u00020\u00162\u0006\u00101\u001a\u000202H\u0002J \u0010/\u001a\u00020-2\u0006\u00100\u001a\u00020\u00162\u0006\u00101\u001a\u0002022\u0006\u00103\u001a\u00020\u0012H\u0002J\u0010\u00104\u001a\u00020-2\u0006\u0010\u0019\u001a\u00020\u001aH\u0002J\u0010\u00105\u001a\u0002062\u0006\u0010\u0019\u001a\u00020\u001aH\u0002J\u0010\u00107\u001a\u0002082\u0006\u00100\u001a\u00020\u0016H\u0002J\u0010\u00109\u001a\u00020:2\u0006\u0010;\u001a\u000208H\u0002J\u0012\u0010<\u001a\u0004\u0018\u00010=2\u0006\u00100\u001a\u00020\u0016H\u0002J\u0010\u0010>\u001a\u00020?2\u0006\u00100\u001a\u00020\u0016H\u0002J\u0010\u0010@\u001a\u00020\u00122\u0006\u0010\u0019\u001a\u00020\u001aH\u0002J\u0010\u0010A\u001a\u0002082\u0006\u00100\u001a\u00020\u0016H\u0002J\u0012\u0010B\u001a\u0002082\b\u0010C\u001a\u0004\u0018\u00010\u0012H\u0003J\u0010\u0010D\u001a\u00020\u00122\u0006\u0010E\u001a\u00020\u0012H\u0002J\u001a\u0010F\u001a\n\u0012\u0004\u0012\u000202\u0018\u00010G2\b\u0010H\u001a\u0004\u0018\u00010\u0012H\u0002J\u0016\u0010I\u001a\b\u0012\u0004\u0012\u0002020G2\u0006\u00100\u001a\u00020\u0016H\u0002J\u0018\u0010J\u001a\n\u0012\u0004\u0012\u000202\u0018\u00010G2\u0006\u00100\u001a\u00020\u0016H\u0002J \u0010K\u001a\u00020-2\u0006\u0010L\u001a\u00020=2\u0006\u0010M\u001a\u00020\u001a2\u0006\u0010N\u001a\u00020\u0015H\u0002J\u0010\u0010O\u001a\u00020P2\u0006\u0010Q\u001a\u00020RH\u0002J\f\u0010S\u001a\u00020-*\u00020\u0016H\u0002J\f\u0010T\u001a\u00020-*\u00020\u0016H\u0002J\f\u0010U\u001a\u00020\u001a*\u00020\u0016H\u0002R\u0010\u0010\u0003\u001a\u0004\u0018\u00010\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\u0005\u001a\u00020\u00068BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u0007\u0010\bR\u0010\u0010\t\u001a\u0004\u0018\u00010\nX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\fX\u0082\u0004¢\u0006\u0002\n\u0000R\u0016\u0010\r\u001a\u0004\u0018\u00010\u00048BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u000e\u0010\u000fR\u001a\u0010\u0010\u001a\u000e\u0012\u0004\u0012\u00020\u0012\u0012\u0004\u0012\u00020\u00130\u0011X\u0082\u0004¢\u0006\u0002\n\u0000R\u0018\u0010\u0014\u001a\u00020\u0015*\u00020\u00168BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u0014\u0010\u0017\u0082\u0002\u0004\n\u0002\b\u0019¨\u0006["}, d2 = {"Lexpo/modules/filesystem/FileSystemModule;", "Lexpo/modules/kotlin/modules/Module;", "()V", "client", "Lokhttp3/OkHttpClient;", "context", "Landroid/content/Context;", "getContext", "()Landroid/content/Context;", "dirPermissionsRequest", "Lexpo/modules/kotlin/Promise;", "moduleCoroutineScope", "Lkotlinx/coroutines/CoroutineScope;", "okHttpClient", "getOkHttpClient", "()Lokhttp3/OkHttpClient;", "taskHandlers", "", "", "Lexpo/modules/filesystem/FileSystemModule$TaskHandler;", "isSAFUri", "", "Landroid/net/Uri;", "(Landroid/net/Uri;)Z", "contentUriFromFile", "file", "Ljava/io/File;", "createRequestBody", "Lokhttp3/RequestBody;", "options", "Lexpo/modules/filesystem/FileSystemUploadOptions;", "decorator", "Lexpo/modules/filesystem/RequestBodyDecorator;", "createUploadRequest", "Lokhttp3/Request;", "url", "fileUriString", "definition", "Lexpo/modules/kotlin/modules/ModuleDefinitionData;", "downloadResumableTask", "", "params", "Lexpo/modules/filesystem/FileSystemModule$DownloadResumableTaskParams;", "(Lexpo/modules/filesystem/FileSystemModule$DownloadResumableTaskParams;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "ensureDirExists", "", "dir", "ensurePermission", PlayerData.STATUS_URI_KEY_PATH, "permission", "Lexpo/modules/interfaces/filesystem/Permission;", "errorMsg", "forceDelete", "getFileSize", "", "getInputStream", "Ljava/io/InputStream;", "getInputStreamBytes", "", "inputStream", "getNearestSAFFile", "Landroidx/documentfile/provider/DocumentFile;", "getOutputStream", "Ljava/io/OutputStream;", "md5", "openAssetInputStream", "openResourceInputStream", "resourceName", "parseFileUri", "uriStr", "permissionsForPath", "Ljava/util/EnumSet;", "path", "permissionsForSAFUri", "permissionsForUri", "transformFilesFromSAF", "documentFile", "outputDir", "copy", "translateHeaders", "Landroid/os/Bundle;", "headers", "Lokhttp3/Headers;", "checkIfFileDirExists", "checkIfFileExists", "toFile", "DownloadResumableTaskParams", "DownloadTaskHandler", "ProgressListener", "ProgressResponseBody", "TaskHandler", "expo-file-system_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
public class FileSystemModule extends Module {
    private OkHttpClient client;
    private Promise dirPermissionsRequest;
    private final Map<String, TaskHandler> taskHandlers = new HashMap();
    private final CoroutineScope moduleCoroutineScope = CoroutineScopeKt.CoroutineScope(Dispatchers.getDefault());

    @Metadata(d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\bà\u0080\u0001\u0018\u00002\u00020\u0001J \u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u00052\u0006\u0010\u0006\u001a\u00020\u00052\u0006\u0010\u0007\u001a\u00020\bH&¨\u0006\t"}, d2 = {"Lexpo/modules/filesystem/FileSystemModule$ProgressListener;", "", "update", "", "bytesRead", "", "contentLength", "done", "", "expo-file-system_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    public interface ProgressListener {
        void update(long bytesRead, long contentLength, boolean done);
    }

    @Metadata(k = 3, mv = {1, 8, 0}, xi = 48)
    public class WhenMappings {
        public static final int[] $EnumSwitchMapping$0;

        static {
            int[] iArr = new int[FileSystemUploadType.values().length];
            try {
                iArr[FileSystemUploadType.BINARY_CONTENT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[FileSystemUploadType.MULTIPART.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    public final Context getContext() {
        Context reactContext = getAppContext().getReactContext();
        if (reactContext != null) {
            return reactContext;
        }
        throw new Exceptions.AppContextLost();
    }

    @Override
    public ModuleDefinitionData definition() {
        FileSystemModule fileSystemModule = this;
        Trace.beginSection("[ExpoModulesCore] " + (fileSystemModule.getClass() + ".ModuleDefinition"));
        try {
            final ModuleDefinitionBuilder moduleDefinitionBuilder = new ModuleDefinitionBuilder(fileSystemModule);
            moduleDefinitionBuilder.Name("ExponentFileSystem");
            moduleDefinitionBuilder.Constants(TuplesKt.to("documentDirectory", Uri.fromFile(getContext().getFilesDir()).toString() + "/"), TuplesKt.to("cacheDirectory", Uri.fromFile(getContext().getCacheDir()).toString() + "/"), TuplesKt.to("bundleDirectory", "asset:///"));
            moduleDefinitionBuilder.Events("expo-file-system.downloadProgress", "expo-file-system.uploadProgress");
            moduleDefinitionBuilder.getEventListeners().put(EventName.MODULE_CREATE, new BasicEventListener(EventName.MODULE_CREATE, new Function0<Unit>() {
                {
                    super(0);
                }

                public Object invoke() {
                    m592invoke();
                    return Unit.INSTANCE;
                }

                public final void m592invoke() {
                    try {
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        File filesDir = fileSystemModule2.getContext().getFilesDir();
                        Intrinsics.checkNotNullExpressionValue(filesDir, "context.filesDir");
                        fileSystemModule2.ensureDirExists(filesDir);
                        FileSystemModule fileSystemModule3 = FileSystemModule.this;
                        File cacheDir = fileSystemModule3.getContext().getCacheDir();
                        Intrinsics.checkNotNullExpressionValue(cacheDir, "context.cacheDir");
                        fileSystemModule3.ensureDirExists(cacheDir);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("getInfoAsync", InfoOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("getInfoAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(java.lang.Object[] r14, expo.modules.kotlin.Promise r15) {
                    throw new UnsupportedOperationException("Method not decompiled: expo.modules.filesystem.FileSystemModule$definition$lambda$48$$inlined$AsyncFunction$2.invoke(java.lang.Object[], expo.modules.kotlin.Promise):void");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("getInfoAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(InfoOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(InfoOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final java.lang.Object invoke(java.lang.Object[] r15) {
                    throw new UnsupportedOperationException("Method not decompiled: expo.modules.filesystem.FileSystemModule$definition$lambda$48$$inlined$AsyncFunction$5.invoke(java.lang.Object[]):java.lang.Object");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("readAsStringAsync", ReadingOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("readAsStringAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    InputStream openResourceInputStream;
                    InputStream openAssetInputStream;
                    File file;
                    InputStream inputStream;
                    byte[] inputStreamBytes;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj != null) {
                        String str = (String) obj;
                        ReadingOptions readingOptions = (ReadingOptions) promise;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.READ);
                        if (readingOptions.getEncoding() == EncodingType.BASE64) {
                            inputStream = FileSystemModule.this.getInputStream(parse);
                            InputStream inputStream2 = inputStream;
                            try {
                                InputStream inputStream3 = inputStream2;
                                if (readingOptions.getLength() == null || readingOptions.getPosition() == null) {
                                    inputStreamBytes = FileSystemModule.this.getInputStreamBytes(inputStream3);
                                    Base64.encodeToString(inputStreamBytes, 2);
                                } else {
                                    byte[] bArr = new byte[readingOptions.getLength().intValue()];
                                    inputStream3.skip(readingOptions.getPosition().intValue());
                                    Base64.encodeToString(bArr, 0, inputStream3.read(bArr, 0, readingOptions.getLength().intValue()), 2);
                                }
                                Unit unit = Unit.INSTANCE;
                                CloseableKt.closeFinally(inputStream2, (Throwable) null);
                                return;
                            } catch (Throwable th) {
                                try {
                                    throw th;
                                } catch (Throwable th2) {
                                    CloseableKt.closeFinally(inputStream2, th);
                                    throw th2;
                                }
                            }
                        }
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            file = FileSystemModule.this.toFile(parse);
                            IOUtils.toString(new FileInputStream(file));
                            return;
                        }
                        if (Intrinsics.areEqual(parse.getScheme(), "asset")) {
                            openAssetInputStream = FileSystemModule.this.openAssetInputStream(parse);
                            IOUtils.toString(openAssetInputStream);
                            return;
                        } else if (parse.getScheme() == null) {
                            openResourceInputStream = FileSystemModule.this.openResourceInputStream(str);
                            IOUtils.toString(openResourceInputStream);
                            return;
                        } else {
                            isSAFUri = FileSystemModule.this.isSAFUri(parse);
                            if (isSAFUri) {
                                IOUtils.toString(FileSystemModule.this.getContext().getContentResolver().openInputStream(parse));
                                return;
                            }
                            throw new IOException("Unsupported scheme for location '" + parse + "'.");
                        }
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("readAsStringAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(ReadingOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(ReadingOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    InputStream openResourceInputStream;
                    InputStream openAssetInputStream;
                    File file;
                    InputStream inputStream;
                    byte[] inputStreamBytes;
                    String encodeToString;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 != null) {
                        ReadingOptions readingOptions = (ReadingOptions) obj2;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.READ);
                        if (readingOptions.getEncoding() == EncodingType.BASE64) {
                            inputStream = FileSystemModule.this.getInputStream(parse);
                            InputStream inputStream2 = inputStream;
                            try {
                                InputStream inputStream3 = inputStream2;
                                if (readingOptions.getLength() == null || readingOptions.getPosition() == null) {
                                    inputStreamBytes = FileSystemModule.this.getInputStreamBytes(inputStream3);
                                    encodeToString = Base64.encodeToString(inputStreamBytes, 2);
                                } else {
                                    byte[] bArr = new byte[readingOptions.getLength().intValue()];
                                    inputStream3.skip(readingOptions.getPosition().intValue());
                                    encodeToString = Base64.encodeToString(bArr, 0, inputStream3.read(bArr, 0, readingOptions.getLength().intValue()), 2);
                                }
                                Unit unit = Unit.INSTANCE;
                                CloseableKt.closeFinally(inputStream2, (Throwable) null);
                                return encodeToString;
                            } catch (Throwable th) {
                                try {
                                    throw th;
                                } catch (Throwable th2) {
                                    CloseableKt.closeFinally(inputStream2, th);
                                    throw th2;
                                }
                            }
                        }
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            file = FileSystemModule.this.toFile(parse);
                            return IOUtils.toString(new FileInputStream(file));
                        }
                        if (Intrinsics.areEqual(parse.getScheme(), "asset")) {
                            openAssetInputStream = FileSystemModule.this.openAssetInputStream(parse);
                            return IOUtils.toString(openAssetInputStream);
                        }
                        if (parse.getScheme() == null) {
                            openResourceInputStream = FileSystemModule.this.openResourceInputStream(str);
                            return IOUtils.toString(openResourceInputStream);
                        }
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            return IOUtils.toString(FileSystemModule.this.getContext().getContentResolver().openInputStream(parse));
                        }
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.ReadingOptions");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("writeAsStringAsync", WritingOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("writeAsStringAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    OutputStream outputStream;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 != null) {
                        String str2 = (String) obj2;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        EncodingType encoding = ((WritingOptions) promise).getEncoding();
                        outputStream = FileSystemModule.this.getOutputStream(parse);
                        OutputStreamWriter outputStreamWriter = outputStream;
                        try {
                            OutputStream outputStream2 = outputStreamWriter;
                            if (encoding == EncodingType.BASE64) {
                                outputStream2.write(Base64.decode(str2, 0));
                            } else {
                                outputStreamWriter = new OutputStreamWriter(outputStream2);
                                try {
                                    outputStreamWriter.write(str2);
                                    Unit unit = Unit.INSTANCE;
                                    CloseableKt.closeFinally(outputStreamWriter, (Throwable) null);
                                } finally {
                                }
                            }
                            Unit unit2 = Unit.INSTANCE;
                            CloseableKt.closeFinally(outputStreamWriter, (Throwable) null);
                        } finally {
                        }
                    } else {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("writeAsStringAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(WritingOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(WritingOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    OutputStream outputStream;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 != null) {
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        EncodingType encoding = ((WritingOptions) obj3).getEncoding();
                        outputStream = FileSystemModule.this.getOutputStream(parse);
                        OutputStreamWriter outputStreamWriter = outputStream;
                        try {
                            OutputStream outputStream2 = outputStreamWriter;
                            if (encoding == EncodingType.BASE64) {
                                outputStream2.write(Base64.decode(str2, 0));
                            } else {
                                outputStreamWriter = new OutputStreamWriter(outputStream2);
                                try {
                                    outputStreamWriter.write(str2);
                                    Unit unit = Unit.INSTANCE;
                                    CloseableKt.closeFinally(outputStreamWriter, (Throwable) null);
                                } finally {
                                }
                            }
                            Unit unit2 = Unit.INSTANCE;
                            CloseableKt.closeFinally(outputStreamWriter, (Throwable) null);
                            return Unit.INSTANCE;
                        } finally {
                        }
                    } else {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.WritingOptions");
                    }
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("deleteAsync", DeletingOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("deleteAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj != null) {
                        DeletingOptions deletingOptions = (DeletingOptions) promise;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                        Uri parse = Uri.parse(slashifyFilePath);
                        Uri withAppendedPath = Uri.withAppendedPath(parse, "..");
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(withAppendedPath, "appendedUri");
                        fileSystemModule2.ensurePermission(withAppendedPath, Permission.WRITE, "Location '" + parse + "' isn't deletable.");
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            FileSystemModule fileSystemModule3 = FileSystemModule.this;
                            Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                            file = fileSystemModule3.toFile(parse);
                            if (file.exists()) {
                                FileUtils.forceDelete(file);
                                return;
                            } else {
                                if (!deletingOptions.getIdempotent()) {
                                    throw new FileSystemFileNotFoundException(parse);
                                }
                                return;
                            }
                        }
                        FileSystemModule fileSystemModule4 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        isSAFUri = fileSystemModule4.isSAFUri(parse);
                        if (isSAFUri) {
                            nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                            if (nearestSAFFile != null && nearestSAFFile.exists()) {
                                nearestSAFFile.delete();
                                return;
                            } else {
                                if (!deletingOptions.getIdempotent()) {
                                    throw new FileSystemFileNotFoundException(parse);
                                }
                                return;
                            }
                        }
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("deleteAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DeletingOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(DeletingOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 != null) {
                        DeletingOptions deletingOptions = (DeletingOptions) obj2;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        Uri withAppendedPath = Uri.withAppendedPath(parse, "..");
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(withAppendedPath, "appendedUri");
                        fileSystemModule2.ensurePermission(withAppendedPath, Permission.WRITE, "Location '" + parse + "' isn't deletable.");
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            FileSystemModule fileSystemModule3 = FileSystemModule.this;
                            Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                            file = fileSystemModule3.toFile(parse);
                            if (file.exists()) {
                                FileUtils.forceDelete(file);
                            } else if (!deletingOptions.getIdempotent()) {
                                throw new FileSystemFileNotFoundException(parse);
                            }
                        } else {
                            FileSystemModule fileSystemModule4 = FileSystemModule.this;
                            Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                            isSAFUri = fileSystemModule4.isSAFUri(parse);
                            if (isSAFUri) {
                                nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                                if (nearestSAFFile != null && nearestSAFFile.exists()) {
                                    nearestSAFFile.delete();
                                } else if (!deletingOptions.getIdempotent()) {
                                    throw new FileSystemFileNotFoundException(parse);
                                }
                            } else {
                                throw new IOException("Unsupported scheme for location '" + parse + "'.");
                            }
                        }
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.DeletingOptions");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("moveAsync", RelocatingOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("moveAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    String slashifyFilePath2;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    File file;
                    File file2;
                    File file3;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    RelocatingOptions relocatingOptions = (RelocatingOptions) promise;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getFrom());
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Uri withAppendedPath = Uri.withAppendedPath(parse, "..");
                    Intrinsics.checkNotNullExpressionValue(withAppendedPath, "withAppendedPath(fromUri, \"..\")");
                    fileSystemModule2.ensurePermission(withAppendedPath, Permission.WRITE, "Location '" + parse + "' isn't movable.");
                    slashifyFilePath2 = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getTo());
                    Uri parse2 = Uri.parse(slashifyFilePath2);
                    FileSystemModule fileSystemModule3 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse2, "toUri");
                    fileSystemModule3.ensurePermission(parse2, Permission.WRITE);
                    if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                        FileSystemModule fileSystemModule4 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, "fromUri");
                        file2 = fileSystemModule4.toFile(parse);
                        file3 = FileSystemModule.this.toFile(parse2);
                        if (!file2.renameTo(file3)) {
                            throw new FileSystemCannotMoveFileException(parse, parse2);
                        }
                        return;
                    }
                    FileSystemModule fileSystemModule5 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse, "fromUri");
                    isSAFUri = fileSystemModule5.isSAFUri(parse);
                    if (isSAFUri) {
                        nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                        if (nearestSAFFile != null && nearestSAFFile.exists()) {
                            file = FileSystemModule.this.toFile(parse2);
                            FileSystemModule.this.transformFilesFromSAF(nearestSAFFile, file, false);
                            return;
                        }
                        throw new FileSystemCannotMoveFileException(parse, parse2);
                    }
                    throw new IOException("Unsupported scheme for location '" + parse + "'.");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("moveAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(RelocatingOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(RelocatingOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    String slashifyFilePath2;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    File file;
                    File file2;
                    File file3;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj != null) {
                        RelocatingOptions relocatingOptions = (RelocatingOptions) obj;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getFrom());
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Uri withAppendedPath = Uri.withAppendedPath(parse, "..");
                        Intrinsics.checkNotNullExpressionValue(withAppendedPath, "withAppendedPath(fromUri, \"..\")");
                        fileSystemModule2.ensurePermission(withAppendedPath, Permission.WRITE, "Location '" + parse + "' isn't movable.");
                        slashifyFilePath2 = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getTo());
                        Uri parse2 = Uri.parse(slashifyFilePath2);
                        FileSystemModule fileSystemModule3 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse2, "toUri");
                        fileSystemModule3.ensurePermission(parse2, Permission.WRITE);
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            FileSystemModule fileSystemModule4 = FileSystemModule.this;
                            Intrinsics.checkNotNullExpressionValue(parse, "fromUri");
                            file2 = fileSystemModule4.toFile(parse);
                            file3 = FileSystemModule.this.toFile(parse2);
                            if (!file2.renameTo(file3)) {
                                throw new FileSystemCannotMoveFileException(parse, parse2);
                            }
                        } else {
                            FileSystemModule fileSystemModule5 = FileSystemModule.this;
                            Intrinsics.checkNotNullExpressionValue(parse, "fromUri");
                            isSAFUri = fileSystemModule5.isSAFUri(parse);
                            if (isSAFUri) {
                                nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                                if (nearestSAFFile != null && nearestSAFFile.exists()) {
                                    file = FileSystemModule.this.toFile(parse2);
                                    FileSystemModule.this.transformFilesFromSAF(nearestSAFFile, file, false);
                                } else {
                                    throw new FileSystemCannotMoveFileException(parse, parse2);
                                }
                            } else {
                                throw new IOException("Unsupported scheme for location '" + parse + "'.");
                            }
                        }
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.RelocatingOptions");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("copyAsync", RelocatingOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("copyAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    String slashifyFilePath2;
                    boolean isSAFUri;
                    InputStream openResourceInputStream;
                    File file;
                    InputStream openAssetInputStream;
                    File file2;
                    File file3;
                    DocumentFile nearestSAFFile;
                    File file4;
                    File file5;
                    File file6;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    RelocatingOptions relocatingOptions = (RelocatingOptions) promise;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getFrom());
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse, "fromUri");
                    fileSystemModule2.ensurePermission(parse, Permission.READ, "Location '" + parse + "' isn't readable.");
                    slashifyFilePath2 = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getTo());
                    Uri parse2 = Uri.parse(slashifyFilePath2);
                    FileSystemModule fileSystemModule3 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse2, "toUri");
                    fileSystemModule3.ensurePermission(parse2, Permission.WRITE);
                    if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                        file5 = FileSystemModule.this.toFile(parse);
                        file6 = FileSystemModule.this.toFile(parse2);
                        if (file5.isDirectory()) {
                            FileUtils.copyDirectory(file5, file6);
                            return;
                        } else {
                            FileUtils.copyFile(file5, file6);
                            return;
                        }
                    }
                    isSAFUri = FileSystemModule.this.isSAFUri(parse);
                    if (isSAFUri) {
                        nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                        if (nearestSAFFile != null && nearestSAFFile.exists()) {
                            file4 = FileSystemModule.this.toFile(parse2);
                            FileSystemModule.this.transformFilesFromSAF(nearestSAFFile, file4, true);
                            return;
                        }
                        throw new FileSystemCopyFailedException(parse);
                    }
                    if (Intrinsics.areEqual(parse.getScheme(), FirebaseAnalytics.Param.CONTENT)) {
                        InputStream openInputStream = FileSystemModule.this.getContext().getContentResolver().openInputStream(parse);
                        file3 = FileSystemModule.this.toFile(parse2);
                        IOUtils.copy(openInputStream, new FileOutputStream(file3));
                    } else if (Intrinsics.areEqual(parse.getScheme(), "asset")) {
                        openAssetInputStream = FileSystemModule.this.openAssetInputStream(parse);
                        file2 = FileSystemModule.this.toFile(parse2);
                        IOUtils.copy(openAssetInputStream, new FileOutputStream(file2));
                    } else {
                        if (parse.getScheme() == null) {
                            openResourceInputStream = FileSystemModule.this.openResourceInputStream(relocatingOptions.getFrom());
                            file = FileSystemModule.this.toFile(parse2);
                            IOUtils.copy(openResourceInputStream, new FileOutputStream(file));
                            return;
                        }
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("copyAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(RelocatingOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(RelocatingOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    String slashifyFilePath2;
                    boolean isSAFUri;
                    InputStream openResourceInputStream;
                    File file;
                    InputStream openAssetInputStream;
                    File file2;
                    File file3;
                    DocumentFile nearestSAFFile;
                    File file4;
                    File file5;
                    File file6;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj != null) {
                        RelocatingOptions relocatingOptions = (RelocatingOptions) obj;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getFrom());
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, "fromUri");
                        fileSystemModule2.ensurePermission(parse, Permission.READ, "Location '" + parse + "' isn't readable.");
                        slashifyFilePath2 = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getTo());
                        Uri parse2 = Uri.parse(slashifyFilePath2);
                        FileSystemModule fileSystemModule3 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse2, "toUri");
                        fileSystemModule3.ensurePermission(parse2, Permission.WRITE);
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            file5 = FileSystemModule.this.toFile(parse);
                            file6 = FileSystemModule.this.toFile(parse2);
                            if (file5.isDirectory()) {
                                FileUtils.copyDirectory(file5, file6);
                            } else {
                                FileUtils.copyFile(file5, file6);
                            }
                            return Unit.INSTANCE;
                        }
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                            if (nearestSAFFile != null && nearestSAFFile.exists()) {
                                file4 = FileSystemModule.this.toFile(parse2);
                                FileSystemModule.this.transformFilesFromSAF(nearestSAFFile, file4, true);
                                return Unit.INSTANCE;
                            }
                            throw new FileSystemCopyFailedException(parse);
                        }
                        if (Intrinsics.areEqual(parse.getScheme(), FirebaseAnalytics.Param.CONTENT)) {
                            InputStream openInputStream = FileSystemModule.this.getContext().getContentResolver().openInputStream(parse);
                            file3 = FileSystemModule.this.toFile(parse2);
                            return Integer.valueOf(IOUtils.copy(openInputStream, new FileOutputStream(file3)));
                        }
                        if (Intrinsics.areEqual(parse.getScheme(), "asset")) {
                            openAssetInputStream = FileSystemModule.this.openAssetInputStream(parse);
                            file2 = FileSystemModule.this.toFile(parse2);
                            return Integer.valueOf(IOUtils.copy(openAssetInputStream, new FileOutputStream(file2)));
                        }
                        if (parse.getScheme() == null) {
                            openResourceInputStream = FileSystemModule.this.openResourceInputStream(relocatingOptions.getFrom());
                            file = FileSystemModule.this.toFile(parse2);
                            return Integer.valueOf(IOUtils.copy(openResourceInputStream, new FileOutputStream(file)));
                        }
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.RelocatingOptions");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("makeDirectoryAsync", MakeDirectoryOptions.class == Promise.class ? new AsyncFunctionWithPromiseComponent("makeDirectoryAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj != null) {
                        MakeDirectoryOptions makeDirectoryOptions = (MakeDirectoryOptions) promise;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            file = FileSystemModule.this.toFile(parse);
                            boolean isDirectory = file.isDirectory();
                            boolean intermediates = makeDirectoryOptions.getIntermediates();
                            if (intermediates ? file.mkdirs() : file.mkdir()) {
                                return;
                            }
                            if (!intermediates || !isDirectory) {
                                throw new FileSystemCannotCreateDirectoryException(parse);
                            }
                            return;
                        }
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("makeDirectoryAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(MakeDirectoryOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(MakeDirectoryOptions.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 != null) {
                        MakeDirectoryOptions makeDirectoryOptions = (MakeDirectoryOptions) obj2;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        if (!Intrinsics.areEqual(parse.getScheme(), "file")) {
                            throw new IOException("Unsupported scheme for location '" + parse + "'.");
                        }
                        file = FileSystemModule.this.toFile(parse);
                        boolean isDirectory = file.isDirectory();
                        boolean intermediates = makeDirectoryOptions.getIntermediates();
                        if (!(intermediates ? file.mkdirs() : file.mkdir()) && (!intermediates || !isDirectory)) {
                            throw new FileSystemCannotCreateDirectoryException(parse);
                        }
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.MakeDirectoryOptions");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("readDirectoryAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("readDirectoryAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) promise);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                    fileSystemModule2.ensurePermission(parse, Permission.READ);
                    if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                        file = FileSystemModule.this.toFile(parse);
                        File[] listFiles = file.listFiles();
                        if (listFiles == null) {
                            throw new FileSystemCannotReadDirectoryException(parse);
                        }
                        ArrayList arrayList = new ArrayList(listFiles.length);
                        int length = listFiles.length;
                        for (int i = 0; i < length; i++) {
                            File file2 = listFiles[i];
                            arrayList.add(file2 != null ? file2.getName() : null);
                        }
                        return;
                    }
                    isSAFUri = FileSystemModule.this.isSAFUri(parse);
                    if (isSAFUri) {
                        throw new FileSystemUnsupportedSchemeException();
                    }
                    throw new IOException("Unsupported scheme for location '" + parse + "'.");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("readDirectoryAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) objArr[0]);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                    fileSystemModule2.ensurePermission(parse, Permission.READ);
                    if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                        file = FileSystemModule.this.toFile(parse);
                        File[] listFiles = file.listFiles();
                        if (listFiles == null) {
                            throw new FileSystemCannotReadDirectoryException(parse);
                        }
                        ArrayList arrayList = new ArrayList(listFiles.length);
                        int length = listFiles.length;
                        for (int i = 0; i < length; i++) {
                            File file2 = listFiles[i];
                            arrayList.add(file2 != null ? file2.getName() : null);
                        }
                        return arrayList;
                    }
                    isSAFUri = FileSystemModule.this.isSAFUri(parse);
                    if (isSAFUri) {
                        throw new FileSystemUnsupportedSchemeException();
                    }
                    throw new IOException("Unsupported scheme for location '" + parse + "'.");
                }
            }));
            AsyncFunctionComponent asyncFunctionComponent = new AsyncFunctionComponent("getTotalDiskCapacityAsync", new AnyType[0], new Function1<Object[], Object>() {
                public final Object invoke(Object[] objArr) {
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
                    return Double.valueOf(RangesKt.coerceAtMost(BigInteger.valueOf(statFs.getBlockCountLong()).multiply(BigInteger.valueOf(statFs.getBlockSizeLong())).doubleValue(), Math.pow(2.0d, 53.0d) - 1));
                }
            });
            moduleDefinitionBuilder.getAsyncFunctions().put("getTotalDiskCapacityAsync", asyncFunctionComponent);
            AsyncFunctionComponent asyncFunctionComponent2 = asyncFunctionComponent;
            AsyncFunctionComponent asyncFunctionComponent3 = new AsyncFunctionComponent("getFreeDiskStorageAsync", new AnyType[0], new Function1<Object[], Object>() {
                public final Object invoke(Object[] objArr) {
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
                    return Double.valueOf(RangesKt.coerceAtMost(BigInteger.valueOf(statFs.getAvailableBlocksLong()).multiply(BigInteger.valueOf(statFs.getBlockSizeLong())).doubleValue(), Math.pow(2.0d, 53.0d) - 1));
                }
            });
            moduleDefinitionBuilder.getAsyncFunctions().put("getFreeDiskStorageAsync", asyncFunctionComponent3);
            AsyncFunctionComponent asyncFunctionComponent4 = asyncFunctionComponent3;
            moduleDefinitionBuilder.getAsyncFunctions().put("getContentUriAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("getContentUriAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    File file;
                    Uri contentUriFromFile;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    String str = (String) promise;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse, "fileUri");
                    fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                    FileSystemModule.this.ensurePermission(parse, Permission.READ);
                    FileSystemModule.this.checkIfFileDirExists(parse);
                    if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                        file = FileSystemModule.this.toFile(parse);
                        contentUriFromFile = FileSystemModule.this.contentUriFromFile(file);
                        contentUriFromFile.toString();
                        return;
                    }
                    throw new FileSystemUnreadableDirectoryException(str);
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("getContentUriAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    File file;
                    Uri contentUriFromFile;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj != null) {
                        String str = (String) obj;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, "fileUri");
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        FileSystemModule.this.ensurePermission(parse, Permission.READ);
                        FileSystemModule.this.checkIfFileDirExists(parse);
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            file = FileSystemModule.this.toFile(parse);
                            contentUriFromFile = FileSystemModule.this.contentUriFromFile(file);
                            return contentUriFromFile.toString();
                        }
                        throw new FileSystemUnreadableDirectoryException(str);
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("readSAFDirectoryAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("readSAFDirectoryAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) promise);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                    fileSystemModule2.ensurePermission(parse, Permission.READ);
                    isSAFUri = FileSystemModule.this.isSAFUri(parse);
                    if (isSAFUri) {
                        DocumentFile fromTreeUri = DocumentFile.fromTreeUri(FileSystemModule.this.getContext(), parse);
                        if (fromTreeUri == null || !fromTreeUri.exists() || !fromTreeUri.isDirectory()) {
                            throw new FileSystemCannotReadDirectoryException(parse);
                        }
                        DocumentFile[] listFiles = fromTreeUri.listFiles();
                        Intrinsics.checkNotNullExpressionValue(listFiles, "file.listFiles()");
                        ArrayList arrayList = new ArrayList(listFiles.length);
                        for (DocumentFile documentFile : listFiles) {
                            arrayList.add(documentFile.getUri().toString());
                        }
                        return;
                    }
                    throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI. Try using FileSystem.readDirectoryAsync instead.");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("readSAFDirectoryAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj != null) {
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.READ);
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            DocumentFile fromTreeUri = DocumentFile.fromTreeUri(FileSystemModule.this.getContext(), parse);
                            if (fromTreeUri == null || !fromTreeUri.exists() || !fromTreeUri.isDirectory()) {
                                throw new FileSystemCannotReadDirectoryException(parse);
                            }
                            DocumentFile[] listFiles = fromTreeUri.listFiles();
                            Intrinsics.checkNotNullExpressionValue(listFiles, "file.listFiles()");
                            ArrayList arrayList = new ArrayList(listFiles.length);
                            for (DocumentFile documentFile : listFiles) {
                                arrayList.add(documentFile.getUri().toString());
                            }
                            return arrayList;
                        }
                        throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI. Try using FileSystem.readDirectoryAsync instead.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("makeSAFDirectoryAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("makeSAFDirectoryAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj != null) {
                        String str = (String) promise;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                            if (nearestSAFFile != null && !nearestSAFFile.isDirectory()) {
                                throw new FileSystemCannotCreateDirectoryException(parse);
                            }
                            DocumentFile createDirectory = nearestSAFFile != null ? nearestSAFFile.createDirectory(str) : null;
                            if (createDirectory == null) {
                                throw new FileSystemCannotCreateDirectoryException(null);
                            }
                            Intrinsics.checkNotNullExpressionValue(createDirectory, "dirName.let { dir?.creat…eDirectoryException(null)");
                            createDirectory.getUri().toString();
                            return;
                        }
                        throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI. Try using FileSystem.makeDirectoryAsync instead.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("makeSAFDirectoryAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 != null) {
                        String str2 = (String) obj2;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                            if (nearestSAFFile != null && !nearestSAFFile.isDirectory()) {
                                throw new FileSystemCannotCreateDirectoryException(parse);
                            }
                            DocumentFile createDirectory = nearestSAFFile != null ? nearestSAFFile.createDirectory(str2) : null;
                            if (createDirectory == null) {
                                throw new FileSystemCannotCreateDirectoryException(null);
                            }
                            Intrinsics.checkNotNullExpressionValue(createDirectory, "dirName.let { dir?.creat…eDirectoryException(null)");
                            return createDirectory.getUri().toString();
                        }
                        throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI. Try using FileSystem.makeDirectoryAsync instead.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("createSAFFileAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("createSAFFileAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 != null) {
                        String str2 = (String) obj2;
                        String str3 = (String) promise;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                            if (nearestSAFFile == null || !nearestSAFFile.isDirectory()) {
                                throw new FileSystemCannotCreateFileException(parse);
                            }
                            DocumentFile createFile = nearestSAFFile.createFile(str3, str2);
                            if (createFile == null) {
                                throw new FileSystemCannotCreateFileException(null);
                            }
                            Intrinsics.checkNotNullExpressionValue(createFile, "dir.createFile(mimeType,…CreateFileException(null)");
                            createFile.getUri().toString();
                            return;
                        }
                        throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("createSAFFileAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 != null) {
                        String str3 = (String) obj3;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        isSAFUri = FileSystemModule.this.isSAFUri(parse);
                        if (isSAFUri) {
                            nearestSAFFile = FileSystemModule.this.getNearestSAFFile(parse);
                            if (nearestSAFFile == null || !nearestSAFFile.isDirectory()) {
                                throw new FileSystemCannotCreateFileException(parse);
                            }
                            DocumentFile createFile = nearestSAFFile.createFile(str3, str2);
                            if (createFile == null) {
                                throw new FileSystemCannotCreateFileException(null);
                            }
                            Intrinsics.checkNotNullExpressionValue(createFile, "dir.createFile(mimeType,…CreateFileException(null)");
                            return createFile.getUri().toString();
                        }
                        throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("requestDirectoryPermissionsAsync", Promise.class == Promise.class ? new AsyncFunctionWithPromiseComponent("requestDirectoryPermissionsAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    Promise promise2;
                    String slashifyFilePath;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    String str = (String) objArr[0];
                    Activity currentActivity = FileSystemModule.this.getAppContext().getCurrentActivity();
                    if (currentActivity != null) {
                        promise2 = FileSystemModule.this.dirPermissionsRequest;
                        if (promise2 != null) {
                            throw new FileSystemPendingPermissionsRequestException();
                        }
                        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
                        if (str != null) {
                            slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                            Uri parse = Uri.parse(slashifyFilePath);
                            if (parse != null) {
                                intent.putExtra("android.provider.extra.INITIAL_URI", parse);
                            }
                        }
                        FileSystemModule.this.dirPermissionsRequest = promise;
                        currentActivity.startActivityForResult(intent, 5394);
                        return;
                    }
                    throw new Exceptions.MissingActivity();
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("requestDirectoryPermissionsAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(Promise.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(Promise.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    Promise promise;
                    String slashifyFilePath;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    String str = (String) objArr[0];
                    Object obj = objArr[1];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.kotlin.Promise");
                    }
                    Promise promise2 = (Promise) obj;
                    Activity currentActivity = FileSystemModule.this.getAppContext().getCurrentActivity();
                    if (currentActivity != null) {
                        promise = FileSystemModule.this.dirPermissionsRequest;
                        if (promise != null) {
                            throw new FileSystemPendingPermissionsRequestException();
                        }
                        Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
                        if (str != null) {
                            slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                            Uri parse = Uri.parse(slashifyFilePath);
                            if (parse != null) {
                                intent.putExtra("android.provider.extra.INITIAL_URI", parse);
                            }
                        }
                        FileSystemModule.this.dirPermissionsRequest = promise2;
                        currentActivity.startActivityForResult(intent, 5394);
                        return Unit.INSTANCE;
                    }
                    throw new Exceptions.MissingActivity();
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("uploadAsync", Promise.class == Promise.class ? new AsyncFunctionWithPromiseComponent("uploadAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(FileSystemUploadOptions.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    Request createUploadRequest;
                    OkHttpClient okHttpClient;
                    Unit unit;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.FileSystemUploadOptions");
                    }
                    createUploadRequest = FileSystemModule.this.createUploadRequest(str, str2, (FileSystemUploadOptions) obj3, FileSystemModule$definition$1$17$request$1.INSTANCE);
                    okHttpClient = FileSystemModule.this.getOkHttpClient();
                    if (okHttpClient != null) {
                        okHttpClient.newCall(createUploadRequest).enqueue(new FileSystemModule$definition$1$17$1$1(promise, FileSystemModule.this));
                        unit = Unit.INSTANCE;
                    } else {
                        unit = null;
                    }
                    if (unit == null) {
                        promise.reject(new FileSystemOkHttpNullException());
                    }
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("uploadAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(FileSystemUploadOptions.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(Promise.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(Promise.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    Request createUploadRequest;
                    OkHttpClient okHttpClient;
                    Unit unit;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.FileSystemUploadOptions");
                    }
                    FileSystemUploadOptions fileSystemUploadOptions = (FileSystemUploadOptions) obj3;
                    Object obj4 = objArr[3];
                    if (obj4 != null) {
                        Promise promise = (Promise) obj4;
                        createUploadRequest = FileSystemModule.this.createUploadRequest(str, str2, fileSystemUploadOptions, FileSystemModule$definition$1$17$request$1.INSTANCE);
                        okHttpClient = FileSystemModule.this.getOkHttpClient();
                        if (okHttpClient != null) {
                            okHttpClient.newCall(createUploadRequest).enqueue(new FileSystemModule$definition$1$17$1$1(promise, FileSystemModule.this));
                            unit = Unit.INSTANCE;
                        } else {
                            unit = null;
                        }
                        if (unit == null) {
                            promise.reject(new FileSystemOkHttpNullException());
                        }
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.kotlin.Promise");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("uploadTaskStartAsync", Promise.class == Promise.class ? new AsyncFunctionWithPromiseComponent("uploadTaskStartAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(FileSystemUploadOptions.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    Request createUploadRequest;
                    OkHttpClient okHttpClient;
                    Map map;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str3 = (String) obj3;
                    Object obj4 = objArr[3];
                    if (obj4 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.FileSystemUploadOptions");
                    }
                    FileSystemModule$definition$1$18$progressListener$1 fileSystemModule$definition$1$18$progressListener$1 = new FileSystemModule$definition$1$18$progressListener$1(str3, FileSystemModule.this);
                    createUploadRequest = FileSystemModule.this.createUploadRequest(str, str2, (FileSystemUploadOptions) obj4, new FileSystemModule$definition$1$18$request$1(fileSystemModule$definition$1$18$progressListener$1));
                    okHttpClient = FileSystemModule.this.getOkHttpClient();
                    Intrinsics.checkNotNull(okHttpClient);
                    Call newCall = okHttpClient.newCall(createUploadRequest);
                    map = FileSystemModule.this.taskHandlers;
                    map.put(str3, new FileSystemModule.TaskHandler(newCall));
                    newCall.enqueue(new FileSystemModule$definition$1$18$1(promise, FileSystemModule.this));
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("uploadTaskStartAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(FileSystemUploadOptions.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(Promise.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(Promise.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    Request createUploadRequest;
                    OkHttpClient okHttpClient;
                    Map map;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str3 = (String) obj3;
                    Object obj4 = objArr[3];
                    if (obj4 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.FileSystemUploadOptions");
                    }
                    FileSystemUploadOptions fileSystemUploadOptions = (FileSystemUploadOptions) obj4;
                    Object obj5 = objArr[4];
                    if (obj5 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.kotlin.Promise");
                    }
                    createUploadRequest = FileSystemModule.this.createUploadRequest(str, str2, fileSystemUploadOptions, new FileSystemModule$definition$1$18$request$1(new FileSystemModule$definition$1$18$progressListener$1(str3, FileSystemModule.this)));
                    okHttpClient = FileSystemModule.this.getOkHttpClient();
                    Intrinsics.checkNotNull(okHttpClient);
                    Call newCall = okHttpClient.newCall(createUploadRequest);
                    map = FileSystemModule.this.taskHandlers;
                    map.put(str3, new FileSystemModule.TaskHandler(newCall));
                    newCall.enqueue(new FileSystemModule$definition$1$18$1((Promise) obj5, FileSystemModule.this));
                    return Unit.INSTANCE;
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("downloadAsync", Promise.class == Promise.class ? new AsyncFunctionWithPromiseComponent("downloadAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(DownloadOptions.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    OkHttpClient okHttpClient;
                    Call newCall;
                    File file;
                    String md5;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    String str2 = (String) objArr[1];
                    Object obj2 = objArr[2];
                    if (obj2 != null) {
                        DownloadOptions downloadOptions = (DownloadOptions) obj2;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str2);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        FileSystemModule.this.checkIfFileDirExists(parse);
                        if (!StringsKt.contains$default(str, ":", false, 2, (Object) null)) {
                            Context context = FileSystemModule.this.getContext();
                            InputStream openRawResource = context.getResources().openRawResource(context.getResources().getIdentifier(str, "raw", context.getPackageName()));
                            Intrinsics.checkNotNullExpressionValue(openRawResource, "context.resources.openRawResource(resourceId)");
                            Source buffer = Okio.buffer(Okio.source(openRawResource));
                            file = FileSystemModule.this.toFile(parse);
                            file.delete();
                            BufferedSink buffer2 = Okio.buffer(Okio.sink$default(file, false, 1, (Object) null));
                            buffer2.writeAll(buffer);
                            buffer2.close();
                            Bundle bundle = new Bundle();
                            bundle.putString(PlayerData.STATUS_URI_KEY_PATH, Uri.fromFile(file).toString());
                            Boolean valueOf = Boolean.valueOf(downloadOptions.getMd5());
                            r8 = valueOf.booleanValue() ? valueOf : null;
                            if (r8 != null) {
                                r8.booleanValue();
                                md5 = FileSystemModule.this.md5(file);
                                bundle.putString("md5", md5);
                            }
                            promise.resolve(bundle);
                            return;
                        }
                        if (Intrinsics.areEqual("file", parse.getScheme())) {
                            Request.Builder url = new Request.Builder().url(str);
                            if (downloadOptions.getHeaders() != null) {
                                for (Map.Entry<String, String> entry : downloadOptions.getHeaders().entrySet()) {
                                    url.addHeader(entry.getKey(), entry.getValue());
                                }
                            }
                            okHttpClient = FileSystemModule.this.getOkHttpClient();
                            if (okHttpClient != null && (newCall = okHttpClient.newCall(url.build())) != null) {
                                newCall.enqueue(new FileSystemModule$definition$1$19$4(promise, FileSystemModule.this, parse, downloadOptions));
                                r8 = Unit.INSTANCE;
                            }
                            if (r8 == null) {
                                promise.reject(new FileSystemOkHttpNullException());
                                return;
                            }
                            return;
                        }
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.DownloadOptions");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("downloadAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(DownloadOptions.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(Promise.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(Promise.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    OkHttpClient okHttpClient;
                    Call newCall;
                    File file;
                    String md5;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    String str2 = (String) objArr[1];
                    Object obj2 = objArr[2];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.DownloadOptions");
                    }
                    DownloadOptions downloadOptions = (DownloadOptions) obj2;
                    Object obj3 = objArr[3];
                    if (obj3 != null) {
                        Promise promise = (Promise) obj3;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str2);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, PlayerData.STATUS_URI_KEY_PATH);
                        fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                        FileSystemModule.this.checkIfFileDirExists(parse);
                        if (!StringsKt.contains$default(str, ":", false, 2, (Object) null)) {
                            Context context = FileSystemModule.this.getContext();
                            InputStream openRawResource = context.getResources().openRawResource(context.getResources().getIdentifier(str, "raw", context.getPackageName()));
                            Intrinsics.checkNotNullExpressionValue(openRawResource, "context.resources.openRawResource(resourceId)");
                            Source buffer = Okio.buffer(Okio.source(openRawResource));
                            file = FileSystemModule.this.toFile(parse);
                            file.delete();
                            BufferedSink buffer2 = Okio.buffer(Okio.sink$default(file, false, 1, (Object) null));
                            buffer2.writeAll(buffer);
                            buffer2.close();
                            Bundle bundle = new Bundle();
                            bundle.putString(PlayerData.STATUS_URI_KEY_PATH, Uri.fromFile(file).toString());
                            Boolean valueOf = Boolean.valueOf(downloadOptions.getMd5());
                            r9 = valueOf.booleanValue() ? valueOf : null;
                            if (r9 != null) {
                                r9.booleanValue();
                                md5 = FileSystemModule.this.md5(file);
                                bundle.putString("md5", md5);
                            }
                            promise.resolve(bundle);
                        } else if (Intrinsics.areEqual("file", parse.getScheme())) {
                            Request.Builder url = new Request.Builder().url(str);
                            if (downloadOptions.getHeaders() != null) {
                                for (Map.Entry<String, String> entry : downloadOptions.getHeaders().entrySet()) {
                                    url.addHeader(entry.getKey(), entry.getValue());
                                }
                            }
                            okHttpClient = FileSystemModule.this.getOkHttpClient();
                            if (okHttpClient != null && (newCall = okHttpClient.newCall(url.build())) != null) {
                                newCall.enqueue(new FileSystemModule$definition$1$19$4(promise, FileSystemModule.this, parse, downloadOptions));
                                r9 = Unit.INSTANCE;
                            }
                            if (r9 == null) {
                                promise.reject(new FileSystemOkHttpNullException());
                            }
                        } else {
                            throw new IOException("Unsupported scheme for location '" + parse + "'.");
                        }
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.kotlin.Promise");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("networkTaskCancelAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("networkTaskCancelAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    Map map;
                    Call call;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    map = FileSystemModule.this.taskHandlers;
                    FileSystemModule.TaskHandler taskHandler = (FileSystemModule.TaskHandler) map.get((String) promise);
                    if (taskHandler == null || (call = taskHandler.getCall()) == null) {
                        return;
                    }
                    call.cancel();
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("networkTaskCancelAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    Map map;
                    Call call;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj != null) {
                        map = FileSystemModule.this.taskHandlers;
                        FileSystemModule.TaskHandler taskHandler = (FileSystemModule.TaskHandler) map.get((String) obj);
                        if (taskHandler == null || (call = taskHandler.getCall()) == null) {
                            return null;
                        }
                        call.cancel();
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("downloadResumableStartAsync", Promise.class == Promise.class ? new AsyncFunctionWithPromiseComponent("downloadResumableStartAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(DownloadOptions.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            }))}, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    String slashifyFilePath;
                    OkHttpClient okHttpClient;
                    Map map;
                    File file;
                    CoroutineScope coroutineScope;
                    OkHttpClient.Builder newBuilder;
                    OkHttpClient.Builder addInterceptor;
                    Intrinsics.checkNotNullParameter(objArr, "args");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str3 = (String) obj3;
                    Object obj4 = objArr[3];
                    if (obj4 != null) {
                        DownloadOptions downloadOptions = (DownloadOptions) obj4;
                        String str4 = (String) objArr[4];
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str2);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, "fileUri");
                        fileSystemModule2.checkIfFileDirExists(parse);
                        if (!Intrinsics.areEqual(parse.getScheme(), "file")) {
                            throw new IOException("Unsupported scheme for location '" + parse + "'.");
                        }
                        FileSystemModule$definition$1$21$progressListener$1 fileSystemModule$definition$1$21$progressListener$1 = new FileSystemModule$definition$1$21$progressListener$1(str4, str3, FileSystemModule.this);
                        okHttpClient = FileSystemModule.this.getOkHttpClient();
                        OkHttpClient build = (okHttpClient == null || (newBuilder = okHttpClient.newBuilder()) == null || (addInterceptor = newBuilder.addInterceptor(new FileSystemModule$definition$lambda$48$lambda$42$$inlined$addInterceptor$1(fileSystemModule$definition$1$21$progressListener$1))) == null) ? null : addInterceptor.build();
                        if (build == null) {
                            promise.reject(new FileSystemOkHttpNullException());
                            return;
                        }
                        Request.Builder builder = new Request.Builder();
                        if (str4 != null) {
                            builder.addHeader(HttpHeaders.RANGE, "bytes=" + str4 + "-");
                        }
                        if (downloadOptions.getHeaders() != null) {
                            for (Map.Entry<String, String> entry : downloadOptions.getHeaders().entrySet()) {
                                builder.addHeader(entry.getKey(), entry.getValue());
                            }
                        }
                        Call newCall = build.newCall(builder.url(str).build());
                        map = FileSystemModule.this.taskHandlers;
                        map.put(str3, new FileSystemModule.DownloadTaskHandler(parse, newCall));
                        file = FileSystemModule.this.toFile(parse);
                        FileSystemModule.DownloadResumableTaskParams downloadResumableTaskParams = new FileSystemModule.DownloadResumableTaskParams(downloadOptions, newCall, file, str4 != null, promise);
                        coroutineScope = FileSystemModule.this.moduleCoroutineScope;
                        BuildersKt.launch$default(coroutineScope, (CoroutineContext) null, (CoroutineStart) null, new FileSystemModule$definition$1$21$3(FileSystemModule.this, downloadResumableTaskParams, null), 3, (Object) null);
                        return;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.DownloadOptions");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("downloadResumableStartAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(DownloadOptions.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.nullableTypeOf(String.class);
                }
            })), new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(Promise.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(Promise.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    String slashifyFilePath;
                    OkHttpClient okHttpClient;
                    Map map;
                    File file;
                    CoroutineScope coroutineScope;
                    OkHttpClient.Builder newBuilder;
                    OkHttpClient.Builder addInterceptor;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str = (String) obj;
                    Object obj2 = objArr[1];
                    if (obj2 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str2 = (String) obj2;
                    Object obj3 = objArr[2];
                    if (obj3 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                    }
                    String str3 = (String) obj3;
                    Object obj4 = objArr[3];
                    if (obj4 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type expo.modules.filesystem.DownloadOptions");
                    }
                    DownloadOptions downloadOptions = (DownloadOptions) obj4;
                    String str4 = (String) objArr[4];
                    Object obj5 = objArr[5];
                    if (obj5 != null) {
                        Promise promise = (Promise) obj5;
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str2);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNullExpressionValue(parse, "fileUri");
                        fileSystemModule2.checkIfFileDirExists(parse);
                        if (!Intrinsics.areEqual(parse.getScheme(), "file")) {
                            throw new IOException("Unsupported scheme for location '" + parse + "'.");
                        }
                        FileSystemModule$definition$1$21$progressListener$1 fileSystemModule$definition$1$21$progressListener$1 = new FileSystemModule$definition$1$21$progressListener$1(str4, str3, FileSystemModule.this);
                        okHttpClient = FileSystemModule.this.getOkHttpClient();
                        OkHttpClient build = (okHttpClient == null || (newBuilder = okHttpClient.newBuilder()) == null || (addInterceptor = newBuilder.addInterceptor(new FileSystemModule$definition$lambda$48$lambda$42$$inlined$addInterceptor$1(fileSystemModule$definition$1$21$progressListener$1))) == null) ? null : addInterceptor.build();
                        if (build == null) {
                            promise.reject(new FileSystemOkHttpNullException());
                        } else {
                            Request.Builder builder = new Request.Builder();
                            if (str4 != null) {
                                builder.addHeader(HttpHeaders.RANGE, "bytes=" + str4 + "-");
                            }
                            if (downloadOptions.getHeaders() != null) {
                                for (Map.Entry<String, String> entry : downloadOptions.getHeaders().entrySet()) {
                                    builder.addHeader(entry.getKey(), entry.getValue());
                                }
                            }
                            Call newCall = build.newCall(builder.url(str).build());
                            map = FileSystemModule.this.taskHandlers;
                            map.put(str3, new FileSystemModule.DownloadTaskHandler(parse, newCall));
                            file = FileSystemModule.this.toFile(parse);
                            FileSystemModule.DownloadResumableTaskParams downloadResumableTaskParams = new FileSystemModule.DownloadResumableTaskParams(downloadOptions, newCall, file, str4 != null, promise);
                            coroutineScope = FileSystemModule.this.moduleCoroutineScope;
                            BuildersKt.launch$default(coroutineScope, (CoroutineContext) null, (CoroutineStart) null, new FileSystemModule$definition$1$21$3(FileSystemModule.this, downloadResumableTaskParams, null), 3, (Object) null);
                        }
                        return Unit.INSTANCE;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type expo.modules.kotlin.Promise");
                }
            }));
            moduleDefinitionBuilder.getAsyncFunctions().put("downloadResumablePauseAsync", String.class == Promise.class ? new AsyncFunctionWithPromiseComponent("downloadResumablePauseAsync", new AnyType[0], new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    Map map;
                    Map map2;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "<anonymous parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    String str = (String) promise;
                    map = FileSystemModule.this.taskHandlers;
                    FileSystemModule.TaskHandler taskHandler = (FileSystemModule.TaskHandler) map.get(str);
                    if (taskHandler == null) {
                        throw new IOException("No download object available");
                    }
                    if (!(taskHandler instanceof FileSystemModule.DownloadTaskHandler)) {
                        throw new FileSystemCannotFindTaskException();
                    }
                    taskHandler.getCall().cancel();
                    map2 = FileSystemModule.this.taskHandlers;
                    map2.remove(str);
                    file = FileSystemModule.this.toFile(((FileSystemModule.DownloadTaskHandler) taskHandler).getFileUri());
                    new Bundle().putString("resumeData", String.valueOf(file.length()));
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            }) : new AsyncFunctionComponent("downloadResumablePauseAsync", new AnyType[]{new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                public final KType invoke() {
                    return Reflection.typeOf(String.class);
                }
            }))}, new Function1<Object[], Object>() {
                {
                    super(1);
                }

                public final Object invoke(Object[] objArr) {
                    Map map;
                    Map map2;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "it");
                    Object obj = objArr[0];
                    if (obj != null) {
                        String str = (String) obj;
                        map = FileSystemModule.this.taskHandlers;
                        FileSystemModule.TaskHandler taskHandler = (FileSystemModule.TaskHandler) map.get(str);
                        if (taskHandler == null) {
                            throw new IOException("No download object available");
                        }
                        if (!(taskHandler instanceof FileSystemModule.DownloadTaskHandler)) {
                            throw new FileSystemCannotFindTaskException();
                        }
                        taskHandler.getCall().cancel();
                        map2 = FileSystemModule.this.taskHandlers;
                        map2.remove(str);
                        file = FileSystemModule.this.toFile(((FileSystemModule.DownloadTaskHandler) taskHandler).getFileUri());
                        Bundle bundle = new Bundle();
                        bundle.putString("resumeData", String.valueOf(file.length()));
                        return bundle;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                }
            }));
            moduleDefinitionBuilder.getEventListeners().put(EventName.ON_ACTIVITY_RESULT, new EventListenerWithSenderAndPayload(EventName.ON_ACTIVITY_RESULT, new Function2<Activity, OnActivityResultPayload, Unit>() {
                {
                    super(2);
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Activity) obj, (OnActivityResultPayload) obj2);
                    return Unit.INSTANCE;
                }

                public final void invoke(Activity activity, OnActivityResultPayload onActivityResultPayload) {
                    Promise promise;
                    Promise promise2;
                    Intrinsics.checkNotNullParameter(activity, "sender");
                    Intrinsics.checkNotNullParameter(onActivityResultPayload, "payload");
                    int requestCode = onActivityResultPayload.getRequestCode();
                    int resultCode = onActivityResultPayload.getResultCode();
                    Intent data = onActivityResultPayload.getData();
                    if (requestCode == 5394) {
                        promise = FileSystemModule.this.dirPermissionsRequest;
                        if (promise != null) {
                            Activity currentActivity = FileSystemModule.this.getAppContext().getCurrentActivity();
                            if (currentActivity == null) {
                                throw new Exceptions.MissingActivity();
                            }
                            Bundle bundle = new Bundle();
                            if (resultCode == -1 && data != null) {
                                Uri data2 = data.getData();
                                int flags = data.getFlags() & 3;
                                if (data2 != null) {
                                    currentActivity.getContentResolver().takePersistableUriPermission(data2, flags);
                                }
                                bundle.putBoolean(PermissionsResponse.GRANTED_KEY, true);
                                bundle.putString("directoryUri", String.valueOf(data2));
                            } else {
                                bundle.putBoolean(PermissionsResponse.GRANTED_KEY, false);
                            }
                            promise2 = FileSystemModule.this.dirPermissionsRequest;
                            if (promise2 != null) {
                                promise2.resolve(bundle);
                            }
                            FileSystemModule.this.dirPermissionsRequest = null;
                        }
                    }
                }
            }));
            moduleDefinitionBuilder.getEventListeners().put(EventName.MODULE_DESTROY, new BasicEventListener(EventName.MODULE_DESTROY, new Function0<Unit>() {
                {
                    super(0);
                }

                public Object invoke() {
                    m593invoke();
                    return Unit.INSTANCE;
                }

                public final void m593invoke() {
                    String str;
                    CoroutineScope coroutineScope;
                    try {
                        coroutineScope = FileSystemModule.this.moduleCoroutineScope;
                        CoroutineScopeKt.cancel(coroutineScope, new ModuleDestroyedException(null, 1, null));
                    } catch (IllegalStateException unused) {
                        str = FileSystemModuleKt.TAG;
                        Log.e(str, "The scope does not have a job in it");
                    }
                }
            }));
            return moduleDefinitionBuilder.buildModule();
        } finally {
            Trace.endSection();
        }
    }

    private final void checkIfFileExists(Uri uri) throws IOException {
        File file = toFile(uri);
        if (file.exists()) {
            return;
        }
        throw new IOException("Directory for '" + file.getPath() + "' doesn't exist.");
    }

    public final void checkIfFileDirExists(Uri uri) throws IOException {
        File file = toFile(uri);
        File parentFile = file.getParentFile();
        if (parentFile == null || !parentFile.exists()) {
            throw new IOException("Directory for '" + file.getPath() + "' doesn't exist. Please make sure directory '" + file.getParent() + "' exists before calling downloadAsync.");
        }
    }

    public final void ensureDirExists(File dir) throws IOException {
        if (!dir.isDirectory() && !dir.mkdirs()) {
            throw new IOException("Couldn't create directory '" + dir + "'");
        }
    }

    private final EnumSet<Permission> permissionsForPath(String path) {
        FilePermissionModuleInterface filePermission = getAppContext().getFilePermission();
        if (filePermission != null) {
            return filePermission.getPathPermissions(getContext(), path);
        }
        return null;
    }

    private final EnumSet<Permission> permissionsForUri(Uri uri) {
        if (isSAFUri(uri)) {
            return permissionsForSAFUri(uri);
        }
        if (!Intrinsics.areEqual(uri.getScheme(), FirebaseAnalytics.Param.CONTENT) && !Intrinsics.areEqual(uri.getScheme(), "asset")) {
            return Intrinsics.areEqual(uri.getScheme(), "file") ? permissionsForPath(uri.getPath()) : uri.getScheme() == null ? EnumSet.of(Permission.READ) : EnumSet.noneOf(Permission.class);
        }
        return EnumSet.of(Permission.READ);
    }

    private final EnumSet<Permission> permissionsForSAFUri(Uri uri) {
        DocumentFile nearestSAFFile = getNearestSAFFile(uri);
        EnumSet<Permission> noneOf = EnumSet.noneOf(Permission.class);
        if (nearestSAFFile != null) {
            if (nearestSAFFile.canRead()) {
                noneOf.add(Permission.READ);
            }
            if (nearestSAFFile.canWrite()) {
                noneOf.add(Permission.WRITE);
            }
        }
        Intrinsics.checkNotNullExpressionValue(noneOf, "noneOf(Permission::class…)\n        }\n      }\n    }");
        return noneOf;
    }

    public final void ensurePermission(Uri uri, Permission permission, String errorMsg) throws IOException {
        EnumSet<Permission> permissionsForUri = permissionsForUri(uri);
        boolean z = false;
        if (permissionsForUri != null && permissionsForUri.contains(permission)) {
            z = true;
        }
        if (!z) {
            throw new IOException(errorMsg);
        }
    }

    public final void ensurePermission(Uri uri, Permission permission) throws IOException {
        if (permission == Permission.READ) {
            ensurePermission(uri, permission, "Location '" + uri + "' isn't readable.");
        }
        if (permission == Permission.WRITE) {
            ensurePermission(uri, permission, "Location '" + uri + "' isn't writable.");
        }
        ensurePermission(uri, permission, "Location '" + uri + "' doesn't have permission '" + permission.name() + "'.");
    }

    public final InputStream openAssetInputStream(Uri uri) throws IOException {
        String path = uri.getPath();
        if (path == null) {
            throw new IllegalArgumentException("Required value was null.".toString());
        }
        Intrinsics.checkNotNullExpressionValue(path, "requireNotNull(uri.path)");
        String substring = path.substring(1);
        Intrinsics.checkNotNullExpressionValue(substring, "this as java.lang.String).substring(startIndex)");
        InputStream open = getContext().getAssets().open(substring);
        Intrinsics.checkNotNullExpressionValue(open, "context.assets.open(asset)");
        return open;
    }

    public final InputStream openResourceInputStream(String resourceName) throws IOException {
        int identifier = getContext().getResources().getIdentifier(resourceName, "raw", getContext().getPackageName());
        if (identifier == 0 && (identifier = getContext().getResources().getIdentifier(resourceName, "drawable", getContext().getPackageName())) == 0) {
            throw new FileNotFoundException("No resource found with the name '" + resourceName + "'");
        }
        InputStream openRawResource = getContext().getResources().openRawResource(identifier);
        Intrinsics.checkNotNullExpressionValue(openRawResource, "context.resources.openRawResource(resourceId)");
        return openRawResource;
    }

    public final void transformFilesFromSAF(DocumentFile documentFile, File outputDir, boolean copy) throws IOException {
        File file;
        if (!documentFile.exists()) {
            return;
        }
        if (!outputDir.isDirectory()) {
            File parentFile = outputDir.getParentFile();
            if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs()) {
                throw new IOException("Couldn't create folder in output dir.");
            }
        } else if (!outputDir.exists() && !outputDir.mkdirs()) {
            throw new IOException("Couldn't create folder in output dir.");
        }
        if (documentFile.isDirectory()) {
            DocumentFile[] listFiles = documentFile.listFiles();
            Intrinsics.checkNotNullExpressionValue(listFiles, "documentFile.listFiles()");
            for (DocumentFile documentFile2 : listFiles) {
                Intrinsics.checkNotNullExpressionValue(documentFile2, "file");
                transformFilesFromSAF(documentFile2, outputDir, copy);
            }
            if (copy) {
                return;
            }
            documentFile.delete();
            return;
        }
        String name = documentFile.getName();
        if (name == null) {
            return;
        }
        if (outputDir.isDirectory()) {
            file = new File(outputDir.getPath(), name);
        } else {
            file = new File(outputDir.getPath());
        }
        FileOutputStream openInputStream = getContext().getContentResolver().openInputStream(documentFile.getUri());
        try {
            InputStream inputStream = openInputStream;
            openInputStream = new FileOutputStream(file);
            try {
                IOUtils.copy(inputStream, openInputStream);
                CloseableKt.closeFinally(openInputStream, (Throwable) null);
                CloseableKt.closeFinally(openInputStream, (Throwable) null);
                if (copy) {
                    return;
                }
                documentFile.delete();
            } finally {
            }
        } catch (Throwable th) {
            try {
                throw th;
            } finally {
            }
        }
    }

    public final Uri contentUriFromFile(File file) {
        Activity currentActivity = getAppContext().getCurrentActivity();
        if (currentActivity == null) {
            throw new Exceptions.MissingActivity();
        }
        Uri uriForFile = FileProvider.getUriForFile(currentActivity.getApplication(), currentActivity.getApplication().getPackageName() + ".FileSystemFileProvider", file);
        Intrinsics.checkNotNullExpressionValue(uriForFile, "getUriForFile(\n      cur…ovider\",\n      file\n    )");
        return uriForFile;
    }

    public final Request createUploadRequest(String url, String fileUriString, FileSystemUploadOptions options, RequestBodyDecorator decorator) throws IOException {
        String slashifyFilePath;
        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(fileUriString);
        Uri parse = Uri.parse(slashifyFilePath);
        Intrinsics.checkNotNullExpressionValue(parse, "fileUri");
        ensurePermission(parse, Permission.READ);
        checkIfFileExists(parse);
        Request.Builder url2 = new Request.Builder().url(url);
        Map<String, String> headers = options.getHeaders();
        if (headers != null) {
            for (Map.Entry<String, String> entry : headers.entrySet()) {
                url2.addHeader(entry.getKey(), entry.getValue());
            }
        }
        return url2.method(options.getHttpMethod().getValue(), createRequestBody(options, decorator, toFile(parse))).build();
    }

    private final RequestBody createRequestBody(FileSystemUploadOptions options, RequestBodyDecorator decorator, File file) {
        int i = WhenMappings.$EnumSwitchMapping$0[options.getUploadType().ordinal()];
        if (i == 1) {
            return decorator.decorate(RequestBody.Companion.create(file, (MediaType) null));
        }
        if (i != 2) {
            throw new NoWhenBranchMatchedException();
        }
        MultipartBody.Builder type = new MultipartBody.Builder((String) null, 1, (DefaultConstructorMarker) null).setType(MultipartBody.FORM);
        Map<String, String> parameters = options.getParameters();
        if (parameters != null) {
            for (Map.Entry<String, String> entry : parameters.entrySet()) {
                type.addFormDataPart(entry.getKey(), entry.getValue().toString());
            }
        }
        String mimeType = options.getMimeType();
        if (mimeType == null) {
            mimeType = URLConnection.guessContentTypeFromName(file.getName());
            Intrinsics.checkNotNullExpressionValue(mimeType, "guessContentTypeFromName(file.name)");
        }
        String fieldName = options.getFieldName();
        if (fieldName == null) {
            fieldName = file.getName();
        }
        Intrinsics.checkNotNullExpressionValue(fieldName, "fieldName");
        type.addFormDataPart(fieldName, file.getName(), decorator.decorate(RequestBody.Companion.create(file, MediaType.Companion.parse(mimeType))));
        return type.build();
    }

    @Metadata(d1 = {"\u00006\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0013\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0000\b\u0082\b\u0018\u00002\u00020\u0001B-\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t\u0012\u0006\u0010\n\u001a\u00020\u000b¢\u0006\u0002\u0010\fJ\t\u0010\u0016\u001a\u00020\u0003HÆ\u0003J\t\u0010\u0017\u001a\u00020\u0005HÆ\u0003J\t\u0010\u0018\u001a\u00020\u0007HÆ\u0003J\t\u0010\u0019\u001a\u00020\tHÆ\u0003J\t\u0010\u001a\u001a\u00020\u000bHÆ\u0003J;\u0010\u001b\u001a\u00020\u00002\b\b\u0002\u0010\u0002\u001a\u00020\u00032\b\b\u0002\u0010\u0004\u001a\u00020\u00052\b\b\u0002\u0010\u0006\u001a\u00020\u00072\b\b\u0002\u0010\b\u001a\u00020\t2\b\b\u0002\u0010\n\u001a\u00020\u000bHÆ\u0001J\u0013\u0010\u001c\u001a\u00020\t2\b\u0010\u001d\u001a\u0004\u0018\u00010\u0001HÖ\u0003J\t\u0010\u001e\u001a\u00020\u001fHÖ\u0001J\t\u0010 \u001a\u00020!HÖ\u0001R\u0011\u0010\u0004\u001a\u00020\u0005¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\u000eR\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\u000f\u0010\u0010R\u0011\u0010\b\u001a\u00020\t¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\u0011R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0012\u0010\u0013R\u0011\u0010\n\u001a\u00020\u000b¢\u0006\b\n\u0000\u001a\u0004\b\u0014\u0010\u0015¨\u0006\""}, d2 = {"Lexpo/modules/filesystem/FileSystemModule$DownloadResumableTaskParams;", "", "options", "Lexpo/modules/filesystem/DownloadOptions;", "call", "Lokhttp3/Call;", "file", "Ljava/io/File;", "isResume", "", "promise", "Lexpo/modules/kotlin/Promise;", "(Lexpo/modules/filesystem/DownloadOptions;Lokhttp3/Call;Ljava/io/File;ZLexpo/modules/kotlin/Promise;)V", "getCall", "()Lokhttp3/Call;", "getFile", "()Ljava/io/File;", "()Z", "getOptions", "()Lexpo/modules/filesystem/DownloadOptions;", "getPromise", "()Lexpo/modules/kotlin/Promise;", "component1", "component2", "component3", "component4", "component5", "copy", "equals", "other", "hashCode", "", "toString", "", "expo-file-system_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    static final class DownloadResumableTaskParams {
        private final Call call;
        private final File file;
        private final boolean isResume;
        private final DownloadOptions options;
        private final Promise promise;

        public static DownloadResumableTaskParams copy$default(DownloadResumableTaskParams downloadResumableTaskParams, DownloadOptions downloadOptions, Call call, File file, boolean z, Promise promise, int i, Object obj) {
            if ((i & 1) != 0) {
                downloadOptions = downloadResumableTaskParams.options;
            }
            if ((i & 2) != 0) {
                call = downloadResumableTaskParams.call;
            }
            Call call2 = call;
            if ((i & 4) != 0) {
                file = downloadResumableTaskParams.file;
            }
            File file2 = file;
            if ((i & 8) != 0) {
                z = downloadResumableTaskParams.isResume;
            }
            boolean z2 = z;
            if ((i & 16) != 0) {
                promise = downloadResumableTaskParams.promise;
            }
            return downloadResumableTaskParams.copy(downloadOptions, call2, file2, z2, promise);
        }

        public final DownloadOptions getOptions() {
            return this.options;
        }

        public final Call getCall() {
            return this.call;
        }

        public final File getFile() {
            return this.file;
        }

        public final boolean getIsResume() {
            return this.isResume;
        }

        public final Promise getPromise() {
            return this.promise;
        }

        public final DownloadResumableTaskParams copy(DownloadOptions options, Call call, File file, boolean isResume, Promise promise) {
            Intrinsics.checkNotNullParameter(options, "options");
            Intrinsics.checkNotNullParameter(call, "call");
            Intrinsics.checkNotNullParameter(file, "file");
            Intrinsics.checkNotNullParameter(promise, "promise");
            return new DownloadResumableTaskParams(options, call, file, isResume, promise);
        }

        public boolean equals(Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof DownloadResumableTaskParams)) {
                return false;
            }
            DownloadResumableTaskParams downloadResumableTaskParams = (DownloadResumableTaskParams) other;
            return Intrinsics.areEqual(this.options, downloadResumableTaskParams.options) && Intrinsics.areEqual(this.call, downloadResumableTaskParams.call) && Intrinsics.areEqual(this.file, downloadResumableTaskParams.file) && this.isResume == downloadResumableTaskParams.isResume && Intrinsics.areEqual(this.promise, downloadResumableTaskParams.promise);
        }

        public int hashCode() {
            int hashCode = ((((this.options.hashCode() * 31) + this.call.hashCode()) * 31) + this.file.hashCode()) * 31;
            boolean z = this.isResume;
            int i = z;
            if (z != 0) {
                i = 1;
            }
            return ((hashCode + i) * 31) + this.promise.hashCode();
        }

        public String toString() {
            return "DownloadResumableTaskParams(options=" + this.options + ", call=" + this.call + ", file=" + this.file + ", isResume=" + this.isResume + ", promise=" + this.promise + ")";
        }

        public DownloadResumableTaskParams(DownloadOptions downloadOptions, Call call, File file, boolean z, Promise promise) {
            Intrinsics.checkNotNullParameter(downloadOptions, "options");
            Intrinsics.checkNotNullParameter(call, "call");
            Intrinsics.checkNotNullParameter(file, "file");
            Intrinsics.checkNotNullParameter(promise, "promise");
            this.options = downloadOptions;
            this.call = call;
            this.file = file;
            this.isResume = z;
            this.promise = promise;
        }

        public final DownloadOptions getOptions() {
            return this.options;
        }

        public final Call getCall() {
            return this.call;
        }

        public final File getFile() {
            return this.file;
        }

        public final boolean isResume() {
            return this.isResume;
        }

        public final Promise getPromise() {
            return this.promise;
        }
    }

    public final Object downloadResumableTask(DownloadResumableTaskParams downloadResumableTaskParams, Continuation continuation) {
        return BuildersKt.withContext(Dispatchers.getIO(), new FileSystemModule$downloadResumableTask$2(downloadResumableTaskParams, this, null), continuation);
    }

    @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0012\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0005\u0010\u0006¨\u0006\u0007"}, d2 = {"Lexpo/modules/filesystem/FileSystemModule$TaskHandler;", "", "call", "Lokhttp3/Call;", "(Lokhttp3/Call;)V", "getCall", "()Lokhttp3/Call;", "expo-file-system_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    static class TaskHandler {
        private final Call call;

        public TaskHandler(Call call) {
            Intrinsics.checkNotNullParameter(call, "call");
            this.call = call;
        }

        public final Call getCall() {
            return this.call;
        }
    }

    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0002\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\b¨\u0006\t"}, d2 = {"Lexpo/modules/filesystem/FileSystemModule$DownloadTaskHandler;", "Lexpo/modules/filesystem/FileSystemModule$TaskHandler;", "fileUri", "Landroid/net/Uri;", "call", "Lokhttp3/Call;", "(Landroid/net/Uri;Lokhttp3/Call;)V", "getFileUri", "()Landroid/net/Uri;", "expo-file-system_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    static final class DownloadTaskHandler extends TaskHandler {
        private final Uri fileUri;

        public DownloadTaskHandler(Uri uri, Call call) {
            super(call);
            Intrinsics.checkNotNullParameter(uri, "fileUri");
            Intrinsics.checkNotNullParameter(call, "call");
            this.fileUri = uri;
        }

        public final Uri getFileUri() {
            return this.fileUri;
        }
    }

    @Metadata(d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\u0017\u0012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0001\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0005J\b\u0010\b\u001a\u00020\tH\u0016J\n\u0010\n\u001a\u0004\u0018\u00010\u000bH\u0016J\b\u0010\f\u001a\u00020\u0007H\u0016J\u0010\u0010\f\u001a\u00020\r2\u0006\u0010\f\u001a\u00020\rH\u0002R\u0010\u0010\u0006\u001a\u0004\u0018\u00010\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u0002\u001a\u0004\u0018\u00010\u0001X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u000e"}, d2 = {"Lexpo/modules/filesystem/FileSystemModule$ProgressResponseBody;", "Lokhttp3/ResponseBody;", "responseBody", "progressListener", "Lexpo/modules/filesystem/FileSystemModule$ProgressListener;", "(Lokhttp3/ResponseBody;Lexpo/modules/filesystem/FileSystemModule$ProgressListener;)V", "bufferedSource", "Lokio/BufferedSource;", "contentLength", "", "contentType", "Lokhttp3/MediaType;", "source", "Lokio/Source;", "expo-file-system_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    static final class ProgressResponseBody extends ResponseBody {
        private BufferedSource bufferedSource;
        private final ProgressListener progressListener;
        private final ResponseBody responseBody;

        public ProgressResponseBody(ResponseBody responseBody, ProgressListener progressListener) {
            Intrinsics.checkNotNullParameter(progressListener, "progressListener");
            this.responseBody = responseBody;
            this.progressListener = progressListener;
        }

        public MediaType contentType() {
            ResponseBody responseBody = this.responseBody;
            if (responseBody != null) {
                return responseBody.contentType();
            }
            return null;
        }

        public long contentLength() {
            ResponseBody responseBody = this.responseBody;
            if (responseBody != null) {
                return responseBody.contentLength();
            }
            return -1L;
        }

        public BufferedSource source() {
            BufferedSource bufferedSource = this.bufferedSource;
            if (bufferedSource != null) {
                return bufferedSource;
            }
            ResponseBody responseBody = this.responseBody;
            Intrinsics.checkNotNull(responseBody);
            return Okio.buffer(source((Source) responseBody.source()));
        }

        private final Source source(final Source source) {
            return new ForwardingSource(source) {
                private long totalBytesRead;

                public final long getTotalBytesRead() {
                    return this.totalBytesRead;
                }

                public final void setTotalBytesRead(long j) {
                    this.totalBytesRead = j;
                }

                public long read(Buffer sink, long byteCount) throws IOException {
                    FileSystemModule.ProgressListener progressListener;
                    ResponseBody responseBody;
                    Intrinsics.checkNotNullParameter(sink, "sink");
                    long read = super.read(sink, byteCount);
                    this.totalBytesRead += read != -1 ? read : 0L;
                    progressListener = this.progressListener;
                    long j = this.totalBytesRead;
                    responseBody = this.responseBody;
                    progressListener.update(j, responseBody != null ? responseBody.contentLength() : -1L, read == -1);
                    return read;
                }
            };
        }
    }

    public final synchronized OkHttpClient getOkHttpClient() {
        Object obj;
        if (this.client == null) {
            OkHttpClient.Builder writeTimeout = new OkHttpClient.Builder().connectTimeout(60L, TimeUnit.SECONDS).readTimeout(60L, TimeUnit.SECONDS).writeTimeout(60L, TimeUnit.SECONDS);
            try {
                obj = getAppContext().getLegacyModuleRegistry().getModule(CookieHandler.class);
            } catch (Exception unused) {
                obj = null;
            }
            CookieHandler cookieHandler = (CookieHandler) obj;
            if (cookieHandler == null) {
                throw new CookieHandlerNotFoundException();
            }
            writeTimeout.cookieJar(new JavaNetCookieJar(cookieHandler));
            this.client = writeTimeout.build();
        }
        return this.client;
    }

    public final String md5(File file) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(file);
        try {
            char[] encodeHex = Hex.encodeHex(DigestUtils.md5(fileInputStream));
            Intrinsics.checkNotNullExpressionValue(encodeHex, "encodeHex(md5bytes)");
            String str = new String(encodeHex);
            CloseableKt.closeFinally(fileInputStream, (Throwable) null);
            return str;
        } finally {
        }
    }

    public final void forceDelete(File file) throws IOException {
        if (file.isDirectory()) {
            File[] listFiles = file.listFiles();
            if (listFiles == null) {
                throw new IOException("Failed to list contents of " + file);
            }
            IOException e = null;
            for (File file2 : listFiles) {
                try {
                    Intrinsics.checkNotNullExpressionValue(file2, "f");
                    forceDelete(file2);
                } catch (IOException e2) {
                    e = e2;
                }
            }
            if (e != null) {
                throw e;
            }
            if (!file.delete()) {
                throw new IOException("Unable to delete directory " + file + ".");
            }
            return;
        }
        if (!file.delete()) {
            throw new IOException("Unable to delete file: " + file);
        }
    }

    public final long getFileSize(File file) {
        Object obj;
        if (!file.isDirectory()) {
            return file.length();
        }
        File[] listFiles = file.listFiles();
        if (listFiles == null) {
            return 0L;
        }
        ArrayList arrayList = new ArrayList(listFiles.length);
        for (File file2 : listFiles) {
            Intrinsics.checkNotNullExpressionValue(file2, "it");
            arrayList.add(Long.valueOf(getFileSize(file2)));
        }
        Iterator it = arrayList.iterator();
        if (it.hasNext()) {
            Object next = it.next();
            while (it.hasNext()) {
                next = Long.valueOf(((Number) next).longValue() + ((Number) it.next()).longValue());
            }
            obj = next;
        } else {
            obj = null;
        }
        Long l = (Long) obj;
        if (l != null) {
            return l.longValue();
        }
        return 0L;
    }

    public final InputStream getInputStream(Uri uri) throws IOException {
        if (Intrinsics.areEqual(uri.getScheme(), "file")) {
            return new FileInputStream(toFile(uri));
        }
        if (Intrinsics.areEqual(uri.getScheme(), "asset")) {
            return openAssetInputStream(uri);
        }
        if (!isSAFUri(uri)) {
            throw new IOException("Unsupported scheme for location '" + uri + "'.");
        }
        InputStream openInputStream = getContext().getContentResolver().openInputStream(uri);
        Intrinsics.checkNotNull(openInputStream);
        return openInputStream;
    }

    public final OutputStream getOutputStream(Uri uri) throws IOException {
        FileOutputStream openOutputStream;
        if (Intrinsics.areEqual(uri.getScheme(), "file")) {
            openOutputStream = new FileOutputStream(toFile(uri));
        } else {
            if (!isSAFUri(uri)) {
                throw new IOException("Unsupported scheme for location '" + uri + "'.");
            }
            openOutputStream = getContext().getContentResolver().openOutputStream(uri);
            Intrinsics.checkNotNull(openOutputStream);
        }
        Intrinsics.checkNotNullExpressionValue(openOutputStream, "when {\n    uri.scheme ==…or location '$uri'.\")\n  }");
        return openOutputStream;
    }

    public final DocumentFile getNearestSAFFile(Uri uri) {
        DocumentFile fromSingleUri = DocumentFile.fromSingleUri(getContext(), uri);
        return (fromSingleUri == null || !fromSingleUri.isFile()) ? DocumentFile.fromTreeUri(getContext(), uri) : fromSingleUri;
    }

    public final File toFile(Uri uri) {
        if (uri.getPath() != null) {
            String path = uri.getPath();
            Intrinsics.checkNotNull(path);
            return new File(path);
        }
        throw new IOException("Invalid Uri: " + uri);
    }

    public final boolean isSAFUri(Uri uri) {
        if (!Intrinsics.areEqual(uri.getScheme(), FirebaseAnalytics.Param.CONTENT)) {
            return false;
        }
        String host = uri.getHost();
        return host != null ? StringsKt.startsWith$default(host, "com.android.externalstorage", false, 2, (Object) null) : false;
    }

    public final String parseFileUri(String uriStr) {
        String substring = uriStr.substring(StringsKt.indexOf$default(uriStr, ':', 0, false, 6, (Object) null) + 3);
        Intrinsics.checkNotNullExpressionValue(substring, "this as java.lang.String).substring(startIndex)");
        return substring;
    }

    public final byte[] getInputStreamBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bArr = new byte[1024];
        while (true) {
            try {
                int read = inputStream.read(bArr);
                if (read == -1) {
                    break;
                }
                byteArrayOutputStream.write(bArr, 0, read);
            } finally {
                try {
                    byteArrayOutputStream.close();
                } catch (IOException unused) {
                }
            }
        }
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        Intrinsics.checkNotNullExpressionValue(byteArray, "byteBuffer.toByteArray()");
        return byteArray;
    }

    public final Bundle translateHeaders(Headers headers) {
        Bundle bundle = new Bundle();
        int size = headers.size();
        for (int i = 0; i < size; i++) {
            String name = headers.name(i);
            if (bundle.containsKey(name)) {
                bundle.putString(name, bundle.getString(name) + ", " + headers.value(i));
            } else {
                bundle.putString(name, headers.value(i));
            }
        }
        return bundle;
    }
}