4

I am using the latest & greatest Android Studio version:

Android Studio Flamingo | 2022.2.1
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023
Runtime version: 17.0.6+0-b2043.56-9586694 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0

So far, it works beautifully, but when I am trying to inspect traffic details as described in https://developer.android.com/studio/debug/network-profiler , I am getting an empty Connection View tab in the Network Inspector window:

Network inspector data unavailable

I may be missing something trivial in how I configure and operate: What do I need to do in order to view populated Connection View rows as seen in the formal documentation?

Properly populated Connection View rows

Note: The formal documentation states that

"Currently, the Network Inspector supports only the HttpsURLConnection and OkHttp libraries for network connections. If your app uses another network connection library, you might not be able to view your network activity in the Network Inspector."

How can I tell whether WebView.loadUrl() uses HttpsURLConnection and/or OkHttp?


Update: By mere chance, I managed to "catch a blip" on Network inspector due to another piece in my code using HttpURLConnection:

HttpURLConnection httpConnection = null;
try {
    URL testurl = new URL("https://www.google.com");
    URLConnection connection = testurl.openConnection();
    connection.setConnectTimeout(5 * 1000);

    httpConnection = (HttpURLConnection) connection;
    int responseCode = httpConnection.getResponseCode();
    ...
}

Connection View shows that request along with the associated data (as desired):

HttpURLConnection Connection View

So, my two questions now are:

  1. How can I tell whether WebView.loadUrl() uses HttpsURLConnection and/or OkHttp?
  2. What do I need to do in order to view populated Connection View rows for WebView.loadUrl() ?
Introspective
  • 554
  • 2
  • 5
  • 13
  • 1
    That is just fabulous. Not able to work on legacy flutter project because of this. Such a shame. – alehro Aug 02 '23 at 11:32
  • It appears that for flutter apps we need to use flatter dev tools. This is small icon in debug window. It opens dev tools in browser. – alehro Aug 06 '23 at 13:14

1 Answers1

2

This older answer appears to be the best I've found so far, that Webview "uses a snapshot of the Chrome network stack or for pre-HC devices the WebKit network stack." From marcin.kosiba's answer.

This answer provides a method for forcibly using OkHttp as the actual network stack and shouldInterceptRequest. See Michalsx's answer.

From this article, the question on Webview is not easy either, as Webview keeps getting changed by Google.

"Early versions of WebView were integrated as part of the core OS. With the release of Android 5.0, Google separated WebView from the core OS. Google combined WebView with Google Chrome for versions 7.0, 8.0 and 9.0. With Android 10.0, it went back to having it as a separate component."

From Developer - Managing WebView objects "Starting in Android 7.0 (API level 24), users can choose among several different packages for displaying web content in a WebView object...display web content using a particular package's implementation of WebView."

G. Putnam
  • 1,262
  • 5
  • 10
  • Thank you for picking up the gauntlet - not an easy one. Your answer is by far the best answer so far. :-) Awarding the bounty although I still don't know how to make `WebView.loadUrl()` traffic show up on `Connection View` rows. – Introspective May 08 '23 at 19:45
  • Thank you for the comment and the bounty award. I suspect that forcibly using OkHttp as the actual network stack may be one of the easiest approaches to having `WebView.loadUrl()` traffic show up on `Connection View` since its specifically among the network stacks supported. – G. Putnam May 08 '23 at 23:28
  • 1
    It appears that `Network Inspector` itself has a related open bug: https://issuetracker.google.com/issues/168580257 – Introspective May 09 '23 at 07:32
  • In your case, does the partial fix of stopping and then reattaching the process fix the issue (at least temporarily?) – G. Putnam May 09 '23 at 17:16
  • I tried the partial fix but it didn't help. Looks like `WebView` isn't using `HttpURLConnection`. – Introspective May 09 '23 at 19:30