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

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

Merge "Fix tethering summary when airplane mode is off" into pi-dev

parents e2d14d40 4fec12cb
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
    private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
    private static final IntentFilter AIRPLANE_INTENT_FILTER = new IntentFilter(
            Intent.ACTION_AIRPLANE_MODE_CHANGED);
    private static final int ID_NULL = -1;

    private final ConnectivityManager mConnectivityManager;
    private final String[] mWifiRegexs;
@@ -152,7 +153,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
                clearSummaryForAirplaneMode();
                clearSummaryForAirplaneMode(R.string.wifi_hotspot_off_subtext);
            }
        }
    };
@@ -194,10 +195,16 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
    }

    private void clearSummaryForAirplaneMode() {
        clearSummaryForAirplaneMode(ID_NULL);
    }

    private void clearSummaryForAirplaneMode(int defaultId) {
        boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
        if (isAirplaneMode) {
            mPreference.setSummary(R.string.wifi_tether_disabled_by_airplane);
        } else if (defaultId != ID_NULL){
            mPreference.setSummary(defaultId);
        }
    }
    //
+16 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class WifiTetherPreferenceControllerTest {
    }

    @Test
    public void testReceiver_goingToAirplaneMode_shouldClearPreferenceSummary() {
    public void testReceiver_turnOnAirplaneMode_clearPreferenceSummary() {
        final ContentResolver cr = mock(ContentResolver.class);
        when(mContext.getContentResolver()).thenReturn(cr);
        Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 1);
@@ -137,6 +137,21 @@ public class WifiTetherPreferenceControllerTest {
                "Unavailable because airplane mode is turned on");
    }

    @Test
    public void testReceiver_turnOffAirplaneMode_displayOffSummary() {
        final ContentResolver cr = mock(ContentResolver.class);
        when(mContext.getContentResolver()).thenReturn(cr);
        Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 0);
        mController.displayPreference(mScreen);
        final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
        final Intent broadcast = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);

        receiver.onReceive(RuntimeEnvironment.application, broadcast);

        assertThat(mPreference.getSummary().toString()).isEqualTo(
                "Not sharing internet or content with other devices");
    }

    @Test
    public void testHandleWifiApStateChanged_stateEnabling_showEnablingSummary() {
        mController.handleWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0 /* reason */);