Browse Source

1.修改FileProvider的名称

20241218TB223FC(测试jar包)
wangwanlei 9 months ago
parent
commit
fac5060e73

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

161
 
161
 
162
         <provider
162
         <provider
163
             android:name="androidx.core.content.FileProvider"
163
             android:name="androidx.core.content.FileProvider"
164
-            android:authorities="com.xhly.manageapp.fileprovider"
164
+            android:authorities="com.xhkjedu.manageapp.fileprovider"
165
             android:exported="false"
165
             android:exported="false"
166
             android:grantUriPermissions="true">
166
             android:grantUriPermissions="true">
167
             <!-- 元数据 -->
167
             <!-- 元数据 -->

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

7
 import android.content.Context
7
 import android.content.Context
8
 import android.content.Intent
8
 import android.content.Intent
9
 import android.content.IntentFilter
9
 import android.content.IntentFilter
10
-import android.content.pm.PackageInfo
11
 import android.content.pm.PackageManager
10
 import android.content.pm.PackageManager
12
 import android.graphics.Color
11
 import android.graphics.Color
13
 import android.graphics.drawable.BitmapDrawable
12
 import android.graphics.drawable.BitmapDrawable
44
 import com.xhly.corelib.utils.GsonUtils
43
 import com.xhly.corelib.utils.GsonUtils
45
 import com.xhly.corelib.utils.ImageUtils
44
 import com.xhly.corelib.utils.ImageUtils
46
 import com.xhly.corelib.utils.LogShow
45
 import com.xhly.corelib.utils.LogShow
47
-import com.xhly.corelib.utils.MD5Utils
46
+import com.xhly.corelib.utils.ModelNameUtils
48
 import com.xhly.corelib.utils.SharedPreferencesUtils
47
 import com.xhly.corelib.utils.SharedPreferencesUtils
49
 import com.xhly.corelib.utils.SystemUtil
48
 import com.xhly.corelib.utils.SystemUtil
50
 import com.xhly.manageapp.AppAdapter
49
 import com.xhly.manageapp.AppAdapter
52
 import com.xhly.manageapp.bean.EventLog
51
 import com.xhly.manageapp.bean.EventLog
53
 import com.xhly.manageapp.bean.SocketMsgBean
52
 import com.xhly.manageapp.bean.SocketMsgBean
54
 import com.xhly.manageapp.bean.app.AppInstallBean
53
 import com.xhly.manageapp.bean.app.AppInstallBean
55
-import com.xhly.manageapp.bean.app.AppModel
56
 import com.xhly.manageapp.bean.log.LogPushBean
54
 import com.xhly.manageapp.bean.log.LogPushBean
57
 import com.xhly.manageapp.bean.log.LogdOperateBean
55
 import com.xhly.manageapp.bean.log.LogdOperateBean
58
 import com.xhly.manageapp.bean.log.UpdateBean
56
 import com.xhly.manageapp.bean.log.UpdateBean
89
     private var userBean: UserBean? = null
87
     private var userBean: UserBean? = null
90
     private var timer: Timer? = null
88
     private var timer: Timer? = null
91
     private val currentSpUtils by lazy { CurrentAppSharedPreferencesUtils.getInstance(this) }
89
     private val currentSpUtils by lazy { CurrentAppSharedPreferencesUtils.getInstance(this) }
90
+
92
     //标记是否请求了时间策略
91
     //标记是否请求了时间策略
93
-    private var updateTimeFlag=false
92
+    private var updateTimeFlag = false
93
+
94
     //标记是否请求了应用策略,都为真则提示
94
     //标记是否请求了应用策略,都为真则提示
95
-    private var updateStrategyFlag=false
95
+    private var updateStrategyFlag = false
96
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
96
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
97
 
97
 
98
+    @SuppressLint("CheckResult")
98
     override fun initData() {
99
     override fun initData() {
99
         val json = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass)
100
         val json = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass)
100
         if (json == null) {
101
         if (json == null) {
104
             userBean = json as UserBean
105
             userBean = json as UserBean
105
         }
106
         }
106
         lifecycleScope.launch {
107
         lifecycleScope.launch {
107
-            withContext(Dispatchers.IO){
108
+            withContext(Dispatchers.IO) {
108
                 val file = File(filesDir, "wallpaper.png")
109
                 val file = File(filesDir, "wallpaper.png")
109
-                if (file.exists()){
110
+                if (file.exists()) {
110
                     try {
111
                     try {
111
                         val bitmap = ImageUtils().getBitmapFromFile(file.toString())
112
                         val bitmap = ImageUtils().getBitmapFromFile(file.toString())
112
-                        withContext(Dispatchers.Main){
113
+                        withContext(Dispatchers.Main) {
113
                             try {
114
                             try {
114
-                                mBinding.root.background=BitmapDrawable(resources,bitmap)
115
-                            }catch (e:Exception){
115
+                                mBinding.root.background = BitmapDrawable(resources, bitmap)
116
+                            } catch (e: Exception) {
116
                                 LogShow("图片设置失败")
117
                                 LogShow("图片设置失败")
117
                             }
118
                             }
118
                         }
119
                         }
119
-                    }catch (e:Exception){
120
+                    } catch (e: Exception) {
120
                         LogShow("图片不存在")
121
                         LogShow("图片不存在")
121
                     }
122
                     }
122
                 }
123
                 }
176
         }
177
         }
177
         viewModel.forceListAppData.observe(this) { modelList ->
178
         viewModel.forceListAppData.observe(this) { modelList ->
178
             //获得必装应用,未安装或者版本较低则更新,先删除目录中的文件
179
             //获得必装应用,未安装或者版本较低则更新,先删除目录中的文件
179
-            val appList = AppUtils.GetAppList(this)
180
-            getExternalFilesDir(null)?.let {
181
-                FileUtils.deleteCurrentFlie(it)
182
-            }
183
-            modelList.forEach { app ->
184
-               try {
185
-                   //获得已安装的应用判断版本,未安装的则直接静默安装。
186
-                   val filter = appList.filter { it.packageName.equals(app.appPackage) }
187
-                   //列表中不存在,或者版本较低则更新
188
-                   val apkPath = app.apkPath
189
-                   val appName = app.appName
190
-                   if (filter.isNotEmpty()) {
191
-                       val currentApp = filter[0]
192
-                       if (app.versionNum > currentApp.versionNum) {
193
-                           //版本低则更新安装。
194
-                           viewModel.viewModelScope.launch {
195
-                               AppDownLoadUtils.addToDownloadQueue(apkPath, appName)
196
-                           }
197
-                       }
198
-                   } else {
199
-                       //不存在,直接下载安装。
200
-                       viewModel.viewModelScope.launch {
201
-                           AppDownLoadUtils.addToDownloadQueue(apkPath, appName)
202
-                       }
203
-                   }
204
-               }catch (e:Exception){
205
-                   LogShow("问题"+e.toString())
206
-               }
207
-            }
180
+            val rxPermissions = RxPermissions(this)
181
+            rxPermissions.request(Manifest.permission.REQUEST_INSTALL_PACKAGES)
182
+                .subscribe { granted ->
183
+                    if (granted || ModelNameUtils.IS_LianxX505f()) {
184
+                        // 权限已授予,执行安装操作
185
+                        val appList = AppUtils.GetAppList(this)
186
+                        getExternalFilesDir(null)?.let {
187
+                            FileUtils.deleteCurrentFlie(it)
188
+                        }
189
+                        modelList.forEach { app ->
190
+                            try {
191
+                                //获得已安装的应用判断版本,未安装的则直接静默安装。
192
+                                val filter =
193
+                                    appList.filter { it.packageName.equals(app.appPackage) }
194
+                                //列表中不存在,或者版本较低则更新
195
+                                val apkPath = app.apkPath
196
+                                val appName = app.appName
197
+                                if (filter.isNotEmpty()) {
198
+                                    val currentApp = filter[0]
199
+                                    if (app.versionNum > currentApp.versionNum) {
200
+                                        //版本低则更新安装。
201
+                                        viewModel.viewModelScope.launch {
202
+                                            AppDownLoadUtils.addToDownloadQueue(apkPath, appName)
203
+                                        }
204
+                                    }
205
+                                } else {
206
+                                    //不存在,直接下载安装。
207
+                                    viewModel.viewModelScope.launch {
208
+                                        AppDownLoadUtils.addToDownloadQueue(apkPath, appName)
209
+                                    }
210
+                                }
211
+                            } catch (e: Exception) {
212
+                                LogShow("问题" + e.toString())
213
+                            }
214
+                        }
215
+                    } else {
216
+                        // 用户拒绝了安装权限,处理相应逻辑
217
+                        viewModel.getAppList()
218
+                    }
219
+
220
+                }
208
         }
221
         }
209
 
222
 
210
         viewModel.strategyData.observe(this) {
223
         viewModel.strategyData.observe(this) {
211
             spUtils.saveJson(Const.STRATEGYBEANKEY, it)
224
             spUtils.saveJson(Const.STRATEGYBEANKEY, it)
212
             StrategyUtils.setStrategy(it)
225
             StrategyUtils.setStrategy(it)
213
             useTimeStrategy()
226
             useTimeStrategy()
214
-            updateStrategyFlag=true
215
-            if (updateTimeFlag){
227
+            updateStrategyFlag = true
228
+            if (updateTimeFlag) {
216
                 showSucessToast()
229
                 showSucessToast()
217
             }
230
             }
218
         }
231
         }
219
         viewModel.appStrategyData.observe(this) {
232
         viewModel.appStrategyData.observe(this) {
220
             //存储app时间策略
233
             //存储app时间策略
221
             spUtils.saveJson(Const.APPSTRATEGYBEANKEY, it)
234
             spUtils.saveJson(Const.APPSTRATEGYBEANKEY, it)
222
-            updateTimeFlag=true
223
-            if (updateStrategyFlag){
235
+            updateTimeFlag = true
236
+            if (updateStrategyFlag) {
224
                 showSucessToast()
237
                 showSucessToast()
225
             }
238
             }
226
         }
239
         }
270
                             transition: Transition<in Drawable>?
283
                             transition: Transition<in Drawable>?
271
                         ) {
284
                         ) {
272
                             mBinding.root.background = resource
285
                             mBinding.root.background = resource
273
-                            val imageUtil=ImageUtils()
274
-                            imageUtil.saveBitmapToFile(imageUtil.drawableToBitmap(resource), File(filesDir,"wallpaper.png"))
286
+                            val imageUtil = ImageUtils()
287
+                            imageUtil.saveBitmapToFile(
288
+                                imageUtil.drawableToBitmap(resource),
289
+                                File(filesDir, "wallpaper.png")
290
+                            )
275
                         }
291
                         }
276
                     })
292
                     })
277
             }
293
             }
286
                 Toast(getString(R.string.codeerror))
302
                 Toast(getString(R.string.codeerror))
287
             }
303
             }
288
         }
304
         }
289
-        viewModel.lockResultData.observe(this){
290
-            if (it){
305
+        viewModel.lockResultData.observe(this) {
306
+            if (it) {
291
                 spUtils.setParam(Const.DISABLEPAD, true)
307
                 spUtils.setParam(Const.DISABLEPAD, true)
292
                 startIntentActivity(MainActivity().javaClass)
308
                 startIntentActivity(MainActivity().javaClass)
293
                 val appList = AppUtils.GetAppList(this)
309
                 val appList = AppUtils.GetAppList(this)
294
                 StrategyUtils.clearMemory(this, appList)
310
                 StrategyUtils.clearMemory(this, appList)
295
             }
311
             }
296
         }
312
         }
297
-        viewModel.resetlResultData.observe(this){
298
-            if (it){
313
+        viewModel.resetlResultData.observe(this) {
314
+            if (it) {
299
                 ManageApplication.launchFactoryReset()
315
                 ManageApplication.launchFactoryReset()
300
             }
316
             }
301
         }
317
         }
302
-        viewModel.logResultData.observe(this){
303
-            if (it.enableFlag){
304
-                when(it.pushType){
305
-                    2->{
318
+        viewModel.logResultData.observe(this) {
319
+            if (it.enableFlag) {
320
+                when (it.pushType) {
321
+                    2 -> {
306
                         spUtils.setParam(Const.DISABLEPAD, false)
322
                         spUtils.setParam(Const.DISABLEPAD, false)
307
                         useTimeStrategy()
323
                         useTimeStrategy()
308
                     }
324
                     }
309
-                    3->{
325
+
326
+                    3 -> {
310
                         val appList = AppUtils.GetAppList(this)
327
                         val appList = AppUtils.GetAppList(this)
311
                         StrategyUtils.clearMemory(this, appList)
328
                         StrategyUtils.clearMemory(this, appList)
312
                         spUtils.setParam(Const.DISABLEPAD, true)
329
                         spUtils.setParam(Const.DISABLEPAD, true)
313
                         startIntentActivity(MainActivity().javaClass)
330
                         startIntentActivity(MainActivity().javaClass)
314
                     }
331
                     }
315
-                    4->{
332
+
333
+                    4 -> {
316
                         //请求接口更新策略
334
                         //请求接口更新策略
317
                         updateAllStrategy()
335
                         updateAllStrategy()
318
                     }
336
                     }
319
-                    5->{
337
+
338
+                    5 -> {
320
                         ManageApplication.rebootDevice()
339
                         ManageApplication.rebootDevice()
321
                     }
340
                     }
322
-                    6->{
341
+
342
+                    6 -> {
323
                         ManageApplication.launchFactoryReset()
343
                         ManageApplication.launchFactoryReset()
324
                     }
344
                     }
325
-                    7->{
326
-                        currentSpUtils.setParam(Const.EXIT_CONTROL,true)
345
+
346
+                    7 -> {
347
+                        currentSpUtils.setParam(Const.EXIT_CONTROL, true)
327
                         StrategyUtils.releaseControl(this)
348
                         StrategyUtils.releaseControl(this)
328
                     }
349
                     }
329
-                    8->{
350
+
351
+                    8 -> {
330
                         loginOut()
352
                         loginOut()
331
                     }
353
                     }
332
                 }
354
                 }
333
             }
355
             }
334
         }
356
         }
335
-        viewModel.logEventData.observe(this){
336
-            when(it.logEventType){
337
-                EventLog.ACCOUNTQUITEVENT->{
357
+        viewModel.logEventData.observe(this) {
358
+            when (it.logEventType) {
359
+                EventLog.ACCOUNTQUITEVENT -> {
338
                     loginOutSucess()
360
                     loginOutSucess()
339
                 }
361
                 }
340
             }
362
             }
345
 
367
 
346
     private fun showSucessToast() {
368
     private fun showSucessToast() {
347
         Toaster.show(R.string.updatetips)
369
         Toaster.show(R.string.updatetips)
348
-        updateStrategyFlag=false
349
-        updateTimeFlag=false
370
+        updateStrategyFlag = false
371
+        updateTimeFlag = false
350
     }
372
     }
351
 
373
 
352
 
374
 
389
         onBackPressedDispatcher.addCallback {
411
         onBackPressedDispatcher.addCallback {
390
             //屏蔽返回键
412
             //屏蔽返回键
391
             Const.backNum++
413
             Const.backNum++
392
-            if (Const.backNum>Const.UPDATESTRATEGYNUM){
393
-                Const.backNum=0
414
+            if (Const.backNum > Const.UPDATESTRATEGYNUM) {
415
+                Const.backNum = 0
394
                 Toaster.show(R.string.updatetips)
416
                 Toaster.show(R.string.updatetips)
395
                 updateAllStrategy()
417
                 updateAllStrategy()
396
             }
418
             }
486
         getLocation()
508
         getLocation()
487
     }
509
     }
488
 
510
 
489
-    private fun updateAllStrategy(){
511
+    private fun updateAllStrategy() {
490
         userBean?.let {
512
         userBean?.let {
491
             Const.USERID = it.userid
513
             Const.USERID = it.userid
492
             Const.USERNAME = it.username.toString()
514
             Const.USERNAME = it.username.toString()
523
                 val removeList = arrayListOf<AppInfo>()
545
                 val removeList = arrayListOf<AppInfo>()
524
                 currentList.forEach { pkg ->
546
                 currentList.forEach { pkg ->
525
                     //除了管控之类的我们的app之外的预装都不在统计范围
547
                     //除了管控之类的我们的app之外的预装都不在统计范围
526
-                    if (Const.CURRENTAPPPKG!=pkg&&Const.STOREAPPPKG!=pkg) {
548
+                    if (Const.CURRENTAPPPKG != pkg && Const.STOREAPPPKG != pkg) {
527
                         appList.filter { it.packageName == pkg }.forEach {
549
                         appList.filter { it.packageName == pkg }.forEach {
528
                             removeList.add(it)
550
                             removeList.add(it)
529
                         }
551
                         }
535
 
557
 
536
             }
558
             }
537
             val userBean = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass) as UserBean
559
             val userBean = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass) as UserBean
538
-            val appInstallList= arrayListOf<AppInstallBean>()
560
+            val appInstallList = arrayListOf<AppInstallBean>()
539
             appList.forEach {
561
             appList.forEach {
540
-                val appInstallBean=AppInstallBean()
541
-                appInstallBean.userid=userBean.userid
542
-                appInstallBean.appName=it.name
543
-                appInstallBean.appVersion=it.versionName
544
-                appInstallBean.appNum=it.versionNum
545
-                appInstallBean.appPackage=it.packageName
546
-                ManageApplication.getDeviceInfo()?.let {sn->
562
+                val appInstallBean = AppInstallBean()
563
+                appInstallBean.userid = userBean.userid
564
+                appInstallBean.appName = it.name
565
+                appInstallBean.appVersion = it.versionName
566
+                appInstallBean.appNum = it.versionNum
567
+                appInstallBean.appPackage = it.packageName
568
+                ManageApplication.getDeviceInfo()?.let { sn ->
547
                     appInstallBean.sn = sn
569
                     appInstallBean.sn = sn
548
                 }
570
                 }
549
-                ManageApplication.getDeviceInfo(1)?.let {mac->
571
+                ManageApplication.getDeviceInfo(1)?.let { mac ->
550
                     appInstallBean.mac = mac
572
                     appInstallBean.mac = mac
551
                 }
573
                 }
552
-                appInstallBean.schoolid=userBean.schoolid
553
-                appInstallBean.regionid=userBean.regionid
574
+                appInstallBean.schoolid = userBean.schoolid
575
+                appInstallBean.regionid = userBean.regionid
554
                 appInstallList.add(appInstallBean)
576
                 appInstallList.add(appInstallBean)
555
             }
577
             }
556
 
578
 
557
             viewModel.updateAppInstallInfo(appInstallList)
579
             viewModel.updateAppInstallInfo(appInstallList)
558
-        }catch (e:Exception){
580
+        } catch (e: Exception) {
559
 
581
 
560
         }
582
         }
561
     }
583
     }
594
     }
616
     }
595
 
617
 
596
 
618
 
597
-
598
     private fun updateMcApp() {
619
     private fun updateMcApp() {
599
         //每天请求一次app更新接口,这个接口是用于提交管控自身的版本信息统计
620
         //每天请求一次app更新接口,这个接口是用于提交管控自身的版本信息统计
600
         try {
621
         try {
618
                 updateBean.schoolid = userBean.schoolid
639
                 updateBean.schoolid = userBean.schoolid
619
                 updateBean.userid = userBean.userid
640
                 updateBean.userid = userBean.userid
620
                 updateBean.regionid = userBean.regionid
641
                 updateBean.regionid = userBean.regionid
621
-               viewModel.updateMcApp(updateBean)
642
+                viewModel.updateMcApp(updateBean)
622
             }
643
             }
623
         } catch (e: Exception) {
644
         } catch (e: Exception) {
624
 
645
 
807
                     data.doEvent = EventLog.APPINSTALLEVENT
828
                     data.doEvent = EventLog.APPINSTALLEVENT
808
                     viewModel.eventLog(data)
829
                     viewModel.eventLog(data)
809
                     updateAppInstallInfo()
830
                     updateAppInstallInfo()
810
-                }catch (e:Exception){
831
+                } catch (e: Exception) {
811
 
832
 
812
                 }
833
                 }
813
             }
834
             }
891
 
912
 
892
             Const.CODE3002.toString() -> {
913
             Const.CODE3002.toString() -> {
893
                 val deviceInfo = ManageApplication.getDeviceInfo()
914
                 val deviceInfo = ManageApplication.getDeviceInfo()
894
-                val sn= deviceInfo ?: ""
915
+                val sn = deviceInfo ?: ""
895
                 viewModel.postExitLocked(sn)
916
                 viewModel.postExitLocked(sn)
896
             }
917
             }
897
 
918
 
898
             Const.CODE3006.toString() -> {
919
             Const.CODE3006.toString() -> {
899
                 val deviceInfo = ManageApplication.getDeviceInfo()
920
                 val deviceInfo = ManageApplication.getDeviceInfo()
900
-                val sn= deviceInfo ?: ""
921
+                val sn = deviceInfo ?: ""
901
                 viewModel.postExitReseted(sn)
922
                 viewModel.postExitReseted(sn)
902
             }
923
             }
924
+            Const.INSTALL_FORCEAPP->{
925
+                ManageApplication.installPackage(uiEvent.message)
926
+            }
903
         }
927
         }
904
     }
928
     }
905
 
929
 
906
     private fun postLogPush(pushType: Int) {
930
     private fun postLogPush(pushType: Int) {
907
         val pushBean = LogPushBean()
931
         val pushBean = LogPushBean()
908
         pushBean.pushType = pushType
932
         pushBean.pushType = pushType
909
-        pushBean.sn=ManageApplication.getDeviceInfo()?:""
933
+        pushBean.sn = ManageApplication.getDeviceInfo() ?: ""
910
         viewModel.postLogPushAdd(pushBean)
934
         viewModel.postLogPushAdd(pushBean)
911
     }
935
     }
912
 
936
 
915
             //获得预装应用和商店应用,商店应用和预装重叠直接显示,其余预装直接隐藏
939
             //获得预装应用和商店应用,商店应用和预装重叠直接显示,其余预装直接隐藏
916
             var schoolDeviceSetBean: SchoolDeviceSetBean? = null
940
             var schoolDeviceSetBean: SchoolDeviceSetBean? = null
917
             schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this)
941
             schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this)
918
-            val storeList= arrayListOf<String>()
942
+            val storeList = arrayListOf<String>()
919
             try {
943
             try {
920
                 val fromJson = spUtils.getFromJson(Const.APPSTOREKEY, ArrayList<String>().javaClass)
944
                 val fromJson = spUtils.getFromJson(Const.APPSTOREKEY, ArrayList<String>().javaClass)
921
-                if (fromJson!=null){
945
+                if (fromJson != null) {
922
                     storeList.addAll(fromJson as ArrayList<String>)
946
                     storeList.addAll(fromJson as ArrayList<String>)
923
                 }
947
                 }
924
-            }catch (e:Exception){
948
+            } catch (e: Exception) {
925
                 LogShow("商店应用为空")
949
                 LogShow("商店应用为空")
926
             }
950
             }
927
             dataList.clear()
951
             dataList.clear()
937
                     ) as ArrayList<String>
961
                     ) as ArrayList<String>
938
                 currentList.forEach { pkg ->
962
                 currentList.forEach { pkg ->
939
                     //学校控制之外的预装应用加入移除集合,应用商店列表包含的不需要加入移除集合
963
                     //学校控制之外的预装应用加入移除集合,应用商店列表包含的不需要加入移除集合
940
-                    if (!Const.schoolSetAppList.contains(pkg)&&!storeList.contains(pkg)) {
964
+                    if (!Const.schoolSetAppList.contains(pkg) && !storeList.contains(pkg)) {
941
                         appList.filter { it.packageName == pkg }.forEach {
965
                         appList.filter { it.packageName == pkg }.forEach {
942
                             removeList.add(it)
966
                             removeList.add(it)
943
                         }
967
                         }
947
 
971
 
948
             }
972
             }
949
             //如果包含应用商店也移除,因为会在自定义app中添加
973
             //如果包含应用商店也移除,因为会在自定义app中添加
950
-            appList.filter { it.packageName == Const.STOREAPPPKG}.forEach {
974
+            appList.filter { it.packageName == Const.STOREAPPPKG }.forEach {
951
                 removeList.add(it)
975
                 removeList.add(it)
952
             }
976
             }
953
             //移除学校控制之外预装应用
977
             //移除学校控制之外预装应用
1068
             .setAlign(CustomDialog.ALIGN.CENTER).show()
1092
             .setAlign(CustomDialog.ALIGN.CENTER).show()
1069
     }
1093
     }
1070
 
1094
 
1071
-    private fun loginOut(hasUser:Boolean=true) {
1095
+    private fun loginOut(hasUser: Boolean = true) {
1072
         //没有用户信息时,判断为初次调用,直接跳转登录页面
1096
         //没有用户信息时,判断为初次调用,直接跳转登录页面
1073
-        if (hasUser){
1097
+        if (hasUser) {
1074
             //调用接口传递退出事件,成功则退出登录
1098
             //调用接口传递退出事件,成功则退出登录
1075
             val data = LogdOperateBean()
1099
             val data = LogdOperateBean()
1076
             ManageApplication.getDeviceInfo()?.let {
1100
             ManageApplication.getDeviceInfo()?.let {
1079
             data.comm = "退出登录"
1103
             data.comm = "退出登录"
1080
             data.doEvent = EventLog.ACCOUNTQUITEVENT
1104
             data.doEvent = EventLog.ACCOUNTQUITEVENT
1081
             viewModel.eventLog(data)
1105
             viewModel.eventLog(data)
1082
-        }else{
1106
+        } else {
1083
             loginOutSucess()
1107
             loginOutSucess()
1084
         }
1108
         }
1085
     }
1109
     }
1086
 
1110
 
1087
-    private fun loginOutSucess(){
1111
+    private fun loginOutSucess() {
1088
         WorkManager.getInstance(this).cancelAllWork()
1112
         WorkManager.getInstance(this).cancelAllWork()
1089
         deleteSharedPreferences(SharedPreferencesUtils.SP_FILE_NAME)
1113
         deleteSharedPreferences(SharedPreferencesUtils.SP_FILE_NAME)
1090
         Const.USERID = null
1114
         Const.USERID = null

+ 8
- 3
app/src/main/java/com/xhly/manageapp/utils/AppDownLoadUtils.kt View File

3
 import com.billbook.lib.downloader.Download
3
 import com.billbook.lib.downloader.Download
4
 import com.billbook.lib.downloader.Downloader
4
 import com.billbook.lib.downloader.Downloader
5
 import com.xhly.corelib.Const
5
 import com.xhly.corelib.Const
6
+import com.xhly.corelib.eventbus.UIEvent
6
 import com.xhly.corelib.utils.LogShow
7
 import com.xhly.corelib.utils.LogShow
7
 import com.xhly.manageapp.ManageApplication
8
 import com.xhly.manageapp.ManageApplication
8
 import kotlinx.coroutines.Dispatchers
9
 import kotlinx.coroutines.Dispatchers
49
                         successful = execute.isSuccessful()
50
                         successful = execute.isSuccessful()
50
                         LogShow("下载结果" + successful)
51
                         LogShow("下载结果" + successful)
51
                         if (successful) {
52
                         if (successful) {
52
-                            withContext(Dispatchers.Main) {
53
-                                ManageApplication.installPackage(File(name, "$appName.apk").toString())
54
-                            }
53
+                            UIEvent(Const.INSTALL_FORCEAPP).setMessage(File(name, "$appName.apk").toString()).post()
55
                         } else {
54
                         } else {
56
                             currentRetry++
55
                             currentRetry++
57
                         }
56
                         }
65
             }
64
             }
66
         }
65
         }
67
     }
66
     }
67
+
68
+    data class DownloadItem(val url: String, val tag: String, val savepath: String, var progress: Int)
69
+
70
+    interface DownloadCallback {
71
+        fun onSuccess(downItem: DownloadItem)
72
+    }
68
 }
73
 }

+ 126
- 0
app/src/main/java/com/xhly/manageapp/utils/DownLoadUtils.kt View File

1
+import android.util.Log
2
+import com.billbook.lib.downloader.Download
3
+import com.billbook.lib.downloader.Downloader
4
+import kotlinx.coroutines.CoroutineScope
5
+import kotlinx.coroutines.Dispatchers
6
+import kotlinx.coroutines.launch
7
+import java.util.LinkedList
8
+import java.util.Queue
9
+
10
+object DownLoadUtils {
11
+    val queue: Queue<DownloadItem> = LinkedList()
12
+    var callbackList = mutableListOf<DownloadCallback>()
13
+    var isRunning = false
14
+
15
+    fun isEmpty(): Boolean {
16
+        return queue.isEmpty()
17
+    }
18
+
19
+    /**
20
+     * 页面启动 添加回调
21
+     */
22
+    fun addCallback(callback: DownloadCallback) {
23
+        callbackList.add(callback)
24
+    }
25
+
26
+
27
+    /**
28
+     * 页面关闭 删除回调
29
+     */
30
+    fun removeCallback(callback: DownloadCallback) {
31
+        callbackList.remove(callback)
32
+    }
33
+
34
+
35
+    /**
36
+     * 下载文件
37
+     */
38
+    fun addDownload(url: String, tag: String, savepath: String) {
39
+        var isHave = false
40
+        for (element in queue) {
41
+            if (element.tag === tag) {
42
+                isHave = true
43
+            }
44
+        }
45
+        if (!isHave) {
46
+            queue.add(DownloadItem(url, tag, savepath, 0))
47
+        } else {
48
+            for (downloadCallback in callbackList) {
49
+                downloadCallback.onFailure(DownloadItem(url, tag, savepath, 0), "已经在下载队列")
50
+            }
51
+        }
52
+        downloadAction()
53
+    }
54
+
55
+    private fun downloadAction() {
56
+        if (isRunning) {
57
+            return
58
+        }
59
+        val coroutineScope = CoroutineScope(Dispatchers.IO)
60
+        coroutineScope.launch {
61
+            while (queue.size > 0) {
62
+                isRunning = true
63
+                val downItem = queue.peek()
64
+                downItem?.let {
65
+                    try {
66
+                        val downloader = Downloader.Builder().build()
67
+                        val request = Download.Request.Builder()
68
+                            .url(it.url)
69
+                            .into(it.savepath)
70
+                            .build()
71
+                        val call = downloader.newCall(request)
72
+                        call.execute(object : Download.Callback {
73
+                            override fun onStart(call: Download.Call) {
74
+                                for (downloadCallback in callbackList) {
75
+                                    downloadCallback.onStart(downItem)
76
+                                }
77
+                            }
78
+
79
+                            override fun onSuccess(call: Download.Call, response: Download.Response) {
80
+                                queue.poll()
81
+                                for (downloadCallback in callbackList) {
82
+                                    downloadCallback.onSuccess(downItem)
83
+                                }
84
+                            }
85
+
86
+                            override fun onFailure(call: Download.Call, response: Download.Response) {
87
+                                queue.poll()
88
+                                for (downloadCallback in callbackList) {
89
+                                    downloadCallback.onFailure(downItem, response.message!!)
90
+                                }
91
+                            }
92
+
93
+                            override fun onLoading(call: Download.Call, current: Long, total: Long) {
94
+                                val progress = (current * 100 / total).toInt()
95
+//                                Log.i("详情", "$progress ${downItem.progress} ${callbackList.size}")
96
+                                if (progress != downItem.progress) {
97
+                                    for (downloadCallback in callbackList) {
98
+                                        downItem.progress = progress
99
+                                        downloadCallback.onLoading(downItem)
100
+                                    }
101
+                                }
102
+                            }
103
+                        })
104
+                    } catch (e: Exception) {
105
+                        queue.poll()
106
+                        for (downloadCallback in callbackList) {
107
+                            downloadCallback.onFailure(downItem, e.toString())
108
+                        }
109
+                    }
110
+                }
111
+
112
+            }
113
+            isRunning = false
114
+        }
115
+
116
+    }
117
+}
118
+
119
+data class DownloadItem(val url: String, val tag: String, val savepath: String, var progress: Int)
120
+
121
+interface DownloadCallback {
122
+    fun onStart(downItem: DownloadItem)
123
+    fun onSuccess(downItem: DownloadItem)
124
+    fun onFailure(downItem: DownloadItem, errMsg: String)
125
+    fun onLoading(downItem: DownloadItem)
126
+}

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

3
     <paths>
3
     <paths>
4
         <external-path path="Android/data/com.example.iu/" name="files_root" />
4
         <external-path path="Android/data/com.example.iu/" name="files_root" />
5
         <external-path path="." name="external_storage_root" />
5
         <external-path path="." name="external_storage_root" />
6
+        <files-path name="data" path="."/>
6
     </paths>
7
     </paths>
7
 </resources>
8
 </resources>

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

71
      */
71
      */
72
     const val ACCOUNTLOGINOUT = "ACCOUNTLOGINOUT"
72
     const val ACCOUNTLOGINOUT = "ACCOUNTLOGINOUT"
73
 
73
 
74
-
74
+    /**
75
+     * 调用安装app方法
76
+     */
77
+    const val INSTALL_FORCEAPP="INSTALL_FORCEAPP"
75
     /**
78
     /**
76
      * 存储应用商店应用包名集合
79
      * 存储应用商店应用包名集合
77
      */
80
      */

Loading…
Cancel
Save