package androidx.media3.ui;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.media.session.MediaSession;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.media.session.MediaSessionCompat$Token;
import androidx.core.app.C;
import androidx.core.app.C1002i;
import androidx.core.app.C1007n;
import androidx.core.app.G;
import androidx.core.app.H;
import androidx.core.app.InterfaceC1001h;
import androidx.core.app.K;
import androidx.core.app.L;
import androidx.core.graphics.drawable.IconCompat;
import androidx.media3.common.Player;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.NotificationUtil;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import i2.C2263c;
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.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
@UnstableApi
public class PlayerNotificationManager {
    private static final String ACTION_DISMISS = "androidx.media3.ui.notification.dismiss";
    public static final String ACTION_FAST_FORWARD = "androidx.media3.ui.notification.ffwd";
    public static final String ACTION_NEXT = "androidx.media3.ui.notification.next";
    public static final String ACTION_PAUSE = "androidx.media3.ui.notification.pause";
    public static final String ACTION_PLAY = "androidx.media3.ui.notification.play";
    public static final String ACTION_PREVIOUS = "androidx.media3.ui.notification.prev";
    public static final String ACTION_REWIND = "androidx.media3.ui.notification.rewind";
    public static final String ACTION_STOP = "androidx.media3.ui.notification.stop";
    public static final String EXTRA_INSTANCE_ID = "INSTANCE_ID";
    private static final int MSG_START_OR_UPDATE_NOTIFICATION = 1;
    private static final int MSG_UPDATE_NOTIFICATION_BITMAP = 2;
    private static int instanceIdCounter;
    private int badgeIconType;
    private C1007n builder;
    private List<C1002i> builderActions;
    private final String channelId;
    private int color;
    private boolean colorized;
    private final Context context;
    private int currentNotificationTag;
    private final CustomActionReceiver customActionReceiver;
    private final Map<String, C1002i> customActions;
    private int defaults;
    private final PendingIntent dismissPendingIntent;
    private String groupKey;
    private final int instanceId;
    private final IntentFilter intentFilter;
    private boolean isNotificationStarted;
    private final Handler mainHandler;
    private final MediaDescriptionAdapter mediaDescriptionAdapter;
    private MediaSession.Token mediaSessionToken;
    private final NotificationBroadcastReceiver notificationBroadcastReceiver;
    private final int notificationId;
    private final NotificationListener notificationListener;
    private final L notificationManager;
    private final Map<String, C1002i> playbackActions;
    private Player player;
    private final Player.Listener playerListener;
    private int priority;
    private boolean showPlayButtonIfSuppressed;
    private int smallIconResourceId;
    private boolean useChronometer;
    private boolean useFastForwardAction;
    private boolean useFastForwardActionInCompactView;
    private boolean useNextAction;
    private boolean useNextActionInCompactView;
    private boolean usePlayPauseActions;
    private boolean usePreviousAction;
    private boolean usePreviousActionInCompactView;
    private boolean useRewindAction;
    private boolean useRewindActionInCompactView;
    private boolean useStopAction;
    private int visibility;

    public final class BitmapCallback {
        private final int notificationTag;

        public void onBitmap(Bitmap bitmap) {
            if (bitmap != null) {
                PlayerNotificationManager.this.postUpdateNotificationBitmap(bitmap, this.notificationTag);
            }
        }

        private BitmapCallback(int i6) {
            this.notificationTag = i6;
        }
    }

    public interface CustomActionReceiver {
        Map<String, C1002i> createCustomActions(Context context, int i6);

        List<String> getCustomActions(Player player);

        void onCustomAction(Player player, String str, Intent intent);
    }

    public interface MediaDescriptionAdapter {
        PendingIntent createCurrentContentIntent(Player player);

        CharSequence getCurrentContentText(Player player);

        CharSequence getCurrentContentTitle(Player player);

        Bitmap getCurrentLargeIcon(Player player, BitmapCallback bitmapCallback);

        default CharSequence getCurrentSubText(Player player) {
            return null;
        }
    }

    public static final class MediaStyle extends C {
        private final int[] actionsToShowInCompact;
        private final MediaSession.Token token;

        public MediaStyle(MediaSession.Token token, int[] iArr) {
            this.token = token;
            this.actionsToShowInCompact = iArr;
        }

        @Override // androidx.core.app.C
        public void apply(InterfaceC1001h interfaceC1001h) {
            Notification.MediaStyle mediaStyle = new Notification.MediaStyle();
            mediaStyle.setShowActionsInCompactView(this.actionsToShowInCompact);
            MediaSession.Token token = this.token;
            if (token != null) {
                mediaStyle.setMediaSession(token);
            }
            ((G) interfaceC1001h).f11193b.setStyle(mediaStyle);
        }
    }

    public class NotificationBroadcastReceiver extends BroadcastReceiver {
        private NotificationBroadcastReceiver() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            Player player = PlayerNotificationManager.this.player;
            if (player != null && PlayerNotificationManager.this.isNotificationStarted && intent.getIntExtra(PlayerNotificationManager.EXTRA_INSTANCE_ID, PlayerNotificationManager.this.instanceId) == PlayerNotificationManager.this.instanceId) {
                String action = intent.getAction();
                if (PlayerNotificationManager.ACTION_PLAY.equals(action)) {
                    Util.handlePlayButtonAction(player);
                    return;
                }
                if (PlayerNotificationManager.ACTION_PAUSE.equals(action)) {
                    Util.handlePauseButtonAction(player);
                    return;
                }
                if (PlayerNotificationManager.ACTION_PREVIOUS.equals(action)) {
                    if (player.isCommandAvailable(7)) {
                        player.seekToPrevious();
                        return;
                    }
                    return;
                }
                if (PlayerNotificationManager.ACTION_REWIND.equals(action)) {
                    if (player.isCommandAvailable(11)) {
                        player.seekBack();
                        return;
                    }
                    return;
                }
                if (PlayerNotificationManager.ACTION_FAST_FORWARD.equals(action)) {
                    if (player.isCommandAvailable(12)) {
                        player.seekForward();
                        return;
                    }
                    return;
                }
                if (PlayerNotificationManager.ACTION_NEXT.equals(action)) {
                    if (player.isCommandAvailable(9)) {
                        player.seekToNext();
                        return;
                    }
                    return;
                }
                if (PlayerNotificationManager.ACTION_STOP.equals(action)) {
                    if (player.isCommandAvailable(3)) {
                        player.stop();
                    }
                    if (player.isCommandAvailable(20)) {
                        player.clearMediaItems();
                        return;
                    }
                    return;
                }
                if (PlayerNotificationManager.ACTION_DISMISS.equals(action)) {
                    PlayerNotificationManager.this.stopNotification(true);
                } else {
                    if (action == null || PlayerNotificationManager.this.customActionReceiver == null || !PlayerNotificationManager.this.customActions.containsKey(action)) {
                        return;
                    }
                    PlayerNotificationManager.this.customActionReceiver.onCustomAction(player, action, intent);
                }
            }
        }
    }

    public interface NotificationListener {
        default void onNotificationCancelled(int i6, boolean z6) {
        }

        default void onNotificationPosted(int i6, Notification notification, boolean z6) {
        }
    }

    public class PlayerListener implements Player.Listener {
        private PlayerListener() {
        }

        @Override // androidx.media3.common.Player.Listener
        public void onEvents(Player player, Player.Events events) {
            if (events.containsAny(4, 5, 7, 0, 12, 11, 8, 9, 14)) {
                PlayerNotificationManager.this.postStartOrUpdateNotification();
            }
        }
    }

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

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

    public PlayerNotificationManager(Context context, String str, int i6, MediaDescriptionAdapter mediaDescriptionAdapter, NotificationListener notificationListener, CustomActionReceiver customActionReceiver, int i7, int i8, int i9, int i10, int i11, int i12, int i13, int i14, String str2) {
        Context applicationContext = context.getApplicationContext();
        this.context = applicationContext;
        this.channelId = str;
        this.notificationId = i6;
        this.mediaDescriptionAdapter = mediaDescriptionAdapter;
        this.notificationListener = notificationListener;
        this.customActionReceiver = customActionReceiver;
        this.smallIconResourceId = i7;
        this.groupKey = str2;
        int i15 = instanceIdCounter;
        instanceIdCounter = i15 + 1;
        this.instanceId = i15;
        this.mainHandler = Util.createHandler(Looper.getMainLooper(), new Handler.Callback() { // from class: androidx.media3.ui.i
            @Override // android.os.Handler.Callback
            public final boolean handleMessage(Message message) {
                return this.f12625a.handleMessage(message);
            }
        });
        this.notificationManager = new L(applicationContext);
        this.playerListener = new PlayerListener();
        this.notificationBroadcastReceiver = new NotificationBroadcastReceiver();
        this.intentFilter = new IntentFilter();
        this.usePreviousAction = true;
        this.useNextAction = true;
        this.usePlayPauseActions = true;
        this.showPlayButtonIfSuppressed = true;
        this.useRewindAction = true;
        this.useFastForwardAction = true;
        this.colorized = true;
        this.useChronometer = true;
        this.color = 0;
        this.defaults = 0;
        this.priority = -1;
        this.badgeIconType = 1;
        this.visibility = 1;
        Map<String, C1002i> mapCreatePlaybackActions = createPlaybackActions(applicationContext, i15, i8, i9, i10, i11, i12, i13, i14);
        this.playbackActions = mapCreatePlaybackActions;
        Iterator<String> it = mapCreatePlaybackActions.keySet().iterator();
        while (it.hasNext()) {
            this.intentFilter.addAction(it.next());
        }
        Map<String, C1002i> mapCreateCustomActions = customActionReceiver != null ? customActionReceiver.createCustomActions(applicationContext, this.instanceId) : Collections.EMPTY_MAP;
        this.customActions = mapCreateCustomActions;
        Iterator<String> it2 = mapCreateCustomActions.keySet().iterator();
        while (it2.hasNext()) {
            this.intentFilter.addAction(it2.next());
        }
        this.dismissPendingIntent = createBroadcastIntent(ACTION_DISMISS, applicationContext, this.instanceId);
        this.intentFilter.addAction(ACTION_DISMISS);
    }

    private static PendingIntent createBroadcastIntent(String str, Context context, int i6) {
        Intent intent = new Intent(str).setPackage(context.getPackageName());
        intent.putExtra(EXTRA_INSTANCE_ID, i6);
        return PendingIntent.getBroadcast(context, i6, intent, Util.SDK_INT >= 23 ? 201326592 : androidx.media3.common.C.BUFFER_FLAG_FIRST_SAMPLE);
    }

    private static Map<String, C1002i> createPlaybackActions(Context context, int i6, int i7, int i8, int i9, int i10, int i11, int i12, int i13) {
        HashMap map = new HashMap();
        map.put(ACTION_PLAY, new C1002i(i7, context.getString(R.string.exo_controls_play_description), createBroadcastIntent(ACTION_PLAY, context, i6)));
        map.put(ACTION_PAUSE, new C1002i(i8, context.getString(R.string.exo_controls_pause_description), createBroadcastIntent(ACTION_PAUSE, context, i6)));
        map.put(ACTION_STOP, new C1002i(i9, context.getString(R.string.exo_controls_stop_description), createBroadcastIntent(ACTION_STOP, context, i6)));
        map.put(ACTION_REWIND, new C1002i(i10, context.getString(R.string.exo_controls_rewind_description), createBroadcastIntent(ACTION_REWIND, context, i6)));
        map.put(ACTION_FAST_FORWARD, new C1002i(i11, context.getString(R.string.exo_controls_fastforward_description), createBroadcastIntent(ACTION_FAST_FORWARD, context, i6)));
        map.put(ACTION_PREVIOUS, new C1002i(i12, context.getString(R.string.exo_controls_previous_description), createBroadcastIntent(ACTION_PREVIOUS, context, i6)));
        map.put(ACTION_NEXT, new C1002i(i13, context.getString(R.string.exo_controls_next_description), createBroadcastIntent(ACTION_NEXT, context, i6)));
        return map;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean handleMessage(Message message) {
        int i6 = message.what;
        if (i6 == 1) {
            Player player = this.player;
            if (player != null) {
                startOrUpdateNotification(player, null);
            }
        } else {
            if (i6 != 2) {
                return false;
            }
            Player player2 = this.player;
            if (player2 != null && this.isNotificationStarted && this.currentNotificationTag == message.arg1) {
                startOrUpdateNotification(player2, (Bitmap) message.obj);
            }
        }
        return true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void postStartOrUpdateNotification() {
        if (this.mainHandler.hasMessages(1)) {
            return;
        }
        this.mainHandler.sendEmptyMessage(1);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void postUpdateNotificationBitmap(Bitmap bitmap, int i6) {
        this.mainHandler.obtainMessage(2, i6, -1, bitmap).sendToTarget();
    }

    private static void setLargeIcon(C1007n c1007n, Bitmap bitmap) {
        IconCompat iconCompat;
        if (bitmap == null) {
            iconCompat = null;
        } else {
            if (Build.VERSION.SDK_INT >= 27) {
                c1007n.getClass();
            } else {
                Resources resources = c1007n.f11249a.getResources();
                int dimensionPixelSize = resources.getDimensionPixelSize(com.debridstream.tv.R.dimen.compat_notification_large_icon_max_width);
                int dimensionPixelSize2 = resources.getDimensionPixelSize(com.debridstream.tv.R.dimen.compat_notification_large_icon_max_height);
                if (bitmap.getWidth() > dimensionPixelSize || bitmap.getHeight() > dimensionPixelSize2) {
                    double dMin = Math.min(((double) dimensionPixelSize) / ((double) Math.max(1, bitmap.getWidth())), ((double) dimensionPixelSize2) / ((double) Math.max(1, bitmap.getHeight())));
                    bitmap = Bitmap.createScaledBitmap(bitmap, (int) Math.ceil(((double) bitmap.getWidth()) * dMin), (int) Math.ceil(((double) bitmap.getHeight()) * dMin), true);
                }
            }
            PorterDuff.Mode mode = IconCompat.f11290k;
            bitmap.getClass();
            IconCompat iconCompat2 = new IconCompat(1);
            iconCompat2.f11292b = bitmap;
            iconCompat = iconCompat2;
        }
        c1007n.f11256h = iconCompat;
    }

    private void startOrUpdateNotification(Player player, Bitmap bitmap) {
        boolean ongoing = getOngoing(player);
        C1007n c1007nCreateNotification = createNotification(player, this.builder, ongoing, bitmap);
        this.builder = c1007nCreateNotification;
        if (c1007nCreateNotification == null) {
            stopNotification(false);
            return;
        }
        Notification notificationA = c1007nCreateNotification.a();
        L l = this.notificationManager;
        int i6 = this.notificationId;
        l.getClass();
        Bundle bundle = notificationA.extras;
        NotificationManager notificationManager = l.f11216b;
        if (bundle == null || !bundle.getBoolean("android.support.useSideChannel")) {
            notificationManager.notify(null, i6, notificationA);
        } else {
            H h5 = new H(l.f11215a.getPackageName(), i6, notificationA);
            synchronized (L.f11213f) {
                try {
                    if (L.f11214g == null) {
                        L.f11214g = new K(l.f11215a.getApplicationContext());
                    }
                    L.f11214g.f11207b.obtainMessage(0, h5).sendToTarget();
                } catch (Throwable th) {
                    throw th;
                }
            }
            notificationManager.cancel(null, i6);
        }
        if (!this.isNotificationStarted) {
            Util.registerReceiverNotExported(this.context, this.notificationBroadcastReceiver, this.intentFilter);
        }
        NotificationListener notificationListener = this.notificationListener;
        if (notificationListener != null) {
            notificationListener.onNotificationPosted(this.notificationId, notificationA, ongoing || !this.isNotificationStarted);
        }
        this.isNotificationStarted = true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void stopNotification(boolean z6) {
        if (this.isNotificationStarted) {
            this.isNotificationStarted = false;
            this.mainHandler.removeMessages(1);
            L l = this.notificationManager;
            l.f11216b.cancel(null, this.notificationId);
            this.context.unregisterReceiver(this.notificationBroadcastReceiver);
            NotificationListener notificationListener = this.notificationListener;
            if (notificationListener != null) {
                notificationListener.onNotificationCancelled(this.notificationId, z6);
            }
        }
    }

    public C1007n createNotification(Player player, C1007n c1007n, boolean z6, Bitmap bitmap) {
        if (player.getPlaybackState() == 1 && player.isCommandAvailable(17) && player.getCurrentTimeline().isEmpty()) {
            this.builderActions = null;
            return null;
        }
        List<String> actions = getActions(player);
        ArrayList arrayList = new ArrayList(actions.size());
        for (int i6 = 0; i6 < actions.size(); i6++) {
            String str = actions.get(i6);
            C1002i c1002i = this.playbackActions.containsKey(str) ? this.playbackActions.get(str) : this.customActions.get(str);
            if (c1002i != null) {
                arrayList.add(c1002i);
            }
        }
        if (c1007n == null || !arrayList.equals(this.builderActions)) {
            c1007n = new C1007n(this.context, this.channelId);
            this.builderActions = arrayList;
            for (int i7 = 0; i7 < arrayList.size(); i7++) {
                C1002i c1002i2 = (C1002i) arrayList.get(i7);
                if (c1002i2 != null) {
                    c1007n.f11250b.add(c1002i2);
                }
            }
        }
        int[] actionIndicesForCompactView = getActionIndicesForCompactView(actions, player);
        int i8 = Util.SDK_INT;
        if (i8 >= 21) {
            c1007n.d(new MediaStyle(this.mediaSessionToken, actionIndicesForCompactView));
        } else {
            C2263c c2263c = new C2263c();
            c2263c.f18835a = actionIndicesForCompactView;
            c1007n.d(c2263c);
        }
        PendingIntent pendingIntent = this.dismissPendingIntent;
        Notification notification = c1007n.f11247B;
        notification.deleteIntent = pendingIntent;
        c1007n.f11272y = this.badgeIconType;
        c1007n.c(2, z6);
        c1007n.f11269v = this.color;
        c1007n.f11266s = this.colorized;
        c1007n.f11267t = true;
        notification.icon = this.smallIconResourceId;
        c1007n.f11270w = this.visibility;
        c1007n.f11257i = this.priority;
        int i9 = this.defaults;
        notification.defaults = i9;
        if ((i9 & 4) != 0) {
            notification.flags |= 1;
        }
        if (i8 >= 21 && this.useChronometer && player.isCommandAvailable(16) && player.isPlaying() && !player.isPlayingAd() && !player.isCurrentMediaItemDynamic() && player.getPlaybackParameters().speed == 1.0f) {
            notification.when = System.currentTimeMillis() - player.getContentPosition();
            c1007n.f11258j = true;
            c1007n.f11259k = true;
        } else {
            c1007n.f11258j = false;
            c1007n.f11259k = false;
        }
        c1007n.f11253e = C1007n.b(this.mediaDescriptionAdapter.getCurrentContentTitle(player));
        c1007n.f11254f = C1007n.b(this.mediaDescriptionAdapter.getCurrentContentText(player));
        c1007n.f11260m = C1007n.b(this.mediaDescriptionAdapter.getCurrentSubText(player));
        if (bitmap == null) {
            MediaDescriptionAdapter mediaDescriptionAdapter = this.mediaDescriptionAdapter;
            int i10 = this.currentNotificationTag + 1;
            this.currentNotificationTag = i10;
            bitmap = mediaDescriptionAdapter.getCurrentLargeIcon(player, new BitmapCallback(i10));
        }
        setLargeIcon(c1007n, bitmap);
        c1007n.f11255g = this.mediaDescriptionAdapter.createCurrentContentIntent(player);
        String str2 = this.groupKey;
        if (str2 != null) {
            c1007n.f11264q = str2;
        }
        c1007n.c(8, true);
        return c1007n;
    }

    /* JADX WARN: Removed duplicated region for block: B:28:0x005f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public int[] getActionIndicesForCompactView(List<String> list, Player player) {
        int i6;
        int iIndexOf = list.indexOf(ACTION_PAUSE);
        int iIndexOf2 = list.indexOf(ACTION_PLAY);
        int iIndexOf3 = this.usePreviousActionInCompactView ? list.indexOf(ACTION_PREVIOUS) : this.useRewindActionInCompactView ? list.indexOf(ACTION_REWIND) : -1;
        int iIndexOf4 = this.useNextActionInCompactView ? list.indexOf(ACTION_NEXT) : this.useFastForwardActionInCompactView ? list.indexOf(ACTION_FAST_FORWARD) : -1;
        int[] iArr = new int[3];
        int i7 = 0;
        if (iIndexOf3 != -1) {
            iArr[0] = iIndexOf3;
            i7 = 1;
        }
        boolean zShouldShowPlayButton = Util.shouldShowPlayButton(player, this.showPlayButtonIfSuppressed);
        if (iIndexOf == -1 || zShouldShowPlayButton) {
            if (iIndexOf2 != -1 && zShouldShowPlayButton) {
                i6 = i7 + 1;
                iArr[i7] = iIndexOf2;
            }
            if (iIndexOf4 != -1) {
                iArr[i7] = iIndexOf4;
                i7++;
            }
            return Arrays.copyOf(iArr, i7);
        }
        i6 = i7 + 1;
        iArr[i7] = iIndexOf;
        i7 = i6;
        if (iIndexOf4 != -1) {
        }
        return Arrays.copyOf(iArr, i7);
    }

    public List<String> getActions(Player player) {
        boolean zIsCommandAvailable = player.isCommandAvailable(7);
        boolean zIsCommandAvailable2 = player.isCommandAvailable(11);
        boolean zIsCommandAvailable3 = player.isCommandAvailable(12);
        boolean zIsCommandAvailable4 = player.isCommandAvailable(9);
        ArrayList arrayList = new ArrayList();
        if (this.usePreviousAction && zIsCommandAvailable) {
            arrayList.add(ACTION_PREVIOUS);
        }
        if (this.useRewindAction && zIsCommandAvailable2) {
            arrayList.add(ACTION_REWIND);
        }
        if (this.usePlayPauseActions) {
            if (Util.shouldShowPlayButton(player, this.showPlayButtonIfSuppressed)) {
                arrayList.add(ACTION_PLAY);
            } else {
                arrayList.add(ACTION_PAUSE);
            }
        }
        if (this.useFastForwardAction && zIsCommandAvailable3) {
            arrayList.add(ACTION_FAST_FORWARD);
        }
        if (this.useNextAction && zIsCommandAvailable4) {
            arrayList.add(ACTION_NEXT);
        }
        CustomActionReceiver customActionReceiver = this.customActionReceiver;
        if (customActionReceiver != null) {
            arrayList.addAll(customActionReceiver.getCustomActions(player));
        }
        if (this.useStopAction) {
            arrayList.add(ACTION_STOP);
        }
        return arrayList;
    }

    public boolean getOngoing(Player player) {
        int playbackState = player.getPlaybackState();
        return (playbackState == 2 || playbackState == 3) && player.getPlayWhenReady();
    }

    public final void invalidate() {
        if (this.isNotificationStarted) {
            postStartOrUpdateNotification();
        }
    }

    public final void setBadgeIconType(int i6) {
        if (this.badgeIconType == i6) {
            return;
        }
        if (i6 != 0 && i6 != 1 && i6 != 2) {
            throw new IllegalArgumentException();
        }
        this.badgeIconType = i6;
        invalidate();
    }

    public final void setColor(int i6) {
        if (this.color != i6) {
            this.color = i6;
            invalidate();
        }
    }

    public final void setColorized(boolean z6) {
        if (this.colorized != z6) {
            this.colorized = z6;
            invalidate();
        }
    }

    public final void setDefaults(int i6) {
        if (this.defaults != i6) {
            this.defaults = i6;
            invalidate();
        }
    }

    @Deprecated
    public final void setMediaSessionToken(MediaSessionCompat$Token mediaSessionCompat$Token) {
        if (Util.SDK_INT >= 21) {
            setMediaSessionToken((MediaSession.Token) mediaSessionCompat$Token.f10877b);
        }
    }

    public final void setPlayer(Player player) {
        boolean z6 = true;
        Assertions.checkState(Looper.myLooper() == Looper.getMainLooper());
        if (player != null && player.getApplicationLooper() != Looper.getMainLooper()) {
            z6 = false;
        }
        Assertions.checkArgument(z6);
        Player player2 = this.player;
        if (player2 == player) {
            return;
        }
        if (player2 != null) {
            player2.removeListener(this.playerListener);
            if (player == null) {
                stopNotification(false);
            }
        }
        this.player = player;
        if (player != null) {
            player.addListener(this.playerListener);
            postStartOrUpdateNotification();
        }
    }

    public final void setPriority(int i6) {
        if (this.priority == i6) {
            return;
        }
        if (i6 != -2 && i6 != -1 && i6 != 0 && i6 != 1 && i6 != 2) {
            throw new IllegalArgumentException();
        }
        this.priority = i6;
        invalidate();
    }

    public void setShowPlayButtonIfPlaybackIsSuppressed(boolean z6) {
        if (this.showPlayButtonIfSuppressed != z6) {
            this.showPlayButtonIfSuppressed = z6;
            invalidate();
        }
    }

    public final void setSmallIcon(int i6) {
        if (this.smallIconResourceId != i6) {
            this.smallIconResourceId = i6;
            invalidate();
        }
    }

    public final void setUseChronometer(boolean z6) {
        if (this.useChronometer != z6) {
            this.useChronometer = z6;
            invalidate();
        }
    }

    public final void setUseFastForwardAction(boolean z6) {
        if (this.useFastForwardAction != z6) {
            this.useFastForwardAction = z6;
            invalidate();
        }
    }

    public final void setUseFastForwardActionInCompactView(boolean z6) {
        if (this.useFastForwardActionInCompactView != z6) {
            this.useFastForwardActionInCompactView = z6;
            if (z6) {
                this.useNextActionInCompactView = false;
            }
            invalidate();
        }
    }

    public final void setUseNextAction(boolean z6) {
        if (this.useNextAction != z6) {
            this.useNextAction = z6;
            invalidate();
        }
    }

    public final void setUseNextActionInCompactView(boolean z6) {
        if (this.useNextActionInCompactView != z6) {
            this.useNextActionInCompactView = z6;
            if (z6) {
                this.useFastForwardActionInCompactView = false;
            }
            invalidate();
        }
    }

    public final void setUsePlayPauseActions(boolean z6) {
        if (this.usePlayPauseActions != z6) {
            this.usePlayPauseActions = z6;
            invalidate();
        }
    }

    public final void setUsePreviousAction(boolean z6) {
        if (this.usePreviousAction != z6) {
            this.usePreviousAction = z6;
            invalidate();
        }
    }

    public final void setUsePreviousActionInCompactView(boolean z6) {
        if (this.usePreviousActionInCompactView != z6) {
            this.usePreviousActionInCompactView = z6;
            if (z6) {
                this.useRewindActionInCompactView = false;
            }
            invalidate();
        }
    }

    public final void setUseRewindAction(boolean z6) {
        if (this.useRewindAction != z6) {
            this.useRewindAction = z6;
            invalidate();
        }
    }

    public final void setUseRewindActionInCompactView(boolean z6) {
        if (this.useRewindActionInCompactView != z6) {
            this.useRewindActionInCompactView = z6;
            if (z6) {
                this.usePreviousActionInCompactView = false;
            }
            invalidate();
        }
    }

    public final void setUseStopAction(boolean z6) {
        if (this.useStopAction == z6) {
            return;
        }
        this.useStopAction = z6;
        invalidate();
    }

    public final void setVisibility(int i6) {
        if (this.visibility == i6) {
            return;
        }
        if (i6 != -1 && i6 != 0 && i6 != 1) {
            throw new IllegalStateException();
        }
        this.visibility = i6;
        invalidate();
    }

    public static class Builder {
        protected int channelDescriptionResourceId;
        protected final String channelId;
        protected int channelImportance;
        protected int channelNameResourceId;
        protected final Context context;
        protected CustomActionReceiver customActionReceiver;
        protected int fastForwardActionIconResourceId;
        protected String groupKey;
        protected MediaDescriptionAdapter mediaDescriptionAdapter;
        protected int nextActionIconResourceId;
        protected final int notificationId;
        protected NotificationListener notificationListener;
        protected int pauseActionIconResourceId;
        protected int playActionIconResourceId;
        protected int previousActionIconResourceId;
        protected int rewindActionIconResourceId;
        protected int smallIconResourceId;
        protected int stopActionIconResourceId;

        @Deprecated
        public Builder(Context context, int i6, String str, MediaDescriptionAdapter mediaDescriptionAdapter) {
            this(context, i6, str);
            this.mediaDescriptionAdapter = mediaDescriptionAdapter;
        }

        public PlayerNotificationManager build() {
            int i6 = this.channelNameResourceId;
            if (i6 != 0) {
                NotificationUtil.createNotificationChannel(this.context, this.channelId, i6, this.channelDescriptionResourceId, this.channelImportance);
            }
            return new PlayerNotificationManager(this.context, this.channelId, this.notificationId, this.mediaDescriptionAdapter, this.notificationListener, this.customActionReceiver, this.smallIconResourceId, this.playActionIconResourceId, this.pauseActionIconResourceId, this.stopActionIconResourceId, this.rewindActionIconResourceId, this.fastForwardActionIconResourceId, this.previousActionIconResourceId, this.nextActionIconResourceId, this.groupKey);
        }

        public Builder setChannelDescriptionResourceId(int i6) {
            this.channelDescriptionResourceId = i6;
            return this;
        }

        public Builder setChannelImportance(int i6) {
            this.channelImportance = i6;
            return this;
        }

        public Builder setChannelNameResourceId(int i6) {
            this.channelNameResourceId = i6;
            return this;
        }

        public Builder setCustomActionReceiver(CustomActionReceiver customActionReceiver) {
            this.customActionReceiver = customActionReceiver;
            return this;
        }

        public Builder setFastForwardActionIconResourceId(int i6) {
            this.fastForwardActionIconResourceId = i6;
            return this;
        }

        public Builder setGroup(String str) {
            this.groupKey = str;
            return this;
        }

        public Builder setMediaDescriptionAdapter(MediaDescriptionAdapter mediaDescriptionAdapter) {
            this.mediaDescriptionAdapter = mediaDescriptionAdapter;
            return this;
        }

        public Builder setNextActionIconResourceId(int i6) {
            this.nextActionIconResourceId = i6;
            return this;
        }

        public Builder setNotificationListener(NotificationListener notificationListener) {
            this.notificationListener = notificationListener;
            return this;
        }

        public Builder setPauseActionIconResourceId(int i6) {
            this.pauseActionIconResourceId = i6;
            return this;
        }

        public Builder setPlayActionIconResourceId(int i6) {
            this.playActionIconResourceId = i6;
            return this;
        }

        public Builder setPreviousActionIconResourceId(int i6) {
            this.previousActionIconResourceId = i6;
            return this;
        }

        public Builder setRewindActionIconResourceId(int i6) {
            this.rewindActionIconResourceId = i6;
            return this;
        }

        public Builder setSmallIconResourceId(int i6) {
            this.smallIconResourceId = i6;
            return this;
        }

        public Builder setStopActionIconResourceId(int i6) {
            this.stopActionIconResourceId = i6;
            return this;
        }

        public Builder(Context context, int i6, String str) {
            Assertions.checkArgument(i6 > 0);
            this.context = context;
            this.notificationId = i6;
            this.channelId = str;
            this.channelImportance = 2;
            this.mediaDescriptionAdapter = new DefaultMediaDescriptionAdapter(null);
            this.smallIconResourceId = R.drawable.exo_notification_small_icon;
            this.playActionIconResourceId = R.drawable.exo_notification_play;
            this.pauseActionIconResourceId = R.drawable.exo_notification_pause;
            this.stopActionIconResourceId = R.drawable.exo_notification_stop;
            this.rewindActionIconResourceId = R.drawable.exo_notification_rewind;
            this.fastForwardActionIconResourceId = R.drawable.exo_notification_fastforward;
            this.previousActionIconResourceId = R.drawable.exo_notification_previous;
            this.nextActionIconResourceId = R.drawable.exo_notification_next;
        }
    }

    public final void setMediaSessionToken(MediaSession.Token token) {
        if (Util.areEqual(this.mediaSessionToken, token)) {
            return;
        }
        this.mediaSessionToken = token;
        invalidate();
    }
}
