public static final String MOBILE_NETWORK_V2 = "settings_mobile_network_v2";
public static final String NETWORK_INTERNET_V2 = "settings_network_and_internet_v2";
public static final String SLICE_INJECTION = "settings_slice_injection";
- public static final String WIFI_DETAILS_SAVED_SCREEN = "settings_wifi_details_saved_screen";
public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
"settings_wifi_details_datausage_header";
}
import com.android.settings.wifi.WifiDialog.WifiDialogListener;
import com.android.settings.wifi.WifiUtils;
import com.android.settings.wifi.dpp.WifiDppUtils;
-import com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
public void onLost(Network network) {
final boolean lostCurrentNetwork = network.equals(mNetwork);
if (lostCurrentNetwork) {
- // If support detail page for saved network, should update as disconnect but not
- // exit. Except for ephemeral network which should not show on saved network list.
- if (SavedAccessPointsWifiSettings.usingDetailsFragment(mContext) && !mIsEphemeral) {
+ // Should update as disconnect but not exit. Except for ephemeral network which
+ // should not show on saved network list.
+ if (!mIsEphemeral) {
return;
}
mLifecycle = lifecycle;
lifecycle.addObserver(this);
- if (SavedAccessPointsWifiSettings.usingDetailsFragment(mContext)) {
- mWifiTracker = WifiTrackerFactory.create(
- mFragment.getActivity(),
- mWifiListener,
- mLifecycle,
- true /*includeSaved*/,
- true /*includeScans*/);
- } else {
- mWifiTracker = null;
- }
+ mWifiTracker = WifiTrackerFactory.create(
+ mFragment.getActivity(),
+ mWifiListener,
+ mLifecycle,
+ true /*includeSaved*/,
+ true /*includeScans*/);
mConnected = mAccessPoint.isActive();
// When lost the network connection, WifiInfo/NetworkInfo will be clear. So causes we
// could not check if the AccessPoint is ephemeral. Need to cache it in first.
if (mNetwork == null || mNetworkInfo == null || mWifiInfo == null) {
// Once connected, can't get mNetworkInfo immediately, return false and wait for
// next time to update UI.
- if (SavedAccessPointsWifiSettings.usingDetailsFragment(mContext)) {
- return false;
- }
-
- exitActivity();
return false;
}
private boolean canConnectNetwork() {
// Display connect button for disconnected AP even not in the range.
- return SavedAccessPointsWifiSettings.usingDetailsFragment(mContext)
- && !mAccessPoint.isActive();
+ return !mAccessPoint.isActive();
}
private void refreshIpLayerInfo() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (mHost != null) {
- mHost.showWifiDialog((AccessPointPreference) preference);
+ mHost.showWifiPage((AccessPointPreference) preference);
}
return false;
}
/**
* UI to manage saved networks/access points.
*/
-public class SavedAccessPointsWifiSettings extends DashboardFragment
- implements WifiDialog.WifiDialogListener, DialogInterface.OnCancelListener {
+public class SavedAccessPointsWifiSettings extends DashboardFragment {
private static final String TAG = "SavedAccessPoints";
- private WifiManager mWifiManager;
private Bundle mAccessPointSavedState;
private AccessPoint mSelectedAccessPoint;
@Override
public void onAttach(Context context) {
super.onAttach(context);
- mWifiManager = (WifiManager) getContext()
- .getApplicationContext().getSystemService(Context.WIFI_SERVICE);
use(SavedAccessPointsPreferenceController.class)
.setHost(this);
use(SubscribedAccessPointsPreferenceController.class)
}
}
- public void showWifiDialog(@Nullable AccessPointPreference accessPoint) {
+ public void showWifiPage(@Nullable AccessPointPreference accessPoint) {
removeDialog(WifiSettings.WIFI_DIALOG_ID);
if (accessPoint != null) {
mAccessPointSavedState = null;
}
- if (usingDetailsFragment(getContext())) {
- if (mSelectedAccessPoint == null) {
- mSelectedAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
- }
- final Bundle savedState = new Bundle();
- mSelectedAccessPoint.saveWifiState(savedState);
-
- new SubSettingLauncher(getContext())
- .setTitleText(mSelectedAccessPoint.getTitle())
- .setDestination(WifiNetworkDetailsFragment.class.getName())
- .setArguments(savedState)
- .setSourceMetricsCategory(getMetricsCategory())
- .launch();
- } else {
- showDialog(WifiSettings.WIFI_DIALOG_ID);
- }
- }
-
- @Override
- public Dialog onCreateDialog(int dialogId) {
- switch (dialogId) {
- case WifiSettings.WIFI_DIALOG_ID:
- // Modify network
- if (mSelectedAccessPoint == null) {
- // Restore AP from save state
- mSelectedAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
- // Reset the saved access point data
- mAccessPointSavedState = null;
- }
- final WifiDialog dialog = WifiDialog.createModal(
- getActivity(), this, mSelectedAccessPoint, WifiConfigUiBase.MODE_VIEW);
- dialog.setOnCancelListener(this);
-
- return dialog;
- }
- return super.onCreateDialog(dialogId);
- }
-
- @Override
- public int getDialogMetricsCategory(int dialogId) {
- switch (dialogId) {
- case WifiSettings.WIFI_DIALOG_ID:
- return SettingsEnums.DIALOG_WIFI_SAVED_AP_EDIT;
- default:
- return 0;
+ if (mSelectedAccessPoint == null) {
+ mSelectedAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
}
+ final Bundle savedState = new Bundle();
+ mSelectedAccessPoint.saveWifiState(savedState);
+
+ new SubSettingLauncher(getContext())
+ .setTitleText(mSelectedAccessPoint.getTitle())
+ .setDestination(WifiNetworkDetailsFragment.class.getName())
+ .setArguments(savedState)
+ .setSourceMetricsCategory(getMetricsCategory())
+ .launch();
}
@Override
}
}
- @Override
- public void onForget(WifiDialog dialog) {
- if (mSelectedAccessPoint != null) {
- if (mSelectedAccessPoint.isPasspointConfig()) {
- try {
- mWifiManager.removePasspointConfiguration(
- mSelectedAccessPoint.getPasspointFqdn());
- } catch (RuntimeException e) {
- Log.e(TAG, "Failed to remove Passpoint configuration for "
- + mSelectedAccessPoint.getConfigName());
- }
- if (isSubscriptionsFeatureEnabled()) {
- use(SubscribedAccessPointsPreferenceController.class)
- .postRefreshSubscribedAccessPoints();
- } else {
- use(SavedAccessPointsPreferenceController.class)
- .postRefreshSavedAccessPoints();
- }
- } else {
- // both onSuccess/onFailure will call postRefreshSavedAccessPoints
- mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId,
- use(SavedAccessPointsPreferenceController.class));
- }
- mSelectedAccessPoint = null;
- }
- }
-
- @Override
- public void onCancel(DialogInterface dialog) {
- mSelectedAccessPoint = null;
- }
-
- /**
- * Checks if showing WifiNetworkDetailsFragment when clicking saved network item.
- */
- public static boolean usingDetailsFragment(Context context) {
- return FeatureFlagUtils.isEnabled(context, FeatureFlags.WIFI_DETAILS_SAVED_SCREEN);
- }
-
boolean isSubscriptionsFeatureEnabled() {
return FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.MOBILE_NETWORK_V2)
&& FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2);
@Override
public boolean onPreferenceClick(Preference preference) {
if (mHost != null) {
- mHost.showWifiDialog((AccessPointPreference) preference);
+ mHost.showWifiPage((AccessPointPreference) preference);
}
return false;
}
setupMockedPreferenceScreen();
- // Disable saved network detail page feature for this test
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.WIFI_DETAILS_SAVED_SCREEN, false);
when(mockAccessPoint.isActive()).thenReturn(true);
mController = newWifiDetailPreferenceController();
}
private void setUpForConnectedNetwork() {
- // Enable saved network detail page feature for this test
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.WIFI_DETAILS_SAVED_SCREEN, true);
when(mockAccessPoint.isActive()).thenReturn(true);
ArrayList list = new ArrayList<>();
list.add(mockAccessPoint);
}
private void setUpForDisconnectedNetwork() {
- // Enable saved network detail page feature for this test
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.WIFI_DETAILS_SAVED_SCREEN, true);
when(mockAccessPoint.isActive()).thenReturn(false);
ArrayList list = new ArrayList<>();
list.add(mockAccessPoint);
}
private void setUpForNotInRangeNetwork() {
- // Enable saved network detail page feature for this test
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.WIFI_DETAILS_SAVED_SCREEN, true);
when(mockAccessPoint.isActive()).thenReturn(false);
ArrayList list = new ArrayList<>();
list.add(mockAccessPoint);
}
@Test
- public void entityHeader_shouldHaveIconSet() {
- Drawable expectedIcon = mockIconInjector.getIcon(LEVEL);
-
- displayAndResume();
-
- verify(mockHeaderController).setIcon(expectedIcon);
- }
-
- @Test
public void entityHeader_shouldHaveIconSetForConnectedNetwork() {
setUpForConnectedNetwork();
Drawable expectedIcon = mockIconInjector.getIcon(LEVEL);
}
@Test
- public void signalStrengthPref_shouldHaveIconSet() {
- displayAndResume();
-
- verify(mockSignalStrengthPref).setIcon(any(Drawable.class));
- }
-
- @Test
public void signalStrengthPref_shouldHaveIconSetForConnectedNetwork() {
setUpForConnectedNetwork();
}
@Test
- public void signalStrengthPref_shouldHaveDetailTextSet() {
- String expectedStrength =
- mContext.getResources().getStringArray(R.array.wifi_signal)[LEVEL];
-
- displayAndResume();
-
- verify(mockSignalStrengthPref).setSummary(expectedStrength);
- }
-
- @Test
public void signalStrengthPref_shouldHaveDetailTextSetForConnectedNetwork() {
setUpForConnectedNetwork();
String expectedStrength =
}
@Test
- public void noCurrentNetwork_shouldFinishActivity() {
- // If WifiManager#getCurrentNetwork() returns null, then the network is neither connected
- // nor connecting and WifiStateMachine has not reached L2ConnectedState.
- when(mockWifiManager.getCurrentNetwork()).thenReturn(null);
-
- displayAndResume();
-
- verify(mockActivity).finish();
- }
-
- @Test
public void noCurrentNetwork_shouldNotFinishActivityForConnectedNetwork() {
// For new feature for display detail page for saved network for disconnected network,
// mNetwork may be null, do finish activity
}
@Test
- public void networkDisconnectedState_shouldFinishActivity() {
- displayAndResume();
-
- when(mockConnectivityManager.getNetworkInfo(any(Network.class))).thenReturn(null);
- mContext.sendBroadcast(new Intent(WifiManager.NETWORK_STATE_CHANGED_ACTION));
-
- verify(mockActivity).finish();
- }
-
- @Test
public void networkDisconnectedState_shouldNotFinishActivityForConnectedNetwork() {
setUpForConnectedNetwork();
}
@Test
- public void networkOnLost_shouldFinishActivity() {
- displayAndResume();
-
- mCallbackCaptor.getValue().onLost(mockNetwork);
-
- verify(mockActivity).finish();
- }
-
- @Test
public void networkOnLost_shouldNotFinishActivityForConnectedNetwork() {
setUpForConnectedNetwork();
}
@Test
- public void testRefreshRssiViews_shouldNotUpdateIfLevelIsSame() {
+ public void testRefreshRssiViews_shouldNotUpdateIfLevelIsSameForConnectedNetwork() {
+ setUpForConnectedNetwork();
displayAndResume();
mContext.sendBroadcast(new Intent(WifiManager.RSSI_CHANGED_ACTION));
- verify(mockAccessPoint, times(2)).getLevel();
+ verify(mockAccessPoint, times(3)).getLevel();
verify(mockIconInjector, times(1)).getIcon(anyInt());
}
@Test
- public void testRefreshRssiViews_shouldUpdateOnLevelChange() {
+ public void testRefreshRssiViews_shouldUpdateOnLevelChangeForConnectedNetwork() {
+ setUpForConnectedNetwork();
displayAndResume();
when(mockAccessPoint.getLevel()).thenReturn(0);
mContext.sendBroadcast(new Intent(WifiManager.RSSI_CHANGED_ACTION));
- verify(mockAccessPoint, times(2)).getLevel();
+ verify(mockAccessPoint, times(4)).getLevel();
verify(mockIconInjector, times(2)).getIcon(anyInt());
}
package com.android.settings.wifi.savedaccesspoints;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.development.featureflags.FeatureFlagPersistent;
-import com.android.settings.wifi.WifiConfigController;
-import com.android.settings.wifi.WifiDialog;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.wifi.AccessPoint;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class SavedAccessPointsWifiSettingsTest {
@Mock
- private WifiManager mWifiManager;
- @Mock
- private WifiDialog mWifiDialog;
- @Mock
- private WifiConfigController mConfigController;
- @Mock
- private WifiConfiguration mWifiConfiguration;
- @Mock
- private AccessPoint mAccessPoint;
- @Mock
private SubscribedAccessPointsPreferenceController mSubscribedApController;
@Mock
private SavedAccessPointsPreferenceController mSavedApController;
.use(SubscribedAccessPointsPreferenceController.class);
doReturn(mSavedApController).when(mSettings)
.use(SavedAccessPointsPreferenceController.class);
-
- ReflectionHelpers.setField(mSettings, "mWifiManager", mWifiManager);
-
- when(mWifiDialog.getController()).thenReturn(mConfigController);
- when(mConfigController.getConfig()).thenReturn(mWifiConfiguration);
- }
-
- @Test
- public void onForget_isPasspointConfig_shouldRefreshAPList() {
- FeatureFlagPersistent.setEnabled(RuntimeEnvironment.application,
- FeatureFlags.NETWORK_INTERNET_V2, false);
- when(mAccessPoint.isPasspointConfig()).thenReturn(true);
- ReflectionHelpers.setField(mSettings, "mSelectedAccessPoint", mAccessPoint);
-
- mSettings.onForget(null);
-
- verify(mSavedApController).postRefreshSavedAccessPoints();
- }
-
- @Test
- public void onForget_isPasspointConfig_shouldRefreshSubscribedAPList() {
- FeatureFlagPersistent.setEnabled(RuntimeEnvironment.application,
- FeatureFlags.NETWORK_INTERNET_V2, true);
- when(mAccessPoint.isPasspointConfig()).thenReturn(true);
- ReflectionHelpers.setField(mSettings, "mSelectedAccessPoint", mAccessPoint);
-
- mSettings.onForget(null);
-
- verify(mSubscribedApController).postRefreshSubscribedAccessPoints();
- }
-
- @Test
- public void onForget_shouldInvokeForgetApi() {
- ReflectionHelpers.setField(mSettings, "mSelectedAccessPoint", mAccessPoint);
- when(mAccessPoint.getConfig()).thenReturn(mWifiConfiguration);
-
- mSettings.onForget(mWifiDialog);
-
- verify(mWifiManager).forget(mWifiConfiguration.networkId, mSavedApController);
}
@Test