尝试通过 TCP 通过 adb 连接到 Android 设备时显示“错误:已关闭”

问题描述 投票:0回答:2

我正在 ARMv7 开发板上构建 Android 系统。出于某种原因,我想使用“adb shell”从我的电脑上操作系统。由于Android系统使用NFS服务器作为根文件系统,因此开发板和PC通过以太网连接。这是我尝试过的(我在 Android 设备上具有 root 访问权限):

在Android设备上(使用putty通过串口访问):

android@ubuntu:~$ setprop service.adb.tcp.port 5555
android@ubuntu:~$ stop adbd
android@ubuntu:~$ start adbd

在 Ubuntu 主机上:

android@ubuntu:~$ adb connect 192.168.0.85:5555
connected to 192.168.0.85:5555
android@ubuntu:~$ adb shell
error: closed
android@ubuntu:~$ adb devices
List of devices attached
192.168.0.85:5555       device

如消息所示,通过 adb 的连接似乎成功(连接到...),但是我无法对其进行“adb shell”。最奇怪的是我仍然可以看到通过“adb devices”连接的设备。

我尝试终止 adb 服务器并重新启动它,但它也不起作用。

android tcp adb
2个回答
3
投票

我研究了

adb
的源码,用gdb调试,终于找到了根本原因。

基本上,为了响应主机命令

adb shell
adbd
(在Android设备上运行的守护进程)应该打开一个伪终端,并分叉另一个子进程来运行shell。这些在
create_subproc_pty
中的
system/core/adb/services.c
函数中实现:

static int create_subproc_pty(const char *cmd, const char *arg0, const char *arg1, pid_t *pid)
{
    ....

    int ptm;

    ptm = unix_open("/dev/ptmx", O_RDWR | O_CLOEXEC); // | O_NOCTTY);
    if(ptm < 0){
        printf("[ cannot open /dev/ptmx - %s ]\n",strerror(errno));
        return -1;
    }

    ....

    *pid = fork();
    if(*pid < 0) {
        printf("- fork failed: %s -\n", strerror(errno));
        adb_close(ptm);
        return -1;
    }

    ....
}

我在我的开发板上发现,

unix_open
功能失败了。这是因为 PTY 驱动程序没有内置到内核中,所以系统上找不到设备
/dev/ptmx

要解决这个问题,只需选择

Character Devices - Unix98 PTY
驱动程序并重建内核,然后
adb shell
就可以工作了。


0
投票

如何在命令行中选择字符设备 - Unix98 PTY?

© www.soinside.com 2019 - 2024. All rights reserved.