package epson.scan.i2lib;

import android.content.Context;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import com.epson.iprint.prtlogger.Analytics;
import com.epson.iprint.prtlogger.CommonLog;
import com.epson.iprint.prtlogger.PrintLog;
import com.epson.iprint.shared.SharedParamScan;
import com.epson.lib.escani2.EscanI2Lib;
import com.epson.lib.escani2.ScanI2Params;
import com.epson.lib.escani2.ScanI2Runner;
import com.epson.lib.escani2.ScanSize;
import com.epson.lib.escani2.ScannerI2Info;
import epson.common.ExternalFileUtils;
import epson.scan.activity.ScanContinueParam;
import epson.scan.activity.ScannerPropertyWrapper;
import epson.scan.lib.CancelableScannerProbe;
import epson.scan.lib.EscanLibException;
import epson.scan.lib.I1ScanParams;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;

public class I2ScanTask extends AsyncTask<Void, Void, TaskError> {
    private static final String LOG_TAG = "I2ScanTask";
    private Context mApplicationContext;
    private volatile boolean mCancelRequested;
    private CancelableScannerProbe mCancelableScannerProbe;
    private CommonLog mCommonLog;
    private ImageProcessController mImageProcessController;
    private ArrayList<String> mResScanFileList;
    private ScanI2Params mScanI2Params;
    private ScanI2Runner mScanI2Runner = new ScanI2Runner();
    private final ScanResultReceiver mScanResultReceiver;
    private ScannerPropertyWrapper mScannerPropertyWrapper;

    public interface ScanResultReceiver {
        @WorkerThread
        void onProgressUpdate(int i, int i2);

        @UiThread
        void onScanEnd(TaskError taskError);
    }

    /* access modifiers changed from: protected */
    public void onPreExecute() {
    }

    public ArrayList<String> getScanFileList() {
        return this.mResScanFileList;
    }

    @Nullable
    public File getScanFile(int i, int i2) {
        if (this.mScanI2Runner == null) {
            return null;
        }
        return this.mImageProcessController.getAllProcessFile(i, i2);
    }

    public I2ScanTask(@NonNull Context context, @Nullable ScanResultReceiver scanResultReceiver, @Nullable SharedParamScan sharedParamScan, CommonLog commonLog) {
        this.mApplicationContext = context;
        ScanI2Params loadAndAdjustScanParams = loadAndAdjustScanParams(context);
        margeScanI2Params(loadAndAdjustScanParams, sharedParamScan);
        this.mScanI2Params = loadAndAdjustScanParams;
        this.mScannerPropertyWrapper = ScannerPropertyWrapper.load(context);
        ScannerPropertyWrapper scannerPropertyWrapper = this.mScannerPropertyWrapper;
        if (scannerPropertyWrapper == null) {
            throw new IllegalStateException("ScannerPropertyWrapper.load() error!");
        } else if (scannerPropertyWrapper.getEscIVersion() == 2) {
            this.mImageProcessController = new ImageProcessController(this, loadAndAdjustScanParams.duplex, loadAndAdjustScanParams.duplexTurnDirection, this.mScannerPropertyWrapper.getI2ScannerAllInfo().scannerI2Info.adfDuplexType, loadAndAdjustScanParams.colorMode == EscanI2Lib.ColorMode.MONO_1BIT, loadAndAdjustScanParams.density);
            this.mImageProcessController.init(getSaveDirectory(context), Calendar.getInstance());
            this.mScanResultReceiver = scanResultReceiver;
            this.mResScanFileList = new ArrayList<>();
            this.mCommonLog = commonLog;
            if (this.mCommonLog == null) {
                this.mCommonLog = new CommonLog();
            }
        } else {
            throw new IllegalStateException("ScannerPropertyWrapper.load() error! ESC/I version != 2");
        }
    }

    private void margeScanI2Params(@NonNull ScanI2Params scanI2Params, @Nullable SharedParamScan sharedParamScan) {
        if (sharedParamScan != null) {
            scanI2Params.resolutionMain = sharedParamScan.getRes_main();
            scanI2Params.resolutionSub = sharedParamScan.getRes_sub();
            scanI2Params.scanSize = new ScanSize(sharedParamScan.getPixel_main(), sharedParamScan.getPixel_sub(), 0, 0);
            EscanI2Lib.ColorMode colorMode = EscanI2Lib.ColorMode.COLOR_24BIT;
            switch (sharedParamScan.getScan_type()) {
                case 2:
                    colorMode = EscanI2Lib.ColorMode.GRAYSCALE_8BIT;
                    break;
                case 3:
                    colorMode = EscanI2Lib.ColorMode.MONO_1BIT;
                    break;
            }
            scanI2Params.colorMode = colorMode;
        }
    }

    private File getSaveDirectory(Context context) {
        File file = new File(ExternalFileUtils.getInstance(context).getScannedImageDir());
        if (file.exists() || file.mkdirs()) {
            return file;
        }
        throw new RuntimeException("mkdirs error '" + file + "'");
    }

    private ScanI2Params loadAndAdjustScanParams(Context context) {
        ScanI2Params loadScanI2Params = I2ScanParamManager.loadScanI2Params(context);
        loadScanI2Params.autoCrop = EscanI2Lib.AutoCrop.FALSE;
        loadScanI2Params.autoSkew = EscanI2Lib.AutoSkew.FALSE;
        loadScanI2Params.lookupTableNo = 0;
        loadScanI2Params.overScan = false;
        loadScanI2Params.doubleFeedLevel = EscanI2Lib.DoubleFeedLevel.LEVEL_NONE;
        if (loadScanI2Params.inputUnit == EscanI2Lib.InputUnit.ADF) {
            loadScanI2Params.maxScanSheets = ScanContinueParam.getAvailableScanPageCount();
            loadScanI2Params.maxWriteSheets = ScanContinueParam.getAvailableScanPageCount();
        } else {
            loadScanI2Params.maxScanSheets = 1;
            loadScanI2Params.maxWriteSheets = 1;
        }
        loadScanI2Params.qualityHW = 90;
        loadScanI2Params.qualitySW = 90;
        return loadScanI2Params;
    }

    public int[] getScanPages() {
        return (int[]) this.mScanI2Runner.getScanPages().clone();
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Missing exception handler attribute for start block: B:78:0x0174 */
    /* JADX WARNING: Removed duplicated region for block: B:75:0x0160  */
    /* JADX WARNING: Removed duplicated region for block: B:81:0x017b  */
    /* JADX WARNING: Removed duplicated region for block: B:85:0x0191  */
    /* JADX WARNING: Unknown top exception splitter block from list: {B:72:0x0150=Splitter:B:72:0x0150, B:78:0x0174=Splitter:B:78:0x0174} */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public epson.scan.i2lib.I2ScanTask.TaskError doInBackground(java.lang.Void... r9) {
        /*
            r8 = this;
            java.lang.String r9 = ""
            r0 = 0
            r1 = 1
            r8.checkCancel()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            boolean r2 = epson.common.Utils.isMediaMounted()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r3 = 2
            if (r2 != 0) goto L_0x0025
            r8.checkCancel()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            epson.scan.i2lib.I2ScanTask$TaskError r2 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r2.<init>(r3, r3)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r2
        L_0x0025:
            android.content.Context r2 = r8.mApplicationContext     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            java.io.File r2 = r8.getSaveDirectory(r2)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            com.epson.lib.escani2.ScanI2Params r4 = r8.mScanI2Params     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            epson.scan.activity.ScannerPropertyWrapper r5 = r8.mScannerPropertyWrapper     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            com.epson.lib.escani2.I2LibScannerInfoAndCapability r5 = r5.getI2ScannerAllInfo()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            com.epson.lib.escani2.ScannerI2Info r5 = r5.scannerI2Info     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            int r4 = r8.checkScanParams(r2, r4, r5)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r5 = -202(0xffffffffffffff36, float:NaN)
            switch(r4) {
                case 0: goto L_0x0058;
                case 1: goto L_0x0043;
                default: goto L_0x003e;
            }     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
        L_0x003e:
            r8.checkCancel()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            goto L_0x0139
        L_0x0043:
            epson.scan.i2lib.I2ScanTask$TaskError r2 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r4 = 3
            r2.<init>(r3, r4)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r2
        L_0x0058:
            boolean r3 = epson.scan.activity.ScanContinueParam.isContinueScanning()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            if (r3 != 0) goto L_0x006e
            android.content.Context r3 = r8.mApplicationContext     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            epson.common.ExternalFileUtils r3 = epson.common.ExternalFileUtils.getInstance(r3)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            java.lang.String r2 = r2.getPath()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r3.clearTempFoler(r2)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            epson.scan.activity.ScanContinueParam.resetParameter()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
        L_0x006e:
            r8.checkCancel()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            android.content.Context r2 = r8.mApplicationContext     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            epson.scan.activity.ScannerPropertyWrapper r3 = r8.mScannerPropertyWrapper     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            java.lang.String r9 = r8.probeScanner(r2, r3)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r8.checkCancel()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            if (r9 != 0) goto L_0x0094
            epson.scan.i2lib.I2ScanTask$TaskError r2 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r3 = -214(0xffffffffffffff2a, float:NaN)
            r2.<init>(r1, r3)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r2
        L_0x0094:
            epson.scan.i2lib.ImageProcessController r2 = r8.mImageProcessController     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r2.startThread()     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            com.epson.lib.escani2.ScanI2Params r2 = r8.mScanI2Params     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            com.epson.lib.escani2.ScanI2Params r2 = r2.clone()     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            com.epson.lib.escani2.EscanI2Lib$ColorMode r3 = r2.colorMode     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            com.epson.lib.escani2.EscanI2Lib$ColorMode r4 = com.epson.lib.escani2.EscanI2Lib.ColorMode.MONO_1BIT     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            if (r3 != r4) goto L_0x00a9
            com.epson.lib.escani2.EscanI2Lib$ColorMode r3 = com.epson.lib.escani2.EscanI2Lib.ColorMode.GRAYSCALE_8BIT     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r2.colorMode = r3     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
        L_0x00a9:
            epson.scan.i2lib.ImageProcessController r3 = r8.mImageProcessController     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            java.lang.String[] r3 = r3.getScanOutFilenameFormat()     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r8.checkCancel()     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            com.epson.lib.escani2.ScanI2Runner r4 = r8.mScanI2Runner     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            epson.scan.i2lib.I2ScanTask$TaskObserver r6 = new epson.scan.i2lib.I2ScanTask$TaskObserver     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r7 = 0
            r6.<init>(r8, r7)     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            int r2 = r4.doScan(r9, r2, r3, r6)     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            boolean r3 = r8.mCancelRequested     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            if (r3 == 0) goto L_0x00c9
            epson.scan.i2lib.ImageProcessController r3 = r8.mImageProcessController     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r3.cancelThread()     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r3 = 0
            goto L_0x00cf
        L_0x00c9:
            epson.scan.i2lib.ImageProcessController r3 = r8.mImageProcessController     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r3.requestFinishThread()     // Catch:{ LocalCancel -> 0x0137, EscanLibException -> 0x0134, all -> 0x0130 }
            r3 = 1
        L_0x00cf:
            if (r2 == 0) goto L_0x00d9
            if (r2 == r1) goto L_0x00d9
            epson.scan.i2lib.I2ScanTask$TaskError r4 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x012e, EscanLibException -> 0x012b, all -> 0x0128 }
            r4.<init>(r1, r2)     // Catch:{ LocalCancel -> 0x012e, EscanLibException -> 0x012b, all -> 0x0128 }
            goto L_0x00da
        L_0x00d9:
            r4 = r7
        L_0x00da:
            epson.scan.i2lib.ImageProcessController r6 = r8.mImageProcessController     // Catch:{ LocalCancel -> 0x012e, EscanLibException -> 0x012b, all -> 0x0128 }
            boolean r6 = r6.waitUntilThreadEnd()     // Catch:{ LocalCancel -> 0x012e, EscanLibException -> 0x012b, all -> 0x0128 }
            if (r6 != 0) goto L_0x00e9
            if (r4 != 0) goto L_0x00e9
            epson.scan.i2lib.I2ScanTask$TaskError r4 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x012e, EscanLibException -> 0x012b, all -> 0x0128 }
            r4.<init>(r1, r5)     // Catch:{ LocalCancel -> 0x012e, EscanLibException -> 0x012b, all -> 0x0128 }
        L_0x00e9:
            r8.convertFile()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            if (r4 == 0) goto L_0x00fd
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r4
        L_0x00fd:
            java.util.ArrayList<java.lang.String> r3 = r8.mResScanFileList     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            boolean r3 = r3.isEmpty()     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            if (r3 == 0) goto L_0x0119
            epson.scan.i2lib.I2ScanTask$TaskError r3 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r3.<init>(r1, r2)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r3
        L_0x0119:
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r7
        L_0x0128:
            r1 = move-exception
            r0 = r3
            goto L_0x018f
        L_0x012b:
            r2 = move-exception
            r0 = r3
            goto L_0x0150
        L_0x012e:
            r0 = r3
            goto L_0x0174
        L_0x0130:
            r0 = move-exception
            r1 = r0
            r0 = 1
            goto L_0x018f
        L_0x0134:
            r2 = move-exception
            r0 = 1
            goto L_0x0150
        L_0x0137:
            r0 = 1
            goto L_0x0174
        L_0x0139:
            epson.scan.i2lib.I2ScanTask$TaskError r2 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            r2.<init>(r1, r5)     // Catch:{ LocalCancel -> 0x0174, EscanLibException -> 0x014f }
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r2
        L_0x014d:
            r1 = move-exception
            goto L_0x018f
        L_0x014f:
            r2 = move-exception
        L_0x0150:
            epson.scan.i2lib.ImageProcessController r3 = r8.mImageProcessController     // Catch:{ all -> 0x014d }
            r3.cancelThread()     // Catch:{ all -> 0x014d }
            epson.scan.i2lib.I2ScanTask$TaskError r3 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ all -> 0x014d }
            int r2 = r2.getEscanLibErrorCode()     // Catch:{ all -> 0x014d }
            r3.<init>(r1, r2)     // Catch:{ all -> 0x014d }
            if (r0 == 0) goto L_0x0165
            epson.scan.i2lib.ImageProcessController r0 = r8.mImageProcessController
            r0.cancelThread()
        L_0x0165:
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r3
        L_0x0174:
            epson.scan.i2lib.I2ScanTask$TaskError r2 = new epson.scan.i2lib.I2ScanTask$TaskError     // Catch:{ all -> 0x014d }
            r2.<init>(r1, r1)     // Catch:{ all -> 0x014d }
            if (r0 == 0) goto L_0x0180
            epson.scan.i2lib.ImageProcessController r0 = r8.mImageProcessController
            r0.cancelThread()
        L_0x0180:
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r1 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r1, r9)
            r8.sendLog(r0)
            return r2
        L_0x018f:
            if (r0 == 0) goto L_0x0196
            epson.scan.i2lib.ImageProcessController r0 = r8.mImageProcessController
            r0.cancelThread()
        L_0x0196:
            android.content.Context r0 = r8.mApplicationContext
            int r0 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r0)
            android.content.Context r2 = r8.mApplicationContext
            epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r2, r9)
            r8.sendLog(r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.I2ScanTask.doInBackground(java.lang.Void[]):epson.scan.i2lib.I2ScanTask$TaskError");
    }

    private void sendLog(int i) {
        CommonLog commonLog = this.mCommonLog;
        if (commonLog != null) {
            commonLog.connectionType = i;
            commonLog.numberOfSheet = getScanFileList().size();
            if (this.mCommonLog.action == 0) {
                this.mCommonLog.action = PrintLog.ACTION_SCAN;
            }
            ScannerPropertyWrapper scannerPropertyWrapper = this.mScannerPropertyWrapper;
            if (scannerPropertyWrapper != null) {
                this.mCommonLog.printerName = scannerPropertyWrapper.getModelName();
            }
            if (this.mCommonLog.numberOfSheet > 0) {
                Analytics.sendScanI1Log(this.mApplicationContext, convertScanParams(this.mScanI2Params), this.mCommonLog, ScanContinueParam.isContinueScanning());
            }
        }
    }

    private I1ScanParams convertScanParams(@NonNull ScanI2Params scanI2Params) {
        I1ScanParams i1ScanParams = new I1ScanParams();
        if (C24451.$SwitchMap$com$epson$lib$escani2$EscanI2Lib$InputUnit[scanI2Params.inputUnit.ordinal()] != 1) {
            i1ScanParams.inputDevice = 0;
        } else {
            i1ScanParams.inputDevice = 1;
        }
        switch (scanI2Params.colorMode) {
            case MONO_1BIT:
                i1ScanParams.colorType = 3;
                break;
            case GRAYSCALE_8BIT:
                i1ScanParams.colorType = 2;
                break;
            default:
                i1ScanParams.colorType = 1;
                break;
        }
        i1ScanParams.resolution = scanI2Params.resolutionMain;
        i1ScanParams.twoSide = scanI2Params.duplex ? 1 : 0;
        if (C24451.$SwitchMap$com$epson$lib$escani2$EscanI2Lib$Gamma[scanI2Params.userGamma.ordinal()] != 1) {
            i1ScanParams.gamma = 1;
        } else {
            i1ScanParams.gamma = 0;
        }
        i1ScanParams.brightness = 255 - scanI2Params.density;
        if (scanI2Params.colorMode != EscanI2Lib.ColorMode.MONO_1BIT) {
            i1ScanParams.brightness = 127;
        }
        return i1ScanParams;
    }

    /* renamed from: epson.scan.i2lib.I2ScanTask$1 */
    static /* synthetic */ class C24451 {
        static final /* synthetic */ int[] $SwitchMap$com$epson$lib$escani2$EscanI2Lib$Gamma = new int[EscanI2Lib.Gamma.values().length];
        static final /* synthetic */ int[] $SwitchMap$com$epson$lib$escani2$EscanI2Lib$InputUnit = new int[EscanI2Lib.InputUnit.values().length];

        /* JADX WARNING: Can't wrap try/catch for region: R(17:0|1|2|3|5|6|7|9|10|11|12|13|14|15|17|18|(3:19|20|22)) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0032 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:13:0x003c */
        /* JADX WARNING: Missing exception handler attribute for start block: B:19:0x005a */
        static {
            /*
                com.epson.lib.escani2.EscanI2Lib$Gamma[] r0 = com.epson.lib.escani2.EscanI2Lib.Gamma.values()
                int r0 = r0.length
                int[] r0 = new int[r0]
                $SwitchMap$com$epson$lib$escani2$EscanI2Lib$Gamma = r0
                r0 = 1
                int[] r1 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$Gamma     // Catch:{ NoSuchFieldError -> 0x0014 }
                com.epson.lib.escani2.EscanI2Lib$Gamma r2 = com.epson.lib.escani2.EscanI2Lib.Gamma.GAMMA_100     // Catch:{ NoSuchFieldError -> 0x0014 }
                int r2 = r2.ordinal()     // Catch:{ NoSuchFieldError -> 0x0014 }
                r1[r2] = r0     // Catch:{ NoSuchFieldError -> 0x0014 }
            L_0x0014:
                r1 = 2
                int[] r2 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$Gamma     // Catch:{ NoSuchFieldError -> 0x001f }
                com.epson.lib.escani2.EscanI2Lib$Gamma r3 = com.epson.lib.escani2.EscanI2Lib.Gamma.GAMMA_180     // Catch:{ NoSuchFieldError -> 0x001f }
                int r3 = r3.ordinal()     // Catch:{ NoSuchFieldError -> 0x001f }
                r2[r3] = r1     // Catch:{ NoSuchFieldError -> 0x001f }
            L_0x001f:
                com.epson.lib.escani2.EscanI2Lib$ColorMode[] r2 = com.epson.lib.escani2.EscanI2Lib.ColorMode.values()
                int r2 = r2.length
                int[] r2 = new int[r2]
                $SwitchMap$com$epson$lib$escani2$EscanI2Lib$ColorMode = r2
                int[] r2 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$ColorMode     // Catch:{ NoSuchFieldError -> 0x0032 }
                com.epson.lib.escani2.EscanI2Lib$ColorMode r3 = com.epson.lib.escani2.EscanI2Lib.ColorMode.MONO_1BIT     // Catch:{ NoSuchFieldError -> 0x0032 }
                int r3 = r3.ordinal()     // Catch:{ NoSuchFieldError -> 0x0032 }
                r2[r3] = r0     // Catch:{ NoSuchFieldError -> 0x0032 }
            L_0x0032:
                int[] r2 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$ColorMode     // Catch:{ NoSuchFieldError -> 0x003c }
                com.epson.lib.escani2.EscanI2Lib$ColorMode r3 = com.epson.lib.escani2.EscanI2Lib.ColorMode.GRAYSCALE_8BIT     // Catch:{ NoSuchFieldError -> 0x003c }
                int r3 = r3.ordinal()     // Catch:{ NoSuchFieldError -> 0x003c }
                r2[r3] = r1     // Catch:{ NoSuchFieldError -> 0x003c }
            L_0x003c:
                int[] r2 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$ColorMode     // Catch:{ NoSuchFieldError -> 0x0047 }
                com.epson.lib.escani2.EscanI2Lib$ColorMode r3 = com.epson.lib.escani2.EscanI2Lib.ColorMode.COLOR_24BIT     // Catch:{ NoSuchFieldError -> 0x0047 }
                int r3 = r3.ordinal()     // Catch:{ NoSuchFieldError -> 0x0047 }
                r4 = 3
                r2[r3] = r4     // Catch:{ NoSuchFieldError -> 0x0047 }
            L_0x0047:
                com.epson.lib.escani2.EscanI2Lib$InputUnit[] r2 = com.epson.lib.escani2.EscanI2Lib.InputUnit.values()
                int r2 = r2.length
                int[] r2 = new int[r2]
                $SwitchMap$com$epson$lib$escani2$EscanI2Lib$InputUnit = r2
                int[] r2 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$InputUnit     // Catch:{ NoSuchFieldError -> 0x005a }
                com.epson.lib.escani2.EscanI2Lib$InputUnit r3 = com.epson.lib.escani2.EscanI2Lib.InputUnit.ADF     // Catch:{ NoSuchFieldError -> 0x005a }
                int r3 = r3.ordinal()     // Catch:{ NoSuchFieldError -> 0x005a }
                r2[r3] = r0     // Catch:{ NoSuchFieldError -> 0x005a }
            L_0x005a:
                int[] r0 = $SwitchMap$com$epson$lib$escani2$EscanI2Lib$InputUnit     // Catch:{ NoSuchFieldError -> 0x0064 }
                com.epson.lib.escani2.EscanI2Lib$InputUnit r2 = com.epson.lib.escani2.EscanI2Lib.InputUnit.FLATBED     // Catch:{ NoSuchFieldError -> 0x0064 }
                int r2 = r2.ordinal()     // Catch:{ NoSuchFieldError -> 0x0064 }
                r0[r2] = r1     // Catch:{ NoSuchFieldError -> 0x0064 }
            L_0x0064:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.I2ScanTask.C24451.<clinit>():void");
        }
    }

    private int checkScanParams(@NonNull File file, @NonNull ScanI2Params scanI2Params, @NonNull ScannerI2Info scannerI2Info) {
        int[] validScanSize = scanI2Params.scanSize.getValidScanSize(scannerI2Info, scanI2Params);
        if (validScanSize == null) {
            return 1;
        }
        if (file.getFreeSpace() < ((long) ((scanI2Params.inputUnit == EscanI2Lib.InputUnit.ADF ? ScanContinueParam.getAvailableScanPageCount() : 1) + 1)) * ((long) (validScanSize[0] * validScanSize[1] * 3))) {
            return 2;
        }
        return 0;
    }

    private String probeScanner(Context context, ScannerPropertyWrapper scannerPropertyWrapper) throws EscanLibException {
        synchronized (this) {
            this.mCancelableScannerProbe = new CancelableScannerProbe();
        }
        String probeScanner = this.mCancelableScannerProbe.probeScanner(scannerPropertyWrapper, context);
        synchronized (this) {
            this.mCancelableScannerProbe = null;
        }
        return probeScanner;
    }

    private void convertFile() {
        this.mResScanFileList = this.mImageProcessController.getScanFiles(this.mScanI2Runner.getScanPages());
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void scanProgressCallback(int i, int i2) {
        this.mImageProcessController.putScanResult(i, i2);
    }

    /* access modifiers changed from: protected */
    public void onPostExecute(TaskError taskError) {
        ScanResultReceiver scanResultReceiver = this.mScanResultReceiver;
        if (scanResultReceiver != null) {
            scanResultReceiver.onScanEnd(taskError);
        }
    }

    public void cancelScan() {
        this.mCancelRequested = true;
        synchronized (this) {
            if (this.mCancelableScannerProbe != null) {
                this.mCancelableScannerProbe.cancel();
            }
        }
        this.mScanI2Runner.cancelScan();
        this.mImageProcessController.cancelThread();
    }

    private void checkCancel() throws LocalCancel {
        if (this.mCancelRequested) {
            throw new LocalCancel();
        }
    }

    /* access modifiers changed from: package-private */
    public void onImageProcessEnd(int i, int i2) {
        ScanResultReceiver scanResultReceiver = this.mScanResultReceiver;
        if (scanResultReceiver != null) {
            scanResultReceiver.onProgressUpdate(i, i2);
        }
    }

    private class TaskObserver implements EscanI2Lib.Observer {
        private TaskObserver() {
        }

        /* synthetic */ TaskObserver(I2ScanTask i2ScanTask, C24451 r2) {
            this();
        }

        public void update(int i, int i2) {
            if (i2 > 0) {
                I2ScanTask.this.scanProgressCallback(i, i2 - 1);
            }
        }
    }

    public static class TaskError {
        public static final int ERROR_SD_CARD_NOT_MOUNTED = 2;
        public static final int ESC_I2_ERROR = 1;
        public static final int OTHER_ERROR = 2;
        public static final int OTHER_ERROR_INVALID_SCAN_AREA = 3;
        public int error1;
        public int error2;

        public TaskError(int i, int i2) {
            this.error1 = i;
            this.error2 = i2;
        }

        public boolean isCancel() {
            return this.error1 == 1 && this.error2 == 1;
        }

        public static boolean isInvalidScanArea(@Nullable TaskError taskError) {
            return taskError != null && taskError.error1 == 2 && taskError.error2 == 3;
        }
    }

    static class LocalCancel extends Throwable {
        LocalCancel() {
        }
    }
}
