InkReplenishSystem.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package epson.print.inkrpln;
  2. import android.content.Context;
  3. import android.net.Uri;
  4. import android.os.Build;
  5. import android.support.annotation.NonNull;
  6. import android.support.annotation.Nullable;
  7. import android.util.Base64;
  8. import com.epson.mobilephone.common.escpr.EPS_REDYINKINFO;
  9. import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
  10. import epson.common.Utils;
  11. import epson.print.R;
  12. import epson.print.inkrpln.GoEpsonClient;
  13. import epson.print.inkrpln.InkRplnInfoClient;
  14. import java.io.IOException;
  15. import java.nio.charset.Charset;
  16. import java.util.Arrays;
  17. import java.util.Locale;
  18. import org.apache.commons.lang.CharEncoding;
  19. public class InkReplenishSystem {
  20. private static InkReplenishSystem sInkReplenishSystem;
  21. private GoEpsonClient mGoEpsonClient;
  22. private InkRplnInfoClient mInkRsInfoClient;
  23. private InkRplnRepository mIrsRepository;
  24. private PrinterAdapter mPrinterAdapter;
  25. @VisibleForTesting
  26. InkReplenishSystem(PrinterAdapter printerAdapter, InkRplnRepository inkRplnRepository, GoEpsonClient goEpsonClient, InkRplnInfoClient inkRplnInfoClient) {
  27. this.mPrinterAdapter = printerAdapter;
  28. this.mIrsRepository = inkRplnRepository;
  29. this.mGoEpsonClient = goEpsonClient;
  30. this.mInkRsInfoClient = inkRplnInfoClient;
  31. }
  32. public InkReplenishSystem(PrinterAdapter printerAdapter, InkRplnRepository inkRplnRepository) {
  33. this.mPrinterAdapter = printerAdapter;
  34. this.mIrsRepository = inkRplnRepository;
  35. this.mGoEpsonClient = new GoEpsonClient();
  36. this.mInkRsInfoClient = new InkRplnInfoClient();
  37. }
  38. /* access modifiers changed from: package-private */
  39. @VisibleForTesting
  40. @NonNull
  41. public GoEpsonClient.ReadyInkParams getGoEpsonParams(@NonNull Context context) {
  42. GoEpsonClient.ReadyInkParams readyInkParams = new GoEpsonClient.ReadyInkParams();
  43. Locale locale = Locale.getDefault();
  44. readyInkParams.country = locale.getCountry();
  45. readyInkParams.language = locale.getLanguage();
  46. readyInkParams.printerSerial = this.mPrinterAdapter.getSerialNo(context);
  47. readyInkParams.printerName = this.mPrinterAdapter.getNonRemotePrinterDeviceId(context);
  48. readyInkParams.androidModel = Build.MODEL;
  49. return readyInkParams;
  50. }
  51. public synchronized boolean tryRecordPrinterInfoFromServer(@NonNull Context context) throws IOException {
  52. clearServerReplyPrinterInfo(context);
  53. if (!isInSupportedArea()) {
  54. return false;
  55. }
  56. if (!checkPrinterAndNetworkConnectivity(context)) {
  57. return false;
  58. }
  59. String serialNo = this.mPrinterAdapter.getSerialNo(context);
  60. if (serialNo == null) {
  61. return false;
  62. }
  63. EPS_REDYINKINFO readyInkInfo = this.mPrinterAdapter.getReadyInkInfo();
  64. if (readyInkInfo == null) {
  65. return false;
  66. }
  67. if (readyInkInfo.subscriptionStatus != 0) {
  68. this.mIrsRepository.saveBuyInkButtonOffReadyInkOff(context);
  69. return false;
  70. }
  71. String redirectLocation = this.mGoEpsonClient.getRedirectLocation(getGoEpsonParams(context), useGoEpsonTls(context));
  72. this.mIrsRepository.saveInkReplenishServerUrl(context, redirectLocation);
  73. if (redirectLocation == null) {
  74. return false;
  75. }
  76. this.mPrinterAdapter.activateEma(readyInkInfo);
  77. InkRplnInfoClient.InkRsInfo inkDsInfo = this.mInkRsInfoClient.getInkDsInfo(serialNo, redirectLocation);
  78. if (inkDsInfo == null) {
  79. return false;
  80. }
  81. this.mIrsRepository.saveData(context, inkDsInfo);
  82. return true;
  83. }
  84. /* access modifiers changed from: package-private */
  85. @VisibleForTesting
  86. public boolean checkPrinterAndNetworkConnectivity(@NonNull Context context) {
  87. if (Utils.isConnectedWifi(context) && !WiFiDirectManager.isSimpleAP(context) && Utils.isOnline(context) && !this.mPrinterAdapter.isRemotePrinter(context)) {
  88. return true;
  89. }
  90. return false;
  91. }
  92. public synchronized void clearServerReplyPrinterInfo(Context context) {
  93. this.mIrsRepository.clearServerData(context);
  94. }
  95. /* JADX WARNING: Code restructure failed: missing block: B:14:0x001c, code lost:
  96. return r1;
  97. */
  98. /* Code decompiled incorrectly, please refer to instructions dump. */
  99. public synchronized boolean needsDisplayInvitationDialog(@android.support.annotation.NonNull android.content.Context r3) {
  100. /*
  101. r2 = this;
  102. monitor-enter(r2)
  103. epson.print.inkrpln.InkRplnRepository r0 = r2.mIrsRepository // Catch:{ all -> 0x001d }
  104. boolean r0 = r0.getInvitationDialogDisabledValue(r3) // Catch:{ all -> 0x001d }
  105. r1 = 0
  106. if (r0 == 0) goto L_0x000c
  107. monitor-exit(r2)
  108. return r1
  109. L_0x000c:
  110. epson.print.inkrpln.InkRplnRepository r0 = r2.mIrsRepository // Catch:{ all -> 0x001d }
  111. epson.print.inkrpln.InkRplnInfoClient$InkRsInfo r3 = r0.getInfo(r3) // Catch:{ all -> 0x001d }
  112. if (r3 == 0) goto L_0x001b
  113. boolean r3 = r3.needToDisplayInvitationDialog() // Catch:{ all -> 0x001d }
  114. if (r3 == 0) goto L_0x001b
  115. r1 = 1
  116. L_0x001b:
  117. monitor-exit(r2)
  118. return r1
  119. L_0x001d:
  120. r3 = move-exception
  121. monitor-exit(r2)
  122. throw r3
  123. */
  124. throw new UnsupportedOperationException("Method not decompiled: epson.print.inkrpln.InkReplenishSystem.needsDisplayInvitationDialog(android.content.Context):boolean");
  125. }
  126. public synchronized void setServerCheckDisabled(@NonNull Context context) {
  127. this.mIrsRepository.saveInvitationDialogDisableValue(context, true);
  128. }
  129. /* JADX WARNING: Code restructure failed: missing block: B:24:0x0035, code lost:
  130. return null;
  131. */
  132. @android.support.annotation.Nullable
  133. /* Code decompiled incorrectly, please refer to instructions dump. */
  134. public synchronized android.net.Uri refreshReplenInfoAndGetJumpUrl(@android.support.annotation.NonNull android.content.Context r5) {
  135. /*
  136. r4 = this;
  137. monitor-enter(r4)
  138. epson.print.inkrpln.InkRplnRepository r0 = r4.mIrsRepository // Catch:{ all -> 0x0038 }
  139. java.lang.String r0 = r0.getInkReplenishServerUrl(r5) // Catch:{ all -> 0x0038 }
  140. r1 = 0
  141. if (r0 != 0) goto L_0x000c
  142. monitor-exit(r4)
  143. return r1
  144. L_0x000c:
  145. epson.print.inkrpln.PrinterAdapter r2 = r4.mPrinterAdapter // Catch:{ all -> 0x0038 }
  146. java.lang.String r2 = r2.getSerialNo(r5) // Catch:{ all -> 0x0038 }
  147. epson.print.inkrpln.InkRplnInfoClient r3 = r4.mInkRsInfoClient // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  148. epson.print.inkrpln.InkRplnInfoClient$InkRsInfo r0 = r3.getInkDsInfo(r2, r0) // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  149. if (r0 == 0) goto L_0x0034
  150. java.lang.String r3 = r0.landingUrl // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  151. if (r3 == 0) goto L_0x0034
  152. if (r2 != 0) goto L_0x0021
  153. goto L_0x0034
  154. L_0x0021:
  155. epson.print.inkrpln.InkRplnRepository r3 = r4.mIrsRepository // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  156. r3.saveData(r5, r0) // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  157. java.lang.String r5 = r0.landingUrl // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  158. boolean r0 = r0.appendSerial // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  159. if (r0 == 0) goto L_0x002d
  160. goto L_0x002e
  161. L_0x002d:
  162. r2 = r1
  163. L_0x002e:
  164. android.net.Uri r5 = r4.getReadyInkUri(r5, r2) // Catch:{ IOException | IllegalArgumentException -> 0x0036 }
  165. monitor-exit(r4)
  166. return r5
  167. L_0x0034:
  168. monitor-exit(r4)
  169. return r1
  170. L_0x0036:
  171. monitor-exit(r4)
  172. return r1
  173. L_0x0038:
  174. r5 = move-exception
  175. monitor-exit(r4)
  176. throw r5
  177. */
  178. throw new UnsupportedOperationException("Method not decompiled: epson.print.inkrpln.InkReplenishSystem.refreshReplenInfoAndGetJumpUrl(android.content.Context):android.net.Uri");
  179. }
  180. /* JADX WARNING: Code restructure failed: missing block: B:15:0x0024, code lost:
  181. return null;
  182. */
  183. @android.support.annotation.Nullable
  184. /* Code decompiled incorrectly, please refer to instructions dump. */
  185. public synchronized android.net.Uri getReadyInkUriFromSavedData(@android.support.annotation.NonNull android.content.Context r4) {
  186. /*
  187. r3 = this;
  188. monitor-enter(r3)
  189. epson.print.inkrpln.InkRplnRepository r0 = r3.mIrsRepository // Catch:{ all -> 0x0025 }
  190. epson.print.inkrpln.InkRplnInfoClient$InkRsInfo r0 = r0.getInfo(r4) // Catch:{ all -> 0x0025 }
  191. r1 = 0
  192. if (r0 == 0) goto L_0x0023
  193. java.lang.String r2 = r0.landingUrl // Catch:{ all -> 0x0025 }
  194. if (r2 != 0) goto L_0x000f
  195. goto L_0x0023
  196. L_0x000f:
  197. epson.print.inkrpln.PrinterAdapter r2 = r3.mPrinterAdapter // Catch:{ all -> 0x0025 }
  198. java.lang.String r4 = r2.getSerialNo(r4) // Catch:{ all -> 0x0025 }
  199. java.lang.String r2 = r0.landingUrl // Catch:{ all -> 0x0025 }
  200. boolean r0 = r0.appendSerial // Catch:{ all -> 0x0025 }
  201. if (r0 == 0) goto L_0x001c
  202. goto L_0x001d
  203. L_0x001c:
  204. r4 = r1
  205. L_0x001d:
  206. android.net.Uri r4 = r3.getReadyInkUri(r2, r4) // Catch:{ all -> 0x0025 }
  207. monitor-exit(r3)
  208. return r4
  209. L_0x0023:
  210. monitor-exit(r3)
  211. return r1
  212. L_0x0025:
  213. r4 = move-exception
  214. monitor-exit(r3)
  215. throw r4
  216. */
  217. throw new UnsupportedOperationException("Method not decompiled: epson.print.inkrpln.InkReplenishSystem.getReadyInkUriFromSavedData(android.content.Context):android.net.Uri");
  218. }
  219. /* access modifiers changed from: package-private */
  220. @VisibleForTesting
  221. public Uri getReadyInkUri(@NonNull String str, @Nullable String str2) {
  222. Uri.Builder buildUpon = Uri.parse(str).buildUpon();
  223. if (str2 != null) {
  224. buildUpon.appendQueryParameter("sn", encodePrinterSerial(str2));
  225. }
  226. return buildUpon.build();
  227. }
  228. @NonNull
  229. static String encodePrinterSerial(@NonNull String str) {
  230. return Base64.encodeToString(str.getBytes(Charset.forName(CharEncoding.US_ASCII)), 2);
  231. }
  232. public boolean isInSupportedArea() {
  233. return isSupportedCountry(Locale.getDefault().getCountry());
  234. }
  235. /* access modifiers changed from: package-private */
  236. @VisibleForTesting
  237. public boolean isSupportedCountry(String str) {
  238. return Arrays.asList(new String[]{Locale.US.getCountry(), Locale.CANADA.getCountry(), Locale.UK.getCountry(), Locale.FRANCE.getCountry(), Locale.ITALY.getCountry(), Locale.GERMANY.getCountry(), "ES", "PT", "NL", "CZ", "DK", "FI", "NO", "PL", "SE", "AT", "BE", "IE", "CH"}).contains(str);
  239. }
  240. static boolean isInkReplenishSystemEnabled(@NonNull Context context) {
  241. return context.getResources().getBoolean(R.bool.ink_replenish_system_enabled);
  242. }
  243. static boolean useGoEpsonTls(@NonNull Context context) {
  244. return context.getResources().getBoolean(R.bool.ink_replen_go_epson_use_tls);
  245. }
  246. }