133 lines
4.6 KiB
Java
133 lines
4.6 KiB
Java
package androidx.media;
|
|
|
|
import android.content.Context;
|
|
import android.media.session.MediaSessionManager;
|
|
import android.os.Build;
|
|
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.media.MediaSessionManagerImplApi28;
|
|
import androidx.media.MediaSessionManagerImplBase;
|
|
import java.util.Objects;
|
|
/* loaded from: classes.dex */
|
|
public final class MediaSessionManager {
|
|
private static volatile MediaSessionManager sSessionManager;
|
|
public MediaSessionManagerImpl mImpl;
|
|
public static final String TAG = "MediaSessionManager";
|
|
public static final boolean DEBUG = Log.isLoggable(TAG, 3);
|
|
private static final Object sLock = new Object();
|
|
|
|
/* loaded from: classes.dex */
|
|
public interface MediaSessionManagerImpl {
|
|
Context getContext();
|
|
|
|
boolean isTrustedForMediaControl(RemoteUserInfoImpl remoteUserInfoImpl);
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class RemoteUserInfo {
|
|
public static final String LEGACY_CONTROLLER = "android.media.session.MediaController";
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static final int UNKNOWN_PID = -1;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static final int UNKNOWN_UID = -1;
|
|
public RemoteUserInfoImpl mImpl;
|
|
|
|
@RequiresApi(28)
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public RemoteUserInfo(MediaSessionManager.RemoteUserInfo remoteUserInfo) {
|
|
String packageName = MediaSessionManagerImplApi28.RemoteUserInfoImplApi28.getPackageName(remoteUserInfo);
|
|
Objects.requireNonNull(packageName, "package shouldn't be null");
|
|
if (!TextUtils.isEmpty(packageName)) {
|
|
this.mImpl = new MediaSessionManagerImplApi28.RemoteUserInfoImplApi28(remoteUserInfo);
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("packageName should be nonempty");
|
|
}
|
|
|
|
public RemoteUserInfo(@NonNull String str, int i, int i2) {
|
|
Objects.requireNonNull(str, "package shouldn't be null");
|
|
if (TextUtils.isEmpty(str)) {
|
|
throw new IllegalArgumentException("packageName should be nonempty");
|
|
} else if (Build.VERSION.SDK_INT >= 28) {
|
|
this.mImpl = new MediaSessionManagerImplApi28.RemoteUserInfoImplApi28(str, i, i2);
|
|
} else {
|
|
this.mImpl = new MediaSessionManagerImplBase.RemoteUserInfoImplBase(str, i, i2);
|
|
}
|
|
}
|
|
|
|
public boolean equals(@Nullable Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof RemoteUserInfo)) {
|
|
return false;
|
|
}
|
|
return this.mImpl.equals(((RemoteUserInfo) obj).mImpl);
|
|
}
|
|
|
|
@NonNull
|
|
public String getPackageName() {
|
|
return this.mImpl.getPackageName();
|
|
}
|
|
|
|
public int getPid() {
|
|
return this.mImpl.getPid();
|
|
}
|
|
|
|
public int getUid() {
|
|
return this.mImpl.getUid();
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.mImpl.hashCode();
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public interface RemoteUserInfoImpl {
|
|
String getPackageName();
|
|
|
|
int getPid();
|
|
|
|
int getUid();
|
|
}
|
|
|
|
private MediaSessionManager(Context context) {
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
this.mImpl = new MediaSessionManagerImplApi28(context);
|
|
} else {
|
|
this.mImpl = new MediaSessionManagerImplApi21(context);
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public static MediaSessionManager getSessionManager(@NonNull Context context) {
|
|
MediaSessionManager mediaSessionManager;
|
|
if (context != null) {
|
|
synchronized (sLock) {
|
|
if (sSessionManager == null) {
|
|
sSessionManager = new MediaSessionManager(context.getApplicationContext());
|
|
}
|
|
mediaSessionManager = sSessionManager;
|
|
}
|
|
return mediaSessionManager;
|
|
}
|
|
throw new IllegalArgumentException("context cannot be null");
|
|
}
|
|
|
|
public Context getContext() {
|
|
return this.mImpl.getContext();
|
|
}
|
|
|
|
public boolean isTrustedForMediaControl(@NonNull RemoteUserInfo remoteUserInfo) {
|
|
if (remoteUserInfo != null) {
|
|
return this.mImpl.isTrustedForMediaControl(remoteUserInfo.mImpl);
|
|
}
|
|
throw new IllegalArgumentException("userInfo should not be null");
|
|
}
|
|
}
|