adb: switch connect_to_remote to string_view.
Test: test_adb.py
Test: test_device.py
Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test
Test: adb shell /data/nativetest64/adbd_test/adbd_test
Change-Id: Icce121a4c62bf0fa636a35bcae31d057cdff8fd2
diff --git a/adb_listeners.cpp b/adb_listeners.cpp
index 051ab73..be457a6 100644
--- a/adb_listeners.cpp
+++ b/adb_listeners.cpp
@@ -105,7 +105,7 @@
s = create_local_socket(fd);
if (s) {
s->transport = listener->transport;
- connect_to_remote(s, listener->connect_to.c_str());
+ connect_to_remote(s, listener->connect_to);
return;
}
diff --git a/socket.h b/socket.h
index 0392731..e7df991 100644
--- a/socket.h
+++ b/socket.h
@@ -106,7 +106,7 @@
asocket* create_local_service_socket(std::string_view destination, atransport* transport);
asocket *create_remote_socket(unsigned id, atransport *t);
-void connect_to_remote(asocket *s, const char *destination);
+void connect_to_remote(asocket* s, std::string_view destination);
void connect_to_smartsocket(asocket *s);
// Internal functions that are only made available here for testing purposes.
diff --git a/sockets.cpp b/sockets.cpp
index 676ef44..47ae883 100644
--- a/sockets.cpp
+++ b/sockets.cpp
@@ -462,16 +462,19 @@
return s;
}
-void connect_to_remote(asocket* s, const char* destination) {
+void connect_to_remote(asocket* s, std::string_view destination) {
D("Connect_to_remote call RS(%d) fd=%d", s->id, s->fd);
apacket* p = get_apacket();
- D("LS(%d): connect('%s')", s->id, destination);
+ LOG(VERBOSE) << "LS(" << s->id << ": connect(" << destination << ")";
p->msg.command = A_OPEN;
p->msg.arg0 = s->id;
- // adbd expects a null-terminated string.
- p->payload.assign(destination, destination + strlen(destination) + 1);
+ // adbd used to expect a null-terminated string.
+ // Keep doing so to maintain backward compatibility.
+ p->payload.resize(destination.size() + 1);
+ memcpy(p->payload.data(), destination.data(), destination.size());
+ p->payload[destination.size()] = '\0';
p->msg.data_length = p->payload.size();
CHECK_LE(p->msg.data_length, s->get_max_payload());
@@ -826,7 +829,7 @@
/* give him our transport and upref it */
s->peer->transport = s->transport;
- connect_to_remote(s->peer, s->smart_socket_data.data() + 4);
+ connect_to_remote(s->peer, std::string_view(s->smart_socket_data).substr(4));
s->peer = nullptr;
s->close(s);
return 1;