Document valid port range.
Switch the port parameters to long, since Java int can't hold the
largest u32 value.
Throw an exception if out of range values are passed.
Also enforce the >= 1024 restriction in VS, just in case we start
using privileged vsock ports for something.
Use a port number > 2^31 in one of our tests just to make sure it
works.
BYPASS_INCLUSIVE_LANGUAGE_REASON='man' used to refer to the manual command.
Bug: 261037705
Test: atest MicrodroidTests
Change-Id: Icf22d9c2e746f300b184e66469fb6b62c574b6ff
diff --git a/tests/aidl/com/android/microdroid/testservice/ITestService.aidl b/tests/aidl/com/android/microdroid/testservice/ITestService.aidl
index 077c74f..a4ecc45 100644
--- a/tests/aidl/com/android/microdroid/testservice/ITestService.aidl
+++ b/tests/aidl/com/android/microdroid/testservice/ITestService.aidl
@@ -17,9 +17,9 @@
/** {@hide} */
interface ITestService {
- const int SERVICE_PORT = 5678;
+ const long SERVICE_PORT = 5678;
- const int ECHO_REVERSE_PORT = 6789;
+ const long ECHO_REVERSE_PORT = 0x80000001L; // Deliberately chosen to be > 2^31, < 2^32
/* add two integers. */
int addInteger(int a, int b);
diff --git a/tests/testapk/src/native/testbinary.cpp b/tests/testapk/src/native/testbinary.cpp
index 8a0019d..b6a7aa2 100644
--- a/tests/testapk/src/native/testbinary.cpp
+++ b/tests/testapk/src/native/testbinary.cpp
@@ -112,7 +112,7 @@
}
struct sockaddr_vm server_sa = (struct sockaddr_vm){
.svm_family = AF_VSOCK,
- .svm_port = BnTestService::ECHO_REVERSE_PORT,
+ .svm_port = static_cast<uint32_t>(BnTestService::ECHO_REVERSE_PORT),
.svm_cid = VMADDR_CID_ANY,
};
int ret = TEMP_FAILURE_RETRY(bind(server_fd, (struct sockaddr*)&server_sa, sizeof(server_sa)));