360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0
以下内容为反编译后的 NetworkDetectHelper.java 源代码,内容仅作参考
package com.qihoo.speedometer;
import android.content.Context;
import android.text.TextUtils;
import android.util.Pair;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
import com.android.internal.http.multipart.StringPart;
import com.qihoo.appstore.AppStoreApplication;
import com.qihoo.appstore.j.a;
import com.qihoo.appstore.utils.bk;
import com.qihoo.appstore.utils.dc;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.util.EncodingUtils;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
public class NetworkDetectHelper {
static long lastUploadTime;
public static String a() {
return dc.d ? "http://test1.baohe.mobilem.360.cn/feedback/upload?" : "http://update.mobilem.360.cn/feedback/upload?";
}
public static String a(Context context, String str, HashMap hashMap, HashMap hashMap2) {
String entityUtils;
ArrayList arrayList = new ArrayList();
if (hashMap != null) {
for (String str2 : hashMap.keySet()) {
arrayList.add(new StringPart(str2, (String) hashMap.get(str2), "UTF-8"));
}
}
if (hashMap2 != null) {
for (String str3 : hashMap2.keySet()) {
File file = (File) hashMap2.get(str3);
if (file.exists() && file.isFile()) {
try {
arrayList.add(new FilePart(str3, String.format("%s_%s", Long.valueOf(System.currentTimeMillis()), file.getName()), file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
a a2 = a.a(System.getProperty("http.agent"), context);
try {
HttpPost httpPost = new HttpPost(str);
httpPost.setEntity(new MultipartEntity((Part[]) arrayList.toArray(new Part[arrayList.size()])) {
@Override
protected byte[] getMultipartBoundary() {
return EncodingUtils.getAsciiBytes("--" + EncodingUtils.getAsciiString(super.getMultipartBoundary()));
}
});
HttpResponse execute = a2.execute(httpPost);
int statusCode = execute.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new ClientProtocolException("The status code of http is not SC_OK(200):" + statusCode + ",\r\n\turl=" + str);
}
if (execute.getEntity() == null) {
entityUtils = null;
} else {
entityUtils = EntityUtils.toString(execute.getEntity(), "UTF-8");
}
} finally {
if (a2 != null) {
a2.a();
}
}
}
public static void a(final Context context) {
if (System.currentTimeMillis() - lastUploadTime < Config.PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC) {
return;
}
lastUploadTime = System.currentTimeMillis();
if (!TextUtils.isEmpty(FileLogger.e())) {
AppStoreApplication.a(new Runnable() {
@Override
public void run() {
try {
NetworkDetectHelper.b(context);
} catch (Exception e) {
}
}
});
} else if (com.qihoo360.mobilesafe.a.a.f5313a) {
bk.b("uploadLog", "Filename is empty");
}
}
static boolean a(Context context, File file, File file2, final String str) {
BufferedInputStream bufferedInputStream;
ZipOutputStream zipOutputStream = null;
boolean z = false;
ZipOutputStream zipOutputStream2 = null;
try {
try {
if (file2.exists()) {
file2.delete();
}
File[] listFiles = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file3, String str2) {
File file4 = new File(file3, str2);
return str.contains(str2) && file4.exists() && file4.isFile() && file4.length() > 0 && str2 != null && str2.endsWith(".network.log");
}
});
if (listFiles != null && listFiles.length > 0) {
ZipOutputStream zipOutputStream3 = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file2), 8192));
try {
for (File file3 : listFiles) {
ZipEntry zipEntry = new ZipEntry(file3.getName());
zipEntry.setSize(file3.length());
zipEntry.setTime(file3.lastModified());
zipOutputStream3.putNextEntry(zipEntry);
try {
bufferedInputStream = new BufferedInputStream(new FileInputStream(file3));
try {
byte[] bArr = new byte[8192];
while (true) {
int read = bufferedInputStream.read(bArr, 0, bArr.length);
if (read == -1) {
break;
}
zipOutputStream3.write(bArr, 0, read);
}
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
} catch (Throwable th) {
th = th;
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
throw th;
}
} catch (Throwable th2) {
th = th2;
bufferedInputStream = null;
}
}
z = true;
if (zipOutputStream3 != null) {
try {
zipOutputStream3.close();
} catch (IOException e) {
e = e;
e.printStackTrace();
return z;
}
}
} catch (Exception e2) {
e = e2;
zipOutputStream = zipOutputStream3;
e.printStackTrace();
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e3) {
e = e3;
e.printStackTrace();
return z;
}
}
return z;
} catch (Throwable th3) {
th = th3;
zipOutputStream = zipOutputStream3;
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
throw th;
}
} else if (0 != 0) {
try {
zipOutputStream2.close();
} catch (IOException e5) {
e = e5;
e.printStackTrace();
return z;
}
}
} catch (Exception e6) {
e = e6;
}
return z;
} catch (Throwable th4) {
th = th4;
}
}
private static boolean a(File file, String str) {
File[] listFiles = file.listFiles();
if (listFiles == null || listFiles.length <= 0) {
return false;
}
for (File file2 : listFiles) {
if (file2.getPath().endsWith(str)) {
file2.delete();
}
}
return true;
}
public static Pair b(Context context) {
?? r1;
JSONObject jSONObject;
Pair pair;
boolean z = false;
r2 = 0;
r2 = 0;
r2 = 0;
r2 = 0;
r2 = 0;
r2 = 0;
r2 = 0;
r2 = 0;
?? r2 = 0;
if (TextUtils.isEmpty(FileLogger.e())) {
return new Pair(true, null);
}
?? file = new File(FileLogger.a());
?? file2 = new File((File) file, "NetworkLog.zip");
try {
if (file.exists() && file.isDirectory() && a(context, (File) file, (File) file2, FileLogger.e())) {
HashMap hashMap = new HashMap();
hashMap.put("log", file2);
try {
try {
String a2 = a(context, String.format(a() + "mid=%s&ver=bh_%s", dc.L(), Integer.valueOf(com.qihoo.express.mini.c.a.a().j())), (HashMap) null, hashMap);
if (com.qihoo360.mobilesafe.a.a.f5313a) {
bk.b("BugReportActivity", "Upload crash log success! re=" + a2);
}
jSONObject = new JSONObject(a2);
r1 = jSONObject.getInt("errno") != 0 ? 0 : 1;
} catch (Throwable th) {
th = th;
z = true;
try {
if (z) {
a(file, ".network.log");
bk.e("BugReportActivity", "rename log : " + file2.renameTo(new File((File) file, new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date(System.currentTimeMillis())) + ".NetworkLog.zip.bak")));
FileLogger.f();
} else if (file2.exists()) {
file2.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
throw th;
}
} catch (IOException e2) {
e = e2;
r1 = 0;
} catch (Exception e3) {
r1 = 0;
}
try {
if (r1 == 0) {
pair = new Pair(false, null);
try {
if (r1 != 0) {
a(file, ".network.log");
boolean renameTo = file2.renameTo(new File((File) file, new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date(System.currentTimeMillis())) + ".NetworkLog.zip.bak"));
StringBuilder append = new StringBuilder().append("rename log : ");
String sb = append.append(renameTo).toString();
bk.e("BugReportActivity", sb);
FileLogger.f();
r1 = sb;
r2 = "BugReportActivity";
file = append;
file2 = "rename log : ";
} else {
boolean exists = file2.exists();
r1 = exists;
file = file;
file2 = file2;
if (exists) {
file2.delete();
r1 = exists;
file = file;
file2 = file2;
}
}
} catch (Exception e4) {
e = e4;
e.printStackTrace();
return pair;
}
} else {
pair = new Pair(true, jSONObject.getString("feedbackid"));
if (r1 != 0) {
try {
a(file, ".network.log");
try {
try {
try {
try {
try {
try {
try {
try {
try {
try {
try {
try {
try {
try {
boolean renameTo2 = file2.renameTo(new File((File) file, new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date(System.currentTimeMillis())) + ".NetworkLog.zip.bak"));
r2 = "BugReportActivity";
try {
try {
file2 = "rename log : ";
try {
file = new StringBuilder().append("rename log : ");
try {
try {
r1 = file.append(renameTo2).toString();
try {
bk.e("BugReportActivity", r1);
} catch (Exception e5) {
e = e5;
}
try {
FileLogger.f();
} catch (Exception e6) {
e = e6;
e.printStackTrace();
return pair;
}
} catch (Exception e7) {
e = e7;
}
} catch (Exception e8) {
e = e8;
}
} catch (Exception e9) {
e = e9;
}
} catch (Exception e10) {
e = e10;
}
} catch (Exception e11) {
e = e11;
}
} catch (Exception e12) {
e = e12;
}
} catch (Exception e13) {
e = e13;
}
} catch (Exception e14) {
e = e14;
}
} catch (Exception e15) {
e = e15;
}
} catch (Exception e16) {
e = e16;
}
} catch (Exception e17) {
e = e17;
}
} catch (Exception e18) {
e = e18;
}
} catch (Exception e19) {
e = e19;
}
} catch (Exception e20) {
e = e20;
}
} catch (Exception e21) {
e = e21;
}
} catch (Exception e22) {
e = e22;
}
} catch (Exception e23) {
e = e23;
}
} catch (Exception e24) {
e = e24;
}
} catch (Exception e25) {
e = e25;
}
} catch (Exception e26) {
e = e26;
}
} else {
try {
r1 = file2.exists();
if (r1 != 0) {
try {
file2.delete();
} catch (Exception e27) {
e = e27;
e.printStackTrace();
return pair;
}
}
} catch (Exception e28) {
e = e28;
}
}
}
return pair;
} catch (IOException e29) {
e = e29;
bk.d("BugReportActivity", "Upload crash log fail", e);
if (r1 == 0) {
}
return new Pair(Boolean.valueOf((boolean) r2), null);
} catch (Exception e30) {
}
} else {
r1 = 0;
}
try {
if (r1 == 0) {
a(file, ".network.log");
bk.e("BugReportActivity", "rename log : " + file2.renameTo(new File((File) file, new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date(System.currentTimeMillis())) + ".NetworkLog.zip.bak")));
FileLogger.f();
} else if (file2.exists()) {
file2.delete();
}
} catch (Exception e31) {
e31.printStackTrace();
}
return new Pair(Boolean.valueOf((boolean) r2), null);
} catch (Throwable th2) {
th = th2;
}
}
public static String b() {
Exception exc;
String str;
String str2;
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://update.mobilem.360.cn/index/client").openConnection();
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[1024];
StringBuffer stringBuffer = new StringBuffer();
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
stringBuffer.append(new String(bArr, 0, read));
}
str2 = (String) new JSONObject(stringBuffer.toString()).opt("ip");
try {
inputStream.close();
} catch (Exception e) {
str = str2;
exc = e;
exc.printStackTrace();
return str;
}
} else {
str2 = null;
}
httpURLConnection.disconnect();
return str2;
} catch (Exception e2) {
exc = e2;
str = null;
}
}
}