Created
September 3, 2018 09:12
-
-
Save cysin/1353c8d7fd15f529f5daf164ec148c31 to your computer and use it in GitHub Desktop.
a patch to force stop app for android systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project frameworks/base/ | |
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml | |
index 070634b..3e359b4 100644 | |
--- a/packages/SystemUI/AndroidManifest.xml | |
+++ b/packages/SystemUI/AndroidManifest.xml | |
@@ -90,6 +90,8 @@ | |
<uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" /> | |
<uses-permission android:name="android.permission.START_TASKS_FROM_RECENTS" /> | |
<uses-permission android:name="android.permission.GET_INTENT_SENDER_INTENT" /> | |
+ <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" /> | |
+ <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> | |
<!-- WindowManager --> | |
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" /> | |
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java | |
index 86b7790..c30a3d8 100644 | |
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java | |
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java | |
@@ -824,6 +824,13 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD | |
// Remove the task from activity manager | |
SystemServicesProxy ssp = Recents.getSystemServices(); | |
+ if(event.task.topActivity != null) { | |
+ String pkgName = event.task.topActivity.getPackageName(); | |
+ Log.w("CYSIN", "Force stopping: " + pkgName); | |
+ if(pkgName != null && !pkgName.isEmpty()) { | |
+ ssp.forceStopPackage(pkgName); | |
+ } | |
+ } | |
ssp.removeTask(event.task.key.id); | |
} | |
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java | |
index c9ef43e..8a30858 100644 | |
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java | |
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java | |
@@ -806,6 +806,19 @@ public class SystemServicesProxy { | |
}); | |
} | |
+ /** Force stop the task */ | |
+ public void forceStopPackage(String pkgName) { | |
+ if (mAm == null) return; | |
+ if (RecentsDebugFlags.Static.EnableMockTasks) return; | |
+ | |
+ // force stop the task. | |
+ mUiOffloadThread.submit(() -> { | |
+ //mAm.removeTask(taskId); | |
+ mAm.forceStopPackage(pkgName); | |
+ mAm.killBackgroundProcesses(pkgName); | |
+ }); | |
+ } | |
+ | |
/** | |
* Sends a message to close other system windows. | |
*/ | |
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java | |
index 9d823a7..07cb50e 100644 | |
--- a/services/core/java/com/android/server/am/ActiveServices.java | |
+++ b/services/core/java/com/android/server/am/ActiveServices.java | |
@@ -2685,7 +2685,7 @@ public final class ActiveServices { | |
// We are done with the associated start arguments. | |
r.findDeliveredStart(startId, true); | |
// Don't stop if killed. | |
- r.stopIfKilled = false; | |
+ r.stopIfKilled = true; | |
break; | |
} | |
case Service.START_NOT_STICKY: { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment