AppLovin / AppLovin-MAX-SDK-Android

Other
233 stars 104 forks source link

ANR - com.applovin.impl.sdk.SessionTracker$1.onActivityResumed #698

Open maximkir-fl opened 3 months ago

maximkir-fl commented 3 months ago

MAX SDK Version

12.1.0

Device/Platform Info

Android 12, OnePlus

Current Behavior

Firebase crashlytics reports an ANR during application resume. The stack trace clearly shows that your SDK's code is blocking the main thread.

main (native):tid=1 systid=5812 
#00 pc 0xc9dac libc.so (__ioctl + 12) (BuildId: bbbdeb7c87c74f1491f92c6e605095b0)
#01 pc 0x83888 libc.so (ioctl + 156) (BuildId: bbbdeb7c87c74f1491f92c6e605095b0)
#02 pc 0x56044 libbinder.so (android::IPCThreadState::talkWithDriver + 292) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#03 pc 0x57280 libbinder.so (android::IPCThreadState::waitForResponse + 64) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#04 pc 0x56fc4 libbinder.so (android::IPCThreadState::transact + 224) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#05 pc 0x4eb18 libbinder.so (android::BpBinder::transact + 312) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#06 pc 0xfbb0 libsensor.so (android::BpSensorServer::createSensorEventConnection + 228) (BuildId: 4258a08232c7c78f8016f15d50d68575)
#07 pc 0x1377c libsensor.so (android::SensorManager::createEventQueue + 112) (BuildId: 4258a08232c7c78f8016f15d50d68575)
#08 pc 0x1a9400 libandroid_runtime.so ((anonymous namespace)::nativeInitSensorEventQueue + 404) (BuildId: 819617e46a856966e090e9e1d3fe76c6)
       at android.hardware.SystemSensorManager$BaseEventQueue.nativeInitBaseEventQueue(Native method)
       at android.hardware.SystemSensorManager$BaseEventQueue.<init>(SystemSensorManager.java:715)
       at android.hardware.SystemSensorManager$SensorEventQueue.<init>(SystemSensorManager.java:881)
       at android.hardware.SystemSensorManager.registerListenerImpl(SystemSensorManager.java:223)
       at android.hardware.SensorManager.registerListener(SensorManager.java:845)
       at android.hardware.SensorManager.registerListener(SensorManager.java:752)
       at com.applovin.impl.sdk.utils.q.a(SourceFile:77)
       at com.applovin.impl.sdk.utils.q.Lq(SourceFile:69)
       at com.applovin.impl.sdk.utils.q.onReceive(SourceFile:149)
       at com.applovin.impl.sdk.AppLovinBroadcastManager.sendBroadcastSync(SourceFile:232)
       at com.applovin.impl.sdk.SessionTracker.Fv(SourceFile:219)
       at com.applovin.impl.sdk.SessionTracker.AC(SourceFile:159)
       at com.applovin.impl.sdk.SessionTracker.a(unavailable)
       at com.applovin.impl.sdk.SessionTracker$1.onActivityResumed(SourceFile:69)
       at android.app.Application.dispatchActivityResumed(Application.java:430)
       at android.app.Activity.dispatchActivityResumed(Activity.java:1400)
       at android.app.Activity.onResume(Activity.java:1966)
       at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:310)
       at com.sample.app.MainActivity.onResume(MainActivity.kt)

Expected Behavior

Use background threads to perform any I/O-related work.

How to Reproduce

You can use the OS & device I provided in the ANR details.

Additional Info

ANR_stacktrace.txt

maximkir-fl commented 3 months ago

The ANR originates from the session tracker feature. Do you know how I can disable it for a quick WA?

maximkir-fl commented 3 months ago

Another Example of ANR stack trace (Android12, OnePlus Nord N200 5G):

main (native):tid=1 systid=19376 
#00 pc 0xc9dac libc.so (__ioctl + 12) (BuildId: bbbdeb7c87c74f1491f92c6e605095b0)
#01 pc 0x83888 libc.so (ioctl + 156) (BuildId: bbbdeb7c87c74f1491f92c6e605095b0)
#02 pc 0x56044 libbinder.so (android::IPCThreadState::talkWithDriver + 292) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#03 pc 0x57280 libbinder.so (android::IPCThreadState::waitForResponse + 64) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#04 pc 0x56fc4 libbinder.so (android::IPCThreadState::transact + 224) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#05 pc 0x4eb18 libbinder.so (android::BpBinder::transact + 312) (BuildId: 130998bfc090f1da32fe9774d36439a9)
#06 pc 0xdf68 libsensor.so (android::BpSensorEventConnection::enableDisable + 236) (BuildId: 4258a08232c7c78f8016f15d50d68575)
#07 pc 0x1a97ec libandroid_runtime.so ((anonymous namespace)::nativeEnableSensor + 144) (BuildId: 819617e46a856966e090e9e1d3fe76c6)
       at android.hardware.SystemSensorManager$BaseEventQueue.nativeEnableSensor(Native method)
       at android.hardware.SystemSensorManager$BaseEventQueue.enableSensor(SystemSensorManager.java:824)
       at android.hardware.SystemSensorManager$BaseEventQueue.addSensor(SystemSensorManager.java:740)
       at android.hardware.SystemSensorManager.registerListenerImpl(SystemSensorManager.java:224)
       at android.hardware.SensorManager.registerListener(SensorManager.java:845)
       at android.hardware.SensorManager.registerListener(SensorManager.java:752)
       at com.applovin.impl.sdk.utils.q.a(SourceFile:77)
       at com.applovin.impl.sdk.utils.q.Lq(SourceFile:69)
       at com.applovin.impl.sdk.utils.q.onReceive(SourceFile:149)
       at com.applovin.impl.sdk.AppLovinBroadcastManager.sendBroadcastSync(SourceFile:232)
       at com.applovin.impl.sdk.SessionTracker.Fv(SourceFile:219)
       at com.applovin.impl.sdk.SessionTracker.AC(SourceFile:159)
       at com.applovin.impl.sdk.SessionTracker.a(unavailable)
       at com.applovin.impl.sdk.SessionTracker$1.onActivityResumed(SourceFile:69)
       at android.app.Application.dispatchActivityResumed(Application.java:430)
       at android.app.Activity.dispatchActivityResumed(Activity.java:1400)
       at android.app.Activity.onResume(Activity.java:1966)
       at com.google.android.gms.ads.AdActivity.onResume(com.google.android.gms:play-services-ads-lite@@22.6.0)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1491)
       at android.app.Activity.performResume(Activity.java:8280)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4925)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4974)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:60)
       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:2345)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:233)
       at android.os.Looper.loop(Looper.java:344)
       at android.app.ActivityThread.main(ActivityThread.java:8212)
       at java.lang.reflect.Method.invoke(Native method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
richashukla23 commented 3 months ago

@maximkir-fl You seem to be on an older SDK version. Are you able to upgrade to latest and check?

maximkir-fl commented 3 months ago

Hi @richashukla23, Is your suggestion based on a fix added to the newest release?

thomasmso commented 3 months ago

@maximkir-fl - actually, to enable the fix you need to set an extra parameter as I demonstrate below, won't affect your integration.

        val settings = AppLovinSdk.getInstance( this ).getSettings();
        settings.setExtraParameter( "disable_sensor_data_collection", "true" );

        val initConfig = AppLovinSdkInitializationConfiguration.builder( "YOUR_SDK_KEY", this )
                .setMediationProvider( AppLovinMediationProvider.MAX )
                .build();

        AppLovinSdk.getInstance( this ).initialize( initConfig, config -> {
            ...
        } );