package androidx.media;

import X.AnonymousClass07U;
import X.AnonymousClass19Y;
import X.AnonymousClass28A;
import X.C03170Cd;
import X.C03190Cf;
import X.C03200Cg;
import X.C03220Ci;
import X.C03340Cu;
import X.C28541Bs;
import X.C39531hX;
import X.C43961og;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.util.Log;
import com.bytedance.covode.number.Covode;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

public abstract class MediaBrowserServiceCompat extends Service {
    public static final boolean LIZ = Log.isLoggable("MBServiceCompat", 3);
    public final AnonymousClass19Y<IBinder, C03190Cf> LIZIZ = new AnonymousClass19Y<>();
    public C03190Cf LIZJ;
    public final C03340Cu LIZLLL = new C03340Cu(this);
    public MediaSessionCompat.Token LJ;
    public C03200Cg LJFF;

    public abstract C03170Cd LIZ(String str);

    public abstract void LIZ(String str, C03220Ci<List<MediaBrowserCompat.MediaItem>> r2);

    public void dump(FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
    }

    static {
        Covode.recordClassIndex(1321);
    }

    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= 28) {
            this.LJFF = new AnonymousClass28A(this);
        } else if (Build.VERSION.SDK_INT >= 26) {
            this.LJFF = new C43961og(this);
        } else if (Build.VERSION.SDK_INT >= 23) {
            this.LJFF = new C39531hX(this);
        } else {
            this.LJFF = new C28541Bs(this);
        }
        this.LJFF.LIZ();
    }

    public final void LIZ(C03220Ci<MediaBrowserCompat.MediaItem> r2) {
        r2.LJIIIIZZ = 2;
        r2.LIZJ();
    }

    public IBinder onBind(Intent intent) {
        return this.LJFF.LIZ(intent);
    }

    public final void LIZ(MediaSessionCompat.Token token) {
        if (token == null) {
            throw new IllegalArgumentException("Session token may not be null.");
        } else if (this.LJ == null) {
            this.LJ = token;
            this.LJFF.LIZ(token);
        } else {
            throw new IllegalStateException("The session token has already been set.");
        }
    }

    public final void LIZIZ(String str, C03220Ci<List<MediaBrowserCompat.MediaItem>> r3) {
        r3.LJIIIIZZ = 1;
        LIZ(str, r3);
    }

    public final boolean LIZ(String str, C03190Cf r7, IBinder iBinder) {
        boolean z = true;
        boolean z2 = false;
        if (iBinder == null) {
            try {
                if (r7.LJI.remove(str) == null) {
                    z = false;
                }
                return z;
            } finally {
                this.LIZJ = r7;
                this.LIZJ = null;
            }
        } else {
            List list = r7.LJI.get(str);
            if (list != null) {
                Iterator it = list.iterator();
                while (it.hasNext()) {
                    if (iBinder == ((AnonymousClass07U) it.next()).LIZ) {
                        it.remove();
                        z2 = true;
                    }
                }
                if (list.size() == 0) {
                    r7.LJI.remove(str);
                }
            }
            this.LIZJ = r7;
            this.LIZJ = null;
            return z2;
        }
    }
}
