Browse Source

1.主页增加平板策略请求

master
wangwanlei 10 months ago
parent
commit
ccd1cc5546

+ 1
- 0
app/src/main/AndroidManifest.xml View File

36
         android:label="@string/app_name"
36
         android:label="@string/app_name"
37
         android:networkSecurityConfig="@xml/network_security_config"
37
         android:networkSecurityConfig="@xml/network_security_config"
38
         android:roundIcon="@mipmap/ic_launcher_round"
38
         android:roundIcon="@mipmap/ic_launcher_round"
39
+        android:appComponentFactory="androidx.core.app.CoreComponentFactory"
39
         android:supportsRtl="true"
40
         android:supportsRtl="true"
40
         android:theme="@style/MyStyle"
41
         android:theme="@style/MyStyle"
41
         tools:targetApi="31">
42
         tools:targetApi="31">

+ 95
- 62
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

1
 package com.xhly.manageapp.ui.main.activity
1
 package com.xhly.manageapp.ui.main.activity
2
 
2
 
3
 import BaseActivity
3
 import BaseActivity
4
+import android.Manifest
5
+import android.annotation.SuppressLint
4
 import android.app.ActivityManager
6
 import android.app.ActivityManager
7
+import android.app.usage.StorageStatsManager
5
 import android.app.usage.UsageEvents
8
 import android.app.usage.UsageEvents
6
 import android.app.usage.UsageStatsManager
9
 import android.app.usage.UsageStatsManager
7
 import android.content.Context
10
 import android.content.Context
8
 import android.content.Intent
11
 import android.content.Intent
9
 import android.content.IntentFilter
12
 import android.content.IntentFilter
10
 import android.graphics.Color
13
 import android.graphics.Color
14
+import android.os.Build
15
+import android.os.storage.StorageManager
11
 import android.provider.Settings
16
 import android.provider.Settings
12
 import android.view.View
17
 import android.view.View
13
 import android.widget.Button
18
 import android.widget.Button
15
 import android.widget.TextView
20
 import android.widget.TextView
16
 import android.widget.Toast
21
 import android.widget.Toast
17
 import androidx.activity.addCallback
22
 import androidx.activity.addCallback
18
-import androidx.lifecycle.lifecycleScope
19
 import androidx.recyclerview.widget.GridLayoutManager
23
 import androidx.recyclerview.widget.GridLayoutManager
20
 import com.kongzue.dialogx.dialogs.CustomDialog
24
 import com.kongzue.dialogx.dialogs.CustomDialog
21
 import com.kongzue.dialogx.interfaces.OnBindView
25
 import com.kongzue.dialogx.interfaces.OnBindView
26
+import com.tbruyelle.rxpermissions2.RxPermissions
22
 import com.xhly.corelib.Const
27
 import com.xhly.corelib.Const
23
-import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
24
 import com.xhly.corelib.bean.AppInfo
28
 import com.xhly.corelib.bean.AppInfo
25
 import com.xhly.corelib.eventbus.UIEvent
29
 import com.xhly.corelib.eventbus.UIEvent
26
 import com.xhly.corelib.utils.AppUtils
30
 import com.xhly.corelib.utils.AppUtils
31
+import com.xhly.corelib.utils.CustomOSUtils
32
+import com.xhly.corelib.utils.FileSizeUtil
27
 import com.xhly.corelib.utils.LogShow
33
 import com.xhly.corelib.utils.LogShow
34
+import com.xhly.corelib.utils.PhoneInfoUtils
35
+import com.xhly.corelib.utils.toFormat
28
 import com.xhly.manageapp.AppAdapter
36
 import com.xhly.manageapp.AppAdapter
29
 import com.xhly.manageapp.R
37
 import com.xhly.manageapp.R
30
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
38
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
34
 import com.xhly.manageapp.ui.ManageActivity
42
 import com.xhly.manageapp.ui.ManageActivity
35
 import com.xhly.manageapp.ui.login.activity.LoginActivity
43
 import com.xhly.manageapp.ui.login.activity.LoginActivity
36
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
44
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
37
-import kotlinx.coroutines.launch
38
 import java.util.Calendar
45
 import java.util.Calendar
39
 
46
 
40
 
47
 
41
 class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
48
 class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
42
     lateinit var adapter: AppAdapter
49
     lateinit var adapter: AppAdapter
50
+
43
     /*private var csdkManager = CSDKManager(this)*/
51
     /*private var csdkManager = CSDKManager(this)*/
44
     private var mMyInstallReceiver: AppInstallReceiver? = null
52
     private var mMyInstallReceiver: AppInstallReceiver? = null
45
     private var dataList: ArrayList<AppInfo> = arrayListOf()
53
     private var dataList: ArrayList<AppInfo> = arrayListOf()
51
             startIntentActivity(LoginActivity().javaClass)
59
             startIntentActivity(LoginActivity().javaClass)
52
         }
60
         }
53
         val getAppList1 = AppUtils.GetAppList(this)
61
         val getAppList1 = AppUtils.GetAppList(this)
62
+        spUtils.get(Const.DISABLEAPP)
54
         dataList.addAll(getAppList1)
63
         dataList.addAll(getAppList1)
55
         adapter = AppAdapter(this, dataList)
64
         adapter = AppAdapter(this, dataList)
56
         mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
65
         mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
62
         mBinding.resetbtn.setOnClickListener {
71
         mBinding.resetbtn.setOnClickListener {
63
             UIEvent("2005").post()
72
             UIEvent("2005").post()
64
         }
73
         }
65
-        registerAppInstallReceiver()
66
-        /*
74
+        registerAppInstallReceiver()/*
67
          使用情况权限
75
          使用情况权限
68
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
76
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
69
           startActivity(permissionIntent)*/
77
           startActivity(permissionIntent)*/
70
         // csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
78
         // csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
79
+        viewModel.getAppList()
80
+        viewModel.listAppData.observe(this) {
81
+            //获得应用集合,必装应用和推荐应用,再加上预装应用,其余应用需要静默卸载,必装应用需要进行静默下载和安装。
82
+            var appList = AppUtils.GetAppList(this)
83
+
84
+        }
71
     }
85
     }
72
 
86
 
73
     override fun onNewIntent(intent: Intent?) {
87
     override fun onNewIntent(intent: Intent?) {
74
         super.onNewIntent(intent)
88
         super.onNewIntent(intent)
75
     }
89
     }
90
+
76
     override fun initView() {
91
     override fun initView() {
77
         mBinding.loginoutIv.setOnClickListener {
92
         mBinding.loginoutIv.setOnClickListener {
78
             showEditDialog()
93
             showEditDialog()
81
             spUtils.setParam(Const.DISABLEAPP, false)
96
             spUtils.setParam(Const.DISABLEAPP, false)
82
         }
97
         }
83
         onBackPressedDispatcher.addCallback {
98
         onBackPressedDispatcher.addCallback {
84
-          lifecycleScope.launch {
85
-            viewModel.getAppList()
86
-          }
87
             //屏蔽返回
99
             //屏蔽返回
100
+            getAppInfo()
88
         }
101
         }
89
     }
102
     }
90
 
103
 
91
 
104
 
92
     override fun onResume() {
105
     override fun onResume() {
93
         super.onResume()
106
         super.onResume()
94
-        AppSocketService.lastPkgName=""
95
-        getAppInfo()
107
+        AppSocketService.lastPkgName = ""/*getAppInfo()*/
96
         useStrategy()
108
         useStrategy()
97
-    /*    if (!isServiceON(this,AppSocketService::class.java.name)){
98
-            AppSocketService.openWebSocket(this)
99
-        }*/
100
-        /*      lifecycleScope.launch(Dispatchers.IO) {
101
-                  delay(20000)
102
-                  withContext(Dispatchers.Main) {
103
-                      Toast("冻结应用")
104
-                      *//*csdkManager.setPackageEnabled("com.android.calendar", true)*//*
105
-                *//* ManageApplication.killApplicationProcess("com.android.calendar")*//*
106
-            }
107
-        }*/
109
+        try {
110
+            var s =
111
+                "厂商" + CustomOSUtils.getSystemBrand() + ",型号" + CustomOSUtils.getSystemDevice() + ",系统版本" + CustomOSUtils.getSystemDisplay()
112
+        } catch (e: Exception) {
113
+            LogShow("没有数据")
114
+        }
115
+        requestPermissionAndShotView()
108
     }
116
     }
109
 
117
 
110
     private fun useStrategy() {
118
     private fun useStrategy() {
117
                 mBinding.stoptv.visibility = View.GONE
125
                 mBinding.stoptv.visibility = View.GONE
118
             }
126
             }
119
             changeWhiteList()
127
             changeWhiteList()
128
+            viewModel.updateStrategy()
120
         } catch (e: Exception) {
129
         } catch (e: Exception) {
121
 
130
 
122
         }
131
         }
123
     }
132
     }
124
 
133
 
125
-    private fun changeWhiteList() {
126
-/*        //获得当前白名单
127
-        val packageWhiteList = csdkManager.installPackageWhiteList
128
-        LogShow("当前白名单$packageWhiteList")
129
-        //获得从网络获取的白名单
130
-        val jsonArray = spUtils.getFromJson(Const.WHITELISTAPP, ArrayList<String>().javaClass)
131
-        val removeList = arrayListOf<String>()
132
-        //移除白名单外的应用,并设置新的白名单
133
-        if (jsonArray != null) {
134
-            val whiteList = jsonArray as ArrayList<String>
135
-            packageWhiteList.forEach { pkg ->
136
-                val filter = whiteList.filter { it == pkg }
137
-                if (filter.isEmpty()) {
138
-                    removeList.add(pkg)
134
+    private fun changeWhiteList() {/*        //获得当前白名单
135
+                val packageWhiteList = csdkManager.installPackageWhiteList
136
+                LogShow("当前白名单$packageWhiteList")
137
+                //获得从网络获取的白名单
138
+                val jsonArray = spUtils.getFromJson(Const.WHITELISTAPP, ArrayList<String>().javaClass)
139
+                val removeList = arrayListOf<String>()
140
+                //移除白名单外的应用,并设置新的白名单
141
+                if (jsonArray != null) {
142
+                    val whiteList = jsonArray as ArrayList<String>
143
+                    packageWhiteList.forEach { pkg ->
144
+                        val filter = whiteList.filter { it == pkg }
145
+                        if (filter.isEmpty()) {
146
+                            removeList.add(pkg)
147
+                        }
148
+                    }
149
+                    ManageApplication.addInstallPackageWhiteList(whiteList)
139
                 }
150
                 }
140
-            }
141
-            ManageApplication.addInstallPackageWhiteList(whiteList)
142
-        }
143
-        ManageApplication.removeInstallPackageWhiteList(removeList)*/
151
+                ManageApplication.removeInstallPackageWhiteList(removeList)*/
144
     }
152
     }
145
 
153
 
146
     override fun onUiEvent(uiEvent: UIEvent) {
154
     override fun onUiEvent(uiEvent: UIEvent) {
155
                     LogShow("app包名" + it.packageName)
163
                     LogShow("app包名" + it.packageName)
156
                 }
164
                 }
157
             }
165
             }
166
+
158
             Const.APPINSTALL -> {
167
             Const.APPINSTALL -> {
159
-               try {
160
-                   dataList.clear()
161
-                   val getAppList1 = AppUtils.GetAppList(this)
162
-                   dataList.addAll(getAppList1)
163
-                   adapter.notifyDataSetChanged()
164
-               }catch (e:Exception){
165
-
166
-               }
168
+                try {
169
+                    dataList.clear()
170
+                    val getAppList1 = AppUtils.GetAppList(this)
171
+                    dataList.addAll(getAppList1)
172
+                    adapter.notifyDataSetChanged()
173
+                } catch (e: Exception) {
174
+
175
+                }
167
             }
176
             }
168
 
177
 
169
             "策略更新" -> {
178
             "策略更新" -> {
174
 
183
 
175
     private fun getAppInfo() {
184
     private fun getAppInfo() {
176
         //统计使用时长
185
         //统计使用时长
177
-        var instance = Calendar.getInstance()
178
-        instance.set(Calendar.HOUR_OF_DAY, 0)
179
-        instance.set(Calendar.MINUTE, 0)
180
-        instance.set(Calendar.SECOND, 1)
181
-        var timeInMillis = instance.timeInMillis
186
+        var instance = Calendar.getInstance()/*  instance.set(Calendar.HOUR_OF_DAY, 0)
187
+          instance.set(Calendar.MINUTE, 0)
188
+          instance.set(Calendar.SECOND, 1)*/
189
+        var timeInMillis = instance.timeInMillis - 1000 * 60 * 10
182
         val usageManager = getSystemService(USAGE_STATS_SERVICE) as UsageStatsManager
190
         val usageManager = getSystemService(USAGE_STATS_SERVICE) as UsageStatsManager
183
         if (usageManager != null) {
191
         if (usageManager != null) {
184
             val intervalType = UsageStatsManager.INTERVAL_DAILY
192
             val intervalType = UsageStatsManager.INTERVAL_DAILY
213
                         if (event.packageName.equals("com.xhly.manageapp")) {
221
                         if (event.packageName.equals("com.xhly.manageapp")) {
214
                             totalStartTime = event.timeStamp
222
                             totalStartTime = event.timeStamp
215
                         }
223
                         }
224
+
225
+                        if (event.packageName.equals("mark.via")) {
226
+                            LogShow("打开时间" + event.timeStamp.toFormat())
227
+
228
+                        }
216
                     }
229
                     }
217
 
230
 
218
                     UsageEvents.Event.ACTIVITY_PAUSED -> {
231
                     UsageEvents.Event.ACTIVITY_PAUSED -> {
224
                             }
237
                             }
225
                             it.foregroundTime += (event.timeStamp - it.startTime)
238
                             it.foregroundTime += (event.timeStamp - it.startTime)
226
                         }
239
                         }
240
+                        if (event.packageName.equals("mark.via")) {
241
+                            LogShow("关闭时间" + event.timeStamp.toFormat())
242
+                        }
227
                         if (event.packageName.equals("com.xhly.manageapp")) {
243
                         if (event.packageName.equals("com.xhly.manageapp")) {
228
                             totalTime += (event.timeStamp - totalStartTime)
244
                             totalTime += (event.timeStamp - totalStartTime)
229
                         }
245
                         }
232
             }
248
             }
233
 
249
 
234
             dataList.filter { it.foregroundTime > 0L }.forEach {
250
             dataList.filter { it.foregroundTime > 0L }.forEach {
235
-                LogShow("events应用时长统计" + it.name + "使用时间" + millisecondsToHMS(it.foregroundTime))
251
+                // LogShow("events应用时长统计" + it.name + "使用时间" + millisecondsToHMS(it.foregroundTime))
236
             }
252
             }
237
             if (totalTime > 0L) {
253
             if (totalTime > 0L) {
238
-                LogShow("events应用时长统计com.xhly.manageapp使用时间" + millisecondsToHMS(totalTime))
254
+                // LogShow("events应用时长统计com.xhly.manageapp使用时间" + millisecondsToHMS(totalTime))
239
             } else {
255
             } else {
240
-                LogShow("events应用时长统计com.xhly.manageapp使用时间无法获取")
256
+                // LogShow("events应用时长统计com.xhly.manageapp使用时间无法获取")
241
             }
257
             }
242
         }
258
         }
243
     }
259
     }
247
         if (!isServiceON(this, ManageAccessibilityService::class.java.name)) {
263
         if (!isServiceON(this, ManageAccessibilityService::class.java.name)) {
248
             // 引导至辅助功能设置页面
264
             // 引导至辅助功能设置页面
249
             context.startActivity(
265
             context.startActivity(
250
-                Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
251
-                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
266
+                Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
252
             )
267
             )
253
             Toast.makeText(context, "请先开启 \"Activity 栈\" 的辅助功能", Toast.LENGTH_LONG).show()
268
             Toast.makeText(context, "请先开启 \"Activity 栈\" 的辅助功能", Toast.LENGTH_LONG).show()
254
             return false
269
             return false
294
 
309
 
295
 
310
 
296
     private fun showEditDialog() {
311
     private fun showEditDialog() {
297
-        CustomDialog
298
-            .build()
312
+        CustomDialog.build()
299
             .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_edit_dialog) {
313
             .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_edit_dialog) {
300
                 override fun onBind(dialog: CustomDialog, v: View) {
314
                 override fun onBind(dialog: CustomDialog, v: View) {
301
                     var titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
315
                     var titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
317
             .setAlign(CustomDialog.ALIGN.CENTER).show()
331
             .setAlign(CustomDialog.ALIGN.CENTER).show()
318
     }
332
     }
319
 
333
 
320
-    private fun showNoticeDialog(){
321
-        CustomDialog
322
-            .build()
334
+    private fun showNoticeDialog() {
335
+        CustomDialog.build()
323
             .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_notice_dialog) {
336
             .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_notice_dialog) {
324
                 override fun onBind(dialog: CustomDialog, v: View) {
337
                 override fun onBind(dialog: CustomDialog, v: View) {
325
                     var closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
338
                     var closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
345
         }
358
         }
346
         LogShow("MainActivity被销毁")
359
         LogShow("MainActivity被销毁")
347
     }
360
     }
361
+
362
+    /**
363
+     * 请求运行时权限
364
+     */
365
+    @SuppressLint("CheckResult")
366
+    private fun requestPermissionAndShotView() {
367
+        val phoneInfoUtils = PhoneInfoUtils(this)
368
+
369
+        var iccid = ""
370
+        val rxPermissions = RxPermissions(this)
371
+        var request = rxPermissions.request(Manifest.permission.READ_PHONE_STATE)
372
+        request.subscribe({ granted: Boolean ->
373
+            if (granted) {
374
+                iccid = phoneInfoUtils.iccid
375
+                LogShow("手机信息" + iccid + "||" + iccid)
376
+            }
377
+        }, {
378
+            LogShow("手机信息失败了" + it.message)
379
+        })
380
+    }
348
 }
381
 }

+ 35
- 4
app/src/main/java/com/xhly/manageapp/ui/main/viewmodel/MainViewModel.kt View File

1
 package com.xhly.manageapp.ui.main.viewmodel
1
 package com.xhly.manageapp.ui.main.viewmodel
2
 
2
 
3
+import androidx.lifecycle.LiveData
4
+import androidx.lifecycle.MutableLiveData
3
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
4
 import com.xhly.corelib.network.RetrofitService
6
 import com.xhly.corelib.network.RetrofitService
5
-import com.xhly.corelib.utils.LogShow
7
+import com.xhly.manageapp.bean.AppModel
6
 import com.xhly.manageapp.bean.ListAppBean
8
 import com.xhly.manageapp.bean.ListAppBean
9
+import com.xhly.manageapp.bean.strategy.StrategyBean
7
 import com.xhly.manageapp.network.app.AppService
10
 import com.xhly.manageapp.network.app.AppService
11
+import com.xhly.manageapp.network.strategy.StrategyService
8
 
12
 
9
 class MainViewModel : CommonBaseViewModel() {
13
 class MainViewModel : CommonBaseViewModel() {
10
     private val appService by lazy { RetrofitService.create<AppService>() }
14
     private val appService by lazy { RetrofitService.create<AppService>() }
11
-
15
+    private val strategyService by lazy { RetrofitService.create<StrategyService>() }
16
+    private val listData = MutableLiveData<ArrayList<AppModel>>()
17
+    val listAppData: LiveData<ArrayList<AppModel>> = listData
18
+    private val strategy=MutableLiveData<StrategyBean>()
19
+    val strategyData=strategy
12
     fun getAppList() {
20
     fun getAppList() {
13
         launchUI {
21
         launchUI {
14
             val postListApp = appService.postListApp(ListAppBean())
22
             val postListApp = appService.postListApp(ListAppBean())
15
-            postListApp.obj.forEach {
16
-                LogShow("数据是" + it.appName)
23
+            if (postListApp.code == 0) {
24
+                if (postListApp.obj != null && postListApp.obj.isNotEmpty()) {
25
+                    listData.value = postListApp.obj
26
+                } else {
27
+                    listData.value = arrayListOf()
28
+                }
29
+            } else {
30
+                if (!postListApp.msg.isNullOrEmpty()) {
31
+                    netMessage.value = postListApp.msg
32
+                }
17
             }
33
             }
18
         }
34
         }
19
     }
35
     }
36
+
37
+    fun updateStrategy() {
38
+          launchUI {
39
+              val postDetailPad = strategyService.postDetailPad()
40
+              if (postDetailPad.code == 0) {
41
+                  if (postDetailPad.obj != null) {
42
+                     strategy.value=postDetailPad.obj
43
+                  }
44
+              } else {
45
+                  if (!postDetailPad.msg.isNullOrEmpty()) {
46
+                      netMessage.value = postDetailPad.msg
47
+                  }
48
+              }
49
+          }
50
+    }
20
 }
51
 }

Loading…
Cancel
Save