Merge "Add ability to show/hide airplane toggle."
This commit is contained in:
committed by
Android (Google) Code Review
commit
d6b0490dea
@@ -54,6 +54,9 @@
|
|||||||
surface in search results or not.-->
|
surface in search results or not.-->
|
||||||
<bool name="config_show_wifi_settings">true</bool>
|
<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. -->
|
<!-- Whether location mode is available or not. -->
|
||||||
<bool name="config_location_mode_available">true</bool>
|
<bool name="config_location_mode_available">true</bool>
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@ import com.android.settings.AirplaneModeEnabler;
|
|||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
@@ -91,7 +92,8 @@ public class AirplaneModePreferenceController extends AbstractPreferenceControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAvailable(Context context) {
|
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
|
@Override
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
<bool name="config_show_connectivity_monitor">false</bool>
|
<bool name="config_show_connectivity_monitor">false</bool>
|
||||||
<bool name="config_display_recent_apps">false</bool>
|
<bool name="config_display_recent_apps">false</bool>
|
||||||
<bool name="config_show_wifi_settings">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_high_power_apps">false</bool>
|
||||||
<bool name="config_show_alarm_volume">false</bool>
|
<bool name="config_show_alarm_volume">false</bool>
|
||||||
<bool name="config_show_charging_sounds">false</bool>
|
<bool name="config_show_charging_sounds">false</bool>
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
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.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -38,24 +38,20 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class AirplaneModePreferenceControllerTest {
|
public class AirplaneModePreferenceControllerTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Resources mResources;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private AirplaneModePreferenceController mController;
|
private AirplaneModePreferenceController mController;
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private LifecycleOwner mLifecycleOwner;
|
||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
@@ -65,7 +61,7 @@ public class AirplaneModePreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mFactory = FakeFeatureFactory.setupForTest();
|
mFactory = FakeFeatureFactory.setupForTest();
|
||||||
doReturn(mResources).when(mContext).getResources();
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||||
mController = spy(new AirplaneModePreferenceController(mContext, null));
|
mController = spy(new AirplaneModePreferenceController(mContext, null));
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
mLifecycleOwner = () -> mLifecycle;
|
||||||
@@ -74,9 +70,9 @@ public class AirplaneModePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() {
|
@Config(qualifiers = "mcc999")
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true);
|
public void airplaneModePreference_shouldNotBeAvailable_ifSetToNotVisible() {
|
||||||
assertFalse(mController.isAvailable());
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
@@ -84,4 +80,22 @@ public class AirplaneModePreferenceControllerTest {
|
|||||||
mController.onResume();
|
mController.onResume();
|
||||||
mController.onPause();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user