InkReplenishSystem.java 11 KB

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