DO NOT MERGE Allow the Car Setup Wizard appl to send CAR_INFORMATION notifications am: f9574845a6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13496867 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I0c72f632fc3cb890b468893d7d6d4cb7f12931d0
This commit is contained in:
@@ -5694,7 +5694,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
+ " trying to post for invalid pkg " + pkg + " in user " + incomingUserId);
|
+ " trying to post for invalid pkg " + pkg + " in user " + incomingUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRestrictedCategories(notification);
|
checkRestrictedCategories(pkg, notification);
|
||||||
|
|
||||||
// Fix the notification as best we can.
|
// Fix the notification as best we can.
|
||||||
try {
|
try {
|
||||||
@@ -8541,7 +8541,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
* Check if the notification is of a category type that is restricted to system use only,
|
* Check if the notification is of a category type that is restricted to system use only,
|
||||||
* if so throw SecurityException
|
* if so throw SecurityException
|
||||||
*/
|
*/
|
||||||
private void checkRestrictedCategories(final Notification notification) {
|
private void checkRestrictedCategories(final String pkg, final Notification notification) {
|
||||||
try {
|
try {
|
||||||
if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0)) {
|
if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0)) {
|
||||||
return;
|
return;
|
||||||
@@ -8551,10 +8551,24 @@ public class NotificationManagerService extends SystemService {
|
|||||||
+ "restrictions check thus the check will be done anyway");
|
+ "restrictions check thus the check will be done anyway");
|
||||||
}
|
}
|
||||||
if (Notification.CATEGORY_CAR_EMERGENCY.equals(notification.category)
|
if (Notification.CATEGORY_CAR_EMERGENCY.equals(notification.category)
|
||||||
|| Notification.CATEGORY_CAR_WARNING.equals(notification.category)
|
|| Notification.CATEGORY_CAR_WARNING.equals(notification.category)) {
|
||||||
|| Notification.CATEGORY_CAR_INFORMATION.equals(notification.category)) {
|
|
||||||
checkCallerIsSystem();
|
checkCallerIsSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Notification.CATEGORY_CAR_INFORMATION.equals(notification.category)) {
|
||||||
|
checkCallerIsSystemOrSUW(pkg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkCallerIsSystemOrSUW(final String pkg) {
|
||||||
|
|
||||||
|
final PackageManagerInternal pmi = LocalServices.getService(
|
||||||
|
PackageManagerInternal.class);
|
||||||
|
String suwPkg = pmi.getSetupWizardPackageName();
|
||||||
|
if (suwPkg != null && suwPkg.equals(pkg)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkCallerIsSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.pm.LauncherApps;
|
import android.content.pm.LauncherApps;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.content.pm.ParceledListSlice;
|
import android.content.pm.ParceledListSlice;
|
||||||
import android.content.pm.ShortcutInfo;
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.content.pm.ShortcutServiceInternal;
|
import android.content.pm.ShortcutServiceInternal;
|
||||||
@@ -243,6 +244,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
Resources mResources;
|
Resources mResources;
|
||||||
@Mock
|
@Mock
|
||||||
RankingHandler mRankingHandler;
|
RankingHandler mRankingHandler;
|
||||||
|
@Mock
|
||||||
|
protected PackageManagerInternal mPackageManagerInternal;
|
||||||
|
|
||||||
private static final int MAX_POST_DELAY = 1000;
|
private static final int MAX_POST_DELAY = 1000;
|
||||||
|
|
||||||
@@ -1186,6 +1189,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
assertEquals(0, mBinderService.getActiveNotifications(PKG).length);
|
assertEquals(0, mBinderService.getActiveNotifications(PKG).length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnqueuedRestrictedNotifications_asSuwApp() throws Exception {
|
||||||
|
LocalServices.removeServiceForTest(PackageManagerInternal.class);
|
||||||
|
LocalServices.addService(PackageManagerInternal.class, mPackageManagerInternal);
|
||||||
|
when(mPackageManagerInternal.getSetupWizardPackageName()).thenReturn(PKG);
|
||||||
|
|
||||||
|
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE, 0))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
final StatusBarNotification sbn =
|
||||||
|
generateNotificationRecord(mTestNotificationChannel, 0, "", false).getSbn();
|
||||||
|
sbn.getNotification().category = Notification.CATEGORY_CAR_INFORMATION;
|
||||||
|
mBinderService.enqueueNotificationWithTag(PKG, PKG,
|
||||||
|
"testEnqueuedRestrictedNotifications_asSuwApp",
|
||||||
|
sbn.getId(), sbn.getNotification(), sbn.getUserId());
|
||||||
|
|
||||||
|
waitForIdle();
|
||||||
|
assertEquals(1, mBinderService.getActiveNotifications(PKG).length);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockedNotifications_blockedByAssistant() throws Exception {
|
public void testBlockedNotifications_blockedByAssistant() throws Exception {
|
||||||
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
|
when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user