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) {
        handler = handler2;
        timeout = i;
        idFound = i2;
        idNotFound = i3;
    }

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

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

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

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