From b94251ad07bb65ebebecd10d0895b3e969be8fb5 Mon Sep 17 00:00:00 2001 From: Salvador Martinez Date: Fri, 8 Mar 2019 14:38:21 -0800 Subject: [PATCH] Remove airplane mode restriction on hotspot This isn't needed anymore since we support this now. Test: robotests Bug: 111681176 Change-Id: I0292f0a38347e4fa3414170e0351a53f5997a192 --- .../WifiTetherPreferenceController.java | 38 ------------------- .../tether/WifiTetherSwitchBarController.java | 11 +----- .../WifiTetherPreferenceControllerTest.java | 30 --------------- .../WifiTetherSwitchBarControllerTest.java | 12 +----- 4 files changed, 2 insertions(+), 89 deletions(-) diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java index 2ae6b586ae6..8f6d489e7a7 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java @@ -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 - // } diff --git a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java index 8d87b3284b2..0f31d19535c 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java @@ -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); - } + mSwitchBar.setEnabled(!mDataSaverBackend.isDataSaverEnabled()); } @Override diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java index d8cd878ae78..06716db4439 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java @@ -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 */); diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java index 1a5a2288bb4..30358da69e4 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java @@ -73,17 +73,7 @@ public class WifiTetherSwitchBarControllerTest { mController = new WifiTetherSwitchBarController(mContext, 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);