Skip to content

Commit 66b1c5a

Browse files
Treehugger Robotandroid-build-merge-worker-robot
authored andcommitted
Merge "Add capability to send tls server port" into main am: 4f463a6
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3542622 Change-Id: I0a56db70f5355dfda0b6df7a03cb5ec61207e6e1 Signed-off-by: Automerger Merge Worker <[email protected]>
2 parents 35f9fab + 4f463a6 commit 66b1c5a

File tree

5 files changed

+95
-2
lines changed

5 files changed

+95
-2
lines changed

libs/adbd_auth/Android.bp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package {
1919
// to get the below license kinds:
2020
// SPDX-license-identifier-Apache-2.0
2121
default_applicable_licenses: ["frameworks_native_license"],
22+
default_team: "trendy_team_android_developer_tools",
2223
}
2324

2425
cc_library {
@@ -45,7 +46,7 @@ cc_library {
4546
target: {
4647
darwin: {
4748
enabled: false,
48-
}
49+
},
4950
},
5051

5152
static_libs: [
@@ -54,3 +55,20 @@ cc_library {
5455
"liblog",
5556
],
5657
}
58+
59+
cc_test {
60+
name: "libadbd_auth_test",
61+
srcs: [
62+
"adbd_auth_test.cpp",
63+
],
64+
static_libs: [
65+
"libadbd_auth",
66+
"libbase",
67+
"libcutils",
68+
"liblog",
69+
],
70+
test_suites: [
71+
"cts",
72+
"general-tests",
73+
],
74+
}

libs/adbd_auth/adbd_auth.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ struct AdbdPacketTlsDeviceDisconnected {
6969
std::string public_key;
7070
};
7171

72+
struct AdbdPacketTlsServerPort {
73+
uint16_t port;
74+
};
75+
7276
using AdbdAuthPacket = std::variant<AdbdAuthPacketAuthenticated,
7377
AdbdAuthPacketDisconnected,
7478
AdbdAuthPacketRequestAuthorization,
7579
AdbdPacketTlsDeviceConnected,
76-
AdbdPacketTlsDeviceDisconnected>;
80+
AdbdPacketTlsDeviceDisconnected,
81+
AdbdPacketTlsServerPort>;
7782

7883
struct AdbdAuthContext {
7984
static constexpr uint64_t kEpollConstSocket = 0;
@@ -249,6 +254,7 @@ struct AdbdAuthContext {
249254
auto& packet = output_queue_.front();
250255
struct iovec iovs[3];
251256
int iovcnt = 2;
257+
252258
if (auto* p = std::get_if<AdbdAuthPacketAuthenticated>(&packet)) {
253259
iovs[0].iov_base = const_cast<char*>("CK");
254260
iovs[0].iov_len = 2;
@@ -280,10 +286,18 @@ struct AdbdAuthContext {
280286
iovs[1].iov_len = 1;
281287
iovs[2].iov_base = p->public_key.data();
282288
iovs[2].iov_len = p->public_key.size();
289+
} else if (auto* p = std::get_if<AdbdPacketTlsServerPort>(&packet)) {
290+
iovcnt = 2;
291+
iovs[0].iov_base = const_cast<char*>("TP");
292+
iovs[0].iov_len = 2;
293+
iovs[1].iov_base = &p->port;
294+
iovs[1].iov_len = 2;
283295
} else {
284296
LOG(FATAL) << "adbd_auth: unhandled packet type?";
285297
}
286298

299+
LOG(INFO) << "adbd_auth: sending packet: " << std::string((const char*)iovs[0].iov_base, 2);
300+
287301
ssize_t rc = writev(framework_fd_.get(), iovs, iovcnt);
288302
output_queue_.pop_front();
289303
if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
@@ -469,6 +483,14 @@ struct AdbdAuthContext {
469483
Interrupt();
470484
}
471485

486+
void SendTLSServerPort(uint16_t port) {
487+
std::lock_guard<std::mutex> lock(mutex_);
488+
output_queue_.emplace_back(AdbdPacketTlsServerPort{
489+
.port = port
490+
});
491+
Interrupt();
492+
}
493+
472494
// Interrupt the worker thread to do some work.
473495
void Interrupt() {
474496
uint64_t value = 1;
@@ -588,3 +610,7 @@ bool adbd_auth_supports_feature(AdbdAuthFeature f) {
588610
UNUSED(f);
589611
return false;
590612
}
613+
614+
void adbd_auth_send_tls_server_port(AdbdAuthContext* ctx, uint16_t port) {
615+
ctx->SendTLSServerPort(port);
616+
}

libs/adbd_auth/adbd_auth_test.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <gtest/gtest.h>
18+
19+
#include <stddef.h>
20+
#include <stdint.h>
21+
22+
#include "adbd_auth.h"
23+
24+
class AdbAuthTest: public ::testing::Test {
25+
public:
26+
void SetUp() {
27+
AdbdAuthCallbacks callbacks = {.version = 1};
28+
context = adbd_auth_new(&callbacks);
29+
}
30+
31+
void TearDown() {
32+
adbd_auth_delete(context);
33+
}
34+
protected:
35+
AdbdAuthContext* context;
36+
};
37+
38+
TEST_F(AdbAuthTest, SendTcpPort) {
39+
adbd_auth_send_tls_server_port(context, 1);
40+
}

libs/adbd_auth/include/adbd_auth.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,12 @@ enum AdbdAuthFeature : int32_t {
185185
*/
186186
bool adbd_auth_supports_feature(AdbdAuthFeature feature);
187187

188+
/**
189+
* Advertise the port number the TLS server is running on. 0 = not running.
190+
*
191+
* @param ctx the AdbdAuthContext
192+
* @param port the port number the TLS server is running on.
193+
*/
194+
void adbd_auth_send_tls_server_port(AdbdAuthContext* ctx, uint16_t port) __INTRODUCED_IN(37);
195+
188196
__END_DECLS

libs/adbd_auth/libadbd_auth.map.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LIBADBD_AUTH {
1212
adbd_auth_tls_device_disconnected; # systemapi introduced=30
1313
adbd_auth_get_max_version; # systemapi introduced=30
1414
adbd_auth_supports_feature; # systemapi introduced=30
15+
adbd_auth_send_tls_server_port; # systemapi introduced=37
1516
local:
1617
*;
1718
};

0 commit comments

Comments
 (0)