Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d78263d6 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add permission checks

Change-Id: Id85bd27ff94ef248c0e53a7876035a5c3e05dda3
Fixes: 72686578
Test: runtest systemui-notification
parent 099267f3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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) {
@@ -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) {
+19 −1
Original line number Diff line number Diff line
@@ -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
@@ -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;
        }

@@ -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);
    }
}