Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

再起動したあと自動的にadb tcpipを有効化する (root化必要)

More than 1 year has passed since last update.

モチベ

scrcpyするときにいちいちUSBつないでtcpipするのめんどくさい

環境

Nexus 5 無印 (タッチスクリーンが壊れてる)
Android 6.0.1 Mashmallow

手順

  1. adb shell
  2. su
  3. setprop persist.adb.tcp.port 5555
  4. 端末再起動して adb shell getprop で persist.adb.tcp.port があればOK

ソース

https://stackoverflow.com/questions/12251101/how-to-enable-adbd-to-listen-to-a-port-at-boot-time-in-android

This will make it persistent:

setprop persist.adb.tcp.port 5555

https://android.googlesource.com/platform/system/core/+/refs/heads/marshmallow-release/adb/adb_main.cpp

    // If one of these properties is set, also listen on that port
    // If one of the properties isn't set and we couldn't listen on usb,
    // listen on the default port.
    property_get("service.adb.tcp.port", value, "");
    if (!value[0]) {
        property_get("persist.adb.tcp.port", value, "");
    }
    if (sscanf(value, "%d", &port) == 1 && port > 0) {
        printf("using port=%d\n", port);
        // listen on TCP port specified by service.adb.tcp.port property
        local_init(port);
    } else if (!usb) {
        // listen on default port
        local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
    }

https://android.stackexchange.com/questions/151053/difference-between-system-build-prop-properties-and-setprop-persist-adb-tcp-por

To answer your 2 last questions, according to several sources (1, 2, 3), thoses are stored in /data/property/. I couldn't find an offical reference about this location though.

For you, that would be in /data/property/persist.adb.tcp.port.

余談

  • https://forum.xda-developers.com/showthread.php?t=635102 によると service.adb.tcp.port でも行けるみたいな感じだが再起動したら消えてしまった
  • ssh root@192.168.3.109 -L 5555:localhost:5037 みたいな感じでadbdへSSH Port Forwardingするのは妙案だと思った。これならrootなくても行ける?だれか試して。今回scrcpyはなるべくオーバーヘッド下げたいので正攻法でやった。
Nanashia
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away