Commit c76d67f3 authored by liuyang's avatar liuyang

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

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