小爽音 v1.3版本的 MD5 值为:448355de843c720d712f30c7cdfbd99b
以下内容为反编译后的 q.java 源代码,内容仅作参考
package com.alipay.android.phone.mrpc.core;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Proxy;
import android.text.TextUtils;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.NoHttpResponseException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.cookie.Cookie;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
public final class q implements Callable<u> {
private static final HttpRequestRetryHandler f120e = new ad();
public l a;
public Context b;
public o c;
public String f121d;
private HttpUriRequest f122f;
private CookieManager f125i;
private AbstractHttpEntity f126j;
private HttpHost f127k;
private URL f128l;
private String f133q;
private HttpContext f123g = new BasicHttpContext();
private CookieStore f124h = new BasicCookieStore();
private int f129m = 0;
private boolean f130n = false;
private boolean f131o = false;
private String f132p = null;
public q(l lVar, o oVar) {
this.a = lVar;
this.b = lVar.a;
this.c = oVar;
}
private static long a(String[] strArr) {
for (int i2 = 0; i2 < strArr.length; i2++) {
if ("max-age".equalsIgnoreCase(strArr[i2])) {
int i3 = i2 + 1;
if (strArr[i3] != null) {
try {
return Long.parseLong(strArr[i3]);
} catch (Exception unused) {
continue;
}
} else {
continue;
}
}
}
return 0L;
}
private static HttpUrlHeader a(HttpResponse httpResponse) {
Header[] allHeaders;
HttpUrlHeader httpUrlHeader = new HttpUrlHeader();
for (Header header : httpResponse.getAllHeaders()) {
httpUrlHeader.setHead(header.getName(), header.getValue());
}
return httpUrlHeader;
}
private u a(HttpResponse httpResponse, int i2, String str) {
ByteArrayOutputStream byteArrayOutputStream;
String str2;
new StringBuilder("开始handle,handleResponse-1,").append(Thread.currentThread().getId());
HttpEntity entity = httpResponse.getEntity();
ByteArrayOutputStream byteArrayOutputStream2 = null;
String str3 = null;
if (entity == null || httpResponse.getStatusLine().getStatusCode() != 200) {
if (entity == null) {
httpResponse.getStatusLine().getStatusCode();
return null;
}
return null;
}
new StringBuilder("200,开始处理,handleResponse-2,threadid = ").append(Thread.currentThread().getId());
try {
byteArrayOutputStream = new ByteArrayOutputStream();
} catch (Throwable th) {
th = th;
}
try {
long currentTimeMillis = System.currentTimeMillis();
a(entity, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
this.f131o = false;
this.a.c(System.currentTimeMillis() - currentTimeMillis);
this.a.a(byteArray.length);
new StringBuilder("res:").append(byteArray.length);
p pVar = new p(a(httpResponse), i2, str, byteArray);
long b = b(httpResponse);
Header contentType = httpResponse.getEntity().getContentType();
if (contentType != null) {
HashMap<String, String> a = a(contentType.getValue());
str3 = a.get("Content-Type");
str2 = a.get("charset");
} else {
str2 = null;
}
pVar.b(str3);
pVar.a(str2);
pVar.a(System.currentTimeMillis());
pVar.b(b);
try {
byteArrayOutputStream.close();
return pVar;
} catch (IOException e2) {
throw new RuntimeException("ArrayOutputStream close error!", e2.getCause());
}
} catch (Throwable th2) {
th = th2;
byteArrayOutputStream2 = byteArrayOutputStream;
if (byteArrayOutputStream2 != null) {
try {
byteArrayOutputStream2.close();
} catch (IOException e3) {
throw new RuntimeException("ArrayOutputStream close error!", e3.getCause());
}
}
throw th;
}
}
private static HashMap<String, String> a(String str) {
String[] split;
HashMap<String, String> hashMap = new HashMap<>();
for (String str2 : str.split(";")) {
String[] split2 = str2.indexOf(61) == -1 ? new String[]{"Content-Type", str2} : str2.split("=");
hashMap.put(split2[0], split2[1]);
}
return hashMap;
}
private void a(HttpEntity httpEntity, OutputStream outputStream) {
InputStream a = b.a(httpEntity);
long contentLength = httpEntity.getContentLength();
try {
try {
byte[] bArr = new byte[2048];
while (true) {
int read = a.read(bArr);
if (read == -1 || this.c.h()) {
break;
}
outputStream.write(bArr, 0, read);
if (this.c.f() != null) {
int i2 = (contentLength > 0L ? 1 : (contentLength == 0L ? 0 : -1));
}
}
outputStream.flush();
} catch (Exception e2) {
e2.getCause();
throw new IOException("HttpWorker Request Error!" + e2.getLocalizedMessage());
}
} finally {
r.a(a);
}
}
private static long b(HttpResponse httpResponse) {
Header firstHeader = httpResponse.getFirstHeader("Cache-Control");
if (firstHeader != null) {
String[] split = firstHeader.getValue().split("=");
if (split.length >= 2) {
try {
return a(split);
} catch (NumberFormatException unused) {
}
}
}
Header firstHeader2 = httpResponse.getFirstHeader("Expires");
if (firstHeader2 != null) {
return b.b(firstHeader2.getValue()) - System.currentTimeMillis();
}
return 0L;
}
private URI b() {
String a = this.c.a();
String str = this.f121d;
if (str != null) {
a = str;
}
if (a != null) {
return new URI(a);
}
throw new RuntimeException("url should not be null");
}
private HttpUriRequest c() {
HttpUriRequest httpUriRequest = this.f122f;
if (httpUriRequest != null) {
return httpUriRequest;
}
if (this.f126j == null) {
byte[] b = this.c.b();
String b2 = this.c.b("gzip");
if (b != null) {
if (TextUtils.equals(b2, "true")) {
this.f126j = b.a(b);
} else {
this.f126j = new ByteArrayEntity(b);
}
this.f126j.setContentType(this.c.c());
}
}
AbstractHttpEntity abstractHttpEntity = this.f126j;
if (abstractHttpEntity != null) {
HttpPost httpPost = new HttpPost(b());
httpPost.setEntity(abstractHttpEntity);
this.f122f = httpPost;
} else {
this.f122f = new HttpGet(b());
}
return this.f122f;
}
@Override
public u call() {
boolean z;
HttpHost httpHost;
HttpHost httpHost2;
List<Cookie> cookies;
int statusCode;
u a;
String a2;
while (true) {
try {
NetworkInfo[] allNetworkInfo = ((ConnectivityManager) this.b.getSystemService("connectivity")).getAllNetworkInfo();
boolean z2 = true;
if (allNetworkInfo != null) {
for (NetworkInfo networkInfo : allNetworkInfo) {
if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnectedOrConnecting()) {
z = true;
break;
}
}
}
z = false;
if (z) {
ArrayList<Header> d2 = this.c.d();
if (d2 != null && !d2.isEmpty()) {
Iterator<Header> it = d2.iterator();
while (it.hasNext()) {
c().addHeader(it.next());
}
}
b.a((HttpRequest) c());
b.b((HttpRequest) c());
c().addHeader("cookie", i().getCookie(this.c.a()));
this.f123g.setAttribute("http.cookie-store", this.f124h);
this.a.a().a(f120e);
long currentTimeMillis = System.currentTimeMillis();
StringBuilder sb = new StringBuilder("By Http/Https to request. operationType=");
sb.append(f());
sb.append(" url=");
sb.append(this.f122f.getURI().toString());
HttpParams params = this.a.a().getParams();
NetworkInfo activeNetworkInfo = ((ConnectivityManager) this.b.getSystemService("connectivity")).getActiveNetworkInfo();
HttpHost httpHost3 = null;
if (activeNetworkInfo != null && activeNetworkInfo.isAvailable()) {
String defaultHost = Proxy.getDefaultHost();
int defaultPort = Proxy.getDefaultPort();
if (defaultHost != null) {
httpHost = new HttpHost(defaultHost, defaultPort);
if (httpHost != null || !TextUtils.equals(httpHost.getHostName(), "127.0.0.1") || httpHost.getPort() != 8087) {
httpHost3 = httpHost;
}
params.setParameter("http.route.default-proxy", httpHost3);
httpHost2 = this.f127k;
if (httpHost2 != null) {
URL h2 = h();
HttpHost httpHost4 = new HttpHost(h2.getHost(), g(), h2.getProtocol());
this.f127k = httpHost4;
httpHost2 = httpHost4;
}
if (g() == 80) {
httpHost2 = new HttpHost(h().getHost());
}
HttpResponse execute = this.a.a().execute(httpHost2, (HttpRequest) this.f122f, this.f123g);
this.a.b(System.currentTimeMillis() - currentTimeMillis);
cookies = this.f124h.getCookies();
if (this.c.e()) {
i().removeAllCookie();
}
if (!cookies.isEmpty()) {
for (Cookie cookie : cookies) {
if (cookie.getDomain() != null) {
StringBuilder sb2 = new StringBuilder();
sb2.append(cookie.getName());
sb2.append("=");
sb2.append(cookie.getValue());
sb2.append("; domain=");
sb2.append(cookie.getDomain());
sb2.append(cookie.isSecure() ? "; Secure" : "");
i().setCookie(this.c.a(), sb2.toString());
CookieSyncManager.getInstance().sync();
}
}
}
statusCode = execute.getStatusLine().getStatusCode();
String reasonPhrase = execute.getStatusLine().getReasonPhrase();
if (statusCode != 200) {
if (statusCode != 304) {
z2 = false;
}
if (!z2) {
throw new HttpException(Integer.valueOf(execute.getStatusLine().getStatusCode()), execute.getStatusLine().getReasonPhrase());
}
}
a = a(execute, statusCode, reasonPhrase);
if (((a != null || a.b() == null) ? -1L : a.b().length) == -1 && (a instanceof p)) {
try {
Long.parseLong(((p) a).a().getHead("Content-Length"));
} catch (Exception unused) {
}
}
a2 = this.c.a();
if (a2 != null && !TextUtils.isEmpty(f())) {
StringBuilder sb3 = new StringBuilder();
sb3.append(a2);
sb3.append("#");
sb3.append(f());
}
return a;
}
}
httpHost = null;
if (httpHost != null) {
}
httpHost3 = httpHost;
params.setParameter("http.route.default-proxy", httpHost3);
httpHost2 = this.f127k;
if (httpHost2 != null) {
}
if (g() == 80) {
}
HttpResponse execute2 = this.a.a().execute(httpHost2, (HttpRequest) this.f122f, this.f123g);
this.a.b(System.currentTimeMillis() - currentTimeMillis);
cookies = this.f124h.getCookies();
if (this.c.e()) {
}
if (!cookies.isEmpty()) {
}
statusCode = execute2.getStatusLine().getStatusCode();
String reasonPhrase2 = execute2.getStatusLine().getReasonPhrase();
if (statusCode != 200) {
}
a = a(execute2, statusCode, reasonPhrase2);
if (((a != null || a.b() == null) ? -1L : a.b().length) == -1) {
Long.parseLong(((p) a).a().getHead("Content-Length"));
}
a2 = this.c.a();
if (a2 != null) {
StringBuilder sb32 = new StringBuilder();
sb32.append(a2);
sb32.append("#");
sb32.append(f());
}
return a;
}
throw new HttpException(1, "The network is not available");
} catch (IOException e2) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e2);
}
new StringBuilder().append(e2);
throw new HttpException(6, String.valueOf(e2));
} catch (NoHttpResponseException e3) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e3);
}
new StringBuilder().append(e3);
throw new HttpException(5, String.valueOf(e3));
} catch (HttpException e4) {
e();
if (this.c.f() != null) {
e4.getCode();
e4.getMsg();
}
new StringBuilder().append(e4);
throw e4;
} catch (NullPointerException e5) {
e();
int i2 = this.f129m;
if (i2 > 0) {
new StringBuilder().append(e5);
throw new HttpException(0, String.valueOf(e5));
}
this.f129m = i2 + 1;
} catch (SocketTimeoutException e6) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e6);
}
new StringBuilder().append(e6);
throw new HttpException(4, String.valueOf(e6));
} catch (URISyntaxException e7) {
throw new RuntimeException("Url parser error!", e7.getCause());
} catch (UnknownHostException e8) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e8);
}
new StringBuilder().append(e8);
throw new HttpException(9, String.valueOf(e8));
} catch (SSLException e9) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e9);
}
new StringBuilder().append(e9);
throw new HttpException(6, String.valueOf(e9));
} catch (HttpHostConnectException e10) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e10);
}
throw new HttpException(8, String.valueOf(e10));
} catch (SSLHandshakeException e11) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e11);
}
new StringBuilder().append(e11);
throw new HttpException(2, String.valueOf(e11));
} catch (ConnectTimeoutException e12) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e12);
}
new StringBuilder().append(e12);
throw new HttpException(3, String.valueOf(e12));
} catch (Exception e13) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e13);
}
throw new HttpException(0, String.valueOf(e13));
} catch (ConnectionPoolTimeoutException e14) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e14);
}
new StringBuilder().append(e14);
throw new HttpException(3, String.valueOf(e14));
} catch (SSLPeerUnverifiedException e15) {
e();
if (this.c.f() != null) {
new StringBuilder().append(e15);
}
new StringBuilder().append(e15);
throw new HttpException(2, String.valueOf(e15));
}
}
}
private void e() {
HttpUriRequest httpUriRequest = this.f122f;
if (httpUriRequest != null) {
httpUriRequest.abort();
}
}
private String f() {
if (TextUtils.isEmpty(this.f133q)) {
String b = this.c.b("operationType");
this.f133q = b;
return b;
}
return this.f133q;
}
private int g() {
URL h2 = h();
return h2.getPort() == -1 ? h2.getDefaultPort() : h2.getPort();
}
private URL h() {
URL url = this.f128l;
if (url != null) {
return url;
}
URL url2 = new URL(this.c.a());
this.f128l = url2;
return url2;
}
private CookieManager i() {
CookieManager cookieManager = this.f125i;
if (cookieManager != null) {
return cookieManager;
}
CookieManager cookieManager2 = CookieManager.getInstance();
this.f125i = cookieManager2;
return cookieManager2;
}
public final o a() {
return this.c;
}
}