[Wi-Fi] Support intent extra "wifi_enable_next_on_connect" in WifiSettings2
This is a similar code merge of ag/489459. Bug: 143328194 Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiSettings2Test Change-Id: I666b3293f00aa1822a6fdcc3760ae19d27019597
This commit is contained in:
@@ -142,6 +142,13 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
private String mDialogWifiEntryKey;
|
private String mDialogWifiEntryKey;
|
||||||
private WifiEntry mDialogWifiEntry;
|
private WifiEntry mDialogWifiEntry;
|
||||||
|
|
||||||
|
// This boolean extra specifies whether to enable the Next button when connected. Used by
|
||||||
|
// account creation outside of setup wizard.
|
||||||
|
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
|
||||||
|
|
||||||
|
// Enable the Next button when a Wi-Fi network is connected.
|
||||||
|
private boolean mEnableNextOnConnection;
|
||||||
|
|
||||||
private static boolean isVerboseLoggingEnabled() {
|
private static boolean isVerboseLoggingEnabled() {
|
||||||
return WifiPickerTracker.isVerboseLoggingEnabled();
|
return WifiPickerTracker.isVerboseLoggingEnabled();
|
||||||
}
|
}
|
||||||
@@ -329,6 +336,11 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we're supposed to enable/disable the Next button based on our current connection
|
||||||
|
// state, start it off in the right state.
|
||||||
|
final Intent intent = getActivity().getIntent();
|
||||||
|
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -384,6 +396,8 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
mWifiEnabler.resume(activity);
|
mWifiEnabler.resume(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeNextButtonState(mWifiPickerTracker.getConnectedWifiEntry() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -626,6 +640,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onWifiEntriesChanged() {
|
public void onWifiEntriesChanged() {
|
||||||
updateWifiEntryPreferencesDelayed();
|
updateWifiEntryPreferencesDelayed();
|
||||||
|
changeNextButtonState(mWifiPickerTracker.getConnectedWifiEntry() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -882,6 +897,19 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
return R.string.help_url_wifi;
|
return R.string.help_url_wifi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames/replaces "Next" button when appropriate. "Next" button usually exists in
|
||||||
|
* Wi-Fi setup screens, not in usual wifi settings screen.
|
||||||
|
*
|
||||||
|
* @param enabled true when the device is connected to a wifi network.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void changeNextButtonState(boolean enabled) {
|
||||||
|
if (mEnableNextOnConnection && hasNextButton()) {
|
||||||
|
getNextButton().setEnabled(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForget(WifiDialog2 dialog) {
|
public void onForget(WifiDialog2 dialog) {
|
||||||
forget(mDialogWifiEntry);
|
forget(mDialogWifiEntry);
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.wifi;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
@@ -278,4 +279,11 @@ public class WifiSettings2Test {
|
|||||||
verify(menu).add(anyInt(), eq(WifiSettings2.MENU_ID_FORGET), anyInt(), anyInt());
|
verify(menu).add(anyInt(), eq(WifiSettings2.MENU_ID_FORGET), anyInt(), anyInt());
|
||||||
verify(menu).add(anyInt(), eq(WifiSettings2.MENU_ID_DISCONNECT), anyInt(), anyInt());
|
verify(menu).add(anyInt(), eq(WifiSettings2.MENU_ID_DISCONNECT), anyInt(), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onWifiEntriesChanged_shouldChangeNextButtonState() {
|
||||||
|
mWifiSettings2.onWifiEntriesChanged();
|
||||||
|
|
||||||
|
verify(mWifiSettings2).changeNextButtonState(anyBoolean());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user