Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit e6fc32e

Browse files
17.1: June ASB work
Signed-off-by: Tavi <[email protected]>
1 parent 203e27b commit e6fc32e

File tree

14 files changed

+905
-15
lines changed

14 files changed

+905
-15
lines changed

Patches/LineageOS-17.1/android_frameworks_base/393587.patch

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 27549d452e6524778c69c1e7a5e0ab6cae04750e Mon Sep 17 00:00:00 2001
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Valentin Iftime <[email protected]>
33
Date: Mon, 16 Oct 2023 09:29:17 +0200
4-
Subject: [PATCH] [BACKPORT] Prioritize system toasts
4+
Subject: [PATCH] Prioritize system toasts
55

66
Insert toasts from system packages at the front of the queue
77
to ensure that apps can't spam with toast to delay system toasts from showing.
@@ -17,10 +17,10 @@ Change-Id: I13547f853476bc88d12026c545aba9f857ce8724
1717
2 files changed, 104 insertions(+), 4 deletions(-)
1818

1919
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
20-
index e09491867f91a..d769ff8e75055 100755
20+
index e09491867f91..d769ff8e7505 100755
2121
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
2222
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
23-
@@ -744,17 +744,21 @@ private void writePolicyXml(OutputStream stream, boolean forBackup, int userId)
23+
@@ -744,17 +744,21 @@ public class NotificationManagerService extends SystemService {
2424

2525
private static final class ToastRecord
2626
{
@@ -43,7 +43,7 @@ index e09491867f91a..d769ff8e75055 100755
4343
this.callback = callback;
4444
this.duration = duration;
4545
this.token = token;
46-
@@ -2481,10 +2485,21 @@ record = mToastQueue.get(index);
46+
@@ -2481,10 +2485,21 @@ public class NotificationManagerService extends SystemService {
4747

4848
Binder token = new Binder();
4949
mWindowManagerInternal.addWindowToken(token, TYPE_TOAST, displayId);
@@ -68,7 +68,7 @@ index e09491867f91a..d769ff8e75055 100755
6868
keepProcessAliveIfNeededLocked(callingPid);
6969
}
7070
// If it's at index 0, it's the current toast. It doesn't matter if it's
71-
@@ -2500,6 +2515,23 @@ record = new ToastRecord(callingPid, pkg, callback, duration, token,
71+
@@ -2500,6 +2515,23 @@ public class NotificationManagerService extends SystemService {
7272
}
7373
}
7474

@@ -93,10 +93,10 @@ index e09491867f91a..d769ff8e75055 100755
9393
public void cancelToast(String pkg, ITransientNotification callback) {
9494
Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
9595
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
96-
index bcb4c49336cf5..4a0aa7c9e8e74 100755
96+
index bcb4c49336cf..4a0aa7c9e8e7 100755
9797
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
9898
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
99-
@@ -4480,6 +4480,74 @@ public void testAlwaysAllowSystemToasts() throws Exception {
99+
@@ -4480,6 +4480,74 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
100100
assertEquals(1, mService.mToastQueue.size());
101101
}
102102

Patches/LineageOS-17.1/android_frameworks_base/393588.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 9a28c009d937e060bb5c10034cb5370129b8ce81 Mon Sep 17 00:00:00 2001
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22
From: Jan Tomljanovic <[email protected]>
33
Date: Fri, 6 Nov 2020 11:28:09 +0000
44
Subject: [PATCH] Don't try to show the current toast again while it's showing.
@@ -19,7 +19,7 @@ Change-Id: Ie4953109314113efae49fa0c5e0c236e6e0dbb23
1919
2 files changed, 39 insertions(+)
2020

2121
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
22-
index d769ff8e75055..7b1c0ac27ab30 100755
22+
index d769ff8e7505..7b1c0ac27ab3 100755
2323
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
2424
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
2525
@@ -437,6 +437,10 @@ public class NotificationManagerService extends SystemService {
@@ -33,7 +33,7 @@ index d769ff8e75055..7b1c0ac27ab30 100755
3333
// The last key in this list owns the hardware.
3434
ArrayList<String> mLights = new ArrayList<>();
3535

36-
@@ -6482,12 +6486,17 @@ public void run() {
36+
@@ -6482,12 +6486,17 @@ public class NotificationManagerService extends SystemService {
3737

3838
@GuardedBy("mToastQueue")
3939
void showNextToastLocked() {
@@ -51,7 +51,7 @@ index d769ff8e75055..7b1c0ac27ab30 100755
5151
return;
5252
} catch (RemoteException e) {
5353
Slog.w(TAG, "Object died trying to show notification " + record.callback
54-
@@ -6519,6 +6528,10 @@ void cancelToastLocked(int index) {
54+
@@ -6519,6 +6528,10 @@ public class NotificationManagerService extends SystemService {
5555
// the list anyway
5656
}
5757

@@ -63,10 +63,10 @@ index d769ff8e75055..7b1c0ac27ab30 100755
6363

6464
mWindowManagerInternal.removeWindowToken(lastToast.token, false /* removeWindows */,
6565
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
66-
index 4a0aa7c9e8e74..0e8cea43063b9 100755
66+
index 4a0aa7c9e8e7..0e8cea43063b 100755
6767
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
6868
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
69-
@@ -4415,6 +4415,32 @@ public void testAllowForegroundToasts() throws Exception {
69+
@@ -4415,6 +4415,32 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
7070
}
7171

7272
@Test
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From 00961ad29e26dde5d4f56de90ac333ceb2fc8d34 Mon Sep 17 00:00:00 2001
2+
From: Jing Ji <[email protected]>
3+
Date: Tue, 25 Oct 2022 22:39:52 -0700
4+
Subject: [PATCH] DO NOT MERGE: ActivityManager#killBackgroundProcesses can
5+
kill caller's own app only
6+
7+
unless it's a system app.
8+
9+
Bug: 239423414
10+
Bug: 223376078
11+
Test: atest CtsAppTestCases:ActivityManagerTest
12+
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d1c95670b248df945784b0f2830acf83b5682de3)
13+
Merged-In: Iac6baa889965b8ffecd9a43179a4c96632ad1d02
14+
AOSP-Change-Id: Iac6baa889965b8ffecd9a43179a4c96632ad1d02
15+
16+
Change-Id: I41cd6fa1f71e950db18a9fd450355c4e6f80ec7d
17+
---
18+
.../server/am/ActivityManagerService.java | 16 ++++++++++++++++
19+
1 file changed, 16 insertions(+)
20+
21+
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
22+
index 234b23a996267..815ddf63e565a 100644
23+
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
24+
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
25+
@@ -4486,6 +4486,22 @@ void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState) {
26+
throw new SecurityException(msg);
27+
}
28+
29+
+ final int callingUid = Binder.getCallingUid();
30+
+ final int callingPid = Binder.getCallingPid();
31+
+
32+
+ ProcessRecord proc;
33+
+ synchronized (mPidsSelfLocked) {
34+
+ proc = mPidsSelfLocked.get(callingPid);
35+
+ }
36+
+ if (callingUid >= FIRST_APPLICATION_UID
37+
+ && (proc == null || !proc.info.isSystemApp())) {
38+
+ final String msg = "Permission Denial: killAllBackgroundProcesses() from pid="
39+
+ + callingPid + ", uid=" + callingUid + " is not allowed";
40+
+ Slog.w(TAG, msg);
41+
+ // Silently return to avoid existing apps from crashing.
42+
+ return;
43+
+ }
44+
+
45+
final long callingId = Binder.clearCallingIdentity();
46+
try {
47+
synchronized (this) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 14804676d97278009b746073e8339374b0cce927 Mon Sep 17 00:00:00 2001
2+
From: Jing Ji <[email protected]>
3+
Date: Thu, 19 Oct 2023 14:22:58 -0700
4+
Subject: [PATCH] DO NOT MERGE: Fix ActivityManager#killBackgroundProcesses
5+
permissions
6+
7+
In the pevious CL, we incorrectly added the permission check in the
8+
killBackgroundProcessesExcept. Now fix this issue.
9+
10+
Bug: 239423414
11+
Bug: 223376078
12+
Test: atest CtsAppTestCases:ActivityManagerTest
13+
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:140fce861944419a375c669010c6c47cd7ff5b37)
14+
Merged-In: I9471a77188ee63ec32cd0c81569193e4ccad885b
15+
Change-Id: I9471a77188ee63ec32cd0c81569193e4ccad885b
16+
---
17+
.../server/am/ActivityManagerService.java | 16 ----------------
18+
1 file changed, 16 deletions(-)
19+
20+
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
21+
index 815ddf63e565a..234b23a996267 100644
22+
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
23+
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
24+
@@ -4486,22 +4486,6 @@ void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState) {
25+
throw new SecurityException(msg);
26+
}
27+
28+
- final int callingUid = Binder.getCallingUid();
29+
- final int callingPid = Binder.getCallingPid();
30+
-
31+
- ProcessRecord proc;
32+
- synchronized (mPidsSelfLocked) {
33+
- proc = mPidsSelfLocked.get(callingPid);
34+
- }
35+
- if (callingUid >= FIRST_APPLICATION_UID
36+
- && (proc == null || !proc.info.isSystemApp())) {
37+
- final String msg = "Permission Denial: killAllBackgroundProcesses() from pid="
38+
- + callingPid + ", uid=" + callingUid + " is not allowed";
39+
- Slog.w(TAG, msg);
40+
- // Silently return to avoid existing apps from crashing.
41+
- return;
42+
- }
43+
-
44+
final long callingId = Binder.clearCallingIdentity();
45+
try {
46+
synchronized (this) {
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Valentin Iftime <[email protected]>
3+
Date: Thu, 1 Feb 2024 13:58:49 +0100
4+
Subject: [PATCH] Verify URI permission for channel sound update from
5+
NotificationListenerService
6+
7+
Check that a privileged NotificationListenerService (CDM) has the permission to access the sound URI
8+
when updating a notification channel.
9+
10+
Test: atest com.android.server.notification.NotificationManagerServiceTest#testUpdateNotificationChannelFromPrivilegedListener_noSoundUriPermission
11+
Bug: 317357401
12+
(cherry picked from commit 9b7bbbf5ad542ecf9ecbf8cd819b468791b443c0)
13+
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f090c0538a27d8658d8a860046d5c5e931302341)
14+
Merged-In: Ic7d2e96e43565e98d2aa29b8f2ba35c142387ba9
15+
Change-Id: Ic7d2e96e43565e98d2aa29b8f2ba35c142387ba9
16+
---
17+
.../NotificationManagerService.java | 21 ++++++
18+
.../NotificationManagerServiceTest.java | 67 +++++++++++++++++++
19+
2 files changed, 88 insertions(+)
20+
21+
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
22+
index 7b1c0ac27ab3..ca957e4d16e3 100755
23+
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
24+
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
25+
@@ -4333,6 +4333,9 @@ public class NotificationManagerService extends SystemService {
26+
Preconditions.checkNotNull(user);
27+
28+
verifyPrivilegedListener(token, user, false);
29+
+ final NotificationChannel originalChannel = mPreferencesHelper.getNotificationChannel(
30+
+ pkg, getUidForPackageAndUser(pkg, user), channel.getId(), true);
31+
+ verifyPrivilegedListenerUriPermission(Binder.getCallingUid(), channel, originalChannel);
32+
updateNotificationChannelInt(pkg, getUidForPackageAndUser(pkg, user), channel, true);
33+
}
34+
35+
@@ -4412,6 +4415,24 @@ public class NotificationManagerService extends SystemService {
36+
}
37+
}
38+
39+
+ private void verifyPrivilegedListenerUriPermission(int sourceUid,
40+
+ @NonNull NotificationChannel updateChannel,
41+
+ @Nullable NotificationChannel originalChannel) {
42+
+ // Check that the NLS has the required permissions to access the channel
43+
+ final Uri soundUri = updateChannel.getSound();
44+
+ final Uri originalSoundUri =
45+
+ (originalChannel != null) ? originalChannel.getSound() : null;
46+
+ if (soundUri != null && !Objects.equals(originalSoundUri, soundUri)) {
47+
+ Binder.withCleanCallingIdentity(() -> {
48+
+ mUgmInternal.checkGrantUriPermission(sourceUid, null,
49+
+ ContentProvider.getUriWithoutUserId(soundUri),
50+
+ Intent.FLAG_GRANT_READ_URI_PERMISSION,
51+
+ ContentProvider.getUserIdFromUri(soundUri,
52+
+ UserHandle.getUserId(sourceUid)));
53+
+ });
54+
+ }
55+
+ }
56+
+
57+
private int getUidForPackageAndUser(String pkg, UserHandle user) throws RemoteException {
58+
int uid = 0;
59+
long identity = Binder.clearCallingIdentity();
60+
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
61+
index 0e8cea43063b..403772d0f875 100755
62+
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
63+
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
64+
@@ -2037,6 +2037,73 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
65+
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
66+
}
67+
68+
+ @Test
69+
+ public void testUpdateNotificationChannelFromPrivilegedListener_noSoundUriPermission()
70+
+ throws Exception {
71+
+ mService.setPreferencesHelper(mPreferencesHelper);
72+
+ List<String> associations = new ArrayList<>();
73+
+ associations.add("a");
74+
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
75+
+ .thenReturn(associations);
76+
+ when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
77+
+ eq(mTestNotificationChannel.getId()), anyBoolean()))
78+
+ .thenReturn(mTestNotificationChannel);
79+
+
80+
+ final Uri soundUri = Uri.parse("content://media/test/sound/uri");
81+
+ final NotificationChannel updatedNotificationChannel = new NotificationChannel(
82+
+ TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT);
83+
+ updatedNotificationChannel.setSound(soundUri,
84+
+ updatedNotificationChannel.getAudioAttributes());
85+
+
86+
+ doThrow(new SecurityException("no access")).when(mUgmInternal)
87+
+ .checkGrantUriPermission(eq(Process.myUid()), any(), eq(soundUri),
88+
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
89+
+
90+
+ assertThrows(SecurityException.class,
91+
+ () -> mBinderService.updateNotificationChannelFromPrivilegedListener(null, PKG,
92+
+ Process.myUserHandle(), updatedNotificationChannel));
93+
+
94+
+ verify(mPreferencesHelper, never()).updateNotificationChannel(
95+
+ anyString(), anyInt(), any(), anyBoolean());
96+
+
97+
+ verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG),
98+
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
99+
+ eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
100+
+ }
101+
+
102+
+ @Test
103+
+ public void testUpdateNotificationChannelFromPrivilegedListener_noSoundUriPermission_sameSound()
104+
+ throws Exception {
105+
+ mService.setPreferencesHelper(mPreferencesHelper);
106+
+ List<String> associations = new ArrayList<>();
107+
+ associations.add("a");
108+
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
109+
+ .thenReturn(associations);
110+
+ when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
111+
+ eq(mTestNotificationChannel.getId()), anyBoolean()))
112+
+ .thenReturn(mTestNotificationChannel);
113+
+
114+
+ final Uri soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
115+
+ final NotificationChannel updatedNotificationChannel = new NotificationChannel(
116+
+ TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT);
117+
+ updatedNotificationChannel.setSound(soundUri,
118+
+ updatedNotificationChannel.getAudioAttributes());
119+
+
120+
+ doThrow(new SecurityException("no access")).when(mUgmInternal)
121+
+ .checkGrantUriPermission(eq(Process.myUid()), any(), eq(soundUri),
122+
+ anyInt(), eq(Process.myUserHandle().getIdentifier()));
123+
+
124+
+ mBinderService.updateNotificationChannelFromPrivilegedListener(
125+
+ null, PKG, Process.myUserHandle(), updatedNotificationChannel);
126+
+
127+
+ verify(mPreferencesHelper, times(1)).updateNotificationChannel(
128+
+ anyString(), anyInt(), any(), anyBoolean());
129+
+
130+
+ verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG),
131+
+ eq(Process.myUserHandle()), eq(mTestNotificationChannel),
132+
+ eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
133+
+ }
134+
+
135+
@Test
136+
public void testGetNotificationChannelFromPrivilegedListener_cdm_success() throws Exception {
137+
mService.setPreferencesHelper(mPreferencesHelper);

0 commit comments

Comments
 (0)