bug(browser): Fatal SecurityException in `Browser.bindService()` on Android resume when Custom Tabs provider refuses the bind (Unihertz devices)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- backend-api-design, mobile
Línea de trabajo
Start with Browser.java at bindService() and unbindService(), then trace BrowserPlugin.java through handleOnResume() and open(). Check the existing tests for browser service binding and URL launching before changing these paths. Done means refused binds, unbinding after a failed bind, and launch failures do not crash the app, while successful Custom Tabs behavior remains intact.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report
Plugin(s)
@capacitor/browser(verified on 8.0.5; the same code is present onmainas of today)
Capacitor Version
@capacitor/core: 8.5.3
@capacitor/android: 8.5.3
@capacitor/cli: 8.5.3
@capacitor/browser: 8.0.5
Platform(s)
- Android
Current Behavior
The app crashes with a fatal SecurityException on every Activity.onResume when the resolved Custom Tabs provider refuses the bind.
BrowserPlugin.handleOnResume() calls Browser.bindService(), which calls CustomTabsClient.bindCustomTabsService(). The code assumes this method only fails by returning false (which is logged and ignored), but when the resolved provider (e.g. Brave Browser, or Chrome when disabled/blocked by an intent firewall) refuses the bind, the OS throws a SecurityException from ContextImpl.bindServiceCommon instead. Because this runs inside MainActivity.onResume(), the uncaught exception propagates through BridgeActivity.onResume and kills the process.
The affected user cannot use the app at all: the crash fires on launch and on every return to the foreground, regardless of whether the app ever calls Browser.open().
Fatal exception from production crash reporting:
Fatal Exception: java.lang.RuntimeException
Unable to resume activity {app.pkg/app.pkg.MainActivity}: java.lang.SecurityException:
Not allowed to bind to service Intent { act=android.support.customtabs.action.CustomTabsService pkg=com.brave.browser }
android.app.ActivityThread.performResumeActivity (ActivityThread.java:5352)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:962)
Caused by java.lang.SecurityException
Not allowed to bind to service Intent { act=android.support.customtabs.action.CustomTabsService pkg=com.brave.browser }
android.app.ContextImpl.bindServiceCommon (ContextImpl.java:2188)
androidx.browser.customtabs.CustomTabsClient.bindCustomTabsService (CustomTabsClient.java:90)
com.capacitorjs.plugins.browser.Browser.bindService (Browser.java:144)
com.capacitorjs.plugins.browser.BrowserPlugin.handleOnResume (BrowserPlugin.java:95)
com.getcapacitor.Bridge.onResume (Bridge.java:1359)
com.getcapacitor.BridgeActivity.onResume (BridgeActivity.java:98)
android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1722)
Expected Behavior
A refused Custom Tabs bind should be handled gracefully (log and continue), never crash the app. The plugin's existing if (!implementation.bindService()) error-logging path suggests that was the intent — it just doesn't cover the throwing case.
Code Reproduction
- Install the app on a Unihertz device (e.g. Tank 2 Pro, Titan Pocket) with a non-Chrome browser (e.g. Brave) set as the default browser, so
CustomTabsClient.getPackageName()resolves to it. - Launch the app (or resume it from the background).
- Observe the fatal
SecurityExceptioninBrowser.bindService()duringonResume.
Note that no Browser.open() call is required to trigger the crash — the bind happens on every resume.
Device identified: Unihertz Tank 2 Pro (Android 15). This is a known Unihertz firmware behavior: their ROM's app-launch blocker refuses service binds from third-party apps to any Custom Tabs provider except Chrome. Two precedents:
- K-9 Mail crash on a Unihertz Titan Pocket with the identical exception: https://forum.k9mail.app/t/k-9-mail-crashes-right-after-welcome-screen/8541
- FairEmail added a Unihertz-specific workaround for the same
SecurityException(their code comment notes binding "works with Chrome"): https://github.com/m66b/FairEmail — see commit97aab8b8a5("Added workaround for Unihertz") inFragmentOAuth.java
User-side workaround on Unihertz devices: install/enable Chrome and set it as the default browser so CustomTabsClient.getPackageName() resolves to Chrome.
Other Technical Details
- This is a follow-up to #1758 ("feat(browser): support other custom tabs providers", merged Aug 2023). That PR is what made the plugin resolve non-Chrome providers such as Brave, which exposed this crash path. The exception handling around the bind itself was never added, and the current
mainbranch still has the unguarded call inBrowser.bindService(). - The same class of issue exists in two other places:
Browser.unbindService()(called fromhandleOnPause()) throwsIllegalArgumentExceptionwhen the service was never successfully bound — i.e. immediately after the bind failure above, the next pause crashes too.BrowserPlugin.open()→activity.open(...)→CustomTabsIntent.launchUrl()can also throwSecurityException(see the stack trace in the #1758 comments).
Proposed Fix
Wrap the affected calls in try/catch so failures degrade to the existing non-crash paths:
// Browser.java
public boolean bindService() {
String customTabPackageName = CustomTabsClient.getPackageName(context, null);
if (null == customTabPackageName) {
customTabPackageName = FALLBACK_CUSTOM_TAB_PACKAGE_NAME;
}
try {
return CustomTabsClient.bindCustomTabsService(context, customTabPackageName, connection);
} catch (SecurityException | IllegalArgumentException ex) {
return false;
}
}
public void unbindService() {
try {
context.unbindService(connection);
} catch (IllegalArgumentException | SecurityException ex) {
// no-op: service was not bound
}
}
// BrowserPlugin.java, inside the open() listener
} catch (ActivityNotFoundException | SecurityException ex) {
Logger.error(getLogTag(), ex.getLocalizedMessage(), null);
call.reject("Unable to display URL");
}
- Lenguaje dominante
- Java
- Estrellas
- 688
- Forks
- 690
- Merge medio
- 16 h 15 min
- PR fusionados (30 d)
- 7
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ionic-team/capacitor-plugins
-
platform: android
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ionic-team/capacitor-plugins#2647 ·
Los mantenedores suelen responder en 1 día
-
platform: android
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ionic-team/capacitor-plugins#2646 ·
Los mantenedores suelen responder en 1 día
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
ionic-team/capacitor-plugins#2639 ·
Los mantenedores suelen responder en 1 día
-
platform: android
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
ionic-team/capacitor-plugins#2635 ·
Los mantenedores suelen responder en 1 día
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
ionic-team/capacitor-plugins#2627 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de ionic-team/capacitor-plugins
Issues similares
-
enhancement infra
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
5.0.x backport bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
spring-cloud/spring-cloud-function#1569 ·
Los mantenedores suelen responder en 1 día
-
Move the spring-cloud-commons version and BOM import from the bus parent to the stream parentPosiblemente ocupada @olegz la tomó hoy. Abiertotask
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
spring-cloud/spring-cloud-stream#3355 ·
Los mantenedores suelen responder en 1 día
-
NoSuchMethodError in the circuit breaker since 3.103.0 when resilience4j 2.x is on the classpathAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
oracle/oci-java-sdk#803 ·
-
area:cpan-port area:performance bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
fglock/PerlOnJava#2230 ·
Los mantenedores suelen responder en 1 día