Loading res/values/bools.xml +3 −0 Original line number Diff line number Diff line Loading @@ -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> Loading src/com/android/settings/network/AirplaneModePreferenceController.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading tests/robotests/res/values-mcc999/config.xml +1 −0 Original line number Diff line number Diff line Loading @@ -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> Loading tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java +23 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -73,10 +69,22 @@ public class AirplaneModePreferenceControllerTest { mLifecycle.addObserver(mController); } @Test @Config(qualifiers = "mcc999") public void airplaneModePreference_shouldNotBeAvailable_ifSetToNotVisible() { assertThat(mController.isAvailable()).isFalse(); mController.displayPreference(mScreen); // This should not crash mController.onResume(); mController.onPause(); } @Test public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() { when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true); assertFalse(mController.isAvailable()); assertThat(mController.isAvailable()).isFalse(); mController.displayPreference(mScreen); Loading @@ -84,4 +92,10 @@ public class AirplaneModePreferenceControllerTest { mController.onResume(); mController.onPause(); } @Test public void airplaneModePreference_shouldBeAvailable_ifNoLeanbackFeature() { when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(false); assertThat(mController.isAvailable()).isTrue(); } } Loading
res/values/bools.xml +3 −0 Original line number Diff line number Diff line Loading @@ -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> Loading
src/com/android/settings/network/AirplaneModePreferenceController.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
tests/robotests/res/values-mcc999/config.xml +1 −0 Original line number Diff line number Diff line Loading @@ -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> Loading
tests/robotests/src/com/android/settings/network/AirplaneModePreferenceControllerTest.java +23 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -73,10 +69,22 @@ public class AirplaneModePreferenceControllerTest { mLifecycle.addObserver(mController); } @Test @Config(qualifiers = "mcc999") public void airplaneModePreference_shouldNotBeAvailable_ifSetToNotVisible() { assertThat(mController.isAvailable()).isFalse(); mController.displayPreference(mScreen); // This should not crash mController.onResume(); mController.onPause(); } @Test public void airplaneModePreference_shouldNotBeAvailable_ifHasLeanbackFeature() { when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(true); assertFalse(mController.isAvailable()); assertThat(mController.isAvailable()).isFalse(); mController.displayPreference(mScreen); Loading @@ -84,4 +92,10 @@ public class AirplaneModePreferenceControllerTest { mController.onResume(); mController.onPause(); } @Test public void airplaneModePreference_shouldBeAvailable_ifNoLeanbackFeature() { when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)).thenReturn(false); assertThat(mController.isAvailable()).isTrue(); } }