openid / AppAuth-Android

Android client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
https://openid.github.io/AppAuth-Android
Apache License 2.0
2.79k stars 877 forks source link

Crash on net.openid.appauth.browser.CustomTabManager.onCustomTabsServiceConnected #425

Open LubaAro opened 5 years ago

LubaAro commented 5 years ago

Hi guy, Can you please help us with the following crash on OnePlus OS 8:

Fatal Exception: java.lang.IllegalStateException: Not allowed to start service Intent { act=start-gecko cmp=org.torproject.torbrowser_alpha/org.mozilla.gecko.GeckoService (has extras) }: app is in background uid UidRecord{8d5fff9 u0a134 CACC idle change:cached procs:1 seq(0,0,0)} at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1951) at android.support.customtabs.ICustomTabsService$Stub$Proxy.warmup(Unknown Source:23) at android.support.customtabs.CustomTabsClient.bindCustomTabsService(Unknown Source:2) at net.openid.appauth.browser.CustomTabManager$1.onCustomTabsServiceConnected(Unknown Source:10) at android.support.customtabs.CustomTabsServiceConnection.onServiceConnected(Unknown Source:9) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1691) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1720) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6753) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Thanks a lot, Luba

davidmigloz commented 5 years ago

I'm getting the same stack trace in crashlytics for one customer that is using a Motorola Moto G with Android 8.1.

KevinPosim commented 5 years ago

java.lang.IllegalStateException: (Not allowed to start service Intent { act=start-gecko cmp=com.ghostery.android.ghostery/org.mozilla.gecko.GeckoService (has extras) }: app is in background uid UidRecord{a74b3d4 u0a364 CAC bg:+14h49m39s368ms idle procs:2 seq(0,0,0)}) at android.os.Parcel.readException(Parcel.java:1975) at android.os.Parcel.readException(Parcel.java:1913) at android.support.customtabs.ICustomTabsService$Stub$Proxy.warmup(ICustomTabsService.java:224) at androidx.browser.customtabs.CustomTabsClient.warmup(CustomTabsClient.java:173) at net.openid.appauth.browser.CustomTabManager$1.onCustomTabsServiceConnected(CustomTabManager.java:85) at androidx.browser.customtabs.CustomTabsServiceConnection.onServiceConnected(CustomTabsServiceConnection.java:33)

Similar crash. I have been able to replicate it by installing the extension Ghostery, which seems to be a highly rated and very common ad blocker. I installed Firefox on the emulator then installed the Ghostery extension and I get the crash every time.

This is using the code that I converted to AndroidX but it seems to be in the same place as reported above. This was not device specific. Would be nice if this exception was caught down in CustomTabsClient instead of the app crashing.

JenyaKirmizaTripTop commented 5 years ago

Same Here

KevinPosim commented 5 years ago

Since I have the code pulled in manually I did the following:

        @Override
        public void onCustomTabsServiceConnected(ComponentName componentName,
                                                 CustomTabsClient customTabsClient) {
            Logger.debug("CustomTabsService is connected");
            try {
                customTabsClient.warmup(0);
            } catch (Exception exp) {
                // Let's see if blowing this off helps
            }
            setClient(customTabsClient);
        }

It got my past my issues

JenyaKirmizaTripTop commented 5 years ago

try { customTabsClient.warmup(0); } catch (Exception exp) { // Let's see if blowing this off helps } setClient(customTabsClient);

how does this affect the performance?

KevinPosim commented 5 years ago

I have never been able to replicate this crash on a device I have. I believe the warm up tells the chosen browser to get things ready on a background thread. If this crashes then then warm up does not happen and there probably is a slight delay showing the login screen.

If the warm up call is not causing a crash then the affect of adding a try / catch block should be super minimal.

You could just comment out the warmup call and see how much longer it takes to show the login screen. I just wanted to get around the crash in the field.

andriydruk commented 5 years ago

We have the same issue with Tor Browser. The current solution for us - using filter browser with whitelist:

AppAuthConfiguration configuration = new AppAuthConfiguration.Builder().setBrowserMatcher(new BrowserWhitelist(
                VersionedBrowserMatcher.CHROME_BROWSER,
                VersionedBrowserMatcher.CHROME_CUSTOM_TAB,
                VersionedBrowserMatcher.FIREFOX_BROWSER,
                VersionedBrowserMatcher.FIREFOX_CUSTOM_TAB,
                VersionedBrowserMatcher.SAMSUNG_BROWSER,
                VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB
        )).build();
return new AuthorizationService(applicationContext, configuration);