Revert "Wifi MAC Randomization: Developer Options"

This reverts commit 8c6d8daaf0.

Reason for revert: <Enabling feature by default. Global flag moved to OEM
configurable overlay instead.>

Bug: 123408542
Test: unit tests
Test: Manual test to verify dev option is gone
Change-Id: Iae667a331b5d4fb4cb6fe07077eb9f3954f3089e
This commit is contained in:
Oscar Shu
2019-01-25 01:16:29 +00:00
committed by xshu
parent 8167b65871
commit 64328862bd
9 changed files with 31 additions and 236 deletions

View File

@@ -41,10 +41,6 @@
<!-- Whether to show Camera laser sensor switch in Developer Options -->
<bool name="config_show_camera_laser_sensor">false</bool>
<!-- Whether to show Connected MAC Randomization in Developer Options
as not all devices can support dynamic MAC address change. -->
<bool name="config_wifi_support_connected_mac_randomization">false</bool>
<!-- Fully-qualified class name for the implementation of the FeatureFactory to be instantiated. -->
<string name="config_featureFactory" translatable="false">com.android.settings.overlay.FeatureFactoryImpl</string>

View File

@@ -221,11 +221,6 @@
android:title="@string/wifi_verbose_logging"
android:summary="@string/wifi_verbose_logging_summary" />
<SwitchPreference
android:key="wifi_connected_mac_randomization"
android:title="@string/wifi_connected_mac_randomization"
android:summary="@string/wifi_connected_mac_randomization_summary" />
<SwitchPreference
android:key="mobile_data_always_on"
android:title="@string/mobile_data_always_on"

View File

@@ -429,7 +429,6 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new CameraLaserSensorPreferenceController(context));
controllers.add(new WifiDisplayCertificationPreferenceController(context));
controllers.add(new WifiVerboseLoggingPreferenceController(context));
controllers.add(new WifiConnectedMacRandomizationPreferenceController(context));
controllers.add(new MobileDataAlwaysOnPreferenceController(context));
controllers.add(new TetheringHardwareAccelPreferenceController(context));
controllers.add(new BluetoothDeviceNoNamePreferenceController(context));

View File

@@ -1,80 +0,0 @@
/*
* Copyright (C) 2017 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.development;
import android.content.Context;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class WifiConnectedMacRandomizationPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
private static final String WIFI_CONNECTED_MAC_RANDOMIZATION_KEY =
"wifi_connected_mac_randomization";
@VisibleForTesting
static final int SETTING_VALUE_ON = 1;
@VisibleForTesting
static final int SETTING_VALUE_OFF = 0;
public WifiConnectedMacRandomizationPreferenceController(Context context) {
super(context);
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(
R.bool.config_wifi_support_connected_mac_randomization);
}
@Override
public String getPreferenceKey() {
return WIFI_CONNECTED_MAC_RANDOMIZATION_KEY;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean isEnabled = (Boolean) newValue;
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED,
isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
return true;
}
@Override
public void updateState(Preference preference) {
final int enableMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, SETTING_VALUE_OFF);
((SwitchPreference) mPreference).setChecked(enableMode != SETTING_VALUE_OFF);
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, SETTING_VALUE_OFF);
((SwitchPreference) mPreference).setChecked(false);
}
}

View File

@@ -98,12 +98,11 @@ public class WifiInfoPreferenceController extends AbstractPreferenceController
public void updateWifiInfo() {
if (mWifiMacAddressPref != null) {
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
final int macRandomizationMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
final boolean macRandomizationSupported = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported);
final String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
if (macRandomizationMode == 1
&& WifiInfo.DEFAULT_MAC_ADDRESS.equals(macAddress)) {
if (macRandomizationSupported && WifiInfo.DEFAULT_MAC_ADDRESS.equals(macAddress)) {
mWifiMacAddressPref.setSummary(R.string.wifi_status_mac_randomized);
} else if (TextUtils.isEmpty(macAddress)
|| WifiInfo.DEFAULT_MAC_ADDRESS.equals(macAddress)) {

View File

@@ -56,7 +56,6 @@
<bool name="config_show_vibrate_input_devices">false</bool>
<bool name="config_show_reset_dashboard">false</bool>
<bool name="config_show_system_update_settings">false</bool>
<bool name="config_wifi_support_connected_mac_randomization">false</bool>
<bool name="config_show_device_model">false</bool>
<bool name="config_show_top_level_battery">false</bool>
<bool name="config_show_top_level_connected_devices">false</bool>

View File

@@ -20,7 +20,6 @@
<bool name="config_show_camera_laser_sensor">true</bool>
<bool name="config_show_connectivity_monitor">true</bool>
<bool name="config_display_recent_apps">true</bool>
<bool name="config_wifi_support_connected_mac_randomization">true</bool>
<!-- Fake dimen value for restricted icon size - needed to get around Robolectric
issue loading framework hidden resources -->

View File

@@ -1,124 +0,0 @@
/*
* Copyright (C) 2017 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.development;
import static com.android.settings.development.WifiConnectedMacRandomizationPreferenceController
.SETTING_VALUE_OFF;
import static com.android.settings.development.WifiConnectedMacRandomizationPreferenceController
.SETTING_VALUE_ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
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;
@RunWith(RobolectricTestRunner.class)
public class WifiConnectedMacRandomizationPreferenceControllerTest {
@Mock
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private SwitchPreference mPreference;
private WifiConnectedMacRandomizationPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new WifiConnectedMacRandomizationPreferenceController(mContext);
mPreference = new SwitchPreference(mContext);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
}
@Test
public void isAvailable_trueSupportFlag_shouldReturnTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_falseSupportFlag_shouldReturnFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void onPreferenceChange_settingEnabled_shouldEnableConnectedMacRandomization() {
mController.onPreferenceChange(mPreference, true /* new value */);
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, -1 /* default */);
assertThat(mode).isEqualTo(SETTING_VALUE_ON);
}
@Test
public void onPreferenceChange_settingDisabled_shouldDisableConnectedMacRandomization() {
mController.onPreferenceChange(mPreference, false /* new value */);
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, -1 /* default */);
assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
}
@Test
public void updateState_settingEnabled_shouldEnablePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, SETTING_VALUE_ON);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_settingDisabled_shouldDisablePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, SETTING_VALUE_OFF);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
mController.onDeveloperOptionsSwitchDisabled();
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, -1 /* default */);
assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
assertThat(mPreference.isChecked()).isFalse();
assertThat(mPreference.isEnabled()).isFalse();
}
}

View File

@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
@@ -65,6 +66,8 @@ public class WifiInfoPreferenceControllerTest {
private Preference mMacPreference;
@Mock
private WifiInfo mWifiInfo;
@Mock
private Resources mResources;
private Lifecycle mLifecycle;
private LifecycleOwner mLifecycleOwner;
@@ -82,6 +85,7 @@ public class WifiInfoPreferenceControllerTest {
.thenReturn(mIpPreference);
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
when(mWifiManager.getCurrentNetwork()).thenReturn(null);
when(mContext.getResources()).thenReturn(mResources);
mController = new WifiInfoPreferenceController(mContext, mLifecycle, mWifiManager);
}
@@ -117,8 +121,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_nullWifiInfoWithMacRandomizationOff_setMacUnavailable() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(false);
mController.displayPreference(mScreen);
when(mWifiManager.getConnectionInfo()).thenReturn(null);
@@ -129,8 +134,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_nullMacWithMacRandomizationOff_setMacUnavailable() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(false);
mController.displayPreference(mScreen);
when(mWifiInfo.getMacAddress()).thenReturn(null);
@@ -141,8 +147,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_defaultMacWithMacRandomizationOff_setMacUnavailable() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(false);
mController.displayPreference(mScreen);
when(mWifiInfo.getMacAddress()).thenReturn(WifiInfo.DEFAULT_MAC_ADDRESS);
@@ -153,8 +160,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_validMacWithMacRandomizationOff_setValidMac() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(false);
mController.displayPreference(mScreen);
when(mWifiInfo.getMacAddress()).thenReturn(TEST_MAC_ADDRESS);
@@ -165,8 +173,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_nullWifiInfoWithMacRandomizationOn_setMacUnavailable() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(true);
mController.displayPreference(mScreen);
when(mWifiManager.getConnectionInfo()).thenReturn(null);
@@ -177,8 +186,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_nullMacWithMacRandomizationOn_setMacUnavailable() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(true);
mController.displayPreference(mScreen);
when(mWifiInfo.getMacAddress()).thenReturn(null);
@@ -189,8 +199,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_defaultMacWithMacRandomizationOn_setMacRandomized() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(true);
mController.displayPreference(mScreen);
when(mWifiInfo.getMacAddress()).thenReturn(WifiInfo.DEFAULT_MAC_ADDRESS);
@@ -201,8 +212,9 @@ public class WifiInfoPreferenceControllerTest {
@Test
public void updateWifiInfo_validMacWithMacRandomizationOn_setValidMac() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
when(mResources.getBoolean(
com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported))
.thenReturn(true);
mController.displayPreference(mScreen);
when(mWifiInfo.getMacAddress()).thenReturn(TEST_MAC_ADDRESS);