- 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
164 lines
7.7 KiB
Java
164 lines
7.7 KiB
Java
package androidx.media.session;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.app.PendingIntent;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.ActivityInfo;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.ResolveInfo;
|
|
import android.content.pm.ServiceInfo;
|
|
import android.support.v4.media.MediaBrowserCompat;
|
|
import android.support.v4.media.session.MediaControllerCompat;
|
|
import android.support.v4.media.session.MediaSessionCompat;
|
|
import android.support.v4.media.session.PlaybackStateCompat;
|
|
import android.util.Log;
|
|
import android.view.KeyEvent;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.media.MediaBrowserServiceCompat;
|
|
import com.google.android.gms.drive.DriveFile;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MediaButtonReceiver extends BroadcastReceiver {
|
|
private static final String TAG = "MediaButtonReceiver";
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
if (intent == null || !"android.intent.action.MEDIA_BUTTON".equals(intent.getAction()) || !intent.hasExtra("android.intent.extra.KEY_EVENT")) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Ignore unsupported intent: ");
|
|
sb.append(intent);
|
|
return;
|
|
}
|
|
ComponentName serviceComponentByAction = getServiceComponentByAction(context, "android.intent.action.MEDIA_BUTTON");
|
|
if (serviceComponentByAction != null) {
|
|
intent.setComponent(serviceComponentByAction);
|
|
startForegroundService(context, intent);
|
|
return;
|
|
}
|
|
ComponentName serviceComponentByAction2 = getServiceComponentByAction(context, MediaBrowserServiceCompat.SERVICE_INTERFACE);
|
|
if (serviceComponentByAction2 != null) {
|
|
BroadcastReceiver.PendingResult goAsync = goAsync();
|
|
Context applicationContext = context.getApplicationContext();
|
|
MediaButtonConnectionCallback mediaButtonConnectionCallback = new MediaButtonConnectionCallback(applicationContext, intent, goAsync);
|
|
MediaBrowserCompat mediaBrowserCompat = new MediaBrowserCompat(applicationContext, serviceComponentByAction2, mediaButtonConnectionCallback, null);
|
|
mediaButtonConnectionCallback.setMediaBrowser(mediaBrowserCompat);
|
|
mediaBrowserCompat.connect();
|
|
return;
|
|
}
|
|
throw new IllegalStateException("Could not find any Service that handles android.intent.action.MEDIA_BUTTON or implements a media browser service.");
|
|
}
|
|
|
|
public static class MediaButtonConnectionCallback extends MediaBrowserCompat.ConnectionCallback {
|
|
private final Context mContext;
|
|
private final Intent mIntent;
|
|
private MediaBrowserCompat mMediaBrowser;
|
|
private final BroadcastReceiver.PendingResult mPendingResult;
|
|
|
|
public void setMediaBrowser(MediaBrowserCompat mediaBrowserCompat) {
|
|
this.mMediaBrowser = mediaBrowserCompat;
|
|
}
|
|
|
|
public MediaButtonConnectionCallback(Context context, Intent intent, BroadcastReceiver.PendingResult pendingResult) {
|
|
this.mContext = context;
|
|
this.mIntent = intent;
|
|
this.mPendingResult = pendingResult;
|
|
}
|
|
|
|
@Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback
|
|
public void onConnected() {
|
|
new MediaControllerCompat(this.mContext, this.mMediaBrowser.getSessionToken()).dispatchMediaButtonEvent((KeyEvent) this.mIntent.getParcelableExtra("android.intent.extra.KEY_EVENT"));
|
|
finish();
|
|
}
|
|
|
|
@Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback
|
|
public void onConnectionSuspended() {
|
|
finish();
|
|
}
|
|
|
|
@Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback
|
|
public void onConnectionFailed() {
|
|
finish();
|
|
}
|
|
|
|
private void finish() {
|
|
this.mMediaBrowser.disconnect();
|
|
this.mPendingResult.finish();
|
|
}
|
|
}
|
|
|
|
public static KeyEvent handleIntent(MediaSessionCompat mediaSessionCompat, Intent intent) {
|
|
if (mediaSessionCompat == null || intent == null || !"android.intent.action.MEDIA_BUTTON".equals(intent.getAction()) || !intent.hasExtra("android.intent.extra.KEY_EVENT")) {
|
|
return null;
|
|
}
|
|
KeyEvent keyEvent = (KeyEvent) intent.getParcelableExtra("android.intent.extra.KEY_EVENT");
|
|
mediaSessionCompat.getController().dispatchMediaButtonEvent(keyEvent);
|
|
return keyEvent;
|
|
}
|
|
|
|
public static PendingIntent buildMediaButtonPendingIntent(Context context, long j) {
|
|
ComponentName mediaButtonReceiverComponent = getMediaButtonReceiverComponent(context);
|
|
if (mediaButtonReceiverComponent == null) {
|
|
Log.w(TAG, "A unique media button receiver could not be found in the given context, so couldn't build a pending intent.");
|
|
return null;
|
|
}
|
|
return buildMediaButtonPendingIntent(context, mediaButtonReceiverComponent, j);
|
|
}
|
|
|
|
@SuppressLint({"WrongConstant"})
|
|
public static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName componentName, long j) {
|
|
if (componentName == null) {
|
|
Log.w(TAG, "The component name of media button receiver should be provided.");
|
|
return null;
|
|
}
|
|
int keyCode = PlaybackStateCompat.toKeyCode(j);
|
|
if (keyCode == 0) {
|
|
Log.w(TAG, "Cannot build a media button pending intent with the given action: " + j);
|
|
return null;
|
|
}
|
|
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
|
|
intent.setComponent(componentName);
|
|
intent.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(0, keyCode));
|
|
intent.addFlags(DriveFile.MODE_READ_ONLY);
|
|
return PendingIntent.getBroadcast(context, keyCode, intent, MediaSessionCompat.PENDING_INTENT_FLAG_MUTABLE);
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public static ComponentName getMediaButtonReceiverComponent(Context context) {
|
|
Intent intent = new Intent("android.intent.action.MEDIA_BUTTON");
|
|
intent.setPackage(context.getPackageName());
|
|
List<ResolveInfo> queryBroadcastReceivers = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
|
if (queryBroadcastReceivers.size() == 1) {
|
|
ActivityInfo activityInfo = queryBroadcastReceivers.get(0).activityInfo;
|
|
return new ComponentName(activityInfo.packageName, activityInfo.name);
|
|
}
|
|
if (queryBroadcastReceivers.size() <= 1) {
|
|
return null;
|
|
}
|
|
Log.w(TAG, "More than one BroadcastReceiver that handles android.intent.action.MEDIA_BUTTON was found, returning null.");
|
|
return null;
|
|
}
|
|
|
|
private static void startForegroundService(Context context, Intent intent) {
|
|
context.startForegroundService(intent);
|
|
}
|
|
|
|
private static ComponentName getServiceComponentByAction(Context context, String str) {
|
|
PackageManager packageManager = context.getPackageManager();
|
|
Intent intent = new Intent(str);
|
|
intent.setPackage(context.getPackageName());
|
|
List<ResolveInfo> queryIntentServices = packageManager.queryIntentServices(intent, 0);
|
|
if (queryIntentServices.size() == 1) {
|
|
ServiceInfo serviceInfo = queryIntentServices.get(0).serviceInfo;
|
|
return new ComponentName(serviceInfo.packageName, serviceInfo.name);
|
|
}
|
|
if (queryIntentServices.isEmpty()) {
|
|
return null;
|
|
}
|
|
throw new IllegalStateException("Expected 1 service that handles " + str + ", found " + queryIntentServices.size());
|
|
}
|
|
}
|