facebook-android-sdk
facebook-android-sdk copied to clipboard
`com.android.installreferrer` is called in the main thread which leads to ANR
Checklist before submitting a bug report
- [X] I've updated to the latest released version of the SDK
- [X] I've searched for existing Github issues
- [X] I've looked for existing answers on Stack Overflow, the Facebook Developer Community Forum and the Facebook Developers Group
- [X] I've read the Code of Conduct
- [X] This issue is not security related and can safely be disclosed publicly on GitHub
Java version
8
Android version
api 23+
Android SDK version
12.1
Installation platform & version
Gradle
Package
Other / I don't know
Goals
According to our investigations com.android.installreferrer
can block the callers thread for a long time which in case of main thread leads to ANR. We call com.android.installreferrer
from the background thread, it is safer and works just fine. Looks like fb sdk calls it from the main thread and we have a bunch of ANR reports that shows this case. Please consider moving com.android.installreferrer
to the background thread. Thanks
Expected results
com.android.installreferrer
is used in the background thread, no ANRs
Actual results
com.android.installreferrer
is used in the main thread, ANRs
Steps to reproduce
No response
Code samples & details
Thread state: BLOCKED
android.os.BinderProxy.transactNative(BinderProxy.java:N)
android.os.BinderProxy.transact(BinderProxy.java:N)
e.c.a.a.a.XN(BaseProxy.java:N)
e.c.a.b.a.a$a$a.e(IGetInstallReferrerService.java:N)
com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer(InstallReferrerClientImpl.java:N)
com.facebook.internal.v$b.onInstallReferrerSetupFinished(InstallReferrerUtil.kt:N)
com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected(InstallReferrerClientImpl.java:N)
android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:N)
android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:N)
android.os.Handler.handleCallback(Handler.java:N)
android.os.Handler.dispatchMessage(Handler.java:N)
android.os.Looper.loop(Looper.java:N)
android.app.ActivityThread.main(ActivityThread.java:N)
java.lang.reflect.Method.invoke(Method.java:N)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:N)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:N)
Edit: added a stacktrace
Can you give me script attack for apk???
Hi guys! I think ANR occur because you don't call the endConnection() on your InstallReferrerClient instance in tryConnectReferrerInfo function.
Information about it you can find in officially documentation
same issue
same issue
Issue is not fixed, we observe exact the same issue on FBSDK 16.0.1
@KylinChang
https://github.com/facebook/facebook-android-sdk/commit/29af39e1fa110e9e499134d70b495626030d36ca This commit most likely does not fix this issue as it is simply closing it but other parts of the system can still be slow on the binder call.
The issue is triggered by the call: referrerClient.installReferrer on line 41 in https://github.com/facebook/facebook-android-sdk/blob/main/facebook-core/src/main/java/com/facebook/internal/InstallReferrerUtil.kt
If you look at the source, it's a bit tricky to follow because it is obfuscated, for InstallReferrerClientImpl you will find it does the following: this(((InstallReferrerClientImpl)super).service.c(bundle)); This then calls Transact on the IBinder which causes the ANR.
From the ANR dashboard: The latency of a Binder call is hard to predict. It can be affected not only by the complexity of the call itself, but also by intermittent factors such as system server lock contention. You should treat them as you would treat I/O calls, and avoid, if possible, making Binder calls in the main thread. If making a Binder call from the main thread is unavoidable, make sure to instrument and monitor such calls to detect slowness.
So this ends up being called on the main thread because onInstallReferrerSetupFinished callback happens on the main thread.
I'm not an Android or Kotlin developer so unfortunately I have no easy fixes here, but this referrerClient.installReferrer call should probably be async.
Any updates on this? Getting exactly the same ANR on Play Console, not so rare. Using Unity SDK 15.1.0.
Having the same issue. Any updates here ?
Having the same issue any update on this ?
We're on 16.2.0 and we're still seeing the same issue. Is there an update on when this will be fixed?
Same issue here. Come on folks, please fix this!
Same issue:
"main" tid=1 Native #00 pc 0x0000000000070950 /apex/com.android.runtime/lib/bionic/libc.so (__ioctl+8) #01 pc 0x000000000003f04f /apex/com.android.runtime/lib/bionic/libc.so (ioctl+26) #02 pc 0x0000000000039f87 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+238) #03 pc 0x000000000003b07b /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+86) #04 pc 0x000000000003ae1f /system/lib/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+122) #05 pc 0x00000000000356a7 /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+98) #06 pc 0x00000000000c7e53 /system/lib/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int)+82) at android.os.BinderProxy.transactNative (Native method) at android.os.BinderProxy.transact (BinderProxy.java:559) at com.google.android.a.a.b (a.java:2) at com.google.android.finsky.externalreferrer.IGetInstallReferrerService$Stub$Proxy.c (IGetInstallReferrerService.java:3) at com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer (InstallReferrerClientImpl.java:5) at com.facebook.internal.InstallReferrerUtil$tryConnectReferrerInfo$installReferrerStateListener$1.onInstallReferrerSetupFinished (InstallReferrerUtil.kt:41) at com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected (InstallReferrerClientImpl.java:4) at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:1972) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2004) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:268) at android.app.ActivityThread.main (ActivityThread.java:8016) at java.lang.reflect.Method.invoke (Native method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:627) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:997)
same issue
Any fix for this, we are also experiencing similar issue
Also same here +1
at android.os.BinderProxy.transact (BinderProxy.java:571) at com.google.android.finsky.externalreferrer.IGetInstallReferrerService$Stub$Proxy.getInstallReferrer (IGetInstallReferrerService.java:117) at com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer (InstallReferrerClientImpl.java:187) at com.facebook.internal.InstallReferrerUtil$tryConnectReferrerInfo$installReferrerStateListener$1.onInstallReferrerSetupFinished (InstallReferrerUtil.kt:41) at com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected (InstallReferrerClientImpl.java:222) at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2095) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2128) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:201) at android.os.Looper.loop (Looper.java:288) at android.app.ActivityThread.main (ActivityThread.java:7881) at java.lang.reflect.Method.invoke (Native method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:568) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1045)
Same Issue here,
"main" tid=1 Native
#00 pc 0x00000000000c9da8 /apex/com.android.runtime/lib64/bionic/libc.so (__ioctl+8)
#01 pc 0x0000000000083888 /apex/com.android.runtime/lib64/bionic/libc.so (ioctl+156)
#02 pc 0x0000000000056044 /system/lib64/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+292)
#03 pc 0x0000000000057280 /system/lib64/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+64)
#04 pc 0x0000000000056fc4 /system/lib64/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+224)
#05 pc 0x000000000004eb18 /system/lib64/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+312)
#06 pc 0x0000000000169a84 /system/lib64/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int)+400)
at android.os.BinderProxy.transactNative (Native method)
at android.os.BinderProxy.transact (BinderProxy.java:635)
at com.google.android.finsky.externalreferrer.IGetInstallReferrerService$Stub$Proxy.getInstallReferrer (IGetInstallReferrerService.java:117)
at com.android.installreferrer.api.InstallReferrerClientImpl.getInstallReferrer (InstallReferrerClientImpl.java:187)
at com.facebook.internal.InstallReferrerUtil$tryConnectReferrerInfo$installReferrerStateListener$1.onInstallReferrerSetupFinished (InstallReferrerUtil.kt:41)
at com.android.installreferrer.api.InstallReferrerClientImpl$InstallReferrerServiceConnection.onServiceConnected (InstallReferrerClientImpl.java:222)
at android.app.LoadedApk$ServiceDispatcher.doConnected (LoadedApk.java:2186)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run (LoadedApk.java:2219)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
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)
Same here.We've encountered the same ANR issue on Google Play Console. Does anyone have a solution for this?
Also having the same issue here. It would be great if this was fixed, as it currently accounts for 30% of our ANRs.