Fallback to "Extended Compatibility" if Speed feature is not ready
- Fallback to the "Extended Compatibility" design when the following conditions occur - 5 GHz band is not supported on the device - 5 GHz SAP available channels cannot be obtained from WifiManager - 6 GHz SAP available channels cannot be obtained from WifiManager Bug: 272450463 Test: manual test atest -c WifiTetherSettingsTest atest -c WifiTetherViewModelTest \ WifiHotspotRepositoryTest \ WifiTetherSecurityPreferenceControllerTest.java \ WifiTetherMaximizeCompatibilityPreferenceControllerTest Change-Id: If7c8c41ebe86f5e7d8e4737ab7a82d38c9d633de
This commit is contained in:
@@ -32,9 +32,11 @@ import android.text.TextUtils;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -96,6 +98,10 @@ public class WifiHotspotRepository {
|
|||||||
protected String mCurrentCountryCode;
|
protected String mCurrentCountryCode;
|
||||||
protected ActiveCountryCodeChangedCallback mActiveCountryCodeChangedCallback;
|
protected ActiveCountryCodeChangedCallback mActiveCountryCodeChangedCallback;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
Boolean mIsConfigShowSpeed;
|
||||||
|
private Boolean mIsSpeedFeatureAvailable;
|
||||||
|
|
||||||
public WifiHotspotRepository(@NonNull Context appContext, @NonNull WifiManager wifiManager) {
|
public WifiHotspotRepository(@NonNull Context appContext, @NonNull WifiManager wifiManager) {
|
||||||
mAppContext = appContext;
|
mAppContext = appContext;
|
||||||
mWifiManager = wifiManager;
|
mWifiManager = wifiManager;
|
||||||
@@ -314,6 +320,7 @@ public class WifiHotspotRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether Wi-Fi Dual Band is supported or not.
|
* Return whether Wi-Fi Dual Band is supported or not.
|
||||||
|
*
|
||||||
* @return {@code true} if Wi-Fi Dual Band is supported
|
* @return {@code true} if Wi-Fi Dual Band is supported
|
||||||
*/
|
*/
|
||||||
public boolean isDualBand() {
|
public boolean isDualBand() {
|
||||||
@@ -326,6 +333,7 @@ public class WifiHotspotRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether Wi-Fi 5 GHz band is supported or not.
|
* Return whether Wi-Fi 5 GHz band is supported or not.
|
||||||
|
*
|
||||||
* @return {@code true} if Wi-Fi 5 GHz Band is supported
|
* @return {@code true} if Wi-Fi 5 GHz Band is supported
|
||||||
*/
|
*/
|
||||||
public boolean is5GHzBandSupported() {
|
public boolean is5GHzBandSupported() {
|
||||||
@@ -338,6 +346,7 @@ public class WifiHotspotRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether Wi-Fi Hotspot 5 GHz band is available or not.
|
* Return whether Wi-Fi Hotspot 5 GHz band is available or not.
|
||||||
|
*
|
||||||
* @return {@code true} if Wi-Fi Hotspot 5 GHz Band is available
|
* @return {@code true} if Wi-Fi Hotspot 5 GHz Band is available
|
||||||
*/
|
*/
|
||||||
public boolean is5gAvailable() {
|
public boolean is5gAvailable() {
|
||||||
@@ -371,6 +380,7 @@ public class WifiHotspotRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether Wi-Fi 6 GHz band is supported or not.
|
* Return whether Wi-Fi 6 GHz band is supported or not.
|
||||||
|
*
|
||||||
* @return {@code true} if Wi-Fi 6 GHz Band is supported
|
* @return {@code true} if Wi-Fi 6 GHz Band is supported
|
||||||
*/
|
*/
|
||||||
public boolean is6GHzBandSupported() {
|
public boolean is6GHzBandSupported() {
|
||||||
@@ -383,6 +393,7 @@ public class WifiHotspotRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether Wi-Fi Hotspot 6 GHz band is available or not.
|
* Return whether Wi-Fi Hotspot 6 GHz band is available or not.
|
||||||
|
*
|
||||||
* @return {@code true} if Wi-Fi Hotspot 6 GHz Band is available
|
* @return {@code true} if Wi-Fi Hotspot 6 GHz Band is available
|
||||||
*/
|
*/
|
||||||
public boolean is6gAvailable() {
|
public boolean is6gAvailable() {
|
||||||
@@ -432,9 +443,63 @@ public class WifiHotspotRepository {
|
|||||||
// This is expected on some hardware.
|
// This is expected on some hardware.
|
||||||
Log.e(TAG, "Querying usable SAP channels is unsupported, band:" + band);
|
Log.e(TAG, "Querying usable SAP channels is unsupported, band:" + band);
|
||||||
}
|
}
|
||||||
|
// Disable Wi-Fi hotspot speed feature if an error occurs while getting usable channels.
|
||||||
|
mIsSpeedFeatureAvailable = false;
|
||||||
|
Log.w(TAG, "isChannelAvailable(): Wi-Fi hotspot speed feature disabled");
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isConfigShowSpeed() {
|
||||||
|
if (mIsConfigShowSpeed == null) {
|
||||||
|
mIsConfigShowSpeed = mAppContext.getResources()
|
||||||
|
.getBoolean(R.bool.config_show_wifi_hotspot_speed);
|
||||||
|
log("isConfigShowSpeed():" + mIsConfigShowSpeed);
|
||||||
|
}
|
||||||
|
return mIsConfigShowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether Wi-Fi Hotspot Speed Feature is available or not.
|
||||||
|
*
|
||||||
|
* @return {@code true} if Wi-Fi Hotspot Speed Feature is available
|
||||||
|
*/
|
||||||
|
public boolean isSpeedFeatureAvailable() {
|
||||||
|
if (mIsSpeedFeatureAvailable != null) {
|
||||||
|
return mIsSpeedFeatureAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check config to show Wi-Fi hotspot speed feature
|
||||||
|
if (!isConfigShowSpeed()) {
|
||||||
|
mIsSpeedFeatureAvailable = false;
|
||||||
|
log("isSpeedFeatureAvailable():false, isConfigShowSpeed():false");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if 5 GHz band is not supported
|
||||||
|
if (!is5GHzBandSupported()) {
|
||||||
|
mIsSpeedFeatureAvailable = false;
|
||||||
|
log("isSpeedFeatureAvailable():false, 5 GHz band is not supported on this device");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check if 5 GHz band SAP channel is not ready
|
||||||
|
isChannelAvailable(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, true /* defaultValue */);
|
||||||
|
if (mIsSpeedFeatureAvailable != null && !mIsSpeedFeatureAvailable) {
|
||||||
|
log("isSpeedFeatureAvailable():false, error occurred while getting 5 GHz SAP channel");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if 6 GHz band SAP channel is not ready
|
||||||
|
isChannelAvailable(WifiScanner.WIFI_BAND_6_GHZ, false /* defaultValue */);
|
||||||
|
if (mIsSpeedFeatureAvailable != null && !mIsSpeedFeatureAvailable) {
|
||||||
|
log("isSpeedFeatureAvailable():false, error occurred while getting 6 GHz SAP channel");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mIsSpeedFeatureAvailable = true;
|
||||||
|
log("isSpeedFeatureAvailable():true");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected void purgeRefreshData() {
|
protected void purgeRefreshData() {
|
||||||
mIs5gAvailable = null;
|
mIs5gAvailable = null;
|
||||||
mIs6gAvailable = null;
|
mIs6gAvailable = null;
|
||||||
|
@@ -25,6 +25,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller helps to manage the state of maximize compatibility switch preference.
|
* This controller helps to manage the state of maximize compatibility switch preference.
|
||||||
@@ -36,13 +37,30 @@ public class WifiTetherMaximizeCompatibilityPreferenceController extends
|
|||||||
public static final String PREF_KEY = "wifi_tether_maximize_compatibility";
|
public static final String PREF_KEY = "wifi_tether_maximize_compatibility";
|
||||||
|
|
||||||
private boolean mIsChecked;
|
private boolean mIsChecked;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mShouldHidePreference;
|
||||||
|
|
||||||
public WifiTetherMaximizeCompatibilityPreferenceController(Context context,
|
public WifiTetherMaximizeCompatibilityPreferenceController(Context context,
|
||||||
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
|
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
|
||||||
super(context, listener);
|
super(context, listener);
|
||||||
|
// If the Wi-Fi Hotspot Speed Feature available, then hide this controller.
|
||||||
|
mShouldHidePreference = FeatureFactory.getFactory(context)
|
||||||
|
.getWifiFeatureProvider().getWifiHotspotRepository().isSpeedFeatureAvailable();
|
||||||
|
Log.d(TAG, "mShouldHidePreference:" + mShouldHidePreference);
|
||||||
|
if (mShouldHidePreference) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mIsChecked = isMaximizeCompatibilityEnabled();
|
mIsChecked = isMaximizeCompatibilityEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (mShouldHidePreference) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.isAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return PREF_KEY;
|
return PREF_KEY;
|
||||||
|
@@ -32,6 +32,7 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.FeatureFlags;
|
import com.android.settings.core.FeatureFlags;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -48,10 +49,19 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
|||||||
private int mSecurityValue;
|
private int mSecurityValue;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mIsWpa3Supported = true;
|
boolean mIsWpa3Supported = true;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mShouldHidePreference;
|
||||||
|
|
||||||
public WifiTetherSecurityPreferenceController(Context context,
|
public WifiTetherSecurityPreferenceController(Context context,
|
||||||
OnTetherConfigUpdateListener listener) {
|
OnTetherConfigUpdateListener listener) {
|
||||||
super(context, listener);
|
super(context, listener);
|
||||||
|
// If the Wi-Fi Hotspot Speed Feature available, then hide this controller.
|
||||||
|
mShouldHidePreference = FeatureFactory.getFactory(context)
|
||||||
|
.getWifiFeatureProvider().getWifiHotspotRepository().isSpeedFeatureAvailable();
|
||||||
|
Log.d(TAG, "shouldHidePreference():" + mShouldHidePreference);
|
||||||
|
if (mShouldHidePreference) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final String[] securityNames = mContext.getResources().getStringArray(
|
final String[] securityNames = mContext.getResources().getStringArray(
|
||||||
R.array.wifi_tether_security);
|
R.array.wifi_tether_security);
|
||||||
final String[] securityValues = mContext.getResources().getStringArray(
|
final String[] securityValues = mContext.getResources().getStringArray(
|
||||||
@@ -62,6 +72,14 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
|||||||
mWifiManager.registerSoftApCallback(context.getMainExecutor(), this);
|
mWifiManager.registerSoftApCallback(context.getMainExecutor(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (mShouldHidePreference) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.isAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
||||||
|
@@ -136,12 +136,22 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
mWifiTetherViewModel = FeatureFactory.getFactory(getContext()).getWifiFeatureProvider()
|
mWifiTetherViewModel = FeatureFactory.getFactory(getContext()).getWifiFeatureProvider()
|
||||||
.getWifiTetherViewModel(this);
|
.getWifiTetherViewModel(this);
|
||||||
mWifiHotspotSecurity = findPreference(KEY_WIFI_HOTSPOT_SECURITY);
|
if (mWifiTetherViewModel != null) {
|
||||||
if (mWifiHotspotSecurity != null && mWifiHotspotSecurity.isVisible()) {
|
setupSpeedFeature(mWifiTetherViewModel.isSpeedFeatureAvailable());
|
||||||
mWifiTetherViewModel.getSecuritySummary().observe(this, this::onSecuritySummaryChanged);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setupSpeedFeature(boolean isSpeedFeatureAvailable) {
|
||||||
|
mWifiHotspotSecurity = findPreference(KEY_WIFI_HOTSPOT_SECURITY);
|
||||||
mWifiHotspotSpeed = findPreference(KEY_WIFI_HOTSPOT_SPEED);
|
mWifiHotspotSpeed = findPreference(KEY_WIFI_HOTSPOT_SPEED);
|
||||||
if (mWifiHotspotSpeed != null && mWifiHotspotSpeed.isVisible()) {
|
if (mWifiHotspotSecurity == null || mWifiHotspotSpeed == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mWifiHotspotSecurity.setVisible(isSpeedFeatureAvailable);
|
||||||
|
mWifiHotspotSpeed.setVisible(isSpeedFeatureAvailable);
|
||||||
|
if (isSpeedFeatureAvailable) {
|
||||||
|
mWifiTetherViewModel.getSecuritySummary().observe(this, this::onSecuritySummaryChanged);
|
||||||
mWifiTetherViewModel.getSpeedSummary().observe(this, this::onSpeedSummaryChanged);
|
mWifiTetherViewModel.getSpeedSummary().observe(this, this::onSpeedSummaryChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -83,9 +83,22 @@ public class WifiTetherViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCleared() {
|
protected void onCleared() {
|
||||||
|
if (mSecuritySummary != null) {
|
||||||
mWifiHotspotRepository.getSecurityType().removeObserver(mSecurityTypeObserver);
|
mWifiHotspotRepository.getSecurityType().removeObserver(mSecurityTypeObserver);
|
||||||
|
}
|
||||||
|
if (mSpeedSummary != null) {
|
||||||
mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
|
mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether Wi-Fi Hotspot Speed Feature is available or not.
|
||||||
|
*
|
||||||
|
* @return {@code true} if Wi-Fi Hotspot Speed Feature is available
|
||||||
|
*/
|
||||||
|
public boolean isSpeedFeatureAvailable() {
|
||||||
|
return mWifiHotspotRepository.isSpeedFeatureAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the tethered Wi-Fi AP Configuration.
|
* Sets the tethered Wi-Fi AP Configuration.
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
package com.android.settings.wifi.tether;
|
package com.android.settings.wifi.tether;
|
||||||
|
|
||||||
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
||||||
|
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY;
|
||||||
|
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ import static org.mockito.ArgumentMatchers.nullable;
|
|||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -41,6 +44,7 @@ import android.util.FeatureFlagUtils;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.ViewModelStoreOwner;
|
import androidx.lifecycle.ViewModelStoreOwner;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -79,7 +83,7 @@ public class WifiTetherSettingsTest {
|
|||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@Spy
|
@Spy
|
||||||
Context mContext = ApplicationProvider.getApplicationContext();
|
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
@Mock
|
@Mock
|
||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -95,11 +99,19 @@ public class WifiTetherSettingsTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TextView mEmptyTextView;
|
private TextView mEmptyTextView;
|
||||||
@Mock
|
@Mock
|
||||||
WifiTetherViewModel mWifiTetherViewModel;
|
private WifiTetherViewModel mWifiTetherViewModel;
|
||||||
@Mock
|
@Mock
|
||||||
WifiHotspotRepository mWifiHotspotRepository;
|
private WifiHotspotRepository mWifiHotspotRepository;
|
||||||
|
@Mock
|
||||||
|
private Preference mWifiHotspotSecurity;
|
||||||
|
@Mock
|
||||||
|
private LiveData<Integer> mSecuritySummary;
|
||||||
|
@Mock
|
||||||
|
private Preference mWifiHotspotSpeed;
|
||||||
|
@Mock
|
||||||
|
private LiveData<Integer> mSpeedSummary;
|
||||||
|
|
||||||
private WifiTetherSettings mWifiTetherSettings;
|
private WifiTetherSettings mSettings;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -118,19 +130,25 @@ public class WifiTetherSettingsTest {
|
|||||||
when(provider.getWifiHotspotRepository()).thenReturn(mWifiHotspotRepository);
|
when(provider.getWifiHotspotRepository()).thenReturn(mWifiHotspotRepository);
|
||||||
when(provider.getWifiTetherViewModel(mock(ViewModelStoreOwner.class)))
|
when(provider.getWifiTetherViewModel(mock(ViewModelStoreOwner.class)))
|
||||||
.thenReturn(mWifiTetherViewModel);
|
.thenReturn(mWifiTetherViewModel);
|
||||||
|
when(mWifiTetherViewModel.isSpeedFeatureAvailable()).thenReturn(false);
|
||||||
|
when(mWifiTetherViewModel.getSecuritySummary()).thenReturn(mSecuritySummary);
|
||||||
|
when(mWifiTetherViewModel.getSpeedSummary()).thenReturn(mSpeedSummary);
|
||||||
|
|
||||||
mWifiTetherSettings = new WifiTetherSettings(mWifiRestriction);
|
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||||
|
mSettings.mWifiTetherViewModel = mWifiTetherViewModel;
|
||||||
|
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SECURITY)).thenReturn(mWifiHotspotSecurity);
|
||||||
|
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SPEED)).thenReturn(mWifiHotspotSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowRestrictedDashboardFragment.class)
|
@Config(shadows = ShadowRestrictedDashboardFragment.class)
|
||||||
public void onCreate_canNotShowWifiHotspot_shouldFinish() {
|
public void onCreate_canNotShowWifiHotspot_shouldFinish() {
|
||||||
setCanShowWifiHotspotCached(false);
|
setCanShowWifiHotspotCached(false);
|
||||||
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||||
|
|
||||||
mWifiTetherSettings.onCreate(null);
|
mSettings.onCreate(null);
|
||||||
|
|
||||||
verify(mWifiTetherSettings).finish();
|
verify(mSettings).finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -138,7 +156,7 @@ public class WifiTetherSettingsTest {
|
|||||||
public void onStart_uiIsRestricted_removeAllPreferences() {
|
public void onStart_uiIsRestricted_removeAllPreferences() {
|
||||||
spyWifiTetherSettings();
|
spyWifiTetherSettings();
|
||||||
|
|
||||||
mWifiTetherSettings.onStart();
|
mSettings.onStart();
|
||||||
|
|
||||||
verify(mPreferenceScreen).removeAll();
|
verify(mPreferenceScreen).removeAll();
|
||||||
}
|
}
|
||||||
@@ -149,7 +167,7 @@ public class WifiTetherSettingsTest {
|
|||||||
spyWifiTetherSettings();
|
spyWifiTetherSettings();
|
||||||
when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(false);
|
when(mWifiRestriction.isHotspotAvailable(mContext)).thenReturn(false);
|
||||||
|
|
||||||
mWifiTetherSettings.onStart();
|
mSettings.onStart();
|
||||||
|
|
||||||
verify(mPreferenceScreen).removeAll();
|
verify(mPreferenceScreen).removeAll();
|
||||||
verify(mEmptyTextView).setText(anyInt());
|
verify(mEmptyTextView).setText(anyInt());
|
||||||
@@ -158,21 +176,21 @@ public class WifiTetherSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onSecuritySummaryChanged_canNotShowWifiHotspot_returnFalse() {
|
public void onSecuritySummaryChanged_canNotShowWifiHotspot_returnFalse() {
|
||||||
int stringResId = R.string.wifi_security_sae;
|
int stringResId = R.string.wifi_security_sae;
|
||||||
mWifiTetherSettings.mWifiHotspotSecurity = mock(Preference.class);
|
mSettings.mWifiHotspotSecurity = mock(Preference.class);
|
||||||
|
|
||||||
mWifiTetherSettings.onSecuritySummaryChanged(stringResId);
|
mSettings.onSecuritySummaryChanged(stringResId);
|
||||||
|
|
||||||
verify(mWifiTetherSettings.mWifiHotspotSecurity).setSummary(stringResId);
|
verify(mSettings.mWifiHotspotSecurity).setSummary(stringResId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSpeedSummaryChanged_canNotShowWifiHotspot_returnFalse() {
|
public void onSpeedSummaryChanged_canNotShowWifiHotspot_returnFalse() {
|
||||||
int stringResId = R.string.wifi_hotspot_speed_summary_6g;
|
int stringResId = R.string.wifi_hotspot_speed_summary_6g;
|
||||||
mWifiTetherSettings.mWifiHotspotSpeed = mock(Preference.class);
|
mSettings.mWifiHotspotSpeed = mock(Preference.class);
|
||||||
|
|
||||||
mWifiTetherSettings.onSpeedSummaryChanged(stringResId);
|
mSettings.onSpeedSummaryChanged(stringResId);
|
||||||
|
|
||||||
verify(mWifiTetherSettings.mWifiHotspotSpeed).setSummary(stringResId);
|
verify(mSettings.mWifiHotspotSpeed).setSummary(stringResId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -183,7 +201,7 @@ public class WifiTetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createPreferenceControllers_hasAutoOffPreference() {
|
public void createPreferenceControllers_hasAutoOffPreference() {
|
||||||
assertThat(mWifiTetherSettings.createPreferenceControllers(mContext)
|
assertThat(mSettings.createPreferenceControllers(mContext)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(controller -> controller instanceof WifiTetherAutoOffPreferenceController)
|
.filter(controller -> controller instanceof WifiTetherAutoOffPreferenceController)
|
||||||
.count())
|
.count())
|
||||||
@@ -270,23 +288,42 @@ public class WifiTetherSettingsTest {
|
|||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setupSpeedFeature_speedFeatureIsAvailable_setVisibleToTrue() {
|
||||||
|
mSettings.setupSpeedFeature(true);
|
||||||
|
|
||||||
|
verify(mWifiHotspotSecurity).setVisible(true);
|
||||||
|
verify(mWifiHotspotSpeed).setVisible(true);
|
||||||
|
verify(mSecuritySummary).observe(any(), any());
|
||||||
|
verify(mSpeedSummary).observe(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setupSpeedFeature_speedFeatureIsNotAvailable_setVisibleToFalse() {
|
||||||
|
mSettings.setupSpeedFeature(false);
|
||||||
|
|
||||||
|
verify(mWifiHotspotSecurity).setVisible(false);
|
||||||
|
verify(mWifiHotspotSpeed).setVisible(false);
|
||||||
|
verify(mSecuritySummary, never()).observe(any(), any());
|
||||||
|
verify(mSpeedSummary, never()).observe(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
private void spyWifiTetherSettings() {
|
private void spyWifiTetherSettings() {
|
||||||
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||||
final FragmentActivity activity = mock(FragmentActivity.class);
|
final FragmentActivity activity = mock(FragmentActivity.class);
|
||||||
when(mWifiTetherSettings.getActivity()).thenReturn(activity);
|
when(mSettings.getActivity()).thenReturn(activity);
|
||||||
when(mWifiTetherSettings.getContext()).thenReturn(mContext);
|
when(mSettings.getContext()).thenReturn(mContext);
|
||||||
final Resources.Theme theme = mContext.getTheme();
|
final Resources.Theme theme = mContext.getTheme();
|
||||||
when(activity.getTheme()).thenReturn(theme);
|
when(activity.getTheme()).thenReturn(theme);
|
||||||
when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
when(activity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
doNothing().when(mWifiTetherSettings)
|
doNothing().when(mSettings).onCreatePreferences(any(Bundle.class), nullable(String.class));
|
||||||
.onCreatePreferences(any(Bundle.class), nullable(String.class));
|
|
||||||
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
final FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
ReflectionHelpers.setField(mWifiTetherSettings, "mDashboardFeatureProvider",
|
ReflectionHelpers.setField(mSettings, "mDashboardFeatureProvider",
|
||||||
fakeFeatureFactory.dashboardFeatureProvider);
|
fakeFeatureFactory.dashboardFeatureProvider);
|
||||||
ReflectionHelpers.setField(mWifiTetherSettings, "mEmptyTextView", mEmptyTextView);
|
ReflectionHelpers.setField(mSettings, "mEmptyTextView", mEmptyTextView);
|
||||||
doReturn(mPreferenceScreen).when(mWifiTetherSettings).getPreferenceScreen();
|
doReturn(mPreferenceScreen).when(mSettings).getPreferenceScreen();
|
||||||
|
|
||||||
mWifiTetherSettings.onCreate(Bundle.EMPTY);
|
mSettings.onCreate(Bundle.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implements(RestrictedDashboardFragment.class)
|
@Implements(RestrictedDashboardFragment.class)
|
||||||
|
@@ -36,6 +36,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.atLeast;
|
import static org.mockito.Mockito.atLeast;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -592,6 +593,65 @@ public class WifiHotspotRepositoryTest {
|
|||||||
assertThat(mWifiHotspotRepository.get6gAvailable()).isNotNull();
|
assertThat(mWifiHotspotRepository.get6gAvailable()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSpeedFeatureAvailable_configNotShow_returnFalse() {
|
||||||
|
mWifiHotspotRepository.mIsConfigShowSpeed = false;
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSpeedFeatureAvailable_5gBandNotSupported_returnFalse() {
|
||||||
|
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||||
|
mWifiHotspotRepository.mIs5gBandSupported = false;
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSpeedFeatureAvailable_throwExceptionWhenGet5gSapChannel_returnFalse() {
|
||||||
|
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||||
|
mWifiHotspotRepository.mIs5gBandSupported = true;
|
||||||
|
doThrow(IllegalArgumentException.class).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||||
|
|
||||||
|
doThrow(UnsupportedOperationException.class).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSpeedFeatureAvailable_throwExceptionWhenGet6gSapChannel_returnFalse() {
|
||||||
|
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||||
|
mWifiHotspotRepository.mIs5gBandSupported = true;
|
||||||
|
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP))).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||||
|
doThrow(IllegalArgumentException.class).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||||
|
|
||||||
|
doThrow(UnsupportedOperationException.class).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSpeedFeatureAvailable_conditionsAreReady_returnTrue() {
|
||||||
|
mWifiHotspotRepository.mIsConfigShowSpeed = true;
|
||||||
|
mWifiHotspotRepository.mIs5gBandSupported = true;
|
||||||
|
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP))).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
|
||||||
|
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_6GHZ, OP_MODE_SAP))).when(mWifiManager)
|
||||||
|
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
|
||||||
|
|
||||||
|
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
private void mockConfigSecurityType(int securityType) {
|
private void mockConfigSecurityType(int securityType) {
|
||||||
mockConfig(securityType, SPEED_2GHZ);
|
mockConfig(securityType, SPEED_2GHZ);
|
||||||
}
|
}
|
||||||
|
@@ -237,4 +237,11 @@ public class WifiTetherMaximizeCompatibilityPreferenceControllerTest {
|
|||||||
|
|
||||||
assertThat(builder.build().getBand()).isEqualTo(SoftApConfiguration.BAND_2GHZ);
|
assertThat(builder.build().getBand()).isEqualTo(SoftApConfiguration.BAND_2GHZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_shouldHidePreference_returnFalse() {
|
||||||
|
mController.mShouldHidePreference = true;
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -203,4 +203,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
|
|||||||
.isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
.isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||||
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
|
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_shouldHidePreference_returnFalse() {
|
||||||
|
mController.mShouldHidePreference = true;
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,7 +72,10 @@ public class WifiTetherViewModelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCleared_setAutoRefreshFalse() {
|
public void onCleared_removeObservers() {
|
||||||
|
mViewModel.getSecuritySummary();
|
||||||
|
mViewModel.getSpeedSummary();
|
||||||
|
|
||||||
mViewModel.onCleared();
|
mViewModel.onCleared();
|
||||||
|
|
||||||
verify(mSecurityType).removeObserver(mViewModel.mSecurityTypeObserver);
|
verify(mSecurityType).removeObserver(mViewModel.mSecurityTypeObserver);
|
||||||
@@ -116,4 +119,11 @@ public class WifiTetherViewModelTest {
|
|||||||
assertThat(mViewModel.mSpeedSummary).isNotNull();
|
assertThat(mViewModel.mSpeedSummary).isNotNull();
|
||||||
verify(mSpeedType).observeForever(mViewModel.mSpeedTypeObserver);
|
verify(mSpeedType).observeForever(mViewModel.mSpeedTypeObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSpeedFeatureAvailable_verifyRepositoryIsCalled() {
|
||||||
|
mViewModel.isSpeedFeatureAvailable();
|
||||||
|
|
||||||
|
verify(mWifiHotspotRepository).isSpeedFeatureAvailable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user