This partially reverts commit 0ccc849de7
which added a config value. Instead, we will use feature flag to switch
between the fragments.
This CL also adds a postfix to keys in all_tether_prefs to
de-duplicate with keys in tether_prefs and wifi_tether_settings.
Bug: 148182953
Change-Id: I92832c786473990065a965409072e4117a7e75a8
Fix: 148618984
Test: make RunSettingsRoboTests
Test: make RunSettingsRoboTests ROBOTEST_FILTER=CodeInspectionTest
143 lines
5.8 KiB
Java
143 lines
5.8 KiB
Java
/*
|
|
* Copyright (C) 2020 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;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
|
|
import static org.mockito.Mockito.doReturn;
|
|
import static org.mockito.Mockito.spy;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import android.content.Context;
|
|
import android.net.ConnectivityManager;
|
|
import android.os.UserHandle;
|
|
import android.os.UserManager;
|
|
import android.util.FeatureFlagUtils;
|
|
|
|
import com.android.settings.core.FeatureFlags;
|
|
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
|
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.mockito.Mock;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.robolectric.RobolectricTestRunner;
|
|
import org.robolectric.RuntimeEnvironment;
|
|
import org.robolectric.annotation.Config;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
@Config(shadows = {ShadowWifiManager.class})
|
|
public class AllInOneTetherSettingsTest {
|
|
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
|
|
|
|
private Context mContext;
|
|
private AllInOneTetherSettings mAllInOneTetherSettings;
|
|
|
|
@Mock
|
|
private ConnectivityManager mConnectivityManager;
|
|
@Mock
|
|
private UserManager mUserManager;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
mContext = spy(RuntimeEnvironment.application);
|
|
|
|
MockitoAnnotations.initMocks(this);
|
|
doReturn(mConnectivityManager)
|
|
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
|
|
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
|
|
|
mAllInOneTetherSettings = new AllInOneTetherSettings();
|
|
}
|
|
|
|
@Test
|
|
public void getNonIndexableKeys_tetherAvailable_keysNotReturned() {
|
|
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
|
|
setupIsTetherAvailable(true);
|
|
|
|
final List<String> niks =
|
|
AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
|
|
|
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)) {
|
|
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
|
|
assertThat(niks).doesNotContain(
|
|
AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
|
|
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
|
} else {
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void getNonIndexableKeys_tetherNotAvailable_keysReturned() {
|
|
// To let TetherUtil.isTetherAvailable return false, select one of the combinations
|
|
setupIsTetherAvailable(false);
|
|
|
|
final List<String> niks =
|
|
AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
|
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
|
}
|
|
|
|
@Test
|
|
public void getPreferenceControllers_notEmpty() {
|
|
assertThat(AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER
|
|
.getPreferenceControllers(mContext)).isNotEmpty();
|
|
}
|
|
|
|
@Test
|
|
public void createPreferenceControllers_hasAutoOffPreference() {
|
|
assertThat(mAllInOneTetherSettings.createPreferenceControllers(mContext)
|
|
.stream()
|
|
.filter(controller -> controller instanceof WifiTetherAutoOffPreferenceController)
|
|
.count())
|
|
.isEqualTo(1);
|
|
}
|
|
|
|
private void setupIsTetherAvailable(boolean returnValue) {
|
|
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
|
|
// For RestrictedLockUtils.checkIfRestrictionEnforced
|
|
final int userId = UserHandle.myUserId();
|
|
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
|
|
when(mUserManager.getUserRestrictionSources(
|
|
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(userId)))
|
|
.thenReturn(enforcingUsers);
|
|
|
|
// For RestrictedLockUtils.hasBaseUserRestriction
|
|
when(mUserManager.hasBaseUserRestriction(
|
|
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(userId)))
|
|
.thenReturn(!returnValue);
|
|
}
|
|
}
|