Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6b0490d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents c2b151d8 e5e8f036
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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>

+3 −1
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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>
+23 −9
Original line number Diff line number Diff line
@@ -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;
@@ -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);

@@ -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();
    }
}