EPPrinterManager.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. package epson.print;
  2. import android.content.Context;
  3. import com.epson.iprint.storage.StorageSecureStore;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.util.ArrayList;
  8. import java.util.Iterator;
  9. import epson.common.Constants;
  10. import epson.common.ExternalFileUtils;
  11. import epson.common.Utils;
  12. import epson.print.Util.EPLog;
  13. import epson.print.ecclient.EpsonConnectAccess;
  14. import epson.scan.lib.ScanSettingHelper;
  15. /**
  16. * 爱普生打印管理器
  17. */
  18. public class EPPrinterManager {
  19. private static final String TAG = "EPPrinterManager";
  20. private static ArrayList<EPPrinterInfo> deletedRemotePrinterList;
  21. private static ArrayList<EPPrinterInfo> ipPrinterList;
  22. private static ArrayList<EPPrinterInfo> remotePrinterList;
  23. Context context;
  24. public EPPrinterManager(Context context2) {
  25. StorageSecureStore.initSharedSecureStore(context2);
  26. context = context2;
  27. }
  28. public ArrayList<EPPrinterInfo> getRemotePrinterList() {
  29. ArrayList<EPPrinterInfo> arrayList = remotePrinterList;
  30. if (arrayList != null) {
  31. return arrayList;
  32. }
  33. remotePrinterList = loadPrinterList(ExternalFileUtils.getInstance(context).getRemotePrintersInfo(), 2);
  34. return remotePrinterList;
  35. }
  36. public ArrayList<EPPrinterInfo> getIpPrinterList() {
  37. ArrayList<EPPrinterInfo> arrayList = ipPrinterList;
  38. if (arrayList != null) {
  39. return arrayList;
  40. }
  41. ipPrinterList = loadPrinterList(ExternalFileUtils.getInstance(context).getIpPrintersInfo(), 3);
  42. return ipPrinterList;
  43. }
  44. public String getIpPrinterUserName(String str) {
  45. if (str == null || str.isEmpty()) {
  46. return null;
  47. }
  48. Iterator<EPPrinterInfo> it = getIpPrinterList().iterator();
  49. while (it.hasNext()) {
  50. EPPrinterInfo next = it.next();
  51. if (str.equals(next.scannerID)) {
  52. return next.userDefName;
  53. }
  54. }
  55. return null;
  56. }
  57. public boolean doseContainScannerIdInIpPrinterList(String str) {
  58. if (str == null || str.isEmpty()) {
  59. return false;
  60. }
  61. Iterator<EPPrinterInfo> it = getIpPrinterList().iterator();
  62. while (it.hasNext()) {
  63. if (str.equals(it.next().scannerID)) {
  64. return true;
  65. }
  66. }
  67. return false;
  68. }
  69. /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r4v4, resolved type: epson.print.EPPrinterInfo} */
  70. /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r4v6, resolved type: java.io.ObjectInputStream} */
  71. /* JADX WARNING: type inference failed for: r4v2 */
  72. /* JADX WARNING: type inference failed for: r4v3, types: [java.io.ObjectInputStream] */
  73. /* JADX WARNING: type inference failed for: r4v5 */
  74. /* JADX WARNING: type inference failed for: r4v7 */
  75. /* JADX WARNING: type inference failed for: r4v8 */
  76. /* JADX WARNING: type inference failed for: r4v9 */
  77. /* JADX WARNING: type inference failed for: r4v10 */
  78. /* JADX WARNING: Code restructure failed: missing block: B:54:0x00c1, code lost:
  79. r7 = th;
  80. */
  81. /* JADX WARNING: Code restructure failed: missing block: B:55:0x00c2, code lost:
  82. r4 = r2;
  83. */
  84. /* JADX WARNING: Code restructure failed: missing block: B:57:0x00c5, code lost:
  85. r4.close();
  86. */
  87. /* JADX WARNING: Code restructure failed: missing block: B:59:0x00ca, code lost:
  88. r3.close();
  89. */
  90. /* JADX WARNING: Failed to insert additional move for type inference */
  91. /* JADX WARNING: Failed to process nested try/catch */
  92. /* JADX WARNING: Multi-variable type inference failed */
  93. /* JADX WARNING: Removed duplicated region for block: B:41:0x006b A[SYNTHETIC, Splitter:B:41:0x006b] */
  94. /* JADX WARNING: Removed duplicated region for block: B:44:0x0070 A[Catch:{ Exception -> 0x00ce }] */
  95. /* JADX WARNING: Removed duplicated region for block: B:46:0x0073 A[Catch:{ Exception -> 0x00ce }] */
  96. /* JADX WARNING: Removed duplicated region for block: B:57:0x00c5 A[Catch:{ Exception -> 0x00ce }] */
  97. /* JADX WARNING: Removed duplicated region for block: B:59:0x00ca A[Catch:{ Exception -> 0x00ce }] */
  98. /* JADX WARNING: Removed duplicated region for block: B:66:0x00bd A[SYNTHETIC] */
  99. /* Code decompiled incorrectly, please refer to instructions dump. */
  100. private ArrayList<EPPrinterInfo> loadPrinterList(String r7, int r8) {
  101. /*
  102. r6 = this;
  103. java.util.ArrayList r0 = new java.util.ArrayList
  104. r0.<init>()
  105. java.io.File r1 = new java.io.File // Catch:{ Exception -> 0x00ce }
  106. r1.<init>(r7) // Catch:{ Exception -> 0x00ce }
  107. java.io.File[] r7 = r1.listFiles() // Catch:{ Exception -> 0x00ce }
  108. if (r7 != 0) goto L_0x0011
  109. return r0
  110. L_0x0011:
  111. r0.clear() // Catch:{ Exception -> 0x00ce }
  112. r1 = 0
  113. L_0x0015:
  114. int r2 = r7.length // Catch:{ Exception -> 0x00ce }
  115. if (r1 >= r2) goto L_0x00d5
  116. epson.print.EPPrinterInfo r2 = new epson.print.EPPrinterInfo // Catch:{ Exception -> 0x00ce }
  117. r2.<init>() // Catch:{ Exception -> 0x00ce }
  118. java.io.FileInputStream r3 = new java.io.FileInputStream // Catch:{ Exception -> 0x00ce }
  119. r4 = r7[r1] // Catch:{ Exception -> 0x00ce }
  120. java.lang.String r4 = r4.getAbsolutePath() // Catch:{ Exception -> 0x00ce }
  121. r3.<init>(r4) // Catch:{ Exception -> 0x00ce }
  122. r4 = 0
  123. r2.readJSON(r3) // Catch:{ JSONException -> 0x003c, Exception -> 0x0034 }
  124. r3.close() // Catch:{ Exception -> 0x00ce }
  125. r4 = r2
  126. goto L_0x0071
  127. L_0x0031:
  128. r7 = move-exception
  129. goto L_0x00c3
  130. L_0x0034:
  131. r2 = move-exception
  132. r2.printStackTrace() // Catch:{ all -> 0x0031 }
  133. L_0x0038:
  134. r3.close() // Catch:{ Exception -> 0x00ce }
  135. goto L_0x0071
  136. L_0x003c:
  137. r2 = move-exception
  138. r2.printStackTrace() // Catch:{ all -> 0x0031 }
  139. r3.close() // Catch:{ all -> 0x0031 }
  140. java.io.FileInputStream r3 = new java.io.FileInputStream // Catch:{ Exception -> 0x0063, all -> 0x0060 }
  141. r2 = r7[r1] // Catch:{ Exception -> 0x0063, all -> 0x0060 }
  142. java.lang.String r2 = r2.getAbsolutePath() // Catch:{ Exception -> 0x0063, all -> 0x0060 }
  143. r3.<init>(r2) // Catch:{ Exception -> 0x0063, all -> 0x0060 }
  144. java.io.ObjectInputStream r2 = new java.io.ObjectInputStream // Catch:{ Exception -> 0x005d }
  145. r2.<init>(r3) // Catch:{ Exception -> 0x005d }
  146. java.lang.Object r5 = r2.readObject() // Catch:{ Exception -> 0x005b }
  147. epson.print.EPPrinterInfo r5 = (epson.print.EPPrinterInfo) r5 // Catch:{ Exception -> 0x005b }
  148. r4 = r5
  149. goto L_0x0069
  150. L_0x005b:
  151. r5 = move-exception
  152. goto L_0x0066
  153. L_0x005d:
  154. r5 = move-exception
  155. r2 = r4
  156. goto L_0x0066
  157. L_0x0060:
  158. r7 = move-exception
  159. r3 = r4
  160. goto L_0x00c3
  161. L_0x0063:
  162. r5 = move-exception
  163. r2 = r4
  164. r3 = r2
  165. L_0x0066:
  166. r5.printStackTrace() // Catch:{ all -> 0x00c1 }
  167. L_0x0069:
  168. if (r2 == 0) goto L_0x006e
  169. r2.close() // Catch:{ Exception -> 0x00ce }
  170. L_0x006e:
  171. if (r3 == 0) goto L_0x0071
  172. goto L_0x0038
  173. L_0x0071:
  174. if (r4 == 0) goto L_0x00bd
  175. r2 = 2
  176. if (r8 != r2) goto L_0x00ba
  177. com.epson.iprint.storage.StorageSecureStore r2 = com.epson.iprint.storage.StorageSecureStore.getSharedSecureStore() // Catch:{ Exception -> 0x00ce }
  178. java.lang.String r3 = r4.printerEmailAddress // Catch:{ Exception -> 0x00ce }
  179. java.lang.String r3 = r3.toLowerCase() // Catch:{ Exception -> 0x00ce }
  180. java.lang.String r2 = r2.fetch(r3) // Catch:{ Exception -> 0x00ce }
  181. r4.printerAccessKey = r2 // Catch:{ Exception -> 0x00ce }
  182. java.lang.String r2 = r4.printerAccessKey // Catch:{ Exception -> 0x00ce }
  183. if (r2 == 0) goto L_0x00b6
  184. java.lang.String r2 = "EPPrinterManager"
  185. java.lang.StringBuilder r3 = new java.lang.StringBuilder // Catch:{ Exception -> 0x00ce }
  186. r3.<init>() // Catch:{ Exception -> 0x00ce }
  187. java.lang.String r5 = "Success: fetch printerAccessKey. ("
  188. r3.append(r5) // Catch:{ Exception -> 0x00ce }
  189. java.lang.String r5 = r4.printerEmailAddress // Catch:{ Exception -> 0x00ce }
  190. java.lang.String r5 = r5.toLowerCase() // Catch:{ Exception -> 0x00ce }
  191. r3.append(r5) // Catch:{ Exception -> 0x00ce }
  192. java.lang.String r5 = " = "
  193. r3.append(r5) // Catch:{ Exception -> 0x00ce }
  194. java.lang.String r5 = r4.printerAccessKey // Catch:{ Exception -> 0x00ce }
  195. r3.append(r5) // Catch:{ Exception -> 0x00ce }
  196. java.lang.String r5 = ")"
  197. r3.append(r5) // Catch:{ Exception -> 0x00ce }
  198. java.lang.String r3 = r3.toString() // Catch:{ Exception -> 0x00ce }
  199. epson.print.Util.EPLog.i(r2, r3) // Catch:{ Exception -> 0x00ce }
  200. goto L_0x00ba
  201. L_0x00b6:
  202. java.lang.String r2 = ""
  203. r4.printerAccessKey = r2 // Catch:{ Exception -> 0x00ce }
  204. L_0x00ba:
  205. r0.add(r4) // Catch:{ Exception -> 0x00ce }
  206. L_0x00bd:
  207. int r1 = r1 + 1
  208. goto L_0x0015
  209. L_0x00c1:
  210. r7 = move-exception
  211. r4 = r2
  212. L_0x00c3:
  213. if (r4 == 0) goto L_0x00c8
  214. r4.close() // Catch:{ Exception -> 0x00ce }
  215. L_0x00c8:
  216. if (r3 == 0) goto L_0x00cd
  217. r3.close() // Catch:{ Exception -> 0x00ce }
  218. L_0x00cd:
  219. throw r7 // Catch:{ Exception -> 0x00ce }
  220. L_0x00ce:
  221. java.lang.String r7 = "EPPrinterManager"
  222. java.lang.String r8 = "loadPrinterList(): error."
  223. epson.print.Util.EPLog.m307e((java.lang.String) r7, (java.lang.String) r8)
  224. L_0x00d5:
  225. return r0
  226. */
  227. throw new UnsupportedOperationException("Method not decompiled: epson.print.EPPrinterManager.loadPrinterList(java.lang.String, int):java.util.ArrayList");
  228. }
  229. public EPPrinterInfo loadRemotePrinterInfo(String str) {
  230. Iterator<EPPrinterInfo> it = getRemotePrinterList().iterator();
  231. while (it.hasNext()) {
  232. EPPrinterInfo next = it.next();
  233. if (next.printerEmailAddress.toLowerCase().equals(str.toLowerCase())) {
  234. return next;
  235. }
  236. }
  237. return null;
  238. }
  239. public EPPrinterInfo loadIpPrinterInfo(String str) {
  240. Iterator<EPPrinterInfo> it = getIpPrinterList().iterator();
  241. while (it.hasNext()) {
  242. EPPrinterInfo next = it.next();
  243. if (next.printerID.equals(str)) {
  244. return next;
  245. }
  246. }
  247. return null;
  248. }
  249. public void saveRemotePrinterInfo(EPPrinterInfo ePPrinterInfo) {
  250. ePPrinterInfo.printerLocation = 2;
  251. ArrayList<EPPrinterInfo> remotePrinterList2 = getRemotePrinterList();
  252. for (int i = 0; i < remotePrinterList2.size(); i++) {
  253. if (remotePrinterList2.get(i).printerEmailAddress.toLowerCase().equals(ePPrinterInfo.printerEmailAddress.toLowerCase())) {
  254. remotePrinterList2.set(i, ePPrinterInfo);
  255. return;
  256. }
  257. }
  258. remotePrinterList2.add(ePPrinterInfo);
  259. }
  260. public void saveIPPrinterInfo(String str, EPPrinterInfo ePPrinterInfo) {
  261. ePPrinterInfo.printerLocation = 3;
  262. ArrayList<EPPrinterInfo> ipPrinterList2 = getIpPrinterList();
  263. for (int i = 0; i < ipPrinterList2.size(); i++) {
  264. if (ipPrinterList2.get(i).printerID.equals(str)) {
  265. ipPrinterList2.set(i, ePPrinterInfo);
  266. return;
  267. }
  268. }
  269. ipPrinterList2.add(ePPrinterInfo);
  270. }
  271. public void commitRemotePrinterInfo() {
  272. if (remotePrinterList != null) {
  273. EPLog.i(TAG, "commitRemotePrinterInfo() called");
  274. if (deletedRemotePrinterList != null) {
  275. for (int i = 0; i < deletedRemotePrinterList.size(); i++) {
  276. String str = deletedRemotePrinterList.get(i).printerEmailAddress;
  277. if (StorageSecureStore.getSharedSecureStore().revoke(str.toLowerCase())) {
  278. EPLog.i(TAG, "Success: remove printerAccessKey. (" + str.toLowerCase() + ")");
  279. }
  280. }
  281. }
  282. ExternalFileUtils.getInstance(context).clearRemotePrintersInfo();
  283. ArrayList<EPPrinterInfo> remotePrinterList2 = getRemotePrinterList();
  284. for (int i2 = 0; i2 < remotePrinterList2.size(); i2++) {
  285. serializePrinterInfo(ExternalFileUtils.getInstance(context).getRemotePrintersInfo(), remotePrinterList2.get(i2).printerEmailAddress.toLowerCase(), remotePrinterList2.get(i2));
  286. }
  287. rollbackRemotePrinterInfo();
  288. }
  289. }
  290. public void rollbackRemotePrinterInfo() {
  291. EPLog.i(TAG, "rollbackRemotePrinterInfo() called");
  292. remotePrinterList = null;
  293. deletedRemotePrinterList = null;
  294. }
  295. public void commitIPPrinterInfo() {
  296. if (ipPrinterList != null) {
  297. EPLog.i(TAG, "commitIPPrinterInfo() called");
  298. ExternalFileUtils.getInstance(context).clearIpPrintersInfo();
  299. ArrayList<EPPrinterInfo> ipPrinterList2 = getIpPrinterList();
  300. for (int i = 0; i < ipPrinterList2.size(); i++) {
  301. serializePrinterInfo(ExternalFileUtils.getInstance(context).getIpPrintersInfo(), ipPrinterList2.get(i).printerID, ipPrinterList2.get(i));
  302. }
  303. checkModifiedIP();
  304. rollbackIPPrinterInfo();
  305. }
  306. }
  307. private void checkModifiedIP() {
  308. boolean z;
  309. MyPrinter curPrinter = MyPrinter.getCurPrinter(context);
  310. boolean z2 = true;
  311. if (curPrinter.getLocation() == 3) {
  312. Iterator<EPPrinterInfo> it = getIpPrinterList().iterator();
  313. while (true) {
  314. if (!it.hasNext()) {
  315. z = false;
  316. break;
  317. }
  318. EPPrinterInfo next = it.next();
  319. if (curPrinter.getPrinterId().equals(next.printerID)) {
  320. if (!curPrinter.getIp().equals(next.printerIP)) {
  321. curPrinter.setIp(next.printerIP);
  322. curPrinter.setCurPrinter(context);
  323. EPLog.w(TAG, "IP printer's IP changed");
  324. }
  325. z = true;
  326. }
  327. }
  328. if (!z) {
  329. MyPrinter.clearCurPrinter(context);
  330. EPLog.w(TAG, "IP printer deleted");
  331. }
  332. }
  333. if (Utils.getPrefInt(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_LOCATION) == 3) {
  334. String prefString = Utils.getPrefString(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_ID);
  335. String prefString2 = Utils.getPrefString(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_IP);
  336. Iterator<EPPrinterInfo> it2 = getIpPrinterList().iterator();
  337. while (true) {
  338. if (!it2.hasNext()) {
  339. z2 = false;
  340. break;
  341. }
  342. EPPrinterInfo next2 = it2.next();
  343. if (prefString.equals(next2.scannerID)) {
  344. if (!prefString2.equals(next2.printerIP)) {
  345. Utils.savePref(context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_IP, next2.printerIP);
  346. EPLog.w(TAG, "IP scanner's IP changed");
  347. }
  348. }
  349. }
  350. if (!z2) {
  351. ScanSettingHelper.saveErroredBlankSettings(context);
  352. EPLog.w(TAG, "IP scanner deleted");
  353. }
  354. }
  355. }
  356. public void rollbackIPPrinterInfo() {
  357. EPLog.i(TAG, "rollbackIPPrinterInfo() called");
  358. ipPrinterList = null;
  359. }
  360. private void serializePrinterInfo(String str, String str2, EPPrinterInfo ePPrinterInfo) {
  361. FileOutputStream fileOutputStream = null;
  362. try {
  363. String path = new File(str, Integer.toString(str2.hashCode())).getPath();
  364. if (ePPrinterInfo.printerLocation == 2) {
  365. StorageSecureStore sharedSecureStore = StorageSecureStore.getSharedSecureStore();
  366. sharedSecureStore.revoke(str2);
  367. if (sharedSecureStore.put(str2, ePPrinterInfo.printerAccessKey)) {
  368. EPLog.i(TAG, "Success: put printerAccessKey. (" + str2 + " = " + ePPrinterInfo.printerAccessKey + ")");
  369. }
  370. ePPrinterInfo.printerAccessKey = "";
  371. }
  372. File file = new File(str);
  373. if (!file.exists()) {
  374. file.mkdirs();
  375. }
  376. FileOutputStream fileOutputStream2 = new FileOutputStream(path);
  377. try {
  378. ePPrinterInfo.writeJSON(fileOutputStream2);
  379. } catch (Exception unused) {
  380. fileOutputStream = fileOutputStream2;
  381. }
  382. } catch (Exception unused2) {
  383. EPLog.m307e(TAG, "savePrinterInfo(): writeObject error.");
  384. if (fileOutputStream != null) {
  385. try {
  386. fileOutputStream.close();
  387. } catch (IOException unused3) {
  388. }
  389. }
  390. }
  391. }
  392. public boolean deleteRemotePrinterInfo(String str) {
  393. ArrayList<EPPrinterInfo> remotePrinterList2 = getRemotePrinterList();
  394. for (int i = 0; i < remotePrinterList2.size(); i++) {
  395. if (remotePrinterList2.get(i).printerEmailAddress.toLowerCase().equals(str.toLowerCase())) {
  396. if (deletedRemotePrinterList == null) {
  397. deletedRemotePrinterList = new ArrayList<>();
  398. }
  399. deletedRemotePrinterList.add(remotePrinterList2.get(i));
  400. remotePrinterList2.remove(i);
  401. return true;
  402. }
  403. }
  404. EPLog.m307e(TAG, "deleteRemotePrinterInfo(): Couldn't delete - " + str.toLowerCase() + CommonDefine.DOT);
  405. return false;
  406. }
  407. public boolean deleteIpPrinterInfo(String str) {
  408. ArrayList<EPPrinterInfo> ipPrinterList2 = getIpPrinterList();
  409. for (int i = 0; i < ipPrinterList2.size(); i++) {
  410. if (ipPrinterList2.get(i).printerID.equals(str)) {
  411. ipPrinterList2.remove(i);
  412. return true;
  413. }
  414. }
  415. EPLog.m307e(TAG, "deleteIpPrinterInfo(): Couldn't delete - " + str + CommonDefine.DOT);
  416. return false;
  417. }
  418. public static void convertV3RemotePrinter(Context context2) {
  419. EPPrinterManager ePPrinterManager = new EPPrinterManager(context2);
  420. ArrayList<EPPrinterInfo> remotePrinterList2 = ePPrinterManager.getRemotePrinterList();
  421. for (int i = 0; i < remotePrinterList2.size(); i++) {
  422. EPPrinterInfo ePPrinterInfo = remotePrinterList2.get(i);
  423. if (ePPrinterInfo.userDefName == null || ePPrinterInfo.userDefName.length() <= 0) {
  424. EpsonConnectAccess.RemotePrinterInfo printerInfo = EpsonConnectAccess.getPrinterInfo(context2, ePPrinterInfo.printerEmailAddress, ePPrinterInfo.printerAccessKey);
  425. if (printerInfo != null) {
  426. ePPrinterInfo.userDefName = ePPrinterInfo.printerName;
  427. ePPrinterInfo.printerName = printerInfo.mDeviceId;
  428. ePPrinterInfo.printerSerialNo = printerInfo.mSerialNumber;
  429. }
  430. remotePrinterList2.set(i, ePPrinterInfo);
  431. }
  432. }
  433. ePPrinterManager.commitRemotePrinterInfo();
  434. }
  435. public static boolean checkV3RemotePrinterData(Context r2) {
  436. throw new UnsupportedOperationException("Method not decompiled: epson.print.EPPrinterManager.checkV3RemotePrinterData(android.content.Context):boolean");
  437. }
  438. }