|
@@ -3,7 +3,6 @@ package com.xhly.manageapp.service.websocket
|
3
|
3
|
import android.app.Notification
|
4
|
4
|
import android.app.NotificationChannel
|
5
|
5
|
import android.app.NotificationManager
|
6
|
|
-import android.app.Service
|
7
|
6
|
import android.content.ComponentName
|
8
|
7
|
import android.content.Context
|
9
|
8
|
import android.content.Intent
|
|
@@ -19,6 +18,7 @@ import com.xhly.corelib.utils.LogShow
|
19
|
18
|
import com.xhly.corelib.utils.MD5Utils
|
20
|
19
|
import com.xhly.corelib.utils.SharedPreferencesUtils
|
21
|
20
|
import com.xhly.manageapp.ManageApplication
|
|
21
|
+import com.xhly.manageapp.bean.EventLog
|
22
|
22
|
import com.xhly.manageapp.bean.log.LogAppStartBean
|
23
|
23
|
import com.xhly.manageapp.bean.log.LogdOperateBean
|
24
|
24
|
import com.xhly.manageapp.network.LogService
|
|
@@ -42,13 +42,12 @@ open class AppSocketService : LongConnService() {
|
42
|
42
|
private val serviceScope = CoroutineScope(MainScope().coroutineContext)
|
43
|
43
|
private var appList = arrayListOf<AppInfo>()
|
44
|
44
|
|
45
|
|
- //标记上次打开的包名,当连续打开同一包名时,不认为打开多次
|
46
|
|
- private var lastPkgName = ""
|
47
|
|
-
|
48
|
45
|
/* private var csdkManager: CSDKManager? = null*/
|
49
|
46
|
val spUtils by lazy { SharedPreferencesUtils.getInstance(this) }
|
50
|
47
|
|
51
|
48
|
companion object {
|
|
49
|
+ //标记上次打开的包名,当连续打开同一包名时,不认为打开多次
|
|
50
|
+ var lastPkgName = ""
|
52
|
51
|
fun openWebSocket(context: Context) {
|
53
|
52
|
LogShow("打开广播")
|
54
|
53
|
context.startService(Intent(context, AppSocketService::class.java))
|
|
@@ -62,7 +61,7 @@ open class AppSocketService : LongConnService() {
|
62
|
61
|
override fun onCreate() {
|
63
|
62
|
super.onCreate()
|
64
|
63
|
EventBus.getDefault().register(this)
|
65
|
|
- connectUrl = "wss://mcwstest.xhkjedu.com/ws"
|
|
64
|
+ connectUrl = Const.WSURL
|
66
|
65
|
/* csdkManager = CSDKManager(this)*/
|
67
|
66
|
/* startNotification()*/
|
68
|
67
|
LogShow("已经创建")
|
|
@@ -78,14 +77,15 @@ open class AppSocketService : LongConnService() {
|
78
|
77
|
override fun onConnectedSuccess() {
|
79
|
78
|
super.onConnectedSuccess()
|
80
|
79
|
UIEvent(Const.UPDATE_CONNECTED_SUCCESS).post()
|
81
|
|
- val webData=WebSocketData()
|
82
|
|
- webData.code=1002
|
83
|
|
- webData.mid=UUID.randomUUID().toString()
|
|
80
|
+ val webData = WebSocketData()
|
|
81
|
+ webData.code = 1002
|
|
82
|
+ webData.mid = UUID.randomUUID().toString()
|
84
|
83
|
val currentTimeSeconds = System.currentTimeMillis() / 1000
|
85
|
|
- webData.timeunix=currentTimeSeconds
|
86
|
|
- webData.fid=1
|
87
|
|
- val jsMD5 = MD5Utils.getJsMD5(webData.code.toString()+"_"+webData.mid+"_"+webData.timeunix.toString())
|
88
|
|
- webData.sign=MD5Utils.getJsMD5(jsMD5)
|
|
84
|
+ webData.timeunix = currentTimeSeconds
|
|
85
|
+ webData.fid = 1
|
|
86
|
+ val jsMD5 =
|
|
87
|
+ MD5Utils.getJsMD5(webData.code.toString() + "_" + webData.mid + "_" + webData.timeunix.toString())
|
|
88
|
+ webData.sign = MD5Utils.getJsMD5(jsMD5)
|
89
|
89
|
WebSocketHelper.getInstance().sendSocketString(GsonUtils.parseClassToJson(webData))
|
90
|
90
|
}
|
91
|
91
|
|
|
@@ -115,13 +115,13 @@ open class AppSocketService : LongConnService() {
|
115
|
115
|
|
116
|
116
|
Const.LOGAPPSTART -> {
|
117
|
117
|
val message = uiEvent.message
|
118
|
|
- if (lastPkgName==message){
|
|
118
|
+ if (lastPkgName == message) {
|
119
|
119
|
return
|
120
|
120
|
}
|
121
|
121
|
val filter = appList.filter { it.packageName == message }
|
122
|
122
|
if (filter.isNotEmpty()) {
|
123
|
123
|
val appInfo = filter[0]
|
124
|
|
- lastPkgName=message
|
|
124
|
+ lastPkgName = message
|
125
|
125
|
serviceScope.launch {
|
126
|
126
|
val logStartBean = LogAppStartBean()
|
127
|
127
|
ManageApplication.getDeviceInfo()?.let {
|
|
@@ -131,12 +131,43 @@ open class AppSocketService : LongConnService() {
|
131
|
131
|
logStartBean.appPackage = appInfo.packageName
|
132
|
132
|
logStartBean.versionName = appInfo.versionName
|
133
|
133
|
logStartBean.versionNum = appInfo.versionNum
|
134
|
|
- LogShow("当前应用"+logStartBean.appName+"|||"+logStartBean.versionName+"|||"+logStartBean.versionNum)
|
135
|
|
- logService.postLogAppStartAdd(logStartBean)
|
|
134
|
+ LogShow("当前应用" + logStartBean.appName + "|||" + logStartBean.versionName + "|||" + logStartBean.versionNum)
|
|
135
|
+ logService.postLogAppStartAdd(logStartBean)
|
|
136
|
+ }
|
|
137
|
+ val data = LogdOperateBean()
|
|
138
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
139
|
+ data.sn = it
|
136
|
140
|
}
|
|
141
|
+ data.appPackage=message
|
|
142
|
+ data.doEvent = EventLog.STARTAPPEVENT
|
|
143
|
+ eventLog(data)
|
137
|
144
|
}
|
138
|
145
|
}
|
139
|
146
|
|
|
147
|
+ Const.APPINSTALL -> {
|
|
148
|
+ val message = uiEvent.message
|
|
149
|
+ val data = LogdOperateBean()
|
|
150
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
151
|
+ data.sn = it
|
|
152
|
+ }
|
|
153
|
+ data.appPackage=message
|
|
154
|
+ data.comm="应用安装"
|
|
155
|
+ data.doEvent = EventLog.APPINSTALLEVENT
|
|
156
|
+ eventLog(data)
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+ Const.APPUNINSTALL -> {
|
|
160
|
+ val message = uiEvent.message
|
|
161
|
+ val data = LogdOperateBean()
|
|
162
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
163
|
+ data.sn = it
|
|
164
|
+ }
|
|
165
|
+ data.appPackage=message
|
|
166
|
+ data.comm="应用卸载"
|
|
167
|
+ data.doEvent = EventLog.APPUNINSTALLEVENT
|
|
168
|
+ eventLog(data)
|
|
169
|
+ }
|
|
170
|
+
|
140
|
171
|
"10086" -> {
|
141
|
172
|
serviceScope.launch {
|
142
|
173
|
logService.postLogdoperateAdd(LogdOperateBean())
|
|
@@ -164,13 +195,18 @@ open class AppSocketService : LongConnService() {
|
164
|
195
|
}
|
165
|
196
|
}
|
166
|
197
|
|
|
198
|
+ //用来发送事件日志
|
|
199
|
+ private fun eventLog(operateBean: LogdOperateBean) {
|
|
200
|
+ serviceScope.launch {
|
|
201
|
+ logService.postLogdoperateAdd(operateBean)
|
|
202
|
+ }
|
|
203
|
+ }
|
|
204
|
+
|
167
|
205
|
override fun onDestroy() {
|
168
|
206
|
super.onDestroy()
|
169
|
207
|
EventBus.getDefault().unregister(this)
|
170
|
208
|
serviceScope.cancel()
|
171
|
|
- stopForeground(Service.STOP_FOREGROUND_REMOVE)
|
172
|
|
- /* val intent=Intent(this,ManageService::class.java)
|
173
|
|
- startService(intent)*/
|
|
209
|
+ /* stopForeground(Service.STOP_FOREGROUND_REMOVE)*/
|
174
|
210
|
val intent = Intent()
|
175
|
211
|
intent.setPackage("com.xhly.manageapp")
|
176
|
212
|
intent.setAction("test")
|