Companion device mgr doesn't always exist

E.g. on tvs.

Test: runtest systemui-notification
Change-Id: I1f1fd3cc5d361d3854eef5e5726816b50f5d7eb6
Fixes: 37276184
(cherry picked from commit 727a728836d459e8b3547608034fe85e1fd54b79)
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 2c7a61b..d8e7e7d 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -4663,8 +4663,11 @@
 
     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 @@
         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;
diff --git a/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java
index 07e4bb8..f666727 100644
--- a/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -19,6 +19,7 @@
 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 @@
         protected boolean isCallerSystem() {
             return true;
         }
+
+        @Override
+        protected ICompanionDeviceManager getCompanionManager() {
+            return null;
+        }
     }
 
     @Before
@@ -644,4 +650,13 @@
                 new IllegalArgumentException());
         mNotificationManagerService.hasCompanionDevice(mListener);
     }
+
+    @Test
+    @UiThreadTest
+    public void testHasCompanionDevice_noService() throws Exception {
+        mNotificationManagerService = new TestableNotificationManagerService(mContext);
+
+        assertFalse(mNotificationManagerService.hasCompanionDevice(mListener));
+    }
+
 }