UsbPrintDriver.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. package com.epson.mobilephone.common.usb;
  2. import android.content.Context;
  3. import android.hardware.usb.UsbDevice;
  4. import android.hardware.usb.UsbDeviceConnection;
  5. import android.hardware.usb.UsbEndpoint;
  6. import android.hardware.usb.UsbInterface;
  7. import android.hardware.usb.UsbManager;
  8. import java.util.ArrayList;
  9. import java.util.HashMap;
  10. public class UsbPrintDriver {
  11. private static final String TAG = "UsbPrintDriver";
  12. private static UsbPrintDriver instance;
  13. private Context context;
  14. private UsbManager usbManager;
  15. private ArrayList<UsbPrinter> usbPrintersPemmited = null;
  16. private UsbPrintDriver(Context context2) {
  17. usbManager = (UsbManager) context2.getSystemService("usb");
  18. context = context2;
  19. }
  20. public static synchronized UsbPrintDriver getInstance(Context context2) {
  21. UsbPrintDriver usbPrintDriver;
  22. synchronized (UsbPrintDriver.class) {
  23. if (instance == null) {
  24. instance = new UsbPrintDriver(context2);
  25. }
  26. usbPrintDriver = instance;
  27. }
  28. return usbPrintDriver;
  29. }
  30. public UsbManager getUsbManager() {
  31. return usbManager;
  32. }
  33. public boolean isExistPermitedDevice() {
  34. synchronized (this) {
  35. return findDevice(0, new int[3]) != -1;
  36. }
  37. }
  38. /* JADX WARNING: Code restructure failed: missing block: B:18:0x0058, code lost:
  39. return;
  40. */
  41. /* Code decompiled incorrectly, please refer to instructions dump. */
  42. public void deletePrinterPermmited(android.hardware.usb.UsbDevice r5) {
  43. /*
  44. r4 = this;
  45. monitor-enter(r4)
  46. if (r5 != 0) goto L_0x0005
  47. monitor-exit(r4) // Catch:{ all -> 0x0059 }
  48. return
  49. L_0x0005:
  50. java.util.ArrayList<com.epson.mobilephone.common.usb.UsbPrinter> r0 = r4.usbPrintersPemmited // Catch:{ all -> 0x0059 }
  51. if (r0 != 0) goto L_0x000b
  52. monitor-exit(r4) // Catch:{ all -> 0x0059 }
  53. return
  54. L_0x000b:
  55. java.util.ArrayList<com.epson.mobilephone.common.usb.UsbPrinter> r0 = r4.usbPrintersPemmited // Catch:{ all -> 0x0059 }
  56. java.util.Iterator r0 = r0.iterator() // Catch:{ all -> 0x0059 }
  57. L_0x0011:
  58. boolean r1 = r0.hasNext() // Catch:{ all -> 0x0059 }
  59. if (r1 == 0) goto L_0x0057
  60. java.lang.Object r1 = r0.next() // Catch:{ all -> 0x0059 }
  61. com.epson.mobilephone.common.usb.UsbPrinter r1 = (com.epson.mobilephone.common.usb.UsbPrinter) r1 // Catch:{ all -> 0x0059 }
  62. android.hardware.usb.UsbDevice r2 = r1.getUsbDevice() // Catch:{ all -> 0x0059 }
  63. int r2 = r2.getDeviceId() // Catch:{ all -> 0x0059 }
  64. int r3 = r5.getDeviceId() // Catch:{ all -> 0x0059 }
  65. if (r2 != r3) goto L_0x0011
  66. java.lang.String r5 = "Tag"
  67. java.lang.StringBuilder r0 = new java.lang.StringBuilder // Catch:{ all -> 0x0059 }
  68. r0.<init>() // Catch:{ all -> 0x0059 }
  69. java.lang.String r2 = "EPSON delete usbPrinter = "
  70. r0.append(r2) // Catch:{ all -> 0x0059 }
  71. java.lang.String r2 = r1.toString() // Catch:{ all -> 0x0059 }
  72. r0.append(r2) // Catch:{ all -> 0x0059 }
  73. java.lang.String r0 = r0.toString() // Catch:{ all -> 0x0059 }
  74. com.epson.mobilephone.common.EPLog.i(r5, r0) // Catch:{ all -> 0x0059 }
  75. r1.closePort() // Catch:{ all -> 0x0059 }
  76. java.util.ArrayList<com.epson.mobilephone.common.usb.UsbPrinter> r5 = r4.usbPrintersPemmited // Catch:{ all -> 0x0059 }
  77. boolean r5 = r5.remove(r1) // Catch:{ all -> 0x0059 }
  78. if (r5 == 0) goto L_0x0057
  79. java.lang.String r5 = "Tag"
  80. java.lang.String r0 = "EPSON delete success"
  81. com.epson.mobilephone.common.EPLog.i(r5, r0) // Catch:{ all -> 0x0059 }
  82. L_0x0057:
  83. monitor-exit(r4) // Catch:{ all -> 0x0059 }
  84. return
  85. L_0x0059:
  86. r5 = move-exception
  87. monitor-exit(r4) // Catch:{ all -> 0x0059 }
  88. throw r5
  89. */
  90. throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.usb.UsbPrintDriver.deletePrinterPermmited(android.hardware.usb.UsbDevice):void");
  91. }
  92. public synchronized ArrayList<UsbPrinter> findPrinters(boolean z, int i) {
  93. ArrayList<UsbPrinter> arrayList;
  94. synchronized (this) {
  95. arrayList = new ArrayList<>();
  96. HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
  97. for (String str : deviceList.keySet()) {
  98. UsbDevice usbDevice = deviceList.get(str);
  99. if (z) {
  100. if (usbManager.hasPermission(usbDevice)) {
  101. int i2 = i;
  102. }
  103. }
  104. if (usbDevice.getVendorId() == i) {
  105. int interfaceCount = usbDevice.getInterfaceCount();
  106. for (int i3 = 0; i3 < interfaceCount; i3++) {
  107. UsbInterface usbInterface = usbDevice.getInterface(i3);
  108. if (7 == usbInterface.getInterfaceClass() && 1 == usbInterface.getInterfaceSubclass()) {
  109. int i4 = 2;
  110. if (2 == usbInterface.getInterfaceProtocol()) {
  111. int endpointCount = usbInterface.getEndpointCount();
  112. UsbEndpoint usbEndpoint = null;
  113. UsbEndpoint usbEndpoint2 = null;
  114. int i5 = 0;
  115. while (i5 < endpointCount) {
  116. UsbEndpoint endpoint = usbInterface.getEndpoint(i5);
  117. if (usbEndpoint == null && i4 == endpoint.getType() && endpoint.getDirection() == 0) {
  118. usbEndpoint = endpoint;
  119. } else if (usbEndpoint2 == null && i4 == endpoint.getType() && 128 == endpoint.getDirection()) {
  120. usbEndpoint2 = endpoint;
  121. }
  122. i5++;
  123. i4 = 2;
  124. }
  125. if (!(usbEndpoint == null || usbEndpoint2 == null)) {
  126. UsbPrinter usbPrinter = new UsbPrinter(usbManager, usbDevice, usbInterface, usbEndpoint, usbEndpoint2);
  127. EPLog.i("EPSON", "Found Printer " + usbPrinter.toString());
  128. arrayList.add(usbPrinter);
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. return arrayList;
  137. }
  138. /* JADX WARNING: Code restructure failed: missing block: B:17:0x004c, code lost:
  139. return -1;
  140. */
  141. /* Code decompiled incorrectly, please refer to instructions dump. */
  142. public int findDevice(int r5, int[] r6) {
  143. /*
  144. r4 = this;
  145. java.lang.String r0 = "UsbPrintDriver"
  146. java.lang.String r1 = "Call findDevice"
  147. com.epson.mobilephone.common.EPLog.i(r0, r1)
  148. monitor-enter(r4)
  149. r0 = 1
  150. if (r5 != 0) goto L_0x0016
  151. int r1 = com.epson.mobilephone.common.PrintingLib.define.Constants.EPSON_VENDERID // Catch:{ all -> 0x0014 }
  152. java.util.ArrayList r1 = r4.findPrinters(r0, r1) // Catch:{ all -> 0x0014 }
  153. r4.usbPrintersPemmited = r1 // Catch:{ all -> 0x0014 }
  154. goto L_0x0016
  155. L_0x0014:
  156. r5 = move-exception
  157. goto L_0x004e
  158. L_0x0016:
  159. if (r5 < 0) goto L_0x004b
  160. java.util.ArrayList<com.epson.mobilephone.common.usb.UsbPrinter> r1 = r4.usbPrintersPemmited // Catch:{ all -> 0x0014 }
  161. if (r1 == 0) goto L_0x004b
  162. java.util.ArrayList<com.epson.mobilephone.common.usb.UsbPrinter> r1 = r4.usbPrintersPemmited // Catch:{ all -> 0x0014 }
  163. int r1 = r1.size() // Catch:{ all -> 0x0014 }
  164. if (r5 >= r1) goto L_0x004b
  165. java.util.ArrayList<com.epson.mobilephone.common.usb.UsbPrinter> r1 = r4.usbPrintersPemmited // Catch:{ all -> 0x0014 }
  166. java.lang.Object r1 = r1.get(r5) // Catch:{ all -> 0x0014 }
  167. com.epson.mobilephone.common.usb.UsbPrinter r1 = (com.epson.mobilephone.common.usb.UsbPrinter) r1 // Catch:{ all -> 0x0014 }
  168. r2 = 0
  169. android.hardware.usb.UsbDevice r3 = r1.getUsbDevice() // Catch:{ all -> 0x0014 }
  170. int r3 = r3.getVendorId() // Catch:{ all -> 0x0014 }
  171. r6[r2] = r3 // Catch:{ all -> 0x0014 }
  172. android.hardware.usb.UsbDevice r2 = r1.getUsbDevice() // Catch:{ all -> 0x0014 }
  173. int r2 = r2.getProductId() // Catch:{ all -> 0x0014 }
  174. r6[r0] = r2 // Catch:{ all -> 0x0014 }
  175. r2 = 2
  176. int r1 = r1.getDeviceNumbers() // Catch:{ all -> 0x0014 }
  177. r6[r2] = r1 // Catch:{ all -> 0x0014 }
  178. int r5 = r5 + r0
  179. monitor-exit(r4) // Catch:{ all -> 0x0014 }
  180. return r5
  181. L_0x004b:
  182. monitor-exit(r4) // Catch:{ all -> 0x0014 }
  183. r5 = -1
  184. return r5
  185. L_0x004e:
  186. monitor-exit(r4) // Catch:{ all -> 0x0014 }
  187. throw r5
  188. */
  189. throw new UnsupportedOperationException("Method not decompiled: com.epson.mobilephone.common.usb.UsbPrintDriver.findDevice(int, int[]):int");
  190. }
  191. public int openPort(int[] iArr) {
  192. EPLog.i(TAG, "Call openPort");
  193. synchronized (this) {
  194. for (int i = 0; i < usbPrintersPemmited.size(); i++) {
  195. UsbPrinter usbPrinter = usbPrintersPemmited.get(i);
  196. if (iArr[0] == usbPrinter.getUsbDevice().getVendorId() && iArr[1] == usbPrinter.getUsbDevice().getProductId() && iArr[2] == usbPrinter.getDeviceNumbers()) {
  197. int openPort = usbPrinter.openPort();
  198. return openPort;
  199. }
  200. }
  201. return -1;
  202. }
  203. }
  204. public UsbPrinter findPrinterOpened(int i) {
  205. synchronized (this) {
  206. for (int i2 = 0; i2 < usbPrintersPemmited.size(); i2++) {
  207. UsbPrinter usbPrinter = usbPrintersPemmited.get(i2);
  208. UsbDeviceConnection usbPrinter2 = usbPrinter.getUsbPrinter();
  209. if (usbPrinter2 != null) {
  210. if (i == usbPrinter2.getFileDescriptor()) {
  211. return usbPrinter;
  212. }
  213. }
  214. }
  215. return null;
  216. }
  217. }
  218. public long readPort(int i, byte[] bArr, int i2) {
  219. EPLog.i(TAG, "Call readPort");
  220. synchronized (this) {
  221. UsbPrinter findPrinterOpened = findPrinterOpened(i);
  222. if (findPrinterOpened == null) {
  223. return -1;
  224. }
  225. long readPort = findPrinterOpened.readPort(bArr, i2);
  226. return readPort;
  227. }
  228. }
  229. public long writePort(int i, byte[] bArr, int i2) {
  230. EPLog.i(TAG, "Call writePort");
  231. synchronized (this) {
  232. UsbPrinter findPrinterOpened = findPrinterOpened(i);
  233. if (findPrinterOpened == null) {
  234. return -1;
  235. }
  236. long writePort = findPrinterOpened.writePort(bArr, i2);
  237. return writePort;
  238. }
  239. }
  240. public long getDeviceIdString(int i, byte[] bArr, int i2) {
  241. EPLog.i(TAG, "Call getDeviceIdString");
  242. synchronized (this) {
  243. UsbPrinter findPrinterOpened = findPrinterOpened(i);
  244. if (findPrinterOpened == null) {
  245. return -1;
  246. }
  247. long deviceIdString = findPrinterOpened.getDeviceIdString(bArr, i2);
  248. return deviceIdString;
  249. }
  250. }
  251. public int softReset(int i) {
  252. EPLog.i(TAG, "Call softReset");
  253. synchronized (this) {
  254. UsbPrinter findPrinterOpened = findPrinterOpened(i);
  255. if (findPrinterOpened == null) {
  256. return -1;
  257. }
  258. int softReset = findPrinterOpened.softReset();
  259. return softReset;
  260. }
  261. }
  262. public void closePort(int i) {
  263. EPLog.i(TAG, "Call closePort");
  264. synchronized (this) {
  265. UsbPrinter findPrinterOpened = findPrinterOpened(i);
  266. if (findPrinterOpened != null) {
  267. findPrinterOpened.closePort();
  268. }
  269. }
  270. }
  271. }