Merge "Modify handling of notifs with invalid sounds" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
08f603903c
@@ -1348,14 +1348,14 @@ public final class NotificationRecord {
|
|||||||
protected void calculateGrantableUris() {
|
protected void calculateGrantableUris() {
|
||||||
final Notification notification = getNotification();
|
final Notification notification = getNotification();
|
||||||
notification.visitUris((uri) -> {
|
notification.visitUris((uri) -> {
|
||||||
visitGrantableUri(uri, false);
|
visitGrantableUri(uri, false, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (notification.getChannelId() != null) {
|
if (notification.getChannelId() != null) {
|
||||||
NotificationChannel channel = getChannel();
|
NotificationChannel channel = getChannel();
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
visitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
|
visitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
|
||||||
& NotificationChannel.USER_LOCKED_SOUND) != 0);
|
& NotificationChannel.USER_LOCKED_SOUND) != 0, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1368,7 +1368,7 @@ public final class NotificationRecord {
|
|||||||
* {@link #mGrantableUris}. Otherwise, this will either log or throw
|
* {@link #mGrantableUris}. Otherwise, this will either log or throw
|
||||||
* {@link SecurityException} depending on target SDK of enqueuing app.
|
* {@link SecurityException} depending on target SDK of enqueuing app.
|
||||||
*/
|
*/
|
||||||
private void visitGrantableUri(Uri uri, boolean userOverriddenUri) {
|
private void visitGrantableUri(Uri uri, boolean userOverriddenUri, boolean isSound) {
|
||||||
if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) return;
|
if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) return;
|
||||||
|
|
||||||
// We can't grant Uri permissions from system
|
// We can't grant Uri permissions from system
|
||||||
@@ -1389,10 +1389,16 @@ public final class NotificationRecord {
|
|||||||
mGrantableUris.add(uri);
|
mGrantableUris.add(uri);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
if (!userOverriddenUri) {
|
if (!userOverriddenUri) {
|
||||||
if (mTargetSdkVersion >= Build.VERSION_CODES.P) {
|
if (isSound) {
|
||||||
throw e;
|
mSound = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||||
|
Log.w(TAG, "Replacing " + uri + " from " + sourceUid + ": " + e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Ignoring " + uri + " from " + sourceUid + ": " + e.getMessage());
|
if (mTargetSdkVersion >= Build.VERSION_CODES.P) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
Log.w(TAG,
|
||||||
|
"Ignoring " + uri + " from " + sourceUid + ": " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -816,8 +816,10 @@ public class NotificationRecordTest extends UiServiceTestCase {
|
|||||||
when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class),
|
when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class),
|
||||||
anyInt(), anyInt())).thenThrow(new SecurityException());
|
anyInt(), anyInt())).thenThrow(new SecurityException());
|
||||||
|
|
||||||
Notification n = mock(Notification.class);
|
channel.setSound(null, null);
|
||||||
when(n.getChannelId()).thenReturn(channel.getId());
|
Notification n = new Notification.Builder(mContext, channel.getId())
|
||||||
|
.setSmallIcon(Icon.createWithContentUri(Uri.parse("content://something")))
|
||||||
|
.build();
|
||||||
StatusBarNotification sbn =
|
StatusBarNotification sbn =
|
||||||
new StatusBarNotification(PKG_P, PKG_P, id1, tag1, uid, uid, n, mUser, null, uid);
|
new StatusBarNotification(PKG_P, PKG_P, id1, tag1, uid, uid, n, mUser, null, uid);
|
||||||
NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
|
NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
|
||||||
@@ -832,6 +834,27 @@ public class NotificationRecordTest extends UiServiceTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCalculateGrantableUris_PappProvided_invalidSound() {
|
||||||
|
IActivityManager am = mock(IActivityManager.class);
|
||||||
|
UriGrantsManagerInternal ugm = mock(UriGrantsManagerInternal.class);
|
||||||
|
when(ugm.checkGrantUriPermission(anyInt(), eq(null), any(Uri.class),
|
||||||
|
anyInt(), anyInt())).thenThrow(new SecurityException());
|
||||||
|
|
||||||
|
channel.setSound(Uri.parse("content://something"), mock(AudioAttributes.class));
|
||||||
|
|
||||||
|
Notification n = mock(Notification.class);
|
||||||
|
when(n.getChannelId()).thenReturn(channel.getId());
|
||||||
|
StatusBarNotification sbn =
|
||||||
|
new StatusBarNotification(PKG_P, PKG_P, id1, tag1, uid, uid, n, mUser, null, uid);
|
||||||
|
NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
|
||||||
|
record.mAm = am;
|
||||||
|
record.mUgmInternal = ugm;
|
||||||
|
|
||||||
|
record.calculateGrantableUris();
|
||||||
|
assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, record.getSound());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateGrantableUris_PuserOverridden() {
|
public void testCalculateGrantableUris_PuserOverridden() {
|
||||||
IActivityManager am = mock(IActivityManager.class);
|
IActivityManager am = mock(IActivityManager.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user