Ver código fonte

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

master
wangwanlei 10 meses atrás
pai
commit
ccd1cc5546

+ 1
- 0
app/src/main/AndroidManifest.xml Ver arquivo

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

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

@@ -1,13 +1,18 @@
1 1
 package com.xhly.manageapp.ui.main.activity
2 2
 
3 3
 import BaseActivity
4
+import android.Manifest
5
+import android.annotation.SuppressLint
4 6
 import android.app.ActivityManager
7
+import android.app.usage.StorageStatsManager
5 8
 import android.app.usage.UsageEvents
6 9
 import android.app.usage.UsageStatsManager
7 10
 import android.content.Context
8 11
 import android.content.Intent
9 12
 import android.content.IntentFilter
10 13
 import android.graphics.Color
14
+import android.os.Build
15
+import android.os.storage.StorageManager
11 16
 import android.provider.Settings
12 17
 import android.view.View
13 18
 import android.widget.Button
@@ -15,16 +20,19 @@ import android.widget.EditText
15 20
 import android.widget.TextView
16 21
 import android.widget.Toast
17 22
 import androidx.activity.addCallback
18
-import androidx.lifecycle.lifecycleScope
19 23
 import androidx.recyclerview.widget.GridLayoutManager
20 24
 import com.kongzue.dialogx.dialogs.CustomDialog
21 25
 import com.kongzue.dialogx.interfaces.OnBindView
26
+import com.tbruyelle.rxpermissions2.RxPermissions
22 27
 import com.xhly.corelib.Const
23
-import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
24 28
 import com.xhly.corelib.bean.AppInfo
25 29
 import com.xhly.corelib.eventbus.UIEvent
26 30
 import com.xhly.corelib.utils.AppUtils
31
+import com.xhly.corelib.utils.CustomOSUtils
32
+import com.xhly.corelib.utils.FileSizeUtil
27 33
 import com.xhly.corelib.utils.LogShow
34
+import com.xhly.corelib.utils.PhoneInfoUtils
35
+import com.xhly.corelib.utils.toFormat
28 36
 import com.xhly.manageapp.AppAdapter
29 37
 import com.xhly.manageapp.R
30 38
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
@@ -34,12 +42,12 @@ import com.xhly.manageapp.service.websocket.AppSocketService
34 42
 import com.xhly.manageapp.ui.ManageActivity
35 43
 import com.xhly.manageapp.ui.login.activity.LoginActivity
36 44
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
37
-import kotlinx.coroutines.launch
38 45
 import java.util.Calendar
39 46
 
40 47
 
41 48
 class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
42 49
     lateinit var adapter: AppAdapter
50
+
43 51
     /*private var csdkManager = CSDKManager(this)*/
44 52
     private var mMyInstallReceiver: AppInstallReceiver? = null
45 53
     private var dataList: ArrayList<AppInfo> = arrayListOf()
@@ -51,6 +59,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
51 59
             startIntentActivity(LoginActivity().javaClass)
52 60
         }
53 61
         val getAppList1 = AppUtils.GetAppList(this)
62
+        spUtils.get(Const.DISABLEAPP)
54 63
         dataList.addAll(getAppList1)
55 64
         adapter = AppAdapter(this, dataList)
56 65
         mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
@@ -62,17 +71,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
62 71
         mBinding.resetbtn.setOnClickListener {
63 72
             UIEvent("2005").post()
64 73
         }
65
-        registerAppInstallReceiver()
66
-        /*
74
+        registerAppInstallReceiver()/*
67 75
          使用情况权限
68 76
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
69 77
           startActivity(permissionIntent)*/
70 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 87
     override fun onNewIntent(intent: Intent?) {
74 88
         super.onNewIntent(intent)
75 89
     }
90
+
76 91
     override fun initView() {
77 92
         mBinding.loginoutIv.setOnClickListener {
78 93
             showEditDialog()
@@ -81,30 +96,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
81 96
             spUtils.setParam(Const.DISABLEAPP, false)
82 97
         }
83 98
         onBackPressedDispatcher.addCallback {
84
-          lifecycleScope.launch {
85
-            viewModel.getAppList()
86
-          }
87 99
             //屏蔽返回
100
+            getAppInfo()
88 101
         }
89 102
     }
90 103
 
91 104
 
92 105
     override fun onResume() {
93 106
         super.onResume()
94
-        AppSocketService.lastPkgName=""
95
-        getAppInfo()
107
+        AppSocketService.lastPkgName = ""/*getAppInfo()*/
96 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 118
     private fun useStrategy() {
@@ -117,30 +125,30 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
117 125
                 mBinding.stoptv.visibility = View.GONE
118 126
             }
119 127
             changeWhiteList()
128
+            viewModel.updateStrategy()
120 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 154
     override fun onUiEvent(uiEvent: UIEvent) {
@@ -155,15 +163,16 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
155 163
                     LogShow("app包名" + it.packageName)
156 164
                 }
157 165
             }
166
+
158 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,11 +183,10 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
174 183
 
175 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 190
         val usageManager = getSystemService(USAGE_STATS_SERVICE) as UsageStatsManager
183 191
         if (usageManager != null) {
184 192
             val intervalType = UsageStatsManager.INTERVAL_DAILY
@@ -213,6 +221,11 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
213 221
                         if (event.packageName.equals("com.xhly.manageapp")) {
214 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 231
                     UsageEvents.Event.ACTIVITY_PAUSED -> {
@@ -224,6 +237,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
224 237
                             }
225 238
                             it.foregroundTime += (event.timeStamp - it.startTime)
226 239
                         }
240
+                        if (event.packageName.equals("mark.via")) {
241
+                            LogShow("关闭时间" + event.timeStamp.toFormat())
242
+                        }
227 243
                         if (event.packageName.equals("com.xhly.manageapp")) {
228 244
                             totalTime += (event.timeStamp - totalStartTime)
229 245
                         }
@@ -232,12 +248,12 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
232 248
             }
233 249
 
234 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 253
             if (totalTime > 0L) {
238
-                LogShow("events应用时长统计com.xhly.manageapp使用时间" + millisecondsToHMS(totalTime))
254
+                // LogShow("events应用时长统计com.xhly.manageapp使用时间" + millisecondsToHMS(totalTime))
239 255
             } else {
240
-                LogShow("events应用时长统计com.xhly.manageapp使用时间无法获取")
256
+                // LogShow("events应用时长统计com.xhly.manageapp使用时间无法获取")
241 257
             }
242 258
         }
243 259
     }
@@ -247,8 +263,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
247 263
         if (!isServiceON(this, ManageAccessibilityService::class.java.name)) {
248 264
             // 引导至辅助功能设置页面
249 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 268
             Toast.makeText(context, "请先开启 \"Activity 栈\" 的辅助功能", Toast.LENGTH_LONG).show()
254 269
             return false
@@ -294,8 +309,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
294 309
 
295 310
 
296 311
     private fun showEditDialog() {
297
-        CustomDialog
298
-            .build()
312
+        CustomDialog.build()
299 313
             .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_edit_dialog) {
300 314
                 override fun onBind(dialog: CustomDialog, v: View) {
301 315
                     var titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
@@ -317,9 +331,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
317 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 336
             .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_notice_dialog) {
324 337
                 override fun onBind(dialog: CustomDialog, v: View) {
325 338
                     var closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
@@ -345,4 +358,24 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
345 358
         }
346 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 Ver arquivo

@@ -1,20 +1,51 @@
1 1
 package com.xhly.manageapp.ui.main.viewmodel
2 2
 
3
+import androidx.lifecycle.LiveData
4
+import androidx.lifecycle.MutableLiveData
3 5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
4 6
 import com.xhly.corelib.network.RetrofitService
5
-import com.xhly.corelib.utils.LogShow
7
+import com.xhly.manageapp.bean.AppModel
6 8
 import com.xhly.manageapp.bean.ListAppBean
9
+import com.xhly.manageapp.bean.strategy.StrategyBean
7 10
 import com.xhly.manageapp.network.app.AppService
11
+import com.xhly.manageapp.network.strategy.StrategyService
8 12
 
9 13
 class MainViewModel : CommonBaseViewModel() {
10 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 20
     fun getAppList() {
13 21
         launchUI {
14 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
 }

Carregando…
Cancelar
Salvar