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

Commit 94d7dba7 authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Companion device mgr doesn't always exist" into oc-dev am: 3d6225b4

am: a98a3444

Change-Id: I4d540fadf69842a45fc86f08f8fc3f10cab5a0c7
parents 8d90496b a98a3444
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -4663,8 +4663,11 @@ public class NotificationManagerService extends SystemService {

    boolean hasCompanionDevice(ManagedServiceInfo info) {
        if (mCompanionManager == null) {
            mCompanionManager = ICompanionDeviceManager.Stub.asInterface(
                    ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE));
            mCompanionManager = getCompanionManager();
        }
        // Companion mgr doesn't exist on all device types
        if (mCompanionManager == null) {
            return false;
        }
        long identity = Binder.clearCallingIdentity();
        try {
@@ -4685,6 +4688,11 @@ public class NotificationManagerService extends SystemService {
        return false;
    }

    protected ICompanionDeviceManager getCompanionManager() {
        return ICompanionDeviceManager.Stub.asInterface(
                ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE));
    }

    private boolean isVisibleToListener(StatusBarNotification sbn, ManagedServiceInfo listener) {
        if (!listener.enabledAndUserMatches(sbn.getUserId())) {
            return false;
+15 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.notification;
import static android.app.NotificationManager.IMPORTANCE_LOW;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;

@@ -99,6 +100,11 @@ public class NotificationManagerServiceTest {
        protected boolean isCallerSystem() {
            return true;
        }

        @Override
        protected ICompanionDeviceManager getCompanionManager() {
            return null;
        }
    }

    @Before
@@ -644,4 +650,13 @@ public class NotificationManagerServiceTest {
                new IllegalArgumentException());
        mNotificationManagerService.hasCompanionDevice(mListener);
    }

    @Test
    @UiThreadTest
    public void testHasCompanionDevice_noService() throws Exception {
        mNotificationManagerService = new TestableNotificationManagerService(mContext);

        assertFalse(mNotificationManagerService.hasCompanionDevice(mListener));
    }

}