diff options
| author | 2017-07-12 06:18:11 +0000 | |
|---|---|---|
| committer | 2017-07-12 06:18:11 +0000 | |
| commit | c8b4ef85dc059026c99aeaeb21a98c93bbebca70 (patch) | |
| tree | b0e981abe8eb544c56d9234ece34a3b8700762ce | |
| parent | 2a13286d8d60460d36a03f2e3a7861b7d88f1b68 (diff) | |
| parent | 5bb30496cf381c6546cbf02a2c5b55adf046aeb8 (diff) | |
Merge "Restructure use of absent tether_offload_disabled setting"
am: 5bb30496cf
Change-Id: I9d1ec7d1c060278018c80c9374d724ee0ddba3a4
3 files changed, 55 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/connectivity/tethering/OffloadController.java b/services/core/java/com/android/server/connectivity/tethering/OffloadController.java index 20ec20681ce2..a69e4caebd5d 100644 --- a/services/core/java/com/android/server/connectivity/tethering/OffloadController.java +++ b/services/core/java/com/android/server/connectivity/tethering/OffloadController.java @@ -142,8 +142,9 @@ public class OffloadController { } private boolean isOffloadDisabled() { - // Defaults to |false| if not present. - return (Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 0) != 0); + final int defaultDisposition = mHwInterface.getDefaultTetherOffloadDisabled(); + return (Settings.Global.getInt( + mContentResolver, TETHER_OFFLOAD_DISABLED, defaultDisposition) != 0); } private boolean started() { diff --git a/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java b/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java index 09fd96b4966e..cd98b30027d2 100644 --- a/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java +++ b/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java @@ -35,6 +35,10 @@ import java.util.ArrayList; */ public class OffloadHardwareInterface { private static final String TAG = OffloadHardwareInterface.class.getSimpleName(); + // Change this value to control whether tether offload is enabled or + // disabled by default in the absence of an explicit Settings value. + // See accompanying unittest to distinguish 0 from non-0 values. + private static final int DEFAULT_TETHER_OFFLOAD_DISABLED = 0; private static final String NO_INTERFACE_NAME = ""; private static final String NO_IPV4_ADDRESS = ""; private static final String NO_IPV4_GATEWAY = ""; @@ -60,6 +64,10 @@ public class OffloadHardwareInterface { mLog = log.forSubComponent(TAG); } + public int getDefaultTetherOffloadDisabled() { + return DEFAULT_TETHER_OFFLOAD_DISABLED; + } + public boolean initOffloadConfig() { return configOffload(); } diff --git a/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java b/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java index 1ddaf66d2274..c3313f8cb2ce 100644 --- a/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java +++ b/tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java @@ -46,6 +46,7 @@ import com.android.internal.util.test.FakeSettingsProvider; import java.net.InetAddress; import java.util.ArrayList; +import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.Test; @@ -73,6 +74,13 @@ public class OffloadControllerTest { mContentResolver = new MockContentResolver(mContext); mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); when(mContext.getContentResolver()).thenReturn(mContentResolver); + // TODO: call this when available. + // FakeSettingsProvider.clearSettingsProvider(); + } + + @After public void tearDown() throws Exception { + // TODO: call this when available. + // FakeSettingsProvider.clearSettingsProvider(); } private void setupFunctioningHardwareInterface() { @@ -81,9 +89,15 @@ public class OffloadControllerTest { .thenReturn(true); } - @Test - public void testNoSettingsValueAllowsStart() { + private void enableOffload() { + Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 0); + } + + // TODO: Restore when FakeSettingsProvider.clearSettingsProvider() is available. + // @Test + public void testNoSettingsValueDefaultDisabledDoesNotStart() { setupFunctioningHardwareInterface(); + when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1); try { Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED); fail(); @@ -94,6 +108,29 @@ public class OffloadControllerTest { offload.start(); final InOrder inOrder = inOrder(mHardware); + inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); + inOrder.verify(mHardware, never()).initOffloadConfig(); + inOrder.verify(mHardware, never()).initOffloadControl( + any(OffloadHardwareInterface.ControlCallback.class)); + inOrder.verifyNoMoreInteractions(); + } + + // TODO: Restore when FakeSettingsProvider.clearSettingsProvider() is available. + // @Test + public void testNoSettingsValueDefaultEnabledDoesStart() { + setupFunctioningHardwareInterface(); + when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(0); + try { + Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED); + fail(); + } catch (SettingNotFoundException expected) {} + + final OffloadController offload = + new OffloadController(null, mHardware, mContentResolver, new SharedLog("test")); + offload.start(); + + final InOrder inOrder = inOrder(mHardware); + inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); inOrder.verify(mHardware, times(1)).initOffloadConfig(); inOrder.verify(mHardware, times(1)).initOffloadControl( any(OffloadHardwareInterface.ControlCallback.class)); @@ -110,6 +147,7 @@ public class OffloadControllerTest { offload.start(); final InOrder inOrder = inOrder(mHardware); + inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); inOrder.verify(mHardware, times(1)).initOffloadConfig(); inOrder.verify(mHardware, times(1)).initOffloadControl( any(OffloadHardwareInterface.ControlCallback.class)); @@ -126,6 +164,7 @@ public class OffloadControllerTest { offload.start(); final InOrder inOrder = inOrder(mHardware); + inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); inOrder.verify(mHardware, never()).initOffloadConfig(); inOrder.verify(mHardware, never()).initOffloadControl(anyObject()); inOrder.verifyNoMoreInteractions(); @@ -134,11 +173,14 @@ public class OffloadControllerTest { @Test public void testSetUpstreamLinkPropertiesWorking() throws Exception { setupFunctioningHardwareInterface(); + enableOffload(); + final OffloadController offload = new OffloadController(null, mHardware, mContentResolver, new SharedLog("test")); offload.start(); final InOrder inOrder = inOrder(mHardware); + inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); inOrder.verify(mHardware, times(1)).initOffloadConfig(); inOrder.verify(mHardware, times(1)).initOffloadControl( any(OffloadHardwareInterface.ControlCallback.class)); |