Remove airplane mode restriction on hotspot
This isn't needed anymore since we support this now. Test: robotests Bug: 111681176 Change-Id: I0292f0a38347e4fa3414170e0351a53f5997a192
This commit is contained in:
@@ -43,9 +43,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
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;
|
||||
@@ -103,8 +100,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mPreference != null) {
|
||||
mContext.registerReceiver(mReceiver, AIRPLANE_INTENT_FILTER);
|
||||
clearSummaryForAirplaneMode();
|
||||
if (mWifiTetherSoftApManager != null) {
|
||||
mWifiTetherSoftApManager.registerSoftApCallback();
|
||||
}
|
||||
@@ -114,7 +109,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mPreference != null) {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
if (mWifiTetherSoftApManager != null) {
|
||||
mWifiTetherSoftApManager.unRegisterSoftApCallback();
|
||||
}
|
||||
@@ -146,19 +140,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Everything below is copied from WifiApEnabler
|
||||
//
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
|
||||
clearSummaryForAirplaneMode(R.string.wifi_hotspot_off_subtext);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
void handleWifiApStateChanged(int state, int reason) {
|
||||
switch (state) {
|
||||
@@ -174,7 +155,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
break;
|
||||
case WifiManager.WIFI_AP_STATE_DISABLED:
|
||||
mPreference.setSummary(R.string.wifi_hotspot_off_subtext);
|
||||
clearSummaryForAirplaneMode();
|
||||
break;
|
||||
default:
|
||||
if (reason == WifiManager.SAP_START_FAILURE_NO_CHANNEL) {
|
||||
@@ -182,7 +162,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
} else {
|
||||
mPreference.setSummary(R.string.wifi_error);
|
||||
}
|
||||
clearSummaryForAirplaneMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,21 +173,4 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
BidiFormatter.getInstance().unicodeWrap(
|
||||
(wifiConfig == null) ? s : wifiConfig.SSID)));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Everything above is copied from WifiApEnabler
|
||||
//
|
||||
}
|
||||
|
@@ -61,7 +61,6 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
|
||||
|
||||
static {
|
||||
WIFI_INTENT_FILTER = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
WIFI_INTENT_FILTER.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
}
|
||||
|
||||
WifiTetherSwitchBarController(Context context, SwitchWidgetController switchBar) {
|
||||
@@ -119,8 +118,6 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
|
||||
final int state = intent.getIntExtra(
|
||||
WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED);
|
||||
handleWifiApStateChanged(state);
|
||||
} else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
|
||||
updateWifiSwitch();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -154,13 +151,7 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
|
||||
}
|
||||
|
||||
private void updateWifiSwitch() {
|
||||
boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
|
||||
if (!isAirplaneMode) {
|
||||
mSwitchBar.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
|
||||
} else {
|
||||
mSwitchBar.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -111,36 +111,6 @@ public class WifiTetherPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
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(
|
||||
"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 */);
|
||||
|
@@ -74,16 +74,6 @@ public class WifiTetherSwitchBarControllerTest {
|
||||
new SwitchBarController(mSwitchBar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_airplaneModeOn_switchBarDisabled() {
|
||||
Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
|
||||
new WifiTetherSwitchBarController(mContext, new SwitchBarController(mSwitchBar));
|
||||
|
||||
assertThat(mSwitchBar.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startTether_fail_resetSwitchBar() {
|
||||
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
|
||||
|
Reference in New Issue
Block a user