Commit 0ab9467f authored by liuyang's avatar liuyang

APK抓包>从频道1开始依次抓取, ftp上传优化

#BYLSERVER-1693
parent 4e6bf84b
...@@ -2,7 +2,6 @@ package com.duolebo.blyrobot.data ...@@ -2,7 +2,6 @@ package com.duolebo.blyrobot.data
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import com.duolebo.blyrobot.tools.FtpManager
import com.duolebo.blyrobot.util.Config import com.duolebo.blyrobot.util.Config
import net.gotev.uploadservice.* import net.gotev.uploadservice.*
import net.gotev.uploadservice.ftp.FTPUploadRequest import net.gotev.uploadservice.ftp.FTPUploadRequest
...@@ -14,6 +13,11 @@ import java.io.File ...@@ -14,6 +13,11 @@ import java.io.File
*/ */
class ImageUploadTask { class ImageUploadTask {
companion object {
const val TAG = "RobotTaskUpload"
}
var packageName: String = ""
var uploadImages = ArrayList<String>() var uploadImages = ArrayList<String>()
var uploadId: String = "" var uploadId: String = ""
var reUpload = false var reUpload = false
...@@ -26,6 +30,7 @@ class ImageUploadTask { ...@@ -26,6 +30,7 @@ class ImageUploadTask {
} }
fun from(task: Task) { fun from(task: Task) {
this.packageName = task.apkInfo.packageName
this.uploadImages.clear() this.uploadImages.clear()
this.uploadImages.addAll(task.uploadImages) this.uploadImages.addAll(task.uploadImages)
} }
...@@ -58,7 +63,7 @@ class ImageUploadTask { ...@@ -58,7 +63,7 @@ class ImageUploadTask {
} }
private fun uploadImage() { private fun uploadImage() {
Log.i(FtpManager.TAG, "upload image....") Log.i(TAG, "upload image....")
try { try {
val uploadRequest = FTPUploadRequest(context, Config.instance.getFtpServer(), 21) val uploadRequest = FTPUploadRequest(context, Config.instance.getFtpServer(), 21)
.setUsernameAndPassword(Config.instance.getFtpUserName(), Config.instance.getFtpPassword()) .setUsernameAndPassword(Config.instance.getFtpUserName(), Config.instance.getFtpPassword())
...@@ -77,14 +82,14 @@ class ImageUploadTask { ...@@ -77,14 +82,14 @@ class ImageUploadTask {
} }
this.uploadId = uploadRequest.startUpload() this.uploadId = uploadRequest.startUpload()
Log.i(FtpManager.TAG, "upload id $uploadId") Log.i(TAG, "upload id $uploadId")
} catch (exc: Exception) { } catch (exc: Exception) {
Log.e(FtpManager.TAG, exc.message, exc) Log.e(TAG, exc.message, exc)
} }
} }
private fun uploadComplete(errorCount: Int) { private fun uploadComplete(errorCount: Int) {
Log.i(FtpManager.TAG, "upload errorCount: $errorCount") Log.i(TAG, "upload errorCount: $errorCount")
this.isRunning = false this.isRunning = false
if (errorCount > 0 && errorCount > this.uploadImages.size / 3) { if (errorCount > 0 && errorCount > this.uploadImages.size / 3) {
this.reUpload = true this.reUpload = true
...@@ -105,24 +110,25 @@ class ImageUploadTask { ...@@ -105,24 +110,25 @@ class ImageUploadTask {
*/ */
private fun uploadImageCallback(): UploadStatusDelegate { private fun uploadImageCallback(): UploadStatusDelegate {
val totalUpload = this.uploadImages.size val totalUpload = this.uploadImages.size
Log.i(FtpManager.TAG, "total upload count : $totalUpload") Log.i(TAG, "total upload count : $totalUpload")
return object : UploadStatusDelegate { return object : UploadStatusDelegate {
override fun onCancelled(context: Context?, uploadInfo: UploadInfo?) { override fun onCancelled(context: Context?, uploadInfo: UploadInfo?) {
// empty
} }
override fun onProgress(context: Context?, uploadInfo: UploadInfo?) { override fun onProgress(context: Context?, uploadInfo: UploadInfo?) {
// empty
} }
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?) {
val uploadSize = uploadInfo?.successfullyUploadedFiles!!.size val uploadSize = uploadInfo?.successfullyUploadedFiles!!.size
Log.i(FtpManager.TAG, "onError...uploadCount: $uploadSize") Log.i(TAG, "onError...uploadCount: $uploadSize")
} }
override fun onCompleted(context: Context?, uploadInfo: UploadInfo?, serverResponse: ServerResponse?) { override fun onCompleted(context: Context?, uploadInfo: UploadInfo?, serverResponse: ServerResponse?) {
val uploadSize = uploadInfo?.successfullyUploadedFiles!!.size val uploadSize = uploadInfo?.successfullyUploadedFiles!!.size
Log.i(FtpManager.TAG, "onCompleted...uploadCount: $uploadSize") Log.i(TAG, "onCompleted...uploadCount: $uploadSize")
uploadComplete(totalUpload - uploadSize) uploadComplete(totalUpload - uploadSize)
} }
} }
......
...@@ -18,12 +18,10 @@ import com.duolebo.blyrobot.data.Task ...@@ -18,12 +18,10 @@ import com.duolebo.blyrobot.data.Task
import com.duolebo.blyrobot.protocol.GetAppInfoProtocol import com.duolebo.blyrobot.protocol.GetAppInfoProtocol
import com.duolebo.blyrobot.tools.FtpManager import com.duolebo.blyrobot.tools.FtpManager
import com.duolebo.blyrobot.tools.TaskManager import com.duolebo.blyrobot.tools.TaskManager
import com.duolebo.blyrobot.util.AdbUtil
import com.duolebo.blyrobot.util.AppUtil import com.duolebo.blyrobot.util.AppUtil
import com.duolebo.blyrobot.util.Config import com.duolebo.blyrobot.util.Config
import com.duolebo.blyrobot.util.Constants import com.duolebo.blyrobot.util.Constants
import org.json.JSONObject import org.json.JSONObject
import java.util.*
@SuppressLint("Registered") @SuppressLint("Registered")
class BylRobotService: Service(), IAppBaseCallback { class BylRobotService: Service(), IAppBaseCallback {
...@@ -48,7 +46,7 @@ class BylRobotService: Service(), IAppBaseCallback { ...@@ -48,7 +46,7 @@ class BylRobotService: Service(), IAppBaseCallback {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
FtpManager.instance.init(this) FtpManager.instance.start()
initBroadcast() initBroadcast()
// requestAppList() // requestAppList()
} }
...@@ -93,6 +91,7 @@ class BylRobotService: Service(), IAppBaseCallback { ...@@ -93,6 +91,7 @@ class BylRobotService: Service(), IAppBaseCallback {
override fun onDestroy() { override fun onDestroy() {
Log.i(TAG, "destroy...") Log.i(TAG, "destroy...")
super.onDestroy() super.onDestroy()
FtpManager.instance.stop()
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver) LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver)
} }
......
package com.duolebo.blyrobot.tools package com.duolebo.blyrobot.tools
import android.util.Log
import com.duolebo.blyrobot.data.ImageUploadTask import com.duolebo.blyrobot.data.ImageUploadTask
import net.gotev.uploadservice.UploadService import net.gotev.uploadservice.UploadService
import java.util.* import java.util.*
...@@ -20,6 +21,7 @@ class FtpManager { ...@@ -20,6 +21,7 @@ class FtpManager {
private var scheduleTime: Timer? = null private var scheduleTime: Timer? = null
fun start() { fun start() {
Log.i(TAG, "ftp manager start...")
scheduleTime?.run { cancel() } scheduleTime?.run { cancel() }
this.isRunning = true this.isRunning = true
scheduleTime = Timer() scheduleTime = Timer()
...@@ -28,13 +30,14 @@ class FtpManager { ...@@ -28,13 +30,14 @@ class FtpManager {
while (isRunning) { while (isRunning) {
for (uploadTask in uploadTasks) { for (uploadTask in uploadTasks) {
if (uploadTask.needReUpload()) { if (uploadTask.needReUpload()) {
Log.i(TAG, "task ${uploadTask.packageName} need upload again")
uploadTask.start() uploadTask.start()
} }
} }
Thread.sleep(1 * 60 * 1000) Thread.sleep(1 * 60 * 1000)
} }
} }
}, 0) }, 5 * 1000)
} }
......
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