mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
59bf3b75c7
https://review.lineageos.org/c/LineageOS/android_frameworks_base/+/353117 https://review.lineageos.org/q/topic:Q_asb_2023-03 https://review.lineageos.org/q/topic:Q_asb_2023-04 https://review.lineageos.org/q/topic:Q_asb_2023-05 https://review.lineageos.org/q/topic:Q_asb_2023-06 https://review.lineageos.org/q/topic:Q_asb_2023-07 https://review.lineageos.org/q/topic:Q_asb_2023-08 accounted for via patches: https://review.lineageos.org/c/LineageOS/android_system_ca-certificates/+/376560 https://review.lineageos.org/c/LineageOS/android_system_ca-certificates/+/376561 https://review.lineageos.org/c/LineageOS/android_system_ca-certificates/+/376562 https://review.lineageos.org/q/topic:Q_asb_2023-09 https://review.lineageos.org/q/topic:Q_asb_2023-10 https://review.lineageos.org/q/topic:Q_asb_2023-11 accounted for via patches: https://review.lineageos.org/c/LineageOS/android_system_ca-certificates/+/376563 accounted for via manifest change: https://review.lineageos.org/c/LineageOS/android_external_webp/+/376568 https://review.lineageos.org/q/topic:Q_asb_2023-12 https://review.lineageos.org/q/topic:Q_asb_2024-01 https://review.lineageos.org/q/topic:Q_asb_2024-02 https://review.lineageos.org/q/topic:Q_asb_2024-03 Signed-off-by: Tavi <tavi@divested.dev>
110 lines
4.9 KiB
Diff
110 lines
4.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jing Ji <jji@google.com>
|
|
Date: Tue, 25 Oct 2022 22:39:52 -0700
|
|
Subject: [PATCH] DO NOT MERGE: ActivityManager#killBackgroundProcesses can
|
|
kill caller's own app only
|
|
|
|
unless it's a system app.
|
|
|
|
Bug: 239423414
|
|
Bug: 223376078
|
|
Test: atest CtsAppTestCases:ActivityManagerTest
|
|
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:8b382775b258220466a977453905797521e159de)
|
|
Merged-In: Iac6baa889965b8ffecd9a43179a4c96632ad1d02
|
|
Change-Id: Iac6baa889965b8ffecd9a43179a4c96632ad1d02
|
|
---
|
|
core/java/android/app/ActivityManager.java | 3 ++
|
|
core/res/AndroidManifest.xml | 6 +++-
|
|
.../server/am/ActivityManagerService.java | 32 +++++++++++++++++--
|
|
3 files changed, 38 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
|
|
index 556b60bafd16..eff49bc1fe95 100644
|
|
--- a/core/java/android/app/ActivityManager.java
|
|
+++ b/core/java/android/app/ActivityManager.java
|
|
@@ -3452,6 +3452,9 @@ public class ActivityManager {
|
|
* processes to reclaim memory; the system will take care of restarting
|
|
* these processes in the future as needed.
|
|
*
|
|
+ * <p class="note">Third party applications can only use this API to kill their own processes.
|
|
+ * </p>
|
|
+ *
|
|
* @param packageName The name of the package whose processes are to
|
|
* be killed.
|
|
*/
|
|
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
|
|
index 586d9a819d1e..a8dd041454c9 100644
|
|
--- a/core/res/AndroidManifest.xml
|
|
+++ b/core/res/AndroidManifest.xml
|
|
@@ -2379,7 +2379,11 @@
|
|
android:protectionLevel="normal" />
|
|
|
|
<!-- Allows an application to call
|
|
- {@link android.app.ActivityManager#killBackgroundProcesses}.
|
|
+ {@link android.app.ActivityManager#killBackgroundProcesses}.
|
|
+
|
|
+ <p class="note">Third party applications can only use this API to kill their own
|
|
+ processes.</p>
|
|
+
|
|
<p>Protection level: normal
|
|
-->
|
|
<permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
|
|
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
|
|
index efbccb3b8f94..9bf5898102d4 100644
|
|
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
|
|
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
|
|
@@ -4148,8 +4148,20 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|
Slog.w(TAG, msg);
|
|
throw new SecurityException(msg);
|
|
}
|
|
+ final int callingUid = Binder.getCallingUid();
|
|
+ final int callingPid = Binder.getCallingPid();
|
|
+ final int callingAppId = UserHandle.getAppId(callingUid);
|
|
|
|
- userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
|
|
+ ProcessRecord proc;
|
|
+ synchronized (mPidsSelfLocked) {
|
|
+ proc = mPidsSelfLocked.get(callingPid);
|
|
+ }
|
|
+ final boolean hasKillAllPermission = PERMISSION_GRANTED == checkPermission(
|
|
+ android.Manifest.permission.FORCE_STOP_PACKAGES, callingPid, callingUid)
|
|
+ || UserHandle.isCore(callingUid)
|
|
+ || (proc != null && proc.info.isSystemApp());
|
|
+
|
|
+ userId = mUserController.handleIncomingUser(callingPid, callingUid,
|
|
userId, true, ALLOW_FULL_ONLY, "killBackgroundProcesses", null);
|
|
final int[] userIds = mUserController.expandUserId(userId);
|
|
|
|
@@ -4164,7 +4176,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|
targetUserId));
|
|
} catch (RemoteException e) {
|
|
}
|
|
- if (appId == -1) {
|
|
+ if (appId == -1 || (!hasKillAllPermission && appId != callingAppId)) {
|
|
Slog.w(TAG, "Invalid packageName: " + packageName);
|
|
return;
|
|
}
|
|
@@ -4189,6 +4201,22 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|
throw new SecurityException(msg);
|
|
}
|
|
|
|
+ final int callingUid = Binder.getCallingUid();
|
|
+ final int callingPid = Binder.getCallingPid();
|
|
+
|
|
+ ProcessRecord proc;
|
|
+ synchronized (mPidsSelfLocked) {
|
|
+ proc = mPidsSelfLocked.get(callingPid);
|
|
+ }
|
|
+ if (callingUid >= FIRST_APPLICATION_UID
|
|
+ && (proc == null || !proc.info.isSystemApp())) {
|
|
+ final String msg = "Permission Denial: killAllBackgroundProcesses() from pid="
|
|
+ + callingPid + ", uid=" + callingUid + " is not allowed";
|
|
+ Slog.w(TAG, msg);
|
|
+ // Silently return to avoid existing apps from crashing.
|
|
+ return;
|
|
+ }
|
|
+
|
|
final long callingId = Binder.clearCallingIdentity();
|
|
try {
|
|
synchronized (this) {
|