|
@@ -1,5 +1,6 @@
|
|
|
package com.wdkl.ncs.android.component.home.service
|
|
|
|
|
|
+import android.app.Activity
|
|
|
import android.app.ActivityManager
|
|
|
import android.content.ComponentName
|
|
|
import android.content.Context
|
|
@@ -7,18 +8,22 @@ import android.content.Intent
|
|
|
import android.os.Handler
|
|
|
import android.os.IBinder
|
|
|
import android.os.Messenger
|
|
|
+import android.text.TextUtils
|
|
|
import android.util.Log
|
|
|
+import com.alibaba.fastjson.JSON
|
|
|
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.core.util.ActivityStackManager
|
|
|
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.*
|
|
|
import com.wdkl.ncs.android.component.nursehome.common.Constants
|
|
|
+import com.wdkl.ncs.android.lib.utils.AppTool
|
|
|
import com.wdkl.ncs.android.lib.utils.getJsonString
|
|
|
import com.wdkl.ncs.android.middleware.api.ApiManager
|
|
|
import com.wdkl.ncs.android.middleware.model.dos.PartSettingDO
|
|
@@ -40,9 +45,10 @@ 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>()
|
|
|
+ var updateLastTime: Long = System.currentTimeMillis() / 1000
|
|
|
+ var sosQueue: ConcurrentLinkedQueue<TcpModel> = ConcurrentLinkedQueue<TcpModel>()
|
|
|
|
|
|
var mNewEventListActive = false
|
|
|
}
|
|
@@ -91,21 +97,21 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
- when(messageEvent.tag){
|
|
|
+ when (messageEvent.tag) {
|
|
|
//拨出成功 || 有来电
|
|
|
- 1->{
|
|
|
+ 1 -> {
|
|
|
Util.wakeUpAndUnlock(this)
|
|
|
|
|
|
SpeechUtil.getInstance().stopSpeak()
|
|
|
|
|
|
val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
- if (tcpModel.type == TcpType.VOICE){
|
|
|
+ if (tcpModel.type == TcpType.VOICE) {
|
|
|
// var gson = GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create()
|
|
|
val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
val intent = Intent()
|
|
|
|
|
|
- if (tcpModel.action == TcpAction.VoiceAction.SUCCESS){ //拨出成功
|
|
|
- Log.i(TAG,"拨出成功 ${interactionVO.fromMemberName} ${interactionVO.id}")
|
|
|
+ if (tcpModel.action == TcpAction.VoiceAction.SUCCESS) { //拨出成功
|
|
|
+ Log.i(TAG, "拨出成功 ${interactionVO.fromMemberName} ${interactionVO.id}")
|
|
|
DeviceChannel.calling = true;
|
|
|
intent.setClass(this, WebRTCVoipAudioActivity::class.java)
|
|
|
intent.putExtra("targetId", interactionVO?.toSipId)
|
|
@@ -113,8 +119,9 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
intent.putExtra(WebRTCVoipAudioActivity().ACTION, WebRTCVoipAudioActivity().CALL)
|
|
|
startActivity(intent)
|
|
|
- } else if (tcpModel.action == TcpAction.VoiceAction.CALL){ //有来电
|
|
|
+ } else if (tcpModel.action == TcpAction.VoiceAction.CALL) { //有来电
|
|
|
DeviceChannel.calling = true;
|
|
|
+ Log.i(TAG, "来电:" + JSON.toJSONString(interactionVO))
|
|
|
intent.setClass(this, WebRTCVoipAudioRingingActivity::class.java)
|
|
|
intent.putExtra("targetId", interactionVO?.fromSipId)
|
|
|
intent.putExtra("TcpModel", tcpModel)
|
|
@@ -124,7 +131,7 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
}
|
|
|
//事件与语音留言通道
|
|
|
- 3->{
|
|
|
+ 3 -> {
|
|
|
if (!mNewEventListActive) {
|
|
|
Thread(Runnable {
|
|
|
while (DeviceChannel.calling) {
|
|
@@ -146,7 +153,7 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
}
|
|
|
//SOS通道
|
|
|
- 999->{
|
|
|
+ 999 -> {
|
|
|
if (!mNewEventListActive) {
|
|
|
while (DeviceChannel.calling) {
|
|
|
Thread.sleep(400)
|
|
@@ -167,12 +174,12 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Constants.EVENT_SOS_POLL->{
|
|
|
+ Constants.EVENT_SOS_POLL -> {
|
|
|
val tcpModel = sosQueue.poll()
|
|
|
openSos(tcpModel)
|
|
|
}
|
|
|
//用户切换
|
|
|
- Constants.EVENT_USER_CHANGE->{
|
|
|
+ Constants.EVENT_USER_CHANGE -> {
|
|
|
Thread(Runnable {
|
|
|
while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
Thread.sleep(400)
|
|
@@ -183,7 +190,7 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}).start()
|
|
|
}
|
|
|
//设备切换
|
|
|
- Constants.EVENT_DEVICE_CHANGE->{
|
|
|
+ Constants.EVENT_DEVICE_CHANGE -> {
|
|
|
Thread(Runnable {
|
|
|
while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
Thread.sleep(400)
|
|
@@ -198,18 +205,18 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}).start()
|
|
|
}
|
|
|
//系统设置
|
|
|
- Constants.EVENT_DEVICE_SETTING->{
|
|
|
+ Constants.EVENT_DEVICE_SETTING -> {
|
|
|
Thread(Runnable {
|
|
|
var jsonStr = ""
|
|
|
- val partSettingDO = ApiManager.API_WatchDeviceInfoAndTCPMailingAddress.getDeviceSettingData(""+Constants.partId).map {
|
|
|
+ val partSettingDO = ApiManager.API_WatchDeviceInfoAndTCPMailingAddress.getDeviceSettingData("" + Constants.partId).map {
|
|
|
jsonStr = it.getJsonString()
|
|
|
val gson = GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create()
|
|
|
val partSettingDO = gson.fromJson(jsonStr, PartSettingDO::class.java)
|
|
|
return@map partSettingDO
|
|
|
}.blockingSingle()
|
|
|
|
|
|
- Log.i(TAG,"收到系统设置 " + jsonStr)
|
|
|
- if(partSettingDO != null&&partSettingDO.transferDuration !=null&&partSettingDO.transferDurationLeader != null){
|
|
|
+ Log.i(TAG, "收到系统设置 " + jsonStr)
|
|
|
+ if (partSettingDO != null && partSettingDO.transferDuration != null && partSettingDO.transferDurationLeader != null) {
|
|
|
if (Constants.userRoleName != null) {
|
|
|
if (!Constants.userRoleName!!.contains("护士组长") && Constants.userRoleName!!.contains("护士")) {
|
|
|
SettingConfig.setCountdownTime(application, partSettingDO.transferDuration)
|
|
@@ -221,7 +228,7 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}).start()
|
|
|
}
|
|
|
//APP升级
|
|
|
- Constants.EVENT_APP_UPDATE->{
|
|
|
+ Constants.EVENT_APP_UPDATE -> {
|
|
|
Thread(Runnable {
|
|
|
while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
Thread.sleep(400)
|
|
@@ -231,7 +238,7 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
Util.wakeUpAndUnlock(this)
|
|
|
val tcpModel = messageEvent.getMessage() as TcpModel
|
|
|
if (tcpModel.action == TcpAction.DeviceAction.APP_UPDATE) {
|
|
|
- if ((System.currentTimeMillis() / 1000) - updateLastTime > 10){ //大于10秒可继续升级
|
|
|
+ if ((System.currentTimeMillis() / 1000) - updateLastTime > 10) { //大于10秒可继续升级
|
|
|
updateLastTime = System.currentTimeMillis() / 1000
|
|
|
val intent = Intent()
|
|
|
intent.setClass(this, AppUpdateActivity::class.java)
|
|
@@ -242,7 +249,7 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}).start()
|
|
|
}
|
|
|
//网络断开
|
|
|
- Constants.EVENT_TCP_BREAK->{
|
|
|
+ Constants.EVENT_TCP_BREAK -> {
|
|
|
Util.wakeUpAndUnlock(this@WdKeepAliveService)
|
|
|
Log.w(TAG, "EVENT TCP BREAK")
|
|
|
reConnect()
|
|
@@ -250,8 +257,8 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun openSos(tcpModel: TcpModel?){
|
|
|
- if (tcpModel!=null) {
|
|
|
+ fun openSos(tcpModel: TcpModel?) {
|
|
|
+ if (tcpModel != null) {
|
|
|
while (DeviceChannel.calling) { //通话中不处理,一直等待至结束
|
|
|
Thread.sleep(400)
|
|
|
}
|
|
@@ -292,27 +299,30 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
}
|
|
|
}
|
|
|
checkNetStateTimer!!.schedule(checkNetStateTimerTask, 8000, Constants.heartBeat * 1000L)
|
|
|
+// checkNetStateTimer!!.schedule(checkNetStateTimerTask, 8000, 5000)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun reConnect(){
|
|
|
+ fun reConnect() {
|
|
|
if (NetHelper.getInstance().getNetworkState(this@WdKeepAliveService) != NetHelper.NETWORK_NONE) {
|
|
|
+ if (!TextUtils.isEmpty(Constants.sipId) && !SocketManager.getInstance().userState.equals(1)) { //webrtc 断线重连
|
|
|
+ SocketManager.getInstance().connect(Urls.WS, Constants.sipId, 0)
|
|
|
+ }
|
|
|
+
|
|
|
if (!TcpClientHandler.getConnected()) {
|
|
|
Log.w(TAG, "断网唤醒CPU")
|
|
|
- val wakeLock = Util.wakeUpAndUnlock(this@WdKeepAliveService)
|
|
|
+// val wakeLock = Util.wakeUpAndUnlock(this@WdKeepAliveService)
|
|
|
if (TcpClient.getInstance().retryTimes < 30) {
|
|
|
if (TcpClient.getInstance().channel == null || TcpClient.getInstance().bootstrap == null) {
|
|
|
- TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat, iTcpCallBack)
|
|
|
- } else {
|
|
|
- TcpClient.getInstance().doConnect(iTcpCallBack)
|
|
|
+ TcpClient.getInstance().doConnect(iTcpCallBack)// TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat, iTcpCallBack)
|
|
|
}
|
|
|
} else {
|
|
|
AppUtils.restartApp()
|
|
|
}
|
|
|
} else {
|
|
|
TcpClient.getInstance().sendMsg("0")
|
|
|
- if (SocketManager.getInstance().connectFlag){
|
|
|
- EventBus.getDefault().post(MessageEvent(TcpModel(),Constants.EVENT_RTC_STATE))
|
|
|
+ if (SocketManager.getInstance().connectFlag) {
|
|
|
+ EventBus.getDefault().post(MessageEvent(TcpModel(), Constants.EVENT_RTC_STATE))
|
|
|
} else {
|
|
|
iTcpCallBack.connected()
|
|
|
}
|