AppAuth-Android icon indicating copy to clipboard operation
AppAuth-Android copied to clipboard

android.content.ActivityNotFoundException: When app opened

Open dhruvsunking opened this issue 1 year ago • 18 comments

Checklist:

Configuration

  • Version: 0.11.1
  • Integration: Java/Kotlin

Issue Description

Get this exception on Crashlytics when app is opened

Caused by android.content.ActivityNotFoundException:
       at net.openid.appauth.AuthorizationService.prepareAuthorizationRequestIntent(AuthorizationService.java:555)
       at net.openid.appauth.AuthorizationService.getAuthorizationRequestIntent(AuthorizationService.java:390)
       at login.utils.LoginHelper.doAuth(LoginHelper.java:131)
       at login.utils.LoginHelper.startAuth(LoginHelper.java:112)
       at login.view.LoginHomeActivity.startAuth(LoginHomeActivity.kt:196)
       at login.view.LoginHomeActivity.initView(LoginHomeActivity.kt:118)
       at baseclass.BaseActivity.onCreate(BaseActivity.kt:42)
       at android.app.Activity.performCreate(Activity.java:8591)
       at android.app.Activity.performCreate(Activity.java:8570)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8757)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

dhruvsunking avatar Apr 01 '24 11:04 dhruvsunking

can you explain more? is it minify? if does, you might need to exclude the app auth library to be obsfucate by gradle

CompileConnected avatar Apr 02 '24 03:04 CompileConnected

Sure. no it is not minified. Sometimes it works fine but sometime suddenly (prepareAuthorizationRequestIntent, getAuthorizationRequestIntent) these two started throwing exception of activity not found.

dhruvsunking avatar Apr 02 '24 04:04 dhruvsunking

Hi from Android 13 we are required to add category with the intent. If didn't have that with your intent, can you add the following and check if that helps.

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { authIntent.addCategory(Intent.CATEGORY_DEFAULT) authIntent.addCategory(Intent.CATEGORY_BROWSABLE) }

Update: This doesn't work. It's still crashing.

amit517 avatar Apr 04 '24 09:04 amit517

My user scenario is similar like this old comment

Got several crash report of that. User mostly with Samsung. OS Version 13, 14. And chrome is installed. image

amit517 avatar Apr 25 '24 13:04 amit517

We have the same problem. We've implemented it recently. Successfully tested on multiple devices. However, after we've released it we have a lot of ActivityNotFoundException. Mostly Samsung devices and Android 13. Unfortunately, I don't have any device with this problem :-(

image

JaFiOriflame avatar May 03 '24 10:05 JaFiOriflame

I also had several users reporting this problem, all with Samsung devices with Android 13. And the problem goes away after restarting the device. It seems like there's a bug with intent handling on this version of Samsung-modified Android version. Seems related to this SO question: https://stackoverflow.com/questions/78341069/packagemanager-queryintentactivities-returns-empty-on-random-devices

guillaume-tgl avatar May 31 '24 08:05 guillaume-tgl

图片 图片 图片

W-quan avatar Jul 01 '24 03:07 W-quan

Screen Shot 2024-09-23 at 09 25 44

@guillaume-tgl not only Android 13, not only Samsung, hope you all fix this bug on next version

uitstu avatar Sep 23 '24 02:09 uitstu

Also seeing the same crashes in Firebase Crashlytics but can't reproduce it.

Also see issue #991 with some interesting information: It might be related to Samsung Internet Browser installed from the Galaxy Store.

svenjacobs avatar Sep 27 '24 06:09 svenjacobs

Is there any solution to this yet?

Some of our users face the same issue with Samsung (Android 13) devices - they suddenly get an ActivityNotFoundException in prepareAuthorizationRequestIntent, even though there are browsers installed on the device.

We cannot reproduce it on our side with Samsung Internet Browser installed from the Galaxy Store as default browser (and no other browser enabled).

wnetsimon avatar Oct 15 '24 05:10 wnetsimon

As a workaround, I created an authentication WebView that opens when an ActivityNotFoundException is thrown. I use AuthorizationRequest to load URL in webview and I create AuthorizationResponse to return result. So handling result is the same implementation for webview and browser.

I haven't reproduced this error, but I believe it would work, because no need to open external browser when using internal webview.

rprunskas avatar Oct 16 '24 10:10 rprunskas

@rprunskas do you mind sharing a github gist for how you implemented your workaround?

SunnyBe avatar Nov 13 '24 13:11 SunnyBe

@guillaume-tgl did you find any fix or workaround, kindly share with me

SunnyBe avatar Nov 13 '24 14:11 SunnyBe

@rprunskas do you mind sharing a github gist for how you implemented your workaround?

Sorry, I can't provide code as it isn't open source. But the main idea is to use webview instead of browser. And I could confirm that this workaround solves this issue(it might not work if auth provider doesn't support webview).

rprunskas avatar Dec 06 '24 07:12 rprunskas

But the main idea is to use webview instead of browser.

I think AppAuth doesn't use the WebView for a reason, because a WebView might be outdated on a smartphone and also WebViews allow injecting JavaScript code from the app side. I think these are good reasons to not use a WebView for a security critical process like authentication.

svenjacobs avatar Dec 06 '24 08:12 svenjacobs

But the main idea is to use webview instead of browser.

I think AppAuth doesn't use the WebView for a reason, because a WebView might be outdated on a smartphone and also WebViews allow injecting JavaScript code from the app side. I think these are good reasons to not use a WebView for a security critical process like authentication.

Yes, I agree. Many of our users experienced this issue, so I had to do workaound for them only.

rprunskas avatar Dec 06 '24 08:12 rprunskas

The problem still exists... Does someone have new insights, why this is happening? In our case it's only Samsung Android 13. Do other vendor implementations, which were initially forked from appauth, have solutions and workarounds others than using WebViews?

MarcDahlem avatar Jan 30 '25 17:01 MarcDahlem

Does someone have new insights, why this is happening?

This is very likely a bug with Android 13 on Samsung devices. As stated by this comment, restarting the device sometimes helps temporarily. But it seems there is no workaround from our side once the issue occurs on the user's device.

svenjacobs avatar Jun 11 '25 09:06 svenjacobs