Android7.0 中添加清除后台应用的广播

--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -85,6 +85,7 @@ import com.android.systemui.recents.views.RecentsView;
 import com.android.systemui.recents.views.SystemBarScrimViews;
 import com.android.systemui.statusbar.BaseStatusBar;
 
+import java.util.ArrayList;
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 
@@ -177,7 +178,10 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
                 // up if the task time is set forward.
                 Prefs.putLong(RecentsActivity.this, Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME,
                         0);
-            }
+            }else if ( action.equals("hwapu.intent.action.KILL_ALLBGAPP")){
+
+                   cleanStack();
+           }
         }
     };
 
@@ -203,6 +207,21 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
         return false;
     }
 
+    private void cleanStack() {
+
+           reloadStackView();
+           TaskStack stack = mRecentsView.getStack();
+
+           ArrayList tasks = stack.getStackTasks();
+           int taskCounts = tasks.size();
+
+           for( int j = 0; j < taskCounts; j++){
+
+                   Task t = tasks.get(j);
+                   mRecentsView.dismissTask(t);
+           }
+    }
+
     /**
      * Dismisses recents back to the launch target task.
      */
@@ -323,6 +342,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(Intent.ACTION_TIME_CHANGED);
+       filter.addAction("hwapu.intent.action.KILL_ALLBGAPP");
         registerReceiver(mSystemBroadcastReceiver, filter);
 
         getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION);
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
index cb59512..336681f 100755
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -72,6 +72,7 @@ import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.misc.Utilities;
 import com.android.systemui.recents.model.Task;
 import com.android.systemui.recents.model.TaskStack;
+import com.android.systemui.recents.model.RecentsTaskLoader;
 import com.android.systemui.recents.views.RecentsTransitionHelper.AnimationSpecComposer;
 import com.android.systemui.stackdivider.WindowManagerProxy;
 import com.android.systemui.statusbar.FlingAnimationUtils;
@@ -813,4 +814,11 @@ public class RecentsView extends FrameLayout {
             mTaskStackView.dump(innerPrefix, writer);
         }
     }
+
+    public void dismissTask(Task t){
+
+           RecentsTaskLoader loader = Recents.getTaskLoader();
+           loader.deleteTaskData(t, false);
+           Recents.getSystemServices().removeTask(t.key.id);
+    }
 }

你可能感兴趣的:(Android系统)