Add ability to show/hide default_home preference.

This adds a new boolean flag, config_show_default_home, which when set
to false will hide the default_home preference item.

Bug: 62378256
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=DefaultHomePreferenceControllerTest

Change-Id: Ibbf17ebb76b61fc8b2eac84016e3d874ca15a513
This commit is contained in:
Ben Lin
2017-12-18 17:55:40 -08:00
parent 86097b0e19
commit b60d2cbb5b
5 changed files with 21 additions and 10 deletions

View File

@@ -54,4 +54,7 @@
<!-- Whether wallpaper attribution should be shown or not. -->
<bool name="config_show_wallpaper_attribution">true</bool>
<!-- Whether default_home should be shown or not. -->
<bool name="config_show_default_home">true</bool>
</resources>

View File

@@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import com.android.settings.R;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import java.util.ArrayList;
@@ -53,7 +54,7 @@ public class DefaultHomePreferenceController extends DefaultAppPreferenceControl
@Override
public boolean isAvailable() {
return true;
return mContext.getResources().getBoolean(R.bool.config_show_default_home);
}
@Override

View File

@@ -22,4 +22,5 @@
<bool name="config_display_recent_apps">false</bool>
<bool name="config_location_mode_available">false</bool>
<bool name="config_show_wallpaper_attribution">false</bool>
<bool name="config_show_default_home">false</bool>
</resources>

View File

@@ -147,20 +147,19 @@ public class DefaultAppSettingsTest {
@Test
public void testNonIndexableKeys_existInXmlLayout() {
final Context context = spy(RuntimeEnvironment.application);
final Context mockContext = mock(Context.class);
when(mockContext.getApplicationContext()).thenReturn(mockContext);
when(context.getApplicationContext()).thenReturn(context);
final UserManager userManager = mock(UserManager.class, RETURNS_DEEP_STUBS);
when(mockContext.getSystemService(Context.USER_SERVICE))
when(context.getSystemService(Context.USER_SERVICE))
.thenReturn(userManager);
when(userManager.getUserInfo(anyInt()).isRestricted()).thenReturn(true);
when(mockContext.getSystemService(Context.TELEPHONY_SERVICE))
when(context.getSystemService(Context.TELEPHONY_SERVICE))
.thenReturn(mock(TelephonyManager.class));
when(mockContext.getPackageManager())
when(context.getPackageManager())
.thenReturn(mock(PackageManager.class));
final List<String> niks = DefaultAppSettings.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mockContext);
.getNonIndexableKeys(context);
final int xmlId = (new DefaultAppSettings()).getPreferenceScreenResId();

View File

@@ -45,6 +45,7 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import java.util.Arrays;
@@ -54,18 +55,18 @@ import java.util.Arrays;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DefaultHomePreferenceControllerTest {
@Mock
private Context mContext;
@Mock
private UserManager mUserManager;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PackageManagerWrapper mPackageManager;
private Context mContext;
private DefaultHomePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mController = spy(new DefaultHomePreferenceController(mContext));
@@ -73,10 +74,16 @@ public class DefaultHomePreferenceControllerTest {
}
@Test
public void isAlwaysAvailable() {
public void testDefaultHome_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testDefaultHome_ifDisabled_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getDefaultApp_shouldGetDefaultBrowserPackage() {
assertThat(mController.getDefaultAppInfo()).isNotNull();