package android.support.v4.media.session;

import X.AnonymousClass01R;
import X.AnonymousClass01S;
import X.AnonymousClass01V;
import X.C002901b;
import X.C275717z;
import X.C38831gP;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ResultReceiver;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.text.TextUtils;
import android.util.TypedValue;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MediaSessionCompat {
    public static int LIZIZ;
    public final MediaControllerCompat LIZ;
    public final AnonymousClass01S LIZJ;
    public final ArrayList<Object> LIZLLL;

    static {
        Covode.recordClassIndex(153);
    }

    public final void LIZ() {
        this.LIZJ.LIZ();
    }

    public final boolean LIZIZ() {
        return this.LIZJ.LIZIZ();
    }

    public final void LIZJ() {
        this.LIZJ.LIZJ();
    }

    public final Token LIZLLL() {
        return this.LIZJ.LIZLLL();
    }

    public static final class QueueItem implements Parcelable {
        public static final Parcelable.Creator<QueueItem> CREATOR = new Parcelable.Creator<QueueItem>() {
            static {
                Covode.recordClassIndex(157);
            }

            public final /* bridge */ /* synthetic */ Object[] newArray(int i) {
                return new QueueItem[i];
            }

            public final /* synthetic */ Object createFromParcel(Parcel parcel) {
                return new QueueItem(parcel);
            }
        };
        public final MediaDescriptionCompat LIZ;
        public final long LIZIZ;
        public Object LIZJ;

        public final int describeContents() {
            return 0;
        }

        static {
            Covode.recordClassIndex(156);
        }

        public final String toString() {
            return "MediaSession.QueueItem {Description=" + this.LIZ + ", Id=" + this.LIZIZ + " }";
        }

        public QueueItem(Parcel parcel) {
            this.LIZ = MediaDescriptionCompat.CREATOR.createFromParcel(parcel);
            this.LIZIZ = parcel.readLong();
        }

        public final void writeToParcel(Parcel parcel, int i) {
            this.LIZ.writeToParcel(parcel, i);
            parcel.writeLong(this.LIZIZ);
        }

        public QueueItem(Object obj, MediaDescriptionCompat mediaDescriptionCompat, long j) {
            if (mediaDescriptionCompat == null) {
                throw new IllegalArgumentException("Description cannot be null.");
            } else if (j != -1) {
                this.LIZ = mediaDescriptionCompat;
                this.LIZIZ = j;
                this.LIZJ = obj;
            } else {
                throw new IllegalArgumentException("Id cannot be QueueItem.UNKNOWN_ID");
            }
        }
    }

    public static final class ResultReceiverWrapper implements Parcelable {
        public static final Parcelable.Creator<ResultReceiverWrapper> CREATOR = new Parcelable.Creator<ResultReceiverWrapper>() {
            static {
                Covode.recordClassIndex(159);
            }

            public final /* bridge */ /* synthetic */ Object[] newArray(int i) {
                return new ResultReceiverWrapper[i];
            }

            public final /* synthetic */ Object createFromParcel(Parcel parcel) {
                return new ResultReceiverWrapper(parcel);
            }
        };
        public ResultReceiver LIZ;

        public final int describeContents() {
            return 0;
        }

        static {
            Covode.recordClassIndex(158);
        }

        public ResultReceiverWrapper(Parcel parcel) {
            this.LIZ = (ResultReceiver) ResultReceiver.CREATOR.createFromParcel(parcel);
        }

        public final void writeToParcel(Parcel parcel, int i) {
            this.LIZ.writeToParcel(parcel, i);
        }
    }

    public static final class Token implements Parcelable {
        public static final Parcelable.Creator<Token> CREATOR = new Parcelable.Creator<Token>() {
            static {
                Covode.recordClassIndex(161);
            }

            public final /* bridge */ /* synthetic */ Object[] newArray(int i) {
                return new Token[i];
            }

            public final /* synthetic */ Object createFromParcel(Parcel parcel) {
                return new Token(parcel.readParcelable((ClassLoader) null));
            }
        };
        public final Object LIZ;
        public AnonymousClass01V LIZIZ;
        public Bundle LIZJ;

        public final int describeContents() {
            return 0;
        }

        static {
            Covode.recordClassIndex(160);
        }

        public final int hashCode() {
            Object obj = this.LIZ;
            if (obj == null) {
                return 0;
            }
            return obj.hashCode();
        }

        public Token(Object obj) {
            this(obj, (AnonymousClass01V) null, (Bundle) null);
        }

        public final boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof Token)) {
                return false;
            }
            Token token = (Token) obj;
            Object obj2 = this.LIZ;
            if (obj2 != null) {
                Object obj3 = token.LIZ;
                if (obj3 == null) {
                    return false;
                }
                return obj2.equals(obj3);
            } else if (token.LIZ == null) {
                return true;
            } else {
                return false;
            }
        }

        public final void writeToParcel(Parcel parcel, int i) {
            parcel.writeParcelable((Parcelable) this.LIZ, i);
        }

        public Token(Object obj, AnonymousClass01V r3) {
            this(obj, r3, (Bundle) null);
        }

        public static Token LIZ(Object obj, AnonymousClass01V r2) {
            if (obj == null) {
                return null;
            }
            C002901b.LIZ(obj);
            return new Token(obj, r2);
        }

        public Token(Object obj, AnonymousClass01V r2, Bundle bundle) {
            this.LIZ = obj;
            this.LIZIZ = r2;
            this.LIZJ = bundle;
        }
    }

    public final void LIZ(AnonymousClass01R r1) {
        LIZIZ(r1);
    }

    public static void LIZ(Bundle bundle) {
        if (bundle != null) {
            bundle.setClassLoader(MediaSessionCompat.class.getClassLoader());
        }
    }

    public final void LIZ(PendingIntent pendingIntent) {
        this.LIZJ.LIZ(pendingIntent);
    }

    public final void LIZIZ(AnonymousClass01R r3) {
        if (r3 == null) {
            this.LIZJ.LIZ((AnonymousClass01R) null, (Handler) null);
        } else {
            this.LIZJ.LIZ(r3, new Handler());
        }
    }

    public final void LIZ(MediaMetadataCompat mediaMetadataCompat) {
        this.LIZJ.LIZ(mediaMetadataCompat);
    }

    public final void LIZ(PlaybackStateCompat playbackStateCompat) {
        this.LIZJ.LIZ(playbackStateCompat);
    }

    public final void LIZ(boolean z) {
        this.LIZJ.LIZ(z);
        Iterator<Object> it = this.LIZLLL.iterator();
        while (it.hasNext()) {
            it.next();
        }
    }

    public MediaSessionCompat(Context context, String str) {
        this(context, str, (byte) 0);
    }

    public MediaSessionCompat(Context context, String str, byte b) {
        this(context, str, (PendingIntent) null);
    }

    public MediaSessionCompat(Context context, String str, PendingIntent pendingIntent) {
        this.LIZLLL = new ArrayList<>();
        if (context == null) {
            throw new IllegalArgumentException("context must not be null");
        } else if (!TextUtils.isEmpty(str)) {
            Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
            intent.setPackage(context.getPackageName());
            List<ResolveInfo> queryBroadcastReceivers = context.getPackageManager().queryBroadcastReceivers(intent, 0);
            if (queryBroadcastReceivers.size() == 1) {
                ResolveInfo resolveInfo = queryBroadcastReceivers.get(0);
                ComponentName componentName = new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
                Intent intent2 = new Intent("android.intent.action.MEDIA_BUTTON");
                intent2.setComponent(componentName);
                pendingIntent = PendingIntent.getBroadcast(context, 0, intent2, 0);
            } else {
                queryBroadcastReceivers.size();
            }
            if (Build.VERSION.SDK_INT >= 28) {
                C38831gP r1 = new C38831gP(context, str);
                this.LIZJ = r1;
                LIZIZ(new AnonymousClass01R() {
                    static {
                        Covode.recordClassIndex(154);
                    }
                });
                r1.LIZ(pendingIntent);
            } else {
                C275717z r12 = new C275717z(context, str, (Bundle) null);
                this.LIZJ = r12;
                LIZIZ(new AnonymousClass01R() {
                    static {
                        Covode.recordClassIndex(155);
                    }
                });
                r12.LIZ(pendingIntent);
            }
            this.LIZ = new MediaControllerCompat(context, this);
            if (LIZIZ == 0) {
                LIZIZ = (int) (TypedValue.applyDimension(1, 320.0f, context.getResources().getDisplayMetrics()) + 0.5f);
            }
        } else {
            throw new IllegalArgumentException("tag must not be null or empty");
        }
    }
}
