Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer Exception on CustomTabsManagerActivity.onResume #2818

Open
1 task done
Mohammed-Amleh opened this issue May 13, 2024 · 10 comments
Open
1 task done

Null Pointer Exception on CustomTabsManagerActivity.onResume #2818

Mohammed-Amleh opened this issue May 13, 2024 · 10 comments
Assignees
Labels
closing soon This issue will be closed in 7 days unless further comments are made. pending-community-response Issue is pending response from the issue requestor question General question

Comments

@Mohammed-Amleh
Copy link

Mohammed-Amleh commented May 13, 2024

Before opening, please confirm:

Language and Async Model

Java, Kotlin

Amplify Categories

Authentication

Describe the bug

#1090 exactly the same as this problem & the amplify version that i am using is v2.14.6, i cant re-produce the problem i counter it on firebase crashlytic.
error :

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.app.t/com.amplifyframework.auth.cognito.activities.CustomTabsManagerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5378)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5444)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       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:8779)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)' on a null object reference
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1799)
       at android.app.Activity.startActivityForResult(Activity.java:5596)
       at android.app.Activity.startActivityForResult(Activity.java:5554)
       at android.app.Activity.startActivity(Activity.java:6052)
       at android.app.Activity.startActivity(Activity.java:6019)
       at com.amplifyframework.auth.cognito.activities.CustomTabsManagerActivity.onResume(CustomTabsManagerActivity.kt:49)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1531)
       at android.app.Activity.performResume(Activity.java:8734)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5351)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5444)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       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:8779)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
@github-actions github-actions bot added the pending-triage Issue is pending triage label May 13, 2024
@tylerjroach
Copy link
Member

@Mohammed-Amleh This one is strange.

Would you have any data on these crashes to determine if Google Play Services is available on these devices? This looks to be the most common scenario that can cause this.

Would you happen to know if these devices are rooted?

If neither of these pieces of info are available, please post a few of the devices that have crashed with this info and we can see if we notice any patterns (ex: manufacturer, OS version, etc)

How many devices/users have you seen this issue on?

@tylerjroach tylerjroach added pending-community-response Issue is pending response from the issue requestor bug Something isn't working and removed pending-triage Issue is pending triage labels May 13, 2024
@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label May 13, 2024
@Mohammed-Amleh
Copy link
Author

@tylerjroach the crash appear for 18 users , and i don't think its Google Play Services Availability
see these :
Screenshot 2024-05-13 at 5 47 51 PM
Screenshot 2024-05-13 at 5 48 02 PM

@Mohammed-Amleh
Copy link
Author

@tylerjroach

@tylerjroach
Copy link
Member

@Mohammed-Amleh Is this a new app, or a crash that has appeared out of nowhere on an older app? Asking because we don't see any occurrences before May 3-4 on that chart.

Can you post any Amplify/AWS related code that you have added to your manifest, as well as show how you are launching signInWithWebUI or signInWithSocialWebUI sign ins?

@Mohammed-Amleh
Copy link
Author

no its not a new app ,we was using amplify v1 ,, this error appear after upgrading to amplify v2 .
sorry but i can't share any code (i don't have the privilege for it).
what what added to manifest :

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />

            <data android:scheme="https" />
        </intent>
        <intent>
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>
    </queries>

        <activity
            android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="my_app_name" />
            </intent-filter>
        </activity>

@tylerjroach
Copy link
Member

@Mohammed-Amleh The block you posted is no longer needed in Amplify v2. Regardless, this wouldn't impact your application.

Would you happen to know if these devices are eventually able to sign in or not? Curious if it is a transient issue for them or these devices failing 100% of time time. Do the devices failing all seem to be specific to a single region? Looking for any more data points that could help identity why this may be happening.

I've not seen this report before. I think I can try/catch to prevent the crash, but the scenario happening here should not be happening. A try/catch would still prevent hosted ui sign in from working correctly.

The crash appears to be the CustomTab intent is null on the first launch (which shouldn't happen since it created and passed directly when calling startActivity on the CustomTabsManagerActivity.

@tylerjroach tylerjroach added the pending-community-response Issue is pending response from the issue requestor label May 17, 2024
@Mohammed-Amleh
Copy link
Author

Mohammed-Amleh commented Jun 24, 2024

@tylerjroach

the problem is from extractState in CustomTabsManagerActivity

  private fun extractState(state: Bundle?) {
        if (state == null) {
            Log.d(TAG, "CustomTabsManagerActivity was created with a null state.")
            finish()
            return
        }
        customTabsIntent = state.getParcelable(CUSTOM_TABS_INTENT_KEY)
        customTabsLaunched = state.getBoolean(CUSTOM_TABS_LAUNCHED_KEY, false)
    }
Screenshot 2024-06-24 at 6 04 46 PM

We use a package for analytics that adds an extra intent for every launch activity. The issue arises in our specific case where the state will never be null, even if the customTabsIntentExtra is not provided. Consequently, the following lines of code can result in null values:

        customTabsIntent = state.getParcelable(CUSTOM_TABS_INTENT_KEY) // will be null 
        customTabsLaunched = state.getBoolean(CUSTOM_TABS_LAUNCHED_KEY, false)

To address this issue, modify the if statement to include a check for the customTabsIntent key:

state == null || state.getParcelable(CUSTOM_TABS_INTENT_KEY) == null

This ensures that u properly handle scenarios where the customTabsIntent is not provided, even though state is not null.

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Jun 24, 2024
@tylerjroach
Copy link
Member

tylerjroach commented Jun 24, 2024

Have you already tested this to work? In some places we launch with startActivityForResult and rely on the result to come back to continue. It may work but the implementation needs thought through a bit more.

The issue arises in our specific case where the state will never be null, even if the customTabsIntentExtra is not provided.

This should never happen. We never launch without intent data. This was just meant to be a safety mechanism.

We don't always pass CUSTOM_TABS_INTENT_KEY ourselves. It is allowed to be null, for the response handling intent.

I'm still concerned about this analytics package that is injecting into our owned activities. Can we look into which library this is? Maybe there is a way to exclude individual activities. This is a headless activity ands its behavior is not meant to be modified by the app developer, nor any other 3rd party libraries.

We are open to work around this 3rd party issue, but would want to test with this analytics library ourselves to make sure that any fix we attempt to create does not result in any adverse side effects elsewhere.

@tylerjroach tylerjroach added question General question and removed bug Something isn't working labels Jun 24, 2024
@Mohammad-amleh
Copy link

Mohammad-amleh commented Jun 25, 2024

@tylerjroach
our workaround when we was using amplify v1 :

 // Handles auth redirect for sign-in and sign-out.
class HostedUIRedirectActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val redirectUri = intent.data
        if (redirectUri?.toString().orEmpty().contains("sign-in")) {
            val redirectHandler =
                    CustomTabsManagerActivity.createResponseHandlingIntent(this, redirectUri)
            startActivity(redirectHandler)
        }
    }

    public override fun onResume() {
        super.onResume()
        Amplify.Auth.handleWebUISignInResponse(intent)
        finish()
    }
}

but in v2 CustomTabsManagerActivity is internal even u guys solve this problem or make CustomTabsManagerActivity public so we can do our changes.

@tylerjroach
Copy link
Member

CustomTabsManagerActivity is intended to remain internal and should not be invoked by anything other than Amplify itself.

I'd like to look at the Analytics library in question and see exactly what is being done, to make sure that we have a stable and complete way of handling unintended outside interference.

@tylerjroach tylerjroach added the pending-community-response Issue is pending response from the issue requestor label Jun 27, 2024
@tylerjroach tylerjroach added the closing soon This issue will be closed in 7 days unless further comments are made. label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing soon This issue will be closed in 7 days unless further comments are made. pending-community-response Issue is pending response from the issue requestor question General question
Projects
None yet
Development

No branches or pull requests

3 participants