From 07b8fe1f92529f1b7bb8bf613955586cfd21a0e5 Mon Sep 17 00:00:00 2001 From: Seungjae Yoo Date: Wed, 19 Jun 2024 16:18:51 +0900 Subject: [PATCH] Introduce TETHERING_VIRTUAL type Bug: 340376953 Test: Presubmit Change-Id: I0714b62ebfc63fc966d7873ebdd68ae72c015bc4 --- .../TetheringLib/api/system-current.txt | 1 + .../src/android/net/TetheringManager.java | 12 ++++++++++- .../networkstack/tethering/Tethering.java | 20 +++++++++++++++++++ common/flags.aconfig | 8 ++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Tethering/common/TetheringLib/api/system-current.txt b/Tethering/common/TetheringLib/api/system-current.txt index a287b428db..cccafd58d2 100644 --- a/Tethering/common/TetheringLib/api/system-current.txt +++ b/Tethering/common/TetheringLib/api/system-current.txt @@ -47,6 +47,7 @@ package android.net { field public static final int TETHERING_INVALID = -1; // 0xffffffff field public static final int TETHERING_NCM = 4; // 0x4 field public static final int TETHERING_USB = 1; // 0x1 + field @FlaggedApi("com.android.net.flags.tethering_request_virtual") public static final int TETHERING_VIRTUAL = 7; // 0x7 field public static final int TETHERING_WIFI = 0; // 0x0 field public static final int TETHERING_WIFI_P2P = 3; // 0x3 field public static final int TETHER_ERROR_DHCPSERVER_ERROR = 12; // 0xc diff --git a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java index 7b769d49fe..2963f87a36 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +++ b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java @@ -68,6 +68,8 @@ public class TetheringManager { public static class Flags { static final String TETHERING_REQUEST_WITH_SOFT_AP_CONFIG = "com.android.net.flags.tethering_request_with_soft_ap_config"; + static final String TETHERING_REQUEST_VIRTUAL = + "com.android.net.flags.tethering_request_virtual"; } private static final String TAG = TetheringManager.class.getSimpleName(); @@ -194,11 +196,19 @@ public class TetheringManager { */ public static final int TETHERING_WIGIG = 6; + /** + * VIRTUAL tethering type. + * @hide + */ + @FlaggedApi(Flags.TETHERING_REQUEST_VIRTUAL) + @SystemApi + public static final int TETHERING_VIRTUAL = 7; + /** * The int value of last tethering type. * @hide */ - public static final int MAX_TETHERING_TYPE = TETHERING_WIGIG; + public static final int MAX_TETHERING_TYPE = TETHERING_VIRTUAL; /** @hide */ @Retention(RetentionPolicy.SOURCE) diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index d85d92f15e..29ced23a16 100644 --- a/Tethering/src/com/android/networkstack/tethering/Tethering.java +++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java @@ -38,6 +38,7 @@ import static android.net.TetheringManager.TETHERING_ETHERNET; import static android.net.TetheringManager.TETHERING_INVALID; import static android.net.TetheringManager.TETHERING_NCM; import static android.net.TetheringManager.TETHERING_USB; +import static android.net.TetheringManager.TETHERING_VIRTUAL; import static android.net.TetheringManager.TETHERING_WIFI; import static android.net.TetheringManager.TETHERING_WIFI_P2P; import static android.net.TetheringManager.TETHERING_WIGIG; @@ -278,6 +279,7 @@ public class Tethering { private TetheredInterfaceRequestShim mBluetoothIfaceRequest; private String mConfiguredEthernetIface; private String mConfiguredBluetoothIface; + private String mConfiguredVirtualIface; private EthernetCallback mEthernetCallback; private TetheredInterfaceCallbackShim mBluetoothCallback; private SettingsObserver mSettingsObserver; @@ -719,6 +721,9 @@ public class Tethering { case TETHERING_ETHERNET: result = setEthernetTethering(enable); break; + case TETHERING_VIRTUAL: + result = setVirtualMachineTethering(enable); + break; default: Log.w(TAG, "Invalid tether type."); result = TETHER_ERROR_UNKNOWN_TYPE; @@ -972,6 +977,21 @@ public class Tethering { } } + private int setVirtualMachineTethering(final boolean enable) { + // TODO(340377643): Use bridge ifname when it's introduced, not fixed TAP ifname. + if (enable) { + mConfiguredVirtualIface = "avf_tap_fixed"; + enableIpServing( + TETHERING_VIRTUAL, + mConfiguredVirtualIface, + getRequestedState(TETHERING_VIRTUAL)); + } else if (mConfiguredVirtualIface != null) { + ensureIpServerStopped(mConfiguredVirtualIface); + mConfiguredVirtualIface = null; + } + return TETHER_ERROR_NO_ERROR; + } + void tether(String iface, int requestedState, final IIntResultListener listener) { mHandler.post(() -> { try { diff --git a/common/flags.aconfig b/common/flags.aconfig index bc4168b6cb..b320b61ee7 100644 --- a/common/flags.aconfig +++ b/common/flags.aconfig @@ -115,3 +115,11 @@ flag { description: "Flag for NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED API" bug: "343823469" } + +flag { + name: "tethering_request_virtual" + is_exported: true + namespace: "android_core_networking" + description: "Flag for introducing TETHERING_VIRTUAL type" + bug: "340376953" +}