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

Commit 7bf914d2 authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Android (Google) Code Review
Browse files

Merge "MediaBrowser: Minor fixes"

parents f70fb29c 8e3fb586
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -455,8 +455,8 @@ public final class MediaBrowser {

    private void subscribeInternal(String parentId, Bundle options, SubscriptionCallback callback) {
        // Check arguments.
        if (parentId == null) {
            throw new IllegalArgumentException("parentId is null");
        if (TextUtils.isEmpty(parentId)) {
            throw new IllegalArgumentException("parentId is empty.");
        }
        if (callback == null) {
            throw new IllegalArgumentException("callback is null");
+21 −13
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.media;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
@@ -41,6 +42,8 @@ import android.util.Log;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -86,6 +89,11 @@ public abstract class MediaBrowserService extends Service {

    private static final int RESULT_FLAG_OPTION_NOT_HANDLED = 0x00000001;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag=true, value = { RESULT_FLAG_OPTION_NOT_HANDLED })
    private @interface ResultFlags { }

    private final ArrayMap<IBinder, ConnectionRecord> mConnections = new ArrayMap<>();
    private final Handler mHandler = new Handler();
    private ServiceBinder mBinder;
@@ -119,7 +127,7 @@ public abstract class MediaBrowserService extends Service {
        private Object mDebug;
        private boolean mDetachCalled;
        private boolean mSendResultCalled;
        private int mFlag;
        private int mFlags;

        Result(Object debug) {
            mDebug = debug;
@@ -133,7 +141,7 @@ public abstract class MediaBrowserService extends Service {
                throw new IllegalStateException("sendResult() called twice for: " + mDebug);
            }
            mSendResultCalled = true;
            onResultSent(result, mFlag);
            onResultSent(result, mFlags);
        }

        /**
@@ -156,15 +164,15 @@ public abstract class MediaBrowserService extends Service {
            return mDetachCalled || mSendResultCalled;
        }

        void setFlag(int flag) {
            mFlag = flag;
        void setFlags(@ResultFlags int flags) {
            mFlags = flags;
        }

        /**
         * Called when the result is sent, after assertions about not being called twice
         * have happened.
         */
        void onResultSent(T result, int flag) {
        void onResultSent(T result, @ResultFlags int flags) {
        }
    }

@@ -388,7 +396,7 @@ public abstract class MediaBrowserService extends Service {
        // To support backward compatibility, when the implementation of MediaBrowserService doesn't
        // override onLoadChildren() with options, onLoadChildren() without options will be used
        // instead, and the options will be applied in the implementation of result.onResultSent().
        result.setFlag(RESULT_FLAG_OPTION_NOT_HANDLED);
        result.setFlags(RESULT_FLAG_OPTION_NOT_HANDLED);
        onLoadChildren(parentId, result);
    }

@@ -574,7 +582,7 @@ public abstract class MediaBrowserService extends Service {
        final Result<List<MediaBrowser.MediaItem>> result
                = new Result<List<MediaBrowser.MediaItem>>(parentId) {
            @Override
            void onResultSent(List<MediaBrowser.MediaItem> list, int flag) {
            void onResultSent(List<MediaBrowser.MediaItem> list, @ResultFlags int flag) {
                if (mConnections.get(connection.callbacks.asBinder()) != connection) {
                    if (DBG) {
                        Log.d(TAG, "Not sending onLoadChildren result for connection that has"
@@ -639,7 +647,7 @@ public abstract class MediaBrowserService extends Service {
        final Result<MediaBrowser.MediaItem> result =
                new Result<MediaBrowser.MediaItem>(itemId) {
            @Override
            void onResultSent(MediaBrowser.MediaItem item, int flag) {
            void onResultSent(MediaBrowser.MediaItem item, @ResultFlags int flag) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(KEY_MEDIA_ITEM, item);
                receiver.send(0, bundle);