urbanairship / android-library

Urban Airship Android SDK
Other
109 stars 123 forks source link

Possible Airship ANR during UI Testing #218

Closed barry-irvine closed 1 year ago

barry-irvine commented 1 year ago

❗For how-to inquiries involving Airship functionality or use cases, please contact (support)[https://support.airship.com/].

Preliminary Info

What Airship dependencies are you using?

Version: 16.7.5 FCM, inApp and messageCenter

Related: WorkManager 2.7.1

What are the versions of any relevant development tools you are using?

Android Studio Dolphin Patch 1

Report

What unexpected behavior are you seeing?

Every so often our UI tests will fail. Looking in the logs we can see an ANR with the SystemJobService. I've seen from other issues online that this is a very old issue in WorkManager that they'll probably never fix because it's hidden to the user. Some people reported that switching to a CoroutineWorker job fixes it.

See this https://stackoverflow.com/questions/56580401/workmanager-causes-anrs-from-broadcasts and also this https://issuetracker.google.com/issues/110507716

I don't even know if this is your jobs or whether it is one of my CoroutineWorkers causing the issue :(

Another possibility would be if there was an easy way to stop the Airship workers when running AndroidTest. I can't just exclude the AirshipAutoPilot from the Manifest because the dependency injection is also getting instances of Airship.shared() which cannot be accessed before takeoff. I'd then also have an issue if the message center was selected during UI testing.

What is the expected behavior?

No ANRs.

What are the steps to reproduce the unexpected behavior?

Not really any particular steps. It just happens once in a while.

Do you have logging for the issue?

logcat.txt

jyaganeh commented 1 year ago

Hi @barry-irvine, and apologies for the delayed response!

I looked through the logs and didn't spot anything obvious. A quick and easy way to reduce the amount of background work our SDK performs is to use PrivacyManager to disable all features in your tests. You can do that a few different ways.

In airshipconfig.properties:

enabledFeatures = none

With the AirshipConfigOptions builder:

val options = AirshipConfigOptions.newBuilder()
        // ...
        .setEnabledFeatures(PrivacyManager.FEATURE_NONE)
        .build()

Or, using PrivacyManager directly, at runtime:

UAirship.shared().privacyManager
        .setEnabledFeatures(PrivacyManager.FEATURE_NONE)

In order to disable Airship more fully in tests, the typical setup involves wrapping calls to the SDK along with an interface that you can swap out for a no-op test class, providing mocks from your test DI graph, or a combo of both.

It also could be worth trying a tool like ANR-WatchDog, to see if it's able to catch anything that helps to narrow down the cause of your issue.