Browse Source

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

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

+ 1
- 4
app/src/main/java/com/xhly/manageapp/ManageApplication.kt View File

103
          */
103
          */
104
         fun setPackageEnabled(pkg: String, enableFlag: Boolean) {
104
         fun setPackageEnabled(pkg: String, enableFlag: Boolean) {
105
             if (ModelNameUtils.IS_LianxX505f()) {
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 View File

17
 import com.kongzue.dialogx.interfaces.OnBindView
17
 import com.kongzue.dialogx.interfaces.OnBindView
18
 import com.tbruyelle.rxpermissions2.RxPermissions
18
 import com.tbruyelle.rxpermissions2.RxPermissions
19
 import com.xhly.corelib.Const
19
 import com.xhly.corelib.Const
20
+import com.xhly.corelib.bean.AppInfo
20
 import com.xhly.corelib.eventbus.UIEvent
21
 import com.xhly.corelib.eventbus.UIEvent
22
+import com.xhly.corelib.utils.AppUtils
21
 import com.xhly.corelib.utils.GsonUtils
23
 import com.xhly.corelib.utils.GsonUtils
22
 import com.xhly.corelib.utils.LogShow
24
 import com.xhly.corelib.utils.LogShow
23
 import com.xhly.corelib.utils.SystemUtil
25
 import com.xhly.corelib.utils.SystemUtil
60
 
62
 
61
     @SuppressLint("CheckResult")
63
     @SuppressLint("CheckResult")
62
     override fun initView() {
64
     override fun initView() {
65
+        initFirstUse()
63
         setSoftInput(mBinding.root)
66
         setSoftInput(mBinding.root)
64
-
65
         mBinding.loginBtn.setOnClickListener {
67
         mBinding.loginBtn.setOnClickListener {
66
             val rxPermissions = RxPermissions(this)
68
             val rxPermissions = RxPermissions(this)
67
             val request = rxPermissions.request(Manifest.permission.READ_PHONE_STATE)
69
             val request = rxPermissions.request(Manifest.permission.READ_PHONE_STATE)
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
     private fun login() {
105
     private fun login() {
83
         val account = mBinding.accountEt.text.toString()
106
         val account = mBinding.accountEt.text.toString()
84
         val code = mBinding.codeEt.text.toString()
107
         val code = mBinding.codeEt.text.toString()

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

25
 import com.bumptech.glide.Glide
25
 import com.bumptech.glide.Glide
26
 import com.bumptech.glide.request.target.CustomViewTarget
26
 import com.bumptech.glide.request.target.CustomViewTarget
27
 import com.bumptech.glide.request.transition.Transition
27
 import com.bumptech.glide.request.transition.Transition
28
+import com.google.gson.reflect.TypeToken
28
 import com.kongzue.dialogx.dialogs.CustomDialog
29
 import com.kongzue.dialogx.dialogs.CustomDialog
29
 import com.kongzue.dialogx.interfaces.OnBindView
30
 import com.kongzue.dialogx.interfaces.OnBindView
30
 import com.tbruyelle.rxpermissions2.RxPermissions
31
 import com.tbruyelle.rxpermissions2.RxPermissions
46
 import com.xhly.manageapp.bean.UpdateBean
47
 import com.xhly.manageapp.bean.UpdateBean
47
 import com.xhly.manageapp.bean.log.LogdOperateBean
48
 import com.xhly.manageapp.bean.log.LogdOperateBean
48
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
49
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
50
+import com.xhly.manageapp.bean.strategy.AppTimeManageBean
49
 import com.xhly.manageapp.bean.strategy.StrategyBean
51
 import com.xhly.manageapp.bean.strategy.StrategyBean
50
 import com.xhly.manageapp.bean.user.UserBean
52
 import com.xhly.manageapp.bean.user.UserBean
51
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
53
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
56
 import com.xhly.manageapp.ui.login.activity.LoginActivity
58
 import com.xhly.manageapp.ui.login.activity.LoginActivity
57
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
59
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
58
 import com.xhly.manageapp.utils.AppDownLoadUtils
60
 import com.xhly.manageapp.utils.AppDownLoadUtils
61
+import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
59
 import com.xhly.manageapp.utils.CustomAppUtils
62
 import com.xhly.manageapp.utils.CustomAppUtils
60
 import com.xhly.manageapp.utils.PadInfoUtils
63
 import com.xhly.manageapp.utils.PadInfoUtils
61
 import com.xhly.manageapp.utils.StrategyUtils
64
 import com.xhly.manageapp.utils.StrategyUtils
74
     private var dataList: ArrayList<AppInfo> = arrayListOf()
77
     private var dataList: ArrayList<AppInfo> = arrayListOf()
75
     private var userBean: UserBean? = null
78
     private var userBean: UserBean? = null
76
     private var timer: Timer?=null
79
     private var timer: Timer?=null
80
+    private val currentSpUtils by lazy {  CurrentAppSharedPreferencesUtils.getInstance(this) }
77
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
81
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
78
 
82
 
79
     override fun initData() {
83
     override fun initData() {
101
         viewModel.listAppData.observe(this) { modelList ->
105
         viewModel.listAppData.observe(this) { modelList ->
102
             //获得应用集合,必装应用和推荐应用,再加上预装应用,其余应用需要静默卸载,必装应用需要进行静默下载和安装。安装应用从forceapp接口获取
106
             //获得应用集合,必装应用和推荐应用,再加上预装应用,其余应用需要静默卸载,必装应用需要进行静默下载和安装。安装应用从forceapp接口获取
103
             val appList = AppUtils.GetAppList(this)
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
             appList.forEach { app ->
117
             appList.forEach { app ->
105
                 val filter = modelList.filter { it.appPackage.equals(app.packageName) }
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
         viewModel.forceListAppData.observe(this) { modelList ->
127
         viewModel.forceListAppData.observe(this) { modelList ->
693
     }
710
     }
694
 
711
 
695
     private fun loginOut() {
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
         WorkManager.getInstance(this).cancelAllWork()
720
         WorkManager.getInstance(this).cancelAllWork()
697
         deleteSharedPreferences(SharedPreferencesUtils.SP_FILE_NAME)
721
         deleteSharedPreferences(SharedPreferencesUtils.SP_FILE_NAME)
698
         startIntentActivity(LoginActivity().javaClass)
722
         startIntentActivity(LoginActivity().javaClass)

+ 3
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt View File

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

+ 3
- 1
corelib/src/main/java/com/xhly/corelib/bean/AppInfo.java View File

3
 import android.content.Intent;
3
 import android.content.Intent;
4
 import android.graphics.drawable.Drawable;
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
     private String packageName; //包名
9
     private String packageName; //包名
8
     private Drawable ico;       //图标
10
     private Drawable ico;       //图标
9
     private String Name;        //应用标签
11
     private String Name;        //应用标签

Loading…
Cancel
Save