package com.epson.mobilephone.common.wifidirect;

import android.os.AsyncTask;
import android.os.Handler;

class FindPrinterTask extends AsyncTask<Void, Void, Boolean> {
    private static final String TAG = "FindPrinterTask";
    boolean canceled = false;
    Handler handler = null;
    int idFound;
    int idNotFound;
    escprLib mEscprLib = new escprLib();
    int timeout;

    FindPrinterTask(Handler handler2, int i, int i2, int i3) {
        this.handler = handler2;
        this.timeout = i;
        this.idFound = i2;
        this.idNotFound = i3;
    }

    protected void onPreExecute() {
        super.onPreExecute();
        this.mEscprLib.setHanlder(this.handler, this.idFound);
        this.mEscprLib.setSearchStt(true);
    }

    protected Boolean doInBackground(Void... voidArr) {
        int epsWrapperInitDriver = this.mEscprLib.epsWrapperInitDriver(192);
        boolean z = true;
        if (epsWrapperInitDriver != -1050 && epsWrapperInitDriver != 0) {
            return true;
        }
        EPLog.m86d(TAG, "epsWrapperFindPrinter start");
        int epsWrapperFindPrinter = this.mEscprLib.epsWrapperFindPrinter(192, this.timeout);
        if (epsWrapperFindPrinter == 0 || epsWrapperFindPrinter == 42) {
            z = false;
        }
        this.mEscprLib.epsWrapperReleaseDriver();
        return Boolean.valueOf(z);
    }

    protected void onPostExecute(Boolean bool) {
        if (bool.booleanValue() || !this.canceled) {
            EPLog.m86d(TAG, "epsWrapperFindPrinter = EPS_ERR_PRINTER_NOT_FOUND");
            this.handler.sendEmptyMessage(this.idNotFound);
        }
    }

    public void cancel() {
        this.mEscprLib.setSearchStt(false);
        this.mEscprLib.epsWrapperCancelFindPrinter();
        this.canceled = true;
    }
}
