Merge "More gracefully handle client death"
diff --git a/services/core/java/com/android/server/slice/PinnedSliceState.java b/services/core/java/com/android/server/slice/PinnedSliceState.java
index 5811714..192fd63 100644
--- a/services/core/java/com/android/server/slice/PinnedSliceState.java
+++ b/services/core/java/com/android/server/slice/PinnedSliceState.java
@@ -166,6 +166,7 @@
     ContentProviderClient getClient() {
         ContentProviderClient client =
                 mService.getContext().getContentResolver().acquireContentProviderClient(mUri);
+        if (client == null) return null;
         client.setDetectNotResponding(SLICE_TIMEOUT);
         return client;
     }
@@ -181,6 +182,7 @@
             }
             if (!isPinned()) {
                 // All the listeners died, remove from pinned state.
+                mService.unlisten(mUri);
                 mService.removePinnedSlice(mUri);
             }
         }
@@ -210,6 +212,7 @@
             }
             if (!isPinned()) {
                 // All the listeners died, remove from pinned state.
+                mService.unlisten(mUri);
                 mService.removePinnedSlice(mUri);
             }
         }
@@ -217,6 +220,7 @@
 
     private Slice doBind(String overridePkg) {
         try (ContentProviderClient client = getClient()) {
+            if (client == null) return null;
             Bundle extras = new Bundle();
             extras.putParcelable(SliceProvider.EXTRA_BIND_URI, mUri);
             extras.putParcelableArrayList(SliceProvider.EXTRA_SUPPORTED_SPECS,
@@ -237,6 +241,7 @@
 
     private void handleSendPinned() {
         try (ContentProviderClient client = getClient()) {
+            if (client == null) return;
             Bundle b = new Bundle();
             b.putParcelable(SliceProvider.EXTRA_BIND_URI, mUri);
             try {
@@ -249,6 +254,7 @@
 
     private void handleSendUnpinned() {
         try (ContentProviderClient client = getClient()) {
+            if (client == null) return;
             Bundle b = new Bundle();
             b.putParcelable(SliceProvider.EXTRA_BIND_URI, mUri);
             try {
diff --git a/services/tests/uiservicestests/src/com/android/server/slice/PinnedSliceStateTest.java b/services/tests/uiservicestests/src/com/android/server/slice/PinnedSliceStateTest.java
index d3bb804..1606bd9 100644
--- a/services/tests/uiservicestests/src/com/android/server/slice/PinnedSliceStateTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/slice/PinnedSliceStateTest.java
@@ -198,6 +198,7 @@
         when(binder.isBinderAlive()).thenReturn(false);
         arg.getValue().binderDied();
 
+        verify(mSliceService).unlisten(eq(TEST_URI));
         verify(mSliceService).removePinnedSlice(eq(TEST_URI));
         assertFalse(mPinnedSliceManager.isPinned());
     }