GoEpsonClient.java 6.6 KB

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