Commit a159a984 authored by liuyang's avatar liuyang

APK图片抓取识别及轮播流地址抓取,客户端上报完善

#BYLSERVER-1438
parent f8d8b53f
...@@ -4,7 +4,6 @@ import android.content.Context ...@@ -4,7 +4,6 @@ import android.content.Context
import android.os.Build import android.os.Build
import android.os.Environment import android.os.Environment
import android.util.Log import android.util.Log
import android.widget.Toast
import com.duolebo.appbase.AppBaseHandler import com.duolebo.appbase.AppBaseHandler
import com.duolebo.appbase.IAppBaseCallback import com.duolebo.appbase.IAppBaseCallback
import com.duolebo.appbase.IProtocol import com.duolebo.appbase.IProtocol
...@@ -54,7 +53,7 @@ class Task : IAppBaseCallback { ...@@ -54,7 +53,7 @@ class Task : IAppBaseCallback {
private lateinit var reportJson: JSONObject private lateinit var reportJson: JSONObject
private var context: Context private var context: Context
private val imageDateFormat = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.CHINA) private val imageDateFormat = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.CHINA)
var proc: Process? = null var proc: Process? = null
constructor(context: Context) { constructor(context: Context) {
...@@ -170,8 +169,12 @@ class Task : IAppBaseCallback { ...@@ -170,8 +169,12 @@ class Task : IAppBaseCallback {
val channels = this.reportJson.optJSONArray("channels") val channels = this.reportJson.optJSONArray("channels")
val channelJson = JSONObject() val channelJson = JSONObject()
channelJson.putOpt("channelImage", screenShots[0])
channelJson.putOpt("channelEpgImage", screenShots[1]) val channelImageFile = File(screenShots[0])
channelJson.putOpt("channelImage", channelImageFile.name)
val channelEpgImageFile = File(screenShots[1])
channelJson.putOpt("channelEpgImage", channelEpgImageFile.name)
channelJson.putOpt("channelId", this.channelIndex) channelJson.putOpt("channelId", this.channelIndex)
val playUrls = JSONArray() val playUrls = JSONArray()
...@@ -296,7 +299,6 @@ class Task : IAppBaseCallback { ...@@ -296,7 +299,6 @@ class Task : IAppBaseCallback {
private fun uploadImageCallback(): UploadStatusDelegate { private fun uploadImageCallback(): UploadStatusDelegate {
val totalUpload = this.uploadImages.size val totalUpload = this.uploadImages.size
Log.i(TAG, "total upload count : $totalUpload") Log.i(TAG, "total upload count : $totalUpload")
var uploadCount = 0
return object: UploadStatusDelegate { return object: UploadStatusDelegate {
override fun onCancelled(context: Context?, uploadInfo: UploadInfo?) { override fun onCancelled(context: Context?, uploadInfo: UploadInfo?) {
...@@ -306,19 +308,12 @@ class Task : IAppBaseCallback { ...@@ -306,19 +308,12 @@ class Task : IAppBaseCallback {
} }
override fun onError(context: Context?, uploadInfo: UploadInfo?, serverResponse: ServerResponse?, exception: java.lang.Exception?) { override fun onError(context: Context?, uploadInfo: UploadInfo?, serverResponse: ServerResponse?, exception: java.lang.Exception?) {
Log.i(TAG, "upload error uploadCount: $uploadCount " + uploadInfo?.toString())
uploadCount++
if (uploadCount == totalUpload - 1) {
uploadComplete(uploadCount - uploadInfo?.successfullyUploadedFiles!!.size)
}
} }
override fun onCompleted(context: Context?, uploadInfo: UploadInfo?, serverResponse: ServerResponse?) { override fun onCompleted(context: Context?, uploadInfo: UploadInfo?, serverResponse: ServerResponse?) {
Log.i(TAG, "onCompleted...uploadCount: $uploadCount") val uploadSize = uploadInfo?.successfullyUploadedFiles!!.size
uploadCount++ Log.i(TAG, "onCompleted...uploadCount: $uploadSize")
if (uploadCount == totalUpload - 1) { uploadComplete(totalUpload - uploadSize)
uploadComplete(uploadCount - uploadInfo?.successfullyUploadedFiles!!.size)
}
} }
} }
} }
...@@ -350,7 +345,11 @@ class Task : IAppBaseCallback { ...@@ -350,7 +345,11 @@ class Task : IAppBaseCallback {
} }
private fun report() { private fun report() {
reportProtocol.withBody(reportJson.toString()).execute(dataHandler) val postJson = JSONObject()
val reportArray = JSONArray()
reportArray.put(this.reportJson)
postJson.putOpt("data", reportArray)
reportProtocol.withBody(postJson.toString()).execute(dataHandler)
} }
override fun onProtocolFailed(p0: IProtocol?) { override fun onProtocolFailed(p0: IProtocol?) {
......
...@@ -25,12 +25,20 @@ class ApkReportProtocol(context: Context?, config: IProtocolConfig?) : ProtocolB ...@@ -25,12 +25,20 @@ class ApkReportProtocol(context: Context?, config: IProtocolConfig?) : ProtocolB
return body.toByteArray() return body.toByteArray()
} }
override fun prepareProtocolRequestKey(): String {
return ""
}
override fun getData(): IModel { override fun getData(): IModel {
return model return model
} }
override fun prepareProtocolRequestKey(): String { override fun prepareHttpRequestUrl(): String {
return Config.instance.getReportProtocolUrl() return Config.instance.getReportProtocolUrl()
} }
override fun getBodyContentType(): String {
return "application/json; charset=utf-8"
}
} }
\ No newline at end of file
...@@ -23,7 +23,6 @@ import java.util.* ...@@ -23,7 +23,6 @@ import java.util.*
class BylRobotService: Service() { class BylRobotService: Service() {
private val TAG = "BylRobotService" private val TAG = "BylRobotService"
private var timer: Timer? = null
private var count = 0 private var count = 0
private val broadcastReceiver = object : BroadcastReceiver() { private val broadcastReceiver = object : BroadcastReceiver() {
...@@ -41,20 +40,6 @@ class BylRobotService: Service() { ...@@ -41,20 +40,6 @@ class BylRobotService: Service() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
initBroadcast() initBroadcast()
timer = Timer()
timer!!.schedule(object: TimerTask() {
override fun run() {
// testKey()
// testCapture()
// screenShot()
count++
if (count > 2) {
cancelTimer()
// proc?.destroy()
}
}
},2000, 180*1000)
} }
private fun initBroadcast() { private fun initBroadcast() {
...@@ -82,28 +67,6 @@ class BylRobotService: Service() { ...@@ -82,28 +67,6 @@ class BylRobotService: Service() {
TaskManager.instance.stop() TaskManager.instance.stop()
} }
private fun testKey() {
Thread(Runnable {
AdbUtil.sendMultiKey("down/up/right")
}).start()
}
var proc: Process ?= null
private fun testCapture() {
proc?.destroy()
Thread(Runnable {
AdbUtil.killTcpdump()
}).start()
Thread.sleep(3000)
Thread(Runnable {
proc = AdbUtil.tcpCapture("")
}).start()
}
private fun cancelTimer() {
timer?.cancel()
timer = null
}
override fun onBind(p0: Intent?): IBinder { override fun onBind(p0: Intent?): IBinder {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
...@@ -113,6 +76,5 @@ class BylRobotService: Service() { ...@@ -113,6 +76,5 @@ class BylRobotService: Service() {
Log.i(TAG, "destroy...") Log.i(TAG, "destroy...")
super.onDestroy() super.onDestroy()
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver) LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver)
cancelTimer()
} }
} }
\ No newline at end of file
...@@ -8,23 +8,29 @@ class TaskManager { ...@@ -8,23 +8,29 @@ class TaskManager {
private val TAG = "TaskManager" private val TAG = "TaskManager"
private val RUN_TASK_PERIOD = 6*60*60*1000 private val RUN_TASK_PERIOD = 6*60*60*1000
val tasks = ArrayList<Task>() val tasks = ArrayList<Task>()
private val overTasks = ArrayList<Task>()
var isRunning = false var isRunning = false
private var status = IDLE private var status = IDLE
private var currentTask: Task ?= null private var currentTask: Task ?= null
// 处理时间 // 处理时间
private var updateTime = 0L
private val runnable = Runnable { private val runnable = Runnable {
while (isRunning) { while (isRunning) {
if (this.status == IDLE) { val interval = System.currentTimeMillis() - this.updateTime
if (this.status == IDLE && interval > RUN_TASK_PERIOD) {
this.updateTime = System.currentTimeMillis()
this.status = RUNNING
for (task in tasks) { for (task in tasks) {
task.reset() task.reset()
currentTask = task currentTask = task
currentTask!!.start() currentTask!!.start()
} }
this.status = COMPLETE
} }
else { else {
Log.i(TAG, "no task running") Log.i(TAG, "no task running")
...@@ -38,6 +44,11 @@ class TaskManager { ...@@ -38,6 +44,11 @@ class TaskManager {
task.taskListener = object : Task.OnTaskListener { task.taskListener = object : Task.OnTaskListener {
override fun onComplete(result: Boolean) { override fun onComplete(result: Boolean) {
Log.i(TAG, "task ${task.apkInfo.name} complete with result: $result") Log.i(TAG, "task ${task.apkInfo.name} complete with result: $result")
overTasks.add(task)
if (overTasks.size == tasks.size) {
status = IDLE
}
} }
} }
this.tasks.add(task) this.tasks.add(task)
...@@ -73,7 +84,7 @@ class TaskManager { ...@@ -73,7 +84,7 @@ class TaskManager {
} }
this.isRunning = true this.isRunning = true
this.status = 0 this.status = IDLE
val t = Thread(runnable) val t = Thread(runnable)
t.start() t.start()
} }
...@@ -83,12 +94,13 @@ class TaskManager { ...@@ -83,12 +94,13 @@ class TaskManager {
it.destroy() it.destroy()
} }
this.overTasks.clear()
this.isRunning = false this.isRunning = false
} }
companion object { companion object {
val instance = TaskManager() val instance = TaskManager()
const val IDLE = 0 const val IDLE = 0
const val COMPLETE = 1 const val RUNNING = 1
} }
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ package com.duolebo.blyrobot.util ...@@ -3,7 +3,7 @@ package com.duolebo.blyrobot.util
import com.duolebo.appbase.prj.bmtv.protocol.IProtocolConfig import com.duolebo.appbase.prj.bmtv.protocol.IProtocolConfig
class Config: IProtocolConfig { class Config: IProtocolConfig {
val isDebug = true val isDebug = false
override fun getProtocolUrl(): String { override fun getProtocolUrl(): String {
if (isDebug) if (isDebug)
...@@ -19,9 +19,10 @@ class Config: IProtocolConfig { ...@@ -19,9 +19,10 @@ class Config: IProtocolConfig {
return "" return ""
} }
fun getReportProtocolUrl(): String { fun getReportProtocolUrl(): String {
if (isDebug) if (isDebug)
return "http://192.168.2.42:8080/manage/apkInfo/report.do" return "http://192.168.2.42:8080/manage/apkReport/report.do"
return "http://test.duolebo.com/staging/apkReport/report.do" return "http://test.duolebo.com/staging/apkReport/report.do"
} }
......
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