package androidx.media; import android.annotation.SuppressLint; import android.app.Service; import android.content.Context; import android.content.Intent; import android.media.browse.MediaBrowser; import android.media.session.MediaSession; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.service.media.MediaBrowserService; import android.support.v4.media.MediaBrowserCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.os.ResultReceiver; import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import androidx.collection.ArrayMap; import androidx.core.app.BundleCompat; import androidx.core.util.Pair; import androidx.media.MediaSessionManager; import c.d.b.a.a; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import x.a.b.b.a.b; public abstract class MediaBrowserServiceCompat extends Service { public static final boolean DEBUG = Log.isLoggable("MBServiceCompat", 3); private static final float EPSILON = 1.0E-5f; @RestrictTo({RestrictTo.Scope.LIBRARY}) public static final String KEY_MEDIA_ITEM = "media_item"; @RestrictTo({RestrictTo.Scope.LIBRARY}) public static final String KEY_SEARCH_RESULTS = "search_results"; @RestrictTo({RestrictTo.Scope.LIBRARY}) public static final int RESULT_ERROR = -1; public static final int RESULT_FLAG_ON_LOAD_ITEM_NOT_IMPLEMENTED = 2; public static final int RESULT_FLAG_ON_SEARCH_NOT_IMPLEMENTED = 4; public static final int RESULT_FLAG_OPTION_NOT_HANDLED = 1; @RestrictTo({RestrictTo.Scope.LIBRARY}) public static final int RESULT_OK = 0; @RestrictTo({RestrictTo.Scope.LIBRARY}) public static final int RESULT_PROGRESS_UPDATE = 1; public static final String SERVICE_INTERFACE = "android.media.browse.MediaBrowserService"; public static final String TAG = "MBServiceCompat"; public final ConnectionRecord mConnectionFromFwk = new ConnectionRecord("android.media.session.MediaController", -1, -1, null, null); public final ArrayMap mConnections = new ArrayMap<>(); public ConnectionRecord mCurConnection; public final ServiceHandler mHandler = new ServiceHandler(); private MediaBrowserServiceImpl mImpl; public final ArrayList mPendingConnections = new ArrayList<>(); public MediaSessionCompat.Token mSession; /* renamed from: androidx.media.MediaBrowserServiceCompat$1 reason: invalid class name */ public class AnonymousClass1 extends Result> { public final /* synthetic */ ConnectionRecord val$connection; public final /* synthetic */ Bundle val$notifyChildrenChangedOptions; public final /* synthetic */ String val$parentId; public final /* synthetic */ Bundle val$subscribeOptions; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(Object obj, ConnectionRecord connectionRecord, String str, Bundle bundle, Bundle bundle2) { super(obj); this.val$connection = connectionRecord; this.val$parentId = str; this.val$subscribeOptions = bundle; this.val$notifyChildrenChangedOptions = bundle2; } public void onResultSent(List list) { if (MediaBrowserServiceCompat.this.mConnections.get(this.val$connection.callbacks.asBinder()) == this.val$connection) { if ((getFlags() & 1) != 0) { list = MediaBrowserServiceCompat.this.applyOptions(list, this.val$subscribeOptions); } try { this.val$connection.callbacks.onLoadChildren(this.val$parentId, list, this.val$subscribeOptions, this.val$notifyChildrenChangedOptions); } catch (RemoteException unused) { StringBuilder L = a.L("Calling onLoadChildren() failed for id="); L.append(this.val$parentId); L.append(" package="); a.j0(L, this.val$connection.pkg, "MBServiceCompat"); } } else if (MediaBrowserServiceCompat.DEBUG) { StringBuilder L2 = a.L("Not sending onLoadChildren result for connection that has been disconnected. pkg="); L2.append(this.val$connection.pkg); L2.append(" id="); L2.append(this.val$parentId); Log.d("MBServiceCompat", L2.toString()); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$2 reason: invalid class name */ public class AnonymousClass2 extends Result { public final /* synthetic */ ResultReceiver val$receiver; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass2(Object obj, ResultReceiver resultReceiver) { super(obj); this.val$receiver = resultReceiver; } public void onResultSent(MediaBrowserCompat.MediaItem mediaItem) { if ((getFlags() & 2) != 0) { this.val$receiver.b(-1, null); return; } Bundle bundle = new Bundle(); bundle.putParcelable("media_item", mediaItem); this.val$receiver.b(0, bundle); } } /* renamed from: androidx.media.MediaBrowserServiceCompat$3 reason: invalid class name */ public class AnonymousClass3 extends Result> { public final /* synthetic */ ResultReceiver val$receiver; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass3(Object obj, ResultReceiver resultReceiver) { super(obj); this.val$receiver = resultReceiver; } public void onResultSent(List list) { if ((getFlags() & 4) != 0 || list == null) { this.val$receiver.b(-1, null); return; } Bundle bundle = new Bundle(); bundle.putParcelableArray("search_results", (Parcelable[]) list.toArray(new MediaBrowserCompat.MediaItem[0])); this.val$receiver.b(0, bundle); } } /* renamed from: androidx.media.MediaBrowserServiceCompat$4 reason: invalid class name */ public class AnonymousClass4 extends Result { public final /* synthetic */ ResultReceiver val$receiver; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass4(Object obj, ResultReceiver resultReceiver) { super(obj); this.val$receiver = resultReceiver; } @Override // androidx.media.MediaBrowserServiceCompat.Result public void onErrorSent(Bundle bundle) { this.val$receiver.b(-1, bundle); } @Override // androidx.media.MediaBrowserServiceCompat.Result public void onProgressUpdateSent(Bundle bundle) { this.val$receiver.b(1, bundle); } public void onResultSent(Bundle bundle) { this.val$receiver.b(0, bundle); } } public static final class BrowserRoot { public static final String EXTRA_OFFLINE = "android.service.media.extra.OFFLINE"; public static final String EXTRA_RECENT = "android.service.media.extra.RECENT"; public static final String EXTRA_SUGGESTED = "android.service.media.extra.SUGGESTED"; @Deprecated public static final String EXTRA_SUGGESTION_KEYWORDS = "android.service.media.extra.SUGGESTION_KEYWORDS"; private final Bundle mExtras; private final String mRootId; public BrowserRoot(@NonNull String str, @Nullable Bundle bundle) { if (str != null) { this.mRootId = str; this.mExtras = bundle; return; } throw new IllegalArgumentException("The root id in BrowserRoot cannot be null. Use null for BrowserRoot instead"); } public static /* synthetic */ String access$000(BrowserRoot browserRoot) { return browserRoot.mRootId; } public static /* synthetic */ Bundle access$100(BrowserRoot browserRoot) { return browserRoot.mExtras; } public Bundle getExtras() { return this.mExtras; } public String getRootId() { return this.mRootId; } } public class ConnectionRecord implements IBinder.DeathRecipient { public final MediaSessionManager.RemoteUserInfo browserInfo; public final ServiceCallbacks callbacks; public final int pid; public final String pkg; public BrowserRoot root; public final Bundle rootHints; public final HashMap>> subscriptions = new HashMap<>(); public final int uid; /* renamed from: androidx.media.MediaBrowserServiceCompat$ConnectionRecord$1 reason: invalid class name */ public class AnonymousClass1 implements Runnable { public AnonymousClass1() { } @Override // java.lang.Runnable public void run() { ConnectionRecord connectionRecord = ConnectionRecord.this; MediaBrowserServiceCompat.this.mConnections.remove(connectionRecord.callbacks.asBinder()); } } public ConnectionRecord(String str, int i, int i2, Bundle bundle, ServiceCallbacks serviceCallbacks) { this.pkg = str; this.pid = i; this.uid = i2; this.browserInfo = new MediaSessionManager.RemoteUserInfo(str, i, i2); this.rootHints = bundle; this.callbacks = serviceCallbacks; } @Override // android.os.IBinder.DeathRecipient public void binderDied() { MediaBrowserServiceCompat.this.mHandler.post(new AnonymousClass1()); } } public interface MediaBrowserServiceImpl { Bundle getBrowserRootHints(); MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo(); void notifyChildrenChanged(MediaSessionManager.RemoteUserInfo remoteUserInfo, String str, Bundle bundle); void notifyChildrenChanged(String str, Bundle bundle); IBinder onBind(Intent intent); void onCreate(); void setSessionToken(MediaSessionCompat.Token token); } @RequiresApi(21) public class MediaBrowserServiceImplApi21 implements MediaBrowserServiceImpl { public Messenger mMessenger; public final List mRootExtrasList = new ArrayList(); public MediaBrowserService mServiceFwk; /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$1 reason: invalid class name */ public class AnonymousClass1 implements Runnable { public final /* synthetic */ MediaSessionCompat.Token val$token; public AnonymousClass1(MediaSessionCompat.Token token) { this.val$token = token; } @Override // java.lang.Runnable public void run() { if (!MediaBrowserServiceImplApi21.this.mRootExtrasList.isEmpty()) { b b = this.val$token.b(); if (b != null) { for (Bundle bundle : MediaBrowserServiceImplApi21.this.mRootExtrasList) { BundleCompat.putBinder(bundle, "extra_session_binder", b.asBinder()); } } MediaBrowserServiceImplApi21.this.mRootExtrasList.clear(); } MediaBrowserServiceImplApi21.this.mServiceFwk.setSessionToken((MediaSession.Token) this.val$token.j); } } /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$2 reason: invalid class name */ public class AnonymousClass2 extends Result> { public final /* synthetic */ ResultWrapper val$resultWrapper; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass2(Object obj, ResultWrapper resultWrapper) { super(obj); this.val$resultWrapper = resultWrapper; } @Override // androidx.media.MediaBrowserServiceCompat.Result public void detach() { this.val$resultWrapper.detach(); } public void onResultSent(List list) { ArrayList arrayList; if (list != null) { arrayList = new ArrayList(); for (MediaBrowserCompat.MediaItem mediaItem : list) { Parcel obtain = Parcel.obtain(); mediaItem.writeToParcel(obtain, 0); arrayList.add(obtain); } } else { arrayList = null; } this.val$resultWrapper.sendResult(arrayList); } } /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$3 reason: invalid class name */ public class AnonymousClass3 implements Runnable { public final /* synthetic */ Bundle val$options; public final /* synthetic */ String val$parentId; public AnonymousClass3(String str, Bundle bundle) { this.val$parentId = str; this.val$options = bundle; } @Override // java.lang.Runnable public void run() { for (IBinder iBinder : MediaBrowserServiceCompat.this.mConnections.keySet()) { ArrayMap arrayMap = MediaBrowserServiceCompat.this.mConnections; MediaBrowserServiceImplApi21.this.notifyChildrenChangedForCompatOnHandler(arrayMap.get(iBinder), this.val$parentId, this.val$options); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$4 reason: invalid class name */ public class AnonymousClass4 implements Runnable { public final /* synthetic */ Bundle val$options; public final /* synthetic */ String val$parentId; public final /* synthetic */ MediaSessionManager.RemoteUserInfo val$remoteUserInfo; public AnonymousClass4(MediaSessionManager.RemoteUserInfo remoteUserInfo, String str, Bundle bundle) { this.val$remoteUserInfo = remoteUserInfo; this.val$parentId = str; this.val$options = bundle; } @Override // java.lang.Runnable public void run() { for (int i = 0; i < MediaBrowserServiceCompat.this.mConnections.size(); i++) { ConnectionRecord valueAt = MediaBrowserServiceCompat.this.mConnections.valueAt(i); if (valueAt.browserInfo.equals(this.val$remoteUserInfo)) { MediaBrowserServiceImplApi21.this.notifyChildrenChangedForCompatOnHandler(valueAt, this.val$parentId, this.val$options); } } } } public class MediaBrowserServiceApi21 extends MediaBrowserService { public MediaBrowserServiceApi21(Context context) { attachBaseContext(context); } @Override // android.service.media.MediaBrowserService @SuppressLint({"SyntheticAccessor"}) public MediaBrowserService.BrowserRoot onGetRoot(String str, int i, Bundle bundle) { MediaSessionCompat.a(bundle); BrowserRoot onGetRoot = MediaBrowserServiceImplApi21.this.onGetRoot(str, i, bundle == null ? null : new Bundle(bundle)); if (onGetRoot == null) { return null; } return new MediaBrowserService.BrowserRoot(BrowserRoot.access$000(onGetRoot), BrowserRoot.access$100(onGetRoot)); } @Override // android.service.media.MediaBrowserService public void onLoadChildren(String str, MediaBrowserService.Result> result) { MediaBrowserServiceImplApi21.this.onLoadChildren(str, new ResultWrapper<>(result)); } } public MediaBrowserServiceImplApi21() { } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public Bundle getBrowserRootHints() { if (this.mMessenger == null) { return null; } ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mCurConnection; if (connectionRecord == null) { throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods"); } else if (connectionRecord.rootHints == null) { return null; } else { return new Bundle(MediaBrowserServiceCompat.this.mCurConnection.rootHints); } } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mCurConnection; if (connectionRecord != null) { return connectionRecord.browserInfo; } throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods"); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void notifyChildrenChanged(MediaSessionManager.RemoteUserInfo remoteUserInfo, String str, Bundle bundle) { notifyChildrenChangedForCompat(remoteUserInfo, str, bundle); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void notifyChildrenChanged(String str, Bundle bundle) { notifyChildrenChangedForFramework(str, bundle); notifyChildrenChangedForCompat(str, bundle); } public void notifyChildrenChangedForCompat(MediaSessionManager.RemoteUserInfo remoteUserInfo, String str, Bundle bundle) { MediaBrowserServiceCompat.this.mHandler.post(new AnonymousClass4(remoteUserInfo, str, bundle)); } public void notifyChildrenChangedForCompat(String str, Bundle bundle) { MediaBrowserServiceCompat.this.mHandler.post(new AnonymousClass3(str, bundle)); } public void notifyChildrenChangedForCompatOnHandler(ConnectionRecord connectionRecord, String str, Bundle bundle) { List> list = connectionRecord.subscriptions.get(str); if (list != null) { for (Pair pair : list) { if (MediaBrowserCompatUtils.hasDuplicatedItems(bundle, pair.second)) { MediaBrowserServiceCompat.this.performLoadChildren(str, connectionRecord, pair.second, bundle); } } } } public void notifyChildrenChangedForFramework(String str, Bundle bundle) { this.mServiceFwk.notifyChildrenChanged(str); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public IBinder onBind(Intent intent) { return this.mServiceFwk.onBind(intent); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void onCreate() { MediaBrowserServiceApi21 mediaBrowserServiceApi21 = new MediaBrowserServiceApi21(MediaBrowserServiceCompat.this); this.mServiceFwk = mediaBrowserServiceApi21; mediaBrowserServiceApi21.onCreate(); } public BrowserRoot onGetRoot(String str, int i, Bundle bundle) { int i2; Bundle bundle2; if (bundle == null || bundle.getInt("extra_client_version", 0) == 0) { bundle2 = null; i2 = -1; } else { bundle.remove("extra_client_version"); this.mMessenger = new Messenger(MediaBrowserServiceCompat.this.mHandler); bundle2 = new Bundle(); bundle2.putInt("extra_service_version", 2); BundleCompat.putBinder(bundle2, "extra_messenger", this.mMessenger.getBinder()); MediaSessionCompat.Token token = MediaBrowserServiceCompat.this.mSession; if (token != null) { b b = token.b(); BundleCompat.putBinder(bundle2, "extra_session_binder", b == null ? null : b.asBinder()); } else { this.mRootExtrasList.add(bundle2); } int i3 = bundle.getInt("extra_calling_pid", -1); bundle.remove("extra_calling_pid"); i2 = i3; } ConnectionRecord connectionRecord = new ConnectionRecord(str, i2, i, bundle, null); MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat.mCurConnection = connectionRecord; BrowserRoot onGetRoot = mediaBrowserServiceCompat.onGetRoot(str, i, bundle); MediaBrowserServiceCompat mediaBrowserServiceCompat2 = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat2.mCurConnection = null; if (onGetRoot == null) { return null; } if (this.mMessenger != null) { mediaBrowserServiceCompat2.mPendingConnections.add(connectionRecord); } if (bundle2 == null) { bundle2 = onGetRoot.getExtras(); } else if (onGetRoot.getExtras() != null) { bundle2.putAll(onGetRoot.getExtras()); } return new BrowserRoot(onGetRoot.getRootId(), bundle2); } public void onLoadChildren(String str, ResultWrapper> resultWrapper) { AnonymousClass2 r0 = new AnonymousClass2(str, resultWrapper); MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk; mediaBrowserServiceCompat.onLoadChildren(str, r0); MediaBrowserServiceCompat.this.mCurConnection = null; } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void setSessionToken(MediaSessionCompat.Token token) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass1(token)); } } @RequiresApi(23) public class MediaBrowserServiceImplApi23 extends MediaBrowserServiceImplApi21 { /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi23$1 reason: invalid class name */ public class AnonymousClass1 extends Result { public final /* synthetic */ ResultWrapper val$resultWrapper; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(Object obj, ResultWrapper resultWrapper) { super(obj); this.val$resultWrapper = resultWrapper; } @Override // androidx.media.MediaBrowserServiceCompat.Result public void detach() { this.val$resultWrapper.detach(); } public void onResultSent(MediaBrowserCompat.MediaItem mediaItem) { if (mediaItem == null) { this.val$resultWrapper.sendResult(null); return; } Parcel obtain = Parcel.obtain(); mediaItem.writeToParcel(obtain, 0); this.val$resultWrapper.sendResult(obtain); } } public class MediaBrowserServiceApi23 extends MediaBrowserServiceImplApi21.MediaBrowserServiceApi21 { public MediaBrowserServiceApi23(Context context) { super(context); } @Override // android.service.media.MediaBrowserService public void onLoadItem(String str, MediaBrowserService.Result result) { MediaBrowserServiceImplApi23.this.onLoadItem(str, new ResultWrapper<>(result)); } } public MediaBrowserServiceImplApi23() { super(); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void onCreate() { MediaBrowserServiceApi23 mediaBrowserServiceApi23 = new MediaBrowserServiceApi23(MediaBrowserServiceCompat.this); this.mServiceFwk = mediaBrowserServiceApi23; mediaBrowserServiceApi23.onCreate(); } public void onLoadItem(String str, ResultWrapper resultWrapper) { AnonymousClass1 r0 = new AnonymousClass1(str, resultWrapper); MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk; mediaBrowserServiceCompat.onLoadItem(str, r0); MediaBrowserServiceCompat.this.mCurConnection = null; } } @RequiresApi(26) public class MediaBrowserServiceImplApi26 extends MediaBrowserServiceImplApi23 { /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi26$1 reason: invalid class name */ public class AnonymousClass1 extends Result> { public final /* synthetic */ Bundle val$options; public final /* synthetic */ ResultWrapper val$resultWrapper; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(Object obj, ResultWrapper resultWrapper, Bundle bundle) { super(obj); this.val$resultWrapper = resultWrapper; this.val$options = bundle; } @Override // androidx.media.MediaBrowserServiceCompat.Result public void detach() { this.val$resultWrapper.detach(); } public void onResultSent(List list) { if (list == null) { this.val$resultWrapper.sendResult(null); return; } if ((getFlags() & 1) != 0) { list = MediaBrowserServiceCompat.this.applyOptions(list, this.val$options); } ArrayList arrayList = new ArrayList(); for (MediaBrowserCompat.MediaItem mediaItem : list) { Parcel obtain = Parcel.obtain(); mediaItem.writeToParcel(obtain, 0); arrayList.add(obtain); } this.val$resultWrapper.sendResult(arrayList); } } public class MediaBrowserServiceApi26 extends MediaBrowserServiceImplApi23.MediaBrowserServiceApi23 { public MediaBrowserServiceApi26(Context context) { super(context); } @Override // android.service.media.MediaBrowserService public void onLoadChildren(String str, MediaBrowserService.Result> result, Bundle bundle) { MediaSessionCompat.a(bundle); MediaBrowserServiceImplApi26 mediaBrowserServiceImplApi26 = MediaBrowserServiceImplApi26.this; MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk; mediaBrowserServiceImplApi26.onLoadChildren(str, new ResultWrapper<>(result), bundle); MediaBrowserServiceCompat.this.mCurConnection = null; } } public MediaBrowserServiceImplApi26() { super(); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public Bundle getBrowserRootHints() { MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; ConnectionRecord connectionRecord = mediaBrowserServiceCompat.mCurConnection; if (connectionRecord == null) { throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods"); } else if (connectionRecord == mediaBrowserServiceCompat.mConnectionFromFwk) { return this.mServiceFwk.getBrowserRootHints(); } else { if (connectionRecord.rootHints == null) { return null; } return new Bundle(MediaBrowserServiceCompat.this.mCurConnection.rootHints); } } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21 public void notifyChildrenChangedForFramework(String str, Bundle bundle) { if (bundle != null) { this.mServiceFwk.notifyChildrenChanged(str, bundle); } else { super.notifyChildrenChangedForFramework(str, bundle); } } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi23, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void onCreate() { MediaBrowserServiceApi26 mediaBrowserServiceApi26 = new MediaBrowserServiceApi26(MediaBrowserServiceCompat.this); this.mServiceFwk = mediaBrowserServiceApi26; mediaBrowserServiceApi26.onCreate(); } public void onLoadChildren(String str, ResultWrapper> resultWrapper, Bundle bundle) { AnonymousClass1 r0 = new AnonymousClass1(str, resultWrapper, bundle); MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk; mediaBrowserServiceCompat.onLoadChildren(str, r0, bundle); MediaBrowserServiceCompat.this.mCurConnection = null; } } @RequiresApi(28) public class MediaBrowserServiceImplApi28 extends MediaBrowserServiceImplApi26 { public MediaBrowserServiceImplApi28() { super(); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() { MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; ConnectionRecord connectionRecord = mediaBrowserServiceCompat.mCurConnection; if (connectionRecord != null) { return connectionRecord == mediaBrowserServiceCompat.mConnectionFromFwk ? new MediaSessionManager.RemoteUserInfo(this.mServiceFwk.getCurrentBrowserInfo()) : connectionRecord.browserInfo; } throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods"); } } public class MediaBrowserServiceImplBase implements MediaBrowserServiceImpl { private Messenger mMessenger; /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplBase$1 reason: invalid class name */ public class AnonymousClass1 implements Runnable { public final /* synthetic */ MediaSessionCompat.Token val$token; public AnonymousClass1(MediaSessionCompat.Token token) { this.val$token = token; } @Override // java.lang.Runnable public void run() { Iterator it = MediaBrowserServiceCompat.this.mConnections.values().iterator(); while (it.hasNext()) { ConnectionRecord next = it.next(); try { next.callbacks.onConnect(next.root.getRootId(), this.val$token, next.root.getExtras()); } catch (RemoteException unused) { StringBuilder L = a.L("Connection for "); L.append(next.pkg); L.append(" is no longer valid."); Log.w("MBServiceCompat", L.toString()); it.remove(); } } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplBase$2 reason: invalid class name */ public class AnonymousClass2 implements Runnable { public final /* synthetic */ Bundle val$options; public final /* synthetic */ String val$parentId; public AnonymousClass2(String str, Bundle bundle) { this.val$parentId = str; this.val$options = bundle; } @Override // java.lang.Runnable public void run() { for (IBinder iBinder : MediaBrowserServiceCompat.this.mConnections.keySet()) { ArrayMap arrayMap = MediaBrowserServiceCompat.this.mConnections; MediaBrowserServiceImplBase.this.notifyChildrenChangedOnHandler(arrayMap.get(iBinder), this.val$parentId, this.val$options); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplBase$3 reason: invalid class name */ public class AnonymousClass3 implements Runnable { public final /* synthetic */ Bundle val$options; public final /* synthetic */ String val$parentId; public final /* synthetic */ MediaSessionManager.RemoteUserInfo val$remoteUserInfo; public AnonymousClass3(MediaSessionManager.RemoteUserInfo remoteUserInfo, String str, Bundle bundle) { this.val$remoteUserInfo = remoteUserInfo; this.val$parentId = str; this.val$options = bundle; } @Override // java.lang.Runnable public void run() { for (int i = 0; i < MediaBrowserServiceCompat.this.mConnections.size(); i++) { ConnectionRecord valueAt = MediaBrowserServiceCompat.this.mConnections.valueAt(i); if (valueAt.browserInfo.equals(this.val$remoteUserInfo)) { MediaBrowserServiceImplBase.this.notifyChildrenChangedOnHandler(valueAt, this.val$parentId, this.val$options); return; } } } } public MediaBrowserServiceImplBase() { } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public Bundle getBrowserRootHints() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mCurConnection; if (connectionRecord == null) { throw new IllegalStateException("This should be called inside of onLoadChildren, onLoadItem, onSearch, or onCustomAction methods"); } else if (connectionRecord.rootHints == null) { return null; } else { return new Bundle(MediaBrowserServiceCompat.this.mCurConnection.rootHints); } } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mCurConnection; if (connectionRecord != null) { return connectionRecord.browserInfo; } throw new IllegalStateException("This should be called inside of onLoadChildren, onLoadItem, onSearch, or onCustomAction methods"); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void notifyChildrenChanged(@NonNull MediaSessionManager.RemoteUserInfo remoteUserInfo, @NonNull String str, Bundle bundle) { MediaBrowserServiceCompat.this.mHandler.post(new AnonymousClass3(remoteUserInfo, str, bundle)); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void notifyChildrenChanged(@NonNull String str, Bundle bundle) { MediaBrowserServiceCompat.this.mHandler.post(new AnonymousClass2(str, bundle)); } public void notifyChildrenChangedOnHandler(ConnectionRecord connectionRecord, String str, Bundle bundle) { List> list = connectionRecord.subscriptions.get(str); if (list != null) { for (Pair pair : list) { if (MediaBrowserCompatUtils.hasDuplicatedItems(bundle, pair.second)) { MediaBrowserServiceCompat.this.performLoadChildren(str, connectionRecord, pair.second, bundle); } } } } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public IBinder onBind(Intent intent) { if ("android.media.browse.MediaBrowserService".equals(intent.getAction())) { return this.mMessenger.getBinder(); } return null; } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void onCreate() { this.mMessenger = new Messenger(MediaBrowserServiceCompat.this.mHandler); } @Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl public void setSessionToken(MediaSessionCompat.Token token) { MediaBrowserServiceCompat.this.mHandler.post(new AnonymousClass1(token)); } } public static class Result { private final Object mDebug; private boolean mDetachCalled; private int mFlags; private boolean mSendErrorCalled; private boolean mSendResultCalled; public Result(Object obj) { this.mDebug = obj; } private void checkExtraFields(Bundle bundle) { if (bundle != null && bundle.containsKey("android.media.browse.extra.DOWNLOAD_PROGRESS")) { float f = bundle.getFloat("android.media.browse.extra.DOWNLOAD_PROGRESS"); if (f < -1.0E-5f || f > 1.00001f) { throw new IllegalArgumentException("The value of the EXTRA_DOWNLOAD_PROGRESS field must be a float number within [0.0, 1.0]"); } } } public void detach() { if (this.mDetachCalled) { StringBuilder L = a.L("detach() called when detach() had already been called for: "); L.append(this.mDebug); throw new IllegalStateException(L.toString()); } else if (this.mSendResultCalled) { StringBuilder L2 = a.L("detach() called when sendResult() had already been called for: "); L2.append(this.mDebug); throw new IllegalStateException(L2.toString()); } else if (!this.mSendErrorCalled) { this.mDetachCalled = true; } else { StringBuilder L3 = a.L("detach() called when sendError() had already been called for: "); L3.append(this.mDebug); throw new IllegalStateException(L3.toString()); } } public int getFlags() { return this.mFlags; } public boolean isDone() { return this.mDetachCalled || this.mSendResultCalled || this.mSendErrorCalled; } public void onErrorSent(Bundle bundle) { StringBuilder L = a.L("It is not supported to send an error for "); L.append(this.mDebug); throw new UnsupportedOperationException(L.toString()); } public void onProgressUpdateSent(Bundle bundle) { StringBuilder L = a.L("It is not supported to send an interim update for "); L.append(this.mDebug); throw new UnsupportedOperationException(L.toString()); } public void onResultSent(T t) { } public void sendError(Bundle bundle) { if (this.mSendResultCalled || this.mSendErrorCalled) { StringBuilder L = a.L("sendError() called when either sendResult() or sendError() had already been called for: "); L.append(this.mDebug); throw new IllegalStateException(L.toString()); } this.mSendErrorCalled = true; onErrorSent(bundle); } public void sendProgressUpdate(Bundle bundle) { if (this.mSendResultCalled || this.mSendErrorCalled) { StringBuilder L = a.L("sendProgressUpdate() called when either sendResult() or sendError() had already been called for: "); L.append(this.mDebug); throw new IllegalStateException(L.toString()); } checkExtraFields(bundle); onProgressUpdateSent(bundle); } public void sendResult(T t) { if (this.mSendResultCalled || this.mSendErrorCalled) { StringBuilder L = a.L("sendResult() called when either sendResult() or sendError() had already been called for: "); L.append(this.mDebug); throw new IllegalStateException(L.toString()); } this.mSendResultCalled = true; onResultSent(t); } public void setFlags(int i) { this.mFlags = i; } } @RequiresApi(21) public static class ResultWrapper { public MediaBrowserService.Result mResultFwk; public ResultWrapper(MediaBrowserService.Result result) { this.mResultFwk = result; } public void detach() { this.mResultFwk.detach(); } public List parcelListToItemList(List list) { if (list == null) { return null; } ArrayList arrayList = new ArrayList(); for (Parcel parcel : list) { parcel.setDataPosition(0); arrayList.add((MediaBrowser.MediaItem) MediaBrowser.MediaItem.CREATOR.createFromParcel(parcel)); parcel.recycle(); } return arrayList; } /* JADX DEBUG: Multi-variable search result rejected for r0v4, resolved type: android.service.media.MediaBrowserService$Result */ /* JADX DEBUG: Multi-variable search result rejected for r0v5, resolved type: android.service.media.MediaBrowserService$Result */ /* JADX WARN: Multi-variable type inference failed */ public void sendResult(T t) { if (t instanceof List) { this.mResultFwk.sendResult(parcelListToItemList(t)); } else if (t instanceof Parcel) { T t2 = t; t2.setDataPosition(0); this.mResultFwk.sendResult(MediaBrowser.MediaItem.CREATOR.createFromParcel(t2)); t2.recycle(); } else { this.mResultFwk.sendResult(null); } } } public class ServiceBinderImpl { /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$1 reason: invalid class name */ public class AnonymousClass1 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ int val$pid; public final /* synthetic */ String val$pkg; public final /* synthetic */ Bundle val$rootHints; public final /* synthetic */ int val$uid; public AnonymousClass1(ServiceCallbacks serviceCallbacks, String str, int i, int i2, Bundle bundle) { this.val$callbacks = serviceCallbacks; this.val$pkg = str; this.val$pid = i; this.val$uid = i2; this.val$rootHints = bundle; } @Override // java.lang.Runnable public void run() { IBinder asBinder = this.val$callbacks.asBinder(); MediaBrowserServiceCompat.this.mConnections.remove(asBinder); ConnectionRecord connectionRecord = new ConnectionRecord(this.val$pkg, this.val$pid, this.val$uid, this.val$rootHints, this.val$callbacks); MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat.mCurConnection = connectionRecord; BrowserRoot onGetRoot = mediaBrowserServiceCompat.onGetRoot(this.val$pkg, this.val$uid, this.val$rootHints); connectionRecord.root = onGetRoot; MediaBrowserServiceCompat mediaBrowserServiceCompat2 = MediaBrowserServiceCompat.this; mediaBrowserServiceCompat2.mCurConnection = null; if (onGetRoot == null) { StringBuilder L = a.L("No root for client "); L.append(this.val$pkg); L.append(" from service "); L.append(getClass().getName()); Log.i("MBServiceCompat", L.toString()); try { this.val$callbacks.onConnectFailed(); } catch (RemoteException unused) { a.j0(a.L("Calling onConnectFailed() failed. Ignoring. pkg="), this.val$pkg, "MBServiceCompat"); } } else { try { mediaBrowserServiceCompat2.mConnections.put(asBinder, connectionRecord); asBinder.linkToDeath(connectionRecord, 0); if (MediaBrowserServiceCompat.this.mSession != null) { this.val$callbacks.onConnect(connectionRecord.root.getRootId(), MediaBrowserServiceCompat.this.mSession, connectionRecord.root.getExtras()); } } catch (RemoteException unused2) { a.j0(a.L("Calling onConnect() failed. Dropping client. pkg="), this.val$pkg, "MBServiceCompat"); MediaBrowserServiceCompat.this.mConnections.remove(asBinder); } } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$2 reason: invalid class name */ public class AnonymousClass2 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public AnonymousClass2(ServiceCallbacks serviceCallbacks) { this.val$callbacks = serviceCallbacks; } @Override // java.lang.Runnable public void run() { ConnectionRecord remove = MediaBrowserServiceCompat.this.mConnections.remove(this.val$callbacks.asBinder()); if (remove != null) { remove.callbacks.asBinder().unlinkToDeath(remove, 0); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$3 reason: invalid class name */ public class AnonymousClass3 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ String val$id; public final /* synthetic */ Bundle val$options; public final /* synthetic */ IBinder val$token; public AnonymousClass3(ServiceCallbacks serviceCallbacks, String str, IBinder iBinder, Bundle bundle) { this.val$callbacks = serviceCallbacks; this.val$id = str; this.val$token = iBinder; this.val$options = bundle; } @Override // java.lang.Runnable public void run() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(this.val$callbacks.asBinder()); if (connectionRecord == null) { a.j0(a.L("addSubscription for callback that isn't registered id="), this.val$id, "MBServiceCompat"); } else { MediaBrowserServiceCompat.this.addSubscription(this.val$id, connectionRecord, this.val$token, this.val$options); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$4 reason: invalid class name */ public class AnonymousClass4 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ String val$id; public final /* synthetic */ IBinder val$token; public AnonymousClass4(ServiceCallbacks serviceCallbacks, String str, IBinder iBinder) { this.val$callbacks = serviceCallbacks; this.val$id = str; this.val$token = iBinder; } @Override // java.lang.Runnable public void run() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(this.val$callbacks.asBinder()); if (connectionRecord == null) { a.j0(a.L("removeSubscription for callback that isn't registered id="), this.val$id, "MBServiceCompat"); } else if (!MediaBrowserServiceCompat.this.removeSubscription(this.val$id, connectionRecord, this.val$token)) { StringBuilder L = a.L("removeSubscription called for "); L.append(this.val$id); L.append(" which is not subscribed"); Log.w("MBServiceCompat", L.toString()); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$5 reason: invalid class name */ public class AnonymousClass5 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ String val$mediaId; public final /* synthetic */ ResultReceiver val$receiver; public AnonymousClass5(ServiceCallbacks serviceCallbacks, String str, ResultReceiver resultReceiver) { this.val$callbacks = serviceCallbacks; this.val$mediaId = str; this.val$receiver = resultReceiver; } @Override // java.lang.Runnable public void run() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(this.val$callbacks.asBinder()); if (connectionRecord == null) { a.j0(a.L("getMediaItem for callback that isn't registered id="), this.val$mediaId, "MBServiceCompat"); } else { MediaBrowserServiceCompat.this.performLoadItem(this.val$mediaId, connectionRecord, this.val$receiver); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$6 reason: invalid class name */ public class AnonymousClass6 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ int val$pid; public final /* synthetic */ String val$pkg; public final /* synthetic */ Bundle val$rootHints; public final /* synthetic */ int val$uid; public AnonymousClass6(ServiceCallbacks serviceCallbacks, int i, String str, int i2, Bundle bundle) { this.val$callbacks = serviceCallbacks; this.val$uid = i; this.val$pkg = str; this.val$pid = i2; this.val$rootHints = bundle; } @Override // java.lang.Runnable public void run() { IBinder asBinder = this.val$callbacks.asBinder(); MediaBrowserServiceCompat.this.mConnections.remove(asBinder); Iterator it = MediaBrowserServiceCompat.this.mPendingConnections.iterator(); ConnectionRecord connectionRecord = null; while (it.hasNext()) { ConnectionRecord next = it.next(); if (next.uid == this.val$uid) { if (TextUtils.isEmpty(this.val$pkg) || this.val$pid <= 0) { connectionRecord = new ConnectionRecord(next.pkg, next.pid, next.uid, this.val$rootHints, this.val$callbacks); } it.remove(); } } if (connectionRecord == null) { connectionRecord = new ConnectionRecord(this.val$pkg, this.val$pid, this.val$uid, this.val$rootHints, this.val$callbacks); } MediaBrowserServiceCompat.this.mConnections.put(asBinder, connectionRecord); try { asBinder.linkToDeath(connectionRecord, 0); } catch (RemoteException unused) { Log.w("MBServiceCompat", "IBinder is already dead."); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$7 reason: invalid class name */ public class AnonymousClass7 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public AnonymousClass7(ServiceCallbacks serviceCallbacks) { this.val$callbacks = serviceCallbacks; } @Override // java.lang.Runnable public void run() { IBinder asBinder = this.val$callbacks.asBinder(); ConnectionRecord remove = MediaBrowserServiceCompat.this.mConnections.remove(asBinder); if (remove != null) { asBinder.unlinkToDeath(remove, 0); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$8 reason: invalid class name */ public class AnonymousClass8 implements Runnable { public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ Bundle val$extras; public final /* synthetic */ String val$query; public final /* synthetic */ ResultReceiver val$receiver; public AnonymousClass8(ServiceCallbacks serviceCallbacks, String str, Bundle bundle, ResultReceiver resultReceiver) { this.val$callbacks = serviceCallbacks; this.val$query = str; this.val$extras = bundle; this.val$receiver = resultReceiver; } @Override // java.lang.Runnable public void run() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(this.val$callbacks.asBinder()); if (connectionRecord == null) { a.j0(a.L("search for callback that isn't registered query="), this.val$query, "MBServiceCompat"); } else { MediaBrowserServiceCompat.this.performSearch(this.val$query, this.val$extras, connectionRecord, this.val$receiver); } } } /* renamed from: androidx.media.MediaBrowserServiceCompat$ServiceBinderImpl$9 reason: invalid class name */ public class AnonymousClass9 implements Runnable { public final /* synthetic */ String val$action; public final /* synthetic */ ServiceCallbacks val$callbacks; public final /* synthetic */ Bundle val$extras; public final /* synthetic */ ResultReceiver val$receiver; public AnonymousClass9(ServiceCallbacks serviceCallbacks, String str, Bundle bundle, ResultReceiver resultReceiver) { this.val$callbacks = serviceCallbacks; this.val$action = str; this.val$extras = bundle; this.val$receiver = resultReceiver; } @Override // java.lang.Runnable public void run() { ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(this.val$callbacks.asBinder()); if (connectionRecord == null) { StringBuilder L = a.L("sendCustomAction for callback that isn't registered action="); L.append(this.val$action); L.append(", extras="); L.append(this.val$extras); Log.w("MBServiceCompat", L.toString()); return; } MediaBrowserServiceCompat.this.performCustomAction(this.val$action, this.val$extras, connectionRecord, this.val$receiver); } } public ServiceBinderImpl() { } public void addSubscription(String str, IBinder iBinder, Bundle bundle, ServiceCallbacks serviceCallbacks) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass3(serviceCallbacks, str, iBinder, bundle)); } public void connect(String str, int i, int i2, Bundle bundle, ServiceCallbacks serviceCallbacks) { if (MediaBrowserServiceCompat.this.isValidPackage(str, i2)) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass1(serviceCallbacks, str, i, i2, bundle)); return; } throw new IllegalArgumentException("Package/uid mismatch: uid=" + i2 + " package=" + str); } public void disconnect(ServiceCallbacks serviceCallbacks) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass2(serviceCallbacks)); } public void getMediaItem(String str, ResultReceiver resultReceiver, ServiceCallbacks serviceCallbacks) { if (!TextUtils.isEmpty(str) && resultReceiver != null) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass5(serviceCallbacks, str, resultReceiver)); } } public void registerCallbacks(ServiceCallbacks serviceCallbacks, String str, int i, int i2, Bundle bundle) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass6(serviceCallbacks, i2, str, i, bundle)); } public void removeSubscription(String str, IBinder iBinder, ServiceCallbacks serviceCallbacks) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass4(serviceCallbacks, str, iBinder)); } public void search(String str, Bundle bundle, ResultReceiver resultReceiver, ServiceCallbacks serviceCallbacks) { if (!TextUtils.isEmpty(str) && resultReceiver != null) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass8(serviceCallbacks, str, bundle, resultReceiver)); } } public void sendCustomAction(String str, Bundle bundle, ResultReceiver resultReceiver, ServiceCallbacks serviceCallbacks) { if (!TextUtils.isEmpty(str) && resultReceiver != null) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass9(serviceCallbacks, str, bundle, resultReceiver)); } } public void unregisterCallbacks(ServiceCallbacks serviceCallbacks) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new AnonymousClass7(serviceCallbacks)); } } public interface ServiceCallbacks { IBinder asBinder(); void onConnect(String str, MediaSessionCompat.Token token, Bundle bundle) throws RemoteException; void onConnectFailed() throws RemoteException; void onLoadChildren(String str, List list, Bundle bundle, Bundle bundle2) throws RemoteException; } public static class ServiceCallbacksCompat implements ServiceCallbacks { public final Messenger mCallbacks; public ServiceCallbacksCompat(Messenger messenger) { this.mCallbacks = messenger; } private void sendRequest(int i, Bundle bundle) throws RemoteException { Message obtain = Message.obtain(); obtain.what = i; obtain.arg1 = 2; obtain.setData(bundle); this.mCallbacks.send(obtain); } @Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks public IBinder asBinder() { return this.mCallbacks.getBinder(); } @Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks public void onConnect(String str, MediaSessionCompat.Token token, Bundle bundle) throws RemoteException { if (bundle == null) { bundle = new Bundle(); } bundle.putInt("extra_service_version", 2); Bundle bundle2 = new Bundle(); bundle2.putString("data_media_item_id", str); bundle2.putParcelable("data_media_session_token", token); bundle2.putBundle("data_root_hints", bundle); sendRequest(1, bundle2); } @Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks public void onConnectFailed() throws RemoteException { sendRequest(2, null); } @Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks public void onLoadChildren(String str, List list, Bundle bundle, Bundle bundle2) throws RemoteException { Bundle bundle3 = new Bundle(); bundle3.putString("data_media_item_id", str); bundle3.putBundle("data_options", bundle); bundle3.putBundle("data_notify_children_changed_options", bundle2); if (list != null) { bundle3.putParcelableArrayList("data_media_item_list", list instanceof ArrayList ? (ArrayList) list : new ArrayList<>(list)); } sendRequest(3, bundle3); } } public final class ServiceHandler extends Handler { private final ServiceBinderImpl mServiceBinderImpl; public ServiceHandler() { this.mServiceBinderImpl = new ServiceBinderImpl(); } @Override // android.os.Handler public void handleMessage(Message message) { Bundle data = message.getData(); switch (message.what) { case 1: Bundle bundle = data.getBundle("data_root_hints"); MediaSessionCompat.a(bundle); this.mServiceBinderImpl.connect(data.getString("data_package_name"), data.getInt("data_calling_pid"), data.getInt("data_calling_uid"), bundle, new ServiceCallbacksCompat(message.replyTo)); return; case 2: this.mServiceBinderImpl.disconnect(new ServiceCallbacksCompat(message.replyTo)); return; case 3: Bundle bundle2 = data.getBundle("data_options"); MediaSessionCompat.a(bundle2); this.mServiceBinderImpl.addSubscription(data.getString("data_media_item_id"), BundleCompat.getBinder(data, "data_callback_token"), bundle2, new ServiceCallbacksCompat(message.replyTo)); return; case 4: this.mServiceBinderImpl.removeSubscription(data.getString("data_media_item_id"), BundleCompat.getBinder(data, "data_callback_token"), new ServiceCallbacksCompat(message.replyTo)); return; case 5: this.mServiceBinderImpl.getMediaItem(data.getString("data_media_item_id"), (ResultReceiver) data.getParcelable("data_result_receiver"), new ServiceCallbacksCompat(message.replyTo)); return; case 6: Bundle bundle3 = data.getBundle("data_root_hints"); MediaSessionCompat.a(bundle3); this.mServiceBinderImpl.registerCallbacks(new ServiceCallbacksCompat(message.replyTo), data.getString("data_package_name"), data.getInt("data_calling_pid"), data.getInt("data_calling_uid"), bundle3); return; case 7: this.mServiceBinderImpl.unregisterCallbacks(new ServiceCallbacksCompat(message.replyTo)); return; case 8: Bundle bundle4 = data.getBundle("data_search_extras"); MediaSessionCompat.a(bundle4); this.mServiceBinderImpl.search(data.getString("data_search_query"), bundle4, (ResultReceiver) data.getParcelable("data_result_receiver"), new ServiceCallbacksCompat(message.replyTo)); return; case 9: Bundle bundle5 = data.getBundle("data_custom_action_extras"); MediaSessionCompat.a(bundle5); this.mServiceBinderImpl.sendCustomAction(data.getString("data_custom_action"), bundle5, (ResultReceiver) data.getParcelable("data_result_receiver"), new ServiceCallbacksCompat(message.replyTo)); return; default: Log.w("MBServiceCompat", "Unhandled message: " + message + "\n Service version: 2\n Client version: " + message.arg1); return; } } public void postOrRun(Runnable runnable) { if (Thread.currentThread() == getLooper().getThread()) { runnable.run(); } else { post(runnable); } } @Override // android.os.Handler public boolean sendMessageAtTime(Message message, long j) { Bundle data = message.getData(); data.setClassLoader(MediaBrowserCompat.class.getClassLoader()); data.putInt("data_calling_uid", Binder.getCallingUid()); int callingPid = Binder.getCallingPid(); if (callingPid > 0) { data.putInt("data_calling_pid", callingPid); } else if (!data.containsKey("data_calling_pid")) { data.putInt("data_calling_pid", -1); } return super.sendMessageAtTime(message, j); } } public void addSubscription(String str, ConnectionRecord connectionRecord, IBinder iBinder, Bundle bundle) { List> list = connectionRecord.subscriptions.get(str); if (list == null) { list = new ArrayList<>(); } for (Pair pair : list) { if (iBinder == pair.first && MediaBrowserCompatUtils.areSameOptions(bundle, pair.second)) { return; } } list.add(new Pair<>(iBinder, bundle)); connectionRecord.subscriptions.put(str, list); performLoadChildren(str, connectionRecord, bundle, null); this.mCurConnection = connectionRecord; onSubscribe(str, bundle); this.mCurConnection = null; } public List applyOptions(List list, Bundle bundle) { if (list == null) { return null; } int i = bundle.getInt("android.media.browse.extra.PAGE", -1); int i2 = bundle.getInt("android.media.browse.extra.PAGE_SIZE", -1); if (i == -1 && i2 == -1) { return list; } int i3 = i2 * i; int i4 = i3 + i2; if (i < 0 || i2 < 1 || i3 >= list.size()) { return Collections.emptyList(); } if (i4 > list.size()) { i4 = list.size(); } return list.subList(i3, i4); } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void attachToBaseContext(Context context) { attachBaseContext(context); } @Override // android.app.Service public void dump(FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { } public final Bundle getBrowserRootHints() { return this.mImpl.getBrowserRootHints(); } @NonNull public final MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() { return this.mImpl.getCurrentBrowserInfo(); } @Nullable public MediaSessionCompat.Token getSessionToken() { return this.mSession; } public boolean isValidPackage(String str, int i) { if (str == null) { return false; } for (String str2 : getPackageManager().getPackagesForUid(i)) { if (str2.equals(str)) { return true; } } return false; } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void notifyChildrenChanged(@NonNull MediaSessionManager.RemoteUserInfo remoteUserInfo, @NonNull String str, @NonNull Bundle bundle) { if (remoteUserInfo == null) { throw new IllegalArgumentException("remoteUserInfo cannot be null in notifyChildrenChanged"); } else if (str == null) { throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged"); } else if (bundle != null) { this.mImpl.notifyChildrenChanged(remoteUserInfo, str, bundle); } else { throw new IllegalArgumentException("options cannot be null in notifyChildrenChanged"); } } public void notifyChildrenChanged(@NonNull String str) { if (str != null) { this.mImpl.notifyChildrenChanged(str, null); return; } throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged"); } public void notifyChildrenChanged(@NonNull String str, @NonNull Bundle bundle) { if (str == null) { throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged"); } else if (bundle != null) { this.mImpl.notifyChildrenChanged(str, bundle); } else { throw new IllegalArgumentException("options cannot be null in notifyChildrenChanged"); } } @Override // android.app.Service public IBinder onBind(Intent intent) { return this.mImpl.onBind(intent); } @Override // android.app.Service public void onCreate() { super.onCreate(); int i = Build.VERSION.SDK_INT; if (i >= 28) { this.mImpl = new MediaBrowserServiceImplApi28(); } else if (i >= 26) { this.mImpl = new MediaBrowserServiceImplApi26(); } else if (i >= 23) { this.mImpl = new MediaBrowserServiceImplApi23(); } else { this.mImpl = new MediaBrowserServiceImplApi21(); } this.mImpl.onCreate(); } public void onCustomAction(@NonNull String str, Bundle bundle, @NonNull Result result) { result.sendError(null); } @Nullable public abstract BrowserRoot onGetRoot(@NonNull String str, int i, @Nullable Bundle bundle); public abstract void onLoadChildren(@NonNull String str, @NonNull Result> result); public void onLoadChildren(@NonNull String str, @NonNull Result> result, @NonNull Bundle bundle) { result.setFlags(1); onLoadChildren(str, result); } public void onLoadItem(String str, @NonNull Result result) { result.setFlags(2); result.sendResult(null); } public void onSearch(@NonNull String str, Bundle bundle, @NonNull Result> result) { result.setFlags(4); result.sendResult(null); } @RestrictTo({RestrictTo.Scope.LIBRARY}) public void onSubscribe(String str, Bundle bundle) { } @RestrictTo({RestrictTo.Scope.LIBRARY}) public void onUnsubscribe(String str) { } public void performCustomAction(String str, Bundle bundle, ConnectionRecord connectionRecord, ResultReceiver resultReceiver) { AnonymousClass4 r0 = new AnonymousClass4(str, resultReceiver); this.mCurConnection = connectionRecord; onCustomAction(str, bundle, r0); this.mCurConnection = null; if (!r0.isDone()) { throw new IllegalStateException("onCustomAction must call detach() or sendResult() or sendError() before returning for action=" + str + " extras=" + bundle); } } public void performLoadChildren(String str, ConnectionRecord connectionRecord, Bundle bundle, Bundle bundle2) { AnonymousClass1 r7 = new AnonymousClass1(str, connectionRecord, str, bundle, bundle2); this.mCurConnection = connectionRecord; if (bundle == null) { onLoadChildren(str, r7); } else { onLoadChildren(str, r7, bundle); } this.mCurConnection = null; if (!r7.isDone()) { StringBuilder L = a.L("onLoadChildren must call detach() or sendResult() before returning for package="); L.append(connectionRecord.pkg); L.append(" id="); L.append(str); throw new IllegalStateException(L.toString()); } } public void performLoadItem(String str, ConnectionRecord connectionRecord, ResultReceiver resultReceiver) { AnonymousClass2 r0 = new AnonymousClass2(str, resultReceiver); this.mCurConnection = connectionRecord; onLoadItem(str, r0); this.mCurConnection = null; if (!r0.isDone()) { throw new IllegalStateException(a.t("onLoadItem must call detach() or sendResult() before returning for id=", str)); } } public void performSearch(String str, Bundle bundle, ConnectionRecord connectionRecord, ResultReceiver resultReceiver) { AnonymousClass3 r0 = new AnonymousClass3(str, resultReceiver); this.mCurConnection = connectionRecord; onSearch(str, bundle, r0); this.mCurConnection = null; if (!r0.isDone()) { throw new IllegalStateException(a.t("onSearch must call detach() or sendResult() before returning for query=", str)); } } public boolean removeSubscription(String str, ConnectionRecord connectionRecord, IBinder iBinder) { boolean z2 = true; boolean z3 = false; ConnectionRecord connectionRecord2 = null; if (iBinder == null) { try { if (connectionRecord.subscriptions.remove(str) == null) { z2 = false; } return z2; } finally { this.mCurConnection = connectionRecord; onUnsubscribe(str); this.mCurConnection = connectionRecord2; } } else { List> list = connectionRecord.subscriptions.get(str); if (list != null) { Iterator> it = list.iterator(); while (it.hasNext()) { if (iBinder == it.next().first) { it.remove(); z3 = true; } } if (list.size() == 0) { connectionRecord.subscriptions.remove(str); } } this.mCurConnection = connectionRecord; onUnsubscribe(str); this.mCurConnection = null; return z3; } } public void setSessionToken(MediaSessionCompat.Token token) { if (token == null) { throw new IllegalArgumentException("Session token may not be null"); } else if (this.mSession == null) { this.mSession = token; this.mImpl.setSessionToken(token); } else { throw new IllegalStateException("The session token has already been set"); } } }