高通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博客,谢谢!

相关推荐
阿智@111 小时前
Node.js 助力前端开发:自动化操作实战
运维·前端·node.js·自动化
万万君1 小时前
Linux 更改Jenkins使用其他账户启动
linux·jenkins
编程洪同学1 小时前
Spring Boot 中实现自定义注解记录接口日志功能
android·java·spring boot·后端
赤叶丶秋枫1 小时前
Jenkins入门使用
运维·jenkins
开心最重要(*^▽^*)1 小时前
Metricbeat安装教程——Linux——Metricbeat监控ES集群
linux·elasticsearch
紫菜(Nori)1 小时前
Jenkins Api Token 访问问题
运维·jenkins
love530love2 小时前
Windows 11 中利用 WSL - Linux 虚拟环境部署 ChatTTS-Enhanced 项目教程
linux·运维·windows
冷曦_sole2 小时前
linux-22 目录管理(二)rmdir命令,删除目录
linux·运维·服务器
群联云防护小杜2 小时前
服务器被攻击怎么办
运维·服务器·网络·网络协议·安全·web安全
活跃的煤矿打工人2 小时前
【星海随笔】删除ceph
linux·服务器·ceph