导航菜单

页面标题

页面副标题

RummyCircle v11000.89 - RNFetchBlob.java 源代码

正在查看: RummyCircle v11000.89 应用的 RNFetchBlob.java JAVA 源代码文件

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


package com.RNFetchBlob;

import android.app.Activity;
import android.app.DownloadManager;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.util.Base64;
import android.util.SparseArray;
import androidx.core.content.FileProvider;
import androidx.test.rule.PortForwardingRule;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.games24x7.coregame.common.utility.Constants;
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.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient;

public class RNFetchBlob extends ReactContextBaseJavaModule {
    private static boolean ActionViewVisible;
    static ReactApplicationContext RCTContext;
    static LinkedBlockingQueue<Runnable> fsTaskQueue;
    private static ThreadPoolExecutor fsThreadPool;
    private static SparseArray<Promise> promiseTable;
    private static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
    private static ThreadPoolExecutor threadPool;
    private final OkHttpClient mClient;

    public class a implements Runnable {
        public final String a;
        public final String b;
        public final Promise c;

        public a(String str, String str2, Promise promise) {
            this.a = str;
            this.b = str2;
            this.c = promise;
        }

        @Override
        public final void run() {
            String str = this.a;
            String str2 = this.b;
            Promise promise = this.c;
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            try {
                HashMap hashMap2 = new HashMap();
                hashMap2.put("md5", "MD5");
                hashMap2.put("sha1", "SHA-1");
                hashMap2.put("sha224", "SHA-224");
                hashMap2.put("sha256", "SHA-256");
                hashMap2.put("sha384", "SHA-384");
                hashMap2.put("sha512", "SHA-512");
                if (!hashMap2.containsKey(str2)) {
                    promise.reject("EINVAL", "Invalid algorithm '" + str2 + "', must be one of md5, sha1, sha224, sha256, sha384, sha512");
                    return;
                }
                File file = new File(str);
                if (file.isDirectory()) {
                    promise.reject("EISDIR", "Expecting a file but '" + str + "' is a directory");
                    return;
                }
                if (!file.exists()) {
                    promise.reject("ENOENT", "No such file '" + str + "'");
                    return;
                }
                MessageDigest messageDigest = MessageDigest.getInstance((String) hashMap2.get(str2));
                FileInputStream fileInputStream = new FileInputStream(str);
                byte[] bArr = new byte[1048576];
                if (file.length() != 0) {
                    while (true) {
                        int read = fileInputStream.read(bArr);
                        if (read == -1) {
                            break;
                        } else {
                            messageDigest.update(bArr, 0, read);
                        }
                    }
                }
                StringBuilder sb = new StringBuilder();
                for (byte b : messageDigest.digest()) {
                    sb.append(String.format("%02x", Integer.valueOf(b & 255)));
                }
                promise.resolve(sb.toString());
            } catch (Exception e) {
                e.printStackTrace();
                promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
            }
        }
    }

    public class b implements Runnable {
        public final ReactApplicationContext a;
        public final String b;
        public final String c;
        public final int d;
        public final int e;
        public final String f;

        public b(ReactApplicationContext reactApplicationContext, String str, String str2, int i, int i2, String str3) {
            this.a = reactApplicationContext;
            this.b = str;
            this.c = str2;
            this.d = i;
            this.e = i2;
            this.f = str3;
        }

        @Override
        public final void run() {
            int i;
            InputStream openInputStream;
            byte[] bArr;
            boolean equalsIgnoreCase;
            int i2;
            int i3;
            String str;
            String str2;
            com.RNFetchBlob.g gVar = new com.RNFetchBlob.g(this.a);
            String str3 = this.c;
            String str4 = this.f;
            String str5 = "base64";
            String str6 = this.b;
            String h = com.RNFetchBlob.g.h(str6);
            if (h != null) {
                str6 = h;
            }
            try {
                try {
                    i = str3.equalsIgnoreCase("base64") ? 4095 : 4096;
                    int i4 = this.d;
                    if (i4 > 0) {
                        i = i4;
                    }
                    openInputStream = (h == null || !str6.startsWith("bundle-assets://")) ? h == null ? RNFetchBlob.RCTContext.getContentResolver().openInputStream(Uri.parse(str6)) : new FileInputStream(new File(str6)) : RNFetchBlob.RCTContext.getAssets().open(str6.replace("bundle-assets://", ""));
                    bArr = new byte[i];
                    equalsIgnoreCase = str3.equalsIgnoreCase("utf8");
                    i2 = this.e;
                    i3 = -1;
                    str = "data";
                } catch (FileNotFoundException unused) {
                    str5 = str6;
                }
                try {
                    if (equalsIgnoreCase) {
                        CharsetEncoder newEncoder = Charset.forName("UTF-8").newEncoder();
                        while (true) {
                            int read = openInputStream.read(bArr);
                            if (read == i3) {
                                break;
                            }
                            newEncoder.encode(ByteBuffer.wrap(bArr).asCharBuffer());
                            gVar.b(str4, str, new String(bArr, 0, read));
                            if (i2 > 0) {
                                str2 = str;
                                SystemClock.sleep(i2);
                            } else {
                                str2 = str;
                            }
                            str = str2;
                            i3 = -1;
                        }
                    } else {
                        String str7 = "data";
                        if (str3.equalsIgnoreCase("ascii")) {
                            while (true) {
                                int read2 = openInputStream.read(bArr);
                                if (read2 == -1) {
                                    break;
                                }
                                WritableArray createArray = Arguments.createArray();
                                for (int i5 = 0; i5 < read2; i5++) {
                                    createArray.pushInt(bArr[i5]);
                                }
                                WritableMap createMap = Arguments.createMap();
                                String str8 = str7;
                                createMap.putString(Constants.Analytics.EVENT, str8);
                                createMap.putArray("detail", createArray);
                                gVar.a.emit(str4, createMap);
                                if (i2 > 0) {
                                    SystemClock.sleep(i2);
                                }
                                str7 = str8;
                            }
                        } else {
                            if (!str3.equalsIgnoreCase("base64")) {
                                str5 = str6;
                                gVar.c(str4, "EINVAL", "Unrecognized encoding `" + str3 + "`, should be one of `base64`, `utf8`, `ascii`");
                                openInputStream.close();
                            }
                            while (true) {
                                int read3 = openInputStream.read(bArr);
                                if (read3 == -1) {
                                    break;
                                }
                                if (read3 < i) {
                                    byte[] bArr2 = new byte[read3];
                                    System.arraycopy(bArr, 0, bArr2, 0, read3);
                                    gVar.b(str4, str7, Base64.encodeToString(bArr2, 2));
                                } else {
                                    gVar.b(str4, str7, Base64.encodeToString(bArr, 2));
                                }
                                if (i2 > 0) {
                                    String str9 = str6;
                                    SystemClock.sleep(i2);
                                    str6 = str9;
                                }
                            }
                        }
                    }
                    str5 = str6;
                    gVar.b(str4, "end", "");
                    openInputStream.close();
                } catch (FileNotFoundException unused2) {
                    gVar.c(str4, "ENOENT", androidx.camera.core.impl.utils.i.c("No such file '", str5, "'"));
                }
            } catch (Exception e) {
                gVar.c(str4, "EUNSPECIFIED", androidx.camera.core.impl.utils.i.c("Failed to convert data to ", str3, " encoded string. This might be because this encoding cannot be used for this data."));
                e.printStackTrace();
            }
        }
    }

    public class c implements Runnable {
        public final Callback a;

        public c(Callback callback) {
            this.a = callback;
        }

        @Override
        public final void run() {
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
            WritableMap createMap = Arguments.createMap();
            createMap.putString("internal_free", String.valueOf(statFs.getFreeBytes()));
            createMap.putString("internal_total", String.valueOf(statFs.getTotalBytes()));
            StatFs statFs2 = new StatFs(Environment.getExternalStorageDirectory().getPath());
            createMap.putString("external_free", String.valueOf(statFs2.getFreeBytes()));
            createMap.putString("external_total", String.valueOf(statFs2.getTotalBytes()));
            this.a.invoke(null, createMap);
        }
    }

    public class e implements Runnable {
        public final String a;
        public final String b;
        public final String c;
        public final Promise d;

        public e(String str, String str2, String str3, Promise promise) {
            this.a = str;
            this.b = str2;
            this.c = str3;
            this.d = promise;
        }

        @Override
        public final void run() {
            String str = this.a;
            String str2 = this.c;
            Promise promise = this.d;
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            try {
                File file = new File(str);
                boolean createNewFile = file.createNewFile();
                boolean equals = str2.equals("uri");
                String str3 = this.b;
                if (equals) {
                    File file2 = new File(str3.replace("RNFetchBlob-file://", ""));
                    if (!file2.exists()) {
                        promise.reject("ENOENT", "Source file : " + str3 + " does not exist");
                        return;
                    }
                    FileInputStream fileInputStream = new FileInputStream(file2);
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    byte[] bArr = new byte[10240];
                    for (int read = fileInputStream.read(bArr); read > 0; read = fileInputStream.read(bArr)) {
                        fileOutputStream.write(bArr, 0, read);
                    }
                    fileInputStream.close();
                    fileOutputStream.close();
                } else {
                    if (!createNewFile) {
                        promise.reject("EEXIST", "File `" + str + "` already exists");
                        return;
                    }
                    new FileOutputStream(file).write(com.RNFetchBlob.g.j(str3, str2));
                }
                promise.resolve(str);
            } catch (Exception e) {
                promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
            }
        }
    }

    public class f implements Runnable {
        public final String a;
        public final ReadableArray b;
        public final Promise c;

        public f(String str, ReadableArray readableArray, Promise promise) {
            this.a = str;
            this.b = readableArray;
            this.c = promise;
        }

        @Override
        public final void run() {
            String str = this.a;
            ReadableArray readableArray = this.b;
            Promise promise = this.c;
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            try {
                File file = new File(str);
                if (!file.createNewFile()) {
                    promise.reject("EEXIST", "File at path `" + str + "` already exists");
                    return;
                }
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                byte[] bArr = new byte[readableArray.size()];
                for (int i = 0; i < readableArray.size(); i++) {
                    bArr[i] = (byte) readableArray.getInt(i);
                }
                fileOutputStream.write(bArr);
                promise.resolve(str);
            } catch (Exception e) {
                promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
            }
        }
    }

    public class h implements Runnable {
        public final String a;
        public final String b;
        public final Callback c;

        public h(String str, String str2, Callback callback) {
            this.a = str;
            this.b = str2;
            this.c = callback;
        }

        @Override
        public final void run() {
            throw new UnsupportedOperationException("Method not decompiled: com.RNFetchBlob.RNFetchBlob.h.run():void");
        }
    }

    public class i implements Runnable {
        public final String a;
        public final String b;
        public final Promise c;

        public i(String str, String str2, Promise promise) {
            this.a = str;
            this.b = str2;
            this.c = promise;
        }

        @Override
        public final void run() {
            throw new UnsupportedOperationException("Method not decompiled: com.RNFetchBlob.RNFetchBlob.i.run():void");
        }
    }

    public class j implements Runnable {
        public final String a;
        public final ReadableArray b;
        public final boolean c;
        public final Promise d;

        public j(String str, ReadableArray readableArray, boolean z, Promise promise) {
            this.a = str;
            this.b = readableArray;
            this.c = z;
            this.d = promise;
        }

        @Override
        public final void run() {
            String str = this.a;
            ReadableArray readableArray = this.b;
            boolean z = this.c;
            Promise promise = this.d;
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            try {
                File file = new File(str);
                File parentFile = file.getParentFile();
                if (!file.exists()) {
                    if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs()) {
                        promise.reject("ENOTDIR", "Failed to create parent directory of '" + str + "'");
                        return;
                    }
                    if (!file.createNewFile()) {
                        promise.reject("ENOENT", "File '" + str + "' does not exist and could not be created");
                        return;
                    }
                }
                FileOutputStream fileOutputStream = new FileOutputStream(file, z);
                try {
                    byte[] bArr = new byte[readableArray.size()];
                    for (int i = 0; i < readableArray.size(); i++) {
                        bArr[i] = (byte) readableArray.getInt(i);
                    }
                    fileOutputStream.write(bArr);
                    fileOutputStream.close();
                    promise.resolve(Integer.valueOf(readableArray.size()));
                } catch (Throwable th) {
                    fileOutputStream.close();
                    throw th;
                }
            } catch (FileNotFoundException unused) {
                promise.reject("ENOENT", "File '" + str + "' does not exist and could not be created");
            } catch (Exception e) {
                promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
            }
        }
    }

    public class k implements Runnable {
        public final String a;
        public final String b;
        public final String c;
        public final boolean d;
        public final Promise e;

        public k(String str, String str2, String str3, boolean z, Promise promise) {
            this.a = str;
            this.b = str2;
            this.c = str3;
            this.d = z;
            this.e = promise;
        }

        @Override
        public final void run() {
            int length;
            FileOutputStream fileOutputStream;
            String str = this.a;
            String str2 = this.b;
            Promise promise = this.e;
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            try {
                File file = new File(str);
                File parentFile = file.getParentFile();
                if (!file.exists()) {
                    if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs()) {
                        promise.reject("EUNSPECIFIED", "Failed to create parent directory of '" + str + "'");
                        return;
                    }
                    if (!file.createNewFile()) {
                        promise.reject("ENOENT", "File '" + str + "' does not exist and could not be created");
                        return;
                    }
                }
                boolean equalsIgnoreCase = str2.equalsIgnoreCase("uri");
                String str3 = this.c;
                boolean z = this.d;
                if (equalsIgnoreCase) {
                    String h = com.RNFetchBlob.g.h(str3);
                    File file2 = new File(h);
                    if (!file2.exists()) {
                        promise.reject("ENOENT", "No such file '" + str + "' ('" + h + "')");
                        return;
                    }
                    byte[] bArr = new byte[10240];
                    FileInputStream fileInputStream = null;
                    try {
                        FileInputStream fileInputStream2 = new FileInputStream(file2);
                        try {
                            fileOutputStream = new FileOutputStream(file, z);
                            length = 0;
                            while (true) {
                                try {
                                    int read = fileInputStream2.read(bArr);
                                    if (read <= 0) {
                                        break;
                                    }
                                    fileOutputStream.write(bArr, 0, read);
                                    length += read;
                                } catch (Throwable th) {
                                    th = th;
                                    fileInputStream = fileInputStream2;
                                    if (fileInputStream != null) {
                                        fileInputStream.close();
                                    }
                                    if (fileOutputStream != null) {
                                        fileOutputStream.close();
                                    }
                                    throw th;
                                }
                            }
                            fileInputStream2.close();
                            fileOutputStream.close();
                        } catch (Throwable th2) {
                            th = th2;
                            fileOutputStream = null;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        fileOutputStream = null;
                    }
                } else {
                    byte[] j = com.RNFetchBlob.g.j(str3, str2);
                    FileOutputStream fileOutputStream2 = new FileOutputStream(file, z);
                    try {
                        fileOutputStream2.write(j);
                        length = j.length;
                    } finally {
                        fileOutputStream2.close();
                    }
                }
                promise.resolve(Integer.valueOf(length));
            } catch (FileNotFoundException unused) {
                promise.reject("ENOENT", "File '" + str + "' does not exist and could not be created, or it is a directory");
            } catch (Exception e) {
                promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
            }
        }
    }

    public class l implements Runnable {
        public final ReadableArray a;
        public final ReactApplicationContext b;
        public final Callback c;

        public l(ReadableArray readableArray, ReactApplicationContext reactApplicationContext, Callback callback) {
            this.a = readableArray;
            this.b = reactApplicationContext;
            this.c = callback;
        }

        @Override
        public final void run() {
            ReadableArray readableArray = this.a;
            int size = readableArray.size();
            String[] strArr = new String[size];
            String[] strArr2 = new String[size];
            for (int i = 0; i < size; i++) {
                ReadableMap map = readableArray.getMap(i);
                if (map.hasKey("path")) {
                    strArr[i] = map.getString("path");
                    if (map.hasKey("mime")) {
                        strArr2[i] = map.getString("mime");
                    } else {
                        strArr2[i] = null;
                    }
                }
            }
            ReactApplicationContext reactApplicationContext = this.b;
            new com.RNFetchBlob.g(reactApplicationContext);
            Callback callback = this.c;
            try {
                MediaScannerConnection.scanFile(reactApplicationContext, strArr, strArr2, new com.RNFetchBlob.e(callback));
            } catch (Exception e) {
                callback.invoke(e.getLocalizedMessage(), null);
            }
        }
    }

    static {
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        threadPool = new ThreadPoolExecutor(5, 10, Constants.Common.TN_SB_DURATION_DEFAULT, timeUnit, taskQueue);
        fsTaskQueue = new LinkedBlockingQueue<>();
        fsThreadPool = new ThreadPoolExecutor(2, 10, Constants.Common.TN_SB_DURATION_DEFAULT, timeUnit, taskQueue);
        ActionViewVisible = false;
        promiseTable = new SparseArray<>();
    }

    public RNFetchBlob(ReactApplicationContext reactApplicationContext) {
        super(reactApplicationContext);
        if (com.facebook.react.modules.network.h.a == null) {
            com.facebook.react.modules.network.h.a = com.facebook.react.modules.network.h.b().build();
        }
        OkHttpClient okHttpClient = com.facebook.react.modules.network.h.a;
        this.mClient = okHttpClient;
        ((com.facebook.react.modules.network.a) okHttpClient.cookieJar()).a(new JavaNetCookieJar(new com.facebook.react.modules.network.e(reactApplicationContext)));
        RCTContext = reactApplicationContext;
        reactApplicationContext.addActivityEventListener(new d());
    }

    @ReactMethod
    public void actionViewIntent(String str, String str2, Promise promise) {
        try {
            Intent dataAndType = new Intent("android.intent.action.VIEW").setDataAndType(FileProvider.d(getCurrentActivity(), new File(str), getReactApplicationContext().getPackageName() + ".provider"), str2);
            dataAndType.setFlags(1);
            dataAndType.addFlags(268435456);
            if (dataAndType.resolveActivity(getCurrentActivity().getPackageManager()) != null) {
                getReactApplicationContext().startActivity(dataAndType);
            }
            ActionViewVisible = true;
            RCTContext.addLifecycleEventListener(new g(promise));
        } catch (Exception e2) {
            promise.reject("EUNSPECIFIED", e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void addCompleteDownload(ReadableMap readableMap, Promise promise) {
        DownloadManager downloadManager = (DownloadManager) RCTContext.getSystemService("download");
        if (readableMap == null || !readableMap.hasKey("path")) {
            promise.reject("EINVAL", "RNFetchblob.addCompleteDownload config or path missing.");
            return;
        }
        String h2 = com.RNFetchBlob.g.h(readableMap.getString("path"));
        if (h2 == null) {
            promise.reject("EINVAL", "RNFetchblob.addCompleteDownload can not resolve URI:" + readableMap.getString("path"));
        } else {
            try {
                downloadManager.addCompletedDownload(readableMap.hasKey("title") ? readableMap.getString("title") : "", readableMap.hasKey("description") ? readableMap.getString("description") : "", true, readableMap.hasKey("mime") ? readableMap.getString("mime") : null, h2, Long.valueOf(com.RNFetchBlob.g.i(h2).getString("size")).longValue(), readableMap.hasKey("showNotification") && readableMap.getBoolean("showNotification"));
                promise.resolve(null);
            } catch (Exception e2) {
                promise.reject("EUNSPECIFIED", e2.getLocalizedMessage());
            }
        }
    }

    @ReactMethod
    public void cancelRequest(String str, Callback callback) {
        try {
            RNFetchBlobReq.a(str);
            callback.invoke(null, str);
        } catch (Exception e2) {
            callback.invoke(e2.getLocalizedMessage(), null);
        }
    }

    @ReactMethod
    public void closeStream(String str, Callback callback) {
        try {
            HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
            FileOutputStream fileOutputStream = hashMap.get(str).c;
            hashMap.remove(str);
            fileOutputStream.close();
            callback.invoke(new Object[0]);
        } catch (Exception e2) {
            callback.invoke(e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void cp(String str, String str2, Callback callback) {
        threadPool.execute(new h(str, str2, callback));
    }

    @ReactMethod
    public void createFile(String str, String str2, String str3, Promise promise) {
        threadPool.execute(new e(str, str2, str3, promise));
    }

    @ReactMethod
    public void createFileASCII(String str, ReadableArray readableArray, Promise promise) {
        threadPool.execute(new f(str, readableArray, promise));
    }

    @ReactMethod
    public void df(Callback callback) {
        fsThreadPool.execute(new c(callback));
    }

    @ReactMethod
    public void enableProgressReport(String str, int i2, int i3) {
        RNFetchBlobReq.u.put(str, new com.RNFetchBlob.i(i2, i3));
    }

    @ReactMethod
    public void enableUploadProgressReport(String str, int i2, int i3) {
        RNFetchBlobReq.v.put(str, new com.RNFetchBlob.i(i2, i3));
    }

    @ReactMethod
    public void exists(String str, Callback callback) {
        if (com.RNFetchBlob.g.f(str)) {
            try {
                RCTContext.getAssets().openFd(str.replace("bundle-assets://", ""));
                callback.invoke(Boolean.TRUE, Boolean.FALSE);
                return;
            } catch (IOException unused) {
                Boolean bool = Boolean.FALSE;
                callback.invoke(bool, bool);
                return;
            }
        }
        String h2 = com.RNFetchBlob.g.h(str);
        if (h2 != null) {
            callback.invoke(Boolean.valueOf(new File(h2).exists()), Boolean.valueOf(new File(h2).isDirectory()));
        } else {
            Boolean bool2 = Boolean.FALSE;
            callback.invoke(bool2, bool2);
        }
    }

    @ReactMethod
    public void fetchBlob(ReadableMap readableMap, String str, String str2, String str3, ReadableMap readableMap2, String str4, Callback callback) {
        new RNFetchBlobReq(readableMap, str, str2, str3, readableMap2, str4, null, this.mClient, callback).run();
    }

    @ReactMethod
    public void fetchBlobForm(ReadableMap readableMap, String str, String str2, String str3, ReadableMap readableMap2, ReadableArray readableArray, Callback callback) {
        new RNFetchBlobReq(readableMap, str, str2, str3, readableMap2, null, readableArray, this.mClient, callback).run();
    }

    @Override
    public Map<String, Object> getConstants() {
        ReactApplicationContext reactApplicationContext = getReactApplicationContext();
        HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
        HashMap hashMap2 = new HashMap();
        hashMap2.put("DocumentDir", reactApplicationContext.getFilesDir().getAbsolutePath());
        hashMap2.put("CacheDir", reactApplicationContext.getCacheDir().getAbsolutePath());
        hashMap2.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
        hashMap2.put("PictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
        hashMap2.put("MusicDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath());
        hashMap2.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
        hashMap2.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
        hashMap2.put("RingtoneDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
        if (Environment.getExternalStorageState().equals("mounted")) {
            hashMap2.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
            File externalFilesDir = reactApplicationContext.getExternalFilesDir(null);
            if (externalFilesDir != null) {
                hashMap2.put("SDCardApplicationDir", externalFilesDir.getParentFile().getAbsolutePath());
            } else {
                hashMap2.put("SDCardApplicationDir", "");
            }
        }
        hashMap2.put("MainBundleDir", reactApplicationContext.getApplicationInfo().dataDir);
        return hashMap2;
    }

    @ReactMethod
    public void getContentIntent(String str, Promise promise) {
        Intent intent = new Intent("android.intent.action.GET_CONTENT");
        if (str != null) {
            intent.setType(str);
        } else {
            intent.setType("*/*");
        }
        SparseArray<Promise> sparseArray = promiseTable;
        Integer num = com.RNFetchBlob.c.a;
        sparseArray.put(num.intValue(), promise);
        getReactApplicationContext().startActivityForResult(intent, num.intValue(), null);
    }

    @Override
    public String getName() {
        return "RNFetchBlob";
    }

    @ReactMethod
    public void getSDCardApplicationDir(Promise promise) {
        ReactApplicationContext reactApplicationContext = getReactApplicationContext();
        HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
        if (!Environment.getExternalStorageState().equals("mounted")) {
            promise.reject("RNFetchBlob.getSDCardApplicationDir", "External storage not mounted");
            return;
        }
        try {
            promise.resolve(reactApplicationContext.getExternalFilesDir(null).getParentFile().getAbsolutePath());
        } catch (Exception e2) {
            promise.reject("RNFetchBlob.getSDCardApplicationDir", e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void getSDCardDir(Promise promise) {
        HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
        if (Environment.getExternalStorageState().equals("mounted")) {
            promise.resolve(Environment.getExternalStorageDirectory().getAbsolutePath());
        } else {
            promise.reject("RNFetchBlob.getSDCardDir", "External storage not mounted");
        }
    }

    @ReactMethod
    public void hash(String str, String str2, Promise promise) {
        threadPool.execute(new a(str, str2, promise));
    }

    @ReactMethod
    public void ls(String str, Promise promise) {
        try {
            String h2 = com.RNFetchBlob.g.h(str);
            File file = new File(h2);
            if (!file.exists()) {
                promise.reject("ENOENT", "No such file '" + h2 + "'");
                return;
            }
            if (!file.isDirectory()) {
                promise.reject("ENOTDIR", "Not a directory '" + h2 + "'");
                return;
            }
            String[] list = new File(h2).list();
            WritableArray createArray = Arguments.createArray();
            for (String str2 : list) {
                createArray.pushString(str2);
            }
            promise.resolve(createArray);
        } catch (Exception e2) {
            e2.printStackTrace();
            promise.reject("EUNSPECIFIED", e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void lstat(String str, Callback callback) {
        new com.RNFetchBlob.d(callback).execute(com.RNFetchBlob.g.h(str));
    }

    @ReactMethod
    public void mkdir(String str, Promise promise) {
        HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
        File file = new File(str);
        if (file.exists()) {
            StringBuilder sb = new StringBuilder();
            sb.append(file.isDirectory() ? "Folder" : "File");
            sb.append(" '");
            sb.append(str);
            sb.append("' already exists");
            promise.reject("EEXIST", sb.toString());
            return;
        }
        try {
            if (file.mkdirs()) {
                promise.resolve(Boolean.TRUE);
                return;
            }
            promise.reject("EUNSPECIFIED", "mkdir failed to create some or all directories in '" + str + "'");
        } catch (Exception e2) {
            promise.reject("EUNSPECIFIED", e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void mv(String str, String str2, Callback callback) {
        HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
        File file = new File(str);
        if (!file.exists()) {
            callback.invoke(androidx.camera.core.impl.utils.i.c("Source file at path `", str, "` does not exist"));
            return;
        }
        try {
            FileInputStream fileInputStream = new FileInputStream(str);
            FileOutputStream fileOutputStream = new FileOutputStream(str2);
            byte[] bArr = new byte[PortForwardingRule.MIN_PORT];
            while (true) {
                int read = fileInputStream.read(bArr);
                if (read == -1) {
                    fileInputStream.close();
                    fileOutputStream.flush();
                    file.delete();
                    callback.invoke(new Object[0]);
                    return;
                }
                fileOutputStream.write(bArr, 0, read);
            }
        } catch (FileNotFoundException unused) {
            callback.invoke("Source file not found.");
        } catch (Exception e2) {
            callback.invoke(e2.toString());
        }
    }

    @ReactMethod
    public void readFile(String str, String str2, Promise promise) {
        threadPool.execute(new i(str, str2, promise));
    }

    @ReactMethod
    public void readStream(String str, String str2, int i2, int i3, String str3) {
        fsThreadPool.execute(new b(getReactApplicationContext(), str, str2, i2, i3, str3));
    }

    @ReactMethod
    public void removeSession(ReadableArray readableArray, Callback callback) {
        HashMap<String, com.RNFetchBlob.g> hashMap = com.RNFetchBlob.g.d;
        new com.RNFetchBlob.f(callback).execute(readableArray);
    }

    @ReactMethod
    public void scanFile(ReadableArray readableArray, Callback callback) {
        threadPool.execute(new l(readableArray, getReactApplicationContext(), callback));
    }

    @ReactMethod
    public void slice(String str, String str2, int i2, int i3, Promise promise) {
        try {
            String h2 = com.RNFetchBlob.g.h(str);
            File file = new File(h2);
            if (file.isDirectory()) {
                promise.reject("EISDIR", "Expecting a file but '" + h2 + "' is a directory");
                return;
            }
            if (!file.exists()) {
                promise.reject("ENOENT", "No such file '" + h2 + "'");
                return;
            }
            int length = (int) file.length();
            int min = Math.min(length, i3) - i2;
            FileInputStream fileInputStream = new FileInputStream(new File(h2));
            FileOutputStream fileOutputStream = new FileOutputStream(new File(str2));
            int skip = (int) fileInputStream.skip(i2);
            if (skip != i2) {
                promise.reject("EUNSPECIFIED", "Skipped " + skip + " instead of the specified " + i2 + " bytes, size is " + length);
                return;
            }
            byte[] bArr = new byte[10240];
            int i4 = 0;
            while (i4 < min) {
                int read = fileInputStream.read(bArr, 0, 10240);
                int i5 = min - i4;
                if (read <= 0) {
                    break;
                }
                fileOutputStream.write(bArr, 0, Math.min(i5, read));
                i4 += read;
            }
            fileInputStream.close();
            fileOutputStream.flush();
            fileOutputStream.close();
            promise.resolve(str2);
        } catch (Exception e2) {
            e2.printStackTrace();
            promise.reject("EUNSPECIFIED", e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void stat(String str, Callback callback) {
        try {
            String h2 = com.RNFetchBlob.g.h(str);
            WritableMap i2 = com.RNFetchBlob.g.i(h2);
            if (i2 == null) {
                callback.invoke("failed to stat path `" + h2 + "` because it does not exist or it is not a folder", null);
            } else {
                callback.invoke(null, i2);
            }
        } catch (Exception e2) {
            callback.invoke(e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void unlink(String str, Callback callback) {
        try {
            com.RNFetchBlob.g.a(new File(com.RNFetchBlob.g.h(str)));
            callback.invoke(null, Boolean.TRUE);
        } catch (Exception e2) {
            callback.invoke(e2.getLocalizedMessage(), Boolean.FALSE);
        }
    }

    @ReactMethod
    public void writeArrayChunk(String str, ReadableArray readableArray, Callback callback) {
        try {
            FileOutputStream fileOutputStream = com.RNFetchBlob.g.d.get(str).c;
            byte[] bArr = new byte[readableArray.size()];
            for (int i2 = 0; i2 < readableArray.size(); i2++) {
                bArr[i2] = (byte) readableArray.getInt(i2);
            }
            fileOutputStream.write(bArr);
            callback.invoke(new Object[0]);
        } catch (Exception e2) {
            callback.invoke(e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void writeChunk(String str, String str2, Callback callback) {
        com.RNFetchBlob.g gVar = com.RNFetchBlob.g.d.get(str);
        try {
            gVar.c.write(com.RNFetchBlob.g.j(str2, gVar.b));
            callback.invoke(new Object[0]);
        } catch (Exception e2) {
            callback.invoke(e2.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void writeFile(String str, String str2, String str3, boolean z, Promise promise) {
        threadPool.execute(new k(str, str2, str3, z, promise));
    }

    @ReactMethod
    public void writeFileArray(String str, ReadableArray readableArray, boolean z, Promise promise) {
        threadPool.execute(new j(str, readableArray, z, promise));
    }

    @ReactMethod
    public void writeStream(String str, String str2, boolean z, Callback callback) {
        com.RNFetchBlob.g gVar = new com.RNFetchBlob.g(getReactApplicationContext());
        try {
            File file = new File(str);
            File parentFile = file.getParentFile();
            if (file.exists()) {
                if (file.isDirectory()) {
                    callback.invoke("EISDIR", "Expecting a file but '" + str + "' is a directory");
                }
                FileOutputStream fileOutputStream = new FileOutputStream(str, z);
                gVar.b = str2;
                String uuid = UUID.randomUUID().toString();
                com.RNFetchBlob.g.d.put(uuid, gVar);
                gVar.c = fileOutputStream;
                callback.invoke(null, null, uuid);
            }
            if (parentFile == null || parentFile.exists() || parentFile.mkdirs()) {
                if (!file.createNewFile()) {
                    callback.invoke("ENOENT", "File '" + str + "' does not exist and could not be created");
                }
                FileOutputStream fileOutputStream2 = new FileOutputStream(str, z);
                gVar.b = str2;
                String uuid2 = UUID.randomUUID().toString();
                com.RNFetchBlob.g.d.put(uuid2, gVar);
                gVar.c = fileOutputStream2;
                callback.invoke(null, null, uuid2);
            } else {
                callback.invoke("ENOTDIR", "Failed to create parent directory of '" + str + "'");
            }
        } catch (Exception e2) {
            StringBuilder f2 = androidx.activity.result.e.f("Failed to create write stream at path `", str, "`; ");
            f2.append(e2.getLocalizedMessage());
            callback.invoke("EUNSPECIFIED", f2.toString());
        }
    }

    public class g implements LifecycleEventListener {
        public final Promise a;

        public g(Promise promise) {
            this.a = promise;
        }

        @Override
        public final void onHostResume() {
            if (RNFetchBlob.ActionViewVisible) {
                this.a.resolve(null);
            }
            RNFetchBlob.RCTContext.removeLifecycleEventListener(this);
        }

        @Override
        public final void onHostDestroy() {
        }

        @Override
        public final void onHostPause() {
        }
    }

    public class d implements ActivityEventListener {
        @Override
        public final void onActivityResult(Activity activity, int i, int i2, Intent intent) {
            Integer num = com.RNFetchBlob.c.a;
            if (i == num.intValue() && i2 == -1) {
                ((Promise) RNFetchBlob.promiseTable.get(num.intValue())).resolve(intent.getData().toString());
                RNFetchBlob.promiseTable.remove(num.intValue());
            }
        }

        @Override
        public final void onNewIntent(Intent intent) {
        }
    }
}