diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-04-10 01:00:06 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-10 01:00:06 +0000 |
commit | b5d1783bbb2cf9e2ca8f3d060c112a82ab2f12f5 (patch) | |
tree | 47d01aefc025c185c2bb667d6f0b41fbf821accd /tests | |
parent | 66ed6f4c29a78457585afe5d5734ba6035d70e08 (diff) | |
parent | 3c9e5da2db2da5ee03c2c765fa33b9aecb1add85 (diff) |
Merge "Add imsi protection notification for saved network" into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java | 58 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiCarrierInfoManagerTest.java | 26 |
2 files changed, 79 insertions, 5 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java index cdc6762ba..839b2e5fe 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java @@ -29,6 +29,7 @@ import android.util.Pair; import com.android.server.wifi.WifiNetworkSelector.NetworkNominator.OnConnectableListener; import com.android.server.wifi.WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs; import com.android.server.wifi.hotspot2.PasspointNetworkNominateHelper; +import com.android.server.wifi.util.WifiPermissionsUtil; import org.junit.After; import org.junit.Before; @@ -52,9 +53,14 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { MockitoAnnotations.initMocks(this); mLocalLog = new LocalLog(512); mSavedNetworkNominator = new SavedNetworkNominator(mWifiConfigManager, - mPasspointNetworkNominateHelper, mLocalLog, mWifiCarrierInfoManager); + mPasspointNetworkNominateHelper, mLocalLog, mWifiCarrierInfoManager, + mWifiPermissionsUtil); when(mWifiCarrierInfoManager.isSimPresent(anyInt())).thenReturn(true); - when(mWifiCarrierInfoManager.getBestMatchSubscriptionId(any())).thenReturn(1); + when(mWifiCarrierInfoManager.getBestMatchSubscriptionId(any())).thenReturn(VALID_SUBID); + when(mWifiCarrierInfoManager.requiresImsiEncryption(VALID_SUBID)).thenReturn(true); + when(mWifiCarrierInfoManager.isImsiEncryptionInfoAvailable(anyInt())).thenReturn(true); + when(mWifiCarrierInfoManager.getMatchingSubId(TEST_CARRIER_ID)).thenReturn(VALID_SUBID); + } /** Cleans up test. */ @@ -65,9 +71,11 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { private ArgumentCaptor<WifiConfiguration> mWifiConfigurationArgumentCaptor = ArgumentCaptor.forClass(WifiConfiguration.class); + private static final int VALID_SUBID = 10; private static final int INVALID_SUBID = 1; private static final int TEST_CARRIER_ID = 100; private static final int RSSI_LEVEL = -50; + private static final int TEST_UID = 1001; private SavedNetworkNominator mSavedNetworkNominator; @Mock private WifiConfigManager mWifiConfigManager; @@ -75,6 +83,7 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { @Mock private OnConnectableListener mOnConnectableListener; @Mock private WifiCarrierInfoManager mWifiCarrierInfoManager; @Mock private PasspointNetworkNominateHelper mPasspointNetworkNominateHelper; + @Mock private WifiPermissionsUtil mWifiPermissionsUtil; private LocalLog mLocalLog; /** @@ -121,8 +130,7 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); savedConfigs[0].carrierId = TEST_CARRIER_ID; // SIM is absent - when(mWifiCarrierInfoManager.getBestMatchSubscriptionId(any(WifiConfiguration.class))) - .thenReturn(INVALID_SUBID); + when(mWifiCarrierInfoManager.getMatchingSubId(TEST_CARRIER_ID)).thenReturn(INVALID_SUBID); when(mWifiCarrierInfoManager.isSimPresent(eq(INVALID_SUBID))).thenReturn(false); mSavedNetworkNominator.nominateNetworks(scanDetails, @@ -238,7 +246,7 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { * Verify if a network is metered and with non-data sim, will not nominate as a candidate. */ @Test - public void ignoreNetworksIfMeteredAndFromNonDataSim() { + public void testIgnoreNetworksIfMeteredAndFromNonDataSim() { String[] ssids = {"\"test1\""}; String[] bssids = {"6c:f3:7f:ae:8c:f3"}; int[] freqs = {2470}; @@ -249,6 +257,7 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { freqs, levels, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + savedConfigs[0].carrierId = TEST_CARRIER_ID; when(mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(savedConfigs[0])) .thenReturn(false); mSavedNetworkNominator.nominateNetworks(scanDetails, @@ -259,4 +268,43 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { .thenReturn(true); verify(mOnConnectableListener, never()).onConnectable(any(), any()); } + + /** + * Verify a saved network is from app not user, if IMSI privacy protection is not required, will + * send notification for user to approve exemption, and not consider as a candidate. + */ + @Test + public void testIgnoreNetworksFromAppIfNoImsiProtection() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] freqs = {2470}; + int[] levels = {RSSI_LEVEL}; + when(mWifiCarrierInfoManager.isCarrierNetworkFromNonDefaultDataSim(any())) + .thenReturn(false); + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigForEapSimNetwork(ssids, bssids, + freqs, levels, mWifiConfigManager, mClock); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + savedConfigs[0].carrierId = TEST_CARRIER_ID; + // Doesn't require Imsi protection and user didn't approved + when(mWifiCarrierInfoManager.requiresImsiEncryption(VALID_SUBID)).thenReturn(false); + when(mWifiCarrierInfoManager.hasUserApprovedImsiPrivacyExemptionForCarrier(TEST_CARRIER_ID)) + .thenReturn(false); + mSavedNetworkNominator.nominateNetworks(scanDetails, + null, null, true, false, mOnConnectableListener); + verify(mOnConnectableListener, never()).onConnectable(any(), any()); + verify(mWifiCarrierInfoManager) + .sendImsiProtectionExemptionNotificationIfRequired(TEST_CARRIER_ID); + // Simulate user approved + when(mWifiCarrierInfoManager.hasUserApprovedImsiPrivacyExemptionForCarrier(TEST_CARRIER_ID)) + .thenReturn(true); + mSavedNetworkNominator.nominateNetworks(scanDetails, + null, null, true, false, mOnConnectableListener); + verify(mOnConnectableListener).onConnectable(any(), any()); + // If from settings app, will bypass the IMSI check. + when(mWifiCarrierInfoManager.hasUserApprovedImsiPrivacyExemptionForCarrier(TEST_CARRIER_ID)) + .thenReturn(false); + when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCarrierInfoManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCarrierInfoManagerTest.java index 1053d733f..28bffa149 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiCarrierInfoManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiCarrierInfoManagerTest.java @@ -75,6 +75,7 @@ import java.security.PublicKey; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import javax.crypto.BadPaddingException; @@ -243,6 +244,7 @@ public class WifiCarrierInfoManagerTest extends WifiBaseTest { eq(R.string.wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation))) .thenReturn("blah"); mWifiCarrierInfoManager.addImsiExemptionUserApprovalListener(mListener); + mImsiDataSource.fromDeserialized(new HashMap<>()); } @After @@ -1698,6 +1700,30 @@ public class WifiCarrierInfoManagerTest extends WifiBaseTest { verify(mListener, never()).onUserAllowed(DATA_CARRIER_ID); } + @Test + public void testUserDataStoreIsNotLoadedNotificationWillNotBeSent() { + // reset data source to unloaded state. + mImsiDataSource.reset(); + // Setup carrier without IMSI privacy protection + when(mCarrierConfigManager.getConfigForSubId(DATA_SUBID)) + .thenReturn(generateTestCarrierConfig(false)); + ArgumentCaptor<BroadcastReceiver> receiver = + ArgumentCaptor.forClass(BroadcastReceiver.class); + verify(mContext).registerReceiver(receiver.capture(), any(IntentFilter.class)); + + receiver.getValue().onReceive(mContext, + new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); + assertFalse(mWifiCarrierInfoManager.requiresImsiEncryption(DATA_SUBID)); + + mWifiCarrierInfoManager.sendImsiProtectionExemptionNotificationIfRequired(DATA_CARRIER_ID); + verifyNoMoreInteractions(mNotificationManger); + + // Loaded user data store, notification should be sent + mImsiDataSource.fromDeserialized(new HashMap<>()); + mWifiCarrierInfoManager.sendImsiProtectionExemptionNotificationIfRequired(DATA_CARRIER_ID); + validateImsiProtectionNotification(CARRIER_NAME); + } + private void validateImsiProtectionNotification(String carrierName) { verify(mNotificationManger, atLeastOnce()).notify( eq(SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE), |