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

相关推荐
心灵彼岸-诗和远方1 小时前
DevOps业务价值流:架构设计最佳实践
运维·产品经理·devops
一只哒布刘1 小时前
NFS服务器
运维·服务器
数据猎手小k1 小时前
AndroidLab:一个系统化的Android代理框架,包含操作环境和可复现的基准测试,支持大型语言模型和多模态模型。
android·人工智能·机器学习·语言模型
你的小102 小时前
JavaWeb项目-----博客系统
android
苹果醋32 小时前
Java8->Java19的初步探索
java·运维·spring boot·mysql·nginx
二十雨辰2 小时前
[linux]docker基础
linux·运维·docker
风和先行2 小时前
adb 命令查看设备存储占用情况
android·adb
Jason-河山2 小时前
【自动化更新,让商品信息跳舞】——利用API返回值的幽默编程之旅
运维·自动化
饮浊酒2 小时前
Linux操作系统 ------(3.文本编译器Vim)
linux·vim
lihuhelihu3 小时前
第3章 CentOS系统管理
linux·运维·服务器·计算机网络·ubuntu·centos·云计算