GoEpsonClient.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package epson.print.inkrpln;
  2. import android.net.Uri;
  3. import com.epson.iprint.prtlogger.Analytics;
  4. import epson.print.CommonDefine;
  5. import epson.print.IprintApplication;
  6. import java.io.IOException;
  7. import java.net.HttpURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import javax.net.ssl.HttpsURLConnection;
  11. public class GoEpsonClient {
  12. private static final int CONNECTION_TIMEOUT = 10000;
  13. private static final String ERROR_HOST_NAME = "www.epson.com";
  14. private static final int READ_TIMEOUT = 10000;
  15. public static class ReadyInkParams {
  16. public String androidModel;
  17. public String country;
  18. public String ctc;
  19. public String language;
  20. public String printerName;
  21. public String printerSerial;
  22. }
  23. public String getRedirectLocation(@NonNull ReadyInkParams readyInkParams, boolean z) {
  24. try {
  25. String goEpsonRedirectLocation = getGoEpsonRedirectLocation(new URL(makeUrl(readyInkParams, z)));
  26. if (checkGoEpsonResultUrl(goEpsonRedirectLocation)) {
  27. return goEpsonRedirectLocation;
  28. }
  29. return null;
  30. } catch (MalformedURLException unused) {
  31. return null;
  32. }
  33. }
  34. /* access modifiers changed from: package-private */
  35. @VisibleForTesting
  36. public boolean checkGoEpsonResultUrl(String str) {
  37. if (str == null) {
  38. return false;
  39. }
  40. try {
  41. URL url = new URL(str);
  42. if (!ERROR_HOST_NAME.equals(url.getHost())) {
  43. return true;
  44. }
  45. if (CommonDefine.SLASH.equals(url.getPath()) || url.getPath().length() <= 0) {
  46. return false;
  47. }
  48. return true;
  49. } catch (MalformedURLException unused) {
  50. return false;
  51. }
  52. }
  53. public String makeUrl(@NonNull ReadyInkParams readyInkParams, boolean z) {
  54. Uri.Builder builder = new Uri.Builder();
  55. builder.scheme(z ? "https" : Analytics.EXTENSION_STRING_WEB);
  56. builder.encodedAuthority(getServerAndPortString());
  57. builder.path("redirect.aspx");
  58. if (readyInkParams.language != null) {
  59. builder.appendQueryParameter("LG2", readyInkParams.language);
  60. }
  61. if (readyInkParams.country != null) {
  62. builder.appendQueryParameter("CN2", readyInkParams.country);
  63. }
  64. builder.appendQueryParameter("CTC", "ReadyInkInvitation");
  65. if (readyInkParams.printerName != null) {
  66. builder.appendQueryParameter("PRN", goEpsonEncodeString(readyInkParams.printerName));
  67. }
  68. builder.appendQueryParameter("OSC", CommonDefine.ARD);
  69. builder.appendQueryParameter("OSV", "ARDAPI_1.0.26");
  70. if (readyInkParams.androidModel != null) {
  71. builder.appendQueryParameter("OATR", goEpsonEncodeString(readyInkParams.androidModel));
  72. }
  73. if (readyInkParams.printerSerial != null && readyInkParams.printerSerial.length() >= 4) {
  74. builder.appendQueryParameter("SID", readyInkParams.printerSerial.substring(0, 4));
  75. }
  76. return builder.build().toString();
  77. }
  78. /* access modifiers changed from: protected */
  79. @VisibleForTesting
  80. public String getServerAndPortString() {
  81. return IprintApplication.getInstance().getGoEpsonServerName();
  82. }
  83. @NonNull
  84. private static String goEpsonEncodeString(@NonNull String str) {
  85. return str.replace(" ", CommonDefine.UNDER_BAR);
  86. }
  87. /* access modifiers changed from: package-private */
  88. /* JADX WARNING: Removed duplicated region for block: B:21:0x003d */
  89. /* JADX WARNING: Removed duplicated region for block: B:26:0x0044 */
  90. @android.support.annotation.Nullable
  91. @android.support.annotation.VisibleForTesting
  92. /* Code decompiled incorrectly, please refer to instructions dump. */
  93. public java.lang.String getGoEpsonRedirectLocation(@android.support.annotation.NonNull java.net.URL r4) {
  94. /*
  95. r3 = this;
  96. r0 = 0
  97. java.net.HttpURLConnection r4 = r3.getGoEpsonConnection(r4) // Catch:{ IOException | IllegalArgumentException -> 0x0041, all -> 0x0037 }
  98. r1 = 10000(0x2710, float:1.4013E-41)
  99. r4.setReadTimeout(r1) // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  100. r4.setConnectTimeout(r1) // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  101. r1 = 0
  102. r4.setInstanceFollowRedirects(r1) // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  103. java.lang.String r1 = "GET"
  104. r4.setRequestMethod(r1) // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  105. r4.connect() // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  106. int r1 = r4.getResponseCode() // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  107. switch(r1) {
  108. case 301: goto L_0x0026;
  109. case 302: goto L_0x0026;
  110. default: goto L_0x0020;
  111. }
  112. L_0x0020:
  113. if (r4 == 0) goto L_0x0032
  114. r4.disconnect()
  115. goto L_0x0032
  116. L_0x0026:
  117. java.lang.String r1 = "Location"
  118. java.lang.String r0 = r4.getHeaderField(r1) // Catch:{ IOException | IllegalArgumentException -> 0x0035, all -> 0x0033 }
  119. if (r4 == 0) goto L_0x0031
  120. r4.disconnect()
  121. L_0x0031:
  122. return r0
  123. L_0x0032:
  124. return r0
  125. L_0x0033:
  126. r0 = move-exception
  127. goto L_0x003b
  128. L_0x0035:
  129. goto L_0x0042
  130. L_0x0037:
  131. r4 = move-exception
  132. r2 = r0
  133. r0 = r4
  134. r4 = r2
  135. L_0x003b:
  136. if (r4 == 0) goto L_0x0040
  137. r4.disconnect()
  138. L_0x0040:
  139. throw r0
  140. L_0x0041:
  141. r4 = r0
  142. L_0x0042:
  143. if (r4 == 0) goto L_0x0047
  144. r4.disconnect()
  145. L_0x0047:
  146. return r0
  147. */
  148. throw new UnsupportedOperationException("Method not decompiled: epson.print.inkrpln.GoEpsonClient.getGoEpsonRedirectLocation(java.net.URL):java.lang.String");
  149. }
  150. private HttpURLConnection getGoEpsonConnection(@NonNull URL url) throws IOException {
  151. HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
  152. httpsURLConnection.setSSLSocketFactory(new LocalSSLSocketFactory(httpsURLConnection.getSSLSocketFactory()));
  153. return httpsURLConnection;
  154. }
  155. }