Appboy / appboy-android-sdk

Public repo for the Braze Android SDK
https://www.braze.com
Other
152 stars 102 forks source link

[Bug]: Braze.getInstance(this).getCurrentUser() causing ANR #250

Closed oradkovsky closed 1 year ago

oradkovsky commented 1 year ago

Braze Android SDK Version

23.2.1

Steps To Reproduce

Main thread (app instance for example) execution:

        BrazeConfig appboyConfig = new BrazeConfig.Builder()
            .setIsFirebaseCloudMessagingRegistrationEnabled(true)
            .setFirebaseCloudMessagingSenderIdKey(getString(R.string.com_appboy_firebase_cloud_messaging_sender_id))
            .build();

        Braze.getInstance(this).getCurrentUser().addAlias("some alias", "some label"); // ANR

Expected Behavior

No ANR? Unless, of course, the code meant to be called off main thread (in that case I found no documentation proof)

Actual Incorrect Behavior

ANR

2022-11-10 15:28:04.335 546-10251/? E/ActivityManager: ANR in package-name
    PID: 10135
    Reason: executing service package-name/com.google.android.gms.tagmanager.TagManagerService
    Frozen: false

Verbose Logs

No response

Additional Information

Only as of sdk31 devices

oradkovsky commented 1 year ago

Btw this approach works fine:

            Braze.getInstance(this).getCurrentUser(brazeUser ->
                brazeUser.addAlias(
                    "some alias",
                    "some label"
                )
            );
radixdev commented 1 year ago

Hi @oradkovsky ,

The synchronous method style of .getCurrentUser() is a blocking call and thus can take a variable amount of time to unblock the main thread. As a result, if calling on the main thread, we recommend using the asynchronous style of https://appboy.github.io/appboy-android-sdk/kdoc/braze-android-sdk/com.braze/-i-braze/get-current-user.html , which is your second reply.

oradkovsky commented 1 year ago

Thank you, that turns my bug report into misuse report :) Still one question left: why the same code worked < sdk 31