3

I am trying to establish a connection between my android application and chrome on android. I am using LocalSocket for socket communication as below:

        JSONObject request = new JSONObject();
        request.put("method", "Page.reload");
        LocalSocket s = new LocalSocket();
    try {
        s.connect(new LocalSocketAddress("chrome_devtools_remote", LocalSocketAddress.Namespace.ABSTRACT));
        Log.i("Chrome: ", "After local socket connect");
        //StringBuilder request = new StringBuilder().append("GET /json HTTP/1.0\r\n");
        OutputStream oss = s.getOutputStream();
        byte[] buffer = jo.toString().getBytes("utf-8");
        oss.write(buffer, 0, buffer.length);
        Log.i("Chrome: ", "outbuf size " + Integer.toString(s.getSendBufferSize()));
        InputStream iss = s.getInputStream();
        Integer i;
        String res = "";
        while ((i = iss.read()) != -1) {
            res += i.toString();
        }
        Log.i("Chrome: ", res);
    } catch (Exception e) {
        Log.e("Error", "Connecting Local Socket "+e.toString());
    }

I am able to establish the connection between Chrome and my App, but I am not able to send and receive messages to automate page loads in chrome.

mdasari
  • 423
  • 4
  • 11

1 Answers1

2

Chrome does not allow every app to connect to the devtool socket. It makes sure the connecting app is either signed with the same key or the user is root or shell. The source code for this security logic can be found here.

In case the security check fails it prints the following message, which you should see in logcat:

DevTools: connection attempt from

dkarv
  • 73
  • 5