Launch Wi-Fi details for connected Wi-Fi network

- Since the posspoint Wi-Fi entry can be connected even if the entry is not saved

- Allow to launch Wi-Fi details when the entry is connected but not saved

Bug: 363151879
Flag: EXEMPT bugfix
Test: Manual testing
atest -c NetworkProviderSettingsTest

Change-Id: I004b8a33bdd07cb92e167039949919f255c5303e
This commit is contained in:
Weng Su
2024-09-06 07:42:15 +08:00
parent ecac69fdcf
commit 99cd495d5b
2 changed files with 52 additions and 9 deletions

View File

@@ -19,6 +19,8 @@ package com.android.settings.network;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED; 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 static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
@@ -669,7 +671,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
@VisibleForTesting @VisibleForTesting
void addModifyMenuIfSuitable(ContextMenu menu, WifiEntry wifiEntry) { void addModifyMenuIfSuitable(ContextMenu menu, WifiEntry wifiEntry) {
if (mIsAdmin && wifiEntry.isSaved() if (mIsAdmin && wifiEntry.isSaved()
&& wifiEntry.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED) { && wifiEntry.getConnectedState() != CONNECTED_STATE_CONNECTED) {
menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify); menu.add(Menu.NONE, MENU_ID_MODIFY, 0 /* order */, R.string.wifi_modify);
} }
} }
@@ -765,7 +767,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
private void showDialog(WifiEntry wifiEntry, int dialogMode) { private void showDialog(WifiEntry wifiEntry, int dialogMode) {
if (WifiUtils.isNetworkLockedDown(getActivity(), wifiEntry.getWifiConfiguration()) if (WifiUtils.isNetworkLockedDown(getActivity(), wifiEntry.getWifiConfiguration())
&& wifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED) { && wifiEntry.getConnectedState() == CONNECTED_STATE_CONNECTED) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(),
RestrictedLockUtilsInternal.getDeviceOwner(getActivity())); RestrictedLockUtilsInternal.getDeviceOwner(getActivity()));
return; return;
@@ -1068,8 +1070,8 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
@VisibleForTesting @VisibleForTesting
void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) { void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) {
final WifiEntry wifiEntry = pref.getWifiEntry(); final WifiEntry wifiEntry = pref.getWifiEntry();
if (!wifiEntry.isSaved()) { if (!wifiEntry.isSaved() && wifiEntry.getConnectedState() != CONNECTED_STATE_CONNECTED) {
Log.w(TAG, "launchNetworkDetailsFragment: Don't launch because WifiEntry isn't saved!"); Log.w(TAG, "Don't launch Wi-Fi details because WifiEntry is not saved or connected!");
return; return;
} }
final Context context = requireContext(); final Context context = requireContext();

View File

@@ -22,6 +22,7 @@ import static com.android.settings.network.NetworkProviderSettings.MENU_ID_MODIF
import static com.android.settings.network.NetworkProviderSettings.MENU_ID_SHARE; import static com.android.settings.network.NetworkProviderSettings.MENU_ID_SHARE;
import static com.android.settings.wifi.WifiConfigUiBase2.MODE_CONNECT; import static com.android.settings.wifi.WifiConfigUiBase2.MODE_CONNECT;
import static com.android.settings.wifi.WifiConfigUiBase2.MODE_MODIFY; import static com.android.settings.wifi.WifiConfigUiBase2.MODE_MODIFY;
import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED;
import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_DISCONNECTED; import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_DISCONNECTED;
import static com.android.wifitrackerlib.WifiPickerTracker.WIFI_ENTRIES_CHANGED_REASON_GENERAL; import static com.android.wifitrackerlib.WifiPickerTracker.WIFI_ENTRIES_CHANGED_REASON_GENERAL;
@@ -343,7 +344,7 @@ public class NetworkProviderSettingsTest {
when(mWifiEntry.canDisconnect()).thenReturn(true); when(mWifiEntry.canDisconnect()).thenReturn(true);
when(mWifiEntry.canForget()).thenReturn(true); when(mWifiEntry.canForget()).thenReturn(true);
when(mWifiEntry.isSaved()).thenReturn(true); when(mWifiEntry.isSaved()).thenReturn(true);
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_CONNECTED);
final LongPressWifiEntryPreference connectedWifiEntryPreference = final LongPressWifiEntryPreference connectedWifiEntryPreference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry); mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
@@ -366,7 +367,7 @@ public class NetworkProviderSettingsTest {
when(mWifiEntry.canShare()).thenReturn(true); when(mWifiEntry.canShare()).thenReturn(true);
when(mWifiEntry.canForget()).thenReturn(true); when(mWifiEntry.canForget()).thenReturn(true);
when(mWifiEntry.isSaved()).thenReturn(true); when(mWifiEntry.isSaved()).thenReturn(true);
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_CONNECTED);
final LongPressWifiEntryPreference connectedWifiEntryPreference = final LongPressWifiEntryPreference connectedWifiEntryPreference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry); mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
@@ -388,7 +389,7 @@ public class NetworkProviderSettingsTest {
when(mWifiEntry.canShare()).thenReturn(false); when(mWifiEntry.canShare()).thenReturn(false);
when(mWifiEntry.canForget()).thenReturn(true); when(mWifiEntry.canForget()).thenReturn(true);
when(mWifiEntry.isSaved()).thenReturn(true); when(mWifiEntry.isSaved()).thenReturn(true);
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED); when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_CONNECTED);
final LongPressWifiEntryPreference connectedWifiEntryPreference = final LongPressWifiEntryPreference connectedWifiEntryPreference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry); mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
@@ -872,14 +873,54 @@ public class NetworkProviderSettingsTest {
} }
@Test @Test
public void launchNetworkDetailsFragment_wifiEntryIsNotSaved_ignoreWifiEntry() { public void launchNetworkDetailsFragment_entryDisconnectedNotSaved_ignore() {
when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
when(mWifiEntry.isSaved()).thenReturn(false); when(mWifiEntry.isSaved()).thenReturn(false);
LongPressWifiEntryPreference preference = LongPressWifiEntryPreference preference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry); mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
mNetworkProviderSettings.launchNetworkDetailsFragment(preference); mNetworkProviderSettings.launchNetworkDetailsFragment(preference);
verify(mWifiEntry, never()).getKey(); verify(mContext, never()).startActivity(any());
}
@Test
public void launchNetworkDetailsFragment_entryConnectedNotSaved_launch() {
doNothing().when(mContext).startActivity(any());
when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_CONNECTED);
when(mWifiEntry.isSaved()).thenReturn(false);
LongPressWifiEntryPreference preference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
mNetworkProviderSettings.launchNetworkDetailsFragment(preference);
verify(mContext).startActivity(any());
}
@Test
public void launchNetworkDetailsFragment_entryDisconnectedSaved_launch() {
doNothing().when(mContext).startActivity(any());
when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_DISCONNECTED);
when(mWifiEntry.isSaved()).thenReturn(true);
LongPressWifiEntryPreference preference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
mNetworkProviderSettings.launchNetworkDetailsFragment(preference);
verify(mContext).startActivity(any());
}
@Test
public void launchNetworkDetailsFragment_entryConnectedSaved_launch() {
doNothing().when(mContext).startActivity(any());
when(mWifiEntry.getConnectedState()).thenReturn(CONNECTED_STATE_CONNECTED);
when(mWifiEntry.isSaved()).thenReturn(true);
LongPressWifiEntryPreference preference =
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
mNetworkProviderSettings.launchNetworkDetailsFragment(preference);
verify(mContext).startActivity(any());
} }
@Implements(PreferenceFragmentCompat.class) @Implements(PreferenceFragmentCompat.class)