package epson.print.service;

import android.os.RemoteException;
import com.epson.cameracopy.printlayout.ImageAndLayout;
import com.epson.iprint.prtlogger.Analytics;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import epson.common.ExternalFileUtils;
import epson.common.Info_paper;
import epson.image.epsonImage;
import epson.print.EPImageUtil;
import epson.print.MyPrinter;
import epson.print.screen.PrintSetting;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

class PrintAndLayoutThread extends Thread {
    private static final int DUPLEX_NONE = 0;
    private static final long REMOTE_FILE_SIZE_MAX = 10000000;
    private static final int[] REMOTE_IMAGE_CREATE_PROGRESS = {20, 25, 50, 70, 75};
    private static final int[] REMOTE_JPEG_QUALITYS = {95, 80};
    final int EPS_JOB_CANCELED = 40;
    private int mColorValue;
    private int mCopies;
    private final EpsonService mEpsonService;
    private final List<ImageAndLayout> mImageAndLayoutList;
    private boolean mIsBkRetry;
    private int mLayout;
    private int mPaperSizeId;
    private int mRemoteImageCreateProgress;

    public PrintAndLayoutThread(EpsonService epsonService, List<ImageAndLayout> list, boolean z) {
        this.mEpsonService = epsonService;
        this.mImageAndLayoutList = list;
        this.mIsBkRetry = z;
    }

    private int callStartJob() {
        int i;
        PrintSetting printSetting = new PrintSetting(this.mEpsonService, PrintSetting.Kind.cameracopy);
        printSetting.loadSettings();
        int i2 = printSetting.paperSizeValue;
        this.mPaperSizeId = i2;
        int i3 = printSetting.paperTypeValue;
        int i4 = printSetting.layoutValue;
        this.mLayout = i4;
        int i5 = printSetting.qualityValue;
        int i6 = printSetting.paperSourceValue;
        int i7 = printSetting.colorValue;
        this.mColorValue = i7;
        this.mCopies = printSetting.copiesValue;
        if (this.mEpsonService.getLang() == 2 || this.mEpsonService.getLang() == 3) {
            i = printSetting.feedDirectionValue;
        } else {
            i = 0;
        }
        return this.mEpsonService.startJob(i2, i3, i4, i5, i6, i7, 0, 0, 0, i, 0, this.mIsBkRetry);
    }

    private int getPrintRotation() {
        int lang = this.mEpsonService.getLang();
        return ((lang == 4 || lang == 7) && this.mEpsonService.pageSneedRotate(this.mPaperSizeId)) ? 1 : 0;
    }

    protected boolean createPrintImage(ImageAndLayout imageAndLayout, String str, int[] iArr) {
        int printRotation = getPrintRotation();
        int[] iArr2 = new int[2];
        boolean z = false;
        if ((printRotation & 1) != 0) {
            iArr2[0] = iArr[1];
            iArr2[1] = iArr[0];
        } else {
            iArr2[0] = iArr[0];
            iArr2[1] = iArr[1];
        }
        if (this.mColorValue == 1) {
            z = true;
        }
        return imageAndLayout.createPrintData(str, z, iArr2, printRotation);
    }

    private String getPrintFileName(int i) {
        return new File(ExternalFileUtils.getInstance(this.mEpsonService.getApplicationContext()).getPrintDir(), String.format(Locale.US, "_%02d.bmp", new Object[]{Integer.valueOf(i + 1)})).getPath();
    }

    public void run() {
        int i;
        synchronized (this.mEpsonService.getPrintLockObject()) {
            this.mEpsonService.setPrinting(true);
            this.mEpsonService.setCancelPrinting(false);
            if (MyPrinter.isRemotePrinter(this.mEpsonService)) {
                i = remotePrint();
            } else {
                i = localPrint();
            }
            if (i == 40) {
                i = 0;
            }
            this.mEpsonService.setPrinting(false);
            this.mEpsonService.setCancelPrinting(false);
            EpsonService.onNotifyEndJob(i);
        }
    }

    private int localPrint() {
        int i;
        try {
            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), true);
            int callStartJob = callStartJob();
            if (callStartJob != 0) {
                this.mEpsonService.endJob();
                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                this.mEpsonService.waitIfSimpleAp();
                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                return callStartJob;
            } else if (this.mEpsonService.getCancelPrinting()) {
                this.mEpsonService.endJob();
                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                this.mEpsonService.waitIfSimpleAp();
                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                return 40;
            } else {
                int[] printableArea = this.mEpsonService.getPrintableArea();
                int i2 = 0;
                i = 0;
                while (i2 < this.mCopies) {
                    try {
                        for (ImageAndLayout createPrintImage : this.mImageAndLayoutList) {
                            String printFileName = getPrintFileName(0);
                            if (!createPrintImage(createPrintImage, printFileName, printableArea)) {
                                this.mEpsonService.epsNotifyError(-1, EpsonService.MEDIA_INFO_MEMORY_ERROR, false);
                                this.mEpsonService.endJob();
                                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                this.mEpsonService.waitIfSimpleAp();
                                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                return EpsonService.MEDIA_INFO_MEMORY_ERROR;
                            } else if (this.mEpsonService.getCancelPrinting()) {
                                this.mEpsonService.endJob();
                                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                this.mEpsonService.waitIfSimpleAp();
                                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                return 40;
                            } else {
                                int initImage = this.mEpsonService.initImage(printFileName);
                                if (initImage != 0) {
                                    this.mEpsonService.endJob();
                                    Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                    this.mEpsonService.waitIfSimpleAp();
                                    WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                    return initImage;
                                } else if (this.mEpsonService.getCancelPrinting()) {
                                    this.mEpsonService.endJob();
                                    Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                    this.mEpsonService.waitIfSimpleAp();
                                    WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                    return 40;
                                } else {
                                    int startPage = this.mEpsonService.startPage();
                                    if (startPage != 0) {
                                        this.mEpsonService.endJob();
                                        Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                        this.mEpsonService.waitIfSimpleAp();
                                        WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                        return startPage;
                                    } else if (this.mEpsonService.getCancelPrinting()) {
                                        this.mEpsonService.endJob();
                                        Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                        this.mEpsonService.waitIfSimpleAp();
                                        WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                        return 40;
                                    } else {
                                        int printPage = this.mEpsonService.printPage();
                                        if (printPage != 0) {
                                            this.mEpsonService.endJob();
                                            Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                            this.mEpsonService.waitIfSimpleAp();
                                            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                            return printPage;
                                        } else if (this.mEpsonService.getCancelPrinting()) {
                                            this.mEpsonService.endJob();
                                            Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                            this.mEpsonService.waitIfSimpleAp();
                                            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                            return 40;
                                        } else {
                                            int endPage = this.mEpsonService.endPage(false);
                                            if (endPage != 0) {
                                                this.mEpsonService.endJob();
                                                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                                this.mEpsonService.waitIfSimpleAp();
                                                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                                return endPage;
                                            } else if (this.mEpsonService.getCancelPrinting()) {
                                                this.mEpsonService.endJob();
                                                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                                this.mEpsonService.waitIfSimpleAp();
                                                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                                return 40;
                                            } else {
                                                this.mEpsonService.releaseImage();
                                                if (this.mEpsonService.getCancelPrinting()) {
                                                    this.mEpsonService.endJob();
                                                    Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), 0);
                                                    this.mEpsonService.waitIfSimpleAp();
                                                    WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                                                    return 40;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        i2++;
                        i = 1;
                    } catch (Exception e) {
                        e = e;
                        try {
                            e.printStackTrace();
                            this.mEpsonService.endJob();
                            Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), i);
                            this.mEpsonService.waitIfSimpleAp();
                            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                            return 0;
                        } catch (Throwable th) {
                            th = th;
                            this.mEpsonService.endJob();
                            Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), i);
                            this.mEpsonService.waitIfSimpleAp();
                            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                            throw th;
                        }
                    }
                }
                this.mEpsonService.endJob();
                Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), i);
                this.mEpsonService.waitIfSimpleAp();
                WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
                return 0;
            }
        } catch (Exception e2) {
            e = e2;
            i = 0;
            e.printStackTrace();
            this.mEpsonService.endJob();
            Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), i);
            this.mEpsonService.waitIfSimpleAp();
            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
            return 0;
        } catch (Throwable th2) {
            th = th2;
            i = 0;
            this.mEpsonService.endJob();
            Analytics.savePrintInfo(this.mEpsonService.getApplicationContext(), i);
            this.mEpsonService.waitIfSimpleAp();
            WiFiDirectManager.setPriorityToSimpleAP(this.mEpsonService.getLocalApplicationContext(), false);
            throw th;
        }
    }

    private int remoteCreateJob() throws RemoteException {
        PrintSetting printSetting = new PrintSetting(this.mEpsonService, PrintSetting.Kind.cameracopy);
        printSetting.loadSettings();
        int i = printSetting.paperSizeValue;
        this.mPaperSizeId = i;
        int i2 = printSetting.paperTypeValue;
        int i3 = printSetting.layoutValue;
        this.mLayout = i3;
        int i4 = printSetting.qualityValue;
        int i5 = printSetting.paperSourceValue;
        int i6 = printSetting.colorValue;
        this.mColorValue = i6;
        this.mCopies = printSetting.copiesValue;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmm", Locale.US);
        return this.mEpsonService.epsonConnectCreateJob(2, simpleDateFormat.format(new Date()) + ".jpg", i, i2, i3, i4, i5, i6, 0, 0, 0, 0, 0, 0, 0);
    }

    /* JADX WARNING: Removed duplicated region for block: B:136:0x01e9  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private int remotePrint() {
        /*
            r7 = this;
            r0 = -1
            r1 = 0
            epson.print.service.EpsonService r2 = r7.mEpsonService     // Catch:{ Exception -> 0x01bc, all -> 0x01b8 }
            boolean r2 = r2.getCancelPrinting()     // Catch:{ Exception -> 0x01bc, all -> 0x01b8 }
            if (r2 == 0) goto L_0x001e
            epson.print.service.EpsonService r0 = r7.mEpsonService
            android.content.Context r0 = r0.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r0, r1)
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x0019 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x0019 }
            goto L_0x001d
        L_0x0019:
            r0 = move-exception
            r0.printStackTrace()
        L_0x001d:
            return r1
        L_0x001e:
            int r2 = r7.remoteCreateJob()     // Catch:{ Exception -> 0x01bc, all -> 0x01b8 }
            if (r2 == 0) goto L_0x003f
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x0034
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x0034:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x003a }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x003a }
            goto L_0x003e
        L_0x003a:
            r0 = move-exception
            r0.printStackTrace()
        L_0x003e:
            return r2
        L_0x003f:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r4 = 2
            r3.epsNotifyPage(r4)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            boolean r3 = r3.getCancelPrinting()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r3 == 0) goto L_0x0068
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x005d
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x005d:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x0063 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x0063 }
            goto L_0x0067
        L_0x0063:
            r0 = move-exception
            r0.printStackTrace()
        L_0x0067:
            return r1
        L_0x0068:
            java.lang.String r3 = r7.getPrintFileName(r1)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            java.lang.StringBuilder r4 = new java.lang.StringBuilder     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r4.<init>()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            java.lang.String r5 = "\\.\\w+$"
            java.lang.String r6 = ""
            java.lang.String r5 = r3.replaceFirst(r5, r6)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r4.append(r5)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            java.lang.String r5 = ".jpg"
            r4.append(r5)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            java.lang.String r4 = r4.toString()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            int r2 = r7.makeRemoteFile(r3, r4)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r2 == 0) goto L_0x00a6
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x009b
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x009b:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x00a1 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x00a1 }
            goto L_0x00a5
        L_0x00a1:
            r0 = move-exception
            r0.printStackTrace()
        L_0x00a5:
            return r2
        L_0x00a6:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r5 = 75
            r3.epsNotifyPage(r5)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            boolean r3 = r3.getCancelPrinting()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r3 == 0) goto L_0x00d0
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x00c5
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x00c5:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x00cb }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x00cb }
            goto L_0x00cf
        L_0x00cb:
            r0 = move-exception
            r0.printStackTrace()
        L_0x00cf:
            return r1
        L_0x00d0:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r5 = 1
            int r2 = r3.epsonConnectUploadFile(r4, r5)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r2 == 0) goto L_0x00f4
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x00e9
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x00e9:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x00ef }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x00ef }
            goto L_0x00f3
        L_0x00ef:
            r0 = move-exception
            r0.printStackTrace()
        L_0x00f3:
            return r2
        L_0x00f4:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r4 = 80
            r3.epsNotifyPage(r4)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            boolean r3 = r3.getCancelPrinting()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r3 == 0) goto L_0x011e
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x0113
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x0113:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x0119 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x0119 }
            goto L_0x011d
        L_0x0119:
            r0 = move-exception
            r0.printStackTrace()
        L_0x011d:
            return r1
        L_0x011e:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            int r4 = r7.mCopies     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r3.setEpsonConnectCopies(r4)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            int r2 = r3.epsonConnectChangePrintSetting()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r2 == 0) goto L_0x0148
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x013d
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x013d:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x0143 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x0143 }
            goto L_0x0147
        L_0x0143:
            r0 = move-exception
            r0.printStackTrace()
        L_0x0147:
            return r2
        L_0x0148:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            r4 = 90
            r3.epsNotifyPage(r4)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            boolean r3 = r3.getCancelPrinting()     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r3 == 0) goto L_0x0172
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x0167
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x0167:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x016d }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x016d }
            goto L_0x0171
        L_0x016d:
            r0 = move-exception
            r0.printStackTrace()
        L_0x0171:
            return r1
        L_0x0172:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            int r2 = r3.epsonConnectStartPrint(r1, r1)     // Catch:{ Exception -> 0x01b6, all -> 0x01b4 }
            if (r2 == 0) goto L_0x0195
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r1)
            if (r2 == 0) goto L_0x018a
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x018a:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x0190 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x0190 }
            goto L_0x0194
        L_0x0190:
            r0 = move-exception
            r0.printStackTrace()
        L_0x0194:
            return r2
        L_0x0195:
            epson.print.service.EpsonService r3 = r7.mEpsonService     // Catch:{ Exception -> 0x01b2 }
            r4 = 100
            r3.epsNotifyPage(r4)     // Catch:{ Exception -> 0x01b2 }
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r5)
            if (r2 == 0) goto L_0x01ac
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
        L_0x01ac:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x01d8 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x01d8 }
            goto L_0x01dc
        L_0x01b2:
            r3 = move-exception
            goto L_0x01bf
        L_0x01b4:
            r3 = move-exception
            goto L_0x01ba
        L_0x01b6:
            r3 = move-exception
            goto L_0x01be
        L_0x01b8:
            r3 = move-exception
            r2 = 0
        L_0x01ba:
            r5 = 0
            goto L_0x01de
        L_0x01bc:
            r3 = move-exception
            r2 = 0
        L_0x01be:
            r5 = 0
        L_0x01bf:
            r3.printStackTrace()     // Catch:{ all -> 0x01dd }
            r2 = -1200(0xfffffffffffffb50, float:NaN)
            epson.print.service.EpsonService r3 = r7.mEpsonService
            android.content.Context r3 = r3.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r3, r5)
            epson.print.service.EpsonService r3 = r7.mEpsonService
            r3.epsNotifyError(r0, r2, r1)
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x01d8 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x01d8 }
            goto L_0x01dc
        L_0x01d8:
            r0 = move-exception
            r0.printStackTrace()
        L_0x01dc:
            return r1
        L_0x01dd:
            r3 = move-exception
        L_0x01de:
            epson.print.service.EpsonService r4 = r7.mEpsonService
            android.content.Context r4 = r4.getApplicationContext()
            com.epson.iprint.prtlogger.Analytics.savePrintInfo(r4, r5)
            if (r2 == 0) goto L_0x01ee
            epson.print.service.EpsonService r4 = r7.mEpsonService
            r4.epsNotifyError(r0, r2, r1)
        L_0x01ee:
            epson.print.service.EpsonService r0 = r7.mEpsonService     // Catch:{ RemoteException -> 0x01f4 }
            r0.epsonConnectEndJob()     // Catch:{ RemoteException -> 0x01f4 }
            goto L_0x01f8
        L_0x01f4:
            r0 = move-exception
            r0.printStackTrace()
        L_0x01f8:
            throw r3
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.service.PrintAndLayoutThread.remotePrint():int");
    }

    protected int[] getRemotePrintableArea(int i, int i2) {
        Info_paper infoPaper = Info_paper.getInfoPaper(this.mEpsonService.getApplicationContext(), i);
        int[] iArr = new int[2];
        if (i2 == 2) {
            iArr[0] = infoPaper.getPaper_width_boder();
            iArr[1] = infoPaper.getPaper_height_boder();
        } else if (i2 == 1) {
            iArr[0] = infoPaper.getPaper_width_boderless();
            iArr[1] = infoPaper.getPaper_height_boderless();
        }
        return iArr;
    }

    static int convertBmpToJpeg(String str, String str2) {
        return new epsonImage().bmp2Jpg2(str, str2);
    }

    protected EPImageUtil getEPImageUtil() {
        return new EPImageUtil();
    }

    private void updateRemoteImageCreateProgress() {
        int i = this.mRemoteImageCreateProgress;
        int[] iArr = REMOTE_IMAGE_CREATE_PROGRESS;
        if (i < iArr.length) {
            this.mEpsonService.epsNotifyPage(iArr[i]);
            this.mRemoteImageCreateProgress++;
            return;
        }
        this.mEpsonService.epsNotifyPage(iArr[iArr.length - 1]);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:26:0x0072, code lost:
        r7 = r7 + 1;
        r6[0] = r6[0] / 2;
        r6[1] = r6[1] / 2;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private int makeRemoteFile(java.lang.String r18, java.lang.String r19) {
        /*
            r17 = this;
            r0 = r17
            r1 = r18
            r2 = r19
            java.util.List<com.epson.cameracopy.printlayout.ImageAndLayout> r3 = r0.mImageAndLayoutList
            r4 = 0
            java.lang.Object r3 = r3.get(r4)
            com.epson.cameracopy.printlayout.ImageAndLayout r3 = (com.epson.cameracopy.printlayout.ImageAndLayout) r3
            epson.print.EPImageUtil r5 = r17.getEPImageUtil()
            int r6 = r0.mPaperSizeId
            int r7 = r0.mLayout
            int[] r6 = r0.getRemotePrintableArea(r6, r7)
            r0.mRemoteImageCreateProgress = r4
            r7 = 0
        L_0x001e:
            r8 = 2
            if (r7 >= r8) goto L_0x007f
            boolean r9 = r0.createPrintImage(r3, r1, r6)
            if (r9 != 0) goto L_0x002a
            r1 = -5201(0xffffffffffffebaf, float:NaN)
            return r1
        L_0x002a:
            r17.updateRemoteImageCreateProgress()
            epson.print.service.EpsonService r9 = r0.mEpsonService
            boolean r9 = r9.getCancelPrinting()
            if (r9 == 0) goto L_0x0036
            return r4
        L_0x0036:
            java.io.File r9 = new java.io.File
            r9.<init>(r2)
            r10 = 1
            if (r7 < r10) goto L_0x0043
            int[] r11 = REMOTE_JPEG_QUALITYS
            int r11 = r11.length
            int r11 = r11 - r10
            goto L_0x0044
        L_0x0043:
            r11 = 0
        L_0x0044:
            int[] r12 = REMOTE_JPEG_QUALITYS
            int r13 = r12.length
            if (r11 >= r13) goto L_0x0072
            r12 = r12[r11]
            int r12 = r5.bmp2jpg(r1, r2, r12)
            long r13 = r9.length()
            if (r12 != 0) goto L_0x0063
            r15 = 0
            int r12 = (r13 > r15 ? 1 : (r13 == r15 ? 0 : -1))
            if (r12 <= 0) goto L_0x0063
            r15 = 10000000(0x989680, double:4.9406565E-317)
            int r12 = (r13 > r15 ? 1 : (r13 == r15 ? 0 : -1))
            if (r12 >= 0) goto L_0x0063
            return r4
        L_0x0063:
            r17.updateRemoteImageCreateProgress()
            epson.print.service.EpsonService r12 = r0.mEpsonService
            boolean r12 = r12.getCancelPrinting()
            if (r12 == 0) goto L_0x006f
            return r4
        L_0x006f:
            int r11 = r11 + 1
            goto L_0x0044
        L_0x0072:
            int r7 = r7 + 1
            r9 = r6[r4]
            int r9 = r9 / r8
            r6[r4] = r9
            r9 = r6[r10]
            int r9 = r9 / r8
            r6[r10] = r9
            goto L_0x001e
        L_0x007f:
            r1 = -1205(0xfffffffffffffb4b, float:NaN)
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.service.PrintAndLayoutThread.makeRemoteFile(java.lang.String, java.lang.String):int");
    }

    protected int test_makeRemoteFile(String str, String str2) {
        return makeRemoteFile(str, str2);
    }
}
