package com.epson.mobilephone.common.wifidirect;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class escprLib {
    public static final int EPS_ERR_COMM_ERROR = -1100;
    public static final int EPS_ERR_LIB_INTIALIZED = -1050;
    public static final int EPS_ERR_NONE = 0;
    public static final int EPS_ERR_PRINTER_NOT_FOUND = -1300;
    public static final int EPS_FIND_CANCELED = 42;
    public static final int EPS_PROTOCOL_LPR = 64;
    public static final int EPS_PROTOCOL_NET = 192;
    public static final int EPS_PROTOCOL_RAW = 128;
    public static final String PRINTER_FRIENDLYNAME = "friendlyname";
    public static final String PRINTER_ID = "id";
    public static final String PRINTER_IP = "ip";
    public static final String PRINTER_MACADDRESS = "mac";
    public static final String PRINTER_MANIFACTURER = "manufacturer";
    public static final String PRINTER_NAME = "name";
    public static final String PRINTER_PROTCOL = "protcol";
    public static final String PRINTER_SERIAL_NO = "serial_no";
    public static final String PRINTER_SUPPORTFUNC = "supportfunc";
    private String debugString;
    private Handler mHandler;
    int mIdFound;
    private boolean mIsSearch;
    private String printerList;

    public static class AutoGoTimeoutInfo {
        int cur;
        int max;
        int min;
    }

    public static class ConnectStrings {
        String friendlyName;
        String modelName;
        String password;
        String printerId;
        String printerIp;
        String serialNo;
        String ssid;
    }

    public native int epsWrapperCancelFindPrinter();

    public native int epsWrapperFindPrinter(int i, int i2);

    public native int epsWrapperGetAutoGoTimeOutValues(char[] cArr, AutoGoTimeoutInfo autoGoTimeoutInfo);

    public native int epsWrapperGetConnectStrings(byte[] bArr, ConnectStrings connectStrings);

    public native int epsWrapperGetSetupConnectStrings(ConnectStrings connectStrings);

    public native int epsWrapperInitDriver(int i);

    public native int epsWrapperReleaseDriver();

    public native int epsWrapperSetAutoGoTimeOut(char[] cArr, int i);

    public native int epsWrapperStartWifiDirect(char[] cArr);

    static {
        System.out.println("begin load escpr-wifidirect lib");
        System.loadLibrary("escpr-wifidirect");
        System.out.println("load escpr-wifidirect lib finish");
    }

    private void findPrinterCB() {
        String str = printerList;
        if (str != null && str.length() > 0) {
            String name = getClass().getName();
            EPLog.e(name, "EXTRACT Printer information: " + printerList);
            String[] split = printerList.split("\\|\\|");
            if (mIsSearch && mHandler != null) {
                Message obtain = Message.obtain();
                obtain.what = mIdFound;
                Bundle bundle = new Bundle();
                String str2 = "";
                if (split.length == 10 && split[9] != null) {
                    str2 = split[9];
                }
                bundle.putInt(PRINTER_SUPPORTFUNC, Integer.parseInt(split[1]));
                bundle.putInt(PRINTER_PROTCOL, Integer.parseInt(split[2]));
                bundle.putString(PRINTER_MANIFACTURER, split[3]);
                bundle.putString("name", split[4]);
                bundle.putString(PRINTER_IP, split[5]);
                bundle.putString(PRINTER_FRIENDLYNAME, split[6]);
                bundle.putString(PRINTER_MACADDRESS, split[7]);
                bundle.putString("id", split[8]);
                bundle.putString(PRINTER_SERIAL_NO, str2);
                obtain.setData(bundle);
                mHandler.sendMessage(obtain);
            }
        }
        printerList = "";
    }

    private void javaDebugCB() {
        EPLog.i(getClass().getName(), debugString);
        debugString = "";
    }

    public void setHanlder(Handler handler, int i) {
        mHandler = handler;
        mIdFound = i;
    }

    public void setSearchStt(boolean z) {
        mIsSearch = z;
    }

    public static byte[] getMd5(byte[] bArr) {
        byte[] bArr2 = {0};
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            instance.update(bArr);
            return instance.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return bArr2;
        }
    }
}
