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

Commit 785d2f41 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

MediaBrowser2: Implement getItem/getChildren

Bug: 72786723
Test: Passed MediaBrowser2Test
Change-Id: I82d9116da16ee5bb6e956748add1bdac800666dd
parent a9eaa7cd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -63,4 +63,7 @@ oneway interface IMediaSession2 {
    // Get library service specific
    //////////////////////////////////////////////////////////////////////////////////////////////
    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);
}
+3 −0
Original line number Diff line number Diff line
@@ -48,4 +48,7 @@ oneway interface IMediaSession2Callback {
    // Browser sepcific
    //////////////////////////////////////////////////////////////////////////////////////////////
    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,
            in List<Bundle> result);
}
+52 −2
Original line number Diff line number Diff line
@@ -19,11 +19,13 @@ package com.android.media;
import android.content.Context;
import android.media.MediaBrowser2;
import android.media.MediaBrowser2.BrowserCallback;
import android.media.MediaItem2;
import android.media.MediaSession2.CommandButton;
import android.media.SessionToken2;
import android.media.update.MediaBrowser2Provider;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;

import java.util.List;
@@ -72,12 +74,47 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow

    @Override
    public void getItem_impl(String mediaId) {
        // TODO(jaewan): Implement
        if (mediaId == null) {
            throw new IllegalArgumentException("mediaId shouldn't be null");
        }

        final IMediaSession2 binder = getSessionBinder();
        if (binder != null) {
            try {
                binder.getItem(getControllerStub(), mediaId);
            } 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 getChildren_impl(String parentId, int page, int pageSize, Bundle options) {
        // TODO(jaewan): Implement
        if (parentId == null) {
            throw new IllegalArgumentException("parentId shouldn't be null");
        }
        if (page < 1 || pageSize < 1) {
            throw new IllegalArgumentException("Neither page nor pageSize should be less than 1");
        }

        final IMediaSession2 binder = getSessionBinder();
        if (binder != null) {
            try {
                binder.getChildren(getControllerStub(), parentId, page, pageSize, options);
            } 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
@@ -91,4 +128,17 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow
            mCallback.onGetRootResult(rootHints, rootMediaId, rootExtra);
        });
    }

    public void onItemLoaded(String mediaId, MediaItem2 item) {
        getCallbackExecutor().execute(() -> {
            mCallback.onItemLoaded(mediaId, item);
        });
    }

    public void onChildrenLoaded(String parentId, int page, int pageSize, Bundle options,
            List<MediaItem2> result) {
        getCallbackExecutor().execute(() -> {
            mCallback.onChildrenLoaded(parentId, page, pageSize, options, result);
        });
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -22,14 +22,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.AudioAttributes;
import android.media.MediaController2;
import android.media.MediaController2.ControllerCallback;
import android.media.MediaController2.PlaybackInfo;
import android.media.MediaItem2;
import android.media.MediaSession2;
import android.media.MediaSession2.Command;
import android.media.MediaSession2.CommandButton;
import android.media.MediaSession2.CommandGroup;
import android.media.MediaController2;
import android.media.MediaController2.ControllerCallback;
import android.media.MediaSession2.PlaylistParams;
import android.media.MediaSessionService2;
import android.media.PlaybackState2;
+43 −0
Original line number Diff line number Diff line
@@ -224,4 +224,47 @@ public class MediaSession2CallbackStub extends IMediaSession2Callback.Stub {
        }
        browser.onGetRootResult(rootHints, rootMediaId, rootExtra);
    }


    @Override
    public void onItemLoaded(String mediaId, Bundle itemBundle) 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;
        }
        browser.onItemLoaded(mediaId,
                MediaItem2Impl.fromBundle(browser.getContext(), itemBundle));
    }

    @Override
    public void onChildrenLoaded(String parentId, int page, int pageSize, Bundle options,
            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.onChildrenLoaded(parentId, page, pageSize, options, result);
    }
}
Loading