Commit 60741e96 authored by liuyang's avatar liuyang

APK抓包>从频道1开始依次抓取, HDP多于100频道抓取成功上报失败跟踪

#BYLSERVER-1693
parent 05ae7ce0
......@@ -35,7 +35,7 @@ class Task : Thread, IAppBaseCallback {
lateinit var apkInfo: ApkInfo
// 截图存放路径
private lateinit var imagePath: String
private lateinit var taskPath: String
// 抓包存放路径
private var capturePath = AppUtil.getAbsoluteSdcardPath() + "/capture.txt"
......@@ -71,10 +71,9 @@ class Task : Thread, IAppBaseCallback {
*/
fun from(apkInfo: ApkInfo) {
this.apkInfo = apkInfo
// this.imagePath = this.context.cacheDir.absolutePath + "/" + apkInfo.packageName
val sdPath = AppUtil.getAbsoluteSdcardPath()
this.imagePath = sdPath + "/upload/" + apkInfo.packageName
val dir = File(this.imagePath)
this.taskPath = sdPath + "/upload/" + apkInfo.packageName
val dir = File(this.taskPath)
if (!dir.exists())
dir.mkdirs()
}
......@@ -149,10 +148,13 @@ class Task : Thread, IAppBaseCallback {
this.channelIndex = 0
this.uploadImages.clear()
val dir = File(this.imagePath)
val dir = File(this.taskPath)
if (dir.exists()) {
for (file in dir.listFiles())
for (file in dir.listFiles()) {
if (file.name.endsWith(".log"))
continue
file.delete()
}
}
}
......@@ -177,6 +179,13 @@ class Task : Thread, IAppBaseCallback {
this.taskListener?.run {
onComplete(result)
}
try {
val logPath = this.taskPath + "/" + this.imageDateFormat.format(Date()) + ".log"
Runtime.getRuntime().exec("logcat -f $logPath")
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
......@@ -268,13 +277,13 @@ class Task : Thread, IAppBaseCallback {
val screenImages = ArrayList<String>()
var time = imageDateFormat.format(Date())
val absName = this.imagePath + "/${this.apkInfo.packageName}_${channelIndex}_$time"
val absName = this.taskPath + "/${this.apkInfo.packageName}_${channelIndex}_$time"
screenShot(absName)
screenImages.add("$absName.jpg")
AdbUtil.sendMultiKey(this.apkInfo.menuKeyEvent)
time = imageDateFormat.format(Date())
val absOkName = this.imagePath + "/${this.apkInfo.packageName}_${channelIndex}_${time}_ok"
val absOkName = this.taskPath + "/${this.apkInfo.packageName}_${channelIndex}_${time}_ok"
screenShot(absOkName)
screenImages.add("$absOkName.jpg")
......@@ -474,6 +483,9 @@ class Task : Thread, IAppBaseCallback {
reportArray.put(this.reportJson)
postJson.putOpt("data", reportArray)
reportProtocol.withBody(postJson.toString()).execute(dataHandler)
val reportPath = this.taskPath + "/" + this.imageDateFormat.format(Date()) + "_report.json"
AppUtil.saveToFile(reportPath, postJson.toString())
}
override fun onProtocolFailed(p0: IProtocol?) {
......
......@@ -188,4 +188,16 @@ object AppUtil {
}
return false
}
fun saveToFile(fileName: String, content: String) {
try {
val fw = FileWriter(File(fileName))
fw.write(content)
fw.close()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment