Merge "Add Instant hotspot preference" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
47c6c86015
@@ -23,6 +23,7 @@ import static android.view.View.VISIBLE;
|
||||
|
||||
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.BAND_2GHZ_5GHZ_6GHZ;
|
||||
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_INSTANT_HOTSPOT;
|
||||
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY;
|
||||
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED;
|
||||
|
||||
@@ -90,6 +91,7 @@ public class WifiTetherSettingsTest {
|
||||
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
|
||||
private static final String SSID = "ssid";
|
||||
private static final String PASSWORD = "password";
|
||||
private static final String SUMMARY = "summary";
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@@ -133,6 +135,10 @@ public class WifiTetherSettingsTest {
|
||||
private WifiTetherAutoOffPreferenceController mWifiTetherAutoOffPreferenceController;
|
||||
@Mock
|
||||
private WifiTetherMaximizeCompatibilityPreferenceController mMaxCompatibilityPrefController;
|
||||
@Mock
|
||||
private Preference mInstantHotspot;
|
||||
@Mock
|
||||
private LiveData<String> mInstantHotspotSummary;
|
||||
|
||||
private WifiTetherSettings mSettings;
|
||||
|
||||
@@ -155,8 +161,10 @@ public class WifiTetherSettingsTest {
|
||||
when(provider.getWifiTetherViewModel(mock(ViewModelStoreOwner.class)))
|
||||
.thenReturn(mWifiTetherViewModel);
|
||||
when(mWifiTetherViewModel.isSpeedFeatureAvailable()).thenReturn(false);
|
||||
when(mWifiTetherViewModel.isInstantHotspotFeatureAvailable()).thenReturn(true);
|
||||
when(mWifiTetherViewModel.getSecuritySummary()).thenReturn(mSecuritySummary);
|
||||
when(mWifiTetherViewModel.getSpeedSummary()).thenReturn(mSpeedSummary);
|
||||
when(mWifiTetherViewModel.getInstantHotspotSummary()).thenReturn(mInstantHotspotSummary);
|
||||
|
||||
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
mSettings.mMainSwitchBar = mMainSwitchBar;
|
||||
@@ -172,6 +180,8 @@ public class WifiTetherSettingsTest {
|
||||
mSettings.mWifiTetherViewModel = mWifiTetherViewModel;
|
||||
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SECURITY)).thenReturn(mWifiHotspotSecurity);
|
||||
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SPEED)).thenReturn(mWifiHotspotSpeed);
|
||||
when(mSettings.findPreference(KEY_INSTANT_HOTSPOT)).thenReturn(mInstantHotspot);
|
||||
mSettings.mInstantHotspot = mInstantHotspot;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -372,6 +382,47 @@ public class WifiTetherSettingsTest {
|
||||
verify(mSettings).setLoading(true, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupInstantHotspot_featureNotAvailable_doNothing() {
|
||||
mSettings.setupInstantHotspot(false /* isFeatureAvailable */);
|
||||
|
||||
verify(mSettings, never()).findPreference(KEY_INSTANT_HOTSPOT);
|
||||
verify(mWifiTetherViewModel, never()).getInstantHotspotSummary();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupInstantHotspot_featureAvailable_doSetup() {
|
||||
when(mWifiTetherViewModel.isInstantHotspotFeatureAvailable()).thenReturn(true);
|
||||
|
||||
mSettings.setupInstantHotspot(true /* isFeatureAvailable */);
|
||||
|
||||
verify(mSettings).findPreference(KEY_INSTANT_HOTSPOT);
|
||||
verify(mInstantHotspotSummary).observe(any(), any());
|
||||
verify(mInstantHotspot).setOnPreferenceClickListener(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInstantHotspotChanged_nullRecord_setVisibleFalse() {
|
||||
mSettings.onInstantHotspotChanged(null);
|
||||
|
||||
verify(mInstantHotspot).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInstantHotspotChanged_summaryNull_setVisibleFalse() {
|
||||
mSettings.onInstantHotspotChanged(null);
|
||||
|
||||
verify(mInstantHotspot).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInstantHotspotChanged_summaryNotNull_setVisibleAndSummary() {
|
||||
mSettings.onInstantHotspotChanged(SUMMARY);
|
||||
|
||||
verify(mInstantHotspot).setVisible(true);
|
||||
verify(mInstantHotspot).setSummary(SUMMARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildNewConfig_speedFeatureIsAvailableAndPasswordChanged_bandShouldNotBeLost() {
|
||||
String newPassword = "new" + PASSWORD;
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.repository;
|
||||
|
||||
import static android.app.PendingIntent.FLAG_IMMUTABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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 android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.sharedconnectivity.app.SharedConnectivityManager;
|
||||
import android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
public class SharedConnectivityRepositoryTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private SharedConnectivityManager mManager;
|
||||
|
||||
private SharedConnectivityRepository mRepository;
|
||||
private PendingIntent mIntent = PendingIntent
|
||||
.getActivity(mContext, 0, new Intent("test"), FLAG_IMMUTABLE);
|
||||
private SharedConnectivitySettingsState mState = new SharedConnectivitySettingsState.Builder()
|
||||
.setInstantTetherSettingsPendingIntent(mIntent).build();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(mContext.getSystemService(SharedConnectivityManager.class)).thenReturn(mManager);
|
||||
when(mManager.getSettingsState()).thenReturn(mState);
|
||||
|
||||
mRepository = spy(new SharedConnectivityRepository(mContext, true /* isConfigEnabled */));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_configEnabled_registerCallback() {
|
||||
verify(mManager).registerCallback(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_configNotEnabled_doNotRegisterCallback() {
|
||||
SharedConnectivityManager manager = mock(SharedConnectivityManager.class);
|
||||
when(mContext.getSystemService(SharedConnectivityManager.class)).thenReturn(manager);
|
||||
|
||||
mRepository = new SharedConnectivityRepository(mContext, false /* isConfigEnabled */);
|
||||
|
||||
verify(manager, never()).registerCallback(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isServiceAvailable_configEnabled_returnTrue() {
|
||||
mRepository = new SharedConnectivityRepository(mContext, true /* isConfigEnabled */);
|
||||
|
||||
assertThat(mRepository.isServiceAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isServiceAvailable_configNotEnabled_returnFalse() {
|
||||
mRepository = new SharedConnectivityRepository(mContext, false /* isConfigEnabled */);
|
||||
|
||||
assertThat(mRepository.isServiceAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsState_isNotNull() {
|
||||
assertThat(mRepository.getSettingsState()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleLaunchSettings_managerNull_doNothing() {
|
||||
when(mContext.getSystemService(SharedConnectivityManager.class)).thenReturn(null);
|
||||
mRepository = spy(new SharedConnectivityRepository(mContext, true /* isConfigEnabled */));
|
||||
|
||||
mRepository.handleLaunchSettings();
|
||||
|
||||
verify(mRepository, never()).sendSettingsIntent(mIntent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleLaunchSettings_stageNull_doNothing() {
|
||||
when(mManager.getSettingsState()).thenReturn(null);
|
||||
|
||||
mRepository.handleLaunchSettings();
|
||||
|
||||
verify(mRepository, never()).sendSettingsIntent(mIntent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleLaunchSettings_intentNull_doNothing() {
|
||||
mState = new SharedConnectivitySettingsState.Builder()
|
||||
.setInstantTetherSettingsPendingIntent(null).build();
|
||||
when(mManager.getSettingsState()).thenReturn(mState);
|
||||
|
||||
mRepository.handleLaunchSettings();
|
||||
|
||||
verify(mRepository, never()).sendSettingsIntent(mIntent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleLaunchSettings_allReady_sendSettingsIntent() {
|
||||
mRepository.handleLaunchSettings();
|
||||
|
||||
verify(mRepository).sendSettingsIntent(mIntent);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.android.settings.wifi.tether.WifiTetherViewModel.RES_INSTANT_HOTSPOT_SUMMARY_OFF;
|
||||
import static com.android.settings.wifi.tether.WifiTetherViewModel.RES_INSTANT_HOTSPOT_SUMMARY_ON;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -23,12 +26,15 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.wifi.repository.SharedConnectivityRepository;
|
||||
import com.android.settings.wifi.repository.WifiHotspotRepository;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -36,6 +42,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
@@ -45,8 +52,8 @@ import java.util.concurrent.Executor;
|
||||
public class WifiTetherViewModelTest {
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Mock
|
||||
Application mApplication;
|
||||
@Spy
|
||||
Application mApplication = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
Executor mExecutor;
|
||||
@Mock
|
||||
@@ -57,6 +64,12 @@ public class WifiTetherViewModelTest {
|
||||
MutableLiveData<Integer> mSpeedType;
|
||||
@Mock
|
||||
private MutableLiveData<Boolean> mRestarting;
|
||||
@Mock
|
||||
private SharedConnectivityRepository mSharedConnectivityRepository;
|
||||
@Mock
|
||||
private MutableLiveData<SharedConnectivitySettingsState> mSettingsState;
|
||||
@Mock
|
||||
private MutableLiveData<String> mInstantHotspotSummary;
|
||||
|
||||
WifiTetherViewModel mViewModel;
|
||||
|
||||
@@ -70,8 +83,18 @@ public class WifiTetherViewModelTest {
|
||||
when(mWifiHotspotRepository.getSecurityType()).thenReturn(mSecurityType);
|
||||
when(mWifiHotspotRepository.getSpeedType()).thenReturn(mSpeedType);
|
||||
when(mWifiHotspotRepository.getRestarting()).thenReturn(mRestarting);
|
||||
when(featureFactory.getWifiFeatureProvider().getSharedConnectivityRepository())
|
||||
.thenReturn(mSharedConnectivityRepository);
|
||||
when(mSharedConnectivityRepository.isServiceAvailable()).thenReturn(true);
|
||||
when(mSharedConnectivityRepository.getSettingsState()).thenReturn(mSettingsState);
|
||||
|
||||
mViewModel = new WifiTetherViewModel(mApplication);
|
||||
mViewModel.mInstantHotspotSummary = mInstantHotspotSummary;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_observeData() {
|
||||
verify(mSettingsState).observeForever(mViewModel.mInstantHotspotStateObserver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,6 +106,7 @@ public class WifiTetherViewModelTest {
|
||||
|
||||
verify(mSecurityType).removeObserver(mViewModel.mSecurityTypeObserver);
|
||||
verify(mSpeedType).removeObserver(mViewModel.mSpeedTypeObserver);
|
||||
verify(mSettingsState).removeObserver(mViewModel.mInstantHotspotStateObserver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,4 +165,59 @@ public class WifiTetherViewModelTest {
|
||||
public void getRestarting_shouldNotReturnNull() {
|
||||
assertThat(mViewModel.getRestarting()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isInstantHotspotFeatureAvailable_serviceAvailable_returnTrue() {
|
||||
when(mSharedConnectivityRepository.isServiceAvailable()).thenReturn(true);
|
||||
|
||||
assertThat(mViewModel.isInstantHotspotFeatureAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isInstantHotspotFeatureAvailable_serviceNotAvailable_returnFalse() {
|
||||
when(mSharedConnectivityRepository.isServiceAvailable()).thenReturn(false);
|
||||
|
||||
assertThat(mViewModel.isInstantHotspotFeatureAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInstantHotspotSummary_isNotNull() {
|
||||
assertThat(mViewModel.getInstantHotspotSummary()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInstantHotspotStateChanged_stageNull_summarySetValueNull() {
|
||||
mViewModel.onInstantHotspotStateChanged(null);
|
||||
|
||||
verify(mInstantHotspotSummary).setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInstantHotspotStateChanged_stateEnabled_summarySetValueOn() {
|
||||
SharedConnectivitySettingsState state = new SharedConnectivitySettingsState.Builder()
|
||||
.setInstantTetherEnabled(true).build();
|
||||
|
||||
mViewModel.onInstantHotspotStateChanged(state);
|
||||
|
||||
verify(mInstantHotspotSummary)
|
||||
.setValue(mApplication.getString(RES_INSTANT_HOTSPOT_SUMMARY_ON));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInstantHotspotStateChanged_stateNotEnabled_recordVisibleSummaryOff() {
|
||||
SharedConnectivitySettingsState state = new SharedConnectivitySettingsState.Builder()
|
||||
.setInstantTetherEnabled(false).build();
|
||||
|
||||
mViewModel.onInstantHotspotStateChanged(state);
|
||||
|
||||
verify(mInstantHotspotSummary)
|
||||
.setValue(mApplication.getString(RES_INSTANT_HOTSPOT_SUMMARY_OFF));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchInstantHotspotSettings_launchSettingsByRepository() {
|
||||
mViewModel.launchInstantHotspotSettings();
|
||||
|
||||
verify(mSharedConnectivityRepository).launchSettings();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user