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

相关推荐
苹果醋39 分钟前
vue3 在哪些方便做了性能提升?
java·运维·spring boot·mysql·nginx
cetcht888821 分钟前
光伏电站项目-视频监控、微气象及安全警卫系统
运维·人工智能·物联网
Dotrust东信创智23 分钟前
浅谈丨功能安全测试,汽车的守护者
运维·服务器·数据库
Abladol-aj1 小时前
并发和并行的基础知识
java·linux·windows
找藉口是失败者的习惯2 小时前
Jetpack Compose 如何布局解析
android·xml·ui
JunLan~6 小时前
Rocky Linux 系统安装/部署 Docker
linux·docker·容器
方竞7 小时前
Linux空口抓包方法
linux·空口抓包
Estar.Lee7 小时前
查手机号归属地免费API接口教程
android·网络·后端·网络协议·tcp/ip·oneapi
温辉_xh7 小时前
uiautomator案例
android
sun0077008 小时前
ubuntu dpkg 删除安装包
运维·服务器·ubuntu