Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inter-process communication in Android

I am trying to develop an android app that reads the loaded HTML contents in the webview(of another background running app).

Getting idea from chrome remote debugging, it forwards tcp connections in a particular port to UNIX Domain socket

adb forward tcp:9222 localabstract:webview_devtools_remote_"process_id"

I tried to communicate with webview_devtools_remote_pid socket using LocalSocket as

    //https://developer.chrome.com/devtools/docs/protocol/1.1/page#command-enable
    JSONObject jo = new JSONObject();
    jo.put("id", 1);
    jo.put("method", "Page.enable");
    LocalSocket s = new LocalSocket();
    try {
        s.connect(new LocalSocketAddress("webview_devtools_remote_<p_id>"));
        OutputStream oss = s.getOutputStream();
        oss.write(jo.toString().getBytes("utf-8"));
        InputStream iss = s.getInputStream();
        Integer i;
        String res = "";
        while((i = iss.read()) != -1) {
            res += i.toString();
        }
    } catch (Exception e) {
        Log.e("Error", e.toString());
    }

but getting connection resetted by peer everytime.

EDIT: Sometimes getting java.io.IOException: Broken pipe

Any ideas about the issue.

Is there someother easier way to accomplish this ?

like image 737
venkatvb Avatar asked Jul 12 '26 19:07

venkatvb


1 Answers

I assume, you are trying to connect to remote web debugging socket from an application that runs on the same device? This is only possible if your app is running as "root", or as "shell" user, or if it is signed with the same key as the app you are connecting to, see the code.

Once you resolve this, you will need to adhere to DevTools remote debugging protocol in order to get to the HTML contents of the page, see the list of existing remote debugging clients and libraries.

like image 83
Mikhail Naganov Avatar answered Jul 15 '26 10:07

Mikhail Naganov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!