Add boolean flags to show/hide top-most settings.

Bug: None
Test: RunSettingsRoboTests
Change-Id: Ib576f5979feda0fa7f573915acffc5065d40095c
This commit is contained in:
Ben Lin
2018-12-14 16:00:21 -08:00
parent 0f95d9c45d
commit 11f698ba22
8 changed files with 65 additions and 6 deletions

View File

@@ -168,6 +168,15 @@
<!-- Whether device_model should be shown or not. --> <!-- Whether device_model should be shown or not. -->
<bool name="config_show_device_model">true</bool> <bool name="config_show_device_model">true</bool>
<!-- Whether top_level_battery should be shown or not. -->
<bool name="config_show_top_level_battery">true</bool>
<!-- Whether top_level_connected_devices should be shown or not. -->
<bool name="config_show_top_level_connected_devices">true</bool>
<!-- Whether top_level_display should be shown or not. -->
<bool name="config_show_top_level_display">true</bool>
<!-- Whether wifi_ip_address should be shown or not. --> <!-- Whether wifi_ip_address should be shown or not. -->
<bool name="config_show_wifi_ip_address">true</bool> <bool name="config_show_wifi_ip_address">true</bool>

View File

@@ -19,6 +19,7 @@ package com.android.settings.connecteddevice;
import android.content.Context; import android.content.Context;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.R;
public class TopLevelConnectedDevicesPreferenceController extends BasePreferenceController { public class TopLevelConnectedDevicesPreferenceController extends BasePreferenceController {
@@ -29,7 +30,9 @@ public class TopLevelConnectedDevicesPreferenceController extends BasePreference
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE; return mContext.getResources().getBoolean(R.bool.config_show_top_level_connected_devices)
? AVAILABLE_UNSEARCHABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -29,7 +29,9 @@ public class TopLevelDisplayPreferenceController extends BasePreferenceControlle
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE; return mContext.getResources().getBoolean(R.bool.config_show_top_level_display)
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -48,7 +48,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE; return mContext.getResources().getBoolean(R.bool.config_show_top_level_battery)
? AVAILABLE_UNSEARCHABLE
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -58,6 +58,9 @@
<bool name="config_show_system_update_settings">false</bool> <bool name="config_show_system_update_settings">false</bool>
<bool name="config_wifi_support_connected_mac_randomization">false</bool> <bool name="config_wifi_support_connected_mac_randomization">false</bool>
<bool name="config_show_device_model">false</bool> <bool name="config_show_device_model">false</bool>
<bool name="config_show_top_level_battery">false</bool>
<bool name="config_show_top_level_connected_devices">false</bool>
<bool name="config_show_top_level_display">false</bool>
<bool name="config_show_wifi_ip_address">false</bool> <bool name="config_show_wifi_ip_address">false</bool>
<bool name="config_show_wifi_mac_address">false</bool> <bool name="config_show_wifi_mac_address">false</bool>
<bool name="config_disable_uninstall_update">true</bool> <bool name="config_disable_uninstall_update">true</bool>

View File

@@ -16,6 +16,9 @@
package com.android.settings.connecteddevice; package com.android.settings.connecteddevice;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
@@ -43,6 +46,17 @@ public class TopLevelConnectedDevicesPreferenceControllerTest {
mController = new TopLevelConnectedDevicesPreferenceController(mContext, "test_key"); mController = new TopLevelConnectedDevicesPreferenceController(mContext, "test_key");
} }
@Test
public void getAvailibilityStatus_availableByDefault() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
@Config(qualifiers = "mcc999")
public void getAvailabilityStatus_unsupportedWhenSet() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test @Test
@Config(shadows = ShadowAdvancedConnectedDeviceController.class) @Config(shadows = ShadowAdvancedConnectedDeviceController.class)
public void getSummary_shouldCallAdvancedConnectedDeviceController() { public void getSummary_shouldCallAdvancedConnectedDeviceController() {

View File

@@ -17,12 +17,14 @@
package com.android.settings.display; package com.android.settings.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE; 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -40,11 +42,13 @@ import org.mockito.MockitoAnnotations;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class TopLevelDisplayPreferenceControllerTest { public class TopLevelDisplayPreferenceControllerTest {
@Mock
private Context mContext; private Context mContext;
@Mock @Mock
private PackageManager mPackageManager; private PackageManager mPackageManager;
@@ -54,6 +58,7 @@ public class TopLevelDisplayPreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getString(R.string.config_wallpaper_picker_package)).thenReturn("pkg"); when(mContext.getString(R.string.config_wallpaper_picker_package)).thenReturn("pkg");
when(mContext.getString(R.string.config_wallpaper_picker_class)).thenReturn("cls"); when(mContext.getString(R.string.config_wallpaper_picker_class)).thenReturn("cls");
@@ -62,10 +67,16 @@ public class TopLevelDisplayPreferenceControllerTest {
} }
@Test @Test
public void getAvailability_alwaysAvailable() { public void getAvailibilityStatus_availableByDefault() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
} }
@Test
@Config(qualifiers = "mcc999")
public void getAvailabilityStatus_unsupportedWhenSet() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test @Test
public void getSummary_hasWallpaper_shouldReturnWallpaperSummary() { public void getSummary_hasWallpaper_shouldReturnWallpaperSummary() {
final List<ResolveInfo> resolveInfos = new ArrayList<>(); final List<ResolveInfo> resolveInfos = new ArrayList<>();

View File

@@ -16,6 +16,8 @@
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel; import static com.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -25,17 +27,30 @@ import android.content.Context;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class TopLevelBatteryPreferenceControllerTest { public class TopLevelBatteryPreferenceControllerTest {
private Context mContext; private Context mContext;
private TopLevelBatteryPreferenceController mController;
@Before @Before
public void setUp() { public void setUp() {
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mController = new TopLevelBatteryPreferenceController(mContext, "test_key");
}
@Test
public void getAvailibilityStatus_availableByDefault() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
@Config(qualifiers = "mcc999")
public void getAvailabilityStatus_unsupportedWhenSet() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@Test @Test