ソースを参照

1.添加初始应用存储和后续展示处理。

20241218TB223FC(测试jar包)
wangwanlei 9ヶ月前
コミット
3afbe39e48

+ 1
- 4
app/src/main/java/com/xhly/manageapp/ManageApplication.kt ファイルの表示

@@ -103,10 +103,7 @@ class ManageApplication : MultiDexApplication() {
103 103
          */
104 104
         fun setPackageEnabled(pkg: String, enableFlag: Boolean) {
105 105
             if (ModelNameUtils.IS_LianxX505f()) {
106
-                //TODO 暂不处理系统应用
107
-               /* if (!pkg.startsWith("com.android.")) {
108
-                    csdkManager?.setPackageEnabled(pkg, enableFlag)
109
-                }*/
106
+                csdkManager?.setPackageEnabled(pkg, enableFlag)
110 107
             }
111 108
         }
112 109
 

+ 24
- 1
app/src/main/java/com/xhly/manageapp/ui/login/activity/LoginActivity.kt ファイルの表示

@@ -17,7 +17,9 @@ import com.kongzue.dialogx.dialogs.CustomDialog
17 17
 import com.kongzue.dialogx.interfaces.OnBindView
18 18
 import com.tbruyelle.rxpermissions2.RxPermissions
19 19
 import com.xhly.corelib.Const
20
+import com.xhly.corelib.bean.AppInfo
20 21
 import com.xhly.corelib.eventbus.UIEvent
22
+import com.xhly.corelib.utils.AppUtils
21 23
 import com.xhly.corelib.utils.GsonUtils
22 24
 import com.xhly.corelib.utils.LogShow
23 25
 import com.xhly.corelib.utils.SystemUtil
@@ -60,8 +62,8 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
60 62
 
61 63
     @SuppressLint("CheckResult")
62 64
     override fun initView() {
65
+        initFirstUse()
63 66
         setSoftInput(mBinding.root)
64
-
65 67
         mBinding.loginBtn.setOnClickListener {
66 68
             val rxPermissions = RxPermissions(this)
67 69
             val request = rxPermissions.request(Manifest.permission.READ_PHONE_STATE)
@@ -79,6 +81,27 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
79 81
         }
80 82
     }
81 83
 
84
+    private fun initFirstUse() {
85
+        val firstFlag = currentSpUtils.getParam(Const.FIRSTFLAG, true) as Boolean
86
+        if (firstFlag){
87
+            //如果第一次使用则提交登录事件,并且保存初始app
88
+            val data = LogdOperateBean()
89
+            ManageApplication.getDeviceInfo()?.let {
90
+                data.sn = it
91
+            }
92
+            data.comm = "退出登录"
93
+            data.doEvent = EventLog.ACCOUNTQUITEVENT
94
+            viewModel.eventLog(data)
95
+            val firstAppList = AppUtils.GetAppList(this)
96
+            //保存初始应用,只保留包名,因为drawble数据存储时有问题
97
+            val pkgNameList= arrayListOf<String>()
98
+            firstAppList.forEach {
99
+                pkgNameList.add(it.packageName)
100
+            }
101
+            currentSpUtils.saveJson(Const.FIRSTAPPLIST,pkgNameList)
102
+        }
103
+    }
104
+
82 105
     private fun login() {
83 106
         val account = mBinding.accountEt.text.toString()
84 107
         val code = mBinding.codeEt.text.toString()

+ 26
- 2
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt ファイルの表示

@@ -25,6 +25,7 @@ import androidx.work.WorkManager
25 25
 import com.bumptech.glide.Glide
26 26
 import com.bumptech.glide.request.target.CustomViewTarget
27 27
 import com.bumptech.glide.request.transition.Transition
28
+import com.google.gson.reflect.TypeToken
28 29
 import com.kongzue.dialogx.dialogs.CustomDialog
29 30
 import com.kongzue.dialogx.interfaces.OnBindView
30 31
 import com.tbruyelle.rxpermissions2.RxPermissions
@@ -46,6 +47,7 @@ import com.xhly.manageapp.bean.SocketMsgBean
46 47
 import com.xhly.manageapp.bean.UpdateBean
47 48
 import com.xhly.manageapp.bean.log.LogdOperateBean
48 49
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
50
+import com.xhly.manageapp.bean.strategy.AppTimeManageBean
49 51
 import com.xhly.manageapp.bean.strategy.StrategyBean
50 52
 import com.xhly.manageapp.bean.user.UserBean
51 53
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
@@ -56,6 +58,7 @@ import com.xhly.manageapp.ui.ManageActivity
56 58
 import com.xhly.manageapp.ui.login.activity.LoginActivity
57 59
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
58 60
 import com.xhly.manageapp.utils.AppDownLoadUtils
61
+import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
59 62
 import com.xhly.manageapp.utils.CustomAppUtils
60 63
 import com.xhly.manageapp.utils.PadInfoUtils
61 64
 import com.xhly.manageapp.utils.StrategyUtils
@@ -74,6 +77,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
74 77
     private var dataList: ArrayList<AppInfo> = arrayListOf()
75 78
     private var userBean: UserBean? = null
76 79
     private var timer: Timer?=null
80
+    private val currentSpUtils by lazy {  CurrentAppSharedPreferencesUtils.getInstance(this) }
77 81
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
78 82
 
79 83
     override fun initData() {
@@ -101,10 +105,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
101 105
         viewModel.listAppData.observe(this) { modelList ->
102 106
             //获得应用集合,必装应用和推荐应用,再加上预装应用,其余应用需要静默卸载,必装应用需要进行静默下载和安装。安装应用从forceapp接口获取
103 107
             val appList = AppUtils.GetAppList(this)
108
+            val firstAppList= arrayListOf<String>()
109
+            try {
110
+                //获得预装应用的包名
111
+                val currentList =
112
+                    currentSpUtils.getFromJson(Const.FIRSTAPPLIST, ArrayList<String>().javaClass) as ArrayList<String>
113
+                firstAppList.addAll(currentList)
114
+            }catch (e:Exception){
115
+               LogShow("冻结失败"+e.toString())
116
+            }
104 117
             appList.forEach { app ->
105 118
                 val filter = modelList.filter { it.appPackage.equals(app.packageName) }
106
-                //列表中不存在则将应用冻结或者卸载,目前是冻结
107
-                ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
119
+                val appInfos = firstAppList.filter { app.packageName.equals(it) }
120
+                //接口列表以及初始化列表中不存在则将应用冻结或者卸载,目前是冻结
121
+                LogShow("${app.name},被冻结"+(filter.isEmpty() && appInfos.isEmpty()))
122
+                if (filter.isEmpty() && appInfos.isEmpty()){
123
+                   ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
124
+                }
108 125
             }
109 126
         }
110 127
         viewModel.forceListAppData.observe(this) { modelList ->
@@ -693,6 +710,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
693 710
     }
694 711
 
695 712
     private fun loginOut() {
713
+        val data = LogdOperateBean()
714
+        ManageApplication.getDeviceInfo()?.let {
715
+            data.sn = it
716
+        }
717
+        data.comm = "退出登录"
718
+        data.doEvent = EventLog.ACCOUNTQUITEVENT
719
+        viewModel.eventLog(data)
696 720
         WorkManager.getInstance(this).cancelAllWork()
697 721
         deleteSharedPreferences(SharedPreferencesUtils.SP_FILE_NAME)
698 722
         startIntentActivity(LoginActivity().javaClass)

+ 3
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt ファイルの表示

@@ -22,6 +22,9 @@ object Const {
22 22
     //存储是否是第一次打开的key
23 23
     const val FIRSTFLAG = "FIRSTFLAG"
24 24
 
25
+    //存储是否是第一次打开的key
26
+    const val FIRSTAPPLIST = "FIRSTAPPLIST"
27
+
25 28
     //401退出登录
26 29
     const val LOGIN_OUT_401 = "LOGIN_OUT_401"
27 30
 

+ 3
- 1
corelib/src/main/java/com/xhly/corelib/bean/AppInfo.java ファイルの表示

@@ -3,7 +3,9 @@ package com.xhly.corelib.bean;
3 3
 import android.content.Intent;
4 4
 import android.graphics.drawable.Drawable;
5 5
 
6
-public class AppInfo {
6
+import java.io.Serializable;
7
+
8
+public class AppInfo implements Serializable {
7 9
     private String packageName; //包名
8 10
     private Drawable ico;       //图标
9 11
     private String Name;        //应用标签

読み込み中…
キャンセル
保存