当前位置: 首页 > article >正文

Android 7.1 点击清空全部按钮清空一切运行进程(包括后台在播音乐)

Android 7.1 点击清空全部按钮清空一切运行进程(包括后台在播音乐)

近来收到客户反馈说音乐在后台播放时点击“清空全部”按钮后台音乐没有被kill掉,仍在播放,需要在点击“清空全部”后kill掉一切后台运行进程,具体修改参照如下:

/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

    private void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess,
            boolean removeFromRecents) {
        if (removeFromRecents) {
            mRecentTasks.remove(tr);
            tr.removedFromRecents();
        }
        ComponentName component = tr.getBaseIntent().getComponent();
        if (component == null) {
            Slog.w(TAG, "No component for base intent of task: " + tr);
            return;
        }

        // Find any running services associated with this app and stop if needed.
        mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent()));

        if (!killProcess) {
            return;
        }

        // Determine if the process(es) for this task should be killed.
        final String pkg = component.getPackageName();
        ArrayList<ProcessRecord> procsToKill = new ArrayList<>();
        ArrayMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
        for (int i = 0; i < pmap.size(); i++) {

            SparseArray<ProcessRecord> uids = pmap.valueAt(i);
            for (int j = 0; j < uids.size(); j++) {
                ProcessRecord proc = uids.valueAt(j);
                if (proc.userId != tr.userId) {
                    // Don't kill process for a different user.
                    continue;
                }
                if (proc == mHomeProcess) {
                    // Don't kill the home process along with tasks from the same package.
                    continue;
                }
                if (!proc.pkgList.containsKey(pkg)) {
                    // Don't kill process that is not associated with this task.
                    continue;
                }

                for (int k = 0; k < proc.activities.size(); k++) {
                    TaskRecord otherTask = proc.activities.get(k).task;
                    if (tr.taskId != otherTask.taskId && otherTask.inRecents) {
                        // Don't kill process(es) that has an activity in a different task that is
                        // also in recents.
                        return;
                    }
                }

-                if (proc.foregroundServices) {
-                    // Don't kill process(es) with foreground service.
-                    return;
-                }

                // Add process to kill list.
                procsToKill.add(proc);
            }
        }

        // Kill the running processes.
        for (int i = 0; i < procsToKill.size(); i++) {
            ProcessRecord pr = procsToKill.get(i);

-            if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND
-                    && pr.curReceiver == null) {
                pr.kill("remove task", true);
-            } else {
-                // We delay killing processes that are not in the background or running a receiver.
-                pr.waitingToKill = "remove task";
-            }
        }
    }

重新编译验证,修改生效,点击“清空全部”按钮后台在播音乐被kill掉


http://www.kler.cn/news/157103.html

相关文章:

  • 【Linux】进程控制--进程创建/进程终止/进程等待/进程程序替换/简易shell实现
  • CPP-SCNUOJ-Problem P29. [算法课指针] 颜色分类,小白偏题超简单方法
  • 前端---JavaScript篇
  • 【LeeCode】链表总结
  • 大数据之Redis
  • Python按要求从多个txt文本中提取指定数据
  • 卷积神经网络(CNN):艺术作品识别
  • 【算法每日一练]-图论(保姆级教程 篇6(图上dp))#最大食物链 #游走
  • redis的缓存击穿,缓存穿透,缓存雪崩
  • 2023年抗量子加密的十件大事
  • java后端redis缓存缓存预热
  • Ubuntu开机出现Welcome to emergency mode解决办法
  • 【qml入门系列教程】:qml QtObject用法介绍
  • c++ day5
  • Windows下打包C++程序无法执行:无法定位程序输入点于动态链接库
  • PTA 7-225 sdut-C语言实验- 冒泡排序中数据交换的次数
  • 继承 多态 拆箱装箱 128陷阱 枚举类
  • 【Java】类和对象之超级详细的总结!!!
  • PPT NO.4 更改PPT“另存为”分辨率
  • java中一个空的Object对象在HotSpot虚拟机中占用多大的内存空间?
  • Vue3 组合式实现 带连接线的Tree型 架构图(一级树形图)
  • 基于springboot + vue框架的网上商城系统
  • Android多用户初探
  • vscode里面使用vue的一些插件,方便开发
  • Spring Security 6.x 系列(8)—— 源码分析之配置器SecurityConfigurer接口及其分支实现
  • MySQL官网推荐书籍
  • 【接口测试】POST请求提交数据的三种方式及Postman实现
  • 【广州华锐视点】机械零件拆装VR仿真教学系统
  • 【EI会议征稿】第五届人工智能与机电自动化国际学术会议(AIEA 2024)
  • bad_python