112 lines
4.9 KiB
Java
112 lines
4.9 KiB
Java
package androidx.media;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.pm.PackageManager;
|
|
import android.provider.Settings;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.core.util.ObjectsCompat;
|
|
import androidx.media.MediaSessionManager;
|
|
import b.d.b.a.a;
|
|
/* loaded from: classes.dex */
|
|
public class MediaSessionManagerImplBase implements MediaSessionManager.MediaSessionManagerImpl {
|
|
private static final boolean DEBUG = MediaSessionManager.DEBUG;
|
|
private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners";
|
|
private static final String PERMISSION_MEDIA_CONTENT_CONTROL = "android.permission.MEDIA_CONTENT_CONTROL";
|
|
private static final String PERMISSION_STATUS_BAR_SERVICE = "android.permission.STATUS_BAR_SERVICE";
|
|
private static final String TAG = "MediaSessionManager";
|
|
public ContentResolver mContentResolver;
|
|
public Context mContext;
|
|
|
|
/* loaded from: classes.dex */
|
|
public static class RemoteUserInfoImplBase implements MediaSessionManager.RemoteUserInfoImpl {
|
|
private String mPackageName;
|
|
private int mPid;
|
|
private int mUid;
|
|
|
|
public RemoteUserInfoImplBase(String str, int i, int i2) {
|
|
this.mPackageName = str;
|
|
this.mPid = i;
|
|
this.mUid = i2;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof RemoteUserInfoImplBase)) {
|
|
return false;
|
|
}
|
|
RemoteUserInfoImplBase remoteUserInfoImplBase = (RemoteUserInfoImplBase) obj;
|
|
return (this.mPid < 0 || remoteUserInfoImplBase.mPid < 0) ? TextUtils.equals(this.mPackageName, remoteUserInfoImplBase.mPackageName) && this.mUid == remoteUserInfoImplBase.mUid : TextUtils.equals(this.mPackageName, remoteUserInfoImplBase.mPackageName) && this.mPid == remoteUserInfoImplBase.mPid && this.mUid == remoteUserInfoImplBase.mUid;
|
|
}
|
|
|
|
@Override // androidx.media.MediaSessionManager.RemoteUserInfoImpl
|
|
public String getPackageName() {
|
|
return this.mPackageName;
|
|
}
|
|
|
|
@Override // androidx.media.MediaSessionManager.RemoteUserInfoImpl
|
|
public int getPid() {
|
|
return this.mPid;
|
|
}
|
|
|
|
@Override // androidx.media.MediaSessionManager.RemoteUserInfoImpl
|
|
public int getUid() {
|
|
return this.mUid;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ObjectsCompat.hash(this.mPackageName, Integer.valueOf(this.mUid));
|
|
}
|
|
}
|
|
|
|
public MediaSessionManagerImplBase(Context context) {
|
|
this.mContext = context;
|
|
this.mContentResolver = context.getContentResolver();
|
|
}
|
|
|
|
private boolean isPermissionGranted(MediaSessionManager.RemoteUserInfoImpl remoteUserInfoImpl, String str) {
|
|
return remoteUserInfoImpl.getPid() < 0 ? this.mContext.getPackageManager().checkPermission(str, remoteUserInfoImpl.getPackageName()) == 0 : this.mContext.checkPermission(str, remoteUserInfoImpl.getPid(), remoteUserInfoImpl.getUid()) == 0;
|
|
}
|
|
|
|
@Override // androidx.media.MediaSessionManager.MediaSessionManagerImpl
|
|
public Context getContext() {
|
|
return this.mContext;
|
|
}
|
|
|
|
public boolean isEnabledNotificationListener(@NonNull MediaSessionManager.RemoteUserInfoImpl remoteUserInfoImpl) {
|
|
String string = Settings.Secure.getString(this.mContentResolver, ENABLED_NOTIFICATION_LISTENERS);
|
|
if (string != null) {
|
|
for (String str : string.split(":")) {
|
|
ComponentName unflattenFromString = ComponentName.unflattenFromString(str);
|
|
if (unflattenFromString != null && unflattenFromString.getPackageName().equals(remoteUserInfoImpl.getPackageName())) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // androidx.media.MediaSessionManager.MediaSessionManagerImpl
|
|
public boolean isTrustedForMediaControl(@NonNull MediaSessionManager.RemoteUserInfoImpl remoteUserInfoImpl) {
|
|
try {
|
|
if (this.mContext.getPackageManager().getApplicationInfo(remoteUserInfoImpl.getPackageName(), 0) == null) {
|
|
return false;
|
|
}
|
|
return isPermissionGranted(remoteUserInfoImpl, PERMISSION_STATUS_BAR_SERVICE) || isPermissionGranted(remoteUserInfoImpl, PERMISSION_MEDIA_CONTENT_CONTROL) || remoteUserInfoImpl.getUid() == 1000 || isEnabledNotificationListener(remoteUserInfoImpl);
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
if (DEBUG) {
|
|
StringBuilder R = a.R("Package ");
|
|
R.append(remoteUserInfoImpl.getPackageName());
|
|
R.append(" doesn't exist");
|
|
Log.d("MediaSessionManager", R.toString());
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|