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掉

相关推荐

  1. Android 清除临时文件,缓存

    2023-12-05 21:08:05       38 阅读
  2. Kafka Topic

    2023-12-05 21:08:05       40 阅读
  3. c# BlockingCollection

    2023-12-05 21:08:05       32 阅读
  4. redislist

    2023-12-05 21:08:05       13 阅读
  5. elasticsearch 数据接口

    2023-12-05 21:08:05       45 阅读
  6. js怎么数组?

    2023-12-05 21:08:05       22 阅读

最近更新

  1. Android Camera Framework:从基础到高级

    2023-12-05 21:08:05       0 阅读
  2. React Native与React Native Web:跨平台开发的新选择

    2023-12-05 21:08:05       0 阅读
  3. React Native

    2023-12-05 21:08:05       0 阅读
  4. ——探索从懵懂学童到职场人的期待与感悟

    2023-12-05 21:08:05       1 阅读
  5. ArduPilot开源代码之AP_MSP

    2023-12-05 21:08:05       1 阅读
  6. dify-on-wechat中涉及企业微信几个函数解析

    2023-12-05 21:08:05       1 阅读
  7. 【maya插件开发】vscode debug python 代码

    2023-12-05 21:08:05       1 阅读
  8. 【AI应用探讨】—主成分分析(PCA)应用场景

    2023-12-05 21:08:05       1 阅读
  9. 基数排序算法Python实现

    2023-12-05 21:08:05       1 阅读
  10. qt todoapp

    2023-12-05 21:08:05       1 阅读

热门阅读

  1. 【python 爬取接口数据】

    2023-12-05 21:08:05       42 阅读
  2. 【防抖和节流】Vue和React当中的防抖和节流处理

    2023-12-05 21:08:05       31 阅读