summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-09 07:19:30 -0700
committerRoshan Pius <rpius@google.com>2019-10-10 01:48:55 +0000
commit9a99a8a4fcdc64c67f016f5a07ffae0792d5e5cf (patch)
tree416f0ed5642eefaf89aa9b9353db8b9330ef6f83 /tests/wifitests/src/com
parenta6d9c2bad258dfcfbf3f0c6359d12d6397b29df7 (diff)
downloadandroid_frameworks_opt_net_wifi-9a99a8a4fcdc64c67f016f5a07ffae0792d5e5cf.tar.gz
android_frameworks_opt_net_wifi-9a99a8a4fcdc64c67f016f5a07ffae0792d5e5cf.tar.bz2
android_frameworks_opt_net_wifi-9a99a8a4fcdc64c67f016f5a07ffae0792d5e5cf.zip
WifiService: Revert get/remove passpoint API deprecation
Allow apps to get/remove passpoint profiles installed by them. Privileged apps can continue to get/remove all profiles. Bug: 141639265 Test: atest com.android.server.wifi Change-Id: Id073c25a021dbeb81e87064e93ead966a363390e Merged-In: Id073c25a021dbeb81e87064e93ead966a363390e
Diffstat (limited to 'tests/wifitests/src/com')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java26
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java77
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java65
3 files changed, 95 insertions, 73 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 7896a8f0b..26c89adf9 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -1866,15 +1866,15 @@ public class ClientModeImplTest {
@Test
public void syncRemovePasspointConfig() throws Exception {
String fqdn = "test.com";
- when(mPasspointManager.removeProvider(fqdn)).thenReturn(true);
+ when(mPasspointManager.removeProvider(anyInt(), anyBoolean(), eq(fqdn))).thenReturn(true);
mLooper.startAutoDispatch();
- assertTrue(mCmi.syncRemovePasspointConfig(mCmiAsyncChannel, fqdn));
+ assertTrue(mCmi.syncRemovePasspointConfig(mCmiAsyncChannel, true, fqdn));
mLooper.stopAutoDispatch();
reset(mPasspointManager);
- when(mPasspointManager.removeProvider(fqdn)).thenReturn(false);
+ when(mPasspointManager.removeProvider(anyInt(), anyBoolean(), eq(fqdn))).thenReturn(false);
mLooper.startAutoDispatch();
- assertFalse(mCmi.syncRemovePasspointConfig(mCmiAsyncChannel, fqdn));
+ assertFalse(mCmi.syncRemovePasspointConfig(mCmiAsyncChannel, true, fqdn));
mLooper.stopAutoDispatch();
}
@@ -1902,16 +1902,17 @@ public class ClientModeImplTest {
config.setHomeSp(homeSp);
expectedConfigs.add(config);
- when(mPasspointManager.getProviderConfigs()).thenReturn(expectedConfigs);
+ when(mPasspointManager.getProviderConfigs(anyInt(), anyBoolean()))
+ .thenReturn(expectedConfigs);
mLooper.startAutoDispatch();
- assertEquals(expectedConfigs, mCmi.syncGetPasspointConfigs(mCmiAsyncChannel));
+ assertEquals(expectedConfigs, mCmi.syncGetPasspointConfigs(mCmiAsyncChannel, true));
mLooper.stopAutoDispatch();
reset(mPasspointManager);
- when(mPasspointManager.getProviderConfigs())
- .thenReturn(new ArrayList<PasspointConfiguration>());
+ when(mPasspointManager.getProviderConfigs(anyInt(), anyBoolean()))
+ .thenReturn(new ArrayList<>());
mLooper.startAutoDispatch();
- assertTrue(mCmi.syncGetPasspointConfigs(mCmiAsyncChannel).isEmpty());
+ assertTrue(mCmi.syncGetPasspointConfigs(mCmiAsyncChannel, true).isEmpty());
mLooper.stopAutoDispatch();
}
@@ -3544,14 +3545,15 @@ public class ClientModeImplTest {
@Test
public void testRemovePasspointConfig() throws Exception {
String fqdn = "test.com";
- when(mPasspointManager.removeProvider(anyString())).thenReturn(true);
+ when(mPasspointManager.removeProvider(anyInt(), anyBoolean(), anyString()))
+ .thenReturn(true);
// switch to connect mode and verify wifi is reported as enabled
startSupplicantAndDispatchMessages();
- mCmi.sendMessage(ClientModeImpl.CMD_REMOVE_PASSPOINT_CONFIG, fqdn);
+ mCmi.sendMessage(ClientModeImpl.CMD_REMOVE_PASSPOINT_CONFIG, TEST_UID, 0, fqdn);
mLooper.dispatchAll();
- verify(mWifiConfigManager).removePasspointConfiguredNetwork(eq(fqdn));
+ verify(mWifiConfigManager).removePasspointConfiguredNetwork(fqdn);
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 9a3bd75be..494d9011b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -174,6 +174,7 @@ public class WifiServiceImplTest {
private static final String WIFI_IFACE_NAME2 = "wlan1";
private static final String TEST_COUNTRY_CODE = "US";
private static final String TEST_FACTORY_MAC = "10:22:34:56:78:92";
+ private static final String TEST_FQDN = "testfqdn";
private static final List<WifiConfiguration> TEST_WIFI_CONFIGURATION_LIST = Arrays.asList(
WifiConfigurationTestUtil.generateWifiConfig(
0, 1000000, "\"red\"", true, true, null, null),
@@ -2788,77 +2789,53 @@ public class WifiServiceImplTest {
}
/**
- * Verify that the call to getPasspointConfigurations is not redirected to specific API
- * syncGetPasspointConfigs when the caller doesn't have NETWORK_SETTINGS permissions and
- * NETWORK_SETUP_WIZARD.
+ * Verify the call to getPasspointConfigurations when the caller doesn't have
+ * NETWORK_SETTINGS and NETWORK_SETUP_WIZARD permissions.
*/
- @Test(expected = SecurityException.class)
- public void testGetPasspointConfigurationsWithOutPermissions() {
+ public void testGetPasspointConfigurationsWithOutPrivilegedPermissions() {
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
when(mWifiPermissionsUtil.checkNetworkSetupWizardPermission(anyInt())).thenReturn(false);
mWifiServiceImpl.getPasspointConfigurations(TEST_PACKAGE_NAME);
+
+ verify(mClientModeImpl).syncGetPasspointConfigs(any(), eq(false));
}
/**
- * Verify that getPasspointConfigurations called by apps that has invalid package will
- * throw {@link SecurityException}.
+ * Verify that the call to getPasspointConfigurations when the caller does have
+ * NETWORK_SETTINGS permission.
*/
- @Test(expected = SecurityException.class)
- public void testGetPasspointConfigurationWithInvalidPackage() {
- doThrow(new SecurityException()).when(mAppOpsManager).checkPackage(anyInt(),
- eq(TEST_PACKAGE_NAME));
+ public void testGetPasspointConfigurationsWithPrivilegedPermissions() {
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
- when(mWifiPermissionsUtil.checkNetworkSetupWizardPermission(anyInt())).thenReturn(true);
mWifiServiceImpl.getPasspointConfigurations(TEST_PACKAGE_NAME);
- }
-
- /**
- * Verify that getPasspointConfigurations called by apps targeting below Q SDK will return
- * empty list if the caller doesn't have NETWORK_SETTINGS permissions and NETWORK_SETUP_WIZARD.
- */
- @Test
- public void testGetPasspointConfigurationForAppsTargetingBelowQSDK() {
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
- when(mWifiPermissionsUtil.checkNetworkSetupWizardPermission(anyInt())).thenReturn(false);
- when(mWifiPermissionsUtil.isTargetSdkLessThan(eq(TEST_PACKAGE_NAME),
- eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true);
- List<PasspointConfiguration> result = mWifiServiceImpl.getPasspointConfigurations(
- TEST_PACKAGE_NAME);
- assertNotNull(result);
- assertEquals(0, result.size());
+ verify(mClientModeImpl).syncGetPasspointConfigs(any(), eq(true));
}
/**
- * Verify that the call to removePasspointConfiguration is not redirected to specific API
- * syncRemovePasspointConfig when the caller doesn't have NETWORK_SETTINGS and
- * NETWORK_CARRIER_PROVISIONING permission.
+ * Verify the call to removePasspointConfigurations when the caller doesn't have
+ * NETWORK_SETTINGS and NETWORK_CARRIER_PROVISIONING permissions.
*/
- @Test(expected = SecurityException.class)
- public void testRemovePasspointConfigurationWithOutPermissions() {
+ public void testRemovePasspointConfigurationWithOutPrivilegedPermissions() {
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())).thenReturn(
false);
- mWifiServiceImpl.removePasspointConfiguration(null, null);
+ mWifiServiceImpl.removePasspointConfiguration(TEST_FQDN, TEST_PACKAGE_NAME);
+ verify(mClientModeImpl).syncRemovePasspointConfig(any(), eq(false), eq(TEST_FQDN));
}
/**
- * Verify that the call to removePasspointConfiguration for apps targeting below Q SDK will
- * return false if the caller doesn't have NETWORK_SETTINGS and NETWORK_CARRIER_PROVISIONING
- * permission.
+ * Verify the call to removePasspointConfigurations when the caller does have
+ * NETWORK_CARRIER_PROVISIONING permission.
*/
- @Test
- public void testRemovePasspointConfigurationForAppsTargetingBelowQSDK() {
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ public void testRemovePasspointConfigurationWithPrivilegedPermissions() {
when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())).thenReturn(
- false);
- when(mWifiPermissionsUtil.isTargetSdkLessThan(isNull(),
- eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true);
+ true);
- assertFalse(mWifiServiceImpl.removePasspointConfiguration(null, null));
+ mWifiServiceImpl.removePasspointConfiguration(TEST_FQDN, TEST_PACKAGE_NAME);
+ verify(mClientModeImpl).syncRemovePasspointConfig(any(), eq(true), eq(TEST_FQDN));
}
/**
@@ -3650,13 +3627,14 @@ public class WifiServiceImplTest {
mWifiServiceImpl.mClientModeImplChannel = mAsyncChannel;
when(mClientModeImpl.syncGetConfiguredNetworks(anyInt(), any(), anyInt()))
.thenReturn(Arrays.asList(network));
- when(mClientModeImpl.syncGetPasspointConfigs(any())).thenReturn(Arrays.asList(config));
+ when(mClientModeImpl.syncGetPasspointConfigs(any(), anyBoolean()))
+ .thenReturn(Arrays.asList(config));
mWifiServiceImpl.factoryReset(TEST_PACKAGE_NAME);
mLooper.dispatchAll();
verify(mClientModeImpl).syncRemoveNetwork(mAsyncChannel, network.networkId);
- verify(mClientModeImpl).syncRemovePasspointConfig(mAsyncChannel, fqdn);
+ verify(mClientModeImpl).syncRemovePasspointConfig(mAsyncChannel, true, fqdn);
verify(mWifiConfigManager).clearDeletedEphemeralNetworks();
verify(mClientModeImpl).clearNetworkRequestUserApprovedAccessPoints();
verify(mWifiNetworkSuggestionsManager).clear();
@@ -3679,8 +3657,9 @@ public class WifiServiceImplTest {
mLooper.dispatchAll();
verify(mClientModeImpl).syncGetConfiguredNetworks(anyInt(), any(), anyInt());
- verify(mClientModeImpl, never()).syncGetPasspointConfigs(any());
- verify(mClientModeImpl, never()).syncRemovePasspointConfig(any(), anyString());
+ verify(mClientModeImpl, never()).syncGetPasspointConfigs(any(), anyBoolean());
+ verify(mClientModeImpl, never()).syncRemovePasspointConfig(
+ any(), anyBoolean(), anyString());
verify(mWifiConfigManager).clearDeletedEphemeralNetworks();
verify(mClientModeImpl).clearNetworkRequestUserApprovedAccessPoints();
verify(mWifiNetworkSuggestionsManager).clear();
@@ -3703,7 +3682,7 @@ public class WifiServiceImplTest {
} catch (SecurityException e) {
}
verify(mClientModeImpl, never()).syncGetConfiguredNetworks(anyInt(), any(), anyInt());
- verify(mClientModeImpl, never()).syncGetPasspointConfigs(any());
+ verify(mClientModeImpl, never()).syncGetPasspointConfigs(any(), eq(false));
}
/**
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 338f7bc40..131425af8 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -268,7 +268,8 @@ public class PasspointManagerTest {
* @param expectedConfig The expected installed Passpoint configuration
*/
private void verifyInstalledConfig(PasspointConfiguration expectedConfig) {
- List<PasspointConfiguration> installedConfigs = mManager.getProviderConfigs();
+ List<PasspointConfiguration> installedConfigs =
+ mManager.getProviderConfigs(TEST_CREATOR_UID, true);
assertEquals(1, installedConfigs.size());
assertEquals(expectedConfig, installedConfigs.get(0));
}
@@ -283,6 +284,7 @@ public class PasspointManagerTest {
PasspointProvider provider = mock(PasspointProvider.class);
when(provider.installCertsAndKeys()).thenReturn(true);
lenient().when(provider.getConfig()).thenReturn(config);
+ lenient().when(provider.getCreatorUid()).thenReturn(TEST_CREATOR_UID);
return provider;
}
@@ -651,14 +653,14 @@ public class PasspointManagerTest {
// Provider index start with 0, should be 1 after adding a provider.
assertEquals(1, mSharedDataSource.getProviderIndex());
- // Remove the provider.
- assertTrue(mManager.removeProvider(TEST_FQDN));
+ // Remove the provider as the creator app.
+ assertTrue(mManager.removeProvider(TEST_CREATOR_UID, false, TEST_FQDN));
verify(provider).uninstallCertsAndKeys();
verify(mWifiConfigManager).saveToStore(true);
verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess();
verify(mAppOpsManager).stopWatchingMode(any(AppOpsManager.OnOpChangedListener.class));
- assertTrue(mManager.getProviderConfigs().isEmpty());
+ assertTrue(mManager.getProviderConfigs(TEST_CREATOR_UID, false).isEmpty());
// Verify content in the data source.
assertTrue(mUserDataSource.getProviders().isEmpty());
@@ -694,13 +696,13 @@ public class PasspointManagerTest {
// Provider index start with 0, should be 1 after adding a provider.
assertEquals(1, mSharedDataSource.getProviderIndex());
- // Remove the provider.
- assertTrue(mManager.removeProvider(TEST_FQDN));
+ // Remove the provider as a privileged non-creator app.
+ assertTrue(mManager.removeProvider(TEST_UID, true, TEST_FQDN));
verify(provider).uninstallCertsAndKeys();
verify(mWifiConfigManager).saveToStore(true);
verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess();
- assertTrue(mManager.getProviderConfigs().isEmpty());
+ assertTrue(mManager.getProviderConfigs(TEST_UID, true).isEmpty());
// Verify content in the data source.
assertTrue(mUserDataSource.getProviders().isEmpty());
@@ -824,7 +826,7 @@ public class PasspointManagerTest {
*/
@Test
public void removeNonExistingProvider() throws Exception {
- assertFalse(mManager.removeProvider(TEST_FQDN));
+ assertFalse(mManager.removeProvider(TEST_CREATOR_UID, true, TEST_FQDN));
verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess();
}
@@ -1285,8 +1287,8 @@ public class PasspointManagerTest {
mUserDataSource.setProviders(providers);
// Verify the providers maintained by PasspointManager.
- assertEquals(1, mManager.getProviderConfigs().size());
- assertEquals(config, mManager.getProviderConfigs().get(0));
+ assertEquals(1, mManager.getProviderConfigs(TEST_CREATOR_UID, true).size());
+ assertEquals(config, mManager.getProviderConfigs(TEST_CREATOR_UID, true).get(0));
}
/**
@@ -1800,7 +1802,7 @@ public class PasspointManagerTest {
verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE),
mAppOpChangedListenerCaptor.capture());
- assertEquals(1, mManager.getProviderConfigs().size());
+ assertEquals(1, mManager.getProviderConfigs(TEST_CREATOR_UID, true).size());
AppOpsManager.OnOpChangedListener listener = mAppOpChangedListenerCaptor.getValue();
assertNotNull(listener);
@@ -1814,6 +1816,45 @@ public class PasspointManagerTest {
verify(mAppOpsManager).stopWatchingMode(mAppOpChangedListenerCaptor.getValue());
verify(mClientModeImpl).disconnectCommand();
- assertTrue(mManager.getProviderConfigs().isEmpty());
+ assertTrue(mManager.getProviderConfigs(TEST_CREATOR_UID, true).isEmpty());
+ }
+
+ /**
+ * Verify that removing a provider with a different UID will not succeed.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void removeGetProviderWithDifferentUid() throws Exception {
+ PasspointConfiguration config = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI,
+ TEST_REALM);
+ PasspointProvider provider = createMockProvider(config);
+ when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
+ 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();
+ reset(mWifiMetrics);
+ reset(mWifiConfigManager);
+
+ // no profiles available for TEST_UID
+ assertTrue(mManager.getProviderConfigs(TEST_UID, false).isEmpty());
+ // 1 profile available for TEST_CREATOR_UID
+ assertFalse(mManager.getProviderConfigs(TEST_CREATOR_UID, false).isEmpty());
+
+ // Remove the provider as a non-privileged non-creator app.
+ assertFalse(mManager.removeProvider(TEST_UID, false, TEST_FQDN));
+ verify(provider, never()).uninstallCertsAndKeys();
+ verify(mWifiConfigManager, never()).saveToStore(true);
+ verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
+ verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess();
+
+ // no profiles available for TEST_UID
+ assertTrue(mManager.getProviderConfigs(TEST_UID, false).isEmpty());
+ // 1 profile available for TEST_CREATOR_UID
+ assertFalse(mManager.getProviderConfigs(TEST_CREATOR_UID, false).isEmpty());
}
}