Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a88ef8c5 authored by Baligh Uddin's avatar Baligh Uddin
Browse files

Migrate system/core/adb to packages/modules/adb

BUG: 167963357
Test: TH
Merged-In: Ie1f82db2fb14e1bdd183bf8d3d93d5e9f974be5d
Change-Id: I8d5285f8a4ab3d1ace4004e023fd18d10d9d37a7
parent f31c5f56
Loading
Loading
Loading
Loading

adb/.clang-format

deleted120000 → 0
+0 −1
Original line number Diff line number Diff line
../.clang-format-4
 No newline at end of file

adb/Android.bp

deleted100644 → 0
+0 −821
Original line number Diff line number Diff line
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

cc_defaults {
    name: "adb_defaults",

    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-Wexit-time-destructors",
        "-Wno-unused-parameter",
        "-Wno-missing-field-initializers",
        "-Wthread-safety",
        "-Wvla",
        "-DADB_HOST=1",         // overridden by adbd_defaults
        "-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION=1",
    ],
    cpp_std: "experimental",

    use_version_lib: true,
    compile_multilib: "first",

    target: {
        darwin: {
            host_ldlibs: [
                "-lpthread",
                "-framework CoreFoundation",
                "-framework IOKit",
                "-lobjc",
            ],
        },

        windows: {
            cflags: [
                // Define windows.h and tchar.h Unicode preprocessor symbols so that
                // CreateFile(), _tfopen(), etc. map to versions that take wchar_t*, breaking the
                // build if you accidentally pass char*. Fix by calling like:
                //   std::wstring path_wide;
                //   if (!android::base::UTF8ToWide(path_utf8, &path_wide)) { /* error handling */ }
                //   CreateFileW(path_wide.c_str());
                "-DUNICODE=1",
                "-D_UNICODE=1",

                // Unlike on Linux, -std=gnu++ doesn't set _GNU_SOURCE on Windows.
                "-D_GNU_SOURCE",

                // MinGW hides some things behind _POSIX_SOURCE.
                "-D_POSIX_SOURCE",

                // libusb uses __stdcall on a variadic function, which gets ignored.
                "-Wno-ignored-attributes",

                // Not supported yet.
                "-Wno-thread-safety",
            ],

            host_ldlibs: [
                "-lws2_32",
                "-lgdi32",
                "-luserenv",
            ],
        },
    },
}

cc_defaults {
    name: "adbd_defaults",
    defaults: ["adb_defaults"],

    cflags: ["-UADB_HOST", "-DADB_HOST=0"],
}

cc_defaults {
    name: "host_adbd_supported",

    host_supported: true,
    target: {
        linux: {
            enabled: true,
            host_ldlibs: [
                "-lresolv", // b64_pton
                "-lutil", // forkpty
            ],
        },
        darwin: {
            enabled: false,
        },
        windows: {
            enabled: false,
        },
    },
}

cc_defaults {
    name: "libadbd_binary_dependencies",
    static_libs: [
        "libadb_crypto",
        "libadb_pairing_connection",
        "libadb_tls_connection",
        "libadbd",
        "libadbd_core",
        "libadbconnection_server",
        "libasyncio",
        "libbrotli",
        "libcutils_sockets",
        "libdiagnose_usb",
        "libmdnssd",
        "libbase",

        "libadb_protos",
    ],

    shared_libs: [
        "libadbd_auth",
        "libadbd_fs",
        "libcrypto",
        "libcrypto_utils",
        "liblog",
        "libselinux",
    ],

    target: {
        recovery: {
            exclude_static_libs: [
                "libadb_pairing_auth",
                "libadb_pairing_connection",
            ],
        },
    },
}

// libadb
// =========================================================
// These files are compiled for both the host and the device.
libadb_srcs = [
    "adb.cpp",
    "adb_io.cpp",
    "adb_listeners.cpp",
    "adb_trace.cpp",
    "adb_unique_fd.cpp",
    "adb_utils.cpp",
    "fdevent/fdevent.cpp",
    "fdevent/fdevent_poll.cpp",
    "services.cpp",
    "sockets.cpp",
    "socket_spec.cpp",
    "sysdeps/errno.cpp",
    "transport.cpp",
    "transport_fd.cpp",
    "transport_local.cpp",
    "types.cpp",
]

libadb_posix_srcs = [
    "sysdeps_unix.cpp",
    "sysdeps/posix/network.cpp",
]

libadb_linux_srcs = [
    "fdevent/fdevent_epoll.cpp",
]

libadb_test_srcs = [
    "adb_io_test.cpp",
    "adb_listeners_test.cpp",
    "adb_utils_test.cpp",
    "fdevent/fdevent_test.cpp",
    "socket_spec_test.cpp",
    "socket_test.cpp",
    "sysdeps_test.cpp",
    "sysdeps/stat_test.cpp",
    "transport_test.cpp",
    "types_test.cpp",
]

cc_library_host_static {
    name: "libadb_host",
    defaults: ["adb_defaults"],

    srcs: libadb_srcs + [
        "client/auth.cpp",
        "client/adb_wifi.cpp",
        "client/usb_libusb.cpp",
        "client/usb_dispatch.cpp",
        "client/transport_mdns.cpp",
        "client/transport_usb.cpp",
        "client/pairing/pairing_client.cpp",
    ],

    generated_headers: ["platform_tools_version"],

    target: {
        linux: {
            srcs: ["client/usb_linux.cpp"] + libadb_linux_srcs,
        },
        darwin: {
            srcs: ["client/usb_osx.cpp"],
        },
        not_windows: {
            srcs: libadb_posix_srcs,
        },
        windows: {
            enabled: true,
            srcs: [
                "client/usb_windows.cpp",
                "sysdeps_win32.cpp",
                "sysdeps/win32/errno.cpp",
                "sysdeps/win32/stat.cpp",
            ],
            shared_libs: ["AdbWinApi"],
        },
    },

    static_libs: [
        "libadb_crypto",
        "libadb_protos",
        "libadb_pairing_connection",
        "libadb_tls_connection",
        "libbase",
        "libcrypto_utils",
        "libcrypto",
        "libdiagnose_usb",
        "libmdnssd",
        "libusb",
        "libutils",
        "liblog",
        "libcutils",
        "libprotobuf-cpp-lite",
    ],
}

cc_test_host {
    name: "adb_test",
    defaults: ["adb_defaults"],
    srcs: libadb_test_srcs,
    static_libs: [
        "libadb_crypto_static",
        "libadb_host",
        "libadb_pairing_auth_static",
        "libadb_pairing_connection_static",
        "libadb_protos_static",
        "libadb_tls_connection_static",
        "libbase",
        "libcutils",
        "libcrypto_utils",
        "libcrypto",
        "liblog",
        "libmdnssd",
        "libdiagnose_usb",
        "libprotobuf-cpp-lite",
        "libssl",
        "libusb",
    ],

    target: {
        windows: {
            enabled: true,
            ldflags: ["-municode"],
            shared_libs: ["AdbWinApi"],
        },
    },
}

cc_binary_host {
    name: "adb",

    stl: "libc++_static",
    defaults: ["adb_defaults"],

    srcs: [
        "client/adb_client.cpp",
        "client/bugreport.cpp",
        "client/commandline.cpp",
        "client/file_sync_client.cpp",
        "client/main.cpp",
        "client/console.cpp",
        "client/adb_install.cpp",
        "client/line_printer.cpp",
        "client/fastdeploy.cpp",
        "client/fastdeploycallbacks.cpp",
        "client/incremental.cpp",
        "client/incremental_server.cpp",
        "client/incremental_utils.cpp",
        "shell_service_protocol.cpp",
    ],

    generated_headers: [
        "bin2c_fastdeployagent",
        "bin2c_fastdeployagentscript"
    ],

    static_libs: [
        "libadb_crypto",
        "libadb_host",
	"libadb_pairing_auth",
	"libadb_pairing_connection",
        "libadb_protos",
        "libadb_tls_connection",
        "libandroidfw",
        "libbase",
        "libbrotli",
        "libcutils",
        "libcrypto_utils",
        "libcrypto",
        "libfastdeploy_host",
        "libdiagnose_usb",
        "liblog",
        "liblz4",
        "libmdnssd",
        "libprotobuf-cpp-lite",
        "libssl",
        "libusb",
        "libutils",
        "liblog",
        "libziparchive",
        "libz",
    ],

    // Don't add anything here, we don't want additional shared dependencies
    // on the host adb tool, and shared libraries that link against libc++
    // will violate ODR
    shared_libs: [],

    // Archive adb, adb.exe.
    dist: {
        targets: [
            "dist_files",
            "sdk",
            "win_sdk",
        ],
    },

    target: {
        darwin: {
            cflags: [
                "-Wno-sizeof-pointer-memaccess",
            ],
        },
        windows: {
            enabled: true,
            ldflags: ["-municode"],
            shared_libs: ["AdbWinApi"],
            required: [
                "AdbWinUsbApi",
            ],
        },
    },
}

// libadbd_core contains the common sources to build libadbd and libadbd_services.
cc_library_static {
    name: "libadbd_core",
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,

    // libminadbd wants both, as it's used to build native tests.
    compile_multilib: "both",

    srcs: libadb_srcs + libadb_linux_srcs + libadb_posix_srcs + [
        "daemon/auth.cpp",
        "daemon/jdwp_service.cpp",
        "daemon/logging.cpp",
        "daemon/adb_wifi.cpp",
    ],

    generated_headers: ["platform_tools_version"],

    static_libs: [
        "libadbconnection_server",
        "libdiagnose_usb",
    ],

    shared_libs: [
        "libadb_crypto",
        "libadb_pairing_connection",
        "libadb_protos",
        "libadb_tls_connection",
        "libadbd_auth",
        "libasyncio",
        "libbase",
        "libcrypto",
        "libcrypto_utils",
        "libcutils_sockets",
        "liblog",
    ],

    target: {
        android: {
            whole_static_libs: [
                "libqemu_pipe",
            ],
            srcs: [
                "daemon/transport_qemu.cpp",
                "daemon/usb.cpp",
                "daemon/usb_ffs.cpp",
            ]
        },
        recovery: {
            exclude_shared_libs: [
                "libadb_pairing_auth",
                "libadb_pairing_connection",
            ],
        }
    },

    apex_available: [
        "//apex_available:platform",
        "com.android.adbd",
    ],
    visibility: [
        "//bootable/recovery/minadbd",
        "//system/core/adb",
    ],
}

cc_library {
    name: "libadbd_services",
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,
    compile_multilib: "both",

    srcs: [
        "daemon/file_sync_service.cpp",
        "daemon/services.cpp",
        "daemon/shell_service.cpp",
        "shell_service_protocol.cpp",
    ],

    cflags: [
        "-D_GNU_SOURCE",
        "-Wno-deprecated-declarations",
    ],

    static_libs: [
        "libadbconnection_server",
        "libadbd_core",
        "libbrotli",
        "libdiagnose_usb",
    ],

    shared_libs: [
        "libadb_crypto",
        "libadb_pairing_connection",
        "libadb_protos",
        "libadb_tls_connection",
        "libasyncio",
        "libbase",
        "libcrypto_utils",
        "libcutils_sockets",

        // APEX dependencies.
        "libadbd_auth",
        "libadbd_fs",
        "libcrypto",
        "liblog",
    ],

    target: {
        android: {
            srcs: [
                "daemon/abb_service.cpp",
                "daemon/framebuffer_service.cpp",
                "daemon/mdns.cpp",
                "daemon/restart_service.cpp",
            ],
            shared_libs: [
                "libmdnssd",
                "libselinux",
            ],
        },
        recovery: {
            exclude_srcs: [
                "daemon/abb_service.cpp",
            ],
            exclude_shared_libs: [
                "libadb_pairing_auth",
                "libadb_pairing_connection",
            ],
        },
    },

    apex_available: [
        "//apex_available:platform",
        "com.android.adbd",
    ],
    visibility: [
        "//system/core/adb",
    ],

}

cc_library {
    name: "libadbd",
    defaults: ["adbd_defaults", "host_adbd_supported"],
    recovery_available: true,
    apex_available: ["com.android.adbd"],

    // avoid getting duplicate symbol of android::build::getbuildnumber().
    use_version_lib: false,

    // libminadbd wants both, as it's used to build native tests.
    compile_multilib: "both",

    shared_libs: [
        "libadb_crypto",
        "libadb_pairing_connection",
        "libadb_tls_connection",
        "libasyncio",
        "libbase",
        "libcrypto",
        "libcrypto_utils",
        "liblog",
        "libselinux",

        // APEX dependencies on the system image.
        "libadbd_auth",
        "libadbd_fs",
        "libadbd_services",
    ],

    target: {
        recovery: {
            exclude_shared_libs: [
                "libadb_pairing_auth",
                "libadb_pairing_connection",
            ],
        }
    },

    static_libs: [
        "libadbd_core",
        "libbrotli",
        "libcutils_sockets",
        "libdiagnose_usb",
        "libmdnssd",
    ],

    visibility: [
        "//bootable/recovery/minadbd",
        "//system/core/adb",
    ],
}

cc_binary {
    name: "adbd",
    defaults: ["adbd_defaults", "host_adbd_supported", "libadbd_binary_dependencies"],
    recovery_available: true,
    apex_available: ["com.android.adbd"],

    srcs: [
        "daemon/main.cpp",
    ],

    cflags: [
        "-D_GNU_SOURCE",
        "-Wno-deprecated-declarations",
    ],

    strip: {
        keep_symbols: true,
    },

    static_libs: [
        "libadbd",
        "libadbd_services",
        "libasyncio",
        "libcap",
        "libminijail",
        "libssl",
    ],

    shared_libs: [
        "libadb_protos",
        "libadbd_auth",
    ],

    target: {
        recovery: {
            exclude_shared_libs: [
                "libadb_pairing_auth",
                "libadb_pairing_connection",
            ],
        }
    },
}

phony {
    // Interface between adbd in a module and the system.
    name: "adbd_system_api",
    required: [
        "libadbd_auth",
        "libadbd_fs",
        "abb",
        "reboot",
        "set-verity-state",
    ]
}

phony {
    name: "adbd_system_api_recovery",
    required: [
        "libadbd_auth",
        "libadbd_fs",
        "reboot.recovery",
    ],
}

cc_binary {
    name: "abb",

    defaults: ["adbd_defaults"],
    stl: "libc++",
    recovery_available: false,

    srcs: [
        "daemon/abb.cpp",
    ],

    cflags: [
        "-D_GNU_SOURCE",
        "-Wno-deprecated-declarations",
    ],

    strip: {
        keep_symbols: true,
    },

    static_libs: [
        "libadbd_core",
        "libadbd_services",
        "libcmd",
    ],

    shared_libs: [
        "libbase",
        "libbinder",
        "liblog",
        "libutils",
        "libselinux",
    ],
}

cc_test {
    name: "adbd_test",

    defaults: ["adbd_defaults", "libadbd_binary_dependencies"],

    recovery_available: false,
    srcs: libadb_test_srcs + [
        "daemon/services.cpp",
        "daemon/shell_service.cpp",
        "daemon/shell_service_test.cpp",
        "shell_service_protocol.cpp",
        "shell_service_protocol_test.cpp",
        "mdns_test.cpp",
    ],

    test_config: "adb_test.xml",

    shared_libs: [
        "liblog",
    ],

    static_libs: [
        "libadbd",
        "libadbd_auth",
        "libbase",
        "libcrypto_utils",
        "libusb",
    ],
    test_suites: ["device-tests", "mts"],
    require_root: true,
}

python_test_host {
    name: "adb_integration_test_adb",
    main: "test_adb.py",
    srcs: [
        "test_adb.py",
    ],
    test_config: "adb_integration_test_adb.xml",
    test_suites: ["general-tests"],
    version: {
        py2: {
            enabled: false,
        },
        py3: {
            enabled: true,
        },
    },
}

python_test_host {
    name: "adb_integration_test_device",
    main: "test_device.py",
    srcs: [
        "test_device.py",
    ],
    libs: [
        "adb_py",
    ],
    test_config: "adb_integration_test_device.xml",
    test_suites: ["general-tests"],
    version: {
        py2: {
            enabled: false,
        },
        py3: {
            enabled: true,
        },
    },
}

// Note: using pipe for xxd to control the variable name generated
// the default name used by xxd is the path to the input file.
java_genrule {
    name: "bin2c_fastdeployagent",
    out: ["deployagent.inc"],
    srcs: [":deployagent"],
    cmd: "(echo 'unsigned char kDeployAgent[] = {' && xxd -i <$(in) && echo '};') > $(out)",
}

genrule {
    name: "bin2c_fastdeployagentscript",
    out: ["deployagentscript.inc"],
    srcs: ["fastdeploy/deployagent/deployagent.sh"],
    cmd: "(echo 'unsigned char kDeployAgentScript[] = {' && xxd -i <$(in) && echo '};') > $(out)",
}

cc_library_host_static {
    name: "libfastdeploy_host",
    defaults: ["adb_defaults"],
    srcs: [
        "fastdeploy/deploypatchgenerator/apk_archive.cpp",
        "fastdeploy/deploypatchgenerator/deploy_patch_generator.cpp",
        "fastdeploy/deploypatchgenerator/patch_utils.cpp",
        "fastdeploy/proto/ApkEntry.proto",
    ],
    static_libs: [
        "libadb_host",
        "libandroidfw",
        "libbase",
        "libcutils",
        "libcrypto_utils",
        "libcrypto",
        "libdiagnose_usb",
        "liblog",
        "libmdnssd",
        "libusb",
        "libutils",
        "libziparchive",
        "libz",
    ],
    proto: {
        type: "lite",
        export_proto_headers: true,
    },
    target: {
        windows: {
            enabled: true,
            shared_libs: ["AdbWinApi"],
        },
    },
}

cc_test_host {
    name: "fastdeploy_test",
    defaults: ["adb_defaults"],
    srcs: [
        "fastdeploy/deploypatchgenerator/apk_archive_test.cpp",
        "fastdeploy/deploypatchgenerator/deploy_patch_generator_test.cpp",
        "fastdeploy/deploypatchgenerator/patch_utils_test.cpp",
    ],
    static_libs: [
        "libadb_crypto_static",
        "libadb_host",
        "libadb_pairing_auth_static",
        "libadb_pairing_connection_static",
        "libadb_protos_static",
        "libadb_tls_connection_static",
        "libandroidfw",
        "libbase",
        "libcutils",
        "libcrypto_utils",
        "libcrypto",
        "libdiagnose_usb",
        "libfastdeploy_host",
        "liblog",
        "libmdnssd",
        "libprotobuf-cpp-lite",
        "libssl",
        "libusb",
        "libutils",
        "libziparchive",
        "libz",
    ],
    target: {
        windows: {
            enabled: true,
            shared_libs: ["AdbWinApi"],
        },
    },
    data: [
        "fastdeploy/testdata/rotating_cube-metadata-release.data",
        "fastdeploy/testdata/rotating_cube-release.apk",
        "fastdeploy/testdata/sample.apk",
        "fastdeploy/testdata/sample.cd",
    ],
}

adb/MODULE_LICENSE_APACHE2

deleted100644 → 0
+0 −0

Empty file deleted.

adb/NOTICE

deleted100644 → 0
+0 −191

File deleted.

Preview size limit exceeded, changes collapsed.

adb/OVERVIEW.TXT

deleted100644 → 0
+0 −135
Original line number Diff line number Diff line
Implementation notes regarding ADB.

I. General Overview:

The Android Debug Bridge (ADB) is used to:

- keep track of all Android devices and emulators instances
  connected to or running on a given host developer machine

- implement various control commands (e.g. "adb shell", "adb pull", etc.)
  for the benefit of clients (command-line users, or helper programs like
  DDMS). These commands are called 'services' in ADB.

As a whole, everything works through the following components:

  1. The ADB server

    This is a background process that runs on the host machine. Its purpose
    is to sense the USB ports to know when devices are attached/removed,
    as well as when emulator instances start/stop.

    It thus maintains a list of "connected devices" and assigns a 'state'
    to each one of them: OFFLINE, BOOTLOADER, RECOVERY or ONLINE (more on
    this below).

    The ADB server is really one giant multiplexing loop whose purpose is
    to orchestrate the exchange of data (packets, really) between clients,
    services and devices.


  2. The ADB daemon (adbd)

    The 'adbd' program runs as a background process within an Android device
    or emulated system. Its purpose is to connect to the ADB server
    (through USB for devices, through TCP for emulators) and provide a
    few services for clients that run on the host.

    The ADB server considers that a device is ONLINE when it has successfully
    connected to the adbd program within it. Otherwise, the device is OFFLINE,
    meaning that the ADB server detected a new device/emulator, but could not
    connect to the adbd daemon.

    The BOOTLOADER and RECOVERY states correspond to alternate states of
    devices when they are in the bootloader or recovery mode.

  3. The ADB command-line client

    The 'adb' command-line program is used to run adb commands from a shell
    or a script. It first tries to locate the ADB server on the host machine,
    and will start one automatically if none is found.

    Then, the client sends its service requests to the ADB server.

    Currently, a single 'adb' binary is used for both the server and client.
    this makes distribution and starting the server easier.


  4. Services

    There are essentially two kinds of services that a client can talk to.

    Host Services:
      These services run within the ADB Server and thus do not need to
      communicate with a device at all. A typical example is "adb devices"
      which is used to return the list of currently known devices and their
      states. They are a few other services though.

    Local Services:
      These services either run within the adbd daemon, or are started by
      it on the device. The ADB server is used to multiplex streams
      between the client and the service running in adbd. In this case
      its role is to initiate the connection, then of being a pass-through
      for the data.


II. Protocol details:

  1. Client <-> Server protocol:

    This details the protocol used between ADB clients and the ADB
    server itself. The ADB server listens on TCP:localhost:5037.

    A client sends a request using the following format:

        1. A 4-byte hexadecimal string giving the length of the payload
        2. Followed by the payload itself.

    For example, to query the ADB server for its internal version number,
    the client will do the following:

        1. Connect to tcp:localhost:5037
        2. Send the string "000Chost:version" to the corresponding socket

    The 'host:' prefix is used to indicate that the request is addressed
    to the server itself (we will talk about other kinds of requests later).
    The content length is encoded in ASCII for easier debugging.

    The server should answer a request with one of the following:

        1. For success, the 4-byte "OKAY" string

        2. For failure, the 4-byte "FAIL" string, followed by a
           4-byte hex length, followed by a string giving the reason
           for failure.

    Note that the connection is still alive after an OKAY, which allows the
    client to make other requests. But in certain cases, an OKAY will even
    change the state of the connection.

    For example, the case of the 'host:transport:<serialnumber>' request,
    where '<serialnumber>' is used to identify a given device/emulator; after
    the "OKAY" answer, all further requests made by the client will go
    directly to the corresponding adbd daemon.

    The file SERVICES.TXT lists all services currently implemented by ADB.


  2. Transports:

    An ADB transport models a connection between the ADB server and one device
    or emulator. There are currently two kinds of transports:

       - USB transports, for physical devices through USB

       - Local transports, for emulators running on the host, connected to
         the server through TCP

    In theory, it should be possible to write a local transport that proxies
    a connection between an ADB server and a device/emulator connected to/
    running on another machine. This hasn't been done yet though.

    Each transport can carry one or more multiplexed streams between clients
    and the device/emulator they point to. The ADB server must handle
    unexpected transport disconnections (e.g. when a device is physically
    unplugged) properly.
Loading