884 lines
39 KiB
Java
884 lines
39 KiB
Java
package androidx.media;
|
|
|
|
import android.app.Service;
|
|
import android.content.Intent;
|
|
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.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.collection.ArrayMap;
|
|
import androidx.core.app.BundleCompat;
|
|
import androidx.core.util.ObjectsCompat;
|
|
import androidx.core.util.Pair;
|
|
import androidx.media.MediaBrowserServiceCompatApi21;
|
|
import androidx.media.MediaBrowserServiceCompatApi23;
|
|
import androidx.media.MediaBrowserServiceCompatApi26;
|
|
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 {
|
|
static final boolean f = Log.isLoggable("MBServiceCompat", 3);
|
|
private MediaBrowserServiceImpl a;
|
|
ConnectionRecord c;
|
|
MediaSessionCompat.Token e;
|
|
final ArrayMap<IBinder, ConnectionRecord> b = new ArrayMap<>();
|
|
final ServiceHandler d = new ServiceHandler();
|
|
|
|
public static final class BrowserRoot {
|
|
public Bundle a() {
|
|
throw null;
|
|
}
|
|
|
|
public String b() {
|
|
throw null;
|
|
}
|
|
}
|
|
|
|
private class ConnectionRecord implements IBinder.DeathRecipient {
|
|
public final String a;
|
|
public final ServiceCallbacks b;
|
|
public final HashMap<String, List<Pair<IBinder, Bundle>>> c = new HashMap<>();
|
|
public BrowserRoot d;
|
|
|
|
ConnectionRecord(final String str, final int i, final int i2, Bundle bundle, ServiceCallbacks serviceCallbacks) {
|
|
this.a = str;
|
|
new Object(str, i, i2) { // from class: androidx.media.MediaSessionManager$RemoteUserInfo
|
|
MediaSessionManager$RemoteUserInfoImpl a;
|
|
|
|
{
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
this.a = new MediaSessionManager$RemoteUserInfoImpl(str, i, i2) { // from class: androidx.media.MediaSessionManagerImplApi28$RemoteUserInfoImplApi28
|
|
final MediaSessionManager.RemoteUserInfo a;
|
|
|
|
{
|
|
this.a = new MediaSessionManager.RemoteUserInfo(str, i, i2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj instanceof MediaSessionManagerImplApi28$RemoteUserInfoImplApi28) {
|
|
return this.a.equals(((MediaSessionManagerImplApi28$RemoteUserInfoImplApi28) obj).a);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ObjectsCompat.a(this.a);
|
|
}
|
|
};
|
|
} else {
|
|
this.a = new MediaSessionManager$RemoteUserInfoImpl(str, i, i2) { // from class: androidx.media.MediaSessionManagerImplBase$RemoteUserInfoImplBase
|
|
private String a;
|
|
private int b;
|
|
private int c;
|
|
|
|
{
|
|
this.a = str;
|
|
this.b = i;
|
|
this.c = i2;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof MediaSessionManagerImplBase$RemoteUserInfoImplBase)) {
|
|
return false;
|
|
}
|
|
MediaSessionManagerImplBase$RemoteUserInfoImplBase mediaSessionManagerImplBase$RemoteUserInfoImplBase = (MediaSessionManagerImplBase$RemoteUserInfoImplBase) obj;
|
|
return TextUtils.equals(this.a, mediaSessionManagerImplBase$RemoteUserInfoImplBase.a) && this.b == mediaSessionManagerImplBase$RemoteUserInfoImplBase.b && this.c == mediaSessionManagerImplBase$RemoteUserInfoImplBase.c;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ObjectsCompat.a(this.a, Integer.valueOf(this.b), Integer.valueOf(this.c));
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj instanceof MediaSessionManager$RemoteUserInfo) {
|
|
return this.a.equals(((MediaSessionManager$RemoteUserInfo) obj).a);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.a.hashCode();
|
|
}
|
|
};
|
|
this.b = serviceCallbacks;
|
|
}
|
|
|
|
@Override // android.os.IBinder.DeathRecipient
|
|
public void binderDied() {
|
|
MediaBrowserServiceCompat.this.d.post(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ConnectionRecord.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord connectionRecord = ConnectionRecord.this;
|
|
MediaBrowserServiceCompat.this.b.remove(connectionRecord.b.asBinder());
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
interface MediaBrowserServiceImpl {
|
|
IBinder a(Intent intent);
|
|
|
|
void a();
|
|
}
|
|
|
|
class MediaBrowserServiceImplApi28 extends MediaBrowserServiceImplApi26 {
|
|
MediaBrowserServiceImplApi28(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
|
|
super();
|
|
}
|
|
}
|
|
|
|
class MediaBrowserServiceImplBase implements MediaBrowserServiceImpl {
|
|
private Messenger a;
|
|
|
|
MediaBrowserServiceImplBase() {
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
|
|
public void a() {
|
|
this.a = new Messenger(MediaBrowserServiceCompat.this.d);
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
|
|
public IBinder a(Intent intent) {
|
|
if ("android.media.browse.MediaBrowserService".equals(intent.getAction())) {
|
|
return this.a.getBinder();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static class Result<T> {
|
|
private final Object a;
|
|
private boolean b;
|
|
private boolean c;
|
|
private boolean d;
|
|
private int e;
|
|
|
|
Result(Object obj) {
|
|
this.a = obj;
|
|
}
|
|
|
|
void a(int i) {
|
|
this.e = i;
|
|
}
|
|
|
|
void a(T t) {
|
|
throw null;
|
|
}
|
|
|
|
public void b(T t) {
|
|
if (!this.c && !this.d) {
|
|
this.c = true;
|
|
a((Result<T>) t);
|
|
} else {
|
|
throw new IllegalStateException("sendResult() called when either sendResult() or sendError() had already been called for: " + this.a);
|
|
}
|
|
}
|
|
|
|
int a() {
|
|
return this.e;
|
|
}
|
|
|
|
void a(Bundle bundle) {
|
|
throw new UnsupportedOperationException("It is not supported to send an error for " + this.a);
|
|
}
|
|
|
|
public void b(Bundle bundle) {
|
|
if (!this.c && !this.d) {
|
|
this.d = true;
|
|
a(bundle);
|
|
} else {
|
|
throw new IllegalStateException("sendError() called when either sendResult() or sendError() had already been called for: " + this.a);
|
|
}
|
|
}
|
|
|
|
boolean b() {
|
|
return this.b || this.c || this.d;
|
|
}
|
|
}
|
|
|
|
private class ServiceBinderImpl {
|
|
ServiceBinderImpl() {
|
|
}
|
|
|
|
public void a(final String str, final int i, final int i2, final Bundle bundle, final ServiceCallbacks serviceCallbacks) {
|
|
if (MediaBrowserServiceCompat.this.a(str, i2)) {
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
IBinder asBinder = serviceCallbacks.asBinder();
|
|
MediaBrowserServiceCompat.this.b.remove(asBinder);
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.new ConnectionRecord(str, i, i2, bundle, serviceCallbacks);
|
|
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
|
|
mediaBrowserServiceCompat.c = connectionRecord;
|
|
connectionRecord.d = mediaBrowserServiceCompat.a(str, i2, bundle);
|
|
MediaBrowserServiceCompat mediaBrowserServiceCompat2 = MediaBrowserServiceCompat.this;
|
|
mediaBrowserServiceCompat2.c = null;
|
|
if (connectionRecord.d != null) {
|
|
try {
|
|
mediaBrowserServiceCompat2.b.put(asBinder, connectionRecord);
|
|
asBinder.linkToDeath(connectionRecord, 0);
|
|
if (MediaBrowserServiceCompat.this.e == null) {
|
|
return;
|
|
}
|
|
connectionRecord.d.b();
|
|
throw null;
|
|
} catch (RemoteException unused) {
|
|
Log.w("MBServiceCompat", "Calling onConnect() failed. Dropping client. pkg=" + str);
|
|
MediaBrowserServiceCompat.this.b.remove(asBinder);
|
|
return;
|
|
}
|
|
}
|
|
Log.i("MBServiceCompat", "No root for client " + str + " from service " + AnonymousClass1.class.getName());
|
|
try {
|
|
serviceCallbacks.a();
|
|
} catch (RemoteException unused2) {
|
|
Log.w("MBServiceCompat", "Calling onConnectFailed() failed. Ignoring. pkg=" + str);
|
|
}
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Package/uid mismatch: uid=" + i2 + " package=" + str);
|
|
}
|
|
|
|
public void b(final ServiceCallbacks serviceCallbacks) {
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.7
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
IBinder asBinder = serviceCallbacks.asBinder();
|
|
ConnectionRecord remove = MediaBrowserServiceCompat.this.b.remove(asBinder);
|
|
if (remove != null) {
|
|
asBinder.unlinkToDeath(remove, 0);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void b(final String str, final Bundle bundle, final ResultReceiver resultReceiver, final ServiceCallbacks serviceCallbacks) {
|
|
if (TextUtils.isEmpty(str) || resultReceiver == null) {
|
|
return;
|
|
}
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.9
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.b.get(serviceCallbacks.asBinder());
|
|
if (connectionRecord != null) {
|
|
MediaBrowserServiceCompat.this.a(str, bundle, connectionRecord, resultReceiver);
|
|
return;
|
|
}
|
|
Log.w("MBServiceCompat", "sendCustomAction for callback that isn't registered action=" + str + ", extras=" + bundle);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(final ServiceCallbacks serviceCallbacks) {
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord remove = MediaBrowserServiceCompat.this.b.remove(serviceCallbacks.asBinder());
|
|
if (remove != null) {
|
|
remove.b.asBinder().unlinkToDeath(remove, 0);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(final String str, final IBinder iBinder, final Bundle bundle, final ServiceCallbacks serviceCallbacks) {
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.b.get(serviceCallbacks.asBinder());
|
|
if (connectionRecord != null) {
|
|
MediaBrowserServiceCompat.this.a(str, connectionRecord, iBinder, bundle);
|
|
return;
|
|
}
|
|
Log.w("MBServiceCompat", "addSubscription for callback that isn't registered id=" + str);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(final String str, final IBinder iBinder, final ServiceCallbacks serviceCallbacks) {
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.4
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.b.get(serviceCallbacks.asBinder());
|
|
if (connectionRecord == null) {
|
|
Log.w("MBServiceCompat", "removeSubscription for callback that isn't registered id=" + str);
|
|
return;
|
|
}
|
|
if (MediaBrowserServiceCompat.this.a(str, connectionRecord, iBinder)) {
|
|
return;
|
|
}
|
|
Log.w("MBServiceCompat", "removeSubscription called for " + str + " which is not subscribed");
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(final String str, final ResultReceiver resultReceiver, final ServiceCallbacks serviceCallbacks) {
|
|
if (TextUtils.isEmpty(str) || resultReceiver == null) {
|
|
return;
|
|
}
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.5
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.b.get(serviceCallbacks.asBinder());
|
|
if (connectionRecord != null) {
|
|
MediaBrowserServiceCompat.this.a(str, connectionRecord, resultReceiver);
|
|
return;
|
|
}
|
|
Log.w("MBServiceCompat", "getMediaItem for callback that isn't registered id=" + str);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(final ServiceCallbacks serviceCallbacks, final String str, final int i, final int i2, final Bundle bundle) {
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.6
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
IBinder asBinder = serviceCallbacks.asBinder();
|
|
MediaBrowserServiceCompat.this.b.remove(asBinder);
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.new ConnectionRecord(str, i, i2, bundle, serviceCallbacks);
|
|
MediaBrowserServiceCompat.this.b.put(asBinder, connectionRecord);
|
|
try {
|
|
asBinder.linkToDeath(connectionRecord, 0);
|
|
} catch (RemoteException unused) {
|
|
Log.w("MBServiceCompat", "IBinder is already dead.");
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(final String str, final Bundle bundle, final ResultReceiver resultReceiver, final ServiceCallbacks serviceCallbacks) {
|
|
if (TextUtils.isEmpty(str) || resultReceiver == null) {
|
|
return;
|
|
}
|
|
MediaBrowserServiceCompat.this.d.a(new Runnable() { // from class: androidx.media.MediaBrowserServiceCompat.ServiceBinderImpl.8
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectionRecord connectionRecord = MediaBrowserServiceCompat.this.b.get(serviceCallbacks.asBinder());
|
|
if (connectionRecord != null) {
|
|
MediaBrowserServiceCompat.this.b(str, bundle, connectionRecord, resultReceiver);
|
|
return;
|
|
}
|
|
Log.w("MBServiceCompat", "search for callback that isn't registered query=" + str);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private interface ServiceCallbacks {
|
|
void a() throws RemoteException;
|
|
|
|
void a(String str, List<MediaBrowserCompat.MediaItem> list, Bundle bundle, Bundle bundle2) throws RemoteException;
|
|
|
|
IBinder asBinder();
|
|
}
|
|
|
|
private static class ServiceCallbacksCompat implements ServiceCallbacks {
|
|
final Messenger a;
|
|
|
|
ServiceCallbacksCompat(Messenger messenger) {
|
|
this.a = messenger;
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks
|
|
public void a() throws RemoteException {
|
|
a(2, null);
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks
|
|
public IBinder asBinder() {
|
|
return this.a.getBinder();
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.ServiceCallbacks
|
|
public void a(String str, List<MediaBrowserCompat.MediaItem> 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));
|
|
}
|
|
a(3, bundle3);
|
|
}
|
|
|
|
private void a(int i, Bundle bundle) throws RemoteException {
|
|
Message obtain = Message.obtain();
|
|
obtain.what = i;
|
|
obtain.arg1 = 2;
|
|
obtain.setData(bundle);
|
|
this.a.send(obtain);
|
|
}
|
|
}
|
|
|
|
private final class ServiceHandler extends Handler {
|
|
private final ServiceBinderImpl a;
|
|
|
|
ServiceHandler() {
|
|
this.a = MediaBrowserServiceCompat.this.new ServiceBinderImpl();
|
|
}
|
|
|
|
public void a(Runnable runnable) {
|
|
if (Thread.currentThread() == getLooper().getThread()) {
|
|
runnable.run();
|
|
} else {
|
|
post(runnable);
|
|
}
|
|
}
|
|
|
|
@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.a.a(data.getString("data_package_name"), data.getInt("data_calling_pid"), data.getInt("data_calling_uid"), bundle, new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 2:
|
|
this.a.a(new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 3:
|
|
Bundle bundle2 = data.getBundle("data_options");
|
|
MediaSessionCompat.a(bundle2);
|
|
this.a.a(data.getString("data_media_item_id"), BundleCompat.a(data, "data_callback_token"), bundle2, new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 4:
|
|
this.a.a(data.getString("data_media_item_id"), BundleCompat.a(data, "data_callback_token"), new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 5:
|
|
this.a.a(data.getString("data_media_item_id"), (ResultReceiver) data.getParcelable("data_result_receiver"), new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 6:
|
|
Bundle bundle3 = data.getBundle("data_root_hints");
|
|
MediaSessionCompat.a(bundle3);
|
|
this.a.a(new ServiceCallbacksCompat(message.replyTo), data.getString("data_package_name"), data.getInt("data_calling_pid"), data.getInt("data_calling_uid"), bundle3);
|
|
break;
|
|
case 7:
|
|
this.a.b(new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 8:
|
|
Bundle bundle4 = data.getBundle("data_search_extras");
|
|
MediaSessionCompat.a(bundle4);
|
|
this.a.a(data.getString("data_search_query"), bundle4, (ResultReceiver) data.getParcelable("data_result_receiver"), new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
case 9:
|
|
Bundle bundle5 = data.getBundle("data_custom_action_extras");
|
|
MediaSessionCompat.a(bundle5);
|
|
this.a.b(data.getString("data_custom_action"), bundle5, (ResultReceiver) data.getParcelable("data_result_receiver"), new ServiceCallbacksCompat(message.replyTo));
|
|
break;
|
|
default:
|
|
Log.w("MBServiceCompat", "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("data_calling_uid", Binder.getCallingUid());
|
|
data.putInt("data_calling_pid", Binder.getCallingPid());
|
|
return super.sendMessageAtTime(message, j);
|
|
}
|
|
}
|
|
|
|
public abstract BrowserRoot a(String str, int i, Bundle bundle);
|
|
|
|
public void a(String str) {
|
|
}
|
|
|
|
public void a(String str, Bundle bundle) {
|
|
}
|
|
|
|
public abstract void a(String str, Result<List<MediaBrowserCompat.MediaItem>> result);
|
|
|
|
public void a(String str, Result<List<MediaBrowserCompat.MediaItem>> result, Bundle bundle) {
|
|
result.a(1);
|
|
a(str, result);
|
|
}
|
|
|
|
public void b(String str, Result<MediaBrowserCompat.MediaItem> result) {
|
|
result.a(2);
|
|
result.b((Result<MediaBrowserCompat.MediaItem>) null);
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public void dump(FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public IBinder onBind(Intent intent) {
|
|
return this.a.a(intent);
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
int i = Build.VERSION.SDK_INT;
|
|
if (i >= 28) {
|
|
this.a = new MediaBrowserServiceImplApi28(this);
|
|
} else if (i >= 26) {
|
|
this.a = new MediaBrowserServiceImplApi26();
|
|
} else if (i >= 23) {
|
|
this.a = new MediaBrowserServiceImplApi23();
|
|
} else if (i >= 21) {
|
|
this.a = new MediaBrowserServiceImplApi21();
|
|
} else {
|
|
this.a = new MediaBrowserServiceImplBase();
|
|
}
|
|
this.a.a();
|
|
}
|
|
|
|
class MediaBrowserServiceImplApi21 implements MediaBrowserServiceImpl, MediaBrowserServiceCompatApi21.ServiceCompatProxy {
|
|
final List<Bundle> a = new ArrayList();
|
|
Object b;
|
|
Messenger c;
|
|
|
|
MediaBrowserServiceImplApi21() {
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
|
|
public void a() {
|
|
this.b = MediaBrowserServiceCompatApi21.a(MediaBrowserServiceCompat.this, this);
|
|
MediaBrowserServiceCompatApi21.a(this.b);
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompatApi21.ServiceCompatProxy
|
|
public void b(String str, final MediaBrowserServiceCompatApi21.ResultWrapper<List<Parcel>> resultWrapper) {
|
|
MediaBrowserServiceCompat.this.a(str, new Result<List<MediaBrowserCompat.MediaItem>>(this, str) { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21.2
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
public void a(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.a((MediaBrowserServiceCompatApi21.ResultWrapper) arrayList);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
|
|
public IBinder a(Intent intent) {
|
|
return MediaBrowserServiceCompatApi21.a(this.b, intent);
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompatApi21.ServiceCompatProxy
|
|
public MediaBrowserServiceCompatApi21.BrowserRoot a(String str, int i, Bundle bundle) {
|
|
Bundle bundle2;
|
|
if (bundle == null || bundle.getInt("extra_client_version", 0) == 0) {
|
|
bundle2 = null;
|
|
} else {
|
|
bundle.remove("extra_client_version");
|
|
this.c = new Messenger(MediaBrowserServiceCompat.this.d);
|
|
bundle2 = new Bundle();
|
|
bundle2.putInt("extra_service_version", 2);
|
|
BundleCompat.a(bundle2, "extra_messenger", this.c.getBinder());
|
|
MediaSessionCompat.Token token = MediaBrowserServiceCompat.this.e;
|
|
if (token != null) {
|
|
IMediaSession extraBinder = token.getExtraBinder();
|
|
BundleCompat.a(bundle2, "extra_session_binder", extraBinder == null ? null : extraBinder.asBinder());
|
|
} else {
|
|
this.a.add(bundle2);
|
|
}
|
|
}
|
|
MediaBrowserServiceCompat mediaBrowserServiceCompat = MediaBrowserServiceCompat.this;
|
|
mediaBrowserServiceCompat.c = mediaBrowserServiceCompat.new ConnectionRecord(str, -1, i, bundle, null);
|
|
BrowserRoot a = MediaBrowserServiceCompat.this.a(str, i, bundle);
|
|
MediaBrowserServiceCompat.this.c = null;
|
|
if (a == null) {
|
|
return null;
|
|
}
|
|
if (bundle2 == null) {
|
|
a.a();
|
|
throw null;
|
|
}
|
|
a.a();
|
|
throw null;
|
|
}
|
|
}
|
|
|
|
class MediaBrowserServiceImplApi23 extends MediaBrowserServiceImplApi21 implements MediaBrowserServiceCompatApi23.ServiceCompatProxy {
|
|
MediaBrowserServiceImplApi23() {
|
|
super();
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
|
|
public void a() {
|
|
this.b = MediaBrowserServiceCompatApi23.a(MediaBrowserServiceCompat.this, this);
|
|
MediaBrowserServiceCompatApi21.a(this.b);
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompatApi23.ServiceCompatProxy
|
|
public void a(String str, final MediaBrowserServiceCompatApi21.ResultWrapper<Parcel> resultWrapper) {
|
|
MediaBrowserServiceCompat.this.b(str, new Result<MediaBrowserCompat.MediaItem>(this, str) { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi23.1
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
public void a(MediaBrowserCompat.MediaItem mediaItem) {
|
|
if (mediaItem == null) {
|
|
resultWrapper.a((MediaBrowserServiceCompatApi21.ResultWrapper) null);
|
|
return;
|
|
}
|
|
Parcel obtain = Parcel.obtain();
|
|
mediaItem.writeToParcel(obtain, 0);
|
|
resultWrapper.a((MediaBrowserServiceCompatApi21.ResultWrapper) obtain);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
class MediaBrowserServiceImplApi26 extends MediaBrowserServiceImplApi23 implements MediaBrowserServiceCompatApi26.ServiceCompatProxy {
|
|
MediaBrowserServiceImplApi26() {
|
|
super();
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi23, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi21, androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImpl
|
|
public void a() {
|
|
this.b = MediaBrowserServiceCompatApi26.a(MediaBrowserServiceCompat.this, this);
|
|
MediaBrowserServiceCompatApi21.a(this.b);
|
|
}
|
|
|
|
@Override // androidx.media.MediaBrowserServiceCompatApi26.ServiceCompatProxy
|
|
public void a(String str, final MediaBrowserServiceCompatApi26.ResultWrapper resultWrapper, Bundle bundle) {
|
|
MediaBrowserServiceCompat.this.a(str, new Result<List<MediaBrowserCompat.MediaItem>>(this, str) { // from class: androidx.media.MediaBrowserServiceCompat.MediaBrowserServiceImplApi26.1
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
public void a(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.a(arrayList, a());
|
|
}
|
|
}, bundle);
|
|
}
|
|
}
|
|
|
|
public void a(String str, Bundle bundle, Result<Bundle> result) {
|
|
result.b((Bundle) null);
|
|
}
|
|
|
|
public void b(String str, Bundle bundle, Result<List<MediaBrowserCompat.MediaItem>> result) {
|
|
result.a(4);
|
|
result.b((Result<List<MediaBrowserCompat.MediaItem>>) null);
|
|
}
|
|
|
|
boolean a(String str, int i) {
|
|
if (str == null) {
|
|
return false;
|
|
}
|
|
for (String str2 : getPackageManager().getPackagesForUid(i)) {
|
|
if (str2.equals(str)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void b(String str, Bundle bundle, ConnectionRecord connectionRecord, final ResultReceiver resultReceiver) {
|
|
Result<List<MediaBrowserCompat.MediaItem>> result = new Result<List<MediaBrowserCompat.MediaItem>>(this, str) { // from class: androidx.media.MediaBrowserServiceCompat.3
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
public void a(List<MediaBrowserCompat.MediaItem> list) {
|
|
if ((a() & 4) != 0 || list == null) {
|
|
resultReceiver.send(-1, null);
|
|
return;
|
|
}
|
|
Bundle bundle2 = new Bundle();
|
|
bundle2.putParcelableArray("search_results", (Parcelable[]) list.toArray(new MediaBrowserCompat.MediaItem[0]));
|
|
resultReceiver.send(0, bundle2);
|
|
}
|
|
};
|
|
b(str, bundle, result);
|
|
if (result.b()) {
|
|
return;
|
|
}
|
|
throw new IllegalStateException("onSearch must call detach() or sendResult() before returning for query=" + str);
|
|
}
|
|
|
|
void a(String str, ConnectionRecord connectionRecord, IBinder iBinder, Bundle bundle) {
|
|
List<Pair<IBinder, Bundle>> list = connectionRecord.c.get(str);
|
|
if (list == null) {
|
|
list = new ArrayList<>();
|
|
}
|
|
for (Pair<IBinder, Bundle> pair : list) {
|
|
if (iBinder == pair.a && MediaBrowserCompatUtils.a(bundle, pair.b)) {
|
|
return;
|
|
}
|
|
}
|
|
list.add(new Pair<>(iBinder, bundle));
|
|
connectionRecord.c.put(str, list);
|
|
a(str, connectionRecord, bundle, (Bundle) null);
|
|
a(str, bundle);
|
|
}
|
|
|
|
boolean a(String str, ConnectionRecord connectionRecord, IBinder iBinder) {
|
|
boolean z = false;
|
|
try {
|
|
if (iBinder == null) {
|
|
return connectionRecord.c.remove(str) != null;
|
|
}
|
|
List<Pair<IBinder, Bundle>> list = connectionRecord.c.get(str);
|
|
if (list != null) {
|
|
Iterator<Pair<IBinder, Bundle>> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
if (iBinder == it.next().a) {
|
|
it.remove();
|
|
z = true;
|
|
}
|
|
}
|
|
if (list.size() == 0) {
|
|
connectionRecord.c.remove(str);
|
|
}
|
|
}
|
|
return z;
|
|
} finally {
|
|
a(str);
|
|
}
|
|
}
|
|
|
|
void a(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
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
public void a(List<MediaBrowserCompat.MediaItem> list) {
|
|
if (MediaBrowserServiceCompat.this.b.get(connectionRecord.b.asBinder()) != connectionRecord) {
|
|
if (MediaBrowserServiceCompat.f) {
|
|
Log.d("MBServiceCompat", "Not sending onLoadChildren result for connection that has been disconnected. pkg=" + connectionRecord.a + " id=" + str);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if ((a() & 1) != 0) {
|
|
list = MediaBrowserServiceCompat.this.a(list, bundle);
|
|
}
|
|
try {
|
|
connectionRecord.b.a(str, list, bundle, bundle2);
|
|
} catch (RemoteException unused) {
|
|
Log.w("MBServiceCompat", "Calling onLoadChildren() failed for id=" + str + " package=" + connectionRecord.a);
|
|
}
|
|
}
|
|
};
|
|
if (bundle == null) {
|
|
a(str, result);
|
|
} else {
|
|
a(str, result, bundle);
|
|
}
|
|
if (result.b()) {
|
|
return;
|
|
}
|
|
throw new IllegalStateException("onLoadChildren must call detach() or sendResult() before returning for package=" + connectionRecord.a + " id=" + str);
|
|
}
|
|
|
|
List<MediaBrowserCompat.MediaItem> a(List<MediaBrowserCompat.MediaItem> 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()) {
|
|
if (i4 > list.size()) {
|
|
i4 = list.size();
|
|
}
|
|
return list.subList(i3, i4);
|
|
}
|
|
return Collections.emptyList();
|
|
}
|
|
|
|
void a(String str, ConnectionRecord connectionRecord, final ResultReceiver resultReceiver) {
|
|
Result<MediaBrowserCompat.MediaItem> result = new Result<MediaBrowserCompat.MediaItem>(this, str) { // from class: androidx.media.MediaBrowserServiceCompat.2
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
public void a(MediaBrowserCompat.MediaItem mediaItem) {
|
|
if ((a() & 2) != 0) {
|
|
resultReceiver.send(-1, null);
|
|
return;
|
|
}
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("media_item", mediaItem);
|
|
resultReceiver.send(0, bundle);
|
|
}
|
|
};
|
|
b(str, result);
|
|
if (result.b()) {
|
|
return;
|
|
}
|
|
throw new IllegalStateException("onLoadItem must call detach() or sendResult() before returning for id=" + str);
|
|
}
|
|
|
|
void a(String str, Bundle bundle, ConnectionRecord connectionRecord, final ResultReceiver resultReceiver) {
|
|
Result<Bundle> result = new Result<Bundle>(this, str) { // from class: androidx.media.MediaBrowserServiceCompat.4
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
/* renamed from: c, reason: merged with bridge method [inline-methods] */
|
|
public void a(Bundle bundle2) {
|
|
resultReceiver.send(0, bundle2);
|
|
}
|
|
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // androidx.media.MediaBrowserServiceCompat.Result
|
|
void a(Bundle bundle2) {
|
|
resultReceiver.send(-1, bundle2);
|
|
}
|
|
};
|
|
a(str, bundle, result);
|
|
if (result.b()) {
|
|
return;
|
|
}
|
|
throw new IllegalStateException("onCustomAction must call detach() or sendResult() or sendError() before returning for action=" + str + " extras=" + bundle);
|
|
}
|
|
}
|