Commit f3598946 authored by liuyang's avatar liuyang

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

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