Commit 60741e96 authored by liuyang's avatar liuyang

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

#BYLSERVER-1693
parent 05ae7ce0
...@@ -35,7 +35,7 @@ class Task : Thread, IAppBaseCallback { ...@@ -35,7 +35,7 @@ class Task : Thread, IAppBaseCallback {
lateinit var apkInfo: ApkInfo lateinit var apkInfo: ApkInfo
// 截图存放路径 // 截图存放路径
private lateinit var imagePath: String private lateinit var taskPath: String
// 抓包存放路径 // 抓包存放路径
private var capturePath = AppUtil.getAbsoluteSdcardPath() + "/capture.txt" private var capturePath = AppUtil.getAbsoluteSdcardPath() + "/capture.txt"
...@@ -71,10 +71,9 @@ class Task : Thread, IAppBaseCallback { ...@@ -71,10 +71,9 @@ class Task : Thread, IAppBaseCallback {
*/ */
fun from(apkInfo: ApkInfo) { fun from(apkInfo: ApkInfo) {
this.apkInfo = apkInfo this.apkInfo = apkInfo
// this.imagePath = this.context.cacheDir.absolutePath + "/" + apkInfo.packageName
val sdPath = AppUtil.getAbsoluteSdcardPath() val sdPath = AppUtil.getAbsoluteSdcardPath()
this.imagePath = sdPath + "/upload/" + apkInfo.packageName this.taskPath = sdPath + "/upload/" + apkInfo.packageName
val dir = File(this.imagePath) val dir = File(this.taskPath)
if (!dir.exists()) if (!dir.exists())
dir.mkdirs() dir.mkdirs()
} }
...@@ -149,12 +148,15 @@ class Task : Thread, IAppBaseCallback { ...@@ -149,12 +148,15 @@ class Task : Thread, IAppBaseCallback {
this.channelIndex = 0 this.channelIndex = 0
this.uploadImages.clear() this.uploadImages.clear()
val dir = File(this.imagePath) val dir = File(this.taskPath)
if (dir.exists()) { if (dir.exists()) {
for (file in dir.listFiles()) for (file in dir.listFiles()) {
if (file.name.endsWith(".log"))
continue
file.delete() file.delete()
} }
} }
}
fun release() { fun release() {
// 杀掉tcpdump进程 // 杀掉tcpdump进程
...@@ -177,6 +179,13 @@ class Task : Thread, IAppBaseCallback { ...@@ -177,6 +179,13 @@ class Task : Thread, IAppBaseCallback {
this.taskListener?.run { this.taskListener?.run {
onComplete(result) 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 { ...@@ -268,13 +277,13 @@ class Task : Thread, IAppBaseCallback {
val screenImages = ArrayList<String>() val screenImages = ArrayList<String>()
var time = imageDateFormat.format(Date()) 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) screenShot(absName)
screenImages.add("$absName.jpg") screenImages.add("$absName.jpg")
AdbUtil.sendMultiKey(this.apkInfo.menuKeyEvent) AdbUtil.sendMultiKey(this.apkInfo.menuKeyEvent)
time = imageDateFormat.format(Date()) 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) screenShot(absOkName)
screenImages.add("$absOkName.jpg") screenImages.add("$absOkName.jpg")
...@@ -474,6 +483,9 @@ class Task : Thread, IAppBaseCallback { ...@@ -474,6 +483,9 @@ class Task : Thread, IAppBaseCallback {
reportArray.put(this.reportJson) reportArray.put(this.reportJson)
postJson.putOpt("data", reportArray) postJson.putOpt("data", reportArray)
reportProtocol.withBody(postJson.toString()).execute(dataHandler) 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?) { override fun onProtocolFailed(p0: IProtocol?) {
......
...@@ -188,4 +188,16 @@ object AppUtil { ...@@ -188,4 +188,16 @@ object AppUtil {
} }
return false 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