Loading libs/adbd_auth/Android.bp +19 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package { // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_native_license"], default_team: "trendy_team_android_developer_tools", } cc_library { Loading @@ -45,7 +46,7 @@ cc_library { target: { darwin: { enabled: false, } }, }, static_libs: [ Loading @@ -54,3 +55,20 @@ cc_library { "liblog", ], } cc_test { name: "libadbd_auth_test", srcs: [ "adbd_auth_test.cpp", ], static_libs: [ "libadbd_auth", "libbase", "libcutils", "liblog", ], test_suites: [ "cts", "general-tests", ], } libs/adbd_auth/adbd_auth.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -69,11 +69,16 @@ struct AdbdPacketTlsDeviceDisconnected { std::string public_key; }; struct AdbdPacketTlsServerPort { uint16_t port; }; using AdbdAuthPacket = std::variant<AdbdAuthPacketAuthenticated, AdbdAuthPacketDisconnected, AdbdAuthPacketRequestAuthorization, AdbdPacketTlsDeviceConnected, AdbdPacketTlsDeviceDisconnected>; AdbdPacketTlsDeviceDisconnected, AdbdPacketTlsServerPort>; struct AdbdAuthContext { static constexpr uint64_t kEpollConstSocket = 0; Loading Loading @@ -249,6 +254,7 @@ public: auto& packet = output_queue_.front(); struct iovec iovs[3]; int iovcnt = 2; if (auto* p = std::get_if<AdbdAuthPacketAuthenticated>(&packet)) { iovs[0].iov_base = const_cast<char*>("CK"); iovs[0].iov_len = 2; Loading Loading @@ -280,10 +286,18 @@ public: iovs[1].iov_len = 1; iovs[2].iov_base = p->public_key.data(); iovs[2].iov_len = p->public_key.size(); } else if (auto* p = std::get_if<AdbdPacketTlsServerPort>(&packet)) { iovcnt = 2; iovs[0].iov_base = const_cast<char*>("TP"); iovs[0].iov_len = 2; iovs[1].iov_base = &p->port; iovs[1].iov_len = 2; } else { LOG(FATAL) << "adbd_auth: unhandled packet type?"; } LOG(INFO) << "adbd_auth: sending packet: " << std::string((const char*)iovs[0].iov_base, 2); ssize_t rc = writev(framework_fd_.get(), iovs, iovcnt); output_queue_.pop_front(); if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { Loading Loading @@ -469,6 +483,14 @@ public: Interrupt(); } void SendTLSServerPort(uint16_t port) { std::lock_guard<std::mutex> lock(mutex_); output_queue_.emplace_back(AdbdPacketTlsServerPort{ .port = port }); Interrupt(); } // Interrupt the worker thread to do some work. void Interrupt() { uint64_t value = 1; Loading Loading @@ -588,3 +610,7 @@ bool adbd_auth_supports_feature(AdbdAuthFeature f) { UNUSED(f); return false; } void adbd_auth_send_tls_server_port(AdbdAuthContext* ctx, uint16_t port) { ctx->SendTLSServerPort(port); } libs/adbd_auth/adbd_auth_test.cpp 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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. */ #include <gtest/gtest.h> #include <stddef.h> #include <stdint.h> #include "adbd_auth.h" class AdbAuthTest: public ::testing::Test { public: void SetUp() { AdbdAuthCallbacks callbacks = {.version = 1}; context = adbd_auth_new(&callbacks); } void TearDown() { adbd_auth_delete(context); } protected: AdbdAuthContext* context; }; TEST_F(AdbAuthTest, SendTcpPort) { adbd_auth_send_tls_server_port(context, 1); } No newline at end of file libs/adbd_auth/include/adbd_auth.h +8 −0 Original line number Diff line number Diff line Loading @@ -185,4 +185,12 @@ enum AdbdAuthFeature : int32_t { */ bool adbd_auth_supports_feature(AdbdAuthFeature feature); /** * Advertise the port number the TLS server is running on. 0 = not running. * * @param ctx the AdbdAuthContext * @param port the port number the TLS server is running on. */ void adbd_auth_send_tls_server_port(AdbdAuthContext* ctx, uint16_t port) __INTRODUCED_IN(37); __END_DECLS libs/adbd_auth/libadbd_auth.map.txt +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ LIBADBD_AUTH { adbd_auth_tls_device_disconnected; # systemapi introduced=30 adbd_auth_get_max_version; # systemapi introduced=30 adbd_auth_supports_feature; # systemapi introduced=30 adbd_auth_send_tls_server_port; # systemapi introduced=37 local: *; }; Loading
libs/adbd_auth/Android.bp +19 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package { // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_native_license"], default_team: "trendy_team_android_developer_tools", } cc_library { Loading @@ -45,7 +46,7 @@ cc_library { target: { darwin: { enabled: false, } }, }, static_libs: [ Loading @@ -54,3 +55,20 @@ cc_library { "liblog", ], } cc_test { name: "libadbd_auth_test", srcs: [ "adbd_auth_test.cpp", ], static_libs: [ "libadbd_auth", "libbase", "libcutils", "liblog", ], test_suites: [ "cts", "general-tests", ], }
libs/adbd_auth/adbd_auth.cpp +27 −1 Original line number Diff line number Diff line Loading @@ -69,11 +69,16 @@ struct AdbdPacketTlsDeviceDisconnected { std::string public_key; }; struct AdbdPacketTlsServerPort { uint16_t port; }; using AdbdAuthPacket = std::variant<AdbdAuthPacketAuthenticated, AdbdAuthPacketDisconnected, AdbdAuthPacketRequestAuthorization, AdbdPacketTlsDeviceConnected, AdbdPacketTlsDeviceDisconnected>; AdbdPacketTlsDeviceDisconnected, AdbdPacketTlsServerPort>; struct AdbdAuthContext { static constexpr uint64_t kEpollConstSocket = 0; Loading Loading @@ -249,6 +254,7 @@ public: auto& packet = output_queue_.front(); struct iovec iovs[3]; int iovcnt = 2; if (auto* p = std::get_if<AdbdAuthPacketAuthenticated>(&packet)) { iovs[0].iov_base = const_cast<char*>("CK"); iovs[0].iov_len = 2; Loading Loading @@ -280,10 +286,18 @@ public: iovs[1].iov_len = 1; iovs[2].iov_base = p->public_key.data(); iovs[2].iov_len = p->public_key.size(); } else if (auto* p = std::get_if<AdbdPacketTlsServerPort>(&packet)) { iovcnt = 2; iovs[0].iov_base = const_cast<char*>("TP"); iovs[0].iov_len = 2; iovs[1].iov_base = &p->port; iovs[1].iov_len = 2; } else { LOG(FATAL) << "adbd_auth: unhandled packet type?"; } LOG(INFO) << "adbd_auth: sending packet: " << std::string((const char*)iovs[0].iov_base, 2); ssize_t rc = writev(framework_fd_.get(), iovs, iovcnt); output_queue_.pop_front(); if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { Loading Loading @@ -469,6 +483,14 @@ public: Interrupt(); } void SendTLSServerPort(uint16_t port) { std::lock_guard<std::mutex> lock(mutex_); output_queue_.emplace_back(AdbdPacketTlsServerPort{ .port = port }); Interrupt(); } // Interrupt the worker thread to do some work. void Interrupt() { uint64_t value = 1; Loading Loading @@ -588,3 +610,7 @@ bool adbd_auth_supports_feature(AdbdAuthFeature f) { UNUSED(f); return false; } void adbd_auth_send_tls_server_port(AdbdAuthContext* ctx, uint16_t port) { ctx->SendTLSServerPort(port); }
libs/adbd_auth/adbd_auth_test.cpp 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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. */ #include <gtest/gtest.h> #include <stddef.h> #include <stdint.h> #include "adbd_auth.h" class AdbAuthTest: public ::testing::Test { public: void SetUp() { AdbdAuthCallbacks callbacks = {.version = 1}; context = adbd_auth_new(&callbacks); } void TearDown() { adbd_auth_delete(context); } protected: AdbdAuthContext* context; }; TEST_F(AdbAuthTest, SendTcpPort) { adbd_auth_send_tls_server_port(context, 1); } No newline at end of file
libs/adbd_auth/include/adbd_auth.h +8 −0 Original line number Diff line number Diff line Loading @@ -185,4 +185,12 @@ enum AdbdAuthFeature : int32_t { */ bool adbd_auth_supports_feature(AdbdAuthFeature feature); /** * Advertise the port number the TLS server is running on. 0 = not running. * * @param ctx the AdbdAuthContext * @param port the port number the TLS server is running on. */ void adbd_auth_send_tls_server_port(AdbdAuthContext* ctx, uint16_t port) __INTRODUCED_IN(37); __END_DECLS
libs/adbd_auth/libadbd_auth.map.txt +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ LIBADBD_AUTH { adbd_auth_tls_device_disconnected; # systemapi introduced=30 adbd_auth_get_max_version; # systemapi introduced=30 adbd_auth_supports_feature; # systemapi introduced=30 adbd_auth_send_tls_server_port; # systemapi introduced=37 local: *; };