package epson.print.screen;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import com.epson.mobilephone.common.EpLog;
import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
import epson.print.Util.EPLog;
import java.util.ArrayList;

public class PaperSourceInfo {
    private static final long CHECK_INTEVAL = 4000;
    private static final int EPS_COMM_BID = 2;
    public static final String KEY_PAPERSOURCEINFO = "PAPERSOURCEINFO";
    public static final int NOTIFY_PAPERSOURCEINFO = 100;
    private static final String TAG = "PaperSourceInfo";
    public static PaperSourceInfo instance;
    private MaintainPrinter2 mPrinter = MaintainPrinter2.getInstance();
    private PaparInfoTask paparInfoTask = null;

    private PaperSourceInfo(Context context) {
        EpLog.i();
        this.mPrinter.doInitDriver(context, 2);
    }

    public static PaperSourceInfo getInstance(Context context) {
        if (instance == null) {
            instance = new PaperSourceInfo(context);
        }
        return instance;
    }

    public void start(Context context, Handler handler) {
        EPLog.i(TAG, "call start()");
        if (this.paparInfoTask == null) {
            this.paparInfoTask = new PaparInfoTask();
            this.paparInfoTask.execute(new Object[]{context, handler});
        }
    }

    public void stop() {
        EPLog.i(TAG, "call stop()");
        if (this.paparInfoTask != null) {
            this.mPrinter.doCancelFindPrinter();
            this.paparInfoTask.cancel(true);
            this.paparInfoTask = null;
        }
    }

    public class PaparInfoTask extends AsyncTask<Object, Void, Void> {
        public PaparInfoTask() {
        }

        /* access modifiers changed from: protected */
        /* JADX WARNING: Removed duplicated region for block: B:41:0x0149  */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public java.lang.Void doInBackground(java.lang.Object... r13) {
            /*
                r12 = this;
                r0 = 0
                r1 = r13[r0]
                android.content.Context r1 = (android.content.Context) r1
                r2 = 1
                r13 = r13[r2]
                android.os.Handler r13 = (android.os.Handler) r13
                r3 = 100
                epson.print.MyPrinter r4 = epson.print.MyPrinter.getCurPrinter(r1)     // Catch:{ InterruptedException -> 0x0141 }
                int r5 = r4.getLocation()     // Catch:{ InterruptedException -> 0x0141 }
                if (r5 == r2) goto L_0x001b
                r1 = 3
                if (r5 == r1) goto L_0x0025
                goto L_0x0142
            L_0x001b:
                java.lang.String r5 = "printer"
                java.lang.String r1 = com.epson.mobilephone.common.wifidirect.WiFiDirectManager.getConnectInfo(r1, r5)     // Catch:{ InterruptedException -> 0x0141 }
                if (r1 == 0) goto L_0x0025
                goto L_0x0142
            L_0x0025:
                boolean r1 = r12.isCancelled()     // Catch:{ InterruptedException -> 0x0141 }
                r5 = 4000(0xfa0, double:1.9763E-320)
                if (r1 != 0) goto L_0x008b
                epson.print.screen.PaperSourceInfo r1 = epson.print.screen.PaperSourceInfo.this     // Catch:{ InterruptedException -> 0x0141 }
                com.epson.mobilephone.common.maintain2.MaintainPrinter2 r1 = r1.mPrinter     // Catch:{ InterruptedException -> 0x0141 }
                r7 = 60
                java.lang.String r8 = r4.getPrinterId()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r9 = r4.getIp()     // Catch:{ InterruptedException -> 0x0141 }
                int r10 = r4.getLocation()     // Catch:{ InterruptedException -> 0x0141 }
                int r1 = r1.doProbePrinter(r7, r8, r9, r10)     // Catch:{ InterruptedException -> 0x0141 }
                r7 = -1300(0xfffffffffffffaec, float:NaN)
                if (r1 == r7) goto L_0x0071
                if (r1 == 0) goto L_0x0063
                java.lang.String r0 = "PaperSourceInfo"
                java.lang.StringBuilder r2 = new java.lang.StringBuilder     // Catch:{ InterruptedException -> 0x0141 }
                r2.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r4 = "doProbePrinter() return "
                r2.append(r4)     // Catch:{ InterruptedException -> 0x0141 }
                r2.append(r1)     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r1 = r2.toString()     // Catch:{ InterruptedException -> 0x0141 }
                epson.print.Util.EPLog.e((java.lang.String) r0, (java.lang.String) r1)     // Catch:{ InterruptedException -> 0x0141 }
                goto L_0x0142
            L_0x0063:
                epson.print.screen.PaperSourceInfo r1 = epson.print.screen.PaperSourceInfo.this     // Catch:{ InterruptedException -> 0x0141 }
                com.epson.mobilephone.common.maintain2.MaintainPrinter2 r1 = r1.mPrinter     // Catch:{ InterruptedException -> 0x0141 }
                int r1 = r1.doSetPrinter()     // Catch:{ InterruptedException -> 0x0141 }
                if (r1 == 0) goto L_0x008b
                goto L_0x0142
            L_0x0071:
                java.lang.String r7 = "PaperSourceInfo"
                java.lang.StringBuilder r8 = new java.lang.StringBuilder     // Catch:{ InterruptedException -> 0x0141 }
                r8.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r9 = "doProbePrinter() return "
                r8.append(r9)     // Catch:{ InterruptedException -> 0x0141 }
                r8.append(r1)     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r1 = r8.toString()     // Catch:{ InterruptedException -> 0x0141 }
                epson.print.Util.EPLog.i(r7, r1)     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.Thread.sleep(r5)     // Catch:{ InterruptedException -> 0x0141 }
                goto L_0x0025
            L_0x008b:
                boolean r1 = r12.isCancelled()     // Catch:{ InterruptedException -> 0x0141 }
                if (r1 != 0) goto L_0x0142
                epson.print.screen.PaperSourceInfo r1 = epson.print.screen.PaperSourceInfo.this     // Catch:{ InterruptedException -> 0x0141 }
                com.epson.mobilephone.common.maintain2.MaintainPrinter2 r1 = r1.mPrinter     // Catch:{ InterruptedException -> 0x0141 }
                int[] r1 = r1.getPaperInfo()     // Catch:{ InterruptedException -> 0x0141 }
                if (r1 != 0) goto L_0x00a6
                java.lang.String r0 = "PaperSourceInfo"
                java.lang.String r1 = "getPaperInfo() return null"
                epson.print.Util.EPLog.e((java.lang.String) r0, (java.lang.String) r1)     // Catch:{ InterruptedException -> 0x0141 }
                goto L_0x0142
            L_0x00a6:
                r4 = r1[r0]     // Catch:{ InterruptedException -> 0x0141 }
                r7 = -1100(0xfffffffffffffbb4, float:NaN)
                if (r4 == r7) goto L_0x0124
                if (r4 == 0) goto L_0x00c8
                java.lang.String r2 = "PaperSourceInfo"
                java.lang.StringBuilder r4 = new java.lang.StringBuilder     // Catch:{ InterruptedException -> 0x0141 }
                r4.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r5 = "getPaperInfo() return "
                r4.append(r5)     // Catch:{ InterruptedException -> 0x0141 }
                r0 = r1[r0]     // Catch:{ InterruptedException -> 0x0141 }
                r4.append(r0)     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r0 = r4.toString()     // Catch:{ InterruptedException -> 0x0141 }
                epson.print.Util.EPLog.e((java.lang.String) r2, (java.lang.String) r0)     // Catch:{ InterruptedException -> 0x0141 }
                goto L_0x0142
            L_0x00c8:
                r4 = r1[r2]     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r7 = "PaperSourceInfo"
                java.lang.StringBuilder r8 = new java.lang.StringBuilder     // Catch:{ InterruptedException -> 0x0141 }
                r8.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r9 = "getPaperInfo() number = "
                r8.append(r9)     // Catch:{ InterruptedException -> 0x0141 }
                r9 = r1[r2]     // Catch:{ InterruptedException -> 0x0141 }
                r8.append(r9)     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r8 = r8.toString()     // Catch:{ InterruptedException -> 0x0141 }
                epson.print.Util.EPLog.i(r7, r8)     // Catch:{ InterruptedException -> 0x0141 }
                if (r4 >= r2) goto L_0x00e5
                goto L_0x0142
            L_0x00e5:
                java.util.ArrayList r7 = new java.util.ArrayList     // Catch:{ InterruptedException -> 0x0141 }
                r7.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                r8 = 0
            L_0x00eb:
                if (r8 >= r4) goto L_0x010c
                epson.print.screen.PaperSourceSetting r9 = new epson.print.screen.PaperSourceSetting     // Catch:{ InterruptedException -> 0x0141 }
                r9.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                int r10 = r8 * 3
                int r11 = r10 + 2
                r11 = r1[r11]     // Catch:{ InterruptedException -> 0x0141 }
                r9.paperSource = r11     // Catch:{ InterruptedException -> 0x0141 }
                int r11 = r10 + 3
                r11 = r1[r11]     // Catch:{ InterruptedException -> 0x0141 }
                r9.paperSizeId = r11     // Catch:{ InterruptedException -> 0x0141 }
                int r10 = r10 + 4
                r10 = r1[r10]     // Catch:{ InterruptedException -> 0x0141 }
                r9.paperTypeId = r10     // Catch:{ InterruptedException -> 0x0141 }
                r7.add(r9)     // Catch:{ InterruptedException -> 0x0141 }
                int r8 = r8 + 1
                goto L_0x00eb
            L_0x010c:
                android.os.Bundle r1 = new android.os.Bundle     // Catch:{ InterruptedException -> 0x0141 }
                r1.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r4 = "PAPERSOURCEINFO"
                r1.putParcelableArrayList(r4, r7)     // Catch:{ InterruptedException -> 0x0141 }
                android.os.Message r4 = new android.os.Message     // Catch:{ InterruptedException -> 0x0141 }
                r4.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                r4.what = r3     // Catch:{ InterruptedException -> 0x0141 }
                r4.setData(r1)     // Catch:{ InterruptedException -> 0x0141 }
                r13.sendMessage(r4)     // Catch:{ InterruptedException -> 0x0141 }
                goto L_0x013c
            L_0x0124:
                java.lang.String r4 = "PaperSourceInfo"
                java.lang.StringBuilder r7 = new java.lang.StringBuilder     // Catch:{ InterruptedException -> 0x0141 }
                r7.<init>()     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r8 = "getPaperInfo() return "
                r7.append(r8)     // Catch:{ InterruptedException -> 0x0141 }
                r1 = r1[r0]     // Catch:{ InterruptedException -> 0x0141 }
                r7.append(r1)     // Catch:{ InterruptedException -> 0x0141 }
                java.lang.String r1 = r7.toString()     // Catch:{ InterruptedException -> 0x0141 }
                epson.print.Util.EPLog.i(r4, r1)     // Catch:{ InterruptedException -> 0x0141 }
            L_0x013c:
                java.lang.Thread.sleep(r5)     // Catch:{ InterruptedException -> 0x0141 }
                goto L_0x008b
            L_0x0141:
            L_0x0142:
                boolean r0 = r12.isCancelled()
                r1 = 0
                if (r0 != 0) goto L_0x0160
                android.os.Bundle r0 = new android.os.Bundle
                r0.<init>()
                java.lang.String r2 = "PAPERSOURCEINFO"
                r0.putParcelableArrayList(r2, r1)
                android.os.Message r2 = new android.os.Message
                r2.<init>()
                r2.what = r3
                r2.setData(r0)
                r13.sendMessage(r2)
            L_0x0160:
                return r1
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.print.screen.PaperSourceInfo.PaparInfoTask.doInBackground(java.lang.Object[]):java.lang.Void");
        }
    }

    public boolean checkPaperMissmatch(PrintSetting printSetting, ArrayList<PaperSourceSetting> arrayList) {
        for (int i = 0; i < arrayList.size(); i++) {
            if (printSetting.paperSourceValue == arrayList.get(i).paperSource && (printSetting.paperSizeValue != arrayList.get(i).paperSizeId || printSetting.paperTypeValue != arrayList.get(i).paperTypeId)) {
                return true;
            }
        }
        return false;
    }
}