summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-07-12 03:05:18 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-07-12 03:05:18 +0000
commitd8fdb26ebfd5c9037ad4e0b97995f280d7a83b8f (patch)
tree2b5cc1aa4a98092f052eca1b40574b937830bb05
parentbd2682d0568cb5730c8749e7749698ed1d60f45f (diff)
parentc87cd411843484225897ebdf91cd05073c1c5f35 (diff)
Merge "Restructure use of absent tether_offload_disabled setting" into oc-dr1-dev
-rw-r--r--services/core/java/com/android/server/connectivity/tethering/OffloadController.java5
-rw-r--r--services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java8
-rw-r--r--tests/net/java/com/android/server/connectivity/tethering/OffloadControllerTest.java40
3 files changed, 50 insertions, 3 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..0dedf703f3bb 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,11 @@ public class OffloadControllerTest {
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 @@ public class OffloadControllerTest {
.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 @@ 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();
+ }
+
+ @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 @@ 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 +160,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 +169,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));