Migrate to getNetworkSelectionStatus()

isNetworkEnabled() & isNetworkPermanentlyDisabled()
should not be formal APIs. Instead,
getNetworkSelectionStatus() with a set of constants
is sufficient as an API surface, and will be more
maintainable in the future.

Bug: 146046526
Test: atest SettingsUnitTests
Change-Id: If599ce88f68a87fa7186ef96156c2bb1fdc1c2c3
This commit is contained in:
David Su
2020-01-30 20:29:24 -08:00
parent fa6e9f7283
commit 68913c5a8b
3 changed files with 8 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI; import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED;
import static android.os.UserManager.DISALLOW_CONFIG_WIFI; import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
import android.annotation.NonNull; import android.annotation.NonNull;
@@ -730,7 +731,8 @@ public class WifiSettings extends RestrictedSettingsFragment
} }
WifiConfiguration.NetworkSelectionStatus networkStatus = WifiConfiguration.NetworkSelectionStatus networkStatus =
config.getNetworkSelectionStatus(); config.getNetworkSelectionStatus();
if (networkStatus == null || networkStatus.isNetworkEnabled()) { if (networkStatus == null
|| networkStatus.getNetworkSelectionStatus() == NETWORK_SELECTION_ENABLED) {
return false; return false;
} }
int reason = networkStatus.getNetworkSelectionDisableReason(); int reason = networkStatus.getNetworkSelectionDisableReason();

View File

@@ -16,6 +16,7 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED;
import static android.os.UserManager.DISALLOW_CONFIG_WIFI; import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
import android.app.Activity; import android.app.Activity;
@@ -1100,7 +1101,8 @@ public class WifiSettings2 extends RestrictedSettingsFragment
} }
WifiConfiguration.NetworkSelectionStatus networkStatus = WifiConfiguration.NetworkSelectionStatus networkStatus =
config.getNetworkSelectionStatus(); config.getNetworkSelectionStatus();
if (networkStatus == null || networkStatus.isNetworkEnabled()) { if (networkStatus == null
|| networkStatus.getNetworkSelectionStatus() == NETWORK_SELECTION_ENABLED) {
return false; return false;
} }
int reason = networkStatus.getNetworkSelectionDisableReason(); int reason = networkStatus.getNetworkSelectionDisableReason();

View File

@@ -316,7 +316,8 @@ public class WifiSettingsUiTest {
assertThat(accessPoint.getConfig()).isNotNull(); assertThat(accessPoint.getConfig()).isNotNull();
NetworkSelectionStatus networkStatus = accessPoint.getConfig().getNetworkSelectionStatus(); NetworkSelectionStatus networkStatus = accessPoint.getConfig().getNetworkSelectionStatus();
assertThat(networkStatus).isNotNull(); assertThat(networkStatus).isNotNull();
assertThat(networkStatus.isNetworkEnabled()).isFalse(); assertThat(networkStatus.getNetworkSelectionStatus())
.isEqualTo(NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
assertThat(networkStatus.getNetworkSelectionDisableReason()).isEqualTo( assertThat(networkStatus.getNetworkSelectionDisableReason()).isEqualTo(
NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD); NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);