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

Commit 91e37de0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Prevent crash when a Browsable player has an empty root"

parents b21a3036 2a905c63
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -207,7 +207,15 @@ class BrowsedPlayerWrapper {
            Log.i(TAG, "onConnected: " + mPackageName + " is connected");
            // Get the root while connected because we may need to use it when disconnected.
            mRoot = mWrappedBrowser.getRoot();
            if (mCallback != null) mCallback.run(STATUS_SUCCESS, BrowsedPlayerWrapper.this);

            if (mCallback == null) return;

            if (mRoot == null || mRoot.isEmpty()) {
                mCallback.run(STATUS_CONN_ERROR, BrowsedPlayerWrapper.this);
                return;
            }

            mCallback.run(STATUS_SUCCESS, BrowsedPlayerWrapper.this);
            mCallback = null;
        }

+17 −0
Original line number Diff line number Diff line
@@ -87,6 +87,23 @@ public class BrowserPlayerWrapperTest {
        verify(mMockBrowser, times(2)).disconnect();
    }

    @Test
    public void testEmptyRoot() {
        BrowsedPlayerWrapper wrapper = BrowsedPlayerWrapper.wrap(null, "test", "test");

        doReturn("").when(mMockBrowser).getRoot();

        wrapper.connect(mConnCb);
        verify(mMockBrowser).testInit(any(), any(), mBrowserConnCb.capture(), any());
        MediaBrowser.ConnectionCallback browserConnCb = mBrowserConnCb.getValue();

        verify(mMockBrowser, times(1)).connect();

        browserConnCb.onConnected();
        verify(mConnCb).run(eq(BrowsedPlayerWrapper.STATUS_CONN_ERROR), eq(wrapper));
        verify(mMockBrowser, times(1)).disconnect();
    }

    @Test
    public void testDisconnect() {
        BrowsedPlayerWrapper wrapper = BrowsedPlayerWrapper.wrap(null, "test", "test");