|
@@ -2,8 +2,10 @@ package com.quyunshuo.module.home.utils
|
|
|
|
|
|
import android.app.XzjhSystemManager
|
|
|
import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
import android.media.AudioManager
|
|
|
import android.media.MediaScannerConnection
|
|
|
+import android.os.Build
|
|
|
import android.os.Environment
|
|
|
import android.util.Log
|
|
|
import com.google.gson.Gson
|
|
@@ -13,9 +15,15 @@ import com.qiniu.android.http.ResponseInfo
|
|
|
import com.qiniu.android.storage.UpCompletionHandler
|
|
|
import com.qiniu.android.storage.UploadManager
|
|
|
import com.qiniu.android.storage.UploadOptions
|
|
|
+import com.quyunshuo.module.home.R
|
|
|
+import com.quyunshuo.module.home.bean.AlarmClockBean
|
|
|
+import com.quyunshuo.module.home.bean.PaySuccessBean
|
|
|
+import com.quyunshuo.module.home.getui.BaseBean
|
|
|
+import com.quyunshuo.module.home.getui.MqttBaseBean
|
|
|
import com.quyunshuo.sbm10.base.BaseApplication
|
|
|
import com.quyunshuo.sbm10.base.BaseApplication.Companion.context
|
|
|
import com.quyunshuo.sbm10.base.addressenum.PlcSettingAddressEnum
|
|
|
+import com.quyunshuo.sbm10.base.utils.JsonUtils
|
|
|
import com.quyunshuo.sbm10.base.utils.SpUtils
|
|
|
import com.quyunshuo.sbm10.common.bean.PaySucessBean
|
|
|
import com.quyunshuo.sbm10.common.constant.Heartbeat
|
|
@@ -27,16 +35,11 @@ import com.quyunshuo.sbm10.common.enums.ConnectStateEnum
|
|
|
import com.quyunshuo.sbm10.common.util.AlarmManagerUtil
|
|
|
import com.quyunshuo.sbm10.common.util.ToastUtil
|
|
|
import com.quyunshuo.sbm10.common.util.UiUtil
|
|
|
-import com.quyunshuo.module.home.R
|
|
|
-import com.quyunshuo.module.home.bean.AlarmClockBean
|
|
|
-import com.quyunshuo.module.home.bean.PaySuccessBean
|
|
|
-import com.quyunshuo.module.home.getui.BaseBean
|
|
|
-import com.quyunshuo.module.home.getui.MqttBaseBean
|
|
|
-import com.quyunshuo.sbm10.base.utils.JsonUtils
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
import okhttp3.Call
|
|
|
import okhttp3.Callback
|
|
|
import okhttp3.OkHttpClient
|
|
@@ -46,6 +49,7 @@ import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
|
import org.json.JSONObject
|
|
|
+import top.wuhaojie.installerlibrary.AutoInstaller
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
import java.io.DataInputStream
|
|
|
import java.io.File
|
|
@@ -63,8 +67,10 @@ import javax.inject.Inject
|
|
|
|
|
|
class RemotePushUtil @Inject constructor() {
|
|
|
private val TAG = "RemotePushUtil"
|
|
|
+
|
|
|
@Inject
|
|
|
lateinit var threadSettingParam: ThreadSettingParam
|
|
|
+
|
|
|
init {
|
|
|
registerToEventBus()
|
|
|
}
|
|
@@ -87,6 +93,7 @@ class RemotePushUtil @Inject constructor() {
|
|
|
Message.Type.ack -> {
|
|
|
ack(messageEvent)
|
|
|
}
|
|
|
+
|
|
|
Message.Type.response -> {}
|
|
|
Message.Type.connected -> {}
|
|
|
Message.Type.disconnected -> {}
|
|
@@ -106,6 +113,7 @@ class RemotePushUtil @Inject constructor() {
|
|
|
threadSettingParam.startRstM3()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
PlcSettingAddressEnum.RM3.address -> {
|
|
|
threadSettingParam.stopRstM3()
|
|
|
}
|
|
@@ -184,13 +192,16 @@ class RemotePushUtil @Inject constructor() {
|
|
|
//远程上传日志文件
|
|
|
uploadLogApi(baseBean.kind_data)
|
|
|
}
|
|
|
+
|
|
|
MqName.updateApk -> {
|
|
|
//远程推送apk或图片
|
|
|
upDateApk(baseBean.kind_data)
|
|
|
}
|
|
|
+
|
|
|
else -> {}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
fun getMqttMessage(msg: String) {
|
|
|
Log.d(TAG, "MqttMessage:" + msg)
|
|
|
var kindStr = JsonUtils.getValue(msg, "dataContent", String::class.java)
|
|
@@ -204,31 +215,32 @@ class RemotePushUtil @Inject constructor() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
fun uploadLog(mqtt: MqttBaseBean) {
|
|
|
try {
|
|
|
var filePath = "/storage/emulated/0/logdata/${mqtt.kind_data}.txt"
|
|
|
val uploadManager = UploadManager()
|
|
|
val uploadFile: File = File(filePath)
|
|
|
- val uploadFileKey: String = mqtt.key
|
|
|
+ val uploadFileKey: String = mqtt.key
|
|
|
.trim()
|
|
|
- Log.d(TAG, "uploadLog: "+filePath)
|
|
|
+ Log.d(TAG, "uploadLog: " + filePath)
|
|
|
val options = UploadOptions(null, null, false,
|
|
|
{ key, percent ->
|
|
|
}, { // 当需要取消时,此处返回 true,SDK 内部会多次检查返回值,当返回值为 true 时会取消上传操作
|
|
|
false
|
|
|
})
|
|
|
- uploadManager.put(uploadFile,uploadFileKey,mqtt.token,object : UpCompletionHandler {
|
|
|
+ uploadManager.put(uploadFile, uploadFileKey, mqtt.token, object : UpCompletionHandler {
|
|
|
override fun complete(key: String?, info: ResponseInfo?, response: JSONObject?) {
|
|
|
- Log.d(TAG, "complete:" + JsonUtils.getJSONString(info))
|
|
|
+ Log.d(TAG, "complete:" + JsonUtils.getJSONString(info))
|
|
|
if (info != null && info.isOK()) {
|
|
|
// 上传成功
|
|
|
} else {
|
|
|
- Log.d(TAG, "失败:" + JsonUtils.getJSONString(info))
|
|
|
+ Log.d(TAG, "失败:" + JsonUtils.getJSONString(info))
|
|
|
// 上传失败
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- },options)
|
|
|
+ }, options)
|
|
|
} catch (e: IOException) {
|
|
|
Log.e("QiniuLab", e.message!!)
|
|
|
}
|
|
@@ -243,16 +255,16 @@ class RemotePushUtil @Inject constructor() {
|
|
|
var str1 = ""
|
|
|
val targetString = ".com.cn/"
|
|
|
var startIndex: Int = kindData.indexOf(targetString)
|
|
|
- var result =""
|
|
|
+ var result = ""
|
|
|
if (startIndex != -1) {
|
|
|
startIndex += targetString.length
|
|
|
result = kindData.substring(startIndex)
|
|
|
- Log.d(TAG, "upDateApk: "+result)
|
|
|
+ Log.d(TAG, "upDateApk: " + result)
|
|
|
str1 = if (result.endsWith(".apk")) {
|
|
|
"apk"
|
|
|
} else if (result.endsWith(".png")) {
|
|
|
"png"
|
|
|
- } else if (result.endsWith(".jpg")) {
|
|
|
+ } else if (result.endsWith(".jpg")) {
|
|
|
"jpg"
|
|
|
} else {
|
|
|
"mp4"
|
|
@@ -266,7 +278,7 @@ class RemotePushUtil @Inject constructor() {
|
|
|
|
|
|
client.newCall(request).enqueue(object : Callback {
|
|
|
override fun onFailure(call: Call, e: IOException) {
|
|
|
- Log.d(TAG, "newCall onFailure: "+e.message)
|
|
|
+ Log.d(TAG, "newCall onFailure: " + e.message)
|
|
|
e.printStackTrace()
|
|
|
}
|
|
|
|
|
@@ -276,34 +288,49 @@ class RemotePushUtil @Inject constructor() {
|
|
|
// 下载成功
|
|
|
val inputStream: InputStream? = response.body?.byteStream()
|
|
|
var pathName = ""
|
|
|
- if (str1.equals("apk")){
|
|
|
- pathName="/apk/" + "mht.apk"
|
|
|
- }else if (str1=="jpg"||str1=="png"){
|
|
|
- pathName="/pic/"+result
|
|
|
+ if (str1.equals("apk")) {
|
|
|
+ pathName = "/apk/" + "mht.apk"
|
|
|
+ } else if (str1 == "jpg" || str1 == "png") {
|
|
|
+ pathName = "/pic/" + result
|
|
|
}
|
|
|
- Log.d(TAG, "upDateApk:2 "+pathName+" :"+str1)
|
|
|
+ Log.d(TAG, "upDateApk:2 " + pathName + " :" + str1)
|
|
|
// 获取目标目录
|
|
|
var file = File(pathName)
|
|
|
if (!file.exists()) {
|
|
|
file.mkdirs()
|
|
|
}
|
|
|
|
|
|
- file= File(Environment.getExternalStorageDirectory().path + pathName)
|
|
|
+ file = File(Environment.getExternalStorageDirectory().path + pathName)
|
|
|
val outputStream = FileOutputStream(file)
|
|
|
inputStream?.use { input ->
|
|
|
outputStream.use { output ->
|
|
|
input.copyTo(output)
|
|
|
}
|
|
|
}
|
|
|
- if (str1!="apk"){
|
|
|
- MediaScannerConnection.scanFile(context, arrayOf(file.absolutePath), null, null)
|
|
|
- }else{
|
|
|
- val mManager: XzjhSystemManager =
|
|
|
- context.getSystemService("xzjh_server") as XzjhSystemManager
|
|
|
- mManager.xzjhSilentInstallApkV2(
|
|
|
- Environment.getExternalStorageDirectory().path + "/apk/" + "mht.apk",
|
|
|
- true
|
|
|
+ if (str1 != "apk") {
|
|
|
+ MediaScannerConnection.scanFile(
|
|
|
+ context,
|
|
|
+ arrayOf(file.absolutePath),
|
|
|
+ null,
|
|
|
+ null
|
|
|
)
|
|
|
+ } else {
|
|
|
+ if (Build.MODEL.equals("rk3566_r")) {
|
|
|
+ val mManager: XzjhSystemManager =
|
|
|
+ context.getSystemService("xzjh_server") as XzjhSystemManager
|
|
|
+ mManager.xzjhSilentInstallApkV2(
|
|
|
+ Environment.getExternalStorageDirectory().path + "/apk/" + "mht.apk",
|
|
|
+ true
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "onResponse: installerapk")
|
|
|
+ CoroutineScope(Dispatchers.IO).launch {
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ val installer: AutoInstaller = AutoInstaller.getDefault(context)
|
|
|
+ installer.install(Environment.getExternalStorageDirectory().path + "/apk/mht.apk")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
Log.d(TAG, "newCall failed: ")
|
|
@@ -418,7 +445,7 @@ class RemotePushUtil @Inject constructor() {
|
|
|
//没有关机
|
|
|
if (kind_data == "1") {
|
|
|
//开机
|
|
|
- threadSettingParam.startUp()
|
|
|
+ threadSettingParam.startUp()
|
|
|
}
|
|
|
|
|
|
}
|