removeTask

摘要:
=0;IntentbaseIntent=newIntent(tr.intent!=null?tr.intent:tr.affinityIntent);ComponentNamecomponent=baseIntent.getComponent();if(component==null){Slog.w(TAG,"Nowcomponentforbaseintentoftask:"+tr);return;}//Findanyrunningservicesassociatedwiththisapp.mServices.cleanUpRemovedTaskLocked(tr,component,baseIntent);④if(killProcesses){//Findanyrunningprocessesassociatedwiththisapp.finalStringpkg=component.getPackageName();ArrayListprocs=newArrayList();ArrayMap˂String,SparseArray˃pmap=mProcessNames.getMap();for(inti=0;i˂pmap.size();i++){SparseArrayuids=pmap.valueAt(i);for(intj=0;j˂uids.size();j++){ProcessRecordproc=uids.valueAt(j);if(proc.userId!=tr.userId){continue;}if(!

SystemUI中,Home键调出小刷子杀最近任务,整个流程从其RecentsPanelView.java开始:

removeTask第1张removeTask第2张
View Codepublic void handleSwipe(View view) {
...
// Currently, either direction means the same thing, so ignore direction and remove
        // the task.
        final ActivityManager am = (ActivityManager)
                getContext().getSystemService(Context.ACTIVITY_SERVICE);
        if (am != null) {
            am.removeTask(ad.persistentTaskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);①
            // Accessibility feedback
            setContentDescription(
                    getContext().getString(R.string.accessibility_recents_item_dismissed, ad.getLabel()));
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
            setContentDescription(null);
        }
}

ActivityManagerService.java

removeTask第3张removeTask第4张
View Codeprivate void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
        mRecentTasks.remove(tr);
        tr.removedFromRecents(mTaskPersister);
        final boolean killProcesses = (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
        Intent baseIntent = new Intent(
                tr.intent != null ? tr.intent : tr.affinityIntent);
        ComponentName component = baseIntent.getComponent();
        if (component == null) {
            Slog.w(TAG, "Now component for base intent of task: " + tr);
            return;
        }
        // Find any running services associated with this app.
        mServices.cleanUpRemovedTaskLocked(tr, component, baseIntent);④
        if (killProcesses) {
            // Find any running processes associated with this app.
            final String pkg = component.getPackageName();
            ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
            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) {
                        continue;
                    }
                    if (!proc.pkgList.containsKey(pkg)) {
                        continue;
                    }
                    procs.add(proc);
                }
            }
            // Kill the running processes.
            for (int i=0; i<procs.size(); i++) {
                ProcessRecord pr = procs.get(i);
                if (pr == mHomeProcess) {
                    // Don't kill the home process along with tasks from the same package.
                    continue;
                }
                if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
                    pr.kill("remove task", true);
                } else {
                    pr.waitingToKill = "remove task";
                }
            }
        }
    }
/**
     * Removes the task with the specified task id.
     *
     * @param taskId Identifier of the task to be removed.
     * @param flags Additional operational flags.  May be 0 or
     * {@link ActivityManager#REMOVE_TASK_KILL_PROCESS}.
     * @return Returns true if the given task was found and removed.
     */
    private boolean removeTaskByIdLocked(int taskId, int flags) {
        TaskRecord tr = recentTaskForIdLocked(taskId);
        if (tr != null) {
            tr.removeTaskActivitiesLocked();
            cleanUpRemovedTaskLocked(tr, flags);③
            if (tr.isPersistable) {
                notifyTaskPersisterLocked(null, true);
            }
            return true;
        }
        return false;
    }
    @Override
    public boolean removeTask(int taskId, int flags) {
        synchronized (this) {
            enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,
                    "removeTask()");
            long ident = Binder.clearCallingIdentity();
            try {
                return removeTaskByIdLocked(taskId, flags);②
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    }

ActiveServices.java

removeTask第5张removeTask第6张
View Codevoid cleanUpRemovedTaskLocked(TaskRecord tr, ComponentName component, Intent baseIntent) {
        ArrayList<ServiceRecord> services = new ArrayList<ServiceRecord>();
        ArrayMap<ComponentName, ServiceRecord> alls = getServices(tr.userId);
        for (int i=0; i<alls.size(); i++) {
            ServiceRecord sr = alls.valueAt(i);
            if (sr.packageName.equals(component.getPackageName())) {
                services.add(sr);
            }
        }
        // Take care of any running services associated with the app.
        for (int i=0; i<services.size(); i++) {
            ServiceRecord sr = services.get(i);
            if (sr.startRequested) {
                if ((sr.serviceInfo.flags&ServiceInfo.FLAG_STOP_WITH_TASK) != 0) {
                    Slog.i(TAG, "Stopping service " + sr.shortName + ": remove task");
                    stopServiceLocked(sr);
                } else {
                    sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true,
                            sr.makeNextStartId(), baseIntent, null));
                    if (sr.app != null && sr.app.thread != null) {
                        // We always run in the foreground, since this is called as
                        // part of the "remove task" UI operation.
                        sendServiceArgsLocked(sr, true, false);
                    }
                }
            }
        }
    }

TaskRecord.java

removeTask第7张removeTask第8张
View Code/**
     * Completely remove all activities associated with an existing
     * task starting at a specified index.
     */
    final void performClearTaskAtIndexLocked(int activityNdx) {
        int numActivities = mActivities.size();
        for ( ; activityNdx < numActivities; ++activityNdx) {
            final ActivityRecord r = mActivities.get(activityNdx);
            if (r.finishing) {
                continue;
            }
            if (stack == null) {
                // Task was restored from persistent storage.
                r.takeFromHistory();
                mActivities.remove(activityNdx);
                --activityNdx;
                --numActivities;
            } else if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear",
                    false)) {
                --activityNdx;
                --numActivities;
            }
        }
    }
    /**
     * Completely remove all activities associated with an existing task.
     */
    final void performClearTaskLocked() {
        mReuseTask = true;
        performClearTaskAtIndexLocked(0);
        mReuseTask = false;
    }

Process.java

removeTask第9张removeTask第10张
View Code/**
     * Background thread group - All threads in
     * this group are scheduled with a reduced share of the CPU.
     * Value is same as constant SP_BACKGROUND of enum SchedPolicy.
     * FIXME rename to THREAD_GROUP_BACKGROUND.
     * @hide
     */
    public static final int THREAD_GROUP_BG_NONINTERACTIVE = 0;

免责声明:文章转载自《removeTask》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【转载】Oracle sqlplus中最简单的一些命令,设置显示的格式用sessionStorage保存登录名并在其他页面获取显示下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

极验验证码破解之selenium

大家好。我是星星在线,我又来了。今天,我给大家带来极性验证码的硒裂解方法。你有点兴奋吗?你们等不及了。让我们直奔主题。首先,随机找到一个特征点,检查元素,看它是否位于div元素,然后查看它后面的位置。距离已确定。以下是移动硒的大量模拟操作。我们只需要确认需要哪些接口。...

selenium自动化之鼠标操作

,selenium为我们提供了一个处理此类事件的类——ActionChains。ActionChains可以模拟鼠标操作,例如单击、双击、右键单击、拖动等。鼠标移动时演示页面的截图:demo1.使用鼠标移动到WriteonOver按钮的顶部。python脚本如下:读取鼠标移动代码,首先定义浏览器驱动程序,最大化窗口,打开测试页面URL,定位到测试按钮顶部,定...

部署springboot+vue项目文档(若依ruoyi项目部署步骤)

1: 部署Linux+nginx部署背景代码1.1因为我使用了idea工具进行开发,所以终端中的mvnclean包生成了相应的jar包。这个jar包可以在相应文件所在目录的目标中找到。linux服务器需要加载redis和nginx。redis存储缓存数据,nginx用于代理前端和后端服务。打包vue项目并将dist文件复制到tomcat的webapps目录中...

C# 没落了吗?

首先,这个数字--------------------------------------------C#是否正在衰落与微软的整个平台密切相关。近年来,使用C#的人越来越少,这也是因为越来越少的人专门为Microsoft平台开发产品。现在是移动时代,微软基本上错过了互联网和移动互联网这两波浪潮。现在生活不容易。在软件工程中,人们常说“唯一不变的就是改变本身”...

vue的富文本编辑器使用,并且添加显示当前输入字数

{模块:{工具栏:{标题:{script://indent〔{direction:text align:background:}.editor{line-height:}.ql editor{line-high:content:padding right:...

狼人杀规则

自爆后,所有演讲立即暂停,进入夜间。自爆后的那晚,狼人可以指着那把刀。预言家只能验证某个玩家是否是狼人,除狼人是否是狼人之外的所有信息都无法验证。如果先知测试丘比特,法官不必担心丘比特是哪一个阵营,只会展示好人的手势。...