Merge "Adding null check when unregistering slice relay handler" into qt-dev
diff --git a/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java b/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java
index 922c65e..b3fc69e 100644
--- a/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java
@@ -59,7 +59,10 @@
         } else if (SliceBroadcastRelay.ACTION_UNREGISTER.equals(intent.getAction())) {
             Uri uri = intent.getParcelableExtra(SliceBroadcastRelay.EXTRA_URI);
             if (DEBUG) Log.d(TAG, "Unregister " + uri);
-            getAndRemoveRelay(uri).unregister(mContext);
+            BroadcastRelay relay = getAndRemoveRelay(uri);
+            if (relay != null) {
+                relay.unregister(mContext);
+            }
         }
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java
index c6e85c3..19e1a5c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java
@@ -95,6 +95,22 @@
     }
 
     @Test
+    public void testUnregisterWithoutRegister() {
+        Uri testUri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority("something")
+                .path("test")
+                .build();
+        SliceBroadcastRelayHandler relayHandler = new SliceBroadcastRelayHandler();
+        relayHandler.mContext = spy(mContext);
+
+        Intent intent = new Intent(SliceBroadcastRelay.ACTION_UNREGISTER);
+        intent.putExtra(SliceBroadcastRelay.EXTRA_URI, ContentProvider.maybeAddUserId(testUri, 0));
+        relayHandler.handleIntent(intent);
+        // No crash
+    }
+
+    @Test
     public void testRelay() {
         Receiver.sReceiver = mock(BroadcastReceiver.class);
         Uri testUri = new Uri.Builder()