OSDN Git Service

Add a boolean flag to show or hide Private DNS in Network & internet.
authorBen Lin <linben@google.com>
Thu, 26 Jul 2018 19:06:48 +0000 (12:06 -0700)
committerBen Lin <linben@google.com>
Thu, 26 Jul 2018 19:12:25 +0000 (12:12 -0700)
The following boolean flag is added:
config_show_private_dns_settings

When set to false, Private DNS will not be shown in Network & internet.

Bug: 111398942
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=PrivateDnsPreferenceControllerTest
Change-Id: I62911930680355b7fc109b295d8526bdb7eac0b3

res/values/bools.xml
src/com/android/settings/network/PrivateDnsPreferenceController.java
tests/robotests/res/values-mcc999/config.xml
tests/robotests/src/com/android/settings/network/PrivateDnsPreferenceControllerTest.java

index b406605..ef8c5b6 100644 (file)
@@ -57,6 +57,9 @@
     <!-- Whether toggle_airplane is available or not. -->
     <bool name="config_show_toggle_airplane">true</bool>
 
+    <!-- Whether private_dns_settings is available or not. -->
+    <bool name="config_show_private_dns_settings">true</bool>
+
     <!-- Whether memory from app_info_settings is available or not. -->
     <bool name="config_show_app_info_settings_memory">false</bool>
 
index ce3a9c0..1c62f81 100644 (file)
@@ -80,7 +80,9 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
 
     @Override
     public int getAvailabilityStatus() {
-        return AVAILABLE;
+        return mContext.getResources().getBoolean(R.bool.config_show_private_dns_settings)
+                ? AVAILABLE
+                : UNSUPPORTED_ON_DEVICE;
     }
 
     @Override
index 2d95b65..1228a06 100644 (file)
@@ -23,6 +23,7 @@
     <bool name="config_additional_system_update_setting_enable">true</bool>
     <bool name="config_show_wifi_settings">false</bool>
     <bool name="config_show_toggle_airplane">false</bool>
+    <bool name="config_show_private_dns_settings">false</bool>
     <bool name="config_show_app_info_settings_memory">true</bool>
     <bool name="config_show_app_info_settings_battery">false</bool>
     <bool name="config_show_high_power_apps">false</bool>
index 47354c7..eb17bcb 100644 (file)
@@ -24,6 +24,8 @@ import static android.provider.Settings.Global.PRIVATE_DNS_MODE;
 import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER;
 import static androidx.lifecycle.Lifecycle.Event.ON_START;
 import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.anyString;
@@ -57,6 +59,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.shadow.api.Shadow;
 import org.robolectric.shadows.ShadowContentResolver;
@@ -144,6 +147,17 @@ public class PrivateDnsPreferenceControllerTest {
     }
 
     @Test
+    public void getAvailibilityStatus_availableByDefault() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void getAvailabilityStatus_unsupportedWhenSet() {
+        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
     public void goThroughLifecycle_shouldRegisterUnregisterSettingsObserver() {
         mLifecycle.handleLifecycleEvent(ON_START);
         verify(mContext, atLeastOnce()).getContentResolver();