[Wi-Fi] Remove the files which use SettingsLib Wi-Fi objects
This change removes WifiDetailPreferenceController WifiPrivacyPreferenceController Bug: 152571756 Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiConfigControllerTest Manualy add a Wi-Fi network of randomized MAC and a Wi-Fi network of device MAC in SetupWizard, then observe the MAC value in Settings Wi-Fi detail. Change-Id: I82ef4e1d2c386d8bd751df8ff18c18163a0e9a6a
This commit is contained in:
@@ -42,7 +42,6 @@ import android.text.InputType;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@@ -69,8 +68,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.ProxySelector;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.wifi.details.WifiPrivacyPreferenceController;
|
||||
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
|
||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
@@ -144,6 +141,10 @@ public class WifiConfigController implements TextWatcher,
|
||||
UNDESIRED_CERTIFICATE_MACRANDSAPSECRET
|
||||
};
|
||||
|
||||
// Should be the same index value as wifi_privacy_entries in arrays.xml
|
||||
@VisibleForTesting static final int PRIVACY_SPINNER_INDEX_RANDOMIZED_MAC = 0;
|
||||
@VisibleForTesting static final int PRIVACY_SPINNER_INDEX_DEVICE_MAC = 1;
|
||||
|
||||
/* Phase2 methods supported by PEAP are limited */
|
||||
private ArrayAdapter<CharSequence> mPhase2PeapAdapter;
|
||||
/* Phase2 methods supported by TTLS are limited */
|
||||
@@ -305,15 +306,9 @@ public class WifiConfigController implements TextWatcher,
|
||||
? HIDDEN_NETWORK
|
||||
: NOT_HIDDEN_NETWORK);
|
||||
|
||||
int prefMacValue;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
prefMacValue = WifiPrivacyPreferenceController2
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
} else {
|
||||
prefMacValue = WifiPrivacyPreferenceController
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
}
|
||||
mPrivacySettingsSpinner.setSelection(prefMacValue);
|
||||
mPrivacySettingsSpinner.setSelection(
|
||||
config.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_PERSISTENT
|
||||
? PRIVACY_SPINNER_INDEX_RANDOMIZED_MAC : PRIVACY_SPINNER_INDEX_DEVICE_MAC);
|
||||
|
||||
if (config.getIpConfiguration().getIpAssignment() == IpAssignment.STATIC) {
|
||||
mIpSettingsSpinner.setSelection(STATIC_IP);
|
||||
@@ -833,15 +828,10 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
|
||||
if (mPrivacySettingsSpinner != null) {
|
||||
int macValue;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
macValue = WifiPrivacyPreferenceController2.translatePrefValueToMacRandomizedValue(
|
||||
mPrivacySettingsSpinner.getSelectedItemPosition());
|
||||
} else {
|
||||
macValue = WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(
|
||||
mPrivacySettingsSpinner.getSelectedItemPosition());
|
||||
}
|
||||
config.macRandomizationSetting = macValue;
|
||||
config.macRandomizationSetting = mPrivacySettingsSpinner.getSelectedItemPosition()
|
||||
== PRIVACY_SPINNER_INDEX_RANDOMIZED_MAC
|
||||
? WifiConfiguration.RANDOMIZATION_PERSISTENT
|
||||
: WifiConfiguration.RANDOMIZATION_NONE;
|
||||
}
|
||||
|
||||
return config;
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.details;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* {@link AbstractPreferenceController} that controls whether the wifi network is mac randomized
|
||||
* or not.
|
||||
*
|
||||
* Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
|
||||
* future, please develop in
|
||||
* {@link com.android.settings.wifi.details2.WifiPrivacyPreferenceController2}.
|
||||
*/
|
||||
public class WifiPrivacyPreferenceController extends BasePreferenceController implements
|
||||
Preference.OnPreferenceChangeListener, WifiDialog.WifiDialogListener {
|
||||
|
||||
private static final String KEY_WIFI_PRIVACY = "privacy";
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private WifiManager mWifiManager;
|
||||
private boolean mIsEphemeral = false;
|
||||
private boolean mIsPasspoint = false;
|
||||
private Preference mPreference;
|
||||
|
||||
public WifiPrivacyPreferenceController(Context context) {
|
||||
super(context, KEY_WIFI_PRIVACY);
|
||||
mWifiConfiguration = null;
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
public void setWifiConfiguration(WifiConfiguration wifiConfiguration) {
|
||||
mWifiConfiguration = wifiConfiguration;
|
||||
}
|
||||
|
||||
public void setIsEphemeral(boolean isEphemeral) {
|
||||
mIsEphemeral = isEphemeral;
|
||||
}
|
||||
|
||||
public void setIsPasspoint(boolean isPasspoint) {
|
||||
mIsPasspoint = isPasspoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mWifiManager.isConnectedMacRandomizationSupported()
|
||||
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final DropDownPreference dropDownPreference = (DropDownPreference) preference;
|
||||
final int randomizationLevel = getRandomizationValue();
|
||||
dropDownPreference.setValue(Integer.toString(randomizationLevel));
|
||||
updateSummary(dropDownPreference, randomizationLevel);
|
||||
|
||||
// Makes preference not selectable, when this is a ephemeral network.
|
||||
if (mIsEphemeral || mIsPasspoint) {
|
||||
preference.setSelectable(false);
|
||||
dropDownPreference.setSummary(R.string.wifi_privacy_settings_ephemeral_summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mWifiConfiguration != null) {
|
||||
mWifiConfiguration.macRandomizationSetting = Integer.parseInt((String) newValue);
|
||||
mWifiManager.updateNetwork(mWifiConfiguration);
|
||||
|
||||
// To activate changing, we need to reconnect network. WiFi will auto connect to
|
||||
// current network after disconnect(). Only needed when this is connected network.
|
||||
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
if (wifiInfo != null && wifiInfo.getNetworkId() == mWifiConfiguration.networkId) {
|
||||
mWifiManager.disconnect();
|
||||
}
|
||||
}
|
||||
updateSummary((DropDownPreference) preference, Integer.parseInt((String) newValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getRandomizationValue() {
|
||||
if (mWifiConfiguration != null) {
|
||||
return mWifiConfiguration.macRandomizationSetting;
|
||||
}
|
||||
return WifiConfiguration.RANDOMIZATION_PERSISTENT;
|
||||
}
|
||||
|
||||
private static final int PREF_RANDOMIZATION_PERSISTENT = 0;
|
||||
private static final int PREF_RANDOMIZATION_NONE = 1;
|
||||
|
||||
/**
|
||||
* Returns preference index value.
|
||||
*
|
||||
* @param macRandomized is mac randomized value
|
||||
* @return index value of preference
|
||||
*/
|
||||
public static int translateMacRandomizedValueToPrefValue(int macRandomized) {
|
||||
return (macRandomized == WifiConfiguration.RANDOMIZATION_PERSISTENT)
|
||||
? PREF_RANDOMIZATION_PERSISTENT : PREF_RANDOMIZATION_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mac randomized value.
|
||||
*
|
||||
* @param prefMacRandomized is preference index value
|
||||
* @return mac randomized value
|
||||
*/
|
||||
public static int translatePrefValueToMacRandomizedValue(int prefMacRandomized) {
|
||||
return (prefMacRandomized == PREF_RANDOMIZATION_PERSISTENT)
|
||||
? WifiConfiguration.RANDOMIZATION_PERSISTENT : WifiConfiguration.RANDOMIZATION_NONE;
|
||||
}
|
||||
|
||||
private void updateSummary(DropDownPreference preference, int macRandomized) {
|
||||
// Translates value here to set RANDOMIZATION_PERSISTENT as first item in UI for better UX.
|
||||
final int prefMacRandomized = translateMacRandomizedValueToPrefValue(macRandomized);
|
||||
preference.setSummary(preference.getEntries()[prefMacRandomized]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubmit(WifiDialog dialog) {
|
||||
if (dialog.getController() != null) {
|
||||
final WifiConfiguration newConfig = dialog.getController().getConfig();
|
||||
if (newConfig == null || mWifiConfiguration == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newConfig.macRandomizationSetting != mWifiConfiguration.macRandomizationSetting) {
|
||||
mWifiConfiguration = newConfig;
|
||||
onPreferenceChange(mPreference, String.valueOf(newConfig.macRandomizationSetting));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.android.settings.wifi.WifiConfigController.PRIVACY_SPINNER_INDEX_DEVICE_MAC;
|
||||
import static com.android.settings.wifi.WifiConfigController.PRIVACY_SPINNER_INDEX_RANDOMIZED_MAC;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.anyString;
|
||||
@@ -43,7 +46,6 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settings.wifi.details.WifiPrivacyPreferenceController;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -381,14 +383,12 @@ public class WifiConfigControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadMacRandomizedValue_shouldPersistentAsDefault() {
|
||||
public void loadMacRandomizedValue_shouldMandomizedMacAsDefault() {
|
||||
final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
|
||||
final int prefPersist =
|
||||
WifiPrivacyPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
WifiConfiguration.RANDOMIZATION_PERSISTENT);
|
||||
|
||||
assertThat(privacySetting.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(privacySetting.getSelectedItemPosition()).isEqualTo(prefPersist);
|
||||
assertThat(privacySetting.getSelectedItemPosition()).isEqualTo(
|
||||
PRIVACY_SPINNER_INDEX_RANDOMIZED_MAC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -409,14 +409,12 @@ public class WifiConfigControllerTest {
|
||||
mockWifiConfig.macRandomizationSetting = macRandomizedValue;
|
||||
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
|
||||
WifiConfigUiBase.MODE_CONNECT);
|
||||
|
||||
final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
|
||||
final int expectedPrefValue =
|
||||
WifiPrivacyPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
macRandomizedValue);
|
||||
|
||||
assertThat(privacySetting.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(privacySetting.getSelectedItemPosition()).isEqualTo(expectedPrefValue);
|
||||
assertThat(privacySetting.getSelectedItemPosition()).isEqualTo(
|
||||
macRandomizedValue == WifiConfiguration.RANDOMIZATION_PERSISTENT
|
||||
? PRIVACY_SPINNER_INDEX_RANDOMIZED_MAC : PRIVACY_SPINNER_INDEX_DEVICE_MAC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -427,12 +425,9 @@ public class WifiConfigControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveMacRandomizedValue_ChangedToNone_shouldGetNone() {
|
||||
public void saveMacRandomizedValue_ChangedToDeviceMac_shouldGetNone() {
|
||||
final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
|
||||
final int prefMacNone =
|
||||
WifiPrivacyPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
WifiConfiguration.RANDOMIZATION_NONE);
|
||||
privacySetting.setSelection(prefMacNone);
|
||||
privacySetting.setSelection(PRIVACY_SPINNER_INDEX_DEVICE_MAC);
|
||||
|
||||
WifiConfiguration config = mController.getConfig();
|
||||
assertThat(config.macRandomizationSetting).isEqualTo(WifiConfiguration.RANDOMIZATION_NONE);
|
||||
|
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.details;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiPrivacyPreferenceControllerTest {
|
||||
|
||||
private static final int PRIVACY_RANDOMIZED = WifiConfiguration.RANDOMIZATION_PERSISTENT;
|
||||
private static final int PRIVACY_TRUSTED = WifiConfiguration.RANDOMIZATION_NONE;
|
||||
|
||||
@Mock
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
|
||||
private WifiPrivacyPreferenceController mPreferenceController;
|
||||
private Context mContext;
|
||||
private DropDownPreference mDropDownPreference;
|
||||
private String[] perferenceString;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
WifiPrivacyPreferenceController preferenceController = new WifiPrivacyPreferenceController(
|
||||
mContext);
|
||||
preferenceController.setWifiConfiguration(mWifiConfiguration);
|
||||
mPreferenceController = spy(preferenceController);
|
||||
mDropDownPreference = new DropDownPreference(mContext);
|
||||
mDropDownPreference.setEntries(R.array.wifi_privacy_entries);
|
||||
mDropDownPreference.setEntryValues(R.array.wifi_privacy_values);
|
||||
|
||||
perferenceString = mContext.getResources().getStringArray(R.array.wifi_privacy_entries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiPrivacy_setCorrectValue() {
|
||||
doReturn(PRIVACY_TRUSTED).when(mPreferenceController).getRandomizationValue();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
int prefValue = mPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
PRIVACY_TRUSTED);
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo(perferenceString[prefValue]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiNotMetered_setCorrectValue() {
|
||||
doReturn(PRIVACY_RANDOMIZED).when(mPreferenceController).getRandomizationValue();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
int prefValue = mPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
PRIVACY_RANDOMIZED);
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo(perferenceString[prefValue]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testController_resilientToNullConfig() {
|
||||
mPreferenceController = spy(new WifiPrivacyPreferenceController(mContext));
|
||||
|
||||
mPreferenceController.getRandomizationValue();
|
||||
mPreferenceController.onPreferenceChange(mDropDownPreference, "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isNotEphemeralNetwork_shouldBeSelectable() {
|
||||
mPreferenceController.setIsEphemeral(false);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isEphemeralNetwork_shouldNotSelectable() {
|
||||
mPreferenceController.setIsEphemeral(true);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isNotPasspointNetwork_shouldBeSelectable() {
|
||||
mPreferenceController.setIsPasspoint(false);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isPasspointNetwork_shouldNotSelectable() {
|
||||
mPreferenceController.setIsPasspoint(true);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user