Merge "Import translations. DO NOT MERGE ANYWHERE" into rvc-qpr-dev
diff --git a/res/drawable/ic_illustration_adaptive_connectivity.xml b/res/drawable/ic_illustration_adaptive_connectivity.xml
new file mode 100644
index 0000000..748dd66
--- /dev/null
+++ b/res/drawable/ic_illustration_adaptive_connectivity.xml
@@ -0,0 +1,99 @@
+<!--
+    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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="412dp"
+    android:height="300dp"
+    android:viewportWidth="412"
+    android:viewportHeight="300">
+  <path
+      android:pathData="M0,0h412v300h-412z"
+      android:fillColor="#fff"/>
+  <path
+      android:pathData="M206,150m-118,0a118,118 0,1 1,236 0a118,118 0,1 1,-236 0"
+      android:strokeAlpha="0.2"
+      android:fillColor="#8ab4f8"
+      android:fillAlpha="0.2"/>
+  <path
+      android:pathData="M206,150m-101.17,0a101.17,101.17 0,1 1,202.34 0a101.17,101.17 0,1 1,-202.34 0"
+      android:strokeAlpha="0.2"
+      android:fillColor="#8ab4f8"
+      android:fillAlpha="0.2"/>
+  <path
+      android:pathData="M206,150m-84.44,0a84.44,84.44 0,1 1,168.88 0a84.44,84.44 0,1 1,-168.88 0"
+      android:strokeAlpha="0.2"
+      android:fillColor="#8ab4f8"
+      android:fillAlpha="0.2"/>
+  <path
+      android:pathData="M141.15,25.48h129.87v250.83h-129.87z"
+      android:fillColor="#fff"/>
+  <path
+      android:pathData="M199.19,237.66h15.2a4.83,4.83 0,0 1,4.83 4.83h0a4.84,4.84 0,0 1,-4.83 4.84h-15.2a4.84,4.84 0,0 1,-4.83 -4.84h0A4.83,4.83 0,0 1,199.19 237.66Z"
+      android:fillColor="#d2e3fc"/>
+  <path
+      android:pathData="M212.32,235.59h0a6.9,6.9 0,0 1,6.9 6.9h0a6.9,6.9 0,0 1,-6.9 6.91h0a6.91,6.91 0,0 1,-6.91 -6.91h0A6.9,6.9 0,0 1,212.32 235.59Z"
+      android:fillColor="#1a73e8"/>
+  <path
+      android:pathData="M262.43,25.48a5,5 0,0 1,5 5V269.54a5,5 0,0 1,-5 5H147.87a5,5 0,0 1,-5 -5V30.46a5,5 0,0 1,5 -5H262.43m0,-6.23H147.87a11.22,11.22 0,0 0,-11.2 11.21V269.54a11.22,11.22 0,0 0,11.2 11.21H262.43a11.22,11.22 0,0 0,11.21 -11.21V30.46a11.22,11.22 0,0 0,-11.21 -11.21Z"
+      android:fillColor="#f1f3f4"/>
+  <path
+      android:pathData="M262.43,282H147.87a12.46,12.46 0,0 1,-12.45 -12.45V30.46A12.46,12.46 0,0 1,147.87 18H262.43a12.46,12.46 0,0 1,12.45 12.45V269.54A12.46,12.46 0,0 1,262.43 282ZM147.87,20.5a10,10 0,0 0,-10 10V269.54a10,10 0,0 0,10 10H262.43a10,10 0,0 0,10 -10V30.46a10,10 0,0 0,-10 -10Z"
+      android:fillColor="#dadce0"/>
+  <path
+      android:pathData="M274.88,82.76h0.69a1.8,1.8 0,0 1,1.8 1.8V95.9a1.8,1.8 0,0 1,-1.8 1.8h-0.69a0,0 0,0 1,0 0V82.76A0,0 0,0 1,274.88 82.76Z"
+      android:fillColor="#dadce0"/>
+  <path
+      android:pathData="M274.88,117.62h0.69a1.8,1.8 0,0 1,1.8 1.8v26.28a1.8,1.8 0,0 1,-1.8 1.8h-0.69a0,0 0,0 1,0 0V117.62a0,0 0,0 1,0 0Z"
+      android:fillColor="#dadce0"/>
+  <path
+      android:pathData="M206.64,182.08m-16.56,0a16.56,16.56 0,1 1,33.12 0a16.56,16.56 0,1 1,-33.12 0"
+      android:fillColor="#f1f3f4"/>
+  <path
+      android:pathData="M190.08,182.08a16.56,16.53 0,1 0,33.12 0a16.56,16.53 0,1 0,-33.12 0z"
+      android:fillColor="#fdd663"/>
+  <path
+      android:pathData="M206.64,174.54l-6.21,4.66l0,9.32l3.88,0l0,-5.44l4.66,0l0,5.44l3.88,0l0,-9.32l-6.21,-4.66z"
+      android:fillColor="#f29900"/>
+  <path
+      android:pathData="M165.84,101.31m-16.53,0a16.53,16.53 0,1 1,33.06 0a16.53,16.53 0,1 1,-33.06 0"
+      android:fillColor="#f6aea9"/>
+  <path
+      android:pathData="M169.77,108.12V96.07a1,1 0,0 0,-1 -1h-1.32V93.46h-3.14V95H163a1,1 0,0 0,-1 1v12a1,1 0,0 0,1 1h5.76A1,1 0,0 0,169.77 108.12ZM168.2,96.6v5.64h-4.71V96.6Z"
+      android:fillColor="#ea4335"/>
+  <path
+      android:pathData="M246.16,152.08m-16.56,0a16.56,16.56 0,1 1,33.12 0a16.56,16.56 0,1 1,-33.12 0"
+      android:fillColor="#f6aea9"/>
+  <path
+      android:pathData="M251.88,146a1.18,1.18 0,0 0,-1.12 -0.79h-8.63A1.19,1.19 0,0 0,241 146l-1.63,4.7L239.37,157a0.78,0.78 0,0 0,0.78 0.79L241,157.79a0.78,0.78 0,0 0,0.78 -0.79v-0.78h9.42L251.2,157a0.79,0.79 0,0 0,0.79 0.79h0.78a0.79,0.79 0,0 0,0.79 -0.79v-6.28ZM242.88,153.84a1.18,1.18 0,1 1,1.18 -1.17A1.17,1.17 0,0 1,242.91 153.88ZM249.95,153.84a1.18,1.18 0,1 1,1.17 -1.17A1.17,1.17 0,0 1,250 153.88ZM241.52,149.22 L242.37,146.78h8.08l0.85,2.44Z"
+      android:fillColor="#ea4335"/>
+  <path
+      android:pathData="M165.84,152.08m-16.56,0a16.56,16.56 0,1 1,33.12 0a16.56,16.56 0,1 1,-33.12 0"
+      android:fillColor="#aecbfa"/>
+  <path
+      android:pathData="M173.24,149.16a4,4 0,0 0,-4 -3.34h-6.11a4.06,4.06 0,0 0,-4 3.34s-1.27,7.34 -1.27,7.45a1.73,1.73 0,0 0,1.73 1.73,1.7 1.7,0 0,0 1.22,-0.49l2.89,-2.85h5l2.88,2.85a1.71,1.71 0,0 0,1.23 0.49,1.73 1.73,0 0,0 1.73,-1.73C174.52,156.5 173.24,149.16 173.24,149.16ZM165.34,150.83h-1.67v1.67h-0.84v-1.67h-1.66L161.17,150h1.66v-1.67h0.84L163.67,150h1.67ZM167.68,151.08a0.67,0.67 0,1 1,0.66 -0.67A0.67,0.67 0,0 1,167.68 151.08ZM169.09,152.5a0.67,0.67 0,1 1,0.66 -0.67A0.67,0.67 0,0 1,169.09 152.5ZM169.09,149.66a0.67,0.67 0,1 1,0.66 -0.67A0.67,0.67 0,0 1,169.09 149.66ZM170.51,151.08a0.67,0.67 0,1 1,0.67 -0.67A0.67,0.67 0,0 1,170.51 151.08Z"
+      android:fillColor="#4285f4"/>
+  <path
+      android:pathData="M246.16,101.31m-16.53,0a16.53,16.53 0,1 1,33.06 0a16.53,16.53 0,1 1,-33.06 0"
+      android:fillColor="#aecbfa"/>
+  <path
+      android:pathData="M242.91,96.47a4.51,4.51 0,0 0,0 6.49l0.83,-0.83a3.47,3.47 0,0 1,-1 -2.42,3.23 3.23,0 0,1 1,-2.41ZM251.06,94.81 L250.23,95.64a5.84,5.84 0,0 1,0 8.14l0.83,0.83a6.77,6.77 0,0 0,2 -4.9A7.08,7.08 0,0 0,251.06 94.81ZM242.06,95.64 L241.24,94.81a7,7 0,0 0,0 9.8l0.82,-0.83a5.84,5.84 0,0 1,0 -8.14ZM249.38,96.47 L248.55,97.3a3.46,3.46 0,0 1,1 2.41,3.25 3.25,0 0,1 -1,2.42l0.83,0.83a4.61,4.61 0,0 0,1.38 -3.25A4.92,4.92 0,0 0,249.4 96.47ZM246.16,98a1.71,1.71 0,0 0,-1.73 1.72,1.76 1.76,0 0,0 1,1.59v6h1.38v-6a1.75,1.75 0,0 0,1 -1.59A1.71,1.71 0,0 0,246.16 98Z"
+      android:fillColor="#1a73e8"/>
+  <path
+      android:pathData="M206.64,71.31m-16.5,0a16.5,16.5 0,1 1,33 0a16.5,16.5 0,1 1,-33 0"
+      android:fillColor="#a8dab5"/>
+  <path
+      android:pathData="M212.14,65.81h-2.06l1.38,2.75h-2.07L208,65.81h-1.38L208,68.56L206,68.56l-1.37,-2.75L203.2,65.81l1.38,2.75h-2.06l-1.38,-2.75a1.37,1.37 0,0 0,-1.37 1.38v8.25a1.37,1.37 0,0 0,1.37 1.37h11a1.38,1.38 0,0 0,1.38 -1.37L213.52,67.19A1.38,1.38 0,0 0,212.14 65.81ZM212.14,75.44h-11v-5.5h11Z"
+      android:fillColor="#34a853"/>
+</vector>
diff --git a/res/layout/adaptive_connectivity_header.xml b/res/layout/adaptive_connectivity_header.xml
new file mode 100644
index 0000000..4c5fb0c
--- /dev/null
+++ b/res/layout/adaptive_connectivity_header.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  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.
+  -->
+
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:contentDescription="@null"
+        android:scaleType="fitCenter"
+        android:src="@drawable/ic_illustration_adaptive_connectivity"/>
+
+</FrameLayout>
diff --git a/res/values/config.xml b/res/values/config.xml
index fa4bc93..de0dcfb 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -459,4 +459,7 @@
 
     <!-- Whether to show Smooth Display feature in Settings Options -->
     <bool name="config_show_smooth_display">false</bool>
+
+    <!-- Whether to show the Preference for Adaptive connectivity -->
+    <bool name="config_show_adaptive_connectivity">false</bool>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 169fea9..1a7e5e5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6192,6 +6192,11 @@
     <!-- Title of preference to enter the VPN settings activity -->
     <string name="vpn_settings_title">VPN</string>
 
+    <!-- Title of Adaptive connectivity. Adaptive connectivity is a feature which automatically manages network connections for better battery life and performance. [CHAR LIMIT=60] -->
+    <string name="adaptive_connectivity_title">Adaptive connectivity</string>
+    <!-- Summary of Adaptive connectivity preference. [CHAR LIMIT=NONE] -->
+    <string name="adaptive_connectivity_summary">Extends battery life and improves device performance by automatically managing your network connections</string>
+
     <!-- Title of preference group for credential storage settings [CHAR LIMIT=30] -->
     <string name="credentials_title">Credential storage</string>
     <!-- Title of preference to install certificates [CHAR LIMIT=30] -->
diff --git a/res/xml/adaptive_connectivity_settings.xml b/res/xml/adaptive_connectivity_settings.xml
new file mode 100644
index 0000000..ff9bdb0
--- /dev/null
+++ b/res/xml/adaptive_connectivity_settings.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
+    android:title="@string/adaptive_connectivity_title">
+
+    <com.android.settingslib.widget.LayoutPreference
+        android:key="adaptive_connectivity_header"
+        android:layout="@layout/adaptive_connectivity_header"
+        android:persistent="false"
+        android:selectable="false"
+        android:title="@string/summary_placeholder"
+        settings:allowDividerBelow="true"
+        settings:searchable="false"/>
+
+    <SwitchPreference
+        android:key="adaptive_connectivity"
+        android:title="@string/adaptive_connectivity_title"
+        android:summary="@string/adaptive_connectivity_summary"
+        settings:allowDividerAbove="true"
+        settings:controller="com.android.settings.network.AdaptiveConnectivityTogglePreferenceController"/>
+
+</PreferenceScreen>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index eaa7808..6bf6dba 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" />
 
+    <Preference
+        android:fragment="com.android.settings.network.AdaptiveConnectivitySettings"
+        android:key="adaptive_connectivity"
+        android:title="@string/adaptive_connectivity_title"
+        android:summary="@string/summary_placeholder"
+        android:order="25"
+        settings:controller="com.android.settings.network.AdaptiveConnectivityPreferenceController"/>
 </PreferenceScreen>
diff --git a/src/com/android/settings/network/AdaptiveConnectivityPreferenceController.java b/src/com/android/settings/network/AdaptiveConnectivityPreferenceController.java
new file mode 100644
index 0000000..33d1d5b
--- /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 0000000..5e1dc12
--- /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 0000000..e072b5c
--- /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/src/com/android/settings/notification/history/NotificationSbnViewHolder.java b/src/com/android/settings/notification/history/NotificationSbnViewHolder.java
index de12847..ac39f88 100644
--- a/src/com/android/settings/notification/history/NotificationSbnViewHolder.java
+++ b/src/com/android/settings/notification/history/NotificationSbnViewHolder.java
@@ -108,7 +108,7 @@
                                 : NotificationHistoryActivity.NotificationHistoryEvent
                                 .NOTIFICATION_HISTORY_RECENT_ITEM_CLICK,
                         uid, pkg, instanceId, position);
-                if (pi != null) {
+                if (pi != null && isPendingIntentValid) {
                     try {
                         pi.send();
                     } catch (PendingIntent.CanceledException e) {
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 0000000..9ba6238
--- /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 0000000..dfb9a8f
--- /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);
+    }
+}