soul-browser/sources/java/androidx/media/session/MediaButtonReceiver.java
KaKi87 550ddb0413
Decompile and recreate Soul Browser v1.4.85 with APK CI builds (#1)
* Decompile and recreate Soul Browser v1.4.85 with APK CI builds

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix CI build: include bundled google.jks and remove PR trigger

The apktool build failed in CI because app/unknown/.../google.jks was
excluded by the *.jks gitignore rule. Whitelist app-bundled JKS files
and commit the missing resource.

Also remove the redundant pull_request workflow trigger.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Change package ID to com.github.kaki87.soulbrowser

Rename the application ID so the rebuilt APK can be installed
alongside the original Soul Browser from Google Play.

- Update AndroidManifest package, permissions, providers, and actions
- Update R class references in smali (com/github/kaki87/soulbrowser/R)
- Update shortcuts.xml targetPackage
- Rename app label to "Soul Rebuild" for easy identification

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix install compatibility: remove split APK metadata and bundle native libs

The rebuilt APK still declared requiredSplitTypes and Play Store split
metadata, causing Android to reject standalone installs as incompatible.

- Remove requiredSplitTypes and split-related manifest meta-data
- Merge native libs from all ABI splits with uncompressed storage
- Page-align before signing for extractNativeLibs=false
- Add .so to apktool doNotCompress list

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix install failure: use apksigner v2/v3 and bundle arm64 native libs

Target SDK 36 requires APK Signature Scheme v2+, but jarsigner only
produces v1 signatures, causing Android to reject the install.

- Sign with apksigner (v1+v2+v3) instead of jarsigner
- Add arm64-v8a native libraries from universal Soul Browser 1.4.79
- Set extractNativeLibs=true for reliable sideload installs
- Commit stable debug keystore for consistent signatures across builds

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Add committed debug keystore for consistent APK signatures

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix startup crash: use original classes2.dex desugar libraries

Apktool recompiles smali_classes2 into a broken classes2.dex, causing
ClassNotFoundException for j$.com.android.tools.r8.a at ML Kit init.

Inject the original classes2.dex (Java 8+ desugar libs) after apktool
build instead of using the recompiled version.

Co-authored-by: KaKi87 <KaKi87@pm.me>

* Fix missing drawable resources from density split APKs

The base APK is an app bundle module; density-specific drawables like
seek_thumb_nor_b live in config.xhdpi.apk and were missing after rebuild,
causing Resources$NotFoundException at runtime.

- Merge non-9-patch resources from split APKs before apktool build
- Sync public.xml IDs from R smali only when backing files exist
- Add 713 density-specific resource IDs to public.xml

Co-authored-by: KaKi87 <KaKi87@pm.me>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-08-10 16:07:14 +02:00

127 lines
5.6 KiB
Java

package androidx.media.session;
import android.app.ForegroundServiceStartNotAllowedException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.a;
import android.support.v4.media.session.MediaControllerCompat;
import android.util.Log;
import android.view.KeyEvent;
import androidx.annotation.DoNotInline;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import java.util.List;
/* loaded from: classes.dex */
public class MediaButtonReceiver extends BroadcastReceiver {
/* renamed from: a, reason: collision with root package name */
public static final /* synthetic */ int f1277a = 0;
@RequiresApi
/* loaded from: classes.dex */
public static final class Api31 {
@DoNotInline
public static ForegroundServiceStartNotAllowedException a(IllegalStateException illegalStateException) {
return (ForegroundServiceStartNotAllowedException) illegalStateException;
}
@DoNotInline
public static boolean b(IllegalStateException illegalStateException) {
return illegalStateException instanceof ForegroundServiceStartNotAllowedException;
}
}
/* loaded from: classes.dex */
public static class MediaButtonConnectionCallback extends MediaBrowserCompat.ConnectionCallback {
/* renamed from: a, reason: collision with root package name */
public final Context f1278a;
public final Intent b;
/* renamed from: c, reason: collision with root package name */
public final BroadcastReceiver.PendingResult f1279c;
public MediaBrowserCompat d;
public MediaButtonConnectionCallback(BroadcastReceiver.PendingResult pendingResult, Context context, Intent intent) {
this.f1278a = context;
this.b = intent;
this.f1279c = pendingResult;
}
@Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback
public final void onConnected() {
new MediaControllerCompat(this.f1278a, this.d.getSessionToken()).dispatchMediaButtonEvent((KeyEvent) this.b.getParcelableExtra("android.intent.extra.KEY_EVENT"));
this.d.disconnect();
this.f1279c.finish();
}
@Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback
public final void onConnectionFailed() {
this.d.disconnect();
this.f1279c.finish();
}
@Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback
public final void onConnectionSuspended() {
this.d.disconnect();
this.f1279c.finish();
}
}
public static ComponentName a(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;
}
StringBuilder w = a.w("Expected 1 service that handles ", str, ", found ");
w.append(queryIntentServices.size());
throw new IllegalStateException(w.toString());
}
@Override // android.content.BroadcastReceiver
public final void onReceive(Context context, Intent intent) {
if (intent != null && "android.intent.action.MEDIA_BUTTON".equals(intent.getAction()) && intent.hasExtra("android.intent.extra.KEY_EVENT")) {
ComponentName a2 = a(context, "android.intent.action.MEDIA_BUTTON");
if (a2 != null) {
intent.setComponent(a2);
try {
ContextCompat.g(context, intent);
return;
} catch (IllegalStateException e) {
if (Build.VERSION.SDK_INT >= 31 && Api31.b(e)) {
Log.e("MediaButtonReceiver", "caught exception when trying to start a foreground service from the background: " + Api31.a(e).getMessage());
return;
}
throw e;
}
}
ComponentName a3 = a(context, "android.media.browse.MediaBrowserService");
if (a3 != null) {
BroadcastReceiver.PendingResult goAsync = goAsync();
Context applicationContext = context.getApplicationContext();
MediaButtonConnectionCallback mediaButtonConnectionCallback = new MediaButtonConnectionCallback(goAsync, applicationContext, intent);
MediaBrowserCompat mediaBrowserCompat = new MediaBrowserCompat(applicationContext, a3, mediaButtonConnectionCallback, null);
mediaButtonConnectionCallback.d = 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.");
}
Log.d("MediaButtonReceiver", "Ignore unsupported intent: " + intent);
}
}