Host can send required infos to the guest for performing forwarding.
Since forwarder_guest_launcher is not implemented in 100%, we should
manually run forwarder_guest_launcher with `--host-addr 192.168.0.1`,
and accessing `http://localhost:12345` to check the log printed at
forwarder_guest_launcher.
Bug: 340126051
Test: Manual test described above.
Change-Id: If3a7784fb29febc3fed8653297fa6c840ef22b49
diff --git a/libs/vm_launcher_lib/Android.bp b/libs/vm_launcher_lib/Android.bp
index f47f6b6..7dced4e 100644
--- a/libs/vm_launcher_lib/Android.bp
+++ b/libs/vm_launcher_lib/Android.bp
@@ -16,6 +16,7 @@
"apache-commons-compress",
],
libs: [
+ "androidx.annotation_annotation",
"framework-virtualization.impl",
"framework-annotations-lib",
],
diff --git a/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/DebianServiceImpl.java b/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/DebianServiceImpl.java
index ccc0ed6..d62ccfb 100644
--- a/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/DebianServiceImpl.java
+++ b/libs/vm_launcher_lib/java/com/android/virtualization/vmlauncher/DebianServiceImpl.java
@@ -18,6 +18,8 @@
import android.util.Log;
+import androidx.annotation.Keep;
+
import com.android.virtualization.vmlauncher.proto.DebianServiceGrpc;
import com.android.virtualization.vmlauncher.proto.Empty;
import com.android.virtualization.vmlauncher.proto.ForwardingRequestItem;
@@ -30,6 +32,10 @@
public static final String TAG = "DebianService";
private final DebianServiceCallback mCallback;
+ static {
+ System.loadLibrary("forwarder_host_jni");
+ }
+
protected DebianServiceImpl(DebianServiceCallback callback) {
super();
mCallback = callback;
@@ -49,12 +55,30 @@
public void openForwardingRequestQueue(
Empty request, StreamObserver<ForwardingRequestItem> responseObserver) {
Log.d(DebianServiceImpl.TAG, "OpenForwardingRequestQueue");
-
- // TODO(b/340126051): Bring information from forwarder_host.
-
+ runForwarderHost(new ForwarderHostCallback(responseObserver));
responseObserver.onCompleted();
}
+ @Keep
+ private static class ForwarderHostCallback {
+ private StreamObserver<ForwardingRequestItem> mResponseObserver;
+
+ ForwarderHostCallback(StreamObserver<ForwardingRequestItem> responseObserver) {
+ mResponseObserver = responseObserver;
+ }
+
+ private void onForwardingRequestReceived(int guestTcpPort, int vsockPort) {
+ ForwardingRequestItem item =
+ ForwardingRequestItem.newBuilder()
+ .setGuestTcpPort(guestTcpPort)
+ .setVsockPort(vsockPort)
+ .build();
+ mResponseObserver.onNext(item);
+ }
+ }
+
+ private static native void runForwarderHost(ForwarderHostCallback callback);
+
protected interface DebianServiceCallback {
void onIpAddressAvailable(String ipAddr);
}