package androidx.media3.session;

import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
import android.text.TextUtils;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MediaMetadata;
import androidx.media3.common.util.Log;
import androidx.media3.session.MediaBrowser;
import androidx.media3.session.MediaController;
import androidx.media3.session.MediaLibraryService;
import androidx.media3.session.legacy.MediaBrowserCompat;
import defpackage.bj4;
import defpackage.fj4;
import defpackage.ks3;
import defpackage.om8;
import defpackage.rq6;
import defpackage.zb5;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
class MediaBrowserImplLegacy extends MediaControllerImplLegacy implements MediaBrowser.MediaBrowserImpl {
    private static final String TAG = "MB2ImplLegacy";
    private final HashMap<MediaLibraryService.LibraryParams, MediaBrowserCompat> browserCompats;
    private fj4<String, CommandButton> commandButtonsForMediaItems;
    private final MediaBrowser instance;
    private final HashMap<String, List<SubscribeCallback>> subscribeCallbacks;

    /* JADX INFO: renamed from: androidx.media3.session.MediaBrowserImplLegacy$2, reason: invalid class name */
    public class AnonymousClass2 extends MediaBrowserCompat.SearchCallback {
        public AnonymousClass2() {
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ void lambda$onError$1(String str, MediaBrowser.Listener listener) {
            listener.onSearchResultChanged(MediaBrowserImplLegacy.this.getInstance(), str, 0, null);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ void lambda$onSearchResult$0(String str, List list, MediaBrowser.Listener listener) {
            listener.onSearchResultChanged(MediaBrowserImplLegacy.this.getInstance(), str, list.size(), null);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SearchCallback
        public void onError(String str, @rq6 Bundle bundle) {
            MediaBrowserImplLegacy.this.getInstance().notifyBrowserListener(new j(this, str, 0));
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SearchCallback
        public void onSearchResult(String str, @rq6 Bundle bundle, List<MediaBrowserCompat.MediaItem> list) {
            MediaBrowserImplLegacy.this.getInstance().notifyBrowserListener(new i(this, str, list, 0));
        }
    }

    public class GetChildrenCallback extends MediaBrowserCompat.SubscriptionCallback {
        private final om8<LibraryResult<bj4<MediaItem>>> future;
        private final String parentId;

        public GetChildrenCallback(om8<LibraryResult<bj4<MediaItem>>> om8Var, String str) {
            this.future = om8Var;
            this.parentId = str;
        }

        private void onChildrenLoadedInternal(@rq6 String str, @rq6 List<MediaBrowserCompat.MediaItem> list) {
            if (TextUtils.isEmpty(str)) {
                Log.w(MediaBrowserImplLegacy.TAG, "GetChildrenCallback.onChildrenLoaded(): Ignoring empty parentId");
                return;
            }
            MediaBrowserCompat browserCompat = MediaBrowserImplLegacy.this.getBrowserCompat();
            if (browserCompat == null) {
                this.future.set(LibraryResult.ofError(-100));
                return;
            }
            browserCompat.unsubscribe(this.parentId, this);
            if (list == null) {
                this.future.set(LibraryResult.ofError(-1));
            } else {
                this.future.set(LibraryResult.ofItemList(LegacyConversions.convertBrowserItemListToMediaItemList(list), null));
            }
        }

        private void onErrorInternal() {
            this.future.set(LibraryResult.ofError(-1));
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onChildrenLoaded(@rq6 String str, @rq6 List<MediaBrowserCompat.MediaItem> list) {
            onChildrenLoadedInternal(str, list);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onError(@rq6 String str) {
            onErrorInternal();
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onChildrenLoaded(@rq6 String str, @rq6 List<MediaBrowserCompat.MediaItem> list, Bundle bundle) {
            onChildrenLoadedInternal(str, list);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onError(@rq6 String str, @rq6 Bundle bundle) {
            onErrorInternal();
        }
    }

    public class GetLibraryRootCallback extends MediaBrowserCompat.ConnectionCallback {
        private final MediaLibraryService.LibraryParams params;
        private final om8<LibraryResult<MediaItem>> result;

        public GetLibraryRootCallback(om8<LibraryResult<MediaItem>> om8Var, MediaLibraryService.LibraryParams libraryParams) {
            this.result = om8Var;
            this.params = libraryParams;
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.ConnectionCallback
        public void onConnected() {
            ArrayList parcelableArrayList;
            MediaBrowserCompat mediaBrowserCompat = (MediaBrowserCompat) MediaBrowserImplLegacy.this.browserCompats.get(this.params);
            if (mediaBrowserCompat == null) {
                this.result.set(LibraryResult.ofError(-1));
                return;
            }
            Bundle extras = mediaBrowserCompat.getExtras();
            if (extras != null && (parcelableArrayList = extras.getParcelableArrayList(androidx.media3.session.legacy.MediaConstants.BROWSER_SERVICE_EXTRAS_KEY_CUSTOM_BROWSER_ACTION_ROOT_LIST)) != null) {
                fj4.a aVar = null;
                for (int i = 0; i < parcelableArrayList.size(); i++) {
                    CommandButton commandButtonConvertCustomBrowseActionToCommandButton = LegacyConversions.convertCustomBrowseActionToCommandButton((Bundle) parcelableArrayList.get(i));
                    if (commandButtonConvertCustomBrowseActionToCommandButton != null) {
                        if (aVar == null) {
                            aVar = new fj4.a(4);
                            aVar.e(MediaBrowserImplLegacy.this.commandButtonsForMediaItems.entrySet());
                        }
                        SessionCommand sessionCommand = commandButtonConvertCustomBrowseActionToCommandButton.sessionCommand;
                        sessionCommand.getClass();
                        aVar.c(sessionCommand.customAction, commandButtonConvertCustomBrowseActionToCommandButton);
                    }
                }
                if (aVar != null) {
                    MediaBrowserImplLegacy.this.commandButtonsForMediaItems = aVar.b();
                }
            }
            this.result.set(LibraryResult.ofItem(MediaBrowserImplLegacy.this.createRootMediaItem(mediaBrowserCompat), LegacyConversions.convertToLibraryParams(MediaBrowserImplLegacy.this.context, extras)));
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.ConnectionCallback
        public void onConnectionFailed() {
            this.result.set(LibraryResult.ofError(-3));
            MediaBrowserImplLegacy.this.release();
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.ConnectionCallback
        public void onConnectionSuspended() {
            onConnectionFailed();
        }
    }

    public class SubscribeCallback extends MediaBrowserCompat.SubscriptionCallback {
        private final om8<LibraryResult<Void>> future;

        @rq6
        private List<MediaBrowserCompat.MediaItem> receivedChildren;
        private final Bundle subscriptionOptions;
        private final String subscriptionParentId;

        public SubscribeCallback(String str, Bundle bundle, om8<LibraryResult<Void>> om8Var) {
            this.subscriptionParentId = str;
            this.subscriptionOptions = bundle;
            this.future = om8Var;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ void lambda$onChildrenLoadedInternal$1(String str, List list, MediaLibraryService.LibraryParams libraryParams, MediaBrowser.Listener listener) {
            listener.onChildrenChanged(MediaBrowserImplLegacy.this.getInstance(), str, list.size(), libraryParams);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ void lambda$onErrorInternal$0(String str, Bundle bundle, MediaBrowser.Listener listener) {
            listener.onChildrenChanged(MediaBrowserImplLegacy.this.getInstance(), str, Integer.MAX_VALUE, new MediaLibraryService.LibraryParams.Builder().setExtras(bundle).build());
        }

        private void onChildrenLoadedInternal(String str, @rq6 List<MediaBrowserCompat.MediaItem> list) {
            if (TextUtils.isEmpty(str)) {
                Log.w(MediaBrowserImplLegacy.TAG, "SubscribeCallback.onChildrenLoaded(): Ignoring empty parentId");
                return;
            }
            MediaBrowserCompat browserCompat = MediaBrowserImplLegacy.this.getBrowserCompat();
            if (browserCompat == null) {
                return;
            }
            if (list == null) {
                onError(this.subscriptionParentId, this.subscriptionOptions);
                return;
            }
            MediaLibraryService.LibraryParams libraryParamsConvertToLibraryParams = LegacyConversions.convertToLibraryParams(MediaBrowserImplLegacy.this.context, browserCompat.getNotifyChildrenChangedOptions());
            this.receivedChildren = list;
            MediaBrowserImplLegacy.this.getInstance().notifyBrowserListener(new k(this, str, list, libraryParamsConvertToLibraryParams));
            this.future.set(LibraryResult.ofVoid());
        }

        private void onErrorInternal(String str, Bundle bundle) {
            if (this.future.isDone()) {
                MediaBrowserImplLegacy.this.getInstance().notifyBrowserListener(new i(this, str, bundle, 1));
            }
            this.future.set(LibraryResult.ofError(-1));
        }

        public boolean canServeGetChildrenRequest(String str, int i) {
            return this.subscriptionParentId.equals(str) && this.receivedChildren != null && i == this.subscriptionOptions.getInt(MediaBrowserCompat.EXTRA_PAGE, 0);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onChildrenLoaded(@rq6 String str, @rq6 List<MediaBrowserCompat.MediaItem> list) {
            onChildrenLoadedInternal(this.subscriptionParentId, list);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onError(@rq6 String str) {
            onError(this.subscriptionParentId, this.subscriptionOptions);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onChildrenLoaded(@rq6 String str, @rq6 List<MediaBrowserCompat.MediaItem> list, @rq6 Bundle bundle) {
            onChildrenLoadedInternal(this.subscriptionParentId, list);
        }

        @Override // androidx.media3.session.legacy.MediaBrowserCompat.SubscriptionCallback
        public void onError(@rq6 String str, @rq6 Bundle bundle) {
            onErrorInternal(this.subscriptionParentId, this.subscriptionOptions);
        }
    }

    public MediaBrowserImplLegacy(Context context, MediaBrowser mediaBrowser, SessionToken sessionToken, Bundle bundle, Looper looper, androidx.media3.common.util.BitmapLoader bitmapLoader, long j) {
        super(context, mediaBrowser, sessionToken, bundle, looper, bitmapLoader, j);
        this.browserCompats = new HashMap<>();
        this.subscribeCallbacks = new HashMap<>();
        this.instance = mediaBrowser;
        this.commandButtonsForMediaItems = fj4.l();
    }

    private static Bundle createOptionsForSubscription(@rq6 MediaLibraryService.LibraryParams libraryParams) {
        return libraryParams == null ? new Bundle() : new Bundle(libraryParams.extras);
    }

    private static Bundle createOptionsWithPagingInfo(@rq6 MediaLibraryService.LibraryParams libraryParams, int i, int i2) {
        Bundle bundleCreateOptionsForSubscription = createOptionsForSubscription(libraryParams);
        bundleCreateOptionsForSubscription.putInt(MediaBrowserCompat.EXTRA_PAGE, i);
        bundleCreateOptionsForSubscription.putInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, i2);
        return bundleCreateOptionsForSubscription;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public MediaItem createRootMediaItem(MediaBrowserCompat mediaBrowserCompat) {
        String root = mediaBrowserCompat.getRoot();
        return new MediaItem.Builder().setMediaId(root).setMediaMetadata(new MediaMetadata.Builder().setIsBrowsable(Boolean.TRUE).setMediaType(20).setIsPlayable(Boolean.FALSE).setExtras(mediaBrowserCompat.getExtras()).build()).build();
    }

    private void evictChildrenFromSubscription(String str) {
        List<SubscribeCallback> list = this.subscribeCallbacks.get(str);
        if (list == null) {
            return;
        }
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).receivedChildren != null) {
                list.get(i).receivedChildren = null;
                return;
            }
        }
    }

    private MediaBrowserCompat getBrowserCompat(MediaLibraryService.LibraryParams libraryParams) {
        return this.browserCompats.get(libraryParams);
    }

    @rq6
    private List<MediaBrowserCompat.MediaItem> getChildrenFromSubscription(String str, int i) {
        List<SubscribeCallback> list = this.subscribeCallbacks.get(str);
        if (list == null) {
            return null;
        }
        for (int i2 = 0; i2 < list.size(); i2++) {
            if (list.get(i2).canServeGetChildrenRequest(str, i)) {
                return list.get(i2).receivedChildren;
            }
        }
        return null;
    }

    @rq6
    private static Bundle getExtras(@rq6 MediaLibraryService.LibraryParams libraryParams) {
        if (libraryParams != null) {
            return libraryParams.extras;
        }
        return null;
    }

    @Override // androidx.media3.session.MediaControllerImplLegacy, androidx.media3.session.MediaController.MediaControllerImpl
    public SessionCommands getAvailableSessionCommands() {
        return getBrowserCompat() != null ? super.getAvailableSessionCommands().buildUpon().addAllLibraryCommands().build() : super.getAvailableSessionCommands();
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<bj4<MediaItem>>> getChildren(String str, int i, int i2, @rq6 MediaLibraryService.LibraryParams libraryParams) {
        if (!getInstance().isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_GET_CHILDREN)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (browserCompat == null) {
            return ks3.d(LibraryResult.ofError(-100));
        }
        Bundle bundleCreateOptionsWithPagingInfo = createOptionsWithPagingInfo(libraryParams, i, i2);
        om8 om8Var = new om8();
        List<MediaBrowserCompat.MediaItem> childrenFromSubscription = getChildrenFromSubscription(str, i);
        evictChildrenFromSubscription(str);
        if (childrenFromSubscription != null) {
            om8Var.set(LibraryResult.ofItemList(LegacyConversions.convertBrowserItemListToMediaItemList(childrenFromSubscription), new MediaLibraryService.LibraryParams.Builder().setExtras(bundleCreateOptionsWithPagingInfo).build()));
            return om8Var;
        }
        browserCompat.subscribe(str, bundleCreateOptionsWithPagingInfo, new GetChildrenCallback(om8Var, str));
        return om8Var;
    }

    @Override // androidx.media3.session.MediaControllerImplLegacy, androidx.media3.session.MediaController.MediaControllerImpl
    public bj4<CommandButton> getCommandButtonsForMediaItem(MediaItem mediaItem) {
        bj4<String> bj4Var = mediaItem.mediaMetadata.supportedCommands;
        bj4.a aVar = new bj4.a();
        for (int i = 0; i < bj4Var.size(); i++) {
            CommandButton commandButton = (CommandButton) this.commandButtonsForMediaItems.get(bj4Var.get(i));
            if (commandButton != null && commandButton.sessionCommand != null) {
                aVar.h(commandButton);
            }
        }
        return aVar.j();
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<MediaItem>> getItem(String str) {
        if (!getInstance().isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_GET_ITEM)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (browserCompat == null) {
            return ks3.d(LibraryResult.ofError(-100));
        }
        final om8 om8Var = new om8();
        browserCompat.getItem(str, new MediaBrowserCompat.ItemCallback() { // from class: androidx.media3.session.MediaBrowserImplLegacy.1
            @Override // androidx.media3.session.legacy.MediaBrowserCompat.ItemCallback
            public void onError(String str2) {
                om8Var.set(LibraryResult.ofError(-1));
            }

            @Override // androidx.media3.session.legacy.MediaBrowserCompat.ItemCallback
            public void onItemLoaded(MediaBrowserCompat.MediaItem mediaItem) {
                if (mediaItem != null) {
                    om8Var.set(LibraryResult.ofItem(LegacyConversions.convertToMediaItem(mediaItem), null));
                } else {
                    om8Var.set(LibraryResult.ofError(-3));
                }
            }
        });
        return om8Var;
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<MediaItem>> getLibraryRoot(@rq6 MediaLibraryService.LibraryParams libraryParams) {
        if (!getInstance().isSessionCommandAvailable(50000)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        om8 om8Var = new om8();
        MediaBrowserCompat browserCompat = getBrowserCompat(libraryParams);
        if (browserCompat != null) {
            om8Var.set(LibraryResult.ofItem(createRootMediaItem(browserCompat), null));
            return om8Var;
        }
        Bundle bundle = libraryParams == null ? new Bundle() : LegacyConversions.convertToRootHints(libraryParams);
        bundle.putInt(androidx.media3.session.legacy.MediaConstants.BROWSER_ROOT_HINTS_KEY_CUSTOM_BROWSER_ACTION_LIMIT, getInstance().getMaxCommandsForMediaItems());
        MediaBrowserCompat mediaBrowserCompat = new MediaBrowserCompat(getContext(), getConnectedToken().getComponentName(), new GetLibraryRootCallback(om8Var, libraryParams), bundle);
        this.browserCompats.put(libraryParams, mediaBrowserCompat);
        mediaBrowserCompat.connect();
        return om8Var;
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<bj4<MediaItem>>> getSearchResult(String str, int i, int i2, @rq6 MediaLibraryService.LibraryParams libraryParams) {
        if (!getInstance().isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (browserCompat == null) {
            return ks3.d(LibraryResult.ofError(-100));
        }
        final om8 om8Var = new om8();
        Bundle bundleCreateOptionsWithPagingInfo = createOptionsWithPagingInfo(libraryParams, i, i2);
        bundleCreateOptionsWithPagingInfo.putInt(MediaBrowserCompat.EXTRA_PAGE, i);
        bundleCreateOptionsWithPagingInfo.putInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, i2);
        browserCompat.search(str, bundleCreateOptionsWithPagingInfo, new MediaBrowserCompat.SearchCallback() { // from class: androidx.media3.session.MediaBrowserImplLegacy.3
            @Override // androidx.media3.session.legacy.MediaBrowserCompat.SearchCallback
            public void onError(String str2, @rq6 Bundle bundle) {
                om8Var.set(LibraryResult.ofError(-1));
            }

            @Override // androidx.media3.session.legacy.MediaBrowserCompat.SearchCallback
            public void onSearchResult(String str2, @rq6 Bundle bundle, List<MediaBrowserCompat.MediaItem> list) {
                om8Var.set(LibraryResult.ofItemList(LegacyConversions.convertBrowserItemListToMediaItemList(list), null));
            }
        });
        return om8Var;
    }

    @Override // androidx.media3.session.MediaControllerImplLegacy, androidx.media3.session.MediaController.MediaControllerImpl
    public void release() {
        Iterator<MediaBrowserCompat> it = this.browserCompats.values().iterator();
        while (it.hasNext()) {
            it.next().disconnect();
        }
        this.browserCompats.clear();
        super.release();
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<Void>> search(String str, @rq6 MediaLibraryService.LibraryParams libraryParams) {
        if (!getInstance().isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_SEARCH)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (browserCompat == null) {
            return ks3.d(LibraryResult.ofError(-100));
        }
        browserCompat.search(str, getExtras(libraryParams), new AnonymousClass2());
        return ks3.d(LibraryResult.ofVoid());
    }

    @Override // androidx.media3.session.MediaControllerImplLegacy, androidx.media3.session.MediaController.MediaControllerImpl
    public zb5<SessionResult> sendCustomCommand(SessionCommand sessionCommand, Bundle bundle) {
        return sendCustomCommand(sessionCommand, bundle, null);
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<Void>> subscribe(String str, @rq6 MediaLibraryService.LibraryParams libraryParams) {
        if (!getInstance().isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_SUBSCRIBE)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (browserCompat == null) {
            return ks3.d(LibraryResult.ofError(-100));
        }
        Bundle bundleCreateOptionsForSubscription = createOptionsForSubscription(libraryParams);
        om8 om8Var = new om8();
        SubscribeCallback subscribeCallback = new SubscribeCallback(str, bundleCreateOptionsForSubscription, om8Var);
        List<SubscribeCallback> arrayList = this.subscribeCallbacks.get(str);
        if (arrayList == null) {
            arrayList = new ArrayList<>();
            this.subscribeCallbacks.put(str, arrayList);
        }
        arrayList.add(subscribeCallback);
        browserCompat.subscribe(str, bundleCreateOptionsForSubscription, subscribeCallback);
        return om8Var;
    }

    @Override // androidx.media3.session.MediaBrowser.MediaBrowserImpl
    public zb5<LibraryResult<Void>> unsubscribe(String str) {
        if (!getInstance().isSessionCommandAvailable(SessionCommand.COMMAND_CODE_LIBRARY_UNSUBSCRIBE)) {
            return ks3.d(LibraryResult.ofError(-4));
        }
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (browserCompat == null) {
            return ks3.d(LibraryResult.ofError(-100));
        }
        List<SubscribeCallback> list = this.subscribeCallbacks.get(str);
        if (list == null) {
            return ks3.d(LibraryResult.ofError(-3));
        }
        for (int i = 0; i < list.size(); i++) {
            browserCompat.unsubscribe(str, list.get(i));
        }
        return ks3.d(LibraryResult.ofVoid());
    }

    @Override // androidx.media3.session.MediaControllerImplLegacy
    public MediaBrowser getInstance() {
        return this.instance;
    }

    @Override // androidx.media3.session.MediaControllerImplLegacy, androidx.media3.session.MediaController.MediaControllerImpl
    public zb5<SessionResult> sendCustomCommand(final SessionCommand sessionCommand, final Bundle bundle, @rq6 final MediaController.ProgressListener progressListener) {
        MediaBrowserCompat browserCompat = getBrowserCompat();
        if (getAvailableSessionCommands().contains(sessionCommand)) {
            return super.sendCustomCommand(sessionCommand, bundle);
        }
        if (browserCompat == null) {
            return ks3.d(new SessionResult(-4));
        }
        final om8 om8Var = new om8();
        browserCompat.sendCustomAction(sessionCommand.customAction, bundle, new MediaBrowserCompat.CustomActionCallback() { // from class: androidx.media3.session.MediaBrowserImplLegacy.4
            @Override // androidx.media3.session.legacy.MediaBrowserCompat.CustomActionCallback
            public void onError(String str, @rq6 Bundle bundle2, @rq6 Bundle bundle3) {
                Bundle bundle4 = new Bundle(bundle2);
                bundle4.putAll(bundle3);
                om8Var.set(new SessionResult(-1, bundle4));
            }

            @Override // androidx.media3.session.legacy.MediaBrowserCompat.CustomActionCallback
            public void onProgressUpdate(String str, Bundle bundle2, Bundle bundle3) {
                MediaController.ProgressListener progressListener2 = progressListener;
                if (progressListener2 != null) {
                    progressListener2.onProgress(MediaBrowserImplLegacy.this.getInstance(), sessionCommand, bundle, bundle3);
                }
            }

            @Override // androidx.media3.session.legacy.MediaBrowserCompat.CustomActionCallback
            public void onResult(String str, @rq6 Bundle bundle2, @rq6 Bundle bundle3) {
                Bundle bundle4 = new Bundle(bundle2);
                bundle4.putAll(bundle3);
                om8Var.set(new SessionResult(0, bundle4));
            }
        });
        return om8Var;
    }
}
