facebook-android-sdk icon indicating copy to clipboard operation
facebook-android-sdk copied to clipboard

`com.android.installreferrer` is called in the main thread which leads to ANR

Open ddovod opened this issue 2 years ago • 19 comments

Checklist before submitting a bug report

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

ddovod avatar Jan 17 '22 15:01 ddovod

Can you give me script attack for apk???

Gell6 avatar Feb 23 '22 15:02 Gell6

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

KulArtsiom avatar Apr 14 '22 15:04 KulArtsiom

same issue

Lok1n8 avatar Mar 13 '23 05:03 Lok1n8

same issue

jasoncfpl avatar Apr 21 '23 03:04 jasoncfpl

Issue is not fixed, we observe exact the same issue on FBSDK 16.0.1

OldSlash avatar Apr 26 '23 10:04 OldSlash

@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.

EllieTellie avatar May 04 '23 12:05 EllieTellie

Any updates on this? Getting exactly the same ANR on Play Console, not so rare. Using Unity SDK 15.1.0.

burak-cypher avatar Jul 28 '23 13:07 burak-cypher

Having the same issue. Any updates here ?

rampr avatar Jul 31 '23 04:07 rampr

Having the same issue any update on this ?

umeriqbalbutt avatar Aug 21 '23 08:08 umeriqbalbutt

We're on 16.2.0 and we're still seeing the same issue. Is there an update on when this will be fixed?

AshikRaj avatar Oct 13 '23 18:10 AshikRaj

Same issue here. Come on folks, please fix this!

rubenwe avatar Oct 29 '23 10:10 rubenwe

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)

Holla-Chris avatar Feb 18 '24 03:02 Holla-Chris

same issue

jygao avatar Feb 26 '24 03:02 jygao

Any fix for this, we are also experiencing similar issue

manjeetcars24 avatar Mar 04 '24 10:03 manjeetcars24

Also same here +1

alkanyunus avatar Mar 07 '24 14:03 alkanyunus

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,

zahid-abstron avatar Mar 28 '24 05:03 zahid-abstron

"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?

zhaowhao avatar Apr 02 '24 08:04 zhaowhao

Also having the same issue here. It would be great if this was fixed, as it currently accounts for 30% of our ANRs.

Ceikry avatar Apr 12 '24 17:04 Ceikry