[Passpointv2] Provide two views for saved networks
List all passpoint network under "Subscriptions" view and others under "Wi-Fi networks". Bug: 116362877 Test: hard code verify subscribed network Change-Id: I9750e9964e8b5affc2e91ea86a058c3ba65b3588
This commit is contained in:
@@ -2266,6 +2266,10 @@
|
||||
|
||||
<!-- Wifi saved access points. Used as a label under the shortcut icon that goes to Wifi saved access points. [CHAR LIMIT=20] -->
|
||||
<string name="wifi_saved_access_points_label">Saved networks</string>
|
||||
<!-- Tab title for showing subscribed WiFi access points. [CHAR LIMIT=20] -->
|
||||
<string name="wifi_subscribed_access_points_tab">Subscriptions</string>
|
||||
<!-- Tab title for showing saved WiFi access points. -->
|
||||
<string name="wifi_saved_access_points_tab">@string/wifi_access_points</string>
|
||||
<!-- Wifi Advanced settings. Used as a label under the shortcut icon that goes to Wifi advanced settings. [CHAR LIMIT=20] -->
|
||||
<string name="wifi_advanced_settings_label">IP settings</string>
|
||||
<!-- Error message for users that aren't allowed to see or modify WiFi advanced settings [CHAR LIMIT=NONE] -->
|
||||
|
@@ -20,9 +20,14 @@
|
||||
android:key="saved_access_points"
|
||||
android:title="@string/wifi_saved_access_points_label">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="subscribed_access_points_category"
|
||||
android:title="@string/wifi_subscribed_access_points_tab"
|
||||
settings:controller="com.android.settings.wifi.savedaccesspoints.SubscribedAccessPointsPreferenceController"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="saved_access_points_category"
|
||||
android:layout="@layout/preference_category_no_label"
|
||||
android:title="@string/wifi_saved_access_points_tab"
|
||||
settings:controller="com.android.settings.wifi.savedaccesspoints.SavedAccessPointsPreferenceController"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -28,6 +28,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.utils.PreferenceGroupChildrenCache;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
@@ -122,6 +123,12 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl
|
||||
final int accessPointsSize = accessPoints.size();
|
||||
for (int i = 0; i < accessPointsSize; ++i) {
|
||||
AccessPoint ap = accessPoints.get(i);
|
||||
|
||||
if (mHost != null && mHost.isSubscriptionsFeatureEnabled()
|
||||
&& ap.isPasspointConfig()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = ap.getKey();
|
||||
AccessPointPreference preference =
|
||||
(AccessPointPreference) mChildrenCache.getCachedPreference(key);
|
||||
@@ -139,6 +146,15 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl
|
||||
|
||||
if (mPreferenceGroup.getPreferenceCount() < 1) {
|
||||
Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!");
|
||||
mPreferenceGroup.setVisible(false);
|
||||
} else {
|
||||
mPreferenceGroup.setVisible(true);
|
||||
}
|
||||
|
||||
if (mHost != null && !mHost.isSubscriptionsFeatureEnabled()) {
|
||||
mPreferenceGroup.setVisible(true);
|
||||
mPreferenceGroup.setTitle(null);
|
||||
mPreferenceGroup.setLayoutResource(R.layout.preference_category_no_label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -75,6 +75,8 @@ public class SavedAccessPointsWifiSettings extends DashboardFragment
|
||||
.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
use(SavedAccessPointsPreferenceController.class)
|
||||
.setHost(this);
|
||||
use(SubscribedAccessPointsPreferenceController.class)
|
||||
.setHost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,10 +174,15 @@ public class SavedAccessPointsWifiSettings extends DashboardFragment
|
||||
Log.e(TAG, "Failed to remove Passpoint configuration for "
|
||||
+ mSelectedAccessPoint.getConfigName());
|
||||
}
|
||||
use(SavedAccessPointsPreferenceController.class)
|
||||
.postRefreshSavedAccessPoints();
|
||||
if (isSubscriptionsFeatureEnabled()) {
|
||||
use(SubscribedAccessPointsPreferenceController.class)
|
||||
.postRefreshSubscribedAccessPoints();
|
||||
} else {
|
||||
use(SavedAccessPointsPreferenceController.class)
|
||||
.postRefreshSavedAccessPoints();
|
||||
}
|
||||
} else {
|
||||
// mForgetListener will call initPreferences upon completion
|
||||
// both onSuccess/onFailure will call postRefreshSavedAccessPoints
|
||||
mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId,
|
||||
use(SavedAccessPointsPreferenceController.class));
|
||||
}
|
||||
@@ -198,4 +205,9 @@ public class SavedAccessPointsWifiSettings extends DashboardFragment
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isSubscriptionsFeatureEnabled() {
|
||||
return FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.MOBILE_NETWORK_V2)
|
||||
&& FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.utils.PreferenceGroupChildrenCache;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
import com.android.settingslib.wifi.AccessPointPreference.UserBadgeCache;
|
||||
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller that manages a PreferenceGroup, which contains a list of subscribed access points.
|
||||
*/
|
||||
// TODO(b/127206629): Code refactor to avoid duplicated coding after removed feature flag.
|
||||
public class SubscribedAccessPointsPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, Preference.OnPreferenceClickListener,
|
||||
WifiManager.ActionListener {
|
||||
|
||||
private static final String TAG = "SubscribedAPPrefCtrl";
|
||||
|
||||
private final WifiManager mWifiManager;
|
||||
private final PreferenceGroupChildrenCache mChildrenCache;
|
||||
private final UserBadgeCache mUserBadgeCache;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private SavedAccessPointsWifiSettings mHost;
|
||||
|
||||
public SubscribedAccessPointsPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(context.getPackageManager());
|
||||
mWifiManager = context.getSystemService(WifiManager.class);
|
||||
mChildrenCache = new PreferenceGroupChildrenCache();
|
||||
}
|
||||
|
||||
public SubscribedAccessPointsPreferenceController setHost(SavedAccessPointsWifiSettings host) {
|
||||
mHost = host;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreferenceGroup = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
refreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
public void postRefreshSubscribedAccessPoints() {
|
||||
ThreadUtils.postOnMainThread(() -> refreshSubscribedAccessPoints());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (mHost != null) {
|
||||
mHost.showWifiDialog((AccessPointPreference) preference);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
postRefreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
postRefreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void refreshSubscribedAccessPoints() {
|
||||
if (mPreferenceGroup == null) {
|
||||
Log.w(TAG, "PreferenceGroup is null, skipping.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mHost != null && !mHost.isSubscriptionsFeatureEnabled()) {
|
||||
mPreferenceGroup.setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final Context prefContext = mPreferenceGroup.getContext();
|
||||
|
||||
final List<AccessPoint> accessPoints =
|
||||
WifiSavedConfigUtils.getAllConfigs(mContext, mWifiManager);
|
||||
Collections.sort(accessPoints, SavedNetworkComparator.INSTANCE);
|
||||
mChildrenCache.cacheRemoveAllPrefs(mPreferenceGroup);
|
||||
|
||||
final int accessPointsSize = accessPoints.size();
|
||||
for (int i = 0; i < accessPointsSize; ++i) {
|
||||
AccessPoint ap = accessPoints.get(i);
|
||||
if (!ap.isPasspointConfig()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String key = ap.getKey();
|
||||
AccessPointPreference preference =
|
||||
(AccessPointPreference) mChildrenCache.getCachedPreference(key);
|
||||
if (preference == null) {
|
||||
preference = new AccessPointPreference(ap, prefContext, mUserBadgeCache, true);
|
||||
preference.setKey(key);
|
||||
preference.setIcon(null);
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
mPreferenceGroup.addPreference(preference);
|
||||
}
|
||||
preference.setOrder(i);
|
||||
}
|
||||
|
||||
mChildrenCache.removeCachedPrefs(mPreferenceGroup);
|
||||
|
||||
if (mPreferenceGroup.getPreferenceCount() < 1) {
|
||||
Log.w(TAG, "Subscribed networks activity loaded,"
|
||||
+ " but there are no subscribed networks!");
|
||||
mPreferenceGroup.setVisible(false);
|
||||
} else {
|
||||
mPreferenceGroup.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,12 +27,15 @@ import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Implements(value = WifiManager.class)
|
||||
public class ShadowWifiManager extends org.robolectric.shadows.ShadowWifiManager {
|
||||
|
||||
private List<PasspointConfiguration> mPasspointConfiguration;
|
||||
|
||||
public WifiConfiguration savedWifiConfig;
|
||||
|
||||
@HiddenApi // @SystemApi
|
||||
@@ -49,7 +52,15 @@ public class ShadowWifiManager extends org.robolectric.shadows.ShadowWifiManager
|
||||
|
||||
@Implementation
|
||||
protected List<PasspointConfiguration> getPasspointConfigurations() {
|
||||
return Collections.emptyList();
|
||||
return mPasspointConfiguration == null ? Collections.emptyList() : mPasspointConfiguration;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected void addOrUpdatePasspointConfiguration(PasspointConfiguration config) {
|
||||
if (mPasspointConfiguration == null) {
|
||||
mPasspointConfiguration = new ArrayList<>();
|
||||
}
|
||||
mPasspointConfiguration.add(config);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
|
@@ -20,7 +20,9 @@ import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -32,6 +34,8 @@ import android.net.wifi.WifiManager;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.development.featureflags.FeatureFlagPersistent;
|
||||
import com.android.settings.testutils.shadow.ShadowAccessPoint;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||
@@ -58,6 +62,7 @@ public class SavedAccessPointsPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private WifiManager mWifiManager;
|
||||
private SavedAccessPointsWifiSettings mSettings;
|
||||
private SavedAccessPointsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
@@ -65,7 +70,9 @@ public class SavedAccessPointsPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
mSettings = spy(new SavedAccessPointsWifiSettings());
|
||||
mController = spy(new SavedAccessPointsPreferenceController(mContext, "test_key"));
|
||||
mController.setHost(mSettings);
|
||||
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreferenceCategory);
|
||||
@@ -115,7 +122,7 @@ public class SavedAccessPointsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void refreshSavedAccessPoints_shouldListAllAPs() {
|
||||
public void refreshSavedAccessPoints_shouldListNonSubscribedAPs() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "SSID";
|
||||
config.BSSID = "BSSID";
|
||||
@@ -132,4 +139,18 @@ public class SavedAccessPointsPreferenceControllerTest {
|
||||
final AccessPointPreference pref = captor.getValue();
|
||||
assertThat(pref.getTitle()).isEqualTo(config.SSID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void refreshSavedAccessPoints_shouldNotListSubscribedAPs() {
|
||||
FeatureFlagPersistent.setEnabled(mContext, FeatureFlags.NETWORK_INTERNET_V2, true);
|
||||
|
||||
mWifiManager.addOrUpdatePasspointConfiguration(
|
||||
SubscribedAccessPointsPreferenceControllerTest.createMockPasspointConfiguration());
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.refreshSavedAccessPoints();
|
||||
|
||||
verify(mPreferenceCategory, never()).addPreference(any(AccessPointPreference.class));
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,8 @@ 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;
|
||||
@@ -39,6 +41,7 @@ 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)
|
||||
@@ -55,6 +58,8 @@ public class SavedAccessPointsWifiSettingsTest {
|
||||
@Mock
|
||||
private AccessPoint mAccessPoint;
|
||||
@Mock
|
||||
private SubscribedAccessPointsPreferenceController mSubscribedApController;
|
||||
@Mock
|
||||
private SavedAccessPointsPreferenceController mSavedApController;
|
||||
|
||||
private TestFragment mSettings;
|
||||
@@ -64,6 +69,8 @@ public class SavedAccessPointsWifiSettingsTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mSettings = spy(new TestFragment());
|
||||
|
||||
doReturn(mSubscribedApController).when(mSettings)
|
||||
.use(SubscribedAccessPointsPreferenceController.class);
|
||||
doReturn(mSavedApController).when(mSettings)
|
||||
.use(SavedAccessPointsPreferenceController.class);
|
||||
|
||||
@@ -83,6 +90,18 @@ public class SavedAccessPointsWifiSettingsTest {
|
||||
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);
|
||||
|
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.FeatureInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import android.net.wifi.hotspot2.PasspointConfiguration;
|
||||
import android.net.wifi.hotspot2.pps.HomeSp;
|
||||
import android.net.wifi.WifiEnterpriseConfig;
|
||||
import android.net.wifi.WifiManager;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.development.featureflags.FeatureFlagPersistent;
|
||||
import com.android.settings.testutils.shadow.ShadowAccessPoint;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowThreadUtils.class, ShadowWifiManager.class})
|
||||
public class SubscribedAccessPointsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
|
||||
private Context mContext;
|
||||
private WifiManager mWifiManager;
|
||||
private SavedAccessPointsWifiSettings mSettings;
|
||||
private SubscribedAccessPointsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
mSettings = spy(new SavedAccessPointsWifiSettings());
|
||||
mController = spy(new SubscribedAccessPointsPreferenceController(mContext, "test_key"));
|
||||
mController.setHost(mSettings);
|
||||
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreferenceCategory);
|
||||
when(mPreferenceCategory.getContext()).thenReturn(mContext);
|
||||
|
||||
FeatureFlagPersistent.setEnabled(mContext, FeatureFlags.NETWORK_INTERNET_V2, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailability_alwaysAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRefreshApList() {
|
||||
doNothing().when(mController).refreshSubscribedAccessPoints();
|
||||
|
||||
mController.onStart();
|
||||
|
||||
verify(mController).refreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRefresh_shouldRefreshApList() {
|
||||
doNothing().when(mController).refreshSubscribedAccessPoints();
|
||||
|
||||
mController.postRefreshSubscribedAccessPoints();
|
||||
|
||||
verify(mController).refreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forget_onSuccess_shouldRefreshApList() {
|
||||
doNothing().when(mController).refreshSubscribedAccessPoints();
|
||||
|
||||
mController.onSuccess();
|
||||
|
||||
verify(mController).refreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forget_onFailure_shouldRefreshApList() {
|
||||
doNothing().when(mController).refreshSubscribedAccessPoints();
|
||||
|
||||
mController.onFailure(0 /* reason */);
|
||||
|
||||
verify(mController).refreshSubscribedAccessPoints();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void refreshSubscribedAccessPoints_shouldNotListNonSubscribedAPs() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "SSID";
|
||||
config.BSSID = "BSSID";
|
||||
config.networkId = 2;
|
||||
mWifiManager.addNetwork(config);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.refreshSubscribedAccessPoints();
|
||||
|
||||
verify(mPreferenceCategory, never()).addPreference(any(AccessPointPreference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void refreshSubscribedAccessPoints_shouldListSubscribedAPs() {
|
||||
mWifiManager.addOrUpdatePasspointConfiguration(createMockPasspointConfiguration());
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.refreshSubscribedAccessPoints();
|
||||
|
||||
final ArgumentCaptor<AccessPointPreference> captor =
|
||||
ArgumentCaptor.forClass(AccessPointPreference.class);
|
||||
verify(mPreferenceCategory).addPreference(captor.capture());
|
||||
|
||||
final AccessPointPreference pref = captor.getValue();
|
||||
assertThat(pref.getTitle()).isEqualTo("TESTPASSPOINT");
|
||||
}
|
||||
|
||||
public static PasspointConfiguration createMockPasspointConfiguration() {
|
||||
final PasspointConfiguration config = new PasspointConfiguration();
|
||||
final HomeSp homeSp = new HomeSp();
|
||||
homeSp.setFqdn("FQDN");
|
||||
homeSp.setFriendlyName("TESTPASSPOINT");
|
||||
config.setHomeSp(homeSp);
|
||||
return config;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user