[Wi-Fi] Support intent extra "wifi_start_connect_ssid" in WifiSettings2
This is a similar code merge of ag/575560 & ag/2588374 Bug: 143328194 Test: manual Connect to a Wi-Fi network with wrong network. Click the fail notification and launch Wi-Fi picker. Check if the editor shows the specified Wi-Fi network. Change-Id: I5bc8cd0ea51e7baf3d6d2d6d522a3973b74ef930
This commit is contained in:
@@ -149,6 +149,12 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
// Enable the Next button when a Wi-Fi network is connected.
|
||||
private boolean mEnableNextOnConnection;
|
||||
|
||||
// This string extra specifies a network to open the connect dialog on, so the user can enter
|
||||
// network credentials. This is used by quick settings for secured networks, among other
|
||||
// things.
|
||||
private static final String EXTRA_START_CONNECT_SSID = "wifi_start_connect_ssid";
|
||||
private String mOpenSsid;
|
||||
|
||||
private static boolean isVerboseLoggingEnabled() {
|
||||
return WifiPickerTracker.isVerboseLoggingEnabled();
|
||||
}
|
||||
@@ -341,6 +347,10 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
// state, start it off in the right state.
|
||||
final Intent intent = getActivity().getIntent();
|
||||
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
||||
|
||||
if (intent.hasExtra(EXTRA_START_CONNECT_SSID)) {
|
||||
mOpenSsid = intent.getStringExtra(EXTRA_START_CONNECT_SSID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -398,6 +408,21 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
changeNextButtonState(mWifiPickerTracker.getConnectedWifiEntry() != null);
|
||||
|
||||
// Edit the Wi-Fi network of specified SSID.
|
||||
if (mOpenSsid != null) {
|
||||
Optional<WifiEntry> matchedWifiEntry = mWifiPickerTracker.getWifiEntries().stream()
|
||||
.filter(wifiEntry -> TextUtils.equals(mOpenSsid, wifiEntry.getSsid()))
|
||||
.filter(wifiEntry -> wifiEntry.getSecurity() != WifiEntry.SECURITY_NONE
|
||||
&& wifiEntry.getSecurity() != WifiEntry.SECURITY_OWE)
|
||||
.filter(wifiEntry -> !wifiEntry.isSaved()
|
||||
|| isDisabledByWrongPassword(wifiEntry))
|
||||
.findFirst();
|
||||
if (matchedWifiEntry.isPresent()) {
|
||||
mOpenSsid = null;
|
||||
launchConfigNewNetworkFragment(matchedWifiEntry.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1042,16 +1067,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
if (mEditIfNoConfig) {
|
||||
// Edit an unsaved secure Wi-Fi network.
|
||||
if (mFullScreenEdit) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
|
||||
mConnectWifiEntry.getKey());
|
||||
new SubSettingLauncher(getContext())
|
||||
.setTitleText(mConnectWifiEntry.getTitle())
|
||||
.setDestination(ConfigureWifiEntryFragment.class.getName())
|
||||
.setArguments(bundle)
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.setResultListener(WifiSettings2.this, CONFIG_NETWORK_REQUEST)
|
||||
.launch();
|
||||
launchConfigNewNetworkFragment(mConnectWifiEntry);
|
||||
} else {
|
||||
showDialog(mConnectWifiEntry, WifiConfigUiBase2.MODE_MODIFY);
|
||||
}
|
||||
@@ -1081,4 +1097,32 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
private boolean isFisishingOrDestroyed(Activity activity) {
|
||||
return activity == null || activity.isFinishing() || activity.isDestroyed();
|
||||
}
|
||||
|
||||
private void launchConfigNewNetworkFragment(WifiEntry wifiEntry) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
|
||||
wifiEntry.getKey());
|
||||
new SubSettingLauncher(getContext())
|
||||
.setTitleText(wifiEntry.getTitle())
|
||||
.setDestination(ConfigureWifiEntryFragment.class.getName())
|
||||
.setArguments(bundle)
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.setResultListener(WifiSettings2.this, CONFIG_NETWORK_REQUEST)
|
||||
.launch();
|
||||
}
|
||||
|
||||
/** Helper method to return whether an WifiEntry is disabled due to a wrong password */
|
||||
private static boolean isDisabledByWrongPassword(WifiEntry wifiEntry) {
|
||||
WifiConfiguration config = wifiEntry.getWifiConfiguration();
|
||||
if (config == null) {
|
||||
return false;
|
||||
}
|
||||
WifiConfiguration.NetworkSelectionStatus networkStatus =
|
||||
config.getNetworkSelectionStatus();
|
||||
if (networkStatus == null || networkStatus.isNetworkEnabled()) {
|
||||
return false;
|
||||
}
|
||||
int reason = networkStatus.getNetworkSelectionDisableReason();
|
||||
return WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD == reason;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user