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:
@@ -54,4 +54,7 @@
|
|||||||
|
|
||||||
<!-- Whether wallpaper attribution should be shown or not. -->
|
<!-- Whether wallpaper attribution should be shown or not. -->
|
||||||
<bool name="config_show_wallpaper_attribution">true</bool>
|
<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>
|
</resources>
|
||||||
|
@@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -53,7 +54,7 @@ public class DefaultHomePreferenceController extends DefaultAppPreferenceControl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return mContext.getResources().getBoolean(R.bool.config_show_default_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -22,4 +22,5 @@
|
|||||||
<bool name="config_display_recent_apps">false</bool>
|
<bool name="config_display_recent_apps">false</bool>
|
||||||
<bool name="config_location_mode_available">false</bool>
|
<bool name="config_location_mode_available">false</bool>
|
||||||
<bool name="config_show_wallpaper_attribution">false</bool>
|
<bool name="config_show_wallpaper_attribution">false</bool>
|
||||||
|
<bool name="config_show_default_home">false</bool>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -147,20 +147,19 @@ public class DefaultAppSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
public void testNonIndexableKeys_existInXmlLayout() {
|
||||||
final Context context = spy(RuntimeEnvironment.application);
|
final Context context = spy(RuntimeEnvironment.application);
|
||||||
final Context mockContext = mock(Context.class);
|
when(context.getApplicationContext()).thenReturn(context);
|
||||||
when(mockContext.getApplicationContext()).thenReturn(mockContext);
|
|
||||||
final UserManager userManager = mock(UserManager.class, RETURNS_DEEP_STUBS);
|
final UserManager userManager = mock(UserManager.class, RETURNS_DEEP_STUBS);
|
||||||
|
|
||||||
when(mockContext.getSystemService(Context.USER_SERVICE))
|
when(context.getSystemService(Context.USER_SERVICE))
|
||||||
.thenReturn(userManager);
|
.thenReturn(userManager);
|
||||||
when(userManager.getUserInfo(anyInt()).isRestricted()).thenReturn(true);
|
when(userManager.getUserInfo(anyInt()).isRestricted()).thenReturn(true);
|
||||||
|
|
||||||
when(mockContext.getSystemService(Context.TELEPHONY_SERVICE))
|
when(context.getSystemService(Context.TELEPHONY_SERVICE))
|
||||||
.thenReturn(mock(TelephonyManager.class));
|
.thenReturn(mock(TelephonyManager.class));
|
||||||
when(mockContext.getPackageManager())
|
when(context.getPackageManager())
|
||||||
.thenReturn(mock(PackageManager.class));
|
.thenReturn(mock(PackageManager.class));
|
||||||
final List<String> niks = DefaultAppSettings.SEARCH_INDEX_DATA_PROVIDER
|
final List<String> niks = DefaultAppSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(mockContext);
|
.getNonIndexableKeys(context);
|
||||||
|
|
||||||
final int xmlId = (new DefaultAppSettings()).getPreferenceScreenResId();
|
final int xmlId = (new DefaultAppSettings()).getPreferenceScreenResId();
|
||||||
|
|
||||||
|
@@ -45,6 +45,7 @@ import org.mockito.Answers;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -54,18 +55,18 @@ import java.util.Arrays;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class DefaultHomePreferenceControllerTest {
|
public class DefaultHomePreferenceControllerTest {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private PackageManagerWrapper mPackageManager;
|
private PackageManagerWrapper mPackageManager;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private DefaultHomePreferenceController mController;
|
private DefaultHomePreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
|
|
||||||
mController = spy(new DefaultHomePreferenceController(mContext));
|
mController = spy(new DefaultHomePreferenceController(mContext));
|
||||||
@@ -73,10 +74,16 @@ public class DefaultHomePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAlwaysAvailable() {
|
public void testDefaultHome_byDefault_shouldBeShown() {
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void testDefaultHome_ifDisabled_shouldNotBeShown() {
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultApp_shouldGetDefaultBrowserPackage() {
|
public void getDefaultApp_shouldGetDefaultBrowserPackage() {
|
||||||
assertThat(mController.getDefaultAppInfo()).isNotNull();
|
assertThat(mController.getDefaultAppInfo()).isNotNull();
|
||||||
|
Reference in New Issue
Block a user