package androidx.media3.session;

import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.media3.common.Player;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.ImmutableIntArray;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;
import java.util.Objects;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public final class CommandButton {
    public static final int ICON_ALBUM = 57369;
    public static final int ICON_ARTIST = 57370;
    public static final int ICON_BLOCK = 57675;
    public static final int ICON_BOOKMARK_FILLED = 1042534;
    public static final int ICON_BOOKMARK_UNFILLED = 59494;
    public static final int ICON_CHECK_CIRCLE_FILLED = 1042540;
    public static final int ICON_CHECK_CIRCLE_UNFILLED = 59500;
    public static final int ICON_CLOSED_CAPTIONS = 57372;
    public static final int ICON_CLOSED_CAPTIONS_OFF = 61916;
    public static final int ICON_FAST_FORWARD = 57375;
    public static final int ICON_FEED = 57573;
    public static final int ICON_FLAG_FILLED = 1040723;
    public static final int ICON_FLAG_UNFILLED = 57683;
    public static final int ICON_HEART_FILLED = 1042557;
    public static final int ICON_HEART_UNFILLED = 59517;
    public static final int ICON_MINUS = 57691;
    public static final int ICON_MINUS_CIRCLE_FILLED = 1040712;
    public static final int ICON_MINUS_CIRCLE_UNFILLED = 1040713;
    public static final int ICON_NEXT = 57412;
    public static final int ICON_PAUSE = 57396;
    public static final int ICON_PLAY = 57399;
    public static final int ICON_PLAYBACK_SPEED = 57448;
    public static final int ICON_PLAYBACK_SPEED_0_5 = 62690;
    public static final int ICON_PLAYBACK_SPEED_0_8 = 1045730;
    public static final int ICON_PLAYBACK_SPEED_1_0 = 61389;
    public static final int ICON_PLAYBACK_SPEED_1_2 = 62689;
    public static final int ICON_PLAYBACK_SPEED_1_5 = 62688;
    public static final int ICON_PLAYBACK_SPEED_1_8 = 1045728;
    public static final int ICON_PLAYBACK_SPEED_2_0 = 62699;
    public static final int ICON_PLAYLIST_ADD = 57403;
    public static final int ICON_PLAYLIST_REMOVE = 60288;
    public static final int ICON_PLUS = 57669;
    public static final int ICON_PLUS_CIRCLE_FILLED = 1040711;
    public static final int ICON_PLUS_CIRCLE_UNFILLED = 57671;
    public static final int ICON_PREVIOUS = 57413;
    public static final int ICON_QUALITY = 58409;
    public static final int ICON_QUEUE_ADD = 57436;
    public static final int ICON_QUEUE_NEXT = 57446;
    public static final int ICON_QUEUE_REMOVE = 57447;
    public static final int ICON_RADIO = 58654;
    public static final int ICON_REPEAT_ALL = 57408;
    public static final int ICON_REPEAT_OFF = 1040448;
    public static final int ICON_REPEAT_ONE = 57409;
    public static final int ICON_REWIND = 57376;
    public static final int ICON_SETTINGS = 59576;
    public static final int ICON_SHARE = 59405;
    public static final int ICON_SHUFFLE_OFF = 1040452;
    public static final int ICON_SHUFFLE_ON = 57411;
    public static final int ICON_SHUFFLE_STAR = 1040451;
    public static final int ICON_SIGNAL = 61512;
    public static final int ICON_SKIP_BACK = 57410;
    public static final int ICON_SKIP_BACK_10 = 57433;
    public static final int ICON_SKIP_BACK_15 = 1040473;
    public static final int ICON_SKIP_BACK_30 = 57434;
    public static final int ICON_SKIP_BACK_5 = 57435;
    public static final int ICON_SKIP_FORWARD = 63220;
    public static final int ICON_SKIP_FORWARD_10 = 57430;
    public static final int ICON_SKIP_FORWARD_15 = 1040470;
    public static final int ICON_SKIP_FORWARD_30 = 57431;
    public static final int ICON_SKIP_FORWARD_5 = 57432;
    public static final int ICON_STAR_FILLED = 1042488;
    public static final int ICON_STAR_UNFILLED = 59448;
    public static final int ICON_STOP = 57415;
    public static final int ICON_SUBTITLES = 57416;
    public static final int ICON_SUBTITLES_OFF = 61298;
    public static final int ICON_SYNC = 58919;
    public static final int ICON_THUMB_DOWN_FILLED = 1042651;
    public static final int ICON_THUMB_DOWN_UNFILLED = 59611;
    public static final int ICON_THUMB_UP_FILLED = 1042652;
    public static final int ICON_THUMB_UP_UNFILLED = 59612;
    public static final int ICON_UNDEFINED = 0;
    public static final int ICON_VOLUME_DOWN = 57421;
    public static final int ICON_VOLUME_OFF = 57423;
    public static final int ICON_VOLUME_UP = 57424;

    @UnstableApi
    public static final int SLOT_BACK = 2;

    @UnstableApi
    public static final int SLOT_BACK_SECONDARY = 4;

    @UnstableApi
    public static final int SLOT_CENTRAL = 1;

    @UnstableApi
    public static final int SLOT_FORWARD = 3;

    @UnstableApi
    public static final int SLOT_FORWARD_SECONDARY = 5;

    @UnstableApi
    public static final int SLOT_OVERFLOW = 6;
    public final CharSequence displayName;
    public final Bundle extras;
    public final int icon;

    @DrawableRes
    public final int iconResId;

    @Nullable
    public final Uri iconUri;
    public final boolean isEnabled;
    public final int playerCommand;

    @Nullable
    public final SessionCommand sessionCommand;

    @UnstableApi
    public final ImmutableIntArray slots;
    private static final String FIELD_SESSION_COMMAND = Util.intToStringMaxRadix(0);
    private static final String FIELD_PLAYER_COMMAND = Util.intToStringMaxRadix(1);
    private static final String FIELD_ICON_RES_ID = Util.intToStringMaxRadix(2);
    private static final String FIELD_DISPLAY_NAME = Util.intToStringMaxRadix(3);
    private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(4);
    private static final String FIELD_ENABLED = Util.intToStringMaxRadix(5);
    private static final String FIELD_ICON_URI = Util.intToStringMaxRadix(6);
    private static final String FIELD_ICON = Util.intToStringMaxRadix(7);
    private static final String FIELD_SLOTS = Util.intToStringMaxRadix(8);

    public static final class Builder {
        private CharSequence displayName;
        private boolean enabled;
        private Bundle extras;
        private final int icon;

        @DrawableRes
        private int iconResId;

        @Nullable
        private Uri iconUri;
        private int playerCommand;

        @Nullable
        private SessionCommand sessionCommand;

        @Nullable
        private ImmutableIntArray slots;

        @Deprecated
        public Builder() {
            this(0);
        }

        public CommandButton build() {
            Assertions.checkState((this.sessionCommand == null) != (this.playerCommand == -1), "Exactly one of sessionCommand and playerCommand should be set");
            if (this.slots == null) {
                this.slots = ImmutableIntArray.of(CommandButton.getDefaultSlot(this.playerCommand, this.icon));
            }
            return new CommandButton(this.sessionCommand, this.playerCommand, this.icon, this.iconResId, this.iconUri, this.displayName, this.extras, this.enabled, this.slots);
        }

        @CanIgnoreReturnValue
        public Builder setCustomIconResId(@DrawableRes int i2) {
            this.iconResId = i2;
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setDisplayName(CharSequence charSequence) {
            this.displayName = charSequence;
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setEnabled(boolean z2) {
            this.enabled = z2;
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setExtras(Bundle bundle) {
            this.extras = new Bundle(bundle);
            return this;
        }

        @CanIgnoreReturnValue
        @Deprecated
        public Builder setIconResId(@DrawableRes int i2) {
            return setCustomIconResId(i2);
        }

        @CanIgnoreReturnValue
        public Builder setIconUri(Uri uri) {
            Assertions.checkArgument(Objects.equals(uri.getScheme(), "content") || Objects.equals(uri.getScheme(), "android.resource"), "Only content or resource Uris are supported for CommandButton");
            this.iconUri = uri;
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setPlayerCommand(int i2) {
            Assertions.checkArgument(this.sessionCommand == null, "sessionCommand is already set. Only one of sessionCommand and playerCommand should be set.");
            this.playerCommand = i2;
            return this;
        }

        @CanIgnoreReturnValue
        public Builder setSessionCommand(SessionCommand sessionCommand) {
            Assertions.checkNotNull(sessionCommand, "sessionCommand should not be null.");
            Assertions.checkArgument(this.playerCommand == -1, "playerCommands is already set. Only one of sessionCommand and playerCommand should be set.");
            this.sessionCommand = sessionCommand;
            return this;
        }

        @CanIgnoreReturnValue
        @UnstableApi
        public Builder setSlots(int... iArr) {
            Assertions.checkArgument(iArr.length != 0);
            this.slots = ImmutableIntArray.copyOf(iArr);
            return this;
        }

        public Builder(int i2) {
            this(i2, CommandButton.getIconResIdForIconConstant(i2));
        }

        Builder(int i2, @DrawableRes int i3) {
            this.icon = i2;
            this.iconResId = i3;
            this.displayName = HttpUrl.FRAGMENT_ENCODE_SET;
            this.extras = Bundle.EMPTY;
            this.playerCommand = -1;
            this.enabled = true;
        }
    }

    @UnstableApi
    public static final class DisplayConstraints {
        private final SparseArray<Player.Commands> allowedPlayerCommandsPerSlot;
        private final SparseArray<SessionCommands> allowedSessionCommandsPerSlot;
        private final SparseBooleanArray areCustomCommandsAllowedPerSlot;
        private final SparseIntArray maxButtonsPerSlot;

        public static final class Builder {
            private final SparseArray<Player.Commands> allowedPlayerCommandsPerSlot;
            private final SparseArray<SessionCommands> allowedSessionCommandsPerSlot;
            private final SparseBooleanArray areCustomCommandsAllowedPerSlot;
            private boolean buildCalled;
            private final SparseIntArray maxButtonsPerSlot;

            public Builder() {
                SparseIntArray sparseIntArray = new SparseIntArray();
                this.maxButtonsPerSlot = sparseIntArray;
                sparseIntArray.put(1, 1);
                sparseIntArray.put(2, 1);
                sparseIntArray.put(3, 1);
                sparseIntArray.put(6, Integer.MAX_VALUE);
                this.allowedPlayerCommandsPerSlot = new SparseArray<>();
                this.allowedSessionCommandsPerSlot = new SparseArray<>();
                this.areCustomCommandsAllowedPerSlot = new SparseBooleanArray();
            }

            public DisplayConstraints build() {
                Assertions.checkState(!this.buildCalled);
                this.buildCalled = true;
                return new DisplayConstraints(this);
            }

            @CanIgnoreReturnValue
            public Builder setAllowCustomCommandsForSlot(int i2, boolean z2) {
                this.areCustomCommandsAllowedPerSlot.put(i2, z2);
                return this;
            }

            @CanIgnoreReturnValue
            public Builder setAllowedPlayerCommandsForSlot(int i2, @Nullable Player.Commands commands) {
                this.allowedPlayerCommandsPerSlot.put(i2, commands);
                return this;
            }

            @CanIgnoreReturnValue
            public Builder setAllowedSessionCommandsForSlot(int i2, @Nullable SessionCommands sessionCommands) {
                this.allowedSessionCommandsPerSlot.put(i2, sessionCommands);
                return this;
            }

            @CanIgnoreReturnValue
            public Builder setMaxButtonsForSlot(int i2, int i3) {
                Assertions.checkArgument(i3 >= 0);
                this.maxButtonsPerSlot.put(i2, i3);
                return this;
            }
        }

        private static CommandButton createButton(int i2, int i3, Player.Commands commands) {
            return new Builder(i2).setPlayerCommand(i3).setEnabled(commands.contains(i3)).build();
        }

        private static CommandButton createOppositeButton(@Nullable CommandButton commandButton, int i2, Player player) {
            Player.Commands availableCommands = player.getAvailableCommands();
            int oppositePlayerCommand = getOppositePlayerCommand(commandButton, i2, availableCommands);
            int oppositeIcon = getOppositeIcon(commandButton);
            if (oppositeIcon == 0) {
                oppositeIcon = getIconForPlayerCommand(oppositePlayerCommand, player);
            }
            return createButton(oppositeIcon, oppositePlayerCommand, availableCommands);
        }

        private static int getFirstAvailableOrFirstCommand(Player.Commands commands, int... iArr) {
            for (int i2 : iArr) {
                if (commands.contains(i2)) {
                    return i2;
                }
            }
            return iArr[0];
        }

        private static int getIconForPlayerCommand(int i2, Player player) {
            switch (i2) {
                case 6:
                case 7:
                    return CommandButton.ICON_PREVIOUS;
                case 8:
                case 9:
                    return CommandButton.ICON_NEXT;
                case 10:
                default:
                    throw new UnsupportedOperationException();
                case 11:
                    long seekBackIncrement = player.getSeekBackIncrement();
                    return (seekBackIncrement < 2500 || seekBackIncrement >= 7500) ? (seekBackIncrement < 7500 || seekBackIncrement >= 12500) ? (seekBackIncrement < 12500 || seekBackIncrement >= 20000) ? (seekBackIncrement < 20000 || seekBackIncrement >= 40000) ? CommandButton.ICON_SKIP_BACK : CommandButton.ICON_SKIP_BACK_30 : CommandButton.ICON_SKIP_BACK_15 : CommandButton.ICON_SKIP_BACK_10 : CommandButton.ICON_SKIP_BACK_5;
                case 12:
                    long seekForwardIncrement = player.getSeekForwardIncrement();
                    return (seekForwardIncrement < 2500 || seekForwardIncrement >= 7500) ? (seekForwardIncrement < 7500 || seekForwardIncrement >= 12500) ? (seekForwardIncrement < 12500 || seekForwardIncrement >= 20000) ? (seekForwardIncrement < 20000 || seekForwardIncrement >= 40000) ? CommandButton.ICON_SKIP_FORWARD : CommandButton.ICON_SKIP_FORWARD_30 : CommandButton.ICON_SKIP_FORWARD_15 : CommandButton.ICON_SKIP_FORWARD_10 : CommandButton.ICON_SKIP_FORWARD_5;
            }
        }

        private static int getOppositeIcon(@Nullable CommandButton commandButton) {
            if (commandButton == null) {
                return 0;
            }
            switch (commandButton.icon) {
                case CommandButton.ICON_FAST_FORWARD /* 57375 */:
                    break;
                case CommandButton.ICON_REWIND /* 57376 */:
                    break;
                case CommandButton.ICON_SKIP_BACK /* 57410 */:
                    break;
                case CommandButton.ICON_NEXT /* 57412 */:
                    break;
                case CommandButton.ICON_PREVIOUS /* 57413 */:
                    break;
                case CommandButton.ICON_SKIP_FORWARD /* 63220 */:
                    break;
            }
            return 0;
        }

        private static int getOppositePlayerCommand(@Nullable CommandButton commandButton, int i2, Player.Commands commands) {
            if (commandButton != null) {
                switch (commandButton.playerCommand) {
                    case 6:
                        return 8;
                    case 7:
                        return 9;
                    case 8:
                        return 6;
                    case 9:
                        return 7;
                    case 11:
                        return 12;
                    case 12:
                        return 11;
                }
            }
            return i2 == 2 ? getFirstAvailableOrFirstCommand(commands, 7, 6, 11) : getFirstAvailableOrFirstCommand(commands, 9, 8, 12);
        }

        /* JADX WARN: Removed duplicated region for block: B:11:0x0020  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        private boolean reserveSlotForButton(androidx.media3.session.CommandButton r5, int r6, android.util.SparseIntArray r7) {
            /*
                r4 = this;
                int r0 = r7.get(r6)
                r1 = 0
                if (r0 != 0) goto L8
                return r1
            L8:
                int r0 = r5.playerCommand
                r2 = -1
                r3 = 1
                if (r0 == r2) goto L22
                android.util.SparseArray<androidx.media3.common.Player$Commands> r0 = r4.allowedPlayerCommandsPerSlot
                java.lang.Object r0 = r0.get(r6)
                androidx.media3.common.Player$Commands r0 = (androidx.media3.common.Player.Commands) r0
                if (r0 == 0) goto L20
                int r5 = r5.playerCommand
                boolean r5 = r0.contains(r5)
                if (r5 == 0) goto L48
            L20:
                r1 = r3
                goto L48
            L22:
                androidx.media3.session.SessionCommand r0 = r5.sessionCommand
                java.lang.Object r0 = androidx.media3.common.util.Assertions.checkNotNull(r0)
                androidx.media3.session.SessionCommand r0 = (androidx.media3.session.SessionCommand) r0
                int r0 = r0.commandCode
                if (r0 != 0) goto L35
                android.util.SparseBooleanArray r5 = r4.areCustomCommandsAllowedPerSlot
                boolean r1 = r5.get(r6, r3)
                goto L48
            L35:
                android.util.SparseArray<androidx.media3.session.SessionCommands> r0 = r4.allowedSessionCommandsPerSlot
                java.lang.Object r0 = r0.get(r6)
                androidx.media3.session.SessionCommands r0 = (androidx.media3.session.SessionCommands) r0
                if (r0 == 0) goto L20
                androidx.media3.session.SessionCommand r5 = r5.sessionCommand
                boolean r5 = r0.contains(r5)
                if (r5 == 0) goto L48
                goto L20
            L48:
                if (r1 == 0) goto L52
                int r5 = r7.get(r6)
                int r5 = r5 - r3
                r7.put(r6, r5)
            L52:
                return r1
            */
            throw new UnsupportedOperationException("Method not decompiled: androidx.media3.session.CommandButton.DisplayConstraints.reserveSlotForButton(androidx.media3.session.CommandButton, int, android.util.SparseIntArray):boolean");
        }

        public ImmutableList<CommandButton> resolve(List<CommandButton> list, Player player) {
            SparseIntArray sparseIntArrayClone = this.maxButtonsPerSlot.clone();
            ImmutableList.Builder builder = ImmutableList.builder();
            CommandButton commandButton = null;
            CommandButton commandButton2 = null;
            int i2 = 0;
            while (true) {
                if (i2 >= list.size()) {
                    break;
                }
                CommandButton commandButton3 = list.get(i2);
                int i3 = 0;
                while (true) {
                    if (i3 < commandButton3.slots.length()) {
                        int i4 = commandButton3.slots.get(i3);
                        if (reserveSlotForButton(commandButton3, i4, sparseIntArrayClone)) {
                            builder.add(commandButton3.copyWithSlots(ImmutableIntArray.of(i4)));
                            if (commandButton == null && i4 == 3) {
                                commandButton = commandButton3;
                            } else if (commandButton2 == null && i4 == 2) {
                                commandButton2 = commandButton3;
                            }
                        } else {
                            i3++;
                        }
                    }
                }
                i2++;
            }
            Player.Commands availableCommands = player.getAvailableCommands();
            if (this.maxButtonsPerSlot.get(1) == sparseIntArrayClone.get(1)) {
                CommandButton commandButtonCreateButton = createButton(Util.shouldShowPlayButton(player) ? CommandButton.ICON_PLAY : CommandButton.ICON_PAUSE, 1, availableCommands);
                if (reserveSlotForButton(commandButtonCreateButton, 1, sparseIntArrayClone)) {
                    builder.add(commandButtonCreateButton);
                }
            }
            boolean z2 = commandButton2 == null && this.maxButtonsPerSlot.get(2) > 0;
            boolean z3 = commandButton == null && this.maxButtonsPerSlot.get(3) > 0;
            if (z2 && z3) {
                int firstAvailableOrFirstCommand = getFirstAvailableOrFirstCommand(availableCommands, 7, 9, 6, 8, 11, 12);
                CommandButton commandButtonCreateButton2 = createButton(getIconForPlayerCommand(firstAvailableOrFirstCommand, player), firstAvailableOrFirstCommand, availableCommands);
                int i5 = commandButtonCreateButton2.slots.get(0);
                if (reserveSlotForButton(commandButtonCreateButton2, i5, sparseIntArrayClone)) {
                    builder.add(commandButtonCreateButton2);
                }
                int i6 = i5 != 2 ? 2 : 3;
                CommandButton commandButtonCreateOppositeButton = createOppositeButton(commandButtonCreateButton2, i6, player);
                if (reserveSlotForButton(commandButtonCreateOppositeButton, i6, sparseIntArrayClone)) {
                    builder.add(commandButtonCreateOppositeButton);
                }
            } else if (z2) {
                CommandButton commandButtonCreateOppositeButton2 = createOppositeButton(commandButton, 2, player);
                if (reserveSlotForButton(commandButtonCreateOppositeButton2, 2, sparseIntArrayClone)) {
                    builder.add(commandButtonCreateOppositeButton2);
                }
            } else if (z3) {
                CommandButton commandButtonCreateOppositeButton3 = createOppositeButton(commandButton2, 3, player);
                if (reserveSlotForButton(commandButtonCreateOppositeButton3, 3, sparseIntArrayClone)) {
                    builder.add(commandButtonCreateOppositeButton3);
                }
            }
            return builder.build();
        }

        private DisplayConstraints(Builder builder) {
            this.maxButtonsPerSlot = builder.maxButtonsPerSlot;
            this.allowedPlayerCommandsPerSlot = builder.allowedPlayerCommandsPerSlot;
            this.allowedSessionCommandsPerSlot = builder.allowedSessionCommandsPerSlot;
            this.areCustomCommandsAllowedPerSlot = builder.areCustomCommandsAllowedPerSlot;
        }
    }

    @Target({ElementType.TYPE_USE})
    @Documented
    @Retention(RetentionPolicy.SOURCE)
    public @interface Icon {
    }

    @Target({ElementType.TYPE_USE})
    @Documented
    @Retention(RetentionPolicy.SOURCE)
    @UnstableApi
    public @interface Slot {
    }

    static boolean containsButtonForSlot(List<CommandButton> list, int i2) {
        for (int i3 = 0; i3 < list.size(); i3++) {
            if (list.get(i3).slots.get(0) == i2) {
                return true;
            }
        }
        return false;
    }

    static ImmutableList<CommandButton> copyWithUnavailableButtonsDisabled(List<CommandButton> list, SessionCommands sessionCommands, Player.Commands commands) {
        ImmutableList.Builder builder = new ImmutableList.Builder();
        for (int i2 = 0; i2 < list.size(); i2++) {
            CommandButton commandButton = list.get(i2);
            if (isButtonCommandAvailable(commandButton, sessionCommands, commands)) {
                builder.add(commandButton);
            } else {
                builder.add(commandButton.copyWithIsEnabled(false));
            }
        }
        return builder.build();
    }

    @UnstableApi
    @Deprecated
    public static CommandButton fromBundle(Bundle bundle) {
        return fromBundle(bundle, 5);
    }

    static ImmutableList<CommandButton> getCustomLayoutFromMediaButtonPreferences(List<CommandButton> list, boolean z2, boolean z3) {
        SessionCommand sessionCommand;
        SessionCommand sessionCommand2;
        int i2;
        if (list.isEmpty()) {
            return ImmutableList.of();
        }
        int i3 = -1;
        int i4 = -1;
        for (int i5 = 0; i5 < list.size(); i5++) {
            CommandButton commandButton = list.get(i5);
            if (commandButton.isEnabled && (sessionCommand2 = commandButton.sessionCommand) != null && sessionCommand2.commandCode == 0) {
                int i6 = 0;
                while (true) {
                    if (i6 >= commandButton.slots.length() || (i2 = commandButton.slots.get(i6)) == 6) {
                        break;
                    }
                    if (z2 && i3 == -1 && i2 == 2) {
                        i3 = i5;
                        break;
                    }
                    if (z3 && i4 == -1 && i2 == 3) {
                        i4 = i5;
                        break;
                    }
                    i6++;
                }
            }
        }
        ImmutableList.Builder builder = ImmutableList.builder();
        if (i3 != -1) {
            builder.add(list.get(i3).copyWithSlots(ImmutableIntArray.of(2)));
        }
        if (i4 != -1) {
            builder.add(list.get(i4).copyWithSlots(ImmutableIntArray.of(3)));
        }
        for (int i7 = 0; i7 < list.size(); i7++) {
            CommandButton commandButton2 = list.get(i7);
            if (commandButton2.isEnabled && (sessionCommand = commandButton2.sessionCommand) != null && sessionCommand.commandCode == 0 && i7 != i3 && i7 != i4 && commandButton2.slots.contains(6)) {
                builder.add(commandButton2.copyWithSlots(ImmutableIntArray.of(6)));
            }
        }
        return builder.build();
    }

    @UnstableApi
    public static int getDefaultSlot(int i2, int i3) {
        if (i2 == 1 || i3 == 57399 || i3 == 57396) {
            return 1;
        }
        if (i2 == 11 || i2 == 7 || i2 == 6 || i3 == 57413 || i3 == 57376 || i3 == 57410 || i3 == 57435 || i3 == 57433 || i3 == 1040473 || i3 == 57434) {
            return 2;
        }
        return (i2 == 12 || i2 == 9 || i2 == 8 || i3 == 57412 || i3 == 57375 || i3 == 63220 || i3 == 57432 || i3 == 57430 || i3 == 1040470 || i3 == 57431) ? 3 : 6;
    }

    @DrawableRes
    @UnstableApi
    public static int getIconResIdForIconConstant(int i2) {
        switch (i2) {
            case ICON_ALBUM /* 57369 */:
                return R.drawable.media3_icon_album;
            case ICON_ARTIST /* 57370 */:
                return R.drawable.media3_icon_artist;
            case ICON_CLOSED_CAPTIONS /* 57372 */:
                return R.drawable.media3_icon_closed_captions;
            case ICON_FAST_FORWARD /* 57375 */:
                return R.drawable.media3_icon_fast_forward;
            case ICON_REWIND /* 57376 */:
                return R.drawable.media3_icon_rewind;
            case ICON_PAUSE /* 57396 */:
                return R.drawable.media3_icon_pause;
            case ICON_PLAY /* 57399 */:
                return R.drawable.media3_icon_play;
            case ICON_PLAYLIST_ADD /* 57403 */:
                return R.drawable.media3_icon_playlist_add;
            case ICON_REPEAT_ALL /* 57408 */:
                return R.drawable.media3_icon_repeat_all;
            case ICON_REPEAT_ONE /* 57409 */:
                return R.drawable.media3_icon_repeat_one;
            case ICON_SKIP_BACK /* 57410 */:
                return R.drawable.media3_icon_skip_back;
            case ICON_SHUFFLE_ON /* 57411 */:
                return R.drawable.media3_icon_shuffle_on;
            case ICON_NEXT /* 57412 */:
                return R.drawable.media3_icon_next;
            case ICON_PREVIOUS /* 57413 */:
                return R.drawable.media3_icon_previous;
            case ICON_STOP /* 57415 */:
                return R.drawable.media3_icon_stop;
            case ICON_SUBTITLES /* 57416 */:
                return R.drawable.media3_icon_subtitles;
            case ICON_VOLUME_DOWN /* 57421 */:
                return R.drawable.media3_icon_volume_down;
            case ICON_VOLUME_OFF /* 57423 */:
                return R.drawable.media3_icon_volume_off;
            case ICON_VOLUME_UP /* 57424 */:
                return R.drawable.media3_icon_volume_up;
            case ICON_SKIP_FORWARD_10 /* 57430 */:
                return R.drawable.media3_icon_skip_forward_10;
            case ICON_SKIP_FORWARD_30 /* 57431 */:
                return R.drawable.media3_icon_skip_forward_30;
            case ICON_SKIP_FORWARD_5 /* 57432 */:
                return R.drawable.media3_icon_skip_forward_5;
            case ICON_SKIP_BACK_10 /* 57433 */:
                return R.drawable.media3_icon_skip_back_10;
            case ICON_SKIP_BACK_30 /* 57434 */:
                return R.drawable.media3_icon_skip_back_30;
            case ICON_SKIP_BACK_5 /* 57435 */:
                return R.drawable.media3_icon_skip_back_5;
            case ICON_QUEUE_ADD /* 57436 */:
                return R.drawable.media3_icon_queue_add;
            case ICON_QUEUE_NEXT /* 57446 */:
                return R.drawable.media3_icon_queue_next;
            case ICON_QUEUE_REMOVE /* 57447 */:
                return R.drawable.media3_icon_queue_remove;
            case ICON_PLAYBACK_SPEED /* 57448 */:
                return R.drawable.media3_icon_playback_speed;
            case ICON_FEED /* 57573 */:
                return R.drawable.media3_icon_feed;
            case ICON_PLUS /* 57669 */:
                return R.drawable.media3_icon_plus;
            case ICON_PLUS_CIRCLE_UNFILLED /* 57671 */:
                return R.drawable.media3_icon_plus_circle_unfilled;
            case ICON_BLOCK /* 57675 */:
                return R.drawable.media3_icon_block;
            case ICON_FLAG_UNFILLED /* 57683 */:
                return R.drawable.media3_icon_flag_unfilled;
            case ICON_MINUS /* 57691 */:
                return R.drawable.media3_icon_minus;
            case ICON_QUALITY /* 58409 */:
                return R.drawable.media3_icon_quality;
            case ICON_RADIO /* 58654 */:
                return R.drawable.media3_icon_radio;
            case ICON_SYNC /* 58919 */:
                return R.drawable.media3_icon_sync;
            case ICON_SHARE /* 59405 */:
                return R.drawable.media3_icon_share;
            case ICON_STAR_UNFILLED /* 59448 */:
                return R.drawable.media3_icon_star_unfilled;
            case ICON_BOOKMARK_UNFILLED /* 59494 */:
                return R.drawable.media3_icon_bookmark_unfilled;
            case ICON_CHECK_CIRCLE_UNFILLED /* 59500 */:
                return R.drawable.media3_icon_check_circle_unfilled;
            case ICON_HEART_UNFILLED /* 59517 */:
                return R.drawable.media3_icon_heart_unfilled;
            case ICON_SETTINGS /* 59576 */:
                return R.drawable.media3_icon_settings;
            case ICON_THUMB_DOWN_UNFILLED /* 59611 */:
                return R.drawable.media3_icon_thumb_down_unfilled;
            case ICON_THUMB_UP_UNFILLED /* 59612 */:
                return R.drawable.media3_icon_thumb_up_unfilled;
            case ICON_PLAYLIST_REMOVE /* 60288 */:
                return R.drawable.media3_icon_playlist_remove;
            case ICON_SUBTITLES_OFF /* 61298 */:
                return R.drawable.media3_icon_subtitles_off;
            case ICON_PLAYBACK_SPEED_1_0 /* 61389 */:
                return R.drawable.media3_icon_playback_speed_1_0;
            case ICON_SIGNAL /* 61512 */:
                return R.drawable.media3_icon_signal;
            case ICON_CLOSED_CAPTIONS_OFF /* 61916 */:
                return R.drawable.media3_icon_closed_captions_off;
            case ICON_PLAYBACK_SPEED_1_5 /* 62688 */:
                return R.drawable.media3_icon_playback_speed_1_5;
            case ICON_PLAYBACK_SPEED_1_2 /* 62689 */:
                return R.drawable.media3_icon_playback_speed_1_2;
            case ICON_PLAYBACK_SPEED_0_5 /* 62690 */:
                return R.drawable.media3_icon_playback_speed_0_5;
            case ICON_PLAYBACK_SPEED_2_0 /* 62699 */:
                return R.drawable.media3_icon_playback_speed_2_0;
            case ICON_SKIP_FORWARD /* 63220 */:
                return R.drawable.media3_icon_skip_forward;
            case ICON_REPEAT_OFF /* 1040448 */:
                return R.drawable.media3_icon_repeat_off;
            case ICON_SHUFFLE_STAR /* 1040451 */:
                return R.drawable.media3_icon_shuffle_star;
            case ICON_SHUFFLE_OFF /* 1040452 */:
                return R.drawable.media3_icon_shuffle_off;
            case ICON_SKIP_FORWARD_15 /* 1040470 */:
                return R.drawable.media3_icon_skip_forward_15;
            case ICON_SKIP_BACK_15 /* 1040473 */:
                return R.drawable.media3_icon_skip_back_15;
            case ICON_PLUS_CIRCLE_FILLED /* 1040711 */:
                return R.drawable.media3_icon_plus_circle_filled;
            case ICON_MINUS_CIRCLE_FILLED /* 1040712 */:
                return R.drawable.media3_icon_minus_circle_filled;
            case ICON_MINUS_CIRCLE_UNFILLED /* 1040713 */:
                return R.drawable.media3_icon_minus_circle_unfilled;
            case ICON_FLAG_FILLED /* 1040723 */:
                return R.drawable.media3_icon_flag_filled;
            case ICON_STAR_FILLED /* 1042488 */:
                return R.drawable.media3_icon_star_filled;
            case ICON_BOOKMARK_FILLED /* 1042534 */:
                return R.drawable.media3_icon_bookmark_filled;
            case ICON_CHECK_CIRCLE_FILLED /* 1042540 */:
                return R.drawable.media3_icon_check_circle_filled;
            case ICON_HEART_FILLED /* 1042557 */:
                return R.drawable.media3_icon_heart_filled;
            case ICON_THUMB_DOWN_FILLED /* 1042651 */:
                return R.drawable.media3_icon_thumb_down_filled;
            case ICON_THUMB_UP_FILLED /* 1042652 */:
                return R.drawable.media3_icon_thumb_up_filled;
            case ICON_PLAYBACK_SPEED_1_8 /* 1045728 */:
                return R.drawable.media3_icon_playback_speed_1_8;
            case ICON_PLAYBACK_SPEED_0_8 /* 1045730 */:
                return R.drawable.media3_icon_playback_speed_0_8;
            default:
                return 0;
        }
    }

    static ImmutableList<CommandButton> getMediaButtonPreferencesFromCustomLayout(List<CommandButton> list, Player.Commands commands, Bundle bundle) {
        if (list.isEmpty()) {
            return ImmutableList.of();
        }
        boolean zContainsAny = commands.containsAny(new int[]{7, 6});
        boolean zContainsAny2 = commands.containsAny(new int[]{9, 8});
        boolean z2 = bundle.getBoolean("android.media.playback.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_PREVIOUS", false);
        boolean z3 = bundle.getBoolean("android.media.playback.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_NEXT", false);
        int i2 = (zContainsAny || z2) ? -1 : 0;
        int i3 = (zContainsAny2 || z3) ? -1 : i2 == 0 ? 1 : 0;
        ImmutableList.Builder builder = ImmutableList.builder();
        for (int i4 = 0; i4 < list.size(); i4++) {
            CommandButton commandButton = list.get(i4);
            if (i4 == i2) {
                if (i3 == -1) {
                    builder.add(commandButton.copyWithSlots(ImmutableIntArray.of(2, 6)));
                } else {
                    builder.add(commandButton.copyWithSlots(ImmutableIntArray.of(2, 3, 6)));
                }
            } else if (i4 == i3) {
                builder.add(commandButton.copyWithSlots(ImmutableIntArray.of(3, 6)));
            } else {
                builder.add(commandButton.copyWithSlots(ImmutableIntArray.of(6)));
            }
        }
        return builder.build();
    }

    static boolean isButtonCommandAvailable(CommandButton commandButton, SessionCommands sessionCommands, Player.Commands commands) {
        int i2;
        SessionCommand sessionCommand = commandButton.sessionCommand;
        return (sessionCommand != null && sessionCommands.contains(sessionCommand)) || ((i2 = commandButton.playerCommand) != -1 && commands.contains(i2));
    }

    @CheckReturnValue
    CommandButton copyWithIsEnabled(boolean z2) {
        return this.isEnabled == z2 ? this : new CommandButton(this.sessionCommand, this.playerCommand, this.icon, this.iconResId, this.iconUri, this.displayName, new Bundle(this.extras), z2, this.slots);
    }

    @CheckReturnValue
    CommandButton copyWithSlots(ImmutableIntArray immutableIntArray) {
        return this.slots.equals(immutableIntArray) ? this : new CommandButton(this.sessionCommand, this.playerCommand, this.icon, this.iconResId, this.iconUri, this.displayName, new Bundle(this.extras), this.isEnabled, immutableIntArray);
    }

    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof CommandButton)) {
            return false;
        }
        CommandButton commandButton = (CommandButton) obj;
        return Objects.equals(this.sessionCommand, commandButton.sessionCommand) && this.playerCommand == commandButton.playerCommand && this.icon == commandButton.icon && this.iconResId == commandButton.iconResId && Objects.equals(this.iconUri, commandButton.iconUri) && TextUtils.equals(this.displayName, commandButton.displayName) && this.isEnabled == commandButton.isEnabled && this.slots.equals(commandButton.slots);
    }

    public int hashCode() {
        return Objects.hash(this.sessionCommand, Integer.valueOf(this.playerCommand), Integer.valueOf(this.icon), Integer.valueOf(this.iconResId), this.displayName, Boolean.valueOf(this.isEnabled), this.iconUri, this.slots);
    }

    @UnstableApi
    public Bundle toBundle() {
        Bundle bundle = new Bundle();
        SessionCommand sessionCommand = this.sessionCommand;
        if (sessionCommand != null) {
            bundle.putBundle(FIELD_SESSION_COMMAND, sessionCommand.toBundle());
        }
        int i2 = this.playerCommand;
        if (i2 != -1) {
            bundle.putInt(FIELD_PLAYER_COMMAND, i2);
        }
        int i3 = this.icon;
        if (i3 != 0) {
            bundle.putInt(FIELD_ICON, i3);
        }
        int i4 = this.iconResId;
        if (i4 != 0) {
            bundle.putInt(FIELD_ICON_RES_ID, i4);
        }
        CharSequence charSequence = this.displayName;
        if (charSequence != HttpUrl.FRAGMENT_ENCODE_SET) {
            bundle.putCharSequence(FIELD_DISPLAY_NAME, charSequence);
        }
        if (!this.extras.isEmpty()) {
            bundle.putBundle(FIELD_EXTRAS, this.extras);
        }
        Uri uri = this.iconUri;
        if (uri != null) {
            bundle.putParcelable(FIELD_ICON_URI, uri);
        }
        boolean z2 = this.isEnabled;
        if (!z2) {
            bundle.putBoolean(FIELD_ENABLED, z2);
        }
        if (this.slots.length() != 1 || this.slots.get(0) != 6) {
            bundle.putIntArray(FIELD_SLOTS, this.slots.toArray());
        }
        return bundle;
    }

    private CommandButton(@Nullable SessionCommand sessionCommand, int i2, int i3, @DrawableRes int i4, @Nullable Uri uri, CharSequence charSequence, Bundle bundle, boolean z2, ImmutableIntArray immutableIntArray) {
        this.sessionCommand = sessionCommand;
        this.playerCommand = i2;
        this.icon = i3;
        this.iconResId = i4;
        this.iconUri = uri;
        this.displayName = charSequence;
        this.extras = new Bundle(bundle);
        this.isEnabled = z2;
        this.slots = immutableIntArray;
    }

    @UnstableApi
    public static CommandButton fromBundle(Bundle bundle, int i2) {
        Bundle bundle2 = bundle.getBundle(FIELD_SESSION_COMMAND);
        SessionCommand sessionCommandFromBundle = bundle2 == null ? null : SessionCommand.fromBundle(bundle2);
        int i3 = bundle.getInt(FIELD_PLAYER_COMMAND, -1);
        int i4 = bundle.getInt(FIELD_ICON_RES_ID, 0);
        CharSequence charSequence = bundle.getCharSequence(FIELD_DISPLAY_NAME, HttpUrl.FRAGMENT_ENCODE_SET);
        Bundle bundle3 = bundle.getBundle(FIELD_EXTRAS);
        boolean z2 = i2 < 3 || bundle.getBoolean(FIELD_ENABLED, true);
        Uri uri = (Uri) bundle.getParcelable(FIELD_ICON_URI);
        int i5 = bundle.getInt(FIELD_ICON, 0);
        int[] intArray = bundle.getIntArray(FIELD_SLOTS);
        Builder builder = new Builder(i5, i4);
        if (sessionCommandFromBundle != null) {
            builder.setSessionCommand(sessionCommandFromBundle);
        }
        if (i3 != -1) {
            builder.setPlayerCommand(i3);
        }
        if (uri != null && (Objects.equals(uri.getScheme(), "content") || Objects.equals(uri.getScheme(), "android.resource"))) {
            builder.setIconUri(uri);
        }
        Builder displayName = builder.setDisplayName(charSequence);
        if (bundle3 == null) {
            bundle3 = Bundle.EMPTY;
        }
        Builder enabled = displayName.setExtras(bundle3).setEnabled(z2);
        if (intArray == null) {
            intArray = new int[]{6};
        }
        return enabled.setSlots(intArray).build();
    }
}
