Merge "Add ability to show/hide airplane toggle."

This commit is contained in:
TreeHugger Robot
2018-01-16 20:16:16 +00:00
committed by Android (Google) Code Review
4 changed files with 32 additions and 12 deletions

View File

@@ -54,6 +54,9 @@
surface in search results or not.-->
<bool name="config_show_wifi_settings">true</bool>
<!-- Whether toggle_airplane is available or not. -->
<bool name="config_show_toggle_airplane">true</bool>
<!-- Whether location mode is available or not. -->
<bool name="config_location_mode_available">true</bool>

View File

@@ -30,6 +30,7 @@ import com.android.settings.AirplaneModeEnabler;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
@@ -91,7 +92,8 @@ public class AirplaneModePreferenceController extends AbstractPreferenceControll
}
public static boolean isAvailable(Context context) {
return !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
return context.getResources().getBoolean(R.bool.config_show_toggle_airplane)
&& !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}
@Override

View File

@@ -21,6 +21,7 @@
<bool name="config_show_connectivity_monitor">false</bool>
<bool name="config_display_recent_apps">false</bool>
<bool name="config_show_wifi_settings">false</bool>
<bool name="config_show_toggle_airplane">false</bool>
<bool name="config_show_high_power_apps">false</bool>
<bool name="config_show_alarm_volume">false</bool>
<bool name="config_show_charging_sounds">false</bool>

View File

@@ -16,7 +16,7 @@
package com.android.settings.network;
import static junit.framework.Assert.assertFalse;
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;
@@ -38,24 +38,20 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AirplaneModePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private Resources mResources;
@Mock
private PreferenceScreen mScreen;
@Mock
private PackageManager mPackageManager;
private Context mContext;
private AirplaneModePreferenceController mController;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle;
@@ -65,7 +61,7 @@ public class AirplaneModePreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
doReturn(mResources).when(mContext).getResources();
mContext = spy(RuntimeEnvironment.application);
doReturn(mPackageManager).when(mContext).getPackageManager();
mController = spy(new AirplaneModePreferenceController(mContext, null));
mLifecycleOwner = () -> mLifecycle;
@@ -74,9 +70,9 @@ public class AirplaneModePreferenceControllerTest {
}
@Test
public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
assertFalse(mController.isAvailable());
@Config(qualifiers = "mcc999")
public void airplaneModePreference_shouldNotBeAvailable_ifSetToNotVisible() {
assertThat(mController.isAvailable()).isFalse();
mController.displayPreference(mScreen);
@@ -84,4 +80,22 @@ public class AirplaneModePreferenceControllerTest {
mController.onResume();
mController.onPause();
}
@Test
public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
assertThat(mController.isAvailable()).isFalse();
mController.displayPreference(mScreen);
// This should not crash
mController.onResume();
mController.onPause();
}
@Test
public void airplaneModePreference_shouldBeAvailable_ifNoLeanbackFeature() {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(false);
assertThat(mController.isAvailable()).isTrue();
}
}