Skeleton for IVmTethering service with flag guarding
This reverts commit f9676878292a49caa03e5270c3be2769b029db60.
Bug: 340376953
Test: adb shell /apex/com.android.virt/bin/vm run-microdroid --network-supported
Change-Id: I9c859dd43e7ba7c852a71afce8f36ca10477ad24
diff --git a/java/service/Android.bp b/java/service/Android.bp
index 8bac7be..814445c 100644
--- a/java/service/Android.bp
+++ b/java/service/Android.bp
@@ -31,6 +31,7 @@
],
static_libs: [
"android.system.virtualizationmaintenance-java",
+ "android.system.vmtethering-java",
],
sdk_version: "core_platform",
apex_available: ["com.android.virt"],
diff --git a/java/service/src/com/android/system/virtualmachine/VirtualizationSystemService.java b/java/service/src/com/android/system/virtualmachine/VirtualizationSystemService.java
index 2461755..970f780 100644
--- a/java/service/src/com/android/system/virtualmachine/VirtualizationSystemService.java
+++ b/java/service/src/com/android/system/virtualmachine/VirtualizationSystemService.java
@@ -26,6 +26,7 @@
import android.os.ServiceManager;
import android.os.UserHandle;
import android.system.virtualizationmaintenance.IVirtualizationMaintenance;
+import android.system.vmtethering.IVmTethering;
import android.util.Log;
import com.android.internal.os.BackgroundThread;
@@ -39,18 +40,35 @@
* storing secrets for apps or users that no longer exist.
*/
public class VirtualizationSystemService extends SystemService {
+ static {
+ System.loadLibrary("virtualizationsystemservice_jni");
+ }
+
private static final String TAG = VirtualizationSystemService.class.getName();
- private static final String SERVICE_NAME = "android.system.virtualizationmaintenance";
+ private static final String MAINTENANCE_SERVICE_NAME =
+ "android.system.virtualizationmaintenance";
private Handler mHandler;
+ private final TetheringService mTetheringService;
+
+ /*
+ * Retrieve boolean value whether RELEASE_AVF_ENABLE_NETWORK build flag is enabled or not.
+ */
+ static native boolean nativeIsNetworkFlagEnabled();
public VirtualizationSystemService(Context context) {
super(context);
+ if (nativeIsNetworkFlagEnabled()) {
+ mTetheringService = new TetheringService();
+ } else {
+ mTetheringService = null;
+ }
}
@Override
public void onStart() {
- // Nothing needed here - we don't expose any binder service. The binder service we use is
- // exposed as a lazy service by the virtualizationservice native binary.
+ if (mTetheringService != null) {
+ publishBinderService(IVmTethering.DESCRIPTOR, mTetheringService);
+ }
}
@Override
@@ -82,11 +100,11 @@
}
static IVirtualizationMaintenance connectToMaintenanceService() {
- IBinder binder = ServiceManager.waitForService(SERVICE_NAME);
+ IBinder binder = ServiceManager.waitForService(MAINTENANCE_SERVICE_NAME);
IVirtualizationMaintenance maintenance =
IVirtualizationMaintenance.Stub.asInterface(binder);
if (maintenance == null) {
- throw new IllegalStateException("Failed to connect to " + SERVICE_NAME);
+ throw new IllegalStateException("Failed to connect to " + MAINTENANCE_SERVICE_NAME);
}
return maintenance;
}
@@ -136,4 +154,11 @@
}
}
}
+
+ private static final class TetheringService extends IVmTethering.Stub {
+ @Override
+ public void enableVmTethering() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("VM tethering is not supported yet");
+ }
+ }
}