Commit a159a984 authored by liuyang's avatar liuyang

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

#BYLSERVER-1438
parent f8d8b53f
......@@ -4,7 +4,6 @@ import android.content.Context
import android.os.Build
import android.os.Environment
import android.util.Log
import android.widget.Toast
import com.duolebo.appbase.AppBaseHandler
import com.duolebo.appbase.IAppBaseCallback
import com.duolebo.appbase.IProtocol
......@@ -54,7 +53,7 @@ class Task : IAppBaseCallback {
private lateinit var reportJson: JSONObject
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
constructor(context: Context) {
......@@ -170,8 +169,12 @@ class Task : IAppBaseCallback {
val channels = this.reportJson.optJSONArray("channels")
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)
val playUrls = JSONArray()
......@@ -296,7 +299,6 @@ class Task : IAppBaseCallback {
private fun uploadImageCallback(): UploadStatusDelegate {
val totalUpload = this.uploadImages.size
Log.i(TAG, "total upload count : $totalUpload")
var uploadCount = 0
return object: UploadStatusDelegate {
override fun onCancelled(context: Context?, uploadInfo: UploadInfo?) {
......@@ -306,19 +308,12 @@ class Task : IAppBaseCallback {
}
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?) {
Log.i(TAG, "onCompleted...uploadCount: $uploadCount")
uploadCount++
if (uploadCount == totalUpload - 1) {
uploadComplete(uploadCount - uploadInfo?.successfullyUploadedFiles!!.size)
}
val uploadSize = uploadInfo?.successfullyUploadedFiles!!.size
Log.i(TAG, "onCompleted...uploadCount: $uploadSize")
uploadComplete(totalUpload - uploadSize)
}
}
}
......@@ -350,7 +345,11 @@ class Task : IAppBaseCallback {
}
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?) {
......
......@@ -25,12 +25,20 @@ class ApkReportProtocol(context: Context?, config: IProtocolConfig?) : ProtocolB
return body.toByteArray()
}
override fun prepareProtocolRequestKey(): String {
return ""
}
override fun getData(): IModel {
return model
}
override fun prepareProtocolRequestKey(): String {
override fun prepareHttpRequestUrl(): String {
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.*
class BylRobotService: Service() {
private val TAG = "BylRobotService"
private var timer: Timer? = null
private var count = 0
private val broadcastReceiver = object : BroadcastReceiver() {
......@@ -41,20 +40,6 @@ class BylRobotService: Service() {
override fun onCreate() {
super.onCreate()
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() {
......@@ -82,28 +67,6 @@ class BylRobotService: Service() {
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 {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
......@@ -113,6 +76,5 @@ class BylRobotService: Service() {
Log.i(TAG, "destroy...")
super.onDestroy()
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver)
cancelTimer()
}
}
\ No newline at end of file
......@@ -8,23 +8,29 @@ class TaskManager {
private val TAG = "TaskManager"
private val RUN_TASK_PERIOD = 6*60*60*1000
val tasks = ArrayList<Task>()
private val overTasks = ArrayList<Task>()
var isRunning = false
private var status = IDLE
private var currentTask: Task ?= null
// 处理时间
private var updateTime = 0L
private val runnable = Runnable {
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) {
task.reset()
currentTask = task
currentTask!!.start()
}
this.status = COMPLETE
}
else {
Log.i(TAG, "no task running")
......@@ -38,6 +44,11 @@ class TaskManager {
task.taskListener = object : Task.OnTaskListener {
override fun onComplete(result: Boolean) {
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)
......@@ -73,7 +84,7 @@ class TaskManager {
}
this.isRunning = true
this.status = 0
this.status = IDLE
val t = Thread(runnable)
t.start()
}
......@@ -83,12 +94,13 @@ class TaskManager {
it.destroy()
}
this.overTasks.clear()
this.isRunning = false
}
companion object {
val instance = TaskManager()
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
import com.duolebo.appbase.prj.bmtv.protocol.IProtocolConfig
class Config: IProtocolConfig {
val isDebug = true
val isDebug = false
override fun getProtocolUrl(): String {
if (isDebug)
......@@ -19,9 +19,10 @@ class Config: IProtocolConfig {
return ""
}
fun getReportProtocolUrl(): String {
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"
}
......
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