diff --git a/api/system-current.txt b/api/system-current.txt index 3ec3467137928..b8e622b75530b 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -205,6 +205,7 @@ package android { field public static final String REVOKE_RUNTIME_PERMISSIONS = "android.permission.REVOKE_RUNTIME_PERMISSIONS"; field public static final String SCORE_NETWORKS = "android.permission.SCORE_NETWORKS"; field public static final String SECURE_ELEMENT_PRIVILEGED_OPERATION = "android.permission.SECURE_ELEMENT_PRIVILEGED_OPERATION"; + field public static final String SEND_CATEGORY_CAR_NOTIFICATIONS = "android.permission.SEND_CATEGORY_CAR_NOTIFICATIONS"; field public static final String SEND_DEVICE_CUSTOMIZATION_READY = "android.permission.SEND_DEVICE_CUSTOMIZATION_READY"; field public static final String SEND_SHOW_SUSPENDED_APP_DETAILS = "android.permission.SEND_SHOW_SUSPENDED_APP_DETAILS"; field public static final String SEND_SMS_NO_CONFIRMATION = "android.permission.SEND_SMS_NO_CONFIRMATION"; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index c9cecdd70ac1c..560e3c11d2f45 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -4691,6 +4691,12 @@ + + + diff --git a/data/etc/car/com.google.android.car.kitchensink.xml b/data/etc/car/com.google.android.car.kitchensink.xml index 7292e0796bf50..59aa45e1f6e49 100644 --- a/data/etc/car/com.google.android.car.kitchensink.xml +++ b/data/etc/car/com.google.android.car.kitchensink.xml @@ -40,6 +40,7 @@ + diff --git a/non-updatable-api/system-current.txt b/non-updatable-api/system-current.txt index ff3999f090e04..49cad8b587622 100644 --- a/non-updatable-api/system-current.txt +++ b/non-updatable-api/system-current.txt @@ -205,6 +205,7 @@ package android { field public static final String REVOKE_RUNTIME_PERMISSIONS = "android.permission.REVOKE_RUNTIME_PERMISSIONS"; field public static final String SCORE_NETWORKS = "android.permission.SCORE_NETWORKS"; field public static final String SECURE_ELEMENT_PRIVILEGED_OPERATION = "android.permission.SECURE_ELEMENT_PRIVILEGED_OPERATION"; + field public static final String SEND_CATEGORY_CAR_NOTIFICATIONS = "android.permission.SEND_CATEGORY_CAR_NOTIFICATIONS"; field public static final String SEND_DEVICE_CUSTOMIZATION_READY = "android.permission.SEND_DEVICE_CUSTOMIZATION_READY"; field public static final String SEND_SHOW_SUSPENDED_APP_DETAILS = "android.permission.SEND_SHOW_SUSPENDED_APP_DETAILS"; field public static final String SEND_SMS_NO_CONFIRMATION = "android.permission.SEND_SMS_NO_CONFIRMATION"; diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 8368df9e20479..52e90218fd24f 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -8465,7 +8465,10 @@ public class NotificationManagerService extends SystemService { if (Notification.CATEGORY_CAR_EMERGENCY.equals(notification.category) || Notification.CATEGORY_CAR_WARNING.equals(notification.category) || Notification.CATEGORY_CAR_INFORMATION.equals(notification.category)) { - checkCallerIsSystem(); + getContext().enforceCallingPermission( + android.Manifest.permission.SEND_CATEGORY_CAR_NOTIFICATIONS, + String.format("Notification category %s restricted", + notification.category)); } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 86447192a441c..9e7226e7cacfa 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -1086,12 +1086,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } /** - * Confirm the system user on automotive devices can use car categories + * Confirm an application with the SEND_CATEGORY_CAR_NOTIFICATIONS permission on automotive + * devices can use car categories. */ @Test - public void testEnqueuedRestrictedNotifications_asSystem() throws Exception { + public void testEnqueuedRestrictedNotifications_hasPermission() throws Exception { when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0)) .thenReturn(true); + // SEND_CATEGORY_CAR_NOTIFICATIONS is a system-level permission that this test cannot + // obtain. Mocking out enforce permission call to ensure notifications can be created when + // permitted. + doNothing().when(mContext).enforceCallingPermission( + eq("android.permission.SEND_CATEGORY_CAR_NOTIFICATIONS"), anyString()); List categories = Arrays.asList(Notification.CATEGORY_CAR_EMERGENCY, Notification.CATEGORY_CAR_WARNING, Notification.CATEGORY_CAR_INFORMATION); @@ -1114,7 +1120,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { */ @Test public void testEnqueuedRestrictedNotifications_notAutomotive() throws Exception { - mService.isSystemUid = false; when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0)) .thenReturn(false); List categories = Arrays.asList(Notification.CATEGORY_CAR_EMERGENCY, @@ -1134,12 +1139,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } /** - * Confirm if a non-system user tries to use the car categories on a automotive device that - * they will get a security exception + * Confirm if an application tries to use the car categories on a automotive device without the + * SEND_CATEGORY_CAR_NOTIFICATIONS permission that a security exception will be thrown. */ @Test - public void testEnqueuedRestrictedNotifications_badUser() throws Exception { - mService.isSystemUid = false; + public void testEnqueuedRestrictedNotifications_noPermission() throws Exception { when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0)) .thenReturn(true); List categories = Arrays.asList(Notification.CATEGORY_CAR_EMERGENCY,