package epson.scan.i2lib;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import com.epson.lib.escani2.EscanI2Lib;
import com.epson.lib.escani2.I2LibScannerInfoAndCapability;
import com.epson.lib.escani2.ScanI2Params;
import com.epson.lib.escani2.ScanSize;
import java.io.File;
import java.io.IOException;

public class I2ScanParamManager {
    static final int DEFAULT_RESOLUTION = 150;
    private static final String I2SCAN_ALL_INFO_FILE_NAME = "i2_all_info";
    private static final String I2SCAN_PARAM_FILE_NAME = "i2_scan_params.bin";
    private static final String TAG = "I2ScanParamManager";
    private static I2ScanParamManager sI2ScanParamManager;

    public static synchronized I2ScanParamManager getInstance() {
        I2ScanParamManager i2ScanParamManager;
        synchronized (I2ScanParamManager.class) {
            if (sI2ScanParamManager == null) {
                sI2ScanParamManager = new I2ScanParamManager();
            }
            i2ScanParamManager = sI2ScanParamManager;
        }
        return i2ScanParamManager;
    }

    @VisibleForTesting
    protected static void replaceInstance(@Nullable I2ScanParamManager i2ScanParamManager) {
        sI2ScanParamManager = i2ScanParamManager;
    }

    @VisibleForTesting
    protected I2ScanParamManager() {
    }

    public static void saveParams(@NonNull Context context, @NonNull ScanI2Params scanI2Params) throws IOException {
        getInstance().saveParamsNonStatic(context, scanI2Params);
    }

    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r0v1, resolved type: java.io.ObjectOutputStream} */
    /* JADX WARNING: type inference failed for: r0v0 */
    /* JADX WARNING: type inference failed for: r0v2 */
    /* JADX WARNING: type inference failed for: r0v3, types: [java.lang.Throwable] */
    /* JADX WARNING: type inference failed for: r0v5 */
    /* access modifiers changed from: protected */
    /* JADX WARNING: Multi-variable type inference failed */
    /* JADX WARNING: Removed duplicated region for block: B:15:0x001f A[SYNTHETIC, Splitter:B:15:0x001f] */
    @android.support.annotation.VisibleForTesting
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void saveParamsNonStatic(@android.support.annotation.NonNull android.content.Context r5, @android.support.annotation.NonNull com.epson.lib.escani2.ScanI2Params r6) throws java.io.IOException {
        /*
            r4 = this;
            r0 = 0
            java.io.ObjectOutputStream r1 = new java.io.ObjectOutputStream     // Catch:{ all -> 0x001c }
            java.lang.String r2 = "i2_scan_params.bin"
            r3 = 0
            java.io.FileOutputStream r5 = r5.openFileOutput(r2, r3)     // Catch:{ all -> 0x001c }
            r1.<init>(r5)     // Catch:{ all -> 0x001c }
            r1.writeObject(r6)     // Catch:{ all -> 0x0019 }
            r1.close()     // Catch:{ IOException -> 0x0014 }
            goto L_0x0015
        L_0x0014:
            r0 = move-exception
        L_0x0015:
            if (r0 != 0) goto L_0x0018
            return
        L_0x0018:
            throw r0
        L_0x0019:
            r5 = move-exception
            r0 = r1
            goto L_0x001d
        L_0x001c:
            r5 = move-exception
        L_0x001d:
            if (r0 == 0) goto L_0x0022
            r0.close()     // Catch:{ IOException -> 0x0022 }
        L_0x0022:
            throw r5
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.I2ScanParamManager.saveParamsNonStatic(android.content.Context, com.epson.lib.escani2.ScanI2Params):void");
    }

    @NonNull
    public static ScanI2Params loadScanI2Params(@NonNull Context context) {
        return getInstance().loadScanI2ParamsNonStatic(context);
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [B:16:0x001f, B:23:0x0029] */
    /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x001f */
    /* JADX WARNING: Missing exception handler attribute for start block: B:23:0x0029 */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x0025 A[SYNTHETIC, Splitter:B:19:0x0025] */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x002f A[SYNTHETIC, Splitter:B:26:0x002f] */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x0035 A[SYNTHETIC, Splitter:B:31:0x0035] */
    /* JADX WARNING: Unknown top exception splitter block from list: {B:23:0x0029=Splitter:B:23:0x0029, B:16:0x001f=Splitter:B:16:0x001f} */
    @android.support.annotation.VisibleForTesting
    @android.support.annotation.NonNull
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public com.epson.lib.escani2.ScanI2Params loadScanI2ParamsNonStatic(@android.support.annotation.NonNull android.content.Context r4) {
        /*
            r3 = this;
            r0 = 0
            java.io.ObjectInputStream r1 = new java.io.ObjectInputStream     // Catch:{ FileNotFoundException -> 0x0029, IOException | ClassNotFoundException -> 0x001f }
            java.lang.String r2 = "i2_scan_params.bin"
            java.io.FileInputStream r4 = r4.openFileInput(r2)     // Catch:{ FileNotFoundException -> 0x0029, IOException | ClassNotFoundException -> 0x001f }
            r1.<init>(r4)     // Catch:{ FileNotFoundException -> 0x0029, IOException | ClassNotFoundException -> 0x001f }
            java.lang.Object r4 = r1.readObject()     // Catch:{ FileNotFoundException -> 0x001b, IOException | ClassNotFoundException -> 0x0019, all -> 0x0016 }
            com.epson.lib.escani2.ScanI2Params r4 = (com.epson.lib.escani2.ScanI2Params) r4     // Catch:{ FileNotFoundException -> 0x001b, IOException | ClassNotFoundException -> 0x0019, all -> 0x0016 }
            r1.close()     // Catch:{ IOException -> 0x0015 }
        L_0x0015:
            return r4
        L_0x0016:
            r4 = move-exception
            r0 = r1
            goto L_0x0033
        L_0x0019:
            r0 = r1
            goto L_0x001f
        L_0x001b:
            r0 = r1
            goto L_0x0029
        L_0x001d:
            r4 = move-exception
            goto L_0x0033
        L_0x001f:
            com.epson.lib.escani2.ScanI2Params r4 = getDefaultScanI2Params()     // Catch:{ all -> 0x001d }
            if (r0 == 0) goto L_0x0028
            r0.close()     // Catch:{ IOException -> 0x0028 }
        L_0x0028:
            return r4
        L_0x0029:
            com.epson.lib.escani2.ScanI2Params r4 = getDefaultScanI2Params()     // Catch:{ all -> 0x001d }
            if (r0 == 0) goto L_0x0032
            r0.close()     // Catch:{ IOException -> 0x0032 }
        L_0x0032:
            return r4
        L_0x0033:
            if (r0 == 0) goto L_0x0038
            r0.close()     // Catch:{ IOException -> 0x0038 }
        L_0x0038:
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.I2ScanParamManager.loadScanI2ParamsNonStatic(android.content.Context):com.epson.lib.escani2.ScanI2Params");
    }

    public static void deleteScanI2Params(@NonNull Context context) {
        getInstance().deleteAllInfoFileNonStatic(context);
    }

    /* access modifiers changed from: protected */
    @VisibleForTesting
    public void deleteScanI2ParamsNonStatic(@NonNull Context context) {
        File fileStreamPath = context.getFileStreamPath(I2SCAN_PARAM_FILE_NAME);
        if (fileStreamPath.exists()) {
            fileStreamPath.delete();
        }
    }

    public static ScanI2Params getDefaultScanI2Params() {
        ScanI2Params scanI2Params = new ScanI2Params();
        scanI2Params.resolutionMain = 150;
        scanI2Params.resolutionSub = 150;
        scanI2Params.inputUnit = EscanI2Lib.InputUnit.ADF;
        scanI2Params.scanSize = ScanSize.getLocaleDefaultSize();
        scanI2Params.colorMode = EscanI2Lib.ColorMode.COLOR_24BIT;
        scanI2Params.userGamma = EscanI2Lib.Gamma.GAMMA_180;
        scanI2Params.autoCrop = EscanI2Lib.AutoCrop.FALSE;
        scanI2Params.autoSkew = EscanI2Lib.AutoSkew.FALSE;
        scanI2Params.lookupTableNo = 0;
        scanI2Params.duplex = false;
        scanI2Params.overScan = false;
        scanI2Params.density = 128;
        scanI2Params.densityChangeable = false;
        scanI2Params.doubleFeedLevel = EscanI2Lib.DoubleFeedLevel.LEVEL_NONE;
        scanI2Params.maxScanSheets = 30;
        scanI2Params.maxWriteSheets = 30;
        scanI2Params.qualityHW = 90;
        scanI2Params.qualitySW = 90;
        return scanI2Params;
    }

    public static void updateScanSize(Context context, ScanSize scanSize) throws IOException {
        getInstance().updateScanSizeNonStatic(context, scanSize);
    }

    /* access modifiers changed from: protected */
    @VisibleForTesting
    public void updateScanSizeNonStatic(Context context, ScanSize scanSize) throws IOException {
        ScanI2Params loadScanI2Params = loadScanI2Params(context);
        loadScanI2Params.scanSize = scanSize;
        saveParams(context, loadScanI2Params);
    }

    public static void saveI2AllInfo(@NonNull Context context, I2LibScannerInfoAndCapability i2LibScannerInfoAndCapability) throws IOException {
        getInstance().saveI2AllInfoNonStatic(context, i2LibScannerInfoAndCapability);
    }

    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r0v1, resolved type: java.io.ObjectOutputStream} */
    /* JADX WARNING: type inference failed for: r0v0 */
    /* JADX WARNING: type inference failed for: r0v2 */
    /* JADX WARNING: type inference failed for: r0v3, types: [java.lang.Throwable] */
    /* JADX WARNING: type inference failed for: r0v5 */
    /* access modifiers changed from: protected */
    /* JADX WARNING: Multi-variable type inference failed */
    /* JADX WARNING: Removed duplicated region for block: B:15:0x001f A[SYNTHETIC, Splitter:B:15:0x001f] */
    @android.support.annotation.VisibleForTesting
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void saveI2AllInfoNonStatic(@android.support.annotation.NonNull android.content.Context r5, com.epson.lib.escani2.I2LibScannerInfoAndCapability r6) throws java.io.IOException {
        /*
            r4 = this;
            r0 = 0
            java.io.ObjectOutputStream r1 = new java.io.ObjectOutputStream     // Catch:{ all -> 0x001c }
            java.lang.String r2 = "i2_all_info"
            r3 = 0
            java.io.FileOutputStream r5 = r5.openFileOutput(r2, r3)     // Catch:{ all -> 0x001c }
            r1.<init>(r5)     // Catch:{ all -> 0x001c }
            r1.writeObject(r6)     // Catch:{ all -> 0x0019 }
            r1.close()     // Catch:{ IOException -> 0x0014 }
            goto L_0x0015
        L_0x0014:
            r0 = move-exception
        L_0x0015:
            if (r0 != 0) goto L_0x0018
            return
        L_0x0018:
            throw r0
        L_0x0019:
            r5 = move-exception
            r0 = r1
            goto L_0x001d
        L_0x001c:
            r5 = move-exception
        L_0x001d:
            if (r0 == 0) goto L_0x0022
            r0.close()     // Catch:{ IOException -> 0x0022 }
        L_0x0022:
            throw r5
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.I2ScanParamManager.saveI2AllInfoNonStatic(android.content.Context, com.epson.lib.escani2.I2LibScannerInfoAndCapability):void");
    }

    @Nullable
    public static I2LibScannerInfoAndCapability loadI2AllInfo(@NonNull Context context) {
        return getInstance().loadI2AllInfoNonStatic(context);
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Removed duplicated region for block: B:15:0x0021 A[SYNTHETIC, Splitter:B:15:0x0021] */
    /* JADX WARNING: Removed duplicated region for block: B:30:? A[RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:31:? A[RETURN, SYNTHETIC] */
    @android.support.annotation.Nullable
    @android.support.annotation.VisibleForTesting
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public com.epson.lib.escani2.I2LibScannerInfoAndCapability loadI2AllInfoNonStatic(@android.support.annotation.NonNull android.content.Context r4) {
        /*
            r3 = this;
            r0 = 0
            java.io.ObjectInputStream r1 = new java.io.ObjectInputStream     // Catch:{ FileNotFoundException -> 0x002c, IOException | ClassNotFoundException -> 0x0025, all -> 0x001e }
            java.lang.String r2 = "i2_all_info"
            java.io.FileInputStream r4 = r4.openFileInput(r2)     // Catch:{ FileNotFoundException -> 0x002c, IOException | ClassNotFoundException -> 0x0025, all -> 0x001e }
            r1.<init>(r4)     // Catch:{ FileNotFoundException -> 0x002c, IOException | ClassNotFoundException -> 0x0025, all -> 0x001e }
            java.lang.Object r4 = r1.readObject()     // Catch:{ FileNotFoundException -> 0x001c, IOException | ClassNotFoundException -> 0x001a, all -> 0x0017 }
            com.epson.lib.escani2.I2LibScannerInfoAndCapability r4 = (com.epson.lib.escani2.I2LibScannerInfoAndCapability) r4     // Catch:{ FileNotFoundException -> 0x001c, IOException | ClassNotFoundException -> 0x001a, all -> 0x0017 }
            r1.close()     // Catch:{ IOException -> 0x0015 }
        L_0x0015:
            r0 = r4
            goto L_0x0030
        L_0x0017:
            r4 = move-exception
            r0 = r1
            goto L_0x001f
        L_0x001a:
            goto L_0x0026
        L_0x001c:
            goto L_0x002d
        L_0x001e:
            r4 = move-exception
        L_0x001f:
            if (r0 == 0) goto L_0x0024
            r0.close()     // Catch:{ IOException -> 0x0024 }
        L_0x0024:
            throw r4
        L_0x0025:
            r1 = r0
        L_0x0026:
            if (r1 == 0) goto L_0x0030
        L_0x0028:
            r1.close()     // Catch:{ IOException -> 0x0030 }
            goto L_0x0030
        L_0x002c:
            r1 = r0
        L_0x002d:
            if (r1 == 0) goto L_0x0030
            goto L_0x0028
        L_0x0030:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.I2ScanParamManager.loadI2AllInfoNonStatic(android.content.Context):com.epson.lib.escani2.I2LibScannerInfoAndCapability");
    }

    public static void deleteAllInfoFile(@NonNull Context context) {
        getInstance().deleteAllInfoFileNonStatic(context);
    }

    /* access modifiers changed from: protected */
    @VisibleForTesting
    public void deleteAllInfoFileNonStatic(@NonNull Context context) {
        File fileStreamPath = context.getFileStreamPath(I2SCAN_ALL_INFO_FILE_NAME);
        if (fileStreamPath.exists()) {
            fileStreamPath.delete();
        }
    }
}
