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

Commit 2cf6d642 authored by Jason Monk's avatar Jason Monk
Browse files

More gracefully handle client death

 - Don't crash
 - Don't listen

Test: runtest --path frameworks/base/services/tests/uiservicestests
Change-Id: I31f526a566d6d11a1a53948a58c5dad51dbe1b17
Fixes: 72540922
parent 90a82350
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ public class PinnedSliceState {
    ContentProviderClient getClient() {
        ContentProviderClient client =
                mService.getContext().getContentResolver().acquireContentProviderClient(mUri);
        if (client == null) return null;
        client.setDetectNotResponding(SLICE_TIMEOUT);
        return client;
    }
@@ -181,6 +182,7 @@ public class PinnedSliceState {
            }
            if (!isPinned()) {
                // All the listeners died, remove from pinned state.
                mService.unlisten(mUri);
                mService.removePinnedSlice(mUri);
            }
        }
@@ -210,6 +212,7 @@ public class PinnedSliceState {
            }
            if (!isPinned()) {
                // All the listeners died, remove from pinned state.
                mService.unlisten(mUri);
                mService.removePinnedSlice(mUri);
            }
        }
@@ -217,6 +220,7 @@ public class PinnedSliceState {

    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 @@ public class PinnedSliceState {

    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 @@ public class PinnedSliceState {

    private void handleSendUnpinned() {
        try (ContentProviderClient client = getClient()) {
            if (client == null) return;
            Bundle b = new Bundle();
            b.putParcelable(SliceProvider.EXTRA_BIND_URI, mUri);
            try {
+1 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ public class PinnedSliceStateTest extends UiServiceTestCase {
        when(binder.isBinderAlive()).thenReturn(false);
        arg.getValue().binderDied();

        verify(mSliceService).unlisten(eq(TEST_URI));
        verify(mSliceService).removePinnedSlice(eq(TEST_URI));
        assertFalse(mPinnedSliceManager.isPinned());
    }