Browse Source

1.Const添加新常量。

2.AppUtils增加获得应用版本和版本名称。
3.ManageAccessibilityService增加Event事件记录应用打开
master
wangwanlei 10 months ago
parent
commit
5a4f823a08

+ 12
- 2
app/src/main/java/com/xhly/manageapp/ManageApplication.kt View File

8
 
8
 
9
 class ManageApplication : MultiDexApplication() {
9
 class ManageApplication : MultiDexApplication() {
10
     companion object {
10
     companion object {
11
-        var csdkManager: CSDKManager? = null
11
+        private var csdkManager: CSDKManager? = null
12
 
12
 
13
         /**
13
         /**
14
          * 加入可安装应用白名单
14
          * 加入可安装应用白名单
53
          */
53
          */
54
         fun setDisplayBlacklist(pkgList: ArrayList<String>) {
54
         fun setDisplayBlacklist(pkgList: ArrayList<String>) {
55
             if (ModelNameUtils.IS_LianxX505f()) {
55
             if (ModelNameUtils.IS_LianxX505f()) {
56
-                csdkManager?.displayBlacklistV3=pkgList
56
+                csdkManager?.displayBlacklistV3 = pkgList
57
             }
57
             }
58
         }
58
         }
59
 
59
 
184
                 csdkManager?.setRuntimePermissions(enableFlag)
184
                 csdkManager?.setRuntimePermissions(enableFlag)
185
             }
185
             }
186
         }
186
         }
187
+
188
+        /**
189
+         * "设备Mac地址", "设备SN号", "获取设备型号信息", "获取设备IMEI信息" 1,2,3,4
190
+         */
191
+        fun getDeviceInfo(type: Int = 2): String? {
192
+            if (ModelNameUtils.IS_LianxX505f()) {
193
+                return csdkManager?.getDeviceInfo(type)
194
+            }
195
+            return "0"
196
+        }
187
     }
197
     }
188
 
198
 
189
     override fun onCreate() {
199
     override fun onCreate() {

+ 8
- 0
app/src/main/java/com/xhly/manageapp/bean/AppTimeManageBean.kt View File

1
+package com.xhly.manageapp.bean
2
+
3
+//用力处理APP的时间管控,包括包名和可使用的时间段
4
+class AppTimeManageBean {
5
+    private var pkgName = ""
6
+    private var startTime = 0L
7
+    private var endTime = 0L
8
+}

+ 3
- 0
app/src/main/java/com/xhly/manageapp/network/LogService.kt View File

20
     @POST(UriAdress.LOGAPPSTARTADD)
20
     @POST(UriAdress.LOGAPPSTARTADD)
21
     suspend fun postLogAppStartAdd(@Body logApp: LogAppStartBean)
21
     suspend fun postLogAppStartAdd(@Body logApp: LogAppStartBean)
22
 
22
 
23
+    @POST("/appgroup/list_app")
24
+    suspend fun postListApp()
25
+
23
 }
26
 }

+ 15
- 8
app/src/main/java/com/xhly/manageapp/service/ManageAccessibilityService.kt View File

2
 
2
 
3
 import android.accessibilityservice.AccessibilityService
3
 import android.accessibilityservice.AccessibilityService
4
 import android.view.accessibility.AccessibilityEvent
4
 import android.view.accessibility.AccessibilityEvent
5
+import com.xhly.corelib.Const
6
+import com.xhly.corelib.eventbus.UIEvent
5
 import com.xhly.corelib.utils.LogShow
7
 import com.xhly.corelib.utils.LogShow
6
 
8
 
7
 class ManageAccessibilityService : AccessibilityService() {
9
 class ManageAccessibilityService : AccessibilityService() {
8
     override fun onAccessibilityEvent(event: AccessibilityEvent?) {
10
     override fun onAccessibilityEvent(event: AccessibilityEvent?) {
9
-       event?.let {
10
-           if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == it.eventType) {
11
-               LogShow(it.packageName.toString() +"|||" + it.className.toString())
12
-               if (it.className.toString().equals("com.example.mytestxf.MainActivity")){
13
-                   performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
14
-               }
15
-           }
16
-       }
11
+        event?.let {
12
+            if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == it.eventType) {
13
+                LogShow(it.packageName.toString() + "|||" + it.className.toString())
14
+                if (it.className.toString().equals("com.example.mytestxf.MainActivity")) {
15
+                    performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
16
+                }
17
+                if (!it.packageName.toString().isNullOrBlank()) {
18
+                    val uiEvent = UIEvent(Const.LOGAPPSTART)
19
+                    uiEvent.setMessage(it.packageName.toString())
20
+                    uiEvent.post()
21
+                }
22
+            }
23
+        }
17
     }
24
     }
18
 
25
 
19
     override fun onInterrupt() {
26
     override fun onInterrupt() {

+ 37
- 2
app/src/main/java/com/xhly/manageapp/service/websocket/AppSocketService.kt View File

10
 import android.os.Build
10
 import android.os.Build
11
 import android.widget.Toast
11
 import android.widget.Toast
12
 import com.xhly.corelib.Const
12
 import com.xhly.corelib.Const
13
+import com.xhly.corelib.bean.AppInfo
13
 import com.xhly.corelib.eventbus.UIEvent
14
 import com.xhly.corelib.eventbus.UIEvent
14
 import com.xhly.corelib.network.RetrofitService
15
 import com.xhly.corelib.network.RetrofitService
16
+import com.xhly.corelib.utils.AppUtils
15
 import com.xhly.corelib.utils.LogShow
17
 import com.xhly.corelib.utils.LogShow
16
 import com.xhly.corelib.utils.SharedPreferencesUtils
18
 import com.xhly.corelib.utils.SharedPreferencesUtils
19
+import com.xhly.manageapp.ManageApplication
20
+import com.xhly.manageapp.bean.LogAppStartBean
17
 import com.xhly.manageapp.bean.LogdOperateBean
21
 import com.xhly.manageapp.bean.LogdOperateBean
18
 import com.xhly.manageapp.network.LogService
22
 import com.xhly.manageapp.network.LogService
19
 import com.xhly.websocket.service.LongConnService
23
 import com.xhly.websocket.service.LongConnService
20
 import com.xhly.websocket.utils.SocketPushUtils.dealPushMessage
24
 import com.xhly.websocket.utils.SocketPushUtils.dealPushMessage
21
 import kotlinx.coroutines.CoroutineScope
25
 import kotlinx.coroutines.CoroutineScope
22
-import kotlinx.coroutines.GlobalScope
23
 import kotlinx.coroutines.MainScope
26
 import kotlinx.coroutines.MainScope
24
 import kotlinx.coroutines.cancel
27
 import kotlinx.coroutines.cancel
25
 import kotlinx.coroutines.launch
28
 import kotlinx.coroutines.launch
32
     var CHANNEL_NAME = "通知"
35
     var CHANNEL_NAME = "通知"
33
     var logService = RetrofitService.create<LogService>()
36
     var logService = RetrofitService.create<LogService>()
34
     private val serviceScope = CoroutineScope(MainScope().coroutineContext)
37
     private val serviceScope = CoroutineScope(MainScope().coroutineContext)
38
+    private var appList = arrayListOf<AppInfo>()
39
+
40
+    //标记上次打开的包名,当连续打开同一包名时,不认为打开多次
41
+    private var lastPkgName = ""
35
 
42
 
36
     /*  private var csdkManager: CSDKManager? = null*/
43
     /*  private var csdkManager: CSDKManager? = null*/
37
     val spUtils by lazy { SharedPreferencesUtils.getInstance(this) }
44
     val spUtils by lazy { SharedPreferencesUtils.getInstance(this) }
38
 
45
 
39
     companion object {
46
     companion object {
40
         fun openWebSocket(context: Context) {
47
         fun openWebSocket(context: Context) {
48
+            LogShow("打开广播")
41
             context.startService(Intent(context, AppSocketService::class.java))
49
             context.startService(Intent(context, AppSocketService::class.java))
42
         }
50
         }
43
 
51
 
49
     override fun onCreate() {
57
     override fun onCreate() {
50
         super.onCreate()
58
         super.onCreate()
51
         EventBus.getDefault().register(this)
59
         EventBus.getDefault().register(this)
52
-        connectUrl = "wss://api.stsotc.com/api/ws"
60
+        connectUrl = "wss://mcwstest.xhkjedu.com/ws"
53
         /*   csdkManager = CSDKManager(this)*/
61
         /*   csdkManager = CSDKManager(this)*/
54
         /* startNotification()*/
62
         /* startNotification()*/
63
+        LogShow("已经创建")
64
+        appList = AppUtils.GetAppList(this) as ArrayList<AppInfo>
55
     }
65
     }
56
 
66
 
57
     override fun processTextMessage(text: String) {
67
     override fun processTextMessage(text: String) {
88
                 //csdkManager?.launchFactoryReset()
98
                 //csdkManager?.launchFactoryReset()
89
             }
99
             }
90
 
100
 
101
+            Const.LOGAPPSTART -> {
102
+                val message = uiEvent.message
103
+                val filter = appList.filter { it.packageName == message }
104
+                if (filter.isNotEmpty()) {
105
+                    val appInfo = filter[0]
106
+                    serviceScope.launch {
107
+                        val logStartBean = LogAppStartBean()
108
+                        ManageApplication.getDeviceInfo()?.let {
109
+                            logStartBean.sn = it
110
+                        }
111
+                        logStartBean.appName = appInfo.name
112
+                        logStartBean.appPackage = appInfo.packageName
113
+                        logStartBean.versionName = appInfo.versionName
114
+                        logStartBean.versionNum = appInfo.versionNum
115
+                    LogShow("当前应用"+logStartBean.appName+"|||"+logStartBean.versionName+"|||"+logStartBean.versionNum)
116
+                    //logService.postLogAppStartAdd(logStartBean)
117
+                    }
118
+                }
119
+            }
120
+
91
             "10086" -> {
121
             "10086" -> {
92
                 serviceScope.launch {
122
                 serviceScope.launch {
93
                     logService.postLogdoperateAdd(LogdOperateBean())
123
                     logService.postLogdoperateAdd(LogdOperateBean())
122
         stopForeground(Service.STOP_FOREGROUND_REMOVE)
152
         stopForeground(Service.STOP_FOREGROUND_REMOVE)
123
         /*  val intent=Intent(this,ManageService::class.java)
153
         /*  val intent=Intent(this,ManageService::class.java)
124
           startService(intent)*/
154
           startService(intent)*/
155
+        val intent = Intent()
156
+        intent.setPackage("com.xhly.manageapp")
157
+        intent.setAction("test")
158
+        sendBroadcast(intent)
159
+        LogShow("已经销毁")
125
     }
160
     }
126
 
161
 
127
     private fun startNotification() {
162
     private fun startNotification() {

+ 14
- 13
app/src/main/java/com/xhly/manageapp/ui/MainActivity.kt View File

28
 import com.xhly.corelib.utils.LogShow
28
 import com.xhly.corelib.utils.LogShow
29
 import com.xhly.manageapp.AppAdapter
29
 import com.xhly.manageapp.AppAdapter
30
 import com.xhly.manageapp.R
30
 import com.xhly.manageapp.R
31
-import com.xhly.manageapp.bean.LogdOperateBean
32
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
31
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
33
 import com.xhly.manageapp.databinding.ActivityMainBinding
32
 import com.xhly.manageapp.databinding.ActivityMainBinding
34
 import com.xhly.manageapp.network.LogService
33
 import com.xhly.manageapp.network.LogService
51
         if (user.isNullOrBlank()) {
50
         if (user.isNullOrBlank()) {
52
             startIntentActivity(LoginActivity().javaClass)
51
             startIntentActivity(LoginActivity().javaClass)
53
         }
52
         }
54
-        val getAppList1 = AppUtils.GetAppList1(this)
53
+        val getAppList1 = AppUtils.GetAppList(this)
55
         dataList.addAll(getAppList1)
54
         dataList.addAll(getAppList1)
56
         dataList.forEach {
55
         dataList.forEach {
57
             LogShow("数据" + it.packageName + "|||")
56
             LogShow("数据" + it.packageName + "|||")
71
          使用情况权限
70
          使用情况权限
72
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
71
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
73
           startActivity(permissionIntent)*/
72
           startActivity(permissionIntent)*/
74
-        AppSocketService.openWebSocket(this)
75
         // csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
73
         // csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
76
     }
74
     }
77
 
75
 
76
+    override fun onNewIntent(intent: Intent?) {
77
+        super.onNewIntent(intent)
78
+    }
78
     override fun initView() {
79
     override fun initView() {
79
-        var logService = RetrofitService.create<LogService>()
80
         mBinding.loginoutIv.setOnClickListener {
80
         mBinding.loginoutIv.setOnClickListener {
81
-           /* showEditDialog()*/
82
-            lifecycleScope.launch {
83
-                logService.postLogdoperateAdd(LogdOperateBean())
84
-            }
81
+            showEditDialog()
85
         }
82
         }
86
         mBinding.stoptv.setOnClickListener {
83
         mBinding.stoptv.setOnClickListener {
87
             spUtils.setParam(Const.DISABLEAPP, false)
84
             spUtils.setParam(Const.DISABLEAPP, false)
88
         }
85
         }
89
         onBackPressedDispatcher.addCallback {
86
         onBackPressedDispatcher.addCallback {
87
+          lifecycleScope.launch {
88
+              var logService = RetrofitService.create<LogService>()
89
+              logService.postListApp()
90
+          }
90
             //屏蔽返回
91
             //屏蔽返回
91
         }
92
         }
92
     }
93
     }
96
         super.onResume()
97
         super.onResume()
97
         getAppInfo()
98
         getAppInfo()
98
         useStrategy()
99
         useStrategy()
100
+        if (!isServiceON(this,AppSocketService::class.java.name)){
101
+            AppSocketService.openWebSocket(this)
102
+        }
99
         /*      lifecycleScope.launch(Dispatchers.IO) {
103
         /*      lifecycleScope.launch(Dispatchers.IO) {
100
                   delay(20000)
104
                   delay(20000)
101
                   withContext(Dispatchers.Main) {
105
                   withContext(Dispatchers.Main) {
147
         when (uiEvent.getEvent()) {
151
         when (uiEvent.getEvent()) {
148
             "update" -> {
152
             "update" -> {
149
                 dataList.clear()
153
                 dataList.clear()
150
-                val getAppList1 = AppUtils.GetAppList1(this)
154
+                val getAppList1 = AppUtils.GetAppList(this)
151
                 dataList.addAll(getAppList1)
155
                 dataList.addAll(getAppList1)
152
                 adapter.notifyDataSetChanged()
156
                 adapter.notifyDataSetChanged()
153
                 dataList.forEach {
157
                 dataList.forEach {
295
                     titleTv.text = getString(R.string.exit)
299
                     titleTv.text = getString(R.string.exit)
296
                     enterTv.setOnClickListener {
300
                     enterTv.setOnClickListener {
297
                         dialog.dismiss()
301
                         dialog.dismiss()
298
-                        val intent = Intent(Settings.ACTION_DEVICE_INFO_SETTINGS)
299
-                        startActivity(intent)
300
-
301
-                        //loginOut()
302
+                        loginOut()
302
                     }
303
                     }
303
                     cancelTv.setOnClickListener {
304
                     cancelTv.setOnClickListener {
304
                         dialog.dismiss()
305
                         dialog.dismiss()

+ 2
- 1
corelib/src/main/java/com/xhly/corelib/Const.kt View File

35
     //恢复出厂
35
     //恢复出厂
36
     const val CODE2006 = 2006
36
     const val CODE2006 = 2006
37
 
37
 
38
-
38
+    //应用启动日志
39
+    const val LOGAPPSTART="LOGAPPSTART"
39
 }
40
 }

+ 9
- 1
corelib/src/main/java/com/xhly/corelib/utils/AppUtils.java View File

5
 import android.content.ComponentName;
5
 import android.content.ComponentName;
6
 import android.content.Context;
6
 import android.content.Context;
7
 import android.content.Intent;
7
 import android.content.Intent;
8
+import android.content.pm.PackageInfo;
8
 import android.content.pm.PackageManager;
9
 import android.content.pm.PackageManager;
9
 import android.content.pm.ResolveInfo;
10
 import android.content.pm.ResolveInfo;
10
 
11
 
15
 import java.util.List;
16
 import java.util.List;
16
 
17
 
17
 public class AppUtils {
18
 public class AppUtils {
18
-    public static List<AppInfo> GetAppList1(Context context) {
19
+    public static List<AppInfo> GetAppList(Context context) {
19
         List<AppInfo> list = new ArrayList<>();
20
         List<AppInfo> list = new ArrayList<>();
20
         PackageManager pm = context.getPackageManager();
21
         PackageManager pm = context.getPackageManager();
21
         Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
22
         Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
31
             mInfo.setIco(info.activityInfo.applicationInfo.loadIcon(pm));
32
             mInfo.setIco(info.activityInfo.applicationInfo.loadIcon(pm));
32
             mInfo.setName(info.activityInfo.applicationInfo.loadLabel(pm).toString());
33
             mInfo.setName(info.activityInfo.applicationInfo.loadLabel(pm).toString());
33
             mInfo.setPackageName(packName);
34
             mInfo.setPackageName(packName);
35
+            try {
36
+                PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packName, PackageManager.GET_META_DATA);
37
+                 mInfo.setVersionName(packageInfo.versionName);
38
+                 mInfo.setVersionNum(packageInfo.versionCode);
39
+            } catch (PackageManager.NameNotFoundException e) {
40
+                throw new RuntimeException(e);
41
+            }
34
             // 为应用程序的启动Activity 准备Intent
42
             // 为应用程序的启动Activity 准备Intent
35
             Intent launchIntent = new Intent();
43
             Intent launchIntent = new Intent();
36
             launchIntent.setComponent(new ComponentName(packName,
44
             launchIntent.setComponent(new ComponentName(packName,

+ 3
- 1
websocket/src/main/java/com/xhly/websocket/utils/SocketPushUtils.kt View File

9
     fun dealPushMessage(content: String) {
9
     fun dealPushMessage(content: String) {
10
         try {
10
         try {
11
             //没用泛型是因为如果带有泛型的类型,可能会遇到解析异常的问题。需要使用TypeToken
11
             //没用泛型是因为如果带有泛型的类型,可能会遇到解析异常的问题。需要使用TypeToken
12
-            var socketData = GsonUtils.parseJsonWithGson(content, WebSocketData::class.java)
12
+          /*  var socketData = GsonUtils.parseJsonWithGson(content, WebSocketData::class.java)*/
13
+            LogShow("数据$content")
14
+            var socketData=WebSocketData()
13
             socketData.code.let { code ->
15
             socketData.code.let { code ->
14
                 when (code) {
16
                 when (code) {
15
                     1001 -> {
17
                     1001 -> {

Loading…
Cancel
Save