Files
rr3-apk/decompiled-community/sources/androidx/media/MediaBrowserServiceCompat.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

1366 lines
65 KiB
Java

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.media.session.MediaSessionManager;
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.IMediaSession;
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 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;
/* loaded from: classes.dex */
public abstract class MediaBrowserServiceCompat extends Service {
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;
static final int RESULT_FLAG_ON_LOAD_ITEM_NOT_IMPLEMENTED = 2;
static final int RESULT_FLAG_ON_SEARCH_NOT_IMPLEMENTED = 4;
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";
ConnectionRecord mCurConnection;
private MediaBrowserServiceImpl mImpl;
MediaSessionCompat.Token mSession;
static final String TAG = "MBServiceCompat";
static final boolean DEBUG = Log.isLoggable(TAG, 3);
final ConnectionRecord mConnectionFromFwk = new ConnectionRecord(MediaSessionManager.RemoteUserInfo.LEGACY_CONTROLLER, -1, -1, null, null);
final ArrayList<ConnectionRecord> mPendingConnections = new ArrayList<>();
final ArrayMap<IBinder, ConnectionRecord> mConnections = new ArrayMap<>();
final ServiceHandler mHandler = new ServiceHandler();
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);
}
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<MediaBrowserCompat.MediaItem> list, Bundle bundle, Bundle bundle2) throws RemoteException;
}
@Override // android.app.Service
public void dump(FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
}
@Nullable
public MediaSessionCompat.Token getSessionToken() {
return this.mSession;
}
@Nullable
public abstract BrowserRoot onGetRoot(@NonNull String str, int i, @Nullable Bundle bundle);
public abstract void onLoadChildren(@NonNull String str, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result);
@RestrictTo({RestrictTo.Scope.LIBRARY})
public void onSubscribe(String str, Bundle bundle) {
}
@RestrictTo({RestrictTo.Scope.LIBRARY})
public void onUnsubscribe(String str) {
}
public class MediaBrowserServiceImplBase implements MediaBrowserServiceImpl {
private Messenger mMessenger;
public MediaBrowserServiceImplBase() {
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void onCreate() {
this.mMessenger = new Messenger(MediaBrowserServiceCompat.this.mHandler);
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public IBinder onBind(Intent intent) {
if (MediaBrowserServiceCompat.SERVICE_INTERFACE.equals(intent.getAction())) {
return this.mMessenger.getBinder();
}
return null;
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void setSessionToken(final MediaSessionCompat.Token token) {
MediaBrowserServiceCompat.this.mHandler.post(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplBase.1
@Override // java.lang.Runnable
public void run() {
Iterator<ConnectionRecord> it = MediaBrowserServiceCompat.this.mConnections.values().iterator();
while (it.hasNext()) {
ConnectionRecord next = it.next();
try {
next.callbacks.onConnect(next.root.getRootId(), token, next.root.getExtras());
} catch (RemoteException unused) {
Log.w(MediaBrowserServiceCompat.TAG, "Connection for " + next.pkg + " is no longer valid.");
it.remove();
}
}
}
});
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void notifyChildrenChanged(@NonNull final String str, final Bundle bundle) {
MediaBrowserServiceCompat.this.mHandler.post(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplBase.2
@Override // java.lang.Runnable
public void run() {
Iterator<IBinder> it = MediaBrowserServiceCompat.this.mConnections.keySet().iterator();
while (it.hasNext()) {
MediaBrowserServiceImplBase.this.notifyChildrenChangedOnHandler(MediaBrowserServiceCompat.this.mConnections.get(it.next()), str, bundle);
}
}
});
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void notifyChildrenChanged(@NonNull final MediaSessionManager.RemoteUserInfo remoteUserInfo, @NonNull final String str, final Bundle bundle) {
MediaBrowserServiceCompat.this.mHandler.post(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplBase.3
@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(remoteUserInfo)) {
MediaBrowserServiceImplBase.this.notifyChildrenChangedOnHandler(valueAt, str, bundle);
return;
}
}
}
});
}
public void notifyChildrenChangedOnHandler(ConnectionRecord connectionRecord, String str, Bundle bundle) {
List<Pair<IBinder, Bundle>> list = connectionRecord.subscriptions.get(str);
if (list != null) {
for (Pair<IBinder, Bundle> pair : list) {
if (MediaBrowserCompatUtils.hasDuplicatedItems(bundle, pair.second)) {
MediaBrowserServiceCompat.this.performLoadChildren(str, connectionRecord, pair.second, bundle);
}
}
}
}
@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");
}
if (connectionRecord.rootHints == null) {
return null;
}
return new Bundle(MediaBrowserServiceCompat.this.mCurConnection.rootHints);
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mCurConnection;
if (connectionRecord == null) {
throw new IllegalStateException("This should be called inside of onLoadChildren, onLoadItem, onSearch, or onCustomAction methods");
}
return connectionRecord.browserInfo;
}
}
@RequiresApi(21)
public class MediaBrowserServiceImplApi21 implements MediaBrowserServiceImpl {
Messenger mMessenger;
final List<Bundle> mRootExtrasList = new ArrayList();
MediaBrowserService mServiceFwk;
public MediaBrowserServiceImplApi21() {
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void onCreate() {
MediaBrowserServiceApi21 mediaBrowserServiceApi21 = new MediaBrowserServiceApi21(MediaBrowserServiceCompat.this);
this.mServiceFwk = mediaBrowserServiceApi21;
mediaBrowserServiceApi21.onCreate();
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public IBinder onBind(Intent intent) {
return this.mServiceFwk.onBind(intent);
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void setSessionToken(final MediaSessionCompat.Token token) {
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21.1
@Override // java.lang.Runnable
public void run() {
if (!MediaBrowserServiceImplApi21.this.mRootExtrasList.isEmpty()) {
IMediaSession extraBinder = token.getExtraBinder();
if (extraBinder != null) {
Iterator<Bundle> it = MediaBrowserServiceImplApi21.this.mRootExtrasList.iterator();
while (it.hasNext()) {
BundleCompat.putBinder(it.next(), MediaBrowserProtocol.EXTRA_SESSION_BINDER, extraBinder.asBinder());
}
}
MediaBrowserServiceImplApi21.this.mRootExtrasList.clear();
}
MediaBrowserServiceImplApi21.this.mServiceFwk.setSessionToken((MediaSession.Token) token.getToken());
}
});
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void notifyChildrenChanged(String str, Bundle bundle) {
notifyChildrenChangedForFramework(str, bundle);
notifyChildrenChangedForCompat(str, bundle);
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public void notifyChildrenChanged(MediaSessionManager.RemoteUserInfo remoteUserInfo, String str, Bundle bundle) {
notifyChildrenChangedForCompat(remoteUserInfo, str, bundle);
}
public BrowserRoot onGetRoot(String str, int i, Bundle bundle) {
Bundle bundle2;
int i2 = -1;
if (bundle == null || bundle.getInt(MediaBrowserProtocol.EXTRA_CLIENT_VERSION, 0) == 0) {
bundle2 = null;
} else {
bundle.remove(MediaBrowserProtocol.EXTRA_CLIENT_VERSION);
this.mMessenger = new Messenger(MediaBrowserServiceCompat.this.mHandler);
bundle2 = new Bundle();
bundle2.putInt(MediaBrowserProtocol.EXTRA_SERVICE_VERSION, 2);
BundleCompat.putBinder(bundle2, MediaBrowserProtocol.EXTRA_MESSENGER_BINDER, this.mMessenger.getBinder());
MediaSessionCompat.Token token = MediaBrowserServiceCompat.this.mSession;
if (token != null) {
IMediaSession extraBinder = token.getExtraBinder();
BundleCompat.putBinder(bundle2, MediaBrowserProtocol.EXTRA_SESSION_BINDER, extraBinder == null ? null : extraBinder.asBinder());
} else {
this.mRootExtrasList.add(bundle2);
}
i2 = bundle.getInt(MediaBrowserProtocol.EXTRA_CALLING_PID, -1);
bundle.remove(MediaBrowserProtocol.EXTRA_CALLING_PID);
}
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.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, final ResultWrapper<List<Parcel>> resultWrapper) {
Result<List<MediaBrowserCompat.MediaItem>> result = new Result<List<MediaBrowserCompat.MediaItem>>(str) { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21.2
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(List<MediaBrowserCompat.MediaItem> 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;
}
resultWrapper.sendResult(arrayList);
}
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void detach() {
resultWrapper.detach();
}
};
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk;
mediaBrowserServiceCompat.onLoadChildren(str, result);
MediaBrowserServiceCompat.this.mCurConnection = null;
}
public void notifyChildrenChangedForFramework(String str, Bundle bundle) {
this.mServiceFwk.notifyChildrenChanged(str);
}
public void notifyChildrenChangedForCompat(final String str, final Bundle bundle) {
MediaBrowserServiceCompat.this.mHandler.post(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21.3
@Override // java.lang.Runnable
public void run() {
Iterator<IBinder> it = MediaBrowserServiceCompat.this.mConnections.keySet().iterator();
while (it.hasNext()) {
MediaBrowserServiceImplApi21.this.notifyChildrenChangedForCompatOnHandler(MediaBrowserServiceCompat.this.mConnections.get(it.next()), str, bundle);
}
}
});
}
public void notifyChildrenChangedForCompat(final MediaSessionManager.RemoteUserInfo remoteUserInfo, final String str, final Bundle bundle) {
MediaBrowserServiceCompat.this.mHandler.post(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21.4
@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(remoteUserInfo)) {
MediaBrowserServiceImplApi21.this.notifyChildrenChangedForCompatOnHandler(valueAt, str, bundle);
}
}
}
});
}
public void notifyChildrenChangedForCompatOnHandler(ConnectionRecord connectionRecord, String str, Bundle bundle) {
List<Pair<IBinder, Bundle>> list = connectionRecord.subscriptions.get(str);
if (list != null) {
for (Pair<IBinder, Bundle> pair : list) {
if (MediaBrowserCompatUtils.hasDuplicatedItems(bundle, pair.second)) {
MediaBrowserServiceCompat.this.performLoadChildren(str, connectionRecord, pair.second, bundle);
}
}
}
}
@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");
}
if (connectionRecord.rootHints == null) {
return null;
}
return new Bundle(MediaBrowserServiceCompat.this.mCurConnection.rootHints);
}
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
public MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mCurConnection;
if (connectionRecord == null) {
throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods");
}
return connectionRecord.browserInfo;
}
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.ensureClassLoader(bundle);
BrowserRoot onGetRoot = MediaBrowserServiceImplApi21.this.onGetRoot(str, i, bundle == null ? null : new Bundle(bundle));
if (onGetRoot == null) {
return null;
}
return new MediaBrowserService.BrowserRoot(onGetRoot.mRootId, onGetRoot.mExtras);
}
@Override // android.service.media.MediaBrowserService
public void onLoadChildren(String str, MediaBrowserService.Result<List<MediaBrowser.MediaItem>> result) {
MediaBrowserServiceImplApi21.this.onLoadChildren(str, new ResultWrapper<>(result));
}
}
}
@RequiresApi(23)
public class MediaBrowserServiceImplApi23 extends MediaBrowserServiceImplApi21 {
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, final ResultWrapper<Parcel> resultWrapper) {
Result<MediaBrowserCompat.MediaItem> result = new Result<MediaBrowserCompat.MediaItem>(str) { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi23.1
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(MediaBrowserCompat.MediaItem mediaItem) {
if (mediaItem == null) {
resultWrapper.sendResult(null);
return;
}
Parcel obtain = Parcel.obtain();
mediaItem.writeToParcel(obtain, 0);
resultWrapper.sendResult(obtain);
}
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void detach() {
resultWrapper.detach();
}
};
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk;
mediaBrowserServiceCompat.onLoadItem(str, result);
MediaBrowserServiceCompat.this.mCurConnection = null;
}
public class MediaBrowserServiceApi23 extends MediaBrowserServiceImplApi21.MediaBrowserServiceApi21 {
public MediaBrowserServiceApi23(Context context) {
super(context);
}
@Override // android.service.media.MediaBrowserService
public void onLoadItem(String str, MediaBrowserService.Result<MediaBrowser.MediaItem> result) {
MediaBrowserServiceImplApi23.this.onLoadItem(str, new ResultWrapper<>(result));
}
}
}
@RequiresApi(26)
public class MediaBrowserServiceImplApi26 extends MediaBrowserServiceImplApi23 {
public MediaBrowserServiceImplApi26() {
super();
}
@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, final ResultWrapper<List<Parcel>> resultWrapper, final Bundle bundle) {
Result<List<MediaBrowserCompat.MediaItem>> result = new Result<List<MediaBrowserCompat.MediaItem>>(str) { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi26.1
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(List<MediaBrowserCompat.MediaItem> list) {
if (list == null) {
resultWrapper.sendResult(null);
return;
}
if ((getFlags() & 1) != 0) {
list = MediaBrowserServiceCompat.this.applyOptions(list, bundle);
}
ArrayList arrayList = new ArrayList();
for (MediaBrowserCompat.MediaItem mediaItem : list) {
Parcel obtain = Parcel.obtain();
mediaItem.writeToParcel(obtain, 0);
arrayList.add(obtain);
}
resultWrapper.sendResult(arrayList);
}
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void detach() {
resultWrapper.detach();
}
};
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk;
mediaBrowserServiceCompat.onLoadChildren(str, result, bundle);
MediaBrowserServiceCompat.this.mCurConnection = null;
}
@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");
}
if (connectionRecord == mediaBrowserServiceCompat.mConnectionFromFwk) {
return this.mServiceFwk.getBrowserRootHints();
}
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);
}
}
public class MediaBrowserServiceApi26 extends MediaBrowserServiceImplApi23.MediaBrowserServiceApi23 {
public MediaBrowserServiceApi26(Context context) {
super(context);
}
@Override // android.service.media.MediaBrowserService
public void onLoadChildren(String str, MediaBrowserService.Result<List<MediaBrowser.MediaItem>> result, Bundle bundle) {
MediaSessionCompat.ensureClassLoader(bundle);
MediaBrowserServiceImplApi26 mediaBrowserServiceImplApi26 = MediaBrowserServiceImplApi26.this;
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
mediaBrowserServiceCompat.mCurConnection = mediaBrowserServiceCompat.mConnectionFromFwk;
mediaBrowserServiceImplApi26.onLoadChildren(str, new ResultWrapper<>(result), 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() {
MediaSessionManager.RemoteUserInfo currentBrowserInfo;
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");
}
if (connectionRecord == mediaBrowserServiceCompat.mConnectionFromFwk) {
currentBrowserInfo = this.mServiceFwk.getCurrentBrowserInfo();
return new MediaSessionManager.RemoteUserInfo(currentBrowserInfo);
}
return connectionRecord.browserInfo;
}
}
public final class ServiceHandler extends Handler {
private final ServiceBinderImpl mServiceBinderImpl;
public ServiceHandler() {
this.mServiceBinderImpl = MediaBrowserServiceCompat.this.new ServiceBinderImpl();
}
@Override // android.os.Handler
public void handleMessage(Message message) {
Bundle data = message.getData();
switch (message.what) {
case 1:
Bundle bundle = data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS);
MediaSessionCompat.ensureClassLoader(bundle);
this.mServiceBinderImpl.connect(data.getString(MediaBrowserProtocol.DATA_PACKAGE_NAME), data.getInt(MediaBrowserProtocol.DATA_CALLING_PID), data.getInt(MediaBrowserProtocol.DATA_CALLING_UID), bundle, new ServiceCallbacksCompat(message.replyTo));
break;
case 2:
this.mServiceBinderImpl.disconnect(new ServiceCallbacksCompat(message.replyTo));
break;
case 3:
Bundle bundle2 = data.getBundle(MediaBrowserProtocol.DATA_OPTIONS);
MediaSessionCompat.ensureClassLoader(bundle2);
this.mServiceBinderImpl.addSubscription(data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), BundleCompat.getBinder(data, MediaBrowserProtocol.DATA_CALLBACK_TOKEN), bundle2, new ServiceCallbacksCompat(message.replyTo));
break;
case 4:
this.mServiceBinderImpl.removeSubscription(data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), BundleCompat.getBinder(data, MediaBrowserProtocol.DATA_CALLBACK_TOKEN), new ServiceCallbacksCompat(message.replyTo));
break;
case 5:
this.mServiceBinderImpl.getMediaItem(data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), (ResultReceiver) data.getParcelable(MediaBrowserProtocol.DATA_RESULT_RECEIVER), new ServiceCallbacksCompat(message.replyTo));
break;
case 6:
Bundle bundle3 = data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS);
MediaSessionCompat.ensureClassLoader(bundle3);
this.mServiceBinderImpl.registerCallbacks(new ServiceCallbacksCompat(message.replyTo), data.getString(MediaBrowserProtocol.DATA_PACKAGE_NAME), data.getInt(MediaBrowserProtocol.DATA_CALLING_PID), data.getInt(MediaBrowserProtocol.DATA_CALLING_UID), bundle3);
break;
case 7:
this.mServiceBinderImpl.unregisterCallbacks(new ServiceCallbacksCompat(message.replyTo));
break;
case 8:
Bundle bundle4 = data.getBundle(MediaBrowserProtocol.DATA_SEARCH_EXTRAS);
MediaSessionCompat.ensureClassLoader(bundle4);
this.mServiceBinderImpl.search(data.getString(MediaBrowserProtocol.DATA_SEARCH_QUERY), bundle4, (ResultReceiver) data.getParcelable(MediaBrowserProtocol.DATA_RESULT_RECEIVER), new ServiceCallbacksCompat(message.replyTo));
break;
case 9:
Bundle bundle5 = data.getBundle(MediaBrowserProtocol.DATA_CUSTOM_ACTION_EXTRAS);
MediaSessionCompat.ensureClassLoader(bundle5);
this.mServiceBinderImpl.sendCustomAction(data.getString(MediaBrowserProtocol.DATA_CUSTOM_ACTION), bundle5, (ResultReceiver) data.getParcelable(MediaBrowserProtocol.DATA_RESULT_RECEIVER), new ServiceCallbacksCompat(message.replyTo));
break;
default:
Log.w(MediaBrowserServiceCompat.TAG, "Unhandled message: " + message + "\n Service version: 2\n Client version: " + message.arg1);
break;
}
}
@Override // android.os.Handler
public boolean sendMessageAtTime(Message message, long j) {
Bundle data = message.getData();
data.setClassLoader(MediaBrowserCompat.class.getClassLoader());
data.putInt(MediaBrowserProtocol.DATA_CALLING_UID, Binder.getCallingUid());
int callingPid = Binder.getCallingPid();
if (callingPid > 0) {
data.putInt(MediaBrowserProtocol.DATA_CALLING_PID, callingPid);
} else if (!data.containsKey(MediaBrowserProtocol.DATA_CALLING_PID)) {
data.putInt(MediaBrowserProtocol.DATA_CALLING_PID, -1);
}
return super.sendMessageAtTime(message, j);
}
public void postOrRun(Runnable runnable) {
if (Thread.currentThread() == getLooper().getThread()) {
runnable.run();
} else {
post(runnable);
}
}
}
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<String, List<Pair<IBinder, Bundle>>> subscriptions = new HashMap<>();
public final int uid;
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 Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ConnectionRecord.1
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord = ConnectionRecord.this;
MediaBrowserServiceCompat.this.mConnections.remove(connectionRecord.callbacks.asBinder());
}
});
}
}
public static class Result<T> {
private final Object mDebug;
private boolean mDetachCalled;
private int mFlags;
private boolean mSendErrorCalled;
private boolean mSendResultCalled;
public int getFlags() {
return this.mFlags;
}
public boolean isDone() {
return this.mDetachCalled || this.mSendResultCalled || this.mSendErrorCalled;
}
public void onResultSent(T t) {
}
public void setFlags(int i) {
this.mFlags = i;
}
public Result(Object obj) {
this.mDebug = obj;
}
public void sendResult(T t) {
if (this.mSendResultCalled || this.mSendErrorCalled) {
throw new IllegalStateException("sendResult() called when either sendResult() or sendError() had already been called for: " + this.mDebug);
}
this.mSendResultCalled = true;
onResultSent(t);
}
public void sendProgressUpdate(Bundle bundle) {
if (this.mSendResultCalled || this.mSendErrorCalled) {
throw new IllegalStateException("sendProgressUpdate() called when either sendResult() or sendError() had already been called for: " + this.mDebug);
}
checkExtraFields(bundle);
onProgressUpdateSent(bundle);
}
public void sendError(Bundle bundle) {
if (this.mSendResultCalled || this.mSendErrorCalled) {
throw new IllegalStateException("sendError() called when either sendResult() or sendError() had already been called for: " + this.mDebug);
}
this.mSendErrorCalled = true;
onErrorSent(bundle);
}
public void detach() {
if (this.mDetachCalled) {
throw new IllegalStateException("detach() called when detach() had already been called for: " + this.mDebug);
}
if (this.mSendResultCalled) {
throw new IllegalStateException("detach() called when sendResult() had already been called for: " + this.mDebug);
}
if (!this.mSendErrorCalled) {
this.mDetachCalled = true;
return;
}
throw new IllegalStateException("detach() called when sendError() had already been called for: " + this.mDebug);
}
public void onProgressUpdateSent(Bundle bundle) {
throw new UnsupportedOperationException("It is not supported to send an interim update for " + this.mDebug);
}
public void onErrorSent(Bundle bundle) {
throw new UnsupportedOperationException("It is not supported to send an error for " + this.mDebug);
}
private void checkExtraFields(Bundle bundle) {
if (bundle != null && bundle.containsKey(MediaBrowserCompat.EXTRA_DOWNLOAD_PROGRESS)) {
float f = bundle.getFloat(MediaBrowserCompat.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 class ServiceBinderImpl {
public ServiceBinderImpl() {
}
public void connect(final String str, final int i, final int i2, final Bundle bundle, final ServiceCallbacks serviceCallbacks) {
if (!MediaBrowserServiceCompat.this.isValidPackage(str, i2)) {
throw new IllegalArgumentException("Package/uid mismatch: uid=" + i2 + " package=" + str);
}
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.1
@Override // java.lang.Runnable
public void run() {
IBinder asBinder = serviceCallbacks.asBinder();
MediaBrowserServiceCompat.this.mConnections.remove(asBinder);
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.new ConnectionRecord(str, i, i2, bundle, serviceCallbacks);
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
mediaBrowserServiceCompat.mCurConnection = connectionRecord;
BrowserRoot onGetRoot = mediaBrowserServiceCompat.onGetRoot(str, i2, bundle);
connectionRecord.root = onGetRoot;
MediaBrowserServiceCompat mediaBrowserServiceCompat2 = MediaBrowserServiceCompat.this;
mediaBrowserServiceCompat2.mCurConnection = null;
if (onGetRoot == null) {
StringBuilder sb = new StringBuilder();
sb.append("No root for client ");
sb.append(str);
sb.append(" from service ");
sb.append(getClass().getName());
try {
serviceCallbacks.onConnectFailed();
return;
} catch (RemoteException unused) {
Log.w(MediaBrowserServiceCompat.TAG, "Calling onConnectFailed() failed. Ignoring. pkg=" + str);
return;
}
}
try {
mediaBrowserServiceCompat2.mConnections.put(asBinder, connectionRecord);
asBinder.linkToDeath(connectionRecord, 0);
if (MediaBrowserServiceCompat.this.mSession != null) {
serviceCallbacks.onConnect(connectionRecord.root.getRootId(), MediaBrowserServiceCompat.this.mSession, connectionRecord.root.getExtras());
}
} catch (RemoteException unused2) {
Log.w(MediaBrowserServiceCompat.TAG, "Calling onConnect() failed. Dropping client. pkg=" + str);
MediaBrowserServiceCompat.this.mConnections.remove(asBinder);
}
}
});
}
public void disconnect(final ServiceCallbacks serviceCallbacks) {
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.2
@Override // java.lang.Runnable
public void run() {
ConnectionRecord remove = MediaBrowserServiceCompat.this.mConnections.remove(serviceCallbacks.asBinder());
if (remove != null) {
remove.callbacks.asBinder().unlinkToDeath(remove, 0);
}
}
});
}
public void addSubscription(final String str, final IBinder iBinder, final Bundle bundle, final ServiceCallbacks serviceCallbacks) {
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.3
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(serviceCallbacks.asBinder());
if (connectionRecord == null) {
Log.w(MediaBrowserServiceCompat.TAG, "addSubscription for callback that isn't registered id=" + str);
return;
}
MediaBrowserServiceCompat.this.addSubscription(str, connectionRecord, iBinder, bundle);
}
});
}
public void removeSubscription(final String str, final IBinder iBinder, final ServiceCallbacks serviceCallbacks) {
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.4
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(serviceCallbacks.asBinder());
if (connectionRecord == null) {
Log.w(MediaBrowserServiceCompat.TAG, "removeSubscription for callback that isn't registered id=" + str);
return;
}
if (MediaBrowserServiceCompat.this.removeSubscription(str, connectionRecord, iBinder)) {
return;
}
Log.w(MediaBrowserServiceCompat.TAG, "removeSubscription called for " + str + " which is not subscribed");
}
});
}
public void getMediaItem(final String str, final ResultReceiver resultReceiver, final ServiceCallbacks serviceCallbacks) {
if (TextUtils.isEmpty(str) || resultReceiver == null) {
return;
}
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.5
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(serviceCallbacks.asBinder());
if (connectionRecord == null) {
Log.w(MediaBrowserServiceCompat.TAG, "getMediaItem for callback that isn't registered id=" + str);
return;
}
MediaBrowserServiceCompat.this.performLoadItem(str, connectionRecord, resultReceiver);
}
});
}
public void registerCallbacks(final ServiceCallbacks serviceCallbacks, final String str, final int i, final int i2, final Bundle bundle) {
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.6
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord;
IBinder asBinder = serviceCallbacks.asBinder();
MediaBrowserServiceCompat.this.mConnections.remove(asBinder);
Iterator<ConnectionRecord> it = MediaBrowserServiceCompat.this.mPendingConnections.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
ConnectionRecord next = it.next();
if (next.uid == i2) {
connectionRecord = (TextUtils.isEmpty(str) || i <= 0) ? MediaBrowserServiceCompat.this.new ConnectionRecord(next.pkg, next.pid, next.uid, bundle, serviceCallbacks) : null;
it.remove();
}
}
if (connectionRecord == null) {
connectionRecord = MediaBrowserServiceCompat.this.new ConnectionRecord(str, i, i2, bundle, serviceCallbacks);
}
MediaBrowserServiceCompat.this.mConnections.put(asBinder, connectionRecord);
try {
asBinder.linkToDeath(connectionRecord, 0);
} catch (RemoteException unused) {
Log.w(MediaBrowserServiceCompat.TAG, "IBinder is already dead.");
}
}
});
}
public void unregisterCallbacks(final ServiceCallbacks serviceCallbacks) {
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.7
@Override // java.lang.Runnable
public void run() {
IBinder asBinder = serviceCallbacks.asBinder();
ConnectionRecord remove = MediaBrowserServiceCompat.this.mConnections.remove(asBinder);
if (remove != null) {
asBinder.unlinkToDeath(remove, 0);
}
}
});
}
public void search(final String str, final Bundle bundle, final ResultReceiver resultReceiver, final ServiceCallbacks serviceCallbacks) {
if (TextUtils.isEmpty(str) || resultReceiver == null) {
return;
}
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.8
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(serviceCallbacks.asBinder());
if (connectionRecord == null) {
Log.w(MediaBrowserServiceCompat.TAG, "search for callback that isn't registered query=" + str);
return;
}
MediaBrowserServiceCompat.this.performSearch(str, bundle, connectionRecord, resultReceiver);
}
});
}
public void sendCustomAction(final String str, final Bundle bundle, final ResultReceiver resultReceiver, final ServiceCallbacks serviceCallbacks) {
if (TextUtils.isEmpty(str) || resultReceiver == null) {
return;
}
MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.9
@Override // java.lang.Runnable
public void run() {
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.mConnections.get(serviceCallbacks.asBinder());
if (connectionRecord == null) {
Log.w(MediaBrowserServiceCompat.TAG, "sendCustomAction for callback that isn't registered action=" + str + ", extras=" + bundle);
return;
}
MediaBrowserServiceCompat.this.performCustomAction(str, bundle, connectionRecord, resultReceiver);
}
});
}
}
public static class ServiceCallbacksCompat implements ServiceCallbacks {
final Messenger mCallbacks;
public ServiceCallbacksCompat(Messenger messenger) {
this.mCallbacks = messenger;
}
@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(MediaBrowserProtocol.EXTRA_SERVICE_VERSION, 2);
Bundle bundle2 = new Bundle();
bundle2.putString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID, str);
bundle2.putParcelable(MediaBrowserProtocol.DATA_MEDIA_SESSION_TOKEN, token);
bundle2.putBundle(MediaBrowserProtocol.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<MediaBrowserCompat.MediaItem> list, Bundle bundle, Bundle bundle2) throws RemoteException {
Bundle bundle3 = new Bundle();
bundle3.putString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID, str);
bundle3.putBundle(MediaBrowserProtocol.DATA_OPTIONS, bundle);
bundle3.putBundle(MediaBrowserProtocol.DATA_NOTIFY_CHILDREN_CHANGED_OPTIONS, bundle2);
if (list != null) {
bundle3.putParcelableArrayList(MediaBrowserProtocol.DATA_MEDIA_ITEM_LIST, list instanceof ArrayList ? (ArrayList) list : new ArrayList<>(list));
}
sendRequest(3, bundle3);
}
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);
}
}
@RequiresApi(21)
public static class ResultWrapper<T> {
MediaBrowserService.Result mResultFwk;
public ResultWrapper(MediaBrowserService.Result result) {
this.mResultFwk = result;
}
/* JADX WARN: Multi-variable type inference failed */
public void sendResult(T t) {
if (t instanceof List) {
this.mResultFwk.sendResult(parcelListToItemList((List) t));
return;
}
if (t instanceof Parcel) {
Parcel parcel = (Parcel) t;
parcel.setDataPosition(0);
this.mResultFwk.sendResult(MediaBrowser.MediaItem.CREATOR.createFromParcel(parcel));
parcel.recycle();
return;
}
this.mResultFwk.sendResult(null);
}
public void detach() {
this.mResultFwk.detach();
}
public List<MediaBrowser.MediaItem> parcelListToItemList(List<Parcel> 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;
}
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public void attachToBaseContext(Context context) {
attachBaseContext(context);
}
@Override // android.app.Service
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= 28) {
this.mImpl = new MediaBrowserServiceImplApi28();
} else {
this.mImpl = new MediaBrowserServiceImplApi26();
}
this.mImpl.onCreate();
}
@Override // android.app.Service
public IBinder onBind(Intent intent) {
return this.mImpl.onBind(intent);
}
public void onLoadChildren(@NonNull String str, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result, @NonNull Bundle bundle) {
result.setFlags(1);
onLoadChildren(str, result);
}
public void onLoadItem(String str, @NonNull Result<MediaBrowserCompat.MediaItem> result) {
result.setFlags(2);
result.sendResult(null);
}
public void onSearch(@NonNull String str, Bundle bundle, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
result.setFlags(4);
result.sendResult(null);
}
public void onCustomAction(@NonNull String str, Bundle bundle, @NonNull Result<Bundle> result) {
result.sendError(null);
}
public void setSessionToken(MediaSessionCompat.Token token) {
if (token == null) {
throw new IllegalArgumentException("Session token may not be null");
}
if (this.mSession != null) {
throw new IllegalStateException("The session token has already been set");
}
this.mSession = token;
this.mImpl.setSessionToken(token);
}
public final Bundle getBrowserRootHints() {
return this.mImpl.getBrowserRootHints();
}
@NonNull
public final MediaSessionManager.RemoteUserInfo getCurrentBrowserInfo() {
return this.mImpl.getCurrentBrowserInfo();
}
public void notifyChildrenChanged(@NonNull String str) {
if (str == null) {
throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
}
this.mImpl.notifyChildrenChanged(str, null);
}
public void notifyChildrenChanged(@NonNull String str, @NonNull Bundle bundle) {
if (str == null) {
throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
}
if (bundle == null) {
throw new IllegalArgumentException("options cannot be null in notifyChildrenChanged");
}
this.mImpl.notifyChildrenChanged(str, bundle);
}
@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");
}
if (str == null) {
throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
}
if (bundle == null) {
throw new IllegalArgumentException("options cannot be null in notifyChildrenChanged");
}
this.mImpl.notifyChildrenChanged(remoteUserInfo, str, bundle);
}
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;
}
public void addSubscription(String str, ConnectionRecord connectionRecord, IBinder iBinder, Bundle bundle) {
List<Pair<IBinder, Bundle>> list = connectionRecord.subscriptions.get(str);
if (list == null) {
list = new ArrayList<>();
}
for (Pair<IBinder, Bundle> 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 boolean removeSubscription(String str, ConnectionRecord connectionRecord, IBinder iBinder) {
boolean z = false;
try {
if (iBinder == null) {
if (connectionRecord.subscriptions.remove(str) != null) {
z = true;
}
} else {
List<Pair<IBinder, Bundle>> list = connectionRecord.subscriptions.get(str);
if (list != null) {
Iterator<Pair<IBinder, Bundle>> it = list.iterator();
while (it.hasNext()) {
if (iBinder == it.next().first) {
it.remove();
z = true;
}
}
if (list.size() == 0) {
connectionRecord.subscriptions.remove(str);
}
}
}
return z;
} finally {
this.mCurConnection = connectionRecord;
onUnsubscribe(str);
this.mCurConnection = null;
}
}
public void performLoadChildren(final String str, final ConnectionRecord connectionRecord, final Bundle bundle, final Bundle bundle2) {
Result<List<MediaBrowserCompat.MediaItem>> result = new Result<List<MediaBrowserCompat.MediaItem>>(str) { // from class: androidx.media.MediaBrowserServiceCompat.1
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(List<MediaBrowserCompat.MediaItem> list) {
if (MediaBrowserServiceCompat.this.mConnections.get(connectionRecord.callbacks.asBinder()) != connectionRecord) {
if (MediaBrowserServiceCompat.DEBUG) {
StringBuilder sb = new StringBuilder();
sb.append("Not sending onLoadChildren result for connection that has been disconnected. pkg=");
sb.append(connectionRecord.pkg);
sb.append(" id=");
sb.append(str);
return;
}
return;
}
if ((getFlags() & 1) != 0) {
list = MediaBrowserServiceCompat.this.applyOptions(list, bundle);
}
try {
connectionRecord.callbacks.onLoadChildren(str, list, bundle, bundle2);
} catch (RemoteException unused) {
Log.w(MediaBrowserServiceCompat.TAG, "Calling onLoadChildren() failed for id=" + str + " package=" + connectionRecord.pkg);
}
}
};
this.mCurConnection = connectionRecord;
if (bundle == null) {
onLoadChildren(str, result);
} else {
onLoadChildren(str, result, bundle);
}
this.mCurConnection = null;
if (result.isDone()) {
return;
}
throw new IllegalStateException("onLoadChildren must call detach() or sendResult() before returning for package=" + connectionRecord.pkg + " id=" + str);
}
public List<MediaBrowserCompat.MediaItem> applyOptions(List<MediaBrowserCompat.MediaItem> list, Bundle bundle) {
if (list == null) {
return null;
}
int i = bundle.getInt(MediaBrowserCompat.EXTRA_PAGE, -1);
int i2 = bundle.getInt(MediaBrowserCompat.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);
}
public void performLoadItem(String str, ConnectionRecord connectionRecord, final ResultReceiver resultReceiver) {
Result<MediaBrowserCompat.MediaItem> result = new Result<MediaBrowserCompat.MediaItem>(str) { // from class: androidx.media.MediaBrowserServiceCompat.2
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(MediaBrowserCompat.MediaItem mediaItem) {
if ((getFlags() & 2) != 0) {
resultReceiver.send(-1, null);
return;
}
Bundle bundle = new Bundle();
bundle.putParcelable(MediaBrowserServiceCompat.KEY_MEDIA_ITEM, mediaItem);
resultReceiver.send(0, bundle);
}
};
this.mCurConnection = connectionRecord;
onLoadItem(str, result);
this.mCurConnection = null;
if (result.isDone()) {
return;
}
throw new IllegalStateException("onLoadItem must call detach() or sendResult() before returning for id=" + str);
}
public void performSearch(String str, Bundle bundle, ConnectionRecord connectionRecord, final ResultReceiver resultReceiver) {
Result<List<MediaBrowserCompat.MediaItem>> result = new Result<List<MediaBrowserCompat.MediaItem>>(str) { // from class: androidx.media.MediaBrowserServiceCompat.3
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(List<MediaBrowserCompat.MediaItem> list) {
if ((getFlags() & 4) != 0 || list == null) {
resultReceiver.send(-1, null);
return;
}
Bundle bundle2 = new Bundle();
bundle2.putParcelableArray(MediaBrowserServiceCompat.KEY_SEARCH_RESULTS, (Parcelable[]) list.toArray(new MediaBrowserCompat.MediaItem[0]));
resultReceiver.send(0, bundle2);
}
};
this.mCurConnection = connectionRecord;
onSearch(str, bundle, result);
this.mCurConnection = null;
if (result.isDone()) {
return;
}
throw new IllegalStateException("onSearch must call detach() or sendResult() before returning for query=" + str);
}
public void performCustomAction(String str, Bundle bundle, ConnectionRecord connectionRecord, final ResultReceiver resultReceiver) {
Result<Bundle> result = new Result<Bundle>(str) { // from class: androidx.media.MediaBrowserServiceCompat.4
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onResultSent(Bundle bundle2) {
resultReceiver.send(0, bundle2);
}
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onProgressUpdateSent(Bundle bundle2) {
resultReceiver.send(1, bundle2);
}
@Override // androidx.media.MediaBrowserServiceCompat.Result
public void onErrorSent(Bundle bundle2) {
resultReceiver.send(-1, bundle2);
}
};
this.mCurConnection = connectionRecord;
onCustomAction(str, bundle, result);
this.mCurConnection = null;
if (result.isDone()) {
return;
}
throw new IllegalStateException("onCustomAction must call detach() or sendResult() or sendError() before returning for action=" + str + " extras=" + 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 Bundle getExtras() {
return this.mExtras;
}
public String getRootId() {
return this.mRootId;
}
public BrowserRoot(@NonNull String str, @Nullable Bundle bundle) {
if (str == null) {
throw new IllegalArgumentException("The root id in BrowserRoot cannot be null. Use null for BrowserRoot instead");
}
this.mRootId = str;
this.mExtras = bundle;
}
}
}