diff options
author | Ecco Park <eccopark@google.com> | 2019-05-04 15:40:13 -0700 |
---|---|---|
committer | Ecco Park <eccopark@google.com> | 2019-05-06 13:17:24 -0700 |
commit | 353e8733c58131f4f78e63f2adb6a4f6379a1d59 (patch) | |
tree | e8579762d47b3cf68dae2e02655b9d597798a584 /tests | |
parent | 63dec560c331910d929f618add9e913601f2e675 (diff) |
Passpoint: remove the passpoint profiles when removing/disabling an app.
It is required to avoid auto-connection by the passpoint profiles
installed by the app which is disabled or uninstalled by user.
If the current network is for the removed Passpoint profile, disconnect
current network.
Bug: 129964730
Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: tested with R1 and R2 flow for connection.
Change-Id: Ic650b522b0bbc979727a2c069c4af51512001527
Signed-off-by: Ecco Park <eccopark@google.com>
Diffstat (limited to 'tests')
5 files changed, 160 insertions, 83 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 69dff1edd..4fb6456d5 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -1748,17 +1748,19 @@ public class ClientModeImplTest { homeSp.setFqdn("test.com"); config.setHomeSp(homeSp); - when(mPasspointManager.addOrUpdateProvider(config, MANAGED_PROFILE_UID)).thenReturn(true); + when(mPasspointManager.addOrUpdateProvider(config, MANAGED_PROFILE_UID, + OP_PACKAGE_NAME)).thenReturn(true); mLooper.startAutoDispatch(); assertTrue(mCmi.syncAddOrUpdatePasspointConfig( - mCmiAsyncChannel, config, MANAGED_PROFILE_UID)); + mCmiAsyncChannel, config, MANAGED_PROFILE_UID, OP_PACKAGE_NAME)); mLooper.stopAutoDispatch(); reset(mPasspointManager); - when(mPasspointManager.addOrUpdateProvider(config, MANAGED_PROFILE_UID)).thenReturn(false); + when(mPasspointManager.addOrUpdateProvider(config, MANAGED_PROFILE_UID, + OP_PACKAGE_NAME)).thenReturn(false); mLooper.startAutoDispatch(); assertFalse(mCmi.syncAddOrUpdatePasspointConfig( - mCmiAsyncChannel, config, MANAGED_PROFILE_UID)); + mCmiAsyncChannel, config, MANAGED_PROFILE_UID, OP_PACKAGE_NAME)); mLooper.stopAutoDispatch(); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 864fbdd1e..ba2135bd6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -108,6 +108,7 @@ import com.android.internal.os.PowerProfile; import com.android.internal.telephony.TelephonyIntents; import com.android.internal.util.AsyncChannel; import com.android.server.wifi.WifiServiceImpl.LocalOnlyRequestorCallback; +import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.hotspot2.PasspointProvisioningTestUtil; import com.android.server.wifi.util.WifiAsyncChannel; import com.android.server.wifi.util.WifiPermissionsUtil; @@ -238,6 +239,7 @@ public class WifiServiceImplTest { @Mock WifiConfigManager mWifiConfigManager; @Mock WifiScoreReport mWifiScoreReport; @Mock WifiScoreCard mWifiScoreCard; + @Mock PasspointManager mPasspointManager; @Spy FakeWifiLog mLog; @@ -362,6 +364,7 @@ public class WifiServiceImplTest { .thenReturn(mWifiNetworkSuggestionsManager); when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager); when(mWifiInjector.getWifiConfigManager()).thenReturn(mWifiConfigManager); + when(mWifiInjector.getPasspointManager()).thenReturn(mPasspointManager); when(mClientModeImpl.getWifiScoreReport()).thenReturn(mWifiScoreReport); when(mWifiInjector.getWifiScoreCard()).thenReturn(mWifiScoreCard); when(mClientModeImpl.syncStartSubscriptionProvisioning(anyInt(), @@ -2476,18 +2479,20 @@ public class WifiServiceImplTest { eq(Build.VERSION_CODES.Q))).thenReturn(true); when(mClientModeImpl.syncAddOrUpdatePasspointConfig(any(), - any(PasspointConfiguration.class), anyInt())).thenReturn(true); + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME))).thenReturn( + true); assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME)); verifyCheckChangePermission(TEST_PACKAGE_NAME); verify(mClientModeImpl).syncAddOrUpdatePasspointConfig(any(), - any(PasspointConfiguration.class), anyInt()); + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME)); reset(mClientModeImpl); when(mClientModeImpl.syncAddOrUpdatePasspointConfig(any(), - any(PasspointConfiguration.class), anyInt())).thenReturn(false); + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME))).thenReturn( + false); assertEquals(-1, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME)); verify(mClientModeImpl).syncAddOrUpdatePasspointConfig(any(), - any(PasspointConfiguration.class), anyInt()); + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME)); } /** @@ -3077,7 +3082,7 @@ public class WifiServiceImplTest { when(mWifiInjector.getClientModeImplHandler()).thenReturn(mHandler); mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), - (IntentFilter) argThat((IntentFilter filter) -> + argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); int uid = TEST_UID; @@ -3094,6 +3099,7 @@ public class WifiServiceImplTest { verify(mScanRequestProxy).clearScanRequestTimestampsForApp(packageName, uid); verify(mWifiNetworkSuggestionsManager).removeApp(packageName); verify(mClientModeImpl).removeNetworkRequestUserApprovedAccessPointsForApp(packageName); + verify(mPasspointManager).removePasspointProviderWithPackage(packageName); } @Test @@ -3101,7 +3107,7 @@ public class WifiServiceImplTest { when(mWifiInjector.getClientModeImplHandler()).thenReturn(mHandler); mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), - (IntentFilter) argThat((IntentFilter filter) -> + argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); String packageName = TEST_PACKAGE_NAME; @@ -3117,6 +3123,7 @@ public class WifiServiceImplTest { verify(mWifiNetworkSuggestionsManager, never()).removeApp(anyString()); verify(mClientModeImpl, never()).removeNetworkRequestUserApprovedAccessPointsForApp( packageName); + verify(mPasspointManager, never()).removePasspointProviderWithPackage(anyString()); } @Test @@ -3124,7 +3131,7 @@ public class WifiServiceImplTest { when(mWifiInjector.getClientModeImplHandler()).thenReturn(mHandler); mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), - (IntentFilter) argThat((IntentFilter filter) -> + argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); int uid = TEST_UID; @@ -3140,13 +3147,14 @@ public class WifiServiceImplTest { verify(mWifiNetworkSuggestionsManager, never()).removeApp(anyString()); verify(mClientModeImpl, never()).removeNetworkRequestUserApprovedAccessPointsForApp( anyString()); + verify(mPasspointManager, never()).removePasspointProviderWithPackage(anyString()); } @Test public void testUserRemovedBroadcastHandling() { mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), - (IntentFilter) argThat((IntentFilter filter) -> + argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_USER_REMOVED))); int userHandle = TEST_USER_HANDLE; @@ -3162,7 +3170,7 @@ public class WifiServiceImplTest { public void testUserRemovedBroadcastHandlingWithWrongIntentAction() { mWifiServiceImpl.checkAndStartWifi(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), - (IntentFilter) argThat((IntentFilter filter) -> + argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_USER_REMOVED))); int userHandle = TEST_USER_HANDLE; diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java index 1f5efb2fe..82cdb5a90 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java @@ -62,6 +62,7 @@ public class PasspointConfigUserStoreDataTest { private static final String TEST_CLIENT_CERTIFICATE_ALIAS = "ClientCert"; private static final String TEST_CLIENT_PRIVATE_KEY_ALIAS = "ClientPrivateKey"; private static final String TEST_REMEDIATION_CA_CERTIFICATE_ALIAS = "CaCert_3"; + private static final String TEST_CREATOR_PACKAGE = "com.android.test"; private static final long TEST_PROVIDER_ID = 1; private static final long TEST_PROVIDER_ID_2 = 2; private static final int TEST_CREATOR_UID = 1234; @@ -241,11 +242,11 @@ public class PasspointConfigUserStoreDataTest { // Setup expected data. List<PasspointProvider> providerList = new ArrayList<>(); providerList.add(new PasspointProvider(createFullPasspointConfiguration(), - mKeyStore, mSimAccessor, TEST_PROVIDER_ID, TEST_CREATOR_UID, + mKeyStore, mSimAccessor, TEST_PROVIDER_ID, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE, Arrays.asList(TEST_CA_CERTIFICATE_ALIAS), TEST_CLIENT_CERTIFICATE_ALIAS, TEST_CLIENT_PRIVATE_KEY_ALIAS, null, TEST_HAS_EVER_CONNECTED, TEST_SHARED)); providerList.add(new PasspointProvider(createFullPasspointConfiguration(), - mKeyStore, mSimAccessor, TEST_PROVIDER_ID_2, TEST_CREATOR_UID, + mKeyStore, mSimAccessor, TEST_PROVIDER_ID_2, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE, Arrays.asList(TEST_CA_CERTIFICATE_ALIAS, TEST_CA_CERTIFICATE_ALIAS_2), TEST_CLIENT_CERTIFICATE_ALIAS, TEST_CLIENT_PRIVATE_KEY_ALIAS, TEST_REMEDIATION_CA_CERTIFICATE_ALIAS, @@ -276,7 +277,7 @@ public class PasspointConfigUserStoreDataTest { /** * Verify that PasspointConfigUserStoreData is written to - * {@link WifiConfigStore#STORE_FILE_NAME_USER_GENERAL}. + * {@link WifiConfigStore#STORE_FILE_USER_GENERAL}. * * @throws Exception */ diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index 578a0153b..e7535b2fa 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -16,6 +16,8 @@ package com.android.server.wifi.hotspot2; +import static android.app.AppOpsManager.MODE_IGNORED; +import static android.app.AppOpsManager.OPSTR_CHANGE_WIFI_STATE; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_DEAUTH_IMMINENT; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_ICON; import static android.net.wifi.WifiManager.ACTION_PASSPOINT_SUBSCRIPTION_REMEDIATION; @@ -50,6 +52,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; +import android.app.AppOpsManager; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Icon; @@ -65,6 +68,7 @@ import android.net.wifi.hotspot2.OsuProvider; import android.net.wifi.hotspot2.PasspointConfiguration; import android.net.wifi.hotspot2.pps.Credential; import android.net.wifi.hotspot2.pps.HomeSp; +import android.os.Handler; import android.os.Looper; import android.os.UserHandle; import android.os.test.TestLooper; @@ -75,6 +79,7 @@ import android.util.Pair; import androidx.test.filters.SmallTest; import com.android.dx.mockito.inline.extended.ExtendedMockito; +import com.android.server.wifi.ClientModeImpl; import com.android.server.wifi.Clock; import com.android.server.wifi.FakeKeys; import com.android.server.wifi.IMSIParameter; @@ -82,6 +87,8 @@ import com.android.server.wifi.SIMAccessor; import com.android.server.wifi.ScanDetail; import com.android.server.wifi.WifiConfigManager; import com.android.server.wifi.WifiConfigStore; +import com.android.server.wifi.WifiConfigurationTestUtil; +import com.android.server.wifi.WifiInjector; import com.android.server.wifi.WifiKeyStore; import com.android.server.wifi.WifiMetrics; import com.android.server.wifi.WifiNative; @@ -122,6 +129,7 @@ import java.util.Set; @SmallTest public class PasspointManagerTest { private static final long BSSID = 0x112233445566L; + private static final String TEST_PACKAGE = "com.android.test"; private static final String ICON_FILENAME = "test"; private static final String TEST_FQDN = "test1.test.com"; private static final String TEST_FQDN2 = "test2.test.com"; @@ -173,9 +181,15 @@ public class PasspointManagerTest { @Mock IProvisioningCallback mCallback; @Mock WfaKeyStore mWfaKeyStore; @Mock KeyStore mKeyStore; + @Mock AppOpsManager mAppOpsManager; + @Mock WifiInjector mWifiInjector; + @Mock ClientModeImpl mClientModeImpl; + Handler mHandler; TestLooper mLooper; PasspointManager mManager; + ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor = + ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class); /** Sets up test. */ @Before @@ -194,8 +208,13 @@ public class PasspointManagerTest { when(mObjectFactory.makePasspointProvisioner(any(Context.class), any(WifiNative.class), any(PasspointManager.class), any(WifiMetrics.class))) .thenReturn(mPasspointProvisioner); - mManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, mWifiMetrics); + when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager); + when(mWifiInjector.getClientModeImpl()).thenReturn(mClientModeImpl); + mLooper = new TestLooper(); + mHandler = new Handler(mLooper.getLooper()); + mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, + mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, mWifiConfigManager, + mWifiConfigStore, mWifiMetrics); ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), @@ -210,7 +229,6 @@ public class PasspointManagerTest { mCallbacks = callbacks.getValue(); mSharedDataSource = sharedDataSource.getValue(); mUserDataSource = userDataSource.getValue(); - mLooper = new TestLooper(); } /** @@ -320,14 +338,15 @@ public class PasspointManagerTest { * * @return {@link PasspointProvider} */ - private PasspointProvider addTestProvider(String fqdn, String friendlyName) { + private PasspointProvider addTestProvider(String fqdn, String friendlyName, + String packageName) { PasspointConfiguration config = createTestConfigWithUserCredential(fqdn, friendlyName); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); - - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); - + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + provider); + when(provider.getPackageName()).thenReturn(packageName); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); return provider; } @@ -341,9 +360,10 @@ public class PasspointManagerTest { PasspointConfiguration config = createTestConfigWithSimCredential(fqdn, imsi, realm); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); return provider; } @@ -559,7 +579,7 @@ public class PasspointManagerTest { */ @Test public void addProviderWithNullConfig() throws Exception { - assertFalse(mManager.addOrUpdateProvider(null, TEST_CREATOR_UID)); + assertFalse(mManager.addOrUpdateProvider(null, TEST_CREATOR_UID, TEST_PACKAGE)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -571,7 +591,8 @@ public class PasspointManagerTest { */ @Test public void addProviderWithEmptyConfig() throws Exception { - assertFalse(mManager.addOrUpdateProvider(new PasspointConfiguration(), TEST_CREATOR_UID)); + assertFalse(mManager.addOrUpdateProvider(new PasspointConfiguration(), TEST_CREATOR_UID, + TEST_PACKAGE)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -588,7 +609,7 @@ public class PasspointManagerTest { TEST_FRIENDLY_NAME); // EAP-TLS not allowed for user credential. config.getCredential().getUserCredential().setEapType(EAPConstants.EAP_TLS); - assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -603,13 +624,17 @@ public class PasspointManagerTest { PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN, TEST_FRIENDLY_NAME); PasspointProvider provider = createMockProvider(config); + when(provider.getPackageName()).thenReturn(TEST_PACKAGE); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verifyInstalledConfig(config); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE), any( + AppOpsManager.OnOpChangedListener.class)); reset(mWifiMetrics); reset(mWifiConfigManager); @@ -626,6 +651,7 @@ public class PasspointManagerTest { verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess(); + verify(mAppOpsManager).stopWatchingMode(any(AppOpsManager.OnOpChangedListener.class)); assertTrue(mManager.getProviderConfigs().isEmpty()); // Verify content in the data source. @@ -645,8 +671,9 @@ public class PasspointManagerTest { TEST_REALM); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verifyInstalledConfig(config); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); @@ -689,8 +716,9 @@ public class PasspointManagerTest { TEST_REALM); PasspointProvider origProvider = createMockProvider(origConfig); when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(origProvider); - assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + origProvider); + assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE)); verifyInstalledConfig(origConfig); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); @@ -710,8 +738,9 @@ public class PasspointManagerTest { TEST_FRIENDLY_NAME); PasspointProvider newProvider = createMockProvider(newConfig); when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(newProvider); - assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + newProvider); + assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE)); verifyInstalledConfig(newConfig); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); @@ -737,8 +766,9 @@ public class PasspointManagerTest { PasspointProvider provider = mock(PasspointProvider.class); when(provider.installCertsAndKeys()).thenReturn(false); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); - assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + provider); + assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -754,7 +784,7 @@ public class PasspointManagerTest { TEST_FRIENDLY_NAME); doThrow(new GeneralSecurityException()) .when(mCertVerifier).verifyCaCert(any(X509Certificate.class)); - assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -772,8 +802,9 @@ public class PasspointManagerTest { config.setUpdateIdentifier(1); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( + provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verify(mCertVerifier, never()).verifyCaCert(any(X509Certificate.class)); verifyInstalledConfig(config); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); @@ -809,7 +840,7 @@ public class PasspointManagerTest { */ @Test public void matchProviderWithAnqpCacheMissed() throws Exception { - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); assertNull(mManager.matchProvider(createTestScanResult())); @@ -825,7 +856,7 @@ public class PasspointManagerTest { */ @Test public void matchProviderAsHomeProvider() throws Exception { - PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); @@ -844,7 +875,7 @@ public class PasspointManagerTest { */ @Test public void matchProviderAsRoamingProvider() throws Exception { - PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); @@ -863,7 +894,7 @@ public class PasspointManagerTest { */ @Test public void matchProviderWithNoMatch() throws Exception { - PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); ANQPData entry = new ANQPData(mClock, null); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); @@ -922,14 +953,17 @@ public class PasspointManagerTest { com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession().mockStatic( InformationElementUtil.class).startMocking(); try { - PasspointProvider providerHome = addTestProvider(TEST_FQDN + 0, TEST_FRIENDLY_NAME); + PasspointProvider providerHome = addTestProvider(TEST_FQDN + 0, TEST_FRIENDLY_NAME, + TEST_PACKAGE); WifiConfiguration homeWifiConfiguration = new WifiConfiguration(); homeWifiConfiguration.FQDN = TEST_FQDN + 0; homeWifiConfiguration.isHomeProviderNetwork = true; - PasspointProvider providerRoaming = addTestProvider(TEST_FQDN + 1, TEST_FRIENDLY_NAME); + PasspointProvider providerRoaming = addTestProvider(TEST_FQDN + 1, TEST_FRIENDLY_NAME, + TEST_PACKAGE); WifiConfiguration roamingWifiConfiguration = new WifiConfiguration(); roamingWifiConfiguration.FQDN = TEST_FQDN + 1; - PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME); + PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, + TEST_PACKAGE); ANQPData entry = new ANQPData(mClock, null); InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID2; @@ -973,13 +1007,15 @@ public class PasspointManagerTest { */ @Test public void getWifiConfigsForPasspointProfiles() { - PasspointProvider provider1 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider1 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); wifiConfiguration1.FQDN = TEST_FQDN; - PasspointProvider provider2 = addTestProvider(TEST_FQDN + 1, TEST_FRIENDLY_NAME); + PasspointProvider provider2 = addTestProvider(TEST_FQDN + 1, TEST_FRIENDLY_NAME, + TEST_PACKAGE); WifiConfiguration wifiConfiguration2 = new WifiConfiguration(); wifiConfiguration2.FQDN = TEST_FQDN + 1; - PasspointProvider provider3 = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME); + PasspointProvider provider3 = addTestProvider(TEST_FQDN + 2, TEST_FRIENDLY_NAME, + TEST_PACKAGE); WifiConfiguration wifiConfiguration3 = new WifiConfiguration(); wifiConfiguration3.FQDN = TEST_FQDN + 2; lenient().when(provider1.getWifiConfig()).thenReturn(wifiConfiguration1); @@ -1180,8 +1216,9 @@ public class PasspointManagerTest { */ @Test public void getMatchingPasspointConfigsForOsuProvidersWithMatch() { - PasspointProvider provider1 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); - PasspointProvider provider2 = addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2); + PasspointProvider provider1 = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); + PasspointProvider provider2 = addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, + TEST_PACKAGE); List<OsuProvider> osuProviders = new ArrayList<>(); Map<String, String> friendlyNames = new HashMap<>(); @@ -1208,8 +1245,8 @@ public class PasspointManagerTest { */ @Test public void getMatchingPasspointConfigsForOsuProvidersWitNoMatch() { - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); - addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); + addTestProvider(TEST_FQDN2, TEST_FRIENDLY_NAME2, TEST_PACKAGE); List<OsuProvider> osuProviders = new ArrayList<>(); @@ -1264,8 +1301,10 @@ public class PasspointManagerTest { PasspointProvider provider = createMockProvider(config); // Verify the provider ID used to create the new provider. when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), eq(providerIndex), eq(TEST_CREATOR_UID))).thenReturn(provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); + eq(mSimAccessor), eq(providerIndex), eq(TEST_CREATOR_UID), + eq(TEST_PACKAGE))).thenReturn(provider); + + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); verifyInstalledConfig(config); verify(mWifiConfigManager).saveToStore(true); reset(mWifiConfigManager); @@ -1507,7 +1546,7 @@ public class PasspointManagerTest { */ @Test public void providerNetworkConnectedFirstTime() throws Exception { - PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); when(provider.getHasEverConnected()).thenReturn(false); mManager.onPasspointNetworkConnected(TEST_FQDN); verify(provider).setHasEverConnected(eq(true)); @@ -1522,7 +1561,7 @@ public class PasspointManagerTest { */ @Test public void providerNetworkConnectedNotFirstTime() throws Exception { - PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); when(provider.getHasEverConnected()).thenReturn(true); mManager.onPasspointNetworkConnected(TEST_FQDN); verify(provider, never()).setHasEverConnected(anyBoolean()); @@ -1536,7 +1575,7 @@ public class PasspointManagerTest { */ @Test public void updateMetrics() { - PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); ArgumentCaptor<Map<String, PasspointProvider>> argCaptor = ArgumentCaptor.forClass( Map.class); // Provider have not provided a successful network connection. @@ -1588,10 +1627,9 @@ public class PasspointManagerTest { TelephonyManager telephonyManager = mock(TelephonyManager.class); when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager); when(telephonyManager.getSimOperator()).thenReturn("123456"); - PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative, - mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, - mWifiMetrics); + PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, + mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, + mWifiConfigManager, mWifiConfigStore, mWifiMetrics); assertNull(passpointManager.createEphemeralPasspointConfigForCarrier( EAPConstants.EAP_TLS)); @@ -1614,11 +1652,9 @@ public class PasspointManagerTest { when(TelephonyManager.from(any(Context.class))).thenReturn(telephonyManager); when(telephonyManager.getSimOperator()).thenReturn(mccmnc); when(telephonyManager.getSimOperatorName()).thenReturn("test"); - - PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative, - mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, - mWifiMetrics); + PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, + mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, + mWifiConfigManager, mWifiConfigStore, mWifiMetrics); PasspointConfiguration result = passpointManager.createEphemeralPasspointConfigForCarrier( @@ -1642,7 +1678,7 @@ public class PasspointManagerTest { PasspointConfiguration config = createTestConfigWithUserCredential("abc.com", "test"); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), anyInt())).thenReturn(provider); + eq(mSimAccessor), anyLong(), anyInt(), isNull())).thenReturn(provider); assertFalse(mManager.installEphemeralPasspointConfigForCarrier(config)); } @@ -1657,9 +1693,11 @@ public class PasspointManagerTest { TEST_REALM); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), anyInt())).thenReturn(provider); + eq(mSimAccessor), anyLong(), anyInt(), isNull())).thenReturn(provider); assertTrue(mManager.installEphemeralPasspointConfigForCarrier(config)); + verify(mAppOpsManager, never()).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), + eq(TEST_PACKAGE), any(AppOpsManager.OnOpChangedListener.class)); } /** @@ -1677,7 +1715,7 @@ public class PasspointManagerTest { */ @Test public void verifyHasProviderForCarrierWithNoMatch() { - addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); assertFalse(mManager.hasCarrierProvider(TEST_MCC_MNC)); } @@ -1714,11 +1752,9 @@ public class PasspointManagerTest { ANQPData anqpData = new ANQPData(mClock, anqpElementMapOfAp1); when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(anqpData); - PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative, - mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, - mWifiMetrics); - + PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, + mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, + mWifiConfigManager, mWifiConfigStore, mWifiMetrics); assertEquals(EAPConstants.EAP_AKA, passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails)); } finally { @@ -1743,10 +1779,9 @@ public class PasspointManagerTest { List<ScanDetail> scanDetails = new ArrayList<>(); scanDetails.add(generateScanDetail(TEST_SSID, TEST_BSSID_STRING, 0, 0, false)); - PasspointManager passpointManager = new PasspointManager(mContext, mWifiNative, - mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, - mWifiMetrics); + PasspointManager passpointManager = new PasspointManager(mContext, mWifiInjector, + mHandler, mWifiNative, mWifiKeyStore, mClock, mSimAccessor, mObjectFactory, + mWifiConfigManager, mWifiConfigStore, mWifiMetrics); assertEquals(-1, passpointManager.findEapMethodFromNAIRealmMatchedWithCarrier(scanDetails)); @@ -1754,4 +1789,33 @@ public class PasspointManagerTest { session.finishMocking(); } } + + /** + * Verify that the corresponding Passpoint provider is removed when the app is disabled. + */ + @Test + public void verifyRemovingPasspointProfilesWhenAppIsDisabled() { + WifiConfiguration currentConfiguration = WifiConfigurationTestUtil.createPasspointNetwork(); + currentConfiguration.FQDN = TEST_FQDN; + when(mClientModeImpl.getCurrentWifiConfiguration()).thenReturn(currentConfiguration); + addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, TEST_PACKAGE); + + verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE), + mAppOpChangedListenerCaptor.capture()); + assertEquals(1, mManager.getProviderConfigs().size()); + AppOpsManager.OnOpChangedListener listener = mAppOpChangedListenerCaptor.getValue(); + assertNotNull(listener); + + // Disallow change wifi state & ensure we remove the profiles from database. + when(mAppOpsManager.unsafeCheckOpNoThrow( + OPSTR_CHANGE_WIFI_STATE, TEST_CREATOR_UID, + TEST_PACKAGE)) + .thenReturn(MODE_IGNORED); + listener.onOpChanged(OPSTR_CHANGE_WIFI_STATE, TEST_PACKAGE); + mLooper.dispatchAll(); + + verify(mAppOpsManager).stopWatchingMode(mAppOpChangedListenerCaptor.getValue()); + verify(mClientModeImpl).disconnectCommand(); + assertTrue(mManager.getProviderConfigs().isEmpty()); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java index 0030c6435..31229c562 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java @@ -78,6 +78,7 @@ import java.util.Set; public class PasspointProviderTest { private static final long PROVIDER_ID = 12L; private static final int CREATOR_UID = 1234; + private static final String CREATOR_PACKAGE = "com.android.test"; private static final String CA_CERTIFICATE_NAME = "CACERT_HS2_12_0"; private static final String CA_CERTIFICATE_NAME_2 = "CACERT_HS2_12_1"; private static final String CLIENT_CERTIFICATE_NAME = "USRCERT_HS2_12"; @@ -124,7 +125,8 @@ public class PasspointProviderTest { * @return {@link com.android.server.wifi.hotspot2.PasspointProvider} */ private PasspointProvider createProvider(PasspointConfiguration config) { - return new PasspointProvider(config, mKeyStore, mSimAccessor, PROVIDER_ID, CREATOR_UID); + return new PasspointProvider(config, mKeyStore, mSimAccessor, PROVIDER_ID, CREATOR_UID, + CREATOR_PACKAGE); } /** |