4

For a project, I am creating an android app that includes a WebView, a service that can switch from background to foreground and the LocationManager relying on the NETWORK_PROVIDER first and the GPS_PROVIDER later. In very random cases, upon starting the app, I find this exception in my logcat-output:

E/GoogleApiClientConnecting: GoogleApiClient connecting is in step STEP_SERVICE_BINDINGS_AND_SIGN_IN but received callback for step STEP_GETTING_REMOTE_SERVICE
    java.lang.Exception
        at qw.b(PG:25)
        at qw.c(PG:36)
        at Iw.c(PG:3)
        at Gx.c(PG:2)
        at ly.d(PG:15)
        at gy.a(PG:19)
        at iy.c(PG:6)
        at hy.handleMessage(PG:46)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at oG.dispatchMessage(PG:1)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:65)

I checked my code and my dependencies and I don't seem to have anything related to a GoogleApiClient (which I found was outdated anyways). I don't (consciously) use Google Play Store integration or such things.

This exception seems to have the effect of slowing down my WebView very much (every single XHR or fetch is stalled for almost exactly 3seconds). How this could possibly be related, I don't know.

Plus, it only happens occasionally when starting or restarting the app (sometimes after clearing all data).

Any help would be appreciated, this is bugging me out.

shoesel
  • 1,198
  • 8
  • 15
  • You registered wrong callback for your method. Check your import and callback method. – Kaushik Burkule Nov 06 '19 at 08:12
  • But I don't register anything in my app. I'm not even using something like a "GoogleApiClient". Somehow this `message` ends up in the MessageQueue of my app and I don't know how. – shoesel Nov 06 '19 at 08:21
  • If you're not directly using the GoogleApiClient seems like one of your libraries are. Run gradle app:dependencies to check where that is coming from. Also posting a log without obfuscation would be more useful ;) – davisjp Nov 08 '19 at 09:52
  • I did. There is nothing indicating any GoogleApi-dependency. I agree, not having to only see the obfuscated stacktrace should have helped, but that's what I got. Btw. I can't even debug this exception. Somehow the execution is not interrupted for that one. – shoesel Nov 08 '19 at 10:06
  • can you show us your dependency list? – Zohaib Amir Nov 08 '19 at 18:42
  • Have you found any solutions yet? I have the same issue at the moment. I already wrote an issue report to Google and I am waiting for the answer. Is it possible, that your application also opens multiple websockets? I think it could be tied to the websockets because I noticed that the exception doesn't occur on a webview with a single websocket. I also think, that it has to be tied to the Chrome engine since I couldn't replicate the issue on Chrome engine versions older then 78.0.3904 – Stefan Edenfeld Jan 10 '20 at 09:36
  • I made a GitHub project which explains how to reproduce the exception. My Github project has more information about the issue. This is the link to the Github Project: https://github.com/Ali-Kortak/Websocket-Test I also created my own Stackoverflow question about this Issue where I add some detail about my experience with this issue. The question can be found here: https://stackoverflow.com/questions/59659906/android-webview-becomes-slow-after-a-certain-exception – Stefan Edenfeld Jan 10 '20 at 09:36
  • Thx @StefanEdenfeld, I was not able to pursue this any further. Good to know, this does not only happen to my project. Pls check my answer below as it helped my to at least keep developing. It may not be a solution when you are providing your app to others, though. – shoesel Jan 13 '20 at 09:20

3 Answers3

3

We just found a good solution to deal with this issue. Google seems to be checking every URL you call within your application with Google-Play-Protect. For some reason some URL's have trouble passing this URL-Check therefore Google-Play-Protect somehow gets stuck while checking the URL.

To deal with this issue we found a way to whitelist the URL's we are using within our application. You can whitelist the URL's by calling the following method on your webview object:

webviewObject.setSafeBrowsingWhitelist(listOfURLs, null);

We also noticed that this improves the perfomance of calling these specific URL's by alot. Some URL's can be opened with much lower latency then before.

ali.12
  • 41
  • 4
2

The only workaround I found was to completely disable "Google Play Protect" on the device (Settings -> Google -> Security -> Google Play Protect -> Cogwheel at the top -> General -> Scan apps with Play Protect).

It is very invasive and potentially dangerous. (It's enough for my evaluation, though.)

shoesel
  • 1,198
  • 8
  • 15
0

As right mentioned in the comments it's about Google service usage. By looking to the source of Google Gms library you can find a reason for that. During library initialization.

1) In details Google Service is initializing as Bound Service in Android. And few int flags just used to annotate, whenever GoogleApiClient is ready of not. By using two values STEP_SERVICE_BINDINGS_AND_SIGN_IN and STEP_GETTING_REMOTE_SERVICE. Some of that resources decompiled and you can check them here.

2) In order to resolve your issue you need to check initializing of that Service from other dependencies. Root library is com.google.android.gms. You can check whenever this library in use by calling ./gradlew app:dependencies.

3) At the same time of finding this library you could check what is out of date. Usage of GoogleApiClient was deprecated and removed in 2017. So probably it's still used by old library which requires update.

GensaGames
  • 5,538
  • 4
  • 24
  • 53
  • Hey, thanks for the info. > I checked my code and my dependencies ..I already checked, `com.google.android.gms` is not in the output of `./gradlew app:dependencies` – shoesel Nov 15 '19 at 09:58
  • @shoesel Share your `Application` file, and MainActivity`. Let's check wahtever you initializing there. – GensaGames Nov 15 '19 at 17:12