导航菜单

页面标题

页面副标题

Glean v1.1.34 - FileSystemModule.java 源代码

正在查看: Glean v1.1.34 应用的 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 com.google.firebase.sessions.settings.RemoteSettings;
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.functions.BoolAsyncFunctionComponent;
import expo.modules.kotlin.functions.DoubleAsyncFunctionComponent;
import expo.modules.kotlin.functions.FloatAsyncFunctionComponent;
import expo.modules.kotlin.functions.IntAsyncFunctionComponent;
import expo.modules.kotlin.functions.StringAsyncFunctionComponent;
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.AnyTypeProvider;
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.URLConnection;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import kotlin.Metadata;
import kotlin.NoWhenBranchMatchedException;
import kotlin.Pair;
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.Callback;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
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\u0018\u0010'\u001a\u0004\u0018\u00010(2\u0006\u0010)\u001a\u00020*H\u0082@¢\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¨\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", "uri", "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, 9, 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, 9, 0}, xi = 48)
    public interface ProgressListener {
        void update(long bytesRead, long contentLength, boolean done);
    }

    @Metadata(k = 3, mv = {1, 9, 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() {
        AsyncFunctionWithPromiseComponent intAsyncFunctionComponent;
        AsyncFunctionWithPromiseComponent intAsyncFunctionComponent2;
        AsyncFunctionWithPromiseComponent intAsyncFunctionComponent3;
        AsyncFunctionWithPromiseComponent intAsyncFunctionComponent4;
        AsyncFunctionWithPromiseComponent intAsyncFunctionComponent5;
        AsyncFunctionComponent asyncFunctionComponent;
        AsyncFunctionWithPromiseComponent intAsyncFunctionComponent6;
        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() + RemoteSettings.FORWARD_SLASH_STRING), TuplesKt.to("cacheDirectory", Uri.fromFile(getContext().getCacheDir()).toString() + RemoteSettings.FORWARD_SLASH_STRING), 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() {
                    m480invoke();
                    return Unit.INSTANCE;
                }

                public final void m480invoke() {
                    try {
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        File filesDir = fileSystemModule2.getContext().getFilesDir();
                        Intrinsics.checkNotNullExpressionValue(filesDir, "getFilesDir(...)");
                        fileSystemModule2.ensureDirExists(filesDir);
                        FileSystemModule fileSystemModule3 = FileSystemModule.this;
                        File cacheDir = fileSystemModule3.getContext().getCacheDir();
                        Intrinsics.checkNotNullExpressionValue(cacheDir, "getCacheDir(...)");
                        fileSystemModule3.ensureDirExists(cacheDir);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }));
            ModuleDefinitionBuilder moduleDefinitionBuilder2 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr = new AnyType[2];
            AnyType anyType = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType == null) {
                anyType = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr[0] = anyType;
            AnyType anyType2 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(InfoOptions.class), false));
            if (anyType2 == null) {
                anyType2 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(InfoOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(InfoOptions.class);
                    }
                }));
            }
            anyTypeArr[1] = anyType2;
            Function1<Object[], Bundle> function1 = new Function1<Object[], Bundle>() {
                {
                    super(1);
                }

                public final android.os.Bundle invoke(java.lang.Object[] r17) {
                    throw new UnsupportedOperationException("Method not decompiled: expo.modules.filesystem.FileSystemModule$definition$lambda$48$$inlined$AsyncFunction$3.invoke(java.lang.Object[]):java.lang.Object");
                }
            };
            moduleDefinitionBuilder2.getAsyncFunctions().put("getInfoAsync", Intrinsics.areEqual(Bundle.class, Integer.TYPE) ? new IntAsyncFunctionComponent("getInfoAsync", anyTypeArr, function1) : Intrinsics.areEqual(Bundle.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("getInfoAsync", anyTypeArr, function1) : Intrinsics.areEqual(Bundle.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("getInfoAsync", anyTypeArr, function1) : Intrinsics.areEqual(Bundle.class, Float.TYPE) ? new FloatAsyncFunctionComponent("getInfoAsync", anyTypeArr, function1) : Intrinsics.areEqual(Bundle.class, String.class) ? new StringAsyncFunctionComponent("getInfoAsync", anyTypeArr, function1) : new AsyncFunctionComponent("getInfoAsync", anyTypeArr, function1));
            ModuleDefinitionBuilder moduleDefinitionBuilder3 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr2 = new AnyType[2];
            AnyType anyType3 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType3 == null) {
                anyType3 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr2[0] = anyType3;
            AnyType anyType4 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(ReadingOptions.class), false));
            if (anyType4 == null) {
                anyType4 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(ReadingOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(ReadingOptions.class);
                    }
                }));
            }
            anyTypeArr2[1] = anyType4;
            moduleDefinitionBuilder3.getAsyncFunctions().put("readAsStringAsync", new AsyncFunctionComponent("readAsStringAsync", anyTypeArr2, new Function1<Object[], String>() {
                {
                    super(1);
                }

                public final String invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    InputStream openResourceInputStream;
                    InputStream openAssetInputStream;
                    File file;
                    InputStream inputStream;
                    byte[] inputStreamBytes;
                    String encodeToString;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Object obj = objArr[0];
                    ReadingOptions readingOptions = (ReadingOptions) objArr[1];
                    String str = (String) obj;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    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 + "'.");
                }
            }));
            ModuleDefinitionBuilder moduleDefinitionBuilder4 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr3 = new AnyType[3];
            AnyType anyType5 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType5 == null) {
                anyType5 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr3[0] = anyType5;
            AnyType anyType6 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType6 == null) {
                anyType6 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr3[1] = anyType6;
            AnyType anyType7 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(WritingOptions.class), false));
            if (anyType7 == null) {
                anyType7 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(WritingOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(WritingOptions.class);
                    }
                }));
            }
            anyTypeArr3[2] = anyType7;
            Function1<Object[], Unit> function12 = new Function1<Object[], Unit>() {
                {
                    super(1);
                }

                public final Unit invoke(Object[] objArr) {
                    String slashifyFilePath;
                    OutputStream outputStream;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Object obj = objArr[0];
                    Object obj2 = objArr[1];
                    WritingOptions writingOptions = (WritingOptions) objArr[2];
                    String str = (String) obj2;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    fileSystemModule2.ensurePermission(parse, Permission.WRITE);
                    EncodingType encoding = writingOptions.getEncoding();
                    outputStream = FileSystemModule.this.getOutputStream(parse);
                    OutputStreamWriter outputStreamWriter = outputStream;
                    try {
                        OutputStream outputStream2 = outputStreamWriter;
                        if (encoding == EncodingType.BASE64) {
                            outputStream2.write(Base64.decode(str, 0));
                        } else {
                            outputStreamWriter = new OutputStreamWriter(outputStream2);
                            try {
                                outputStreamWriter.write(str);
                                Unit unit = Unit.INSTANCE;
                                CloseableKt.closeFinally(outputStreamWriter, (Throwable) null);
                            } finally {
                            }
                        }
                        Unit unit2 = Unit.INSTANCE;
                        CloseableKt.closeFinally(outputStreamWriter, (Throwable) null);
                        return Unit.INSTANCE;
                    } finally {
                    }
                }
            };
            moduleDefinitionBuilder4.getAsyncFunctions().put("writeAsStringAsync", Intrinsics.areEqual(Unit.class, Integer.TYPE) ? new IntAsyncFunctionComponent("writeAsStringAsync", anyTypeArr3, function12) : Intrinsics.areEqual(Unit.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("writeAsStringAsync", anyTypeArr3, function12) : Intrinsics.areEqual(Unit.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("writeAsStringAsync", anyTypeArr3, function12) : Intrinsics.areEqual(Unit.class, Float.TYPE) ? new FloatAsyncFunctionComponent("writeAsStringAsync", anyTypeArr3, function12) : Intrinsics.areEqual(Unit.class, String.class) ? new StringAsyncFunctionComponent("writeAsStringAsync", anyTypeArr3, function12) : new AsyncFunctionComponent("writeAsStringAsync", anyTypeArr3, function12));
            ModuleDefinitionBuilder moduleDefinitionBuilder5 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr4 = new AnyType[2];
            AnyType anyType8 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType8 == null) {
                anyType8 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr4[0] = anyType8;
            AnyType anyType9 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(DeletingOptions.class), false));
            if (anyType9 == null) {
                anyType9 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DeletingOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(DeletingOptions.class);
                    }
                }));
            }
            anyTypeArr4[1] = anyType9;
            Function1<Object[], Unit> function13 = new Function1<Object[], Unit>() {
                {
                    super(1);
                }

                public final Unit invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Object obj = objArr[0];
                    DeletingOptions deletingOptions = (DeletingOptions) objArr[1];
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                    Uri parse = Uri.parse(slashifyFilePath);
                    Uri withAppendedPath = Uri.withAppendedPath(parse, "..");
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(withAppendedPath);
                    fileSystemModule2.ensurePermission(withAppendedPath, Permission.WRITE, "Location '" + parse + "' isn't deletable.");
                    if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                        FileSystemModule fileSystemModule3 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        file = fileSystemModule3.toFile(parse);
                        if (file.exists()) {
                            FileUtils.forceDelete(file);
                        } else if (!deletingOptions.getIdempotent()) {
                            throw new FileSystemFileNotFoundException(parse);
                        }
                    } else {
                        FileSystemModule fileSystemModule4 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        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;
                }
            };
            moduleDefinitionBuilder5.getAsyncFunctions().put("deleteAsync", Intrinsics.areEqual(Unit.class, Integer.TYPE) ? new IntAsyncFunctionComponent("deleteAsync", anyTypeArr4, function13) : Intrinsics.areEqual(Unit.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("deleteAsync", anyTypeArr4, function13) : Intrinsics.areEqual(Unit.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("deleteAsync", anyTypeArr4, function13) : Intrinsics.areEqual(Unit.class, Float.TYPE) ? new FloatAsyncFunctionComponent("deleteAsync", anyTypeArr4, function13) : Intrinsics.areEqual(Unit.class, String.class) ? new StringAsyncFunctionComponent("deleteAsync", anyTypeArr4, function13) : new AsyncFunctionComponent("deleteAsync", anyTypeArr4, function13));
            ModuleDefinitionBuilder moduleDefinitionBuilder6 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(RelocatingOptions.class, Promise.class)) {
                intAsyncFunctionComponent = 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(...)");
                        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.checkNotNull(parse2);
                        fileSystemModule3.ensurePermission(parse2, Permission.WRITE);
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            FileSystemModule fileSystemModule4 = FileSystemModule.this;
                            Intrinsics.checkNotNull(parse);
                            file2 = fileSystemModule4.toFile(parse);
                            file3 = FileSystemModule.this.toFile(parse2);
                            if (!file2.renameTo(file3)) {
                                throw new FileSystemCannotMoveFileException(parse, parse2);
                            }
                            return;
                        }
                        FileSystemModule fileSystemModule5 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        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;
                    }
                });
            } else {
                AnyType[] anyTypeArr5 = new AnyType[1];
                AnyType anyType10 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(RelocatingOptions.class), false));
                if (anyType10 == null) {
                    anyType10 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(RelocatingOptions.class), false, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.typeOf(RelocatingOptions.class);
                        }
                    }));
                }
                anyTypeArr5[0] = anyType10;
                Function1<Object[], Unit> function14 = new Function1<Object[], Unit>() {
                    {
                        super(1);
                    }

                    public final Unit invoke(Object[] objArr) {
                        String slashifyFilePath;
                        String slashifyFilePath2;
                        boolean isSAFUri;
                        DocumentFile nearestSAFFile;
                        File file;
                        File file2;
                        File file3;
                        Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                        RelocatingOptions relocatingOptions = (RelocatingOptions) objArr[0];
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getFrom());
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Uri withAppendedPath = Uri.withAppendedPath(parse, "..");
                        Intrinsics.checkNotNullExpressionValue(withAppendedPath, "withAppendedPath(...)");
                        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.checkNotNull(parse2);
                        fileSystemModule3.ensurePermission(parse2, Permission.WRITE);
                        if (Intrinsics.areEqual(parse.getScheme(), "file")) {
                            FileSystemModule fileSystemModule4 = FileSystemModule.this;
                            Intrinsics.checkNotNull(parse);
                            file2 = fileSystemModule4.toFile(parse);
                            file3 = FileSystemModule.this.toFile(parse2);
                            if (!file2.renameTo(file3)) {
                                throw new FileSystemCannotMoveFileException(parse, parse2);
                            }
                        } else {
                            FileSystemModule fileSystemModule5 = FileSystemModule.this;
                            Intrinsics.checkNotNull(parse);
                            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;
                    }
                };
                intAsyncFunctionComponent = Intrinsics.areEqual(Unit.class, Integer.TYPE) ? new IntAsyncFunctionComponent("moveAsync", anyTypeArr5, function14) : Intrinsics.areEqual(Unit.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("moveAsync", anyTypeArr5, function14) : Intrinsics.areEqual(Unit.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("moveAsync", anyTypeArr5, function14) : Intrinsics.areEqual(Unit.class, Float.TYPE) ? new FloatAsyncFunctionComponent("moveAsync", anyTypeArr5, function14) : Intrinsics.areEqual(Unit.class, String.class) ? new StringAsyncFunctionComponent("moveAsync", anyTypeArr5, function14) : new AsyncFunctionComponent("moveAsync", anyTypeArr5, function14);
            }
            moduleDefinitionBuilder6.getAsyncFunctions().put("moveAsync", intAsyncFunctionComponent);
            ModuleDefinitionBuilder moduleDefinitionBuilder7 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(RelocatingOptions.class, Promise.class)) {
                intAsyncFunctionComponent2 = 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.checkNotNull(parse);
                        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.checkNotNull(parse2);
                        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;
                    }
                });
            } else {
                AnyType[] anyTypeArr6 = new AnyType[1];
                AnyType anyType11 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(RelocatingOptions.class), false));
                if (anyType11 == null) {
                    anyType11 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(RelocatingOptions.class), false, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.typeOf(RelocatingOptions.class);
                        }
                    }));
                }
                anyTypeArr6[0] = anyType11;
                Function1<Object[], Object> function15 = 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, "<name for destructuring parameter 0>");
                        RelocatingOptions relocatingOptions = (RelocatingOptions) objArr[0];
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(relocatingOptions.getFrom());
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        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.checkNotNull(parse2);
                        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 + "'.");
                    }
                };
                intAsyncFunctionComponent2 = Intrinsics.areEqual(Object.class, Integer.TYPE) ? new IntAsyncFunctionComponent("copyAsync", anyTypeArr6, function15) : Intrinsics.areEqual(Object.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("copyAsync", anyTypeArr6, function15) : Intrinsics.areEqual(Object.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("copyAsync", anyTypeArr6, function15) : Intrinsics.areEqual(Object.class, Float.TYPE) ? new FloatAsyncFunctionComponent("copyAsync", anyTypeArr6, function15) : Intrinsics.areEqual(Object.class, String.class) ? new StringAsyncFunctionComponent("copyAsync", anyTypeArr6, function15) : new AsyncFunctionComponent("copyAsync", anyTypeArr6, function15);
            }
            moduleDefinitionBuilder7.getAsyncFunctions().put("copyAsync", intAsyncFunctionComponent2);
            ModuleDefinitionBuilder moduleDefinitionBuilder8 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr7 = new AnyType[2];
            AnyType anyType12 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType12 == null) {
                anyType12 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr7[0] = anyType12;
            AnyType anyType13 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(MakeDirectoryOptions.class), false));
            if (anyType13 == null) {
                anyType13 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(MakeDirectoryOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(MakeDirectoryOptions.class);
                    }
                }));
            }
            anyTypeArr7[1] = anyType13;
            Function1<Object[], Unit> function16 = new Function1<Object[], Unit>() {
                {
                    super(1);
                }

                public final Unit invoke(Object[] objArr) {
                    String slashifyFilePath;
                    File file;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Object obj = objArr[0];
                    MakeDirectoryOptions makeDirectoryOptions = (MakeDirectoryOptions) objArr[1];
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    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;
                }
            };
            moduleDefinitionBuilder8.getAsyncFunctions().put("makeDirectoryAsync", Intrinsics.areEqual(Unit.class, Integer.TYPE) ? new IntAsyncFunctionComponent("makeDirectoryAsync", anyTypeArr7, function16) : Intrinsics.areEqual(Unit.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("makeDirectoryAsync", anyTypeArr7, function16) : Intrinsics.areEqual(Unit.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("makeDirectoryAsync", anyTypeArr7, function16) : Intrinsics.areEqual(Unit.class, Float.TYPE) ? new FloatAsyncFunctionComponent("makeDirectoryAsync", anyTypeArr7, function16) : Intrinsics.areEqual(Unit.class, String.class) ? new StringAsyncFunctionComponent("makeDirectoryAsync", anyTypeArr7, function16) : new AsyncFunctionComponent("makeDirectoryAsync", anyTypeArr7, function16));
            ModuleDefinitionBuilder moduleDefinitionBuilder9 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(String.class, Promise.class)) {
                intAsyncFunctionComponent3 = 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.checkNotNull(parse);
                        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;
                    }
                });
            } else {
                AnyType[] anyTypeArr8 = new AnyType[1];
                AnyType anyType14 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), true));
                if (anyType14 == null) {
                    anyType14 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.nullableTypeOf(String.class);
                        }
                    }));
                }
                anyTypeArr8[0] = anyType14;
                Function1<Object[], List<? extends String>> function17 = new Function1<Object[], List<? extends String>>() {
                    {
                        super(1);
                    }

                    public final List<? extends String> invoke(Object[] objArr) {
                        String slashifyFilePath;
                        boolean isSAFUri;
                        File file;
                        Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) objArr[0]);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        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 + "'.");
                    }
                };
                intAsyncFunctionComponent3 = Intrinsics.areEqual(List.class, Integer.TYPE) ? new IntAsyncFunctionComponent("readDirectoryAsync", anyTypeArr8, function17) : Intrinsics.areEqual(List.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("readDirectoryAsync", anyTypeArr8, function17) : Intrinsics.areEqual(List.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("readDirectoryAsync", anyTypeArr8, function17) : Intrinsics.areEqual(List.class, Float.TYPE) ? new FloatAsyncFunctionComponent("readDirectoryAsync", anyTypeArr8, function17) : Intrinsics.areEqual(List.class, String.class) ? new StringAsyncFunctionComponent("readDirectoryAsync", anyTypeArr8, function17) : new AsyncFunctionComponent("readDirectoryAsync", anyTypeArr8, function17);
            }
            moduleDefinitionBuilder9.getAsyncFunctions().put("readDirectoryAsync", intAsyncFunctionComponent3);
            ModuleDefinitionBuilder moduleDefinitionBuilder10 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr9 = new AnyType[0];
            Function1<Object[], Double> function18 = new Function1<Object[], Double>() {
                public final Double 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));
                }
            };
            moduleDefinitionBuilder10.getAsyncFunctions().put("getTotalDiskCapacityAsync", Intrinsics.areEqual(Double.class, Integer.TYPE) ? new IntAsyncFunctionComponent("getTotalDiskCapacityAsync", anyTypeArr9, function18) : Intrinsics.areEqual(Double.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("getTotalDiskCapacityAsync", anyTypeArr9, function18) : Intrinsics.areEqual(Double.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("getTotalDiskCapacityAsync", anyTypeArr9, function18) : Intrinsics.areEqual(Double.class, Float.TYPE) ? new FloatAsyncFunctionComponent("getTotalDiskCapacityAsync", anyTypeArr9, function18) : Intrinsics.areEqual(Double.class, String.class) ? new StringAsyncFunctionComponent("getTotalDiskCapacityAsync", anyTypeArr9, function18) : new AsyncFunctionComponent("getTotalDiskCapacityAsync", anyTypeArr9, function18));
            ModuleDefinitionBuilder moduleDefinitionBuilder11 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr10 = new AnyType[0];
            Function1<Object[], Double> function19 = new Function1<Object[], Double>() {
                public final Double 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));
                }
            };
            moduleDefinitionBuilder11.getAsyncFunctions().put("getFreeDiskStorageAsync", Intrinsics.areEqual(Double.class, Integer.TYPE) ? new IntAsyncFunctionComponent("getFreeDiskStorageAsync", anyTypeArr10, function19) : Intrinsics.areEqual(Double.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("getFreeDiskStorageAsync", anyTypeArr10, function19) : Intrinsics.areEqual(Double.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("getFreeDiskStorageAsync", anyTypeArr10, function19) : Intrinsics.areEqual(Double.class, Float.TYPE) ? new FloatAsyncFunctionComponent("getFreeDiskStorageAsync", anyTypeArr10, function19) : Intrinsics.areEqual(Double.class, String.class) ? new StringAsyncFunctionComponent("getFreeDiskStorageAsync", anyTypeArr10, function19) : new AsyncFunctionComponent("getFreeDiskStorageAsync", anyTypeArr10, function19));
            ModuleDefinitionBuilder moduleDefinitionBuilder12 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(String.class, Promise.class)) {
                intAsyncFunctionComponent4 = 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.checkNotNull(parse);
                        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;
                    }
                });
            } else {
                AnyType[] anyTypeArr11 = new AnyType[1];
                AnyType anyType15 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
                if (anyType15 == null) {
                    anyType15 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.typeOf(String.class);
                        }
                    }));
                }
                anyTypeArr11[0] = anyType15;
                Function1<Object[], String> function110 = new Function1<Object[], String>() {
                    {
                        super(1);
                    }

                    public final String invoke(Object[] objArr) {
                        String slashifyFilePath;
                        File file;
                        Uri contentUriFromFile;
                        Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                        String str = (String) objArr[0];
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath(str);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        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);
                    }
                };
                intAsyncFunctionComponent4 = Intrinsics.areEqual(String.class, Integer.TYPE) ? new IntAsyncFunctionComponent("getContentUriAsync", anyTypeArr11, function110) : Intrinsics.areEqual(String.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("getContentUriAsync", anyTypeArr11, function110) : Intrinsics.areEqual(String.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("getContentUriAsync", anyTypeArr11, function110) : Intrinsics.areEqual(String.class, Float.TYPE) ? new FloatAsyncFunctionComponent("getContentUriAsync", anyTypeArr11, function110) : Intrinsics.areEqual(String.class, String.class) ? new StringAsyncFunctionComponent("getContentUriAsync", anyTypeArr11, function110) : new AsyncFunctionComponent("getContentUriAsync", anyTypeArr11, function110);
            }
            moduleDefinitionBuilder12.getAsyncFunctions().put("getContentUriAsync", intAsyncFunctionComponent4);
            ModuleDefinitionBuilder moduleDefinitionBuilder13 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(String.class, Promise.class)) {
                intAsyncFunctionComponent5 = 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.checkNotNull(parse);
                        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, "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;
                    }
                });
            } else {
                AnyType[] anyTypeArr12 = new AnyType[1];
                AnyType anyType16 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
                if (anyType16 == null) {
                    anyType16 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.typeOf(String.class);
                        }
                    }));
                }
                anyTypeArr12[0] = anyType16;
                Function1<Object[], List<? extends String>> function111 = new Function1<Object[], List<? extends String>>() {
                    {
                        super(1);
                    }

                    public final List<? extends String> invoke(Object[] objArr) {
                        String slashifyFilePath;
                        boolean isSAFUri;
                        Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                        slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) objArr[0]);
                        Uri parse = Uri.parse(slashifyFilePath);
                        FileSystemModule fileSystemModule2 = FileSystemModule.this;
                        Intrinsics.checkNotNull(parse);
                        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, "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.");
                    }
                };
                intAsyncFunctionComponent5 = Intrinsics.areEqual(List.class, Integer.TYPE) ? new IntAsyncFunctionComponent("readSAFDirectoryAsync", anyTypeArr12, function111) : Intrinsics.areEqual(List.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("readSAFDirectoryAsync", anyTypeArr12, function111) : Intrinsics.areEqual(List.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("readSAFDirectoryAsync", anyTypeArr12, function111) : Intrinsics.areEqual(List.class, Float.TYPE) ? new FloatAsyncFunctionComponent("readSAFDirectoryAsync", anyTypeArr12, function111) : Intrinsics.areEqual(List.class, String.class) ? new StringAsyncFunctionComponent("readSAFDirectoryAsync", anyTypeArr12, function111) : new AsyncFunctionComponent("readSAFDirectoryAsync", anyTypeArr12, function111);
            }
            moduleDefinitionBuilder13.getAsyncFunctions().put("readSAFDirectoryAsync", intAsyncFunctionComponent5);
            ModuleDefinitionBuilder moduleDefinitionBuilder14 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr13 = new AnyType[2];
            AnyType anyType17 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType17 == null) {
                anyType17 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr13[0] = anyType17;
            AnyType anyType18 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType18 == null) {
                anyType18 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr13[1] = anyType18;
            Function1<Object[], String> function112 = new Function1<Object[], String>() {
                {
                    super(1);
                }

                public final String invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Object obj = objArr[0];
                    String str = (String) objArr[1];
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    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.checkNotNull(createDirectory);
                        return createDirectory.getUri().toString();
                    }
                    throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI. Try using FileSystem.makeDirectoryAsync instead.");
                }
            };
            moduleDefinitionBuilder14.getAsyncFunctions().put("makeSAFDirectoryAsync", Intrinsics.areEqual(String.class, Integer.TYPE) ? new IntAsyncFunctionComponent("makeSAFDirectoryAsync", anyTypeArr13, function112) : Intrinsics.areEqual(String.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("makeSAFDirectoryAsync", anyTypeArr13, function112) : Intrinsics.areEqual(String.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("makeSAFDirectoryAsync", anyTypeArr13, function112) : Intrinsics.areEqual(String.class, Float.TYPE) ? new FloatAsyncFunctionComponent("makeSAFDirectoryAsync", anyTypeArr13, function112) : Intrinsics.areEqual(String.class, String.class) ? new StringAsyncFunctionComponent("makeSAFDirectoryAsync", anyTypeArr13, function112) : new AsyncFunctionComponent("makeSAFDirectoryAsync", anyTypeArr13, function112));
            ModuleDefinitionBuilder moduleDefinitionBuilder15 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr14 = new AnyType[3];
            AnyType anyType19 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType19 == null) {
                anyType19 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr14[0] = anyType19;
            AnyType anyType20 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType20 == null) {
                anyType20 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr14[1] = anyType20;
            AnyType anyType21 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType21 == null) {
                anyType21 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr14[2] = anyType21;
            Function1<Object[], String> function113 = new Function1<Object[], String>() {
                {
                    super(1);
                }

                public final String invoke(Object[] objArr) {
                    String slashifyFilePath;
                    boolean isSAFUri;
                    DocumentFile nearestSAFFile;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Object obj = objArr[0];
                    Object obj2 = objArr[1];
                    String str = (String) objArr[2];
                    String str2 = (String) obj2;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    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(str, str2);
                        if (createFile == null) {
                            throw new FileSystemCannotCreateFileException(null);
                        }
                        Intrinsics.checkNotNull(createFile);
                        return createFile.getUri().toString();
                    }
                    throw new IOException("The URI '" + parse + "' is not a Storage Access Framework URI.");
                }
            };
            moduleDefinitionBuilder15.getAsyncFunctions().put("createSAFFileAsync", Intrinsics.areEqual(String.class, Integer.TYPE) ? new IntAsyncFunctionComponent("createSAFFileAsync", anyTypeArr14, function113) : Intrinsics.areEqual(String.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("createSAFFileAsync", anyTypeArr14, function113) : Intrinsics.areEqual(String.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("createSAFFileAsync", anyTypeArr14, function113) : Intrinsics.areEqual(String.class, Float.TYPE) ? new FloatAsyncFunctionComponent("createSAFFileAsync", anyTypeArr14, function113) : Intrinsics.areEqual(String.class, String.class) ? new StringAsyncFunctionComponent("createSAFFileAsync", anyTypeArr14, function113) : new AsyncFunctionComponent("createSAFFileAsync", anyTypeArr14, function113));
            ModuleDefinitionBuilder moduleDefinitionBuilder16 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr15 = new AnyType[1];
            AnyType anyType22 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), true));
            if (anyType22 == null) {
                anyType22 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.nullableTypeOf(String.class);
                    }
                }));
            }
            anyTypeArr15[0] = anyType22;
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent = new AsyncFunctionWithPromiseComponent("requestDirectoryPermissionsAsync", anyTypeArr15, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, Promise promise) {
                    Promise promise2;
                    String slashifyFilePath;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    String str = (String) objArr[0];
                    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;
                    FileSystemModule.this.getAppContext().getThrowingActivity().startActivityForResult(intent, 5394);
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            });
            moduleDefinitionBuilder16.getAsyncFunctions().put("requestDirectoryPermissionsAsync", asyncFunctionWithPromiseComponent);
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent2 = asyncFunctionWithPromiseComponent;
            ModuleDefinitionBuilder moduleDefinitionBuilder17 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr16 = new AnyType[3];
            AnyType anyType23 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType23 == null) {
                anyType23 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr16[0] = anyType23;
            AnyType anyType24 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType24 == null) {
                anyType24 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr16[1] = anyType24;
            AnyType anyType25 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false));
            if (anyType25 == null) {
                anyType25 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(FileSystemUploadOptions.class);
                    }
                }));
            }
            anyTypeArr16[2] = anyType25;
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent3 = new AsyncFunctionWithPromiseComponent("uploadAsync", anyTypeArr16, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, final Promise promise) {
                    Request createUploadRequest;
                    OkHttpClient okHttpClient;
                    Unit unit;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    Object obj2 = objArr[1];
                    FileSystemUploadOptions fileSystemUploadOptions = (FileSystemUploadOptions) objArr[2];
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    createUploadRequest = fileSystemModule2.createUploadRequest((String) obj, (String) obj2, fileSystemUploadOptions, new RequestBodyDecorator() {
                        @Override
                        public final RequestBody decorate(RequestBody requestBody) {
                            Intrinsics.checkNotNullParameter(requestBody, "requestBody");
                            return requestBody;
                        }
                    });
                    okHttpClient = FileSystemModule.this.getOkHttpClient();
                    if (okHttpClient != null) {
                        Call newCall = okHttpClient.newCall(createUploadRequest);
                        final FileSystemModule fileSystemModule3 = FileSystemModule.this;
                        newCall.enqueue(new Callback() {
                            public void onFailure(Call call, IOException e) {
                                String str;
                                String str2;
                                Intrinsics.checkNotNullParameter(call, "call");
                                Intrinsics.checkNotNullParameter(e, "e");
                                str = FileSystemModuleKt.TAG;
                                Log.e(str, String.valueOf(e.getMessage()));
                                Promise promise2 = Promise.this;
                                str2 = FileSystemModuleKt.TAG;
                                Intrinsics.checkNotNullExpressionValue(str2, "access$getTAG$p(...)");
                                promise2.reject(str2, e.getMessage(), e);
                            }

                            public void onResponse(Call call, Response response) {
                                Bundle translateHeaders;
                                Intrinsics.checkNotNullParameter(call, "call");
                                Intrinsics.checkNotNullParameter(response, "response");
                                Bundle bundle = new Bundle();
                                FileSystemModule fileSystemModule4 = fileSystemModule3;
                                ResponseBody body = response.body();
                                bundle.putString("body", body != null ? body.string() : null);
                                bundle.putInt(PermissionsResponse.STATUS_KEY, response.code());
                                translateHeaders = fileSystemModule4.translateHeaders(response.headers());
                                bundle.putBundle("headers", translateHeaders);
                                response.close();
                                Promise.this.resolve(bundle);
                            }
                        });
                        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;
                }
            });
            moduleDefinitionBuilder17.getAsyncFunctions().put("uploadAsync", asyncFunctionWithPromiseComponent3);
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent4 = asyncFunctionWithPromiseComponent3;
            ModuleDefinitionBuilder moduleDefinitionBuilder18 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr17 = new AnyType[4];
            AnyType anyType26 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType26 == null) {
                anyType26 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr17[0] = anyType26;
            AnyType anyType27 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType27 == null) {
                anyType27 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr17[1] = anyType27;
            AnyType anyType28 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType28 == null) {
                anyType28 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr17[2] = anyType28;
            AnyType anyType29 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false));
            if (anyType29 == null) {
                anyType29 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(FileSystemUploadOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(FileSystemUploadOptions.class);
                    }
                }));
            }
            anyTypeArr17[3] = anyType29;
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent5 = new AsyncFunctionWithPromiseComponent("uploadTaskStartAsync", anyTypeArr17, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, final Promise promise) {
                    Request createUploadRequest;
                    OkHttpClient okHttpClient;
                    Map map;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    Object obj2 = objArr[1];
                    Object obj3 = objArr[2];
                    FileSystemUploadOptions fileSystemUploadOptions = (FileSystemUploadOptions) objArr[3];
                    final String str = (String) obj3;
                    final FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    final CountingRequestListener countingRequestListener = new CountingRequestListener() {
                        private long mLastUpdate = -1;

                        @Override
                        public void onProgress(long bytesWritten, long contentLength) {
                            Bundle bundle = new Bundle();
                            Bundle bundle2 = new Bundle();
                            long currentTimeMillis = System.currentTimeMillis();
                            if (currentTimeMillis > this.mLastUpdate + 100 || bytesWritten == contentLength) {
                                this.mLastUpdate = currentTimeMillis;
                                bundle2.putDouble("totalBytesSent", bytesWritten);
                                bundle2.putDouble("totalBytesExpectedToSend", contentLength);
                                bundle.putString("uuid", str);
                                bundle.putBundle("data", bundle2);
                                fileSystemModule2.sendEvent("expo-file-system.uploadProgress", bundle);
                            }
                        }
                    };
                    FileSystemModule fileSystemModule3 = FileSystemModule.this;
                    createUploadRequest = fileSystemModule3.createUploadRequest((String) obj, (String) obj2, fileSystemUploadOptions, new RequestBodyDecorator() {
                        @Override
                        public final RequestBody decorate(RequestBody requestBody) {
                            Intrinsics.checkNotNullParameter(requestBody, "requestBody");
                            return new CountingRequestBody(requestBody, CountingRequestListener.this);
                        }
                    });
                    okHttpClient = FileSystemModule.this.getOkHttpClient();
                    Intrinsics.checkNotNull(okHttpClient);
                    Call newCall = okHttpClient.newCall(createUploadRequest);
                    map = FileSystemModule.this.taskHandlers;
                    map.put(str, new FileSystemModule.TaskHandler(newCall));
                    final FileSystemModule fileSystemModule4 = FileSystemModule.this;
                    newCall.enqueue(new Callback() {
                        public void onFailure(Call call, IOException e) {
                            String str2;
                            String str3;
                            Intrinsics.checkNotNullParameter(call, "call");
                            Intrinsics.checkNotNullParameter(e, "e");
                            if (!call.isCanceled()) {
                                str2 = FileSystemModuleKt.TAG;
                                Log.e(str2, String.valueOf(e.getMessage()));
                                Promise promise2 = Promise.this;
                                str3 = FileSystemModuleKt.TAG;
                                Intrinsics.checkNotNullExpressionValue(str3, "access$getTAG$p(...)");
                                promise2.reject(str3, e.getMessage(), e);
                                return;
                            }
                            Promise.this.resolve((Object) null);
                        }

                        public void onResponse(Call call, Response response) {
                            Bundle translateHeaders;
                            Intrinsics.checkNotNullParameter(call, "call");
                            Intrinsics.checkNotNullParameter(response, "response");
                            Bundle bundle = new Bundle();
                            ResponseBody body = response.body();
                            FileSystemModule fileSystemModule5 = fileSystemModule4;
                            bundle.putString("body", body != null ? body.string() : null);
                            bundle.putInt(PermissionsResponse.STATUS_KEY, response.code());
                            translateHeaders = fileSystemModule5.translateHeaders(response.headers());
                            bundle.putBundle("headers", translateHeaders);
                            response.close();
                            Promise.this.resolve(bundle);
                        }
                    });
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            });
            moduleDefinitionBuilder18.getAsyncFunctions().put("uploadTaskStartAsync", asyncFunctionWithPromiseComponent5);
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent6 = asyncFunctionWithPromiseComponent5;
            ModuleDefinitionBuilder moduleDefinitionBuilder19 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr18 = new AnyType[3];
            AnyType anyType30 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType30 == null) {
                anyType30 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr18[0] = anyType30;
            AnyType anyType31 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), true));
            if (anyType31 == null) {
                anyType31 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.nullableTypeOf(String.class);
                    }
                }));
            }
            anyTypeArr18[1] = anyType31;
            AnyType anyType32 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false));
            if (anyType32 == null) {
                anyType32 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(DownloadOptions.class);
                    }
                }));
            }
            anyTypeArr18[2] = anyType32;
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent7 = new AsyncFunctionWithPromiseComponent("downloadAsync", anyTypeArr18, new Function2<Object[], Promise, Unit>() {
                {
                    super(2);
                }

                public final void invoke(Object[] objArr, final Promise promise) {
                    String slashifyFilePath;
                    OkHttpClient okHttpClient;
                    Call newCall;
                    File file;
                    String md5;
                    Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    Object obj2 = objArr[1];
                    final DownloadOptions downloadOptions = (DownloadOptions) objArr[2];
                    String str = (String) obj;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj2);
                    final Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    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, "openRawResource(...)");
                        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("uri", Uri.fromFile(file).toString());
                        Boolean valueOf = Boolean.valueOf(downloadOptions.getMd5());
                        r7 = valueOf.booleanValue() ? valueOf : null;
                        if (r7 != null) {
                            r7.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) {
                            final FileSystemModule fileSystemModule3 = FileSystemModule.this;
                            newCall.enqueue(new Callback() {
                                public void onFailure(Call call, IOException e) {
                                    String str2;
                                    String str3;
                                    Intrinsics.checkNotNullParameter(call, "call");
                                    Intrinsics.checkNotNullParameter(e, "e");
                                    str2 = FileSystemModuleKt.TAG;
                                    Log.e(str2, String.valueOf(e.getMessage()));
                                    Promise promise2 = Promise.this;
                                    str3 = FileSystemModuleKt.TAG;
                                    Intrinsics.checkNotNullExpressionValue(str3, "access$getTAG$p(...)");
                                    promise2.reject(str3, e.getMessage(), e);
                                }

                                public void onResponse(Call call, Response response) throws IOException {
                                    File file2;
                                    Bundle translateHeaders;
                                    String md52;
                                    Intrinsics.checkNotNullParameter(call, "call");
                                    Intrinsics.checkNotNullParameter(response, "response");
                                    FileSystemModule fileSystemModule4 = fileSystemModule3;
                                    Uri uri = parse;
                                    Intrinsics.checkNotNullExpressionValue(uri, "$uri");
                                    file2 = fileSystemModule4.toFile(uri);
                                    file2.delete();
                                    BufferedSink buffer3 = Okio.buffer(Okio.sink$default(file2, false, 1, (Object) null));
                                    ResponseBody body = response.body();
                                    Intrinsics.checkNotNull(body);
                                    buffer3.writeAll(body.source());
                                    buffer3.close();
                                    Bundle bundle2 = new Bundle();
                                    FileSystemModule fileSystemModule5 = fileSystemModule3;
                                    DownloadOptions downloadOptions2 = downloadOptions;
                                    bundle2.putString("uri", Uri.fromFile(file2).toString());
                                    bundle2.putInt(PermissionsResponse.STATUS_KEY, response.code());
                                    translateHeaders = fileSystemModule5.translateHeaders(response.headers());
                                    bundle2.putBundle("headers", translateHeaders);
                                    if (downloadOptions2.getMd5()) {
                                        md52 = fileSystemModule5.md5(file2);
                                        bundle2.putString("md5", md52);
                                    }
                                    response.close();
                                    Promise.this.resolve(bundle2);
                                }
                            });
                            r7 = Unit.INSTANCE;
                        }
                        if (r7 == null) {
                            promise.reject(new FileSystemOkHttpNullException());
                            return;
                        }
                        return;
                    }
                    throw new IOException("Unsupported scheme for location '" + parse + "'.");
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            });
            moduleDefinitionBuilder19.getAsyncFunctions().put("downloadAsync", asyncFunctionWithPromiseComponent7);
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent8 = asyncFunctionWithPromiseComponent7;
            ModuleDefinitionBuilder moduleDefinitionBuilder20 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(String.class, Promise.class)) {
                asyncFunctionComponent = 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;
                    }
                });
            } else {
                AnyType[] anyTypeArr19 = new AnyType[1];
                AnyType anyType33 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
                if (anyType33 == null) {
                    anyType33 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.typeOf(String.class);
                        }
                    }));
                }
                anyTypeArr19[0] = anyType33;
                asyncFunctionComponent = new AsyncFunctionComponent("networkTaskCancelAsync", anyTypeArr19, new Function1<Object[], Unit>() {
                    {
                        super(1);
                    }

                    public final Unit invoke(Object[] objArr) {
                        Map map;
                        Call call;
                        Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                        String str = (String) objArr[0];
                        map = FileSystemModule.this.taskHandlers;
                        FileSystemModule.TaskHandler taskHandler = (FileSystemModule.TaskHandler) map.get(str);
                        if (taskHandler == null || (call = taskHandler.getCall()) == null) {
                            return null;
                        }
                        call.cancel();
                        return Unit.INSTANCE;
                    }
                });
            }
            moduleDefinitionBuilder20.getAsyncFunctions().put("networkTaskCancelAsync", asyncFunctionComponent);
            ModuleDefinitionBuilder moduleDefinitionBuilder21 = moduleDefinitionBuilder;
            AnyType[] anyTypeArr20 = new AnyType[5];
            AnyType anyType34 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType34 == null) {
                anyType34 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr20[0] = anyType34;
            AnyType anyType35 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType35 == null) {
                anyType35 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr20[1] = anyType35;
            AnyType anyType36 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
            if (anyType36 == null) {
                anyType36 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(String.class);
                    }
                }));
            }
            anyTypeArr20[2] = anyType36;
            AnyType anyType37 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false));
            if (anyType37 == null) {
                anyType37 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(DownloadOptions.class), false, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.typeOf(DownloadOptions.class);
                    }
                }));
            }
            anyTypeArr20[3] = anyType37;
            AnyType anyType38 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), true));
            if (anyType38 == null) {
                anyType38 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), true, new Function0<KType>() {
                    public final KType invoke() {
                        return Reflection.nullableTypeOf(String.class);
                    }
                }));
            }
            anyTypeArr20[4] = anyType38;
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent9 = new AsyncFunctionWithPromiseComponent("downloadResumableStartAsync", anyTypeArr20, 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, "<name for destructuring parameter 0>");
                    Intrinsics.checkNotNullParameter(promise, "promise");
                    Object obj = objArr[0];
                    Object obj2 = objArr[1];
                    Object obj3 = objArr[2];
                    Object obj4 = objArr[3];
                    final String str = (String) objArr[4];
                    DownloadOptions downloadOptions = (DownloadOptions) obj4;
                    final String str2 = (String) obj3;
                    String str3 = (String) obj;
                    slashifyFilePath = FileSystemModuleKt.slashifyFilePath((String) obj2);
                    Uri parse = Uri.parse(slashifyFilePath);
                    FileSystemModule fileSystemModule2 = FileSystemModule.this;
                    Intrinsics.checkNotNull(parse);
                    fileSystemModule2.checkIfFileDirExists(parse);
                    if (!Intrinsics.areEqual(parse.getScheme(), "file")) {
                        throw new IOException("Unsupported scheme for location '" + parse + "'.");
                    }
                    final FileSystemModule fileSystemModule3 = FileSystemModule.this;
                    final FileSystemModule.ProgressListener progressListener = new FileSystemModule.ProgressListener() {
                        private long mLastUpdate = -1;

                        public final long getMLastUpdate() {
                            return this.mLastUpdate;
                        }

                        public final void setMLastUpdate(long j) {
                            this.mLastUpdate = j;
                        }

                        @Override
                        public void update(long bytesRead, long contentLength, boolean done) {
                            Bundle bundle = new Bundle();
                            Bundle bundle2 = new Bundle();
                            String str4 = str;
                            long parseLong = bytesRead + (str4 != null ? Long.parseLong(str4) : 0L);
                            String str5 = str;
                            long parseLong2 = contentLength + (str5 != null ? Long.parseLong(str5) : 0L);
                            long currentTimeMillis = System.currentTimeMillis();
                            if (currentTimeMillis > this.mLastUpdate + 100 || parseLong == parseLong2) {
                                this.mLastUpdate = currentTimeMillis;
                                bundle2.putDouble("totalBytesWritten", parseLong);
                                bundle2.putDouble("totalBytesExpectedToWrite", parseLong2);
                                bundle.putString("uuid", str2);
                                bundle.putBundle("data", bundle2);
                                fileSystemModule3.sendEvent("expo-file-system.downloadProgress", bundle);
                            }
                        }
                    };
                    okHttpClient = FileSystemModule.this.getOkHttpClient();
                    OkHttpClient build = (okHttpClient == null || (newBuilder = okHttpClient.newBuilder()) == null || (addInterceptor = newBuilder.addInterceptor(new Interceptor() {
                        public final Response intercept(Interceptor.Chain chain) {
                            Intrinsics.checkNotNullParameter(chain, "chain");
                            Response proceed = chain.proceed(chain.request());
                            return proceed.newBuilder().body(new FileSystemModule.ProgressResponseBody(proceed.body(), FileSystemModule.ProgressListener.this)).build();
                        }
                    })) == null) ? null : addInterceptor.build();
                    if (build == null) {
                        promise.reject(new FileSystemOkHttpNullException());
                        return;
                    }
                    Request.Builder builder = new Request.Builder();
                    if (str != null) {
                        builder.addHeader(HttpHeaders.RANGE, "bytes=" + str + "-");
                    }
                    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(str3).build());
                    map = FileSystemModule.this.taskHandlers;
                    map.put(str2, new FileSystemModule.DownloadTaskHandler(parse, newCall));
                    file = FileSystemModule.this.toFile(parse);
                    FileSystemModule.DownloadResumableTaskParams downloadResumableTaskParams = new FileSystemModule.DownloadResumableTaskParams(downloadOptions, newCall, file, str != 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);
                }

                public Object invoke(Object obj, Object obj2) {
                    invoke((Object[]) obj, (Promise) obj2);
                    return Unit.INSTANCE;
                }
            });
            moduleDefinitionBuilder21.getAsyncFunctions().put("downloadResumableStartAsync", asyncFunctionWithPromiseComponent9);
            AsyncFunctionWithPromiseComponent asyncFunctionWithPromiseComponent10 = asyncFunctionWithPromiseComponent9;
            ModuleDefinitionBuilder moduleDefinitionBuilder22 = moduleDefinitionBuilder;
            if (Intrinsics.areEqual(String.class, Promise.class)) {
                intAsyncFunctionComponent6 = 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;
                    }
                });
            } else {
                AnyType[] anyTypeArr21 = new AnyType[1];
                AnyType anyType39 = AnyTypeProvider.INSTANCE.getTypesMap().get(new Pair(Reflection.getOrCreateKotlinClass(String.class), false));
                if (anyType39 == null) {
                    anyType39 = new AnyType(new LazyKType(Reflection.getOrCreateKotlinClass(String.class), false, new Function0<KType>() {
                        public final KType invoke() {
                            return Reflection.typeOf(String.class);
                        }
                    }));
                }
                anyTypeArr21[0] = anyType39;
                Function1<Object[], Bundle> function114 = new Function1<Object[], Bundle>() {
                    {
                        super(1);
                    }

                    public final Bundle invoke(Object[] objArr) {
                        Map map;
                        Map map2;
                        File file;
                        Intrinsics.checkNotNullParameter(objArr, "<name for destructuring parameter 0>");
                        String str = (String) objArr[0];
                        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;
                    }
                };
                intAsyncFunctionComponent6 = Intrinsics.areEqual(Bundle.class, Integer.TYPE) ? new IntAsyncFunctionComponent("downloadResumablePauseAsync", anyTypeArr21, function114) : Intrinsics.areEqual(Bundle.class, Boolean.TYPE) ? new BoolAsyncFunctionComponent("downloadResumablePauseAsync", anyTypeArr21, function114) : Intrinsics.areEqual(Bundle.class, Double.TYPE) ? new DoubleAsyncFunctionComponent("downloadResumablePauseAsync", anyTypeArr21, function114) : Intrinsics.areEqual(Bundle.class, Float.TYPE) ? new FloatAsyncFunctionComponent("downloadResumablePauseAsync", anyTypeArr21, function114) : Intrinsics.areEqual(Bundle.class, String.class) ? new StringAsyncFunctionComponent("downloadResumablePauseAsync", anyTypeArr21, function114) : new AsyncFunctionComponent("downloadResumablePauseAsync", anyTypeArr21, function114);
            }
            moduleDefinitionBuilder22.getAsyncFunctions().put("downloadResumablePauseAsync", intAsyncFunctionComponent6);
            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) {
                            Bundle bundle = new Bundle();
                            if (resultCode == -1 && data != null) {
                                Uri data2 = data.getData();
                                int flags = data.getFlags() & 3;
                                if (data2 != null) {
                                    FileSystemModule.this.getAppContext().getThrowingActivity().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() {
                    m481invoke();
                    return Unit.INSTANCE;
                }

                public final void m481invoke() {
                    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, "apply(...)");
        return noneOf;
    }

    public final void ensurePermission(Uri uri, Permission permission, String errorMsg) throws IOException {
        EnumSet<Permission> permissionsForUri = permissionsForUri(uri);
        if (permissionsForUri == null || !permissionsForUri.contains(permission)) {
            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(...)");
        String substring = path.substring(1);
        Intrinsics.checkNotNullExpressionValue(substring, "substring(...)");
        InputStream open = getContext().getAssets().open(substring);
        Intrinsics.checkNotNullExpressionValue(open, "open(...)");
        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, "openRawResource(...)");
        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, "listFiles(...)");
            for (DocumentFile documentFile2 : listFiles) {
                Intrinsics.checkNotNull(documentFile2);
                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) {
        Uri uriForFile = FileProvider.getUriForFile(getAppContext().getThrowingActivity().getApplication(), getAppContext().getThrowingActivity().getApplication().getPackageName() + ".FileSystemFileProvider", file);
        Intrinsics.checkNotNullExpressionValue(uriForFile, "getUriForFile(...)");
        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.checkNotNull(parse);
        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(...)");
        }
        String fieldName = options.getFieldName();
        if (fieldName == null) {
            fieldName = file.getName();
        }
        Intrinsics.checkNotNull(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, 9, 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() {
            return (((((((this.options.hashCode() * 31) + this.call.hashCode()) * 31) + this.file.hashCode()) * 31) + Boolean.hashCode(this.isResume)) * 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, 9, 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, 9, 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, 9, 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() {
        if (this.client == null) {
            this.client = new OkHttpClient.Builder().connectTimeout(60L, TimeUnit.SECONDS).readTimeout(60L, TimeUnit.SECONDS).writeTimeout(60L, TimeUnit.SECONDS).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(...)");
            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.checkNotNull(file2);
                    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.checkNotNull(file2);
            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.checkNotNull(openOutputStream);
        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, "substring(...)");
        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, "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;
    }
}