Add Instant hotspot preference
- Add Instant hotspot preference to Wi-Fi hotspot settings
- Wait onServiceConnected callback and then getSettingsState
- Use the PendingIntent provided by SharedConnectivitySettingsState to launch Instant hotspot settings
Bug: 268550769
Test: manual test
atest -c WifiTetherSettingsTest
atest -c WifiTetherViewModelTest \
SharedConnectivityRepositoryTest
Merged-In: I343599e6127d9b1cb4af661dcc80a8683589c7b8
Change-Id: I343599e6127d9b1cb4af661dcc80a8683589c7b8
This commit is contained in:
@@ -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