Add "Speed & compatibility" preference to Wi-Fi hotspot Settings
- Show 4 speed types in summary - 2.4 Ghz - 5 Ghz - 2.4 and 5 GHz - 6 GHz Bug: 245258763 Test: manual test atest -c WifiTetherViewModelTest atest -c WifiHotspotRepositoryTest make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherSettingsTest Change-Id: I6deb41cb355b0ceb1f1fd2d84408a83b90433e7d
This commit is contained in:
@@ -16,12 +16,21 @@
|
||||
|
||||
package com.android.settings.wifi.repository;
|
||||
|
||||
import static android.net.wifi.SoftApConfiguration.BAND_2GHZ;
|
||||
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_OPEN;
|
||||
import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA3_SAE;
|
||||
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.BAND_2GHZ_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.BAND_2GHZ_5GHZ_6GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -30,6 +39,8 @@ import android.content.Context;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
@@ -46,6 +57,10 @@ import org.mockito.junit.MockitoRule;
|
||||
public class WifiHotspotRepositoryTest {
|
||||
static final String WIFI_SSID = "wifi_ssid";
|
||||
static final String WIFI_PASSWORD = "wifi_password";
|
||||
static final String WIFI_CURRENT_COUNTRY_CODE = "US";
|
||||
|
||||
static final int WIFI_5GHZ_BAND_PREFERRED = BAND_2GHZ_5GHZ;
|
||||
static final int WIFI_6GHZ_BAND_PREFERRED = BAND_2GHZ_5GHZ_6GHZ;
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@@ -53,6 +68,8 @@ public class WifiHotspotRepositoryTest {
|
||||
Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
WifiManager mWifiManager;
|
||||
@Mock
|
||||
MutableLiveData<Integer> mSpeedType;
|
||||
|
||||
WifiHotspotRepository mWifiHotspotRepository;
|
||||
SoftApConfiguration mSoftApConfiguration;
|
||||
@@ -60,6 +77,10 @@ public class WifiHotspotRepositoryTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mWifiHotspotRepository = new WifiHotspotRepository(mContext, mWifiManager);
|
||||
mWifiHotspotRepository.mCurrentCountryCode = WIFI_CURRENT_COUNTRY_CODE;
|
||||
mWifiHotspotRepository.mIsDualBand = true;
|
||||
mWifiHotspotRepository.mIs5gAvailable = true;
|
||||
mWifiHotspotRepository.mIs6gAvailable = true;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,4 +126,171 @@ public class WifiHotspotRepositoryTest {
|
||||
assertThat(password).isNotEqualTo(WIFI_PASSWORD);
|
||||
assertThat(password.length()).isNotEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoftApConfiguration_setConfigByWifiManager() {
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder().build();
|
||||
|
||||
mWifiHotspotRepository.setSoftApConfiguration(config);
|
||||
|
||||
verify(mWifiManager).setSoftApConfiguration(config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_liveDataNotUsed_doNothing() {
|
||||
// If LiveData is not used then it's null.
|
||||
mWifiHotspotRepository.mSpeedType = null;
|
||||
|
||||
mWifiHotspotRepository.refresh();
|
||||
|
||||
verify(mWifiManager, never()).getSoftApConfiguration();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_liveDataIsUsed_getConfigAndUpdateLiveData() {
|
||||
// If LiveData is used then it's not null.
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.refresh();
|
||||
|
||||
verify(mWifiManager).getSoftApConfiguration();
|
||||
verify(mSpeedType).setValue(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAutoRefresh_setEnabled_registerCallback() {
|
||||
mWifiHotspotRepository.mActiveCountryCodeChangedCallback = null;
|
||||
|
||||
mWifiHotspotRepository.setAutoRefresh(true);
|
||||
|
||||
verify(mWifiManager).registerActiveCountryCodeChangedCallback(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAutoRefresh_setDisabled_registerCallback() {
|
||||
mWifiHotspotRepository.setAutoRefresh(true);
|
||||
|
||||
mWifiHotspotRepository.setAutoRefresh(false);
|
||||
|
||||
verify(mWifiManager).unregisterActiveCountryCodeChangedCallback(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSpeedType_shouldNotReturnNull() {
|
||||
// If LiveData is not used then it's null.
|
||||
mWifiHotspotRepository.mSpeedType = null;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder().setBand(BAND_2GHZ).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
|
||||
assertThat(mWifiHotspotRepository.getSpeedType()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_singleBand2g_get2gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder().setBand(BAND_2GHZ).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_2GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_singleBand5gPreferred_get5gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_5GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_singleBand5gPreferredBut5gUnavailable_get2gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = false;
|
||||
mWifiHotspotRepository.mIs5gAvailable = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_2GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_singleBand6gPreferred_get6gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_6GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_6GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_singleBand6gPreferredBut6gUnavailable_get5gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = false;
|
||||
mWifiHotspotRepository.mIs6gAvailable = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_6GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_5GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_singleBand6gPreferredBut5gAnd6gUnavailable_get2gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = false;
|
||||
mWifiHotspotRepository.mIs5gAvailable = false;
|
||||
mWifiHotspotRepository.mIs6gAvailable = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_6GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_2GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_dualBand2gAnd5g_get2gAnd5gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = true;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_2GHZ_5GHZ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSpeedType_dualBand2gAnd5gBut5gUnavailable_get2gSpeedType() {
|
||||
mWifiHotspotRepository.mIsDualBand = true;
|
||||
mWifiHotspotRepository.mIs5gAvailable = false;
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder()
|
||||
.setBand(WIFI_5GHZ_BAND_PREFERRED).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
|
||||
mWifiHotspotRepository.mSpeedType = mSpeedType;
|
||||
|
||||
mWifiHotspotRepository.updateSpeedType();
|
||||
|
||||
verify(mSpeedType).setValue(SPEED_2GHZ);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.tether;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.wifi.repository.WifiHotspotRepository;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiTetherViewModelTest {
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Mock
|
||||
Application mApplication;
|
||||
@Mock
|
||||
Executor mExecutor;
|
||||
@Mock
|
||||
WifiHotspotRepository mWifiHotspotRepository;
|
||||
@Mock
|
||||
MutableLiveData<Integer> mSpeedType;
|
||||
|
||||
WifiTetherViewModel mViewModel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(mApplication.getMainExecutor()).thenReturn(mExecutor);
|
||||
|
||||
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(featureFactory.getWifiFeatureProvider().getWifiHotspotRepository())
|
||||
.thenReturn(mWifiHotspotRepository);
|
||||
when(mWifiHotspotRepository.getSpeedType()).thenReturn(mSpeedType);
|
||||
|
||||
mViewModel = new WifiTetherViewModel(mApplication);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_setAutoRefreshTrue() {
|
||||
verify(mWifiHotspotRepository).setAutoRefresh(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCleared_setAutoRefreshFalse() {
|
||||
mViewModel.onCleared();
|
||||
|
||||
verify(mWifiHotspotRepository).setAutoRefresh(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoftApConfiguration_setConfigByRepository() {
|
||||
SoftApConfiguration config = new SoftApConfiguration.Builder().build();
|
||||
|
||||
mViewModel.setSoftApConfiguration(config);
|
||||
|
||||
verify(mWifiHotspotRepository).setSoftApConfiguration(config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_refreshByRepository() {
|
||||
mViewModel.refresh();
|
||||
|
||||
verify(mWifiHotspotRepository).refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSpeedSummary_returnNotNull() {
|
||||
mViewModel.mSpeedSummary = null;
|
||||
|
||||
mViewModel.getSpeedSummary();
|
||||
|
||||
assertThat(mViewModel.mSpeedSummary).isNotNull();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user