高通Android 12/13添加/移除不被清理后台应用

复制代码
    /**
     * 添加不被清理的后台应用
     *
     * @param packageName
     */
    public void addBackgroundAliveApp(String packageName) {
        List<String> list = getBackgroundAliveAppList();
        if (list != null && packageName != null && packageName.length() > 0) {
            if (!list.contains(packageName)) {
                list.add(packageName);
            }
            setBackgroundAliveAppList(list);
        }
    }

    /**
     * 移除不被清理的后台应用
     *
     * @param packageName
     */
    public void removeBackgroundAliveApp(String packageName) {
        List<String> list = getBackgroundAliveAppList();
        if (list != null && packageName != null && packageName.length() > 0) {
            if (list.contains(packageName)) {
                list.remove(packageName);
            }
            setBackgroundAliveAppList(list);
        }
    }

    /**
     * 获取不被清理的后台应用列表
     *
     * @return
     */
    public List<String> getBackgroundAliveApps() {
        List<String> list = getBackgroundAliveAppList();
        return list;
    }

补充代码

复制代码
   public static List<String> getWhiteAppProcessList() {
        List<String> list = new ArrayList();

        String sizeKey = "persist.test.aliveapps_s";
        String valKey = "persist.test.aliveapps_";
        int size = 0;
        try
        {
            size = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {
        }
        if(size>0)
        {
            for(int i=0;i<size;i++)
            {
                list.add(SystemProperties.get(valKey+i));
            }
        }
        return list;
    }

    public static void setWhiteAppProcessList(List<String> whiteAppProcessList) {
        if(whiteAppProcessList==null || whiteAppProcessList.size()==0)
        {
            whiteAppProcessList = new ArrayList();
        }


        String sizeKey = "persist.test.aliveapps_s";
        String valKey = "persist.test.aliveapps_";
        int orgSize = 0;
        try
        {
            orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {

        }
        if (orgSize > 0) {
            for(int i=0;i<orgSize;i++)
            {
                SystemProperties.set(valKey+i,"");
            }
        }

        int size = whiteAppProcessList.size();
        SystemProperties.set(sizeKey,String.valueOf(size));
        for(int i=0;i<size;i++)
        {
            SystemProperties.set(valKey+i,whiteAppProcessList.get(i));
        }

    }


    public static List<String> getBackgroundAliveAppList() {

        String sizeKey = "persist.test.backgroundapps_s";
        String valKey = "persist.test.backgroundapps_";
        List<String> list = new ArrayList();
        int size = 0;
        try
        {
            size = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {
        }
        if(size>0)
        {
            for(int i=0;i<size;i++)
            {
                list.add(SystemProperties.get(valKey+i));
            }
        }
        return list;
    }

    public static void setBackgroundAliveAppList(List<String> backgroundAliveAppList) {
        if(backgroundAliveAppList==null || backgroundAliveAppList.size()==0)
        {
            backgroundAliveAppList = new ArrayList();
        }

        String sizeKey = "persist.test.backgroundapps_s";
        String valKey = "persist.test.backgroundapps_";
        int orgSize = 0;
        try
        {
            orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
        }
        catch(Exception e)
        {

        }
        if (orgSize > 0) {
            for(int i=0;i<orgSize;i++)
            {
                SystemProperties.set(valKey+i,"");
            }
        }

        int size = backgroundAliveAppList.size();
        SystemProperties.set(sizeKey,String.valueOf(size));
        for(int i=0;i<size;i++)
        {
            SystemProperties.set(valKey+i,backgroundAliveAppList.get(i));
        }

    }

转载请注明出处高通Android 12/13添加/移除不被清理后台应用-CSDN博客,谢谢!

相关推荐
程序员码歌3 小时前
【零代码AI编程实战】AI灯塔导航-总结篇
android·前端·后端
寻道模式4 小时前
【运维心得】三步10分钟拆装笔记本键盘
运维·计算机外设·笔记本
书弋江山4 小时前
flutter 跨平台编码库 protobuf 工具使用
android·flutter
炫友呀5 小时前
Centos 更新/修改宝塔版本
linux·运维·centos
闻道且行之5 小时前
嵌入式|VNC实现开发板远程Debian桌面
运维·debian·嵌入式
IT成长日记6 小时前
【自动化运维神器Ansible】Playbook中的when条件判断:精细化控制任务执行
运维·自动化·ansible·playbook·when·条件判断
来来走走7 小时前
Flutter开发 webview_flutter的基本使用
android·flutter
Jerry说前后端7 小时前
Android 组件封装实践:从解耦到架构演进
android·前端·架构
louisgeek8 小时前
Android OkHttp Interceptor
android
大王派来巡山的小旋风8 小时前
Kotlin基本用法三
android·kotlin