Skip to content

非root调试WebView方案 #4

@nonameShijian

Description

@nonameShijian

我自己项目想内置一个调试自身应用内WebView的功能,目前我可以通过Shizuku权限获取到抽象套接字(webview_devtools_remote_xxx),然后参考本项目,通过ai编写代码,确实可以做到了,参考的本项目代码进行双向绑定。主要就是在shizuku进程里去绑定套接字就可以了,其它的在app进程里实现

限制是只有调试状态下的app才可以

 @Override
    public void bindLocalSocketBridge(String socketName, ParcelFileDescriptor clientSocket) {
        Log.i(TAG, "bindLocalSocketBridge called for @" + socketName);

        executor.execute(() -> {
            LocalSocket localSocket = null;
            try {
                // 1. 连接到WebView的抽象Socket
                localSocket = new LocalSocket();
                LocalSocketAddress address = new LocalSocketAddress(
                        socketName,
                        LocalSocketAddress.Namespace.ABSTRACT
                );
                localSocket.connect(address);

                Log.i(TAG, "Successfully connected to @" + socketName);

                // 2. 获取双向流
                InputStream localInput = localSocket.getInputStream();
                OutputStream localOutput = localSocket.getOutputStream();

                InputStream clientInput = new ParcelFileDescriptor.AutoCloseInputStream(clientSocket);
                OutputStream clientOutput = new ParcelFileDescriptor.AutoCloseOutputStream(clientSocket);

                // 3. 创建会话并保存
                SocketBridgeSession session = new SocketBridgeSession(
                        socketName, localSocket, clientSocket,
                        localInput, localOutput, clientInput, clientOutput
                );
                activeSessions.put(socketName, session);

                // 4. 启动双向数据转发
                session.startForwarding();

                Log.i(TAG, "Bridge established for @" + socketName);

            } catch (Exception e) {
                Log.e(TAG, "Failed to establish bridge for @" + socketName, e);
                try {
                    if (localSocket != null) localSocket.close();
                    clientSocket.close();
                } catch (IOException ignored) {}
            }
        });
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions