|
@@ -1,39 +1,30 @@
|
|
|
package com.wdkl.ncs.android.component.home.service
|
|
|
|
|
|
+import android.app.ActivityManager
|
|
|
+import android.content.ComponentName
|
|
|
+import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.os.Handler
|
|
|
import android.os.IBinder
|
|
|
import android.os.Messenger
|
|
|
import android.util.Log
|
|
|
-import com.enation.javashop.net.engine.model.NetState
|
|
|
-import com.enation.javashop.net.engine.plugin.connection.ConnectionQuality
|
|
|
-import com.enation.javashop.net.engine.plugin.exception.ExceptionHandle
|
|
|
-import com.enation.javashop.net.engine.utils.ThreadFromUtils
|
|
|
import com.google.common.base.Strings
|
|
|
import com.google.gson.FieldNamingPolicy
|
|
|
import com.google.gson.Gson
|
|
|
import com.google.gson.GsonBuilder
|
|
|
import com.wdkl.core.consts.Urls
|
|
|
import com.wdkl.core.socket.SocketManager
|
|
|
+import com.wdkl.ncs.android.component.home.BuildConfig
|
|
|
import com.wdkl.ncs.android.component.home.activity.*
|
|
|
import com.wdkl.ncs.android.component.home.settingconfig.SettingConfig
|
|
|
import com.wdkl.ncs.android.component.home.util.AppUtils
|
|
|
-import com.wdkl.ncs.keepbackground.work.AbsWorkService
|
|
|
import com.wdkl.ncs.android.component.home.util.NetHelper
|
|
|
import com.wdkl.ncs.android.component.home.util.SpeechUtil
|
|
|
import com.wdkl.ncs.android.component.home.util.Util
|
|
|
import com.wdkl.ncs.android.component.nursehome.common.Constants
|
|
|
-import com.wdkl.ncs.android.lib.utils.AppTool
|
|
|
-import com.wdkl.ncs.android.lib.utils.ConnectionObserver
|
|
|
-import com.wdkl.ncs.android.lib.utils.getEventCenter
|
|
|
import com.wdkl.ncs.android.lib.utils.getJsonString
|
|
|
-import com.wdkl.ncs.android.lib.vo.NetStateEvent
|
|
|
import com.wdkl.ncs.android.middleware.api.ApiManager
|
|
|
-import com.wdkl.ncs.android.middleware.api.WatchDeviceInfoAndTCPMailingAddressApi
|
|
|
-import com.wdkl.ncs.android.middleware.di.MiddlewareDaggerComponent
|
|
|
import com.wdkl.ncs.android.middleware.model.dos.PartSettingDO
|
|
|
-import com.wdkl.ncs.android.middleware.model.dto.TcpSeverDTO
|
|
|
-import com.wdkl.ncs.android.middleware.model.vo.DeviceVO
|
|
|
import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
|
|
|
import com.wdkl.ncs.android.middleware.tcp.TcpClient
|
|
|
import com.wdkl.ncs.android.middleware.tcp.TcpClientHandler
|
|
@@ -42,17 +33,18 @@ import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
|
|
|
import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
|
|
|
import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
|
|
|
import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
|
-import io.reactivex.disposables.Disposable
|
|
|
+import com.wdkl.ncs.keepbackground.work.AbsWorkService
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
|
import java.util.*
|
|
|
-import javax.inject.Inject
|
|
|
+import java.util.concurrent.ConcurrentLinkedQueue
|
|
|
|
|
|
class WdKeepAliveService : AbsWorkService() {
|
|
|
val TAG = "WdKeepAliveService"
|
|
|
companion object instance {
|
|
|
var updateLastTime : Long = System.currentTimeMillis() / 1000
|
|
|
+ var sosQueue : ConcurrentLinkedQueue<TcpModel> = ConcurrentLinkedQueue<TcpModel>()
|
|
|
}
|
|
|
|
|
|
private var mIsRunning = false
|
|
@@ -130,74 +122,89 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
//事件与语音留言通道
|
|
|
3->{
|
|
|
- while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
- Thread.sleep(400)
|
|
|
- }
|
|
|
+ Thread(Runnable {
|
|
|
+ while (DeviceChannel.calling) {
|
|
|
+ Thread.sleep(400)
|
|
|
+ }
|
|
|
|
|
|
- SpeechUtil.getInstance().stopSpeak()
|
|
|
+ SpeechUtil.getInstance().stopSpeak()
|
|
|
|
|
|
- Util.wakeUpAndUnlock(this)
|
|
|
+ Util.wakeUpAndUnlock(this)
|
|
|
|
|
|
- val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
- val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- if (tcpModel.type == TcpType.IM) {
|
|
|
- SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
|
|
|
- } else if (tcpModel.type == TcpType.EVENT) {
|
|
|
- var eventStr = ""
|
|
|
- if (interactionVO != null) {
|
|
|
- eventStr = Util.appendSpace(interactionVO.fromFrameFullName.replace("-", "")) + ", " + interactionVO.data
|
|
|
+ val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
+ val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
+ if (tcpModel.type == TcpType.IM) {
|
|
|
+ SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
|
|
|
+ } else if (tcpModel.type == TcpType.EVENT) {
|
|
|
+ var eventStr = ""
|
|
|
+ if (interactionVO != null) {
|
|
|
+ eventStr = Util.appendSpace(interactionVO.fromFrameFullName.replace("-", "")) + ", " + interactionVO.data
|
|
|
+ }
|
|
|
+ SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
|
|
|
}
|
|
|
- SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
|
|
|
- }
|
|
|
- tcpModel.data = interactionVO
|
|
|
-
|
|
|
- val intent = Intent()
|
|
|
- intent.setClass(this, WatchEventDetailActivity::class.java)
|
|
|
- intent.putExtra("tcpModelStr", tcpModel.toJson())
|
|
|
- intent.putExtra("boolVibrator", true)
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- startActivity(intent)
|
|
|
- }
|
|
|
- //SOS通道
|
|
|
- 999->{
|
|
|
- while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
- Thread.sleep(400)
|
|
|
- }
|
|
|
+ tcpModel.data = interactionVO
|
|
|
|
|
|
- SpeechUtil.getInstance().stopSpeak()
|
|
|
-
|
|
|
-// DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
- Util.wakeUpAndUnlock(this)
|
|
|
- val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
- if (tcpModel.type == TcpType.SOS && tcpModel.action === TcpAction.SOSAction.CALL) {
|
|
|
val intent = Intent()
|
|
|
- intent.setClass(this, SOSEmergencyCallActivity::class.java)
|
|
|
- intent.putExtra("TcpModel", tcpModel)
|
|
|
+ intent.setClass(this, WatchEventDetailActivity::class.java)
|
|
|
+ intent.putExtra("tcpModelStr", tcpModel.toJson())
|
|
|
+ intent.putExtra("boolVibrator", true)
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
startActivity(intent)
|
|
|
+ }).start()
|
|
|
+ }
|
|
|
+ //SOS通道
|
|
|
+ 999->{
|
|
|
+ val tcpModelIn = messageEvent.getMessage() as TcpModel
|
|
|
+ if (tcpModelIn.action == TcpAction.SOSAction.CALL) {
|
|
|
+ sosQueue.offer(tcpModelIn)
|
|
|
+ if (!Constants.sosActive) {
|
|
|
+ val tcpModel = sosQueue.poll()
|
|
|
+ openSos(tcpModel)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var tcpModelRm:TcpModel? = null
|
|
|
+ val interactionVoIn = Gson().fromJson(tcpModelIn.data.toString(), InteractionVO::class.java)
|
|
|
+ sosQueue.forEach {
|
|
|
+ val interactionVO = Gson().fromJson(it.data.toString(), InteractionVO::class.java)
|
|
|
+ if (interactionVO.id == interactionVoIn.id){
|
|
|
+ tcpModelRm = it
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tcpModelRm!=null){
|
|
|
+ sosQueue.remove(tcpModelRm)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ Constants.EVENT_SOS_POLL->{
|
|
|
+ val tcpModel = sosQueue.poll()
|
|
|
+ openSos(tcpModel)
|
|
|
+ }
|
|
|
//用户切换
|
|
|
Constants.EVENT_USER_CHANGE->{
|
|
|
- while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
- Thread.sleep(400)
|
|
|
- }
|
|
|
- DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
- Util.wakeUpAndUnlock(this)
|
|
|
- AppUtils.restartApp()
|
|
|
+ Thread(Runnable {
|
|
|
+ while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
+ Thread.sleep(400)
|
|
|
+ }
|
|
|
+ DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
+ Util.wakeUpAndUnlock(this)
|
|
|
+ AppUtils.restartApp()
|
|
|
+ }).start()
|
|
|
}
|
|
|
//设备切换
|
|
|
Constants.EVENT_DEVICE_CHANGE->{
|
|
|
- while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
- Thread.sleep(400)
|
|
|
- }
|
|
|
+ Thread(Runnable {
|
|
|
+ while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
+ Thread.sleep(400)
|
|
|
+ }
|
|
|
|
|
|
- DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
- Util.wakeUpAndUnlock(this)
|
|
|
- val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
- if (tcpModel.action == TcpAction.DeviceAction.RESTART) {
|
|
|
- AppUtils.restartApp()
|
|
|
- }
|
|
|
+ DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
+ Util.wakeUpAndUnlock(this)
|
|
|
+ val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
+ if (tcpModel.action == TcpAction.DeviceAction.RESTART) {
|
|
|
+ AppUtils.restartApp()
|
|
|
+ }
|
|
|
+ }).start()
|
|
|
}
|
|
|
//系统设置
|
|
|
Constants.EVENT_DEVICE_SETTING->{
|
|
@@ -224,22 +231,24 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
//APP升级
|
|
|
Constants.EVENT_APP_UPDATE->{
|
|
|
- while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
- Thread.sleep(400)
|
|
|
- }
|
|
|
+ Thread(Runnable {
|
|
|
+ while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
+ Thread.sleep(400)
|
|
|
+ }
|
|
|
|
|
|
- DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
- Util.wakeUpAndUnlock(this)
|
|
|
- val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
- if (tcpModel.action == TcpAction.DeviceAction.APP_UPDATE) {
|
|
|
- if ((System.currentTimeMillis() / 1000) - updateLastTime > 10){ //大于10秒可继续升级
|
|
|
- updateLastTime = System.currentTimeMillis() / 1000
|
|
|
- val intent = Intent()
|
|
|
- intent.setClass(this, AppUpdateActivity::class.java)
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- startActivity(intent)
|
|
|
+ DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
+ Util.wakeUpAndUnlock(this)
|
|
|
+ val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
+ if (tcpModel.action == TcpAction.DeviceAction.APP_UPDATE) {
|
|
|
+ if ((System.currentTimeMillis() / 1000) - updateLastTime > 10){ //大于10秒可继续升级
|
|
|
+ updateLastTime = System.currentTimeMillis() / 1000
|
|
|
+ val intent = Intent()
|
|
|
+ intent.setClass(this, AppUpdateActivity::class.java)
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+ startActivity(intent)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }).start()
|
|
|
}
|
|
|
//网络断开,1000ms重连
|
|
|
Constants.EVENT_TCP_BREAK->{
|
|
@@ -249,7 +258,31 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
wakeLock?.release()
|
|
|
}).start()
|
|
|
Log.w(TAG, "EVENT TCP BREAK")
|
|
|
- TcpClient.getInstance().doConnect()
|
|
|
+ if (TcpClient.getInstance().channel==null || TcpClient.getInstance().bootstrap == null) {
|
|
|
+ TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat)
|
|
|
+ } else if (!TcpClient.getInstance().channel.isActive){
|
|
|
+ TcpClient.getInstance().doConnect()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun openSos(tcpModel: TcpModel?){
|
|
|
+ if (tcpModel!=null) {
|
|
|
+ while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
+ Thread.sleep(400)
|
|
|
+ }
|
|
|
+
|
|
|
+ SpeechUtil.getInstance().stopSpeak()
|
|
|
+ Util.wakeUpAndUnlock(this)
|
|
|
+
|
|
|
+ if (tcpModel.type == TcpType.SOS && tcpModel.action === TcpAction.SOSAction.CALL) {
|
|
|
+ DeviceChannel.calling = true //置于通话状态中,不可呼叫
|
|
|
+ val intent = Intent()
|
|
|
+ intent.setClass(this, SOSEmergencyCallActivity::class.java)
|
|
|
+ intent.putExtra("TcpModel", tcpModel)
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+ startActivity(intent)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -284,7 +317,11 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
Thread.sleep(1000)
|
|
|
wakeLock?.release()
|
|
|
})
|
|
|
- TcpClient.getInstance().doConnect()
|
|
|
+ if (TcpClient.getInstance().channel==null || TcpClient.getInstance().bootstrap == null) {
|
|
|
+ TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat)
|
|
|
+ } else if (!TcpClient.getInstance().channel.isActive){
|
|
|
+ TcpClient.getInstance().doConnect()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|