From 228cf200ae76bcfa1c8ba5ad0cdba71387f1f3e4 Mon Sep 17 00:00:00 2001 From: govenliu Date: Wed, 2 Oct 2019 10:10:48 +0800 Subject: [PATCH] [Wi-Fi] Wrong MAC address shown in Settings. The MAC addresses in "About phone" and "Saved networks" may be different because of new Randomized MAC mechanism. 1.Add new UIs to guide users to saved network and use different titles to show different conditions. 2.Remove MAC address and IP fields in WifiPreference by new design. Bug: 133466540 Test: add test case to check if the title changed according to the privacy level. Change-Id: Idb5972dc2565f6fe58a83f6aa7124abbc035888f --- res/values/strings.xml | 10 +- res/xml/my_device_info.xml | 15 +- res/xml/wifi_configure_settings.xml | 8 - res/xml/wifi_network_details_fragment.xml | 2 +- .../settings/wifi/ConfigureWifiSettings.java | 23 -- .../wifi/WifiInfoPreferenceController.java | 132 ---------- .../WifiDetailPreferenceController.java | 23 ++ ...SavedAccessPointsPreferenceController.java | 25 +- .../wifi/ConfigureWifiSettingsTest.java | 42 ---- .../WifiInfoPreferenceControllerTest.java | 225 ------------------ .../WifiDetailPreferenceControllerTest.java | 25 ++ 11 files changed, 78 insertions(+), 452 deletions(-) delete mode 100644 src/com/android/settings/wifi/WifiInfoPreferenceController.java delete mode 100644 tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 7479318f28a..b505086b0dd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2364,8 +2364,10 @@ Advanced Wi\u2011Fi SSID - - MAC address + + Factory MAC address + + Randomized MAC address IP address @@ -3131,6 +3133,8 @@ Unmount SD card, view available storage IMEI (sim slot %1$d) + + To view, choose saved network IMEI @@ -3189,6 +3193,8 @@ Network Wi\u2011Fi MAC address + + Factory Wi\u2011Fi MAC address Bluetooth address diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml index 6ebb1a5bc4a..ccd52eabec1 100644 --- a/res/xml/my_device_info.xml +++ b/res/xml/my_device_info.xml @@ -139,9 +139,18 @@ + + + @@ -149,7 +158,7 @@ diff --git a/res/xml/wifi_configure_settings.xml b/res/xml/wifi_configure_settings.xml index c7e16ef6760..1859a1e8546 100644 --- a/res/xml/wifi_configure_settings.xml +++ b/res/xml/wifi_configure_settings.xml @@ -69,12 +69,4 @@ android:title="@string/wifi_menu_p2p" android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings" /> - - - - diff --git a/res/xml/wifi_network_details_fragment.xml b/res/xml/wifi_network_details_fragment.xml index d45f9bc1796..7ec1f0e4a9a 100644 --- a/res/xml/wifi_network_details_fragment.xml +++ b/res/xml/wifi_network_details_fragment.xml @@ -87,7 +87,7 @@ settings:enableCopying="true"/> createPreferenceControllers(Context context) { final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); final List controllers = new ArrayList<>(); - controllers.add(new WifiInfoPreferenceController(context, getSettingsLifecycle(), - wifiManager)); controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(), wifiManager)); return controllers; @@ -107,24 +102,6 @@ public class ConfigureWifiSettings extends DashboardFragment { public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider(R.xml.wifi_configure_settings) { - - @Override - public List getNonIndexableKeys(Context context) { - List keys = super.getNonIndexableKeys(context); - - // If connected to WiFi, this IP address will be the same as the Status IP. - // Or, if there is no connection they will say unavailable. - ConnectivityManager cm = (ConnectivityManager) - context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo info = cm.getActiveNetworkInfo(); - if (info == null - || info.getType() == ConnectivityManager.TYPE_WIFI) { - keys.add(KEY_IP_ADDRESS); - } - - return keys; - } - protected boolean isPageSearchEnabled(Context context) { return context.getResources() .getBoolean(R.bool.config_show_wifi_settings); diff --git a/src/com/android/settings/wifi/WifiInfoPreferenceController.java b/src/com/android/settings/wifi/WifiInfoPreferenceController.java deleted file mode 100644 index 2a8c7b5755e..00000000000 --- a/src/com/android/settings/wifi/WifiInfoPreferenceController.java +++ /dev/null @@ -1,132 +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.wifi; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.provider.Settings; -import android.text.TextUtils; - -import androidx.core.text.BidiFormatter; -import androidx.preference.Preference; -import androidx.preference.PreferenceScreen; - -import com.android.settings.R; -import com.android.settings.Utils; -import com.android.settings.core.PreferenceControllerMixin; -import com.android.settingslib.core.AbstractPreferenceController; -import com.android.settingslib.core.lifecycle.Lifecycle; -import com.android.settingslib.core.lifecycle.LifecycleObserver; -import com.android.settingslib.core.lifecycle.events.OnPause; -import com.android.settingslib.core.lifecycle.events.OnResume; - -/** - * {@link PreferenceControllerMixin} that updates MAC/IP address. - */ -public class WifiInfoPreferenceController extends AbstractPreferenceController - implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause { - - private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address"; - private static final String KEY_MAC_ADDRESS = "mac_address"; - - private final IntentFilter mFilter; - private final WifiManager mWifiManager; - - private Preference mWifiMacAddressPref; - private Preference mWifiIpAddressPref; - - public WifiInfoPreferenceController(Context context, Lifecycle lifecycle, - WifiManager wifiManager) { - super(context); - mWifiManager = wifiManager; - mFilter = new IntentFilter(); - mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION); - mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - - lifecycle.addObserver(this); - } - - @Override - public boolean isAvailable() { - return true; - } - - @Override - public String getPreferenceKey() { - // Returns null because this controller contains more than 1 preference. - return null; - } - - @Override - public void displayPreference(PreferenceScreen screen) { - super.displayPreference(screen); - mWifiMacAddressPref = screen.findPreference(KEY_MAC_ADDRESS); - mWifiMacAddressPref.setSelectable(false); - mWifiIpAddressPref = screen.findPreference(KEY_CURRENT_IP_ADDRESS); - mWifiIpAddressPref.setSelectable(false); - } - - @Override - public void onResume() { - mContext.registerReceiver(mReceiver, mFilter); - updateWifiInfo(); - } - - @Override - public void onPause() { - mContext.unregisterReceiver(mReceiver); - } - - public void updateWifiInfo() { - if (mWifiMacAddressPref != null) { - final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); - 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 (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)) { - mWifiMacAddressPref.setSummary(R.string.status_unavailable); - } else { - mWifiMacAddressPref.setSummary(macAddress); - } - } - if (mWifiIpAddressPref != null) { - final String ipAddress = Utils.getWifiIpAddresses(mContext); - mWifiIpAddressPref.setSummary(ipAddress == null - ? mContext.getString(R.string.status_unavailable) - : BidiFormatter.getInstance().unicodeWrap(ipAddress)); - } - } - - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (action.equals(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION) || - action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { - updateWifiInfo(); - } - } - }; -} diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java index a915766bbe6..3ed561bd835 100644 --- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java @@ -687,6 +687,9 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController } else { mMacAddressPref.setSummary(macAddress); } + + // MAC Address Pref Title + refreshMacTitle(); } private String getMacAddress() { @@ -1141,4 +1144,24 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController mTimer.cancel(); mTimer = null; } + + private void refreshMacTitle() { + if (mWifiConfig == null) { + return; + } + + // For saved Passpoint network, framework doesn't have the field to keep the MAC choice + // persistently, so Passpoint network will always use the default value so far, which is + // randomized MAC address, so don't need to modify title. + if (mAccessPoint.isPasspoint() || mAccessPoint.isPasspointConfig()) { + return; + } + + mMacAddressPref.setTitle( + (mWifiConfig.macRandomizationSetting + == WifiConfiguration.RANDOMIZATION_PERSISTENT) + ? R.string.wifi_advanced_randomized_mac_address_title + : R.string.wifi_advanced_factory_mac_address_title); + + } } diff --git a/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceController.java b/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceController.java index 82c60287387..b8e36a4616b 100644 --- a/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceController.java +++ b/src/com/android/settings/wifi/savedaccesspoints/SavedAccessPointsPreferenceController.java @@ -27,7 +27,6 @@ import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceScreen; import com.android.settings.core.BasePreferenceController; -import com.android.settings.utils.PreferenceGroupChildrenCache; import com.android.settings.R; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; @@ -50,7 +49,6 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl private static final String TAG = "SavedAPPrefCtrl"; private final WifiManager mWifiManager; - private final PreferenceGroupChildrenCache mChildrenCache; private final UserBadgeCache mUserBadgeCache; private PreferenceGroup mPreferenceGroup; @@ -61,7 +59,6 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl super(context, preferenceKey); mUserBadgeCache = new AccessPointPreference.UserBadgeCache(context.getPackageManager()); mWifiManager = context.getSystemService(WifiManager.class); - mChildrenCache = new PreferenceGroupChildrenCache(); } public SavedAccessPointsPreferenceController setHost(SavedAccessPointsWifiSettings host) { @@ -91,8 +88,9 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl @Override public boolean onPreferenceClick(Preference preference) { + final Preference preferenceInGroup = mPreferenceGroup.findPreference(preference.getKey()); if (mHost != null) { - mHost.showWifiPage((AccessPointPreference) preference); + mHost.showWifiPage((AccessPointPreference) preferenceInGroup); } return false; } @@ -118,7 +116,7 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl final List accessPoints = WifiSavedConfigUtils.getAllConfigs(mContext, mWifiManager); Collections.sort(accessPoints, SavedNetworkComparator.INSTANCE); - mChildrenCache.cacheRemoveAllPrefs(mPreferenceGroup); + mPreferenceGroup.removeAll(); final int accessPointsSize = accessPoints.size(); for (int i = 0; i < accessPointsSize; ++i) { @@ -130,20 +128,15 @@ public class SavedAccessPointsPreferenceController extends BasePreferenceControl } String key = ap.getKey(); - AccessPointPreference preference = - (AccessPointPreference) mChildrenCache.getCachedPreference(key); - if (preference == null) { - preference = new AccessPointPreference(ap, prefContext, mUserBadgeCache, true); - preference.setKey(key); - preference.setIcon(null); - preference.setOnPreferenceClickListener(this); - mPreferenceGroup.addPreference(preference); - } + AccessPointPreference preference = new AccessPointPreference(ap, prefContext, + mUserBadgeCache, true); + preference.setKey(key); + preference.setIcon(null); + preference.setOnPreferenceClickListener(this); + mPreferenceGroup.addPreference(preference); preference.setOrder(i); } - mChildrenCache.removeCachedPrefs(mPreferenceGroup); - if (mPreferenceGroup.getPreferenceCount() < 1) { Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!"); mPreferenceGroup.setVisible(false); diff --git a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java index 2e3a111cd15..d1d78854487 100644 --- a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java @@ -2,14 +2,9 @@ package com.android.settings.wifi; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; import com.android.settings.testutils.XmlTestUtils; @@ -54,41 +49,4 @@ public class ConfigureWifiSettingsTest { assertThat(keys).isNotNull(); assertThat(niks).containsAllIn(keys); } - - @Test - public void testNonIndexableKeys_noConnection_blocksIP() { - ConnectivityManager manager = mock(ConnectivityManager.class); - when(manager.getActiveNetworkInfo()).thenReturn(null); - doReturn(manager).when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE); - - final List niks = - ConfigureWifiSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext); - assertThat(niks).contains(ConfigureWifiSettings.KEY_IP_ADDRESS); - } - - @Test - public void testNonIndexableKeys_wifiConnection_blocksIP() { - ConnectivityManager manager = mock(ConnectivityManager.class); - NetworkInfo info = mock(NetworkInfo.class); - when(info.getType()).thenReturn(ConnectivityManager.TYPE_WIFI); - when(manager.getActiveNetworkInfo()).thenReturn(info); - doReturn(manager).when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE); - - final List niks = - ConfigureWifiSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext); - assertThat(niks).contains(ConfigureWifiSettings.KEY_IP_ADDRESS); - } - - @Test - public void testNonIndexableKeys_mobileConnection_blocksIP() { - ConnectivityManager manager = mock(ConnectivityManager.class); - NetworkInfo info = mock(NetworkInfo.class); - when(info.getType()).thenReturn(ConnectivityManager.TYPE_MOBILE); - when(manager.getActiveNetworkInfo()).thenReturn(info); - doReturn(manager).when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE); - - final List niks = - ConfigureWifiSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext); - assertThat(niks).doesNotContain(ConfigureWifiSettings.KEY_IP_ADDRESS); - } } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java deleted file mode 100644 index 85d7726ee66..00000000000 --- a/tests/robotests/src/com/android/settings/wifi/WifiInfoPreferenceControllerTest.java +++ /dev/null @@ -1,225 +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.wifi; - -import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; -import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.verify; -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; - -import androidx.lifecycle.LifecycleOwner; -import androidx.preference.Preference; -import androidx.preference.PreferenceScreen; - -import com.android.settings.R; -import com.android.settingslib.core.lifecycle.Lifecycle; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Answers; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class WifiInfoPreferenceControllerTest { - - private static final String TEST_MAC_ADDRESS = "42:0a:23:43:ac:02"; - - @Mock - private Context mContext; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private WifiManager mWifiManager; - @Mock - private PreferenceScreen mScreen; - @Mock - private Preference mIpPreference; - @Mock - private Preference mMacPreference; - @Mock - private WifiInfo mWifiInfo; - @Mock - private Resources mResources; - - private Lifecycle mLifecycle; - private LifecycleOwner mLifecycleOwner; - private WifiInfoPreferenceController mController; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mLifecycleOwner = () -> mLifecycle; - mLifecycle = new Lifecycle(mLifecycleOwner); - when(mContext.getSystemService(WifiManager.class)) - .thenReturn(mWifiManager); - when(mScreen.findPreference(anyString())) - .thenReturn(mMacPreference) - .thenReturn(mIpPreference); - when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo); - when(mWifiManager.getCurrentNetwork()).thenReturn(null); - when(mContext.getResources()).thenReturn(mResources); - mController = new WifiInfoPreferenceController(mContext, mLifecycle, mWifiManager); - } - - @Test - public void testIsAvailable_shouldAlwaysReturnTrue() { - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void getPreferenceKey_shouldReturnNull() { - assertThat(mController.getPreferenceKey()).isNull(); - } - - @Test - public void runThroughLifecycle_shouldInstallListenerOnResume() { - mLifecycle.handleLifecycleEvent(ON_RESUME); - verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class)); - - mLifecycle.handleLifecycleEvent(ON_PAUSE); - verify(mContext).unregisterReceiver(any(BroadcastReceiver.class)); - } - - @Test - public void onResume_shouldUpdateWifiInfo() { - when(mWifiInfo.getMacAddress()).thenReturn(TEST_MAC_ADDRESS); - - mController.displayPreference(mScreen); - mController.onResume(); - - verify(mMacPreference).setSummary(TEST_MAC_ADDRESS); - verify(mIpPreference).setSummary(any()); - } - - @Test - public void updateWifiInfo_nullWifiInfoWithMacRandomizationOff_setMacUnavailable() { - when(mResources.getBoolean( - com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported)) - .thenReturn(false); - mController.displayPreference(mScreen); - when(mWifiManager.getConnectionInfo()).thenReturn(null); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(R.string.status_unavailable); - } - - @Test - public void updateWifiInfo_nullMacWithMacRandomizationOff_setMacUnavailable() { - when(mResources.getBoolean( - com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported)) - .thenReturn(false); - mController.displayPreference(mScreen); - when(mWifiInfo.getMacAddress()).thenReturn(null); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(R.string.status_unavailable); - } - - @Test - public void updateWifiInfo_defaultMacWithMacRandomizationOff_setMacUnavailable() { - 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); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(R.string.status_unavailable); - } - - @Test - public void updateWifiInfo_validMacWithMacRandomizationOff_setValidMac() { - 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); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(TEST_MAC_ADDRESS); - } - - @Test - public void updateWifiInfo_nullWifiInfoWithMacRandomizationOn_setMacUnavailable() { - when(mResources.getBoolean( - com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported)) - .thenReturn(true); - mController.displayPreference(mScreen); - when(mWifiManager.getConnectionInfo()).thenReturn(null); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(R.string.status_unavailable); - } - - @Test - public void updateWifiInfo_nullMacWithMacRandomizationOn_setMacUnavailable() { - when(mResources.getBoolean( - com.android.internal.R.bool.config_wifi_connected_mac_randomization_supported)) - .thenReturn(true); - mController.displayPreference(mScreen); - when(mWifiInfo.getMacAddress()).thenReturn(null); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(R.string.status_unavailable); - } - - @Test - public void updateWifiInfo_defaultMacWithMacRandomizationOn_setMacRandomized() { - 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); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(R.string.wifi_status_mac_randomized); - } - - @Test - public void updateWifiInfo_validMacWithMacRandomizationOn_setValidMac() { - 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); - - mController.updateWifiInfo(); - - verify(mMacPreference).setSummary(TEST_MAC_ADDRESS); - } -} diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java index 010fb749f74..7f65b0663e9 100644 --- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java @@ -1845,6 +1845,31 @@ public class WifiDetailPreferenceControllerTest { assertThat(icon).isNotNull(); } + @Test + public void checkMacTitle_whenPrivacyRandomizedMac_shouldBeRandom() { + setUpForDisconnectedNetwork(); + mockWifiConfig.macRandomizationSetting = WifiConfiguration.RANDOMIZATION_PERSISTENT; + when(mockWifiConfig.getRandomizedMacAddress()).thenReturn(mockMacAddress); + when(mockMacAddress.toString()).thenReturn(RANDOMIZED_MAC_ADDRESS); + + displayAndResume(); + + verify(mockMacAddressPref).setTitle(R.string.wifi_advanced_randomized_mac_address_title); + } + + @Test + public void checkMacTitle_whenPrivacyDeviceMac_shouldBeFactory() { + setUpForDisconnectedNetwork(); + mockWifiConfig.macRandomizationSetting = WifiConfiguration.RANDOMIZATION_NONE; + when(mockWifiConfig.getRandomizedMacAddress()).thenReturn(mockMacAddress); + when(mockWifiManager.getFactoryMacAddresses()) + .thenReturn(new String[]{FACTORY_MAC_ADDRESS}); + + displayAndResume(); + + verify(mockMacAddressPref).setTitle(R.string.wifi_advanced_factory_mac_address_title); + } + private ActionButtonsPreference createMock() { final ActionButtonsPreference pref = mock(ActionButtonsPreference.class); when(pref.setButton1Text(anyInt())).thenReturn(pref);