|
@@ -36,19 +36,17 @@ public class ApkServiceImpl implements ApkService {
|
|
|
try {
|
|
|
apkInfo = new ApkUtil().getApkInfo(apkPath);
|
|
|
} catch (Exception e) {
|
|
|
- throw new ApkParseException("APK 解析失败");
|
|
|
+ throw new ApkParseException(e.getMessage());
|
|
|
}
|
|
|
return apkInfo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String downloadApk(String downloadUrl, String traceId) {
|
|
|
- if (!downloadUrl.endsWith(".apk")){
|
|
|
+ if (!verifyDownloadUrl(downloadUrl)){
|
|
|
throw new ApkDownloadException("Download APK failed because this is not an apk");
|
|
|
}
|
|
|
- String[] temp = downloadUrl.split("/");
|
|
|
- String fileName = temp[temp.length-1];
|
|
|
- String path = AddressUtil.getApkDownloadPath(traceId, fileName);
|
|
|
+ String path = getApkPath(downloadUrl, traceId);
|
|
|
int downloadTimes = 0;
|
|
|
while (downloadTimes < Consts.DOWNLOAD_MAX_ATTEMPTS) {
|
|
|
try {
|
|
@@ -58,7 +56,7 @@ public class ApkServiceImpl implements ApkService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// 下载失败,10s后重试
|
|
|
- PrintUtil.print(String.format("Download %s failed. Retry after 10 seconds", fileName), TAG);
|
|
|
+ PrintUtil.print(String.format("Trace %s download failed. Retry after 10 seconds", traceId), TAG);
|
|
|
try {
|
|
|
Thread.sleep(10000);
|
|
|
} catch (InterruptedException e) {
|
|
@@ -69,28 +67,14 @@ public class ApkServiceImpl implements ApkService {
|
|
|
throw new ApkDownloadException(String.format("Download APK failed after tried %s times.", Consts.DOWNLOAD_MAX_ATTEMPTS));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updateTraceStartTime(String traceId) {
|
|
|
- updateApkInfoTime(traceId, "startTime");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updateTraceEndTime(String traceId) {
|
|
|
- updateApkInfoTime(traceId, "endTime");
|
|
|
+ private boolean verifyDownloadUrl(String downloadUrl){
|
|
|
+ return downloadUrl.endsWith(".apk");
|
|
|
}
|
|
|
|
|
|
- private void updateApkInfoTime(String traceId, String key){
|
|
|
- File infoFile = new File(AddressUtil.getApkInfoPath(traceId));
|
|
|
- Long now = System.currentTimeMillis();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
|
|
|
- String nowStr = sdf.format(now);
|
|
|
- try {
|
|
|
- BufferedWriter writer = new BufferedWriter(new FileWriter(infoFile, true));
|
|
|
- writer.write(key + "=" + nowStr + "\n");
|
|
|
- writer.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ private String getApkPath(String downloadUrl, String traceId){
|
|
|
+ String[] temp = downloadUrl.split("/");
|
|
|
+ String fileName = temp[temp.length-1];
|
|
|
+ return AddressUtil.getApkDownloadPath(traceId, fileName);
|
|
|
}
|
|
|
|
|
|
@Override
|