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

Commit e4767e39 authored by Hyundo Moon's avatar Hyundo Moon Committed by Android (Google) Code Review
Browse files

Merge "MediaBrowser2: Implement search()/getSearchResult()"

parents 1a8cac04 2f60a419
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -65,5 +65,8 @@ oneway interface IMediaSession2 {
    void getBrowserRoot(IMediaSession2Callback callback, in Bundle rootHints);
    void getItem(IMediaSession2Callback callback, String mediaId);
    void getChildren(IMediaSession2Callback callback, String parentId, int page, int pageSize,
            in Bundle options);
            in Bundle extras);
    void search(IMediaSession2Callback callback, String query, in Bundle extras);
    void getSearchResult(IMediaSession2Callback callback, String query, int page, int pageSize,
            in Bundle extras);
}
+3 −1
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ oneway interface IMediaSession2Callback {
    //////////////////////////////////////////////////////////////////////////////////////////////
    void onGetRootResult(in Bundle rootHints, String rootMediaId, in Bundle rootExtra);
    void onItemLoaded(String mediaId, in Bundle result);
    void onChildrenLoaded(String parentId, int page, int pageSize, in Bundle options,
    void onChildrenLoaded(String parentId, int page, int pageSize, in Bundle extras,
            in List<Bundle> result);
    void onSearchResultLoaded(String query, int page, int pageSize, in Bundle extras,
            in List<Bundle> result);
}
+50 −8
Original line number Diff line number Diff line
@@ -63,12 +63,12 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow
    }

    @Override
    public void subscribe_impl(String parentId, Bundle options) {
    public void subscribe_impl(String parentId, Bundle extras) {
        // TODO(jaewan): Implement
    }

    @Override
    public void unsubscribe_impl(String parentId, Bundle options) {
    public void unsubscribe_impl(String parentId, Bundle extras) {
        // TODO(jaewan): Implement
    }

@@ -94,7 +94,7 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow
    }

    @Override
    public void getChildren_impl(String parentId, int page, int pageSize, Bundle options) {
    public void getChildren_impl(String parentId, int page, int pageSize, Bundle extras) {
        if (parentId == null) {
            throw new IllegalArgumentException("parentId shouldn't be null");
        }
@@ -105,7 +105,7 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow
        final IMediaSession2 binder = getSessionBinder();
        if (binder != null) {
            try {
                binder.getChildren(getControllerStub(), parentId, page, pageSize, options);
                binder.getChildren(getControllerStub(), parentId, page, pageSize, extras);
            } catch (RemoteException e) {
                // TODO(jaewan): Handle disconnect.
                if (DEBUG) {
@@ -118,8 +118,43 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow
    }

    @Override
    public void search_impl(String query, int page, int pageSize, Bundle extras) {
        // TODO(jaewan): Implement
    public void search_impl(String query, Bundle extras) {
        if (TextUtils.isEmpty(query)) {
            throw new IllegalArgumentException("query shouldn't be empty");
        }
        final IMediaSession2 binder = getSessionBinder();
        if (binder != null) {
            try {
                binder.search(getControllerStub(), query, extras);
            } catch (RemoteException e) {
                // TODO(jaewan): Handle disconnect.
                if (DEBUG) {
                    Log.w(TAG, "Cannot connect to the service or the session is gone", e);
                }
            }
        } else {
            Log.w(TAG, "Session isn't active", new IllegalStateException());
        }
    }

    @Override
    public void getSearchResult_impl(String query, int page, int pageSize, Bundle extras) {
        if (TextUtils.isEmpty(query)) {
            throw new IllegalArgumentException("query shouldn't be empty");
        }
        final IMediaSession2 binder = getSessionBinder();
        if (binder != null) {
            try {
                binder.getSearchResult(getControllerStub(), query, page, pageSize, extras);
            } catch (RemoteException e) {
                // TODO(jaewan): Handle disconnect.
                if (DEBUG) {
                    Log.w(TAG, "Cannot connect to the service or the session is gone", e);
                }
            }
        } else {
            Log.w(TAG, "Session isn't active", new IllegalStateException());
        }
    }

    public void onGetRootResult(
@@ -135,10 +170,17 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow
        });
    }

    public void onChildrenLoaded(String parentId, int page, int pageSize, Bundle options,
    public void onChildrenLoaded(String parentId, int page, int pageSize, Bundle extras,
            List<MediaItem2> result) {
        getCallbackExecutor().execute(() -> {
            mCallback.onChildrenLoaded(parentId, page, pageSize, extras, result);
        });
    }

    public void onSearchResultLoaded(String query, int page, int pageSize, Bundle extras,
            List<MediaItem2> result) {
        getCallbackExecutor().execute(() -> {
            mCallback.onChildrenLoaded(parentId, page, pageSize, options, result);
            mCallback.onSearchResultLoaded(query, page, pageSize, extras, result);
        });
    }
}
+9 −12
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public class MediaItem2Impl implements MediaItem2Provider {
            throw new IllegalArgumentException("dsd shouldn't be null");
        }
        if (metadata != null && !TextUtils.equals(mediaId, metadata.getMediaId())) {
            throw new IllegalArgumentException("metadata's id should be match with the mediaid");
            throw new IllegalArgumentException("metadata's id should be matched with the mediaid");
        }

        mContext = context;
@@ -71,7 +71,7 @@ public class MediaItem2Impl implements MediaItem2Provider {
            throw new IllegalArgumentException("mediaId shouldn't be null");
        }
        if (metadata != null && !TextUtils.equals(mediaId, metadata.getMediaId())) {
            throw new IllegalArgumentException("metadata's id should be match with the mediaid");
            throw new IllegalArgumentException("metadata's id should be matched with the mediaid");
        }
        mContext = context;
        mId = mediaId;
@@ -136,24 +136,21 @@ public class MediaItem2Impl implements MediaItem2Provider {
    }

    @Override
    public void setMetadata_impl(@NonNull MediaMetadata2 metadata) {
        if (metadata == null) {
            throw new IllegalArgumentException("metadata shouldn't be null");
        }
        if (TextUtils.isEmpty(metadata.getMediaId())) {
            throw new IllegalArgumentException("metadata must have a non-empty media id");
    public void setMetadata_impl(@Nullable MediaMetadata2 metadata) {
        if (metadata != null && !TextUtils.equals(mId, metadata.getMediaId())) {
            throw new IllegalArgumentException("metadata's id should be matched with the mediaId");
        }
        mMetadata = metadata;
    }

    @Override
    public MediaMetadata2 getMetadata_impl() {
    public @Nullable MediaMetadata2 getMetadata_impl() {
        return mMetadata;
    }

    @Override
    public @Nullable String getMediaId_impl() {
        return mMetadata.getMediaId();
    public @NonNull String getMediaId_impl() {
        return mId;
    }

    @Override
+27 −2
Original line number Diff line number Diff line
@@ -244,7 +244,7 @@ public class MediaSession2CallbackStub extends IMediaSession2Callback.Stub {
    }

    @Override
    public void onChildrenLoaded(String parentId, int page, int pageSize, Bundle options,
    public void onChildrenLoaded(String parentId, int page, int pageSize, Bundle extras,
            List<Bundle> itemBundleList) throws RuntimeException {
        final MediaBrowser2Impl browser;
        try {
@@ -265,6 +265,31 @@ public class MediaSession2CallbackStub extends IMediaSession2Callback.Stub {
                result.add(MediaItem2.fromBundle(browser.getContext(), bundle));
            }
        }
        browser.onChildrenLoaded(parentId, page, pageSize, options, result);
        browser.onChildrenLoaded(parentId, page, pageSize, extras, result);
    }

    @Override
    public void onSearchResultLoaded(String query, int page, int pageSize, Bundle extras,
            List<Bundle> itemBundleList) throws RuntimeException {
        final MediaBrowser2Impl browser;
        try {
            browser = getBrowser();
        } catch (IllegalStateException e) {
            Log.w(TAG, "Don't fail silently here. Highly likely a bug");
            return;
        }
        if (browser == null) {
            // TODO(jaewan): Revisit here. Could be a bug
            return;
        }

        List<MediaItem2> result = null;
        if (itemBundleList != null) {
            result = new ArrayList<>();
            for (Bundle bundle : itemBundleList) {
                result.add(MediaItem2.fromBundle(browser.getContext(), bundle));
            }
        }
        browser.onSearchResultLoaded(query, page, pageSize, extras, result);
    }
}
Loading