123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package com.epson.mobilephone.common.usb;
- import android.hardware.usb.UsbDevice;
- import android.hardware.usb.UsbDeviceConnection;
- import android.hardware.usb.UsbEndpoint;
- import android.hardware.usb.UsbInterface;
- import android.hardware.usb.UsbManager;
- import android.os.Build;
- import com.epson.mobilephone.common.EpLog;
- import com.evernote.edam.limits.Constants;
- public class UsbPrinter {
- private static final String TAG = "UsbPrinter";
- protected static final int USBLP_BULK_TIMEOUT = 5000;
- protected static final int USBLP_CTL_TIMEOUT = 5000;
- protected static final int USBLP_REQ_GET_ID = 0;
- protected static final int USBLP_REQ_GET_STATUS = 1;
- protected static final int USBLP_REQ_RESET = 2;
- public static final int USB_OP_FAIL = -1;
- public static final int USB_OP_SUCCESS = 0;
- private UsbEndpoint endPointIn = null;
- private UsbEndpoint endPointOut = null;
- private long startTime = 0;
- private UsbDevice usbDevice = null;
- private UsbInterface usbInterface = null;
- private UsbManager usbManager = null;
- private UsbDeviceConnection usbPrinter = null;
- private class RequestType {
- public static final int DIR_IN = 128;
- public static final int DIR_OUT = 0;
- public static final int RECIPIENT_DEVICE = 0;
- public static final int RECIPIENT_ENDPOINT = 2;
- public static final int RECIPIENT_INTERFACE = 1;
- public static final int RECIPIENT_OTHER = 3;
- public static final int TYPE_CLASS = 32;
- public static final int TYPE_RESERVED = 96;
- public static final int TYPE_STANDARD = 0;
- public static final int TYPE_VENDOR = 64;
- private RequestType() {
- }
- }
- public UsbPrinter(UsbManager usbManager2, UsbDevice usbDevice2, UsbInterface usbInterface2, UsbEndpoint usbEndpoint, UsbEndpoint usbEndpoint2) {
- usbManager = usbManager2;
- usbDevice = usbDevice2;
- usbInterface = usbInterface2;
- endPointOut = usbEndpoint;
- endPointIn = usbEndpoint2;
- }
- public UsbDevice getUsbDevice() {
- return usbDevice;
- }
- public UsbDeviceConnection getUsbPrinter() {
- return usbPrinter;
- }
- public int getDeviceNumbers() {
- int deviceId = getUsbDevice().getDeviceId();
- int i = deviceId / 1000;
- return (i << 16) + (deviceId - (i * 1000));
- }
- public synchronized int openPort() {
- try {
- usbPrinter = usbManager.openDevice(this.usbDevice);
- if (this.usbPrinter == null) {
- return -1;
- }
- return usbPrinter.getFileDescriptor();
- } catch (Exception unused) {
- return -1;
- }
- }
- public synchronized long readPort(byte[] bArr, int i) {
- if (this.usbPrinter == null) {
- return -1;
- }
- if (!this.usbPrinter.claimInterface(this.usbInterface, true)) {
- return -1;
- }
- setStartTime();
- EpLog.m78i(TAG, "bulkTransfer length=" + i);
- int bulkTransfer = usbPrinter.bulkTransfer(this.endPointIn, bArr, i, Constants.EDAM_BUSINESS_NOTEBOOKS_MAX);
- EpLog.m78i(TAG, "bulkTransfer readByte=" + bulkTransfer);
- if (bulkTransfer < 0 && (getElapsedTime()) >= 4500.0d) {
- bulkTransfer = 0;
- EpLog.m78i(TAG, "bulkTransfer timeout occurred");
- }
- usbPrinter.releaseInterface(this.usbInterface);
- return (long) bulkTransfer;
- }
- public synchronized long writePort(byte[] bArr, int i) {
- if (this.usbPrinter == null) {
- return -1;
- }
- if (!this.usbPrinter.claimInterface(this.usbInterface, true)) {
- return -1;
- }
- setStartTime();
- EpLog.m78i(TAG, "bulkTransfer length=" + i);
- int bulkTransfer = usbPrinter.bulkTransfer(this.endPointOut, bArr, i, Constants.EDAM_BUSINESS_NOTEBOOKS_MAX);
- EpLog.m78i(TAG, "bulkTransfer writtenByte=" + bulkTransfer);
- if (bulkTransfer < 0 && (getElapsedTime()) >= 4500.0d) {
- bulkTransfer = 0;
- EpLog.m78i(TAG, "bulkTransfer timeout occurred");
- }
- usbPrinter.releaseInterface(this.usbInterface);
- return (long) bulkTransfer;
- }
- private void setStartTime() {
- startTime = System.currentTimeMillis();
- }
- private long getElapsedTime() {
- return System.currentTimeMillis() - startTime;
- }
- public synchronized long getDeviceIdString(byte[] bArr, int i) {
- if (this.usbPrinter == null) {
- return -1;
- }
- if (!this.usbPrinter.claimInterface(this.usbInterface, true)) {
- return -1;
- }
- int controlTransfer = usbPrinter.controlTransfer(161, 0, 0, usbInterface.getId() << 8, bArr, i, Constants.EDAM_BUSINESS_NOTEBOOKS_MAX);
- if (controlTransfer > 0) {
- EpLog.m78i("EPSON", "DeviceIdString = " + new String(bArr, 2, controlTransfer - 2));
- }
- usbPrinter.releaseInterface(this.usbInterface);
- return (long) controlTransfer;
- }
- /* JADX WARNING: Code restructure failed: missing block: B:16:0x0034, code lost:
- return -1;
- */
- /* Code decompiled incorrectly, please refer to instructions dump. */
- public synchronized int softReset() {
- /*
- r10 = this;
- monitor-enter(r10)
- android.hardware.usb.UsbDeviceConnection r0 = r10.usbPrinter // Catch:{ all -> 0x0035 }
- r1 = -1
- if (r0 != 0) goto L_0x0008
- monitor-exit(r10)
- return r1
- L_0x0008:
- android.hardware.usb.UsbDeviceConnection r0 = r10.usbPrinter // Catch:{ all -> 0x0035 }
- android.hardware.usb.UsbInterface r2 = r10.usbInterface // Catch:{ all -> 0x0035 }
- r3 = 1
- boolean r0 = r0.claimInterface(r2, r3) // Catch:{ all -> 0x0035 }
- if (r0 == 0) goto L_0x0033
- android.hardware.usb.UsbDeviceConnection r2 = r10.usbPrinter // Catch:{ all -> 0x0035 }
- r3 = 35
- r4 = 2
- r5 = 0
- android.hardware.usb.UsbInterface r0 = r10.usbInterface // Catch:{ all -> 0x0035 }
- int r6 = r0.getId() // Catch:{ all -> 0x0035 }
- r7 = 0
- r8 = 0
- r9 = 5000(0x1388, float:7.006E-42)
- int r0 = r2.controlTransfer(r3, r4, r5, r6, r7, r8, r9) // Catch:{ all -> 0x0035 }
- android.hardware.usb.UsbDeviceConnection r2 = r10.usbPrinter // Catch:{ all -> 0x0035 }
- android.hardware.usb.UsbInterface r3 = r10.usbInterface // Catch:{ all -> 0x0035 }
- r2.releaseInterface(r3) // Catch:{ all -> 0x0035 }
- if (r0 < 0) goto L_0x0033
- r0 = 0
- monitor-exit(r10)
- return r0
- L_0x0033:
- monitor-exit(r10)
- return r1
- L_0x0035:
- r0 = move-exception
- monitor-exit(r10)
- throw r0
- */
- throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.usb.UsbPrinter.softReset():int");
- }
- public synchronized void closePort() {
- if (this.usbPrinter != null) {
- usbPrinter.close();
- usbPrinter = null;
- }
- }
- public String toString() {
- String str = "deviceName = " + usbDevice.getDeviceName() + " : endPointOut = " + Integer.toHexString(this.endPointOut.getAddress()) + " : endPointIn = " + Integer.toHexString(this.endPointIn.getAddress());
- if (Build.VERSION.SDK_INT < 21) {
- return str;
- }
- return (str + " : productName = " + usbDevice.getProductName()) + " : SerialNo = " + usbDevice.getSerialNumber();
- }
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if ((obj instanceof UsbPrinter) && ((UsbPrinter) obj).getUsbDevice().getDeviceId() == getUsbDevice().getDeviceId()) {
- return true;
- }
- return false;
- }
- }
|