From c512ab7e23ec82c7354d2c1fdb97db76a516c6ce Mon Sep 17 00:00:00 2001 From: Mark <markchien@google.com> Date: Tue, 23 Jan 2024 09:55:33 +0000 Subject: [PATCH] Add experiment flag for enabling sync sm The logic is currently disabled by default, adding a flag so that we can compare result with A/B rollout. Tethering only read this flag once when it is created. Bug: 319212113 Test: atest TetheringTests Change-Id: I656b0389e56d29dd691738ee3abfa6418746846f --- .../networkstack/tethering/Tethering.java | 1 + .../tethering/TetheringConfiguration.java | 18 ++++++++++++++- .../tethering/TetheringConfigurationTest.java | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index 5022b40525..76a45474cd 100644 --- a/Tethering/src/com/android/networkstack/tethering/Tethering.java +++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java @@ -370,6 +370,7 @@ public class Tethering { // Load tethering configuration. updateConfiguration(); + mConfig.readEnableSyncSM(mContext); // It is OK for the configuration to be passed to the PrivateAddressCoordinator at // construction time because the only part of the configuration it uses is // shouldEnableWifiP2pDedicatedIp(), and currently do not support changing that. diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java b/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java index 0678525efd..298940e4fc 100644 --- a/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java +++ b/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java @@ -132,6 +132,9 @@ public class TetheringConfiguration { public static final String TETHER_FORCE_RANDOM_PREFIX_BASE_SELECTION = "tether_force_random_prefix_base_selection"; + + public static final String TETHER_ENABLE_SYNC_SM = "tether_enable_sync_sm"; + /** * Default value that used to periodic polls tether offload stats from tethering offload HAL * to make the data warnings work. @@ -139,7 +142,7 @@ public class TetheringConfiguration { public static final int DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS = 5000; /** A flag for using synchronous or asynchronous state machine. */ - public static final boolean USE_SYNC_SM = false; + public static boolean USE_SYNC_SM = false; public final String[] tetherableUsbRegexs; public final String[] tetherableWifiRegexs; @@ -385,6 +388,16 @@ public class TetheringConfiguration { return mRandomPrefixBase; } + /** + * Check whether sync SM is enabled then set it to USE_SYNC_SM. This should be called once + * when tethering is created. Otherwise if the flag is pushed while tethering is enabled, + * then it's possible for some IpServer(s) running the new sync state machine while others + * use the async state machine. + */ + public void readEnableSyncSM(final Context ctx) { + USE_SYNC_SM = mDeps.isFeatureEnabled(ctx, TETHER_ENABLE_SYNC_SM); + } + /** Does the dumping.*/ public void dump(PrintWriter pw) { pw.print("activeDataSubId: "); @@ -438,6 +451,9 @@ public class TetheringConfiguration { pw.print("mRandomPrefixBase: "); pw.println(mRandomPrefixBase); + + pw.print("USE_SYNC_SM: "); + pw.println(USE_SYNC_SM); } /** Returns the string representation of this object.*/ diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java index aa322dc8eb..dd51c7ad1d 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java @@ -754,4 +754,27 @@ public class TetheringConfigurationTest { new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps); assertEquals(p2pLeasesSubnetPrefixLength, p2pCfg.getP2pLeasesSubnetPrefixLength()); } + + private void setTetherEnableSyncSMFlagEnabled(Boolean enabled) { + mDeps.setFeatureEnabled(TetheringConfiguration.TETHER_ENABLE_SYNC_SM, enabled); + new TetheringConfiguration( + mMockContext, mLog, INVALID_SUBSCRIPTION_ID, mDeps).readEnableSyncSM(mMockContext); + } + + private void assertEnableSyncSM(boolean value) { + assertEquals(value, TetheringConfiguration.USE_SYNC_SM); + } + + @Test + public void testEnableSyncSMFlag() throws Exception { + // Test default disabled + setTetherEnableSyncSMFlagEnabled(null); + assertEnableSyncSM(false); + + setTetherEnableSyncSMFlagEnabled(true); + assertEnableSyncSM(true); + + setTetherEnableSyncSMFlagEnabled(false); + assertEnableSyncSM(false); + } } -- GitLab