Loading services/core/java/com/android/server/notification/NotificationManagerService.java +2 −0 Original line number Diff line number Diff line Loading @@ -2891,6 +2891,7 @@ public class NotificationManagerService extends SystemService { // Backup/restore interface @Override public byte[] getBackupPayload(int user) { checkCallerIsSystem(); if (DBG) Slog.d(TAG, "getBackupPayload u=" + user); //TODO: http://b/22388012 if (user != UserHandle.USER_SYSTEM) { Loading @@ -2911,6 +2912,7 @@ public class NotificationManagerService extends SystemService { @Override public void applyRestore(byte[] payload, int user) { checkCallerIsSystem(); if (DBG) Slog.d(TAG, "applyRestore u=" + user + " payload=" + (payload != null ? new String(payload, StandardCharsets.UTF_8) : null)); if (payload == null) { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +19 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ import java.util.Set; public class NotificationManagerServiceTest extends UiServiceTestCase { private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId"; private final int mUid = Binder.getCallingUid(); private NotificationManagerService mService; private TestableNotificationManagerService mService; private INotificationManager mBinderService; private NotificationManagerInternal mInternalService; @Mock Loading Loading @@ -152,17 +152,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Use a Testable subclass so we can simulate calls from the system without failing. private static class TestableNotificationManagerService extends NotificationManagerService { int countSystemChecks = 0; public TestableNotificationManagerService(Context context) { super(context); } @Override protected boolean isCallingUidSystem() { countSystemChecks++; return true; } @Override protected boolean isCallerSystemOrPhone() { countSystemChecks++; return true; } Loading Loading @@ -2429,4 +2433,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setUid(user2.sbn.getUid()) .setLastNotified(user2.sbn.getPostTime()))); } @Test public void testRestore() throws Exception { int systemChecks = mService.countSystemChecks; mBinderService.applyRestore(null, UserHandle.USER_SYSTEM); assertEquals(1, mService.countSystemChecks - systemChecks); } @Test public void testBackup() throws Exception { int systemChecks = mService.countSystemChecks; mBinderService.getBackupPayload(1); assertEquals(1, mService.countSystemChecks - systemChecks); } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +2 −0 Original line number Diff line number Diff line Loading @@ -2891,6 +2891,7 @@ public class NotificationManagerService extends SystemService { // Backup/restore interface @Override public byte[] getBackupPayload(int user) { checkCallerIsSystem(); if (DBG) Slog.d(TAG, "getBackupPayload u=" + user); //TODO: http://b/22388012 if (user != UserHandle.USER_SYSTEM) { Loading @@ -2911,6 +2912,7 @@ public class NotificationManagerService extends SystemService { @Override public void applyRestore(byte[] payload, int user) { checkCallerIsSystem(); if (DBG) Slog.d(TAG, "applyRestore u=" + user + " payload=" + (payload != null ? new String(payload, StandardCharsets.UTF_8) : null)); if (payload == null) { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +19 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ import java.util.Set; public class NotificationManagerServiceTest extends UiServiceTestCase { private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId"; private final int mUid = Binder.getCallingUid(); private NotificationManagerService mService; private TestableNotificationManagerService mService; private INotificationManager mBinderService; private NotificationManagerInternal mInternalService; @Mock Loading Loading @@ -152,17 +152,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Use a Testable subclass so we can simulate calls from the system without failing. private static class TestableNotificationManagerService extends NotificationManagerService { int countSystemChecks = 0; public TestableNotificationManagerService(Context context) { super(context); } @Override protected boolean isCallingUidSystem() { countSystemChecks++; return true; } @Override protected boolean isCallerSystemOrPhone() { countSystemChecks++; return true; } Loading Loading @@ -2429,4 +2433,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setUid(user2.sbn.getUid()) .setLastNotified(user2.sbn.getPostTime()))); } @Test public void testRestore() throws Exception { int systemChecks = mService.countSystemChecks; mBinderService.applyRestore(null, UserHandle.USER_SYSTEM); assertEquals(1, mService.countSystemChecks - systemChecks); } @Test public void testBackup() throws Exception { int systemChecks = mService.countSystemChecks; mBinderService.getBackupPayload(1); assertEquals(1, mService.countSystemChecks - systemChecks); } }