Commit c76d67f3 authored by liuyang's avatar liuyang

APK抓包>从频道1开始依次抓取, 清除png图片,减少磁盘空间占用

#BYLSERVER-1693
parent 60741e96
......@@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<application
android:allowBackup="true"
......
......@@ -47,6 +47,10 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
Log.i(TAG, "onCreate....")
setContentView(R.layout.activity_main)
init()
}
private fun init() {
getLocalAppList()
this.appInfoAdapter = AppConfigAdapter()
......@@ -84,7 +88,6 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
this.appInfoAdapter.clear()
requestAppList()
}
}
private fun start() {
......
......@@ -56,7 +56,7 @@ class Task : Thread, IAppBaseCallback {
constructor(context: Context) {
this.context = context
this.reportProtocol = ApkReportProtocol(context, Config.instance)
this.reportProtocol.retryPolicy = DefaultRetryPolicy(10*1000, 3, DEFAULT_BACKOFF_MULT)
this.reportProtocol.retryPolicy = DefaultRetryPolicy(30*1000, 3, DEFAULT_BACKOFF_MULT)
this.dataHandler = AppBaseHandler(this)
}
......@@ -179,13 +179,6 @@ 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()
}
}
/**
......@@ -407,8 +400,10 @@ class Task : Thread, IAppBaseCallback {
AdbUtil.screenShot(pngPath)
// png转换成jpg
val pngFile = File(pngPath)
if (pngFile.exists())
if (pngFile.exists()) {
AppUtil.pngToJpg(pngPath, jpgPath)
pngFile.delete()
}
else {
Log.i(TAG, "screen shot failed")
}
......@@ -480,9 +475,13 @@ class Task : Thread, IAppBaseCallback {
Log.i(TAG, "report....")
val postJson = JSONObject()
val reportArray = JSONArray()
reportArray.put(this.reportJson)
postJson.putOpt("data", reportArray)
reportProtocol.withBody(postJson.toString()).execute(dataHandler)
try {
reportArray.put(this.reportJson)
postJson.putOpt("data", reportArray)
reportProtocol.withBody(postJson.toString()).execute(dataHandler)
} catch (e: Exception) {
e.printStackTrace()
}
val reportPath = this.taskPath + "/" + this.imageDateFormat.format(Date()) + "_report.json"
AppUtil.saveToFile(reportPath, postJson.toString())
......
......@@ -14,6 +14,9 @@ import android.os.Build
import android.os.Environment
import java.util.regex.Pattern
import android.app.ActivityManager.RunningAppProcessInfo
import java.nio.file.Files.delete
......@@ -76,13 +79,34 @@ object AppUtil {
fun pngToJpg(pngFilePath: String, jpgFilePath: String) {
val bitmap = BitmapFactory.decodeFile(pngFilePath)
try {
BufferedOutputStream(FileOutputStream(jpgFilePath)).use { bos ->
val fos = FileOutputStream(jpgFilePath)
BufferedOutputStream(fos).use { bos ->
if (bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos)) {
bos.flush()
}
bos.close()
}
fos.close()
} catch (e: IOException) {
e.printStackTrace()
} finally {
bitmap!!.recycle()
}
}
fun pngToJpg2(pngFilePath: String, jpgFilePath: String) {
val bitmap: Bitmap? = BitmapFactory.decodeFile(pngFilePath)
try {
val bos = BufferedOutputStream(FileOutputStream(jpgFilePath))
bitmap?.run {
compress(Bitmap.CompressFormat.JPEG, 100, bos)
bos.flush()
}
bos.close()
} catch (e: IOException) {
e.printStackTrace()
} finally {
bitmap!!.recycle()
}
}
......
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