Commit f3598946 authored by liuyang's avatar liuyang

APK图片抓取识别及轮播流地址抓取,客户端4.2版本文件读取问题

#BYLSERVER-1438
parent 3eb63bda
...@@ -33,7 +33,7 @@ android { ...@@ -33,7 +33,7 @@ android {
applicationVariants.all { variant -> applicationVariants.all { variant ->
variant.outputs.all { variant.outputs.all {
outputFileName = "dlbrebot_v${defaultConfig.versionName}_${releaseTime()}.apk" outputFileName = "dlbrobot_v${defaultConfig.versionName}_${releaseTime()}.apk"
} }
} }
} }
......
...@@ -40,7 +40,7 @@ class ApkInfo: IModel { ...@@ -40,7 +40,7 @@ class ApkInfo: IModel {
this.channelCount = json.optInt(CHANNEL_COUNT, 5) this.channelCount = json.optInt(CHANNEL_COUNT, 5)
this.channelKeyEvent = json.optString(CHANNEL_KEY_EVENT) this.channelKeyEvent = json.optString(CHANNEL_KEY_EVENT)
this.mediaExt = json.optString(MEDIA_EXT, VIDEO_EXTS) this.mediaExt = json.optString(MEDIA_EXT, VIDEO_EXTS)
this.filterUrl = json.optString(FILTER_URL) this.filterUrl = json.optString(FILTER_URL, "")
this.menuKeyEvent = json.optString(MENU_KEY_EVENT, "ok") this.menuKeyEvent = json.optString(MENU_KEY_EVENT, "ok")
return true return true
......
...@@ -30,16 +30,16 @@ class Task : IAppBaseCallback { ...@@ -30,16 +30,16 @@ class Task : IAppBaseCallback {
"0" to "未处理", "0" to "未处理",
"1" to "进行中", "1" to "进行中",
"2" to "中断", "2" to "中断",
"3" to "图片上传中", "3" to "截图失败",
"4" to "上报失败", "4" to "图片上传中",
"5" to "处理完成") "5" to "上报失败",
"6" to "处理完成")
lateinit var apkInfo: ApkInfo lateinit var apkInfo: ApkInfo
// 截图存放路径 // 截图存放路径
private lateinit var imagePath: String private lateinit var imagePath: String
// 抓包存放路径 // 抓包存放路径
private var capturePath = Environment private var capturePath = AppUtil.getAbsoluteSdcardPath() + "/capture.txt"
.getExternalStorageDirectory().absolutePath + "/capture.txt"
private var uploadImages = ArrayList<String>() private var uploadImages = ArrayList<String>()
private var uploadId = "" private var uploadId = ""
...@@ -65,8 +65,8 @@ class Task : IAppBaseCallback { ...@@ -65,8 +65,8 @@ class Task : IAppBaseCallback {
fun from(apkInfo: ApkInfo) { fun from(apkInfo: ApkInfo) {
this.apkInfo = apkInfo this.apkInfo = apkInfo
// this.imagePath = this.context.cacheDir.absolutePath + "/" + apkInfo.packageName // this.imagePath = this.context.cacheDir.absolutePath + "/" + apkInfo.packageName
this.imagePath = Environment val sdPath = AppUtil.getAbsoluteSdcardPath()
.getExternalStorageDirectory().absolutePath + "/upload/" + apkInfo.packageName this.imagePath = sdPath + "/upload/" + apkInfo.packageName
val dir = File(this.imagePath) val dir = File(this.imagePath)
if (!dir.exists()) if (!dir.exists())
dir.mkdirs() dir.mkdirs()
...@@ -101,7 +101,7 @@ class Task : IAppBaseCallback { ...@@ -101,7 +101,7 @@ class Task : IAppBaseCallback {
this.processChannels() this.processChannels()
// 上传图片 // 上传图片
this.uploadImage() this.uploadImage()
this.status = "3" this.status = "4"
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
this.status = "2" this.status = "2"
e.printStackTrace() e.printStackTrace()
...@@ -247,11 +247,11 @@ class Task : IAppBaseCallback { ...@@ -247,11 +247,11 @@ class Task : IAppBaseCallback {
val host = it.substring(start) val host = it.substring(start)
val url = "http://$host$partUrl" val url = "http://$host$partUrl"
var add = false var add = true
// 如果筛选url不为空,这里需要进行过滤 // 如果筛选url不为空,这里需要进行过滤
if (!this.apkInfo.filterUrl.isNullOrEmpty()) { if (!this.apkInfo.filterUrl.isEmpty()) {
if (url.contains(this.apkInfo.filterUrl)) if (!url.contains(this.apkInfo.filterUrl))
add = true add = false
} }
if (add) { if (add) {
...@@ -301,7 +301,12 @@ class Task : IAppBaseCallback { ...@@ -301,7 +301,12 @@ class Task : IAppBaseCallback {
val jpgPath = pngPath.replace(".png", ".jpg") val jpgPath = pngPath.replace(".png", ".jpg")
AdbUtil.screenShot(pngPath) AdbUtil.screenShot(pngPath)
// png转换成jpg // png转换成jpg
AppUtil.pngToJpg(pngPath, jpgPath) val pngFile = File(pngPath)
if (pngFile.exists())
AppUtil.pngToJpg(pngPath, jpgPath)
else {
Log.i(TAG, "screen shot failed")
}
} }
private fun uploadComplete(errorCount: Int) { private fun uploadComplete(errorCount: Int) {
...@@ -367,17 +372,17 @@ class Task : IAppBaseCallback { ...@@ -367,17 +372,17 @@ class Task : IAppBaseCallback {
} }
override fun onProtocolFailed(p0: IProtocol?) { override fun onProtocolFailed(p0: IProtocol?) {
this.status = "4" this.status = "5"
finish(false) finish(false)
} }
override fun onHttpFailed(p0: IProtocol?) { override fun onHttpFailed(p0: IProtocol?) {
this.status = "4" this.status = "5"
finish(false) finish(false)
} }
override fun onProtocolSucceed(p0: IProtocol?) { override fun onProtocolSucceed(p0: IProtocol?) {
this.status = "5" this.status = "6"
finish(true) finish(true)
} }
......
...@@ -9,8 +9,9 @@ import android.graphics.Bitmap ...@@ -9,8 +9,9 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import java.io.* import java.io.*
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build
import android.os.Environment
import java.util.regex.Pattern
object AppUtil { object AppUtil {
...@@ -148,4 +149,22 @@ object AppUtil { ...@@ -148,4 +149,22 @@ object AppUtil {
return installed return installed
} }
fun getAbsoluteSdcardPath(): String {
var sdcardAbsPath = ""
if (TextUtils.isEmpty(sdcardAbsPath))
sdcardAbsPath = Environment.getExternalStorageDirectory().absolutePath
// 4.2系统存在legacy|0读取问题
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
sdcardAbsPath = "/sdcard"
}
// val p = Pattern.compile("/?storage/emulated/\\d{1,2}")
// val m = p.matcher(sdcardAbsPath)
// if (m.find()) {
// sdcardAbsPath = sdcardAbsPath.replace("storage/emulated/", "storage/sdcard")
// }
return sdcardAbsPath
}
} }
\ 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