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

This commit is contained in:
TreeHugger Robot
2018-05-18 00:49:50 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 2 deletions

View File

@@ -44,6 +44,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
private static final String WIFI_TETHER_SETTINGS = "wifi_tether"; private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
private static final IntentFilter AIRPLANE_INTENT_FILTER = new IntentFilter( private static final IntentFilter AIRPLANE_INTENT_FILTER = new IntentFilter(
Intent.ACTION_AIRPLANE_MODE_CHANGED); Intent.ACTION_AIRPLANE_MODE_CHANGED);
private static final int ID_NULL = -1;
private final ConnectivityManager mConnectivityManager; private final ConnectivityManager mConnectivityManager;
private final String[] mWifiRegexs; private final String[] mWifiRegexs;
@@ -152,7 +153,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { 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() { private void clearSummaryForAirplaneMode() {
clearSummaryForAirplaneMode(ID_NULL);
}
private void clearSummaryForAirplaneMode(int defaultId) {
boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(), boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0; Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
if (isAirplaneMode) { if (isAirplaneMode) {
mPreference.setSummary(R.string.wifi_tether_disabled_by_airplane); mPreference.setSummary(R.string.wifi_tether_disabled_by_airplane);
} else if (defaultId != ID_NULL){
mPreference.setSummary(defaultId);
} }
} }
// //

View File

@@ -123,7 +123,7 @@ public class WifiTetherPreferenceControllerTest {
} }
@Test @Test
public void testReceiver_goingToAirplaneMode_shouldClearPreferenceSummary() { public void testReceiver_turnOnAirplaneMode_clearPreferenceSummary() {
final ContentResolver cr = mock(ContentResolver.class); final ContentResolver cr = mock(ContentResolver.class);
when(mContext.getContentResolver()).thenReturn(cr); when(mContext.getContentResolver()).thenReturn(cr);
Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 1); Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 1);
@@ -137,6 +137,21 @@ public class WifiTetherPreferenceControllerTest {
"Unavailable because airplane mode is turned on"); "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 @Test
public void testHandleWifiApStateChanged_stateEnabling_showEnablingSummary() { public void testHandleWifiApStateChanged_stateEnabling_showEnablingSummary() {
mController.handleWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0 /* reason */); mController.handleWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0 /* reason */);