Merge "Set Wifi scoring status when Adaptive Connectivity toggle status changes" into sc-dev
diff --git a/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java b/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
index e072b5c..e1e56a8 100644
--- a/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
+++ b/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
@@ -17,6 +17,7 @@
package com.android.settings.network;
import android.content.Context;
+import android.net.wifi.WifiManager;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
@@ -28,8 +29,11 @@
*/
public class AdaptiveConnectivityTogglePreferenceController extends TogglePreferenceController {
+ private final WifiManager mWifiManager;
+
public AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
+ mWifiManager = context.getSystemService(WifiManager.class);
}
@Override
@@ -53,6 +57,7 @@
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED,
isChecked ? 1 : 0);
+ mWifiManager.setWifiScoringEnabled(isChecked);
return true;
}
}
diff --git a/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
index dfb9a8f..c95797f 100644
--- a/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
@@ -19,8 +19,13 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
+import android.net.wifi.WifiManager;
import android.provider.Settings;
import org.junit.Before;
@@ -29,6 +34,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class AdaptiveConnectivityTogglePreferenceControllerTest {
@@ -37,12 +43,16 @@
@Mock(answer = RETURNS_DEEP_STUBS)
private Context mContext;
+ @Mock
+ WifiManager mWifiManager;
private AdaptiveConnectivityTogglePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
mController = new AdaptiveConnectivityTogglePreferenceController(mContext, PREF_KEY);
}
@@ -61,6 +71,7 @@
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
.isEqualTo(1);
+ verify(mWifiManager, atLeastOnce()).setWifiScoringEnabled(true);
}
@Test
@@ -73,5 +84,6 @@
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
.isEqualTo(0);
+ verify(mWifiManager).setWifiScoringEnabled(false);
}
}