Restructure use of absent tether_offload_disabled setting
This restructures the fetching of the default disposition such
that we disable (and enable) the feature with only a single
character change.
Additionally: fix unittests with proper use of FakeSettingsProvider.
Test: as follows
- built
- flashed
- booted
- "runtest frameworks-net" passed with developer enabled and disabled
Bug: 29337859
Bug: 32163131
Bug: 63250751
Change-Id: Ib32489d07778465134bca52c589baddbd78ab129
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 1ddaf66..0dedf70 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 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,11 @@
mContentResolver = new MockContentResolver(mContext);
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ FakeSettingsProvider.clearSettingsProvider();
+ }
+
+ @After public void tearDown() throws Exception {
+ FakeSettingsProvider.clearSettingsProvider();
}
private void setupFunctioningHardwareInterface() {
@@ -81,9 +87,14 @@
.thenReturn(true);
}
+ private void enableOffload() {
+ Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 0);
+ }
+
@Test
- public void testNoSettingsValueAllowsStart() {
+ public void testNoSettingsValueDefaultDisabledDoesNotStart() {
setupFunctioningHardwareInterface();
+ when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1);
try {
Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED);
fail();
@@ -94,6 +105,28 @@
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();
+ }
+
+ @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 +143,7 @@
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 +160,7 @@
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 +169,14 @@
@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));