diff --git a/res/drawable/ic_illustration_adaptive_connectivity.xml b/res/drawable/ic_illustration_adaptive_connectivity.xml
new file mode 100644
index 00000000000..748dd66d0e9
--- /dev/null
+++ b/res/drawable/ic_illustration_adaptive_connectivity.xml
@@ -0,0 +1,99 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/adaptive_connectivity_header.xml b/res/layout/adaptive_connectivity_header.xml
new file mode 100644
index 00000000000..4c5fb0c380b
--- /dev/null
+++ b/res/layout/adaptive_connectivity_header.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
diff --git a/res/values/config.xml b/res/values/config.xml
index ef088e4109a..6a7a1bdae0d 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -462,4 +462,7 @@
true
+
+
+ false
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 643297c2137..c6985353e0a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6170,6 +6170,11 @@
VPN
+
+ Adaptive connectivity
+
+ Extends battery life and improves device performance by automatically managing your network connections
+
Credential storage
diff --git a/res/xml/adaptive_connectivity_settings.xml b/res/xml/adaptive_connectivity_settings.xml
new file mode 100644
index 00000000000..ff9bdb0443e
--- /dev/null
+++ b/res/xml/adaptive_connectivity_settings.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index dd93ec1d412..c92ce940758 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -118,4 +118,11 @@
android:positiveButtonText="@string/save"
android:negativeButtonText="@android:string/cancel" />
+
diff --git a/src/com/android/settings/network/AdaptiveConnectivityPreferenceController.java b/src/com/android/settings/network/AdaptiveConnectivityPreferenceController.java
new file mode 100644
index 00000000000..33d1d5b66cd
--- /dev/null
+++ b/src/com/android/settings/network/AdaptiveConnectivityPreferenceController.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * {@link BasePreferenceController} that shows Adaptive connectivity on/off state.
+ */
+public class AdaptiveConnectivityPreferenceController extends BasePreferenceController {
+
+ public AdaptiveConnectivityPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_adaptive_connectivity)
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1) == 1
+ ? mContext.getString(R.string.switch_on_text)
+ : mContext.getString(R.string.switch_off_text);
+ }
+}
diff --git a/src/com/android/settings/network/AdaptiveConnectivitySettings.java b/src/com/android/settings/network/AdaptiveConnectivitySettings.java
new file mode 100644
index 00000000000..5e1dc124f3b
--- /dev/null
+++ b/src/com/android/settings/network/AdaptiveConnectivitySettings.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.network;
+
+import android.app.settings.SettingsEnums;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+/**
+ * Adaptive connectivity is a feature which automatically manages network connections.
+ */
+@SearchIndexable
+public class AdaptiveConnectivitySettings extends DashboardFragment {
+
+ private static final String TAG = "AdaptiveConnectivitySettings";
+
+ private static final String KEY_ADAPTIVE_CONNECTIVITY_PREFERENCE = "adaptive_connectivity";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.ADAPTIVE_CONNECTIVITY_CATEGORY;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.adaptive_connectivity_settings;
+ }
+
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.adaptive_connectivity_settings);
+}
diff --git a/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java b/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
new file mode 100644
index 00000000000..e072b5c4e38
--- /dev/null
+++ b/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.TogglePreferenceController;
+
+/**
+ * {@link TogglePreferenceController} that controls whether Adaptive connectivity option is enabled.
+ */
+public class AdaptiveConnectivityTogglePreferenceController extends TogglePreferenceController {
+
+ public AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED,
+ isChecked ? 1 : 0);
+ return true;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityPreferenceControllerTest.java
new file mode 100644
index 00000000000..9ba62385756
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityPreferenceControllerTest.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class AdaptiveConnectivityPreferenceControllerTest {
+
+ private static final String PREF_KEY = "adaptive_connectivity";
+
+ private Context mContext;
+ @Mock private Resources mResources;
+ private AdaptiveConnectivityPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mResources).when(mContext).getResources();
+ mController = new AdaptiveConnectivityPreferenceController(mContext, PREF_KEY);
+ }
+
+ @Test
+ public void isAvailable_supportAdaptiveConnectivity_shouldReturnTrue() {
+ when(mResources.getBoolean(R.bool.config_show_adaptive_connectivity))
+ .thenReturn(true);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_notSupportAdaptiveConnectivity_shouldReturnFalse() {
+ when(mResources.getBoolean(R.bool.config_show_adaptive_connectivity))
+ .thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void getSummary_adaptiveConnectivityEnabled_shouldShowOn() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1);
+
+ assertThat(mController.getSummary()).isEqualTo(mContext.getString(R.string.switch_on_text));
+ }
+
+ @Test
+ public void getSummary_adaptiveConnectivityEnabled_shouldShowOff() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 0);
+
+ assertThat(mController.getSummary())
+ .isEqualTo(mContext.getString(R.string.switch_off_text));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
new file mode 100644
index 00000000000..dfb9a8f2136
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/AdaptiveConnectivityTogglePreferenceControllerTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class AdaptiveConnectivityTogglePreferenceControllerTest {
+
+ private static final String PREF_KEY = "adaptive_connectivity";
+
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private Context mContext;
+
+ private AdaptiveConnectivityTogglePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mController = new AdaptiveConnectivityTogglePreferenceController(mContext, PREF_KEY);
+ }
+
+ @Test
+ public void isAvailable_shouldReturnTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void setChecked_withTrue_shouldUpdateSetting() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 0);
+
+ mController.setChecked(true);
+
+ assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
+ .isEqualTo(1);
+ }
+
+ @Test
+ public void setChecked_withFalse_shouldUpdateSetting() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1);
+
+ mController.setChecked(false);
+
+ assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1))
+ .isEqualTo(0);
+ }
+}