diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index 5022b40525a30cefe09ef6fbf41ba323c71d32ef..76a45474cd9aa039eceb8bee89ac4ac4a7e41c16 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 0678525efd45befc9bdb3620dd47768293a872d9..298940e4fc166bd46556b4b46a51f77edc2820e8 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 aa322dc8ebb8fca80086c98318f55236be1b1424..dd51c7ad1d44056c208464231b2f6820f003db8b 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); + } }