summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEcco Park <eccopark@google.com>2019-05-04 15:40:13 -0700
committerEcco Park <eccopark@google.com>2019-05-06 13:17:24 -0700
commit353e8733c58131f4f78e63f2adb6a4f6379a1d59 (patch)
treee8579762d47b3cf68dae2e02655b9d597798a584
parent63dec560c331910d929f618add9e913601f2e675 (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>
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java27
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java9
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java13
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointManager.java176
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java7
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointProvider.java19
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java10
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java26
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java7
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java196
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java4
12 files changed, 363 insertions, 134 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 6ba2debe9..c0ff441a7 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -159,6 +159,9 @@ public class ClientModeImpl extends StateMachine {
private static final String EXTRA_OSU_ICON_QUERY_BSSID = "BSSID";
private static final String EXTRA_OSU_ICON_QUERY_FILENAME = "FILENAME";
private static final String EXTRA_OSU_PROVIDER = "OsuProvider";
+ private static final String EXTRA_UID = "uid";
+ private static final String EXTRA_PACKAGE_NAME = "PackageName";
+ private static final String EXTRA_PASSPOINT_CONFIGURATION = "PasspointConfiguration";
private static final int IPCLIENT_TIMEOUT_MS = 10_000;
private boolean mVerboseLoggingEnabled = false;
@@ -1752,12 +1755,17 @@ public class ClientModeImpl extends StateMachine {
*
* @param channel Channel for communicating with the state machine
* @param config The configuration to add or update
+ * @param packageName Package name of the app adding/updating {@code config}.
* @return true on success
*/
public boolean syncAddOrUpdatePasspointConfig(AsyncChannel channel,
- PasspointConfiguration config, int uid) {
+ PasspointConfiguration config, int uid, String packageName) {
+ Bundle bundle = new Bundle();
+ bundle.putInt(EXTRA_UID, uid);
+ bundle.putString(EXTRA_PACKAGE_NAME, packageName);
+ bundle.putParcelable(EXTRA_PASSPOINT_CONFIGURATION, config);
Message resultMsg = channel.sendMessageSynchronously(CMD_ADD_OR_UPDATE_PASSPOINT_CONFIG,
- uid, 0, config);
+ bundle);
if (messageIsNull(resultMsg)) return false;
boolean result = (resultMsg.arg1 == SUCCESS);
resultMsg.recycle();
@@ -3661,8 +3669,11 @@ public class ClientModeImpl extends StateMachine {
replyToMessage(message, message.what);
break;
case CMD_ADD_OR_UPDATE_PASSPOINT_CONFIG:
- int addResult = mPasspointManager.addOrUpdateProvider(
- (PasspointConfiguration) message.obj, message.arg1)
+ Bundle bundle = (Bundle) message.obj;
+ int addResult = mPasspointManager.addOrUpdateProvider(bundle.getParcelable(
+ EXTRA_PASSPOINT_CONFIGURATION),
+ bundle.getInt(EXTRA_UID),
+ bundle.getString(EXTRA_PACKAGE_NAME))
? SUCCESS : FAILURE;
replyToMessage(message, message.what, addResult);
break;
@@ -4502,8 +4513,12 @@ public class ClientModeImpl extends StateMachine {
replyToMessage(message, message.what, 0);
break;
case CMD_ADD_OR_UPDATE_PASSPOINT_CONFIG:
- PasspointConfiguration passpointConfig = (PasspointConfiguration) message.obj;
- if (mPasspointManager.addOrUpdateProvider(passpointConfig, message.arg1)) {
+ Bundle bundle = (Bundle) message.obj;
+ PasspointConfiguration passpointConfig = bundle.getParcelable(
+ EXTRA_PASSPOINT_CONFIGURATION);
+ if (mPasspointManager.addOrUpdateProvider(passpointConfig,
+ bundle.getInt(EXTRA_UID),
+ bundle.getString(EXTRA_PACKAGE_NAME))) {
String fqdn = passpointConfig.getHomeSp().getFqdn();
if (isProviderOwnedNetwork(mTargetNetworkId, fqdn)
|| isProviderOwnedNetwork(mLastNetworkId, fqdn)) {
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 705ce41ba..02a835673 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -275,7 +275,8 @@ public class WifiInjector {
mCarrierNetworkEvaluator = new CarrierNetworkEvaluator(mWifiConfigManager,
mCarrierNetworkConfig, mConnectivityLocalLog, this);
mSimAccessor = new SIMAccessor(mContext);
- mPasspointManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock,
+ mPasspointManager = new PasspointManager(mContext, this,
+ new Handler(mWifiCoreHandlerThread.getLooper()), mWifiNative, mWifiKeyStore, mClock,
mSimAccessor, new PasspointObjectFactory(), mWifiConfigManager, mWifiConfigStore,
mWifiMetrics);
mPasspointNetworkEvaluator = new PasspointNetworkEvaluator(
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 2a28be7f2..66bf8855c 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2295,7 +2295,7 @@ public class WifiServiceImpl extends BaseWifiService {
return false;
}
return mClientModeImpl.syncAddOrUpdatePasspointConfig(mClientModeImplChannel, config,
- Binder.getCallingUid());
+ Binder.getCallingUid(), packageName);
}
/**
@@ -2706,12 +2706,19 @@ public class WifiServiceImpl extends BaseWifiService {
}
String pkgName = uri.getSchemeSpecificPart();
mClientModeImpl.removeAppConfigs(pkgName, uid);
+
// Call the method in ClientModeImpl thread.
mWifiInjector.getClientModeImplHandler().post(() -> {
mScanRequestProxy.clearScanRequestTimestampsForApp(pkgName, uid);
+
// Remove all suggestions from the package.
mWifiNetworkSuggestionsManager.removeApp(pkgName);
mClientModeImpl.removeNetworkRequestUserApprovedAccessPointsForApp(pkgName);
+
+ // Remove all Passpoint profiles from package.
+ mWifiInjector.getPasspointManager().removePasspointProviderWithPackage(
+ pkgName);
+
});
}
}
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java
index d0bd6ba5d..0114cfb21 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java
@@ -62,6 +62,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
private static final String XML_TAG_PROVIDER_ID = "ProviderID";
private static final String XML_TAG_CREATOR_UID = "CreatorUID";
+ private static final String XML_TAG_PACKAGE_NAME = "PackageName";
private static final String XML_TAG_CA_CERTIFICATE_ALIASES = "CaCertificateAliases";
private static final String XML_TAG_CA_CERTIFICATE_ALIAS = "CaCertificateAlias";
private static final String XML_TAG_CLIENT_CERTIFICATE_ALIAS = "ClientCertificateAlias";
@@ -189,6 +190,9 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_PASSPOINT_PROVIDER);
XmlUtil.writeNextValue(out, XML_TAG_PROVIDER_ID, provider.getProviderId());
XmlUtil.writeNextValue(out, XML_TAG_CREATOR_UID, provider.getCreatorUid());
+ if (provider.getPackageName() != null) {
+ XmlUtil.writeNextValue(out, XML_TAG_PACKAGE_NAME, provider.getPackageName());
+ }
XmlUtil.writeNextValue(out, XML_TAG_CA_CERTIFICATE_ALIASES,
provider.getCaCertificateAliases());
XmlUtil.writeNextValue(out, XML_TAG_CLIENT_CERTIFICATE_ALIAS,
@@ -266,6 +270,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
String clientCertificateAlias = null;
String clientPrivateKeyAlias = null;
String remediationCaCertificateAlias = null;
+ String packageName = null;
boolean hasEverConnected = false;
boolean shared = false;
PasspointConfiguration config = null;
@@ -281,6 +286,9 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
case XML_TAG_CREATOR_UID:
creatorUid = (int) value;
break;
+ case XML_TAG_PACKAGE_NAME:
+ packageName = (String) value;
+ break;
case XML_TAG_CA_CERTIFICATE_ALIASES:
caCertificateAliases = (List) value;
break;
@@ -330,9 +338,8 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
throw new XmlPullParserException("Missing Passpoint configuration");
}
return new PasspointProvider(config, mKeyStore, mSimAccessor, providerId, creatorUid,
- caCertificateAliases, clientCertificateAlias, clientPrivateKeyAlias,
- remediationCaCertificateAlias,
- hasEverConnected, shared);
+ packageName, caCertificateAliases, clientCertificateAlias, clientPrivateKeyAlias,
+ remediationCaCertificateAlias, hasEverConnected, shared);
}
}
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
index ad5cd749e..020beaed2 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
@@ -16,6 +16,7 @@
package com.android.server.wifi.hotspot2;
+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;
@@ -29,7 +30,9 @@ import static android.net.wifi.WifiManager.EXTRA_URL;
import static com.android.server.wifi.hotspot2.Utils.isCarrierEapMethod;
+import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Icon;
@@ -42,6 +45,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.Process;
import android.os.UserHandle;
@@ -56,6 +60,7 @@ 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.WifiInjector;
import com.android.server.wifi.WifiKeyStore;
import com.android.server.wifi.WifiMetrics;
import com.android.server.wifi.WifiNative;
@@ -75,6 +80,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
/**
* This class provides the APIs to manage Passpoint provider configurations.
@@ -105,10 +111,13 @@ public class PasspointManager {
*/
private static PasspointManager sPasspointManager;
- private final PasspointEventHandler mHandler;
+ private final PasspointEventHandler mPasspointEventHandler;
+ private final WifiInjector mWifiInjector;
+ private final Handler mHandler;
private final SIMAccessor mSimAccessor;
private final WifiKeyStore mKeyStore;
private final PasspointObjectFactory mObjectFactory;
+
private final Map<String, PasspointProvider> mProviders;
private final AnqpCache mAnqpCache;
private final ANQPRequestManager mAnqpRequestManager;
@@ -117,6 +126,12 @@ public class PasspointManager {
private final WifiMetrics mWifiMetrics;
private final PasspointProvisioner mPasspointProvisioner;
private final TelephonyManager mTelephonyManager;
+ private final AppOpsManager mAppOps;
+
+ /**
+ * Map of package name of an app to the app ops changed listener for the app.
+ */
+ private final Map<String, AppOpsChangedListener> mAppOpsChangedListenerPerApp = new HashMap<>();
// Counter used for assigning unique identifier to each provider.
private long mProviderIndex;
@@ -200,6 +215,10 @@ public class PasspointManager {
mProviders.clear();
for (PasspointProvider provider : providers) {
mProviders.put(provider.getConfig().getHomeSp().getFqdn(), provider);
+ if (provider.getPackageName() != null) {
+ startTrackingAppOpsChange(provider.getPackageName(),
+ provider.getCreatorUid());
+ }
}
}
}
@@ -220,18 +239,110 @@ public class PasspointManager {
}
}
- public PasspointManager(Context context, WifiNative wifiNative, WifiKeyStore keyStore,
- Clock clock, SIMAccessor simAccessor, PasspointObjectFactory objectFactory,
- WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore,
+ /**
+ * Listener for app-ops changes for apps to remove the corresponding Passpoint profiles.
+ */
+ private final class AppOpsChangedListener implements AppOpsManager.OnOpChangedListener {
+ private final String mPackageName;
+ private final int mUid;
+
+ AppOpsChangedListener(@NonNull String packageName, int uid) {
+ mPackageName = packageName;
+ mUid = uid;
+ }
+
+ @Override
+ public void onOpChanged(String op, String packageName) {
+ mHandler.post(() -> {
+ if (!mPackageName.equals(packageName)) return;
+ if (!OPSTR_CHANGE_WIFI_STATE.equals(op)) return;
+
+ // Ensures the uid to package mapping is still correct.
+ try {
+ mAppOps.checkPackage(mUid, mPackageName);
+ } catch (SecurityException e) {
+ Log.wtf(TAG, "Invalid uid/package" + packageName);
+ return;
+ }
+ if (mAppOps.unsafeCheckOpNoThrow(OPSTR_CHANGE_WIFI_STATE, mUid, mPackageName)
+ == AppOpsManager.MODE_IGNORED) {
+ Log.i(TAG, "User disallowed change wifi state for " + packageName);
+
+ // Removes the profiles installed by the app from database.
+ removePasspointProviderWithPackage(mPackageName);
+ }
+ });
+ }
+ }
+
+ /**
+ * Remove all Passpoint profiles installed by the app that has been disabled or uninstalled.
+ *
+ * @param packageName Package name of the app to remove the corresponding Passpoint profiles.
+ */
+ public void removePasspointProviderWithPackage(@NonNull String packageName) {
+ stopTrackingAppOpsChange(packageName);
+ for (Map.Entry<String, PasspointProvider> entry : getPasspointProviderWithPackage(
+ packageName).entrySet()) {
+ String fqdn = entry.getValue().getConfig().getHomeSp().getFqdn();
+ removeProvider(fqdn);
+ disconnectIfPasspointNetwork(fqdn);
+ }
+ }
+
+ private Map<String, PasspointProvider> getPasspointProviderWithPackage(
+ @NonNull String packageName) {
+ return mProviders.entrySet().stream().filter(
+ entry -> TextUtils.equals(packageName,
+ entry.getValue().getPackageName())).collect(
+ Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
+ }
+
+ private void startTrackingAppOpsChange(@NonNull String packageName, int uid) {
+ // The package is already registered.
+ if (mAppOpsChangedListenerPerApp.containsKey(packageName)) return;
+ AppOpsChangedListener appOpsChangedListener = new AppOpsChangedListener(packageName, uid);
+ mAppOps.startWatchingMode(OPSTR_CHANGE_WIFI_STATE, packageName, appOpsChangedListener);
+ mAppOpsChangedListenerPerApp.put(packageName, appOpsChangedListener);
+ }
+
+ private void stopTrackingAppOpsChange(@NonNull String packageName) {
+ AppOpsChangedListener appOpsChangedListener = mAppOpsChangedListenerPerApp.remove(
+ packageName);
+ if (appOpsChangedListener == null) {
+ Log.wtf(TAG, "No app ops listener found for " + packageName);
+ return;
+ }
+ mAppOps.stopWatchingMode(appOpsChangedListener);
+ }
+
+ private void disconnectIfPasspointNetwork(String fqdn) {
+ WifiConfiguration currentConfiguration =
+ mWifiInjector.getClientModeImpl().getCurrentWifiConfiguration();
+ if (currentConfiguration == null) return;
+ if (currentConfiguration.isPasspoint() && TextUtils.equals(currentConfiguration.FQDN,
+ fqdn)) {
+ Log.i(TAG, "Disconnect current Passpoint network for " + fqdn
+ + "because the profile was removed");
+ mWifiInjector.getClientModeImpl().disconnectCommand();
+ }
+ }
+
+ public PasspointManager(Context context, WifiInjector wifiInjector, Handler handler,
+ WifiNative wifiNative, WifiKeyStore keyStore, Clock clock, SIMAccessor simAccessor,
+ PasspointObjectFactory objectFactory, WifiConfigManager wifiConfigManager,
+ WifiConfigStore wifiConfigStore,
WifiMetrics wifiMetrics) {
- mHandler = objectFactory.makePasspointEventHandler(wifiNative,
+ mPasspointEventHandler = objectFactory.makePasspointEventHandler(wifiNative,
new CallbackHandler(context));
+ mWifiInjector = wifiInjector;
+ mHandler = handler;
mKeyStore = keyStore;
mSimAccessor = simAccessor;
mObjectFactory = objectFactory;
mProviders = new HashMap<>();
mAnqpCache = objectFactory.makeAnqpCache(clock);
- mAnqpRequestManager = objectFactory.makeANQPRequestManager(mHandler, clock);
+ mAnqpRequestManager = objectFactory.makeANQPRequestManager(mPasspointEventHandler, clock);
mCertVerifier = objectFactory.makeCertificateVerifier();
mWifiConfigManager = wifiConfigManager;
mWifiMetrics = wifiMetrics;
@@ -243,6 +354,7 @@ public class PasspointManager {
new SharedDataSourceHandler()));
mPasspointProvisioner = objectFactory.makePasspointProvisioner(context, wifiNative,
this, wifiMetrics);
+ mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
sPasspointManager = this;
}
@@ -270,9 +382,10 @@ public class PasspointManager {
* a provider with the new configuration will replace the existing provider.
*
* @param config Configuration of the Passpoint provider to be added
+ * @param packageName Package name of the app adding/Updating {@code config}
* @return true if provider is added, false otherwise
*/
- public boolean addOrUpdateProvider(PasspointConfiguration config, int uid) {
+ public boolean addOrUpdateProvider(PasspointConfiguration config, int uid, String packageName) {
mWifiMetrics.incrementNumPasspointProviderInstallation();
if (config == null) {
Log.e(TAG, "Configuration not provided");
@@ -302,7 +415,7 @@ public class PasspointManager {
// Create a provider and install the necessary certificates and keys.
PasspointProvider newProvider = mObjectFactory.makePasspointProvider(
- config, mKeyStore, mSimAccessor, mProviderIndex++, uid);
+ config, mKeyStore, mSimAccessor, mProviderIndex++, uid, packageName);
if (!newProvider.installCertsAndKeys()) {
Log.e(TAG, "Failed to install certificates and keys to keystore");
@@ -315,9 +428,11 @@ public class PasspointManager {
mProviders.get(config.getHomeSp().getFqdn()).uninstallCertsAndKeys();
mProviders.remove(config.getHomeSp().getFqdn());
}
-
mProviders.put(config.getHomeSp().getFqdn(), newProvider);
mWifiConfigManager.saveToStore(true /* forceWrite */);
+ if (newProvider.getPackageName() != null) {
+ startTrackingAppOpsChange(newProvider.getPackageName(), uid);
+ }
Log.d(TAG, "Added/updated Passpoint configuration: " + config.getHomeSp().getFqdn()
+ " by " + uid);
mWifiMetrics.incrementNumPasspointProviderInstallSuccess();
@@ -477,7 +592,7 @@ public class PasspointManager {
/**
* Installs a {@link PasspointConfiguration} created for auto connection with EAP-SIM/AKA/AKA'.
*
- * It install the Passpoint configuration created on runtime when the (MCC/MNC) of carrier that
+ * It installs the Passpoint configuration created on runtime when the (MCC/MNC) of carrier that
* supports encrypted IMSI is matched with one of ScanResults
*
* @param config the Passpoint Configuration to connect the AP with EAP-SIM/AKA/AKA'
@@ -492,7 +607,6 @@ public class PasspointManager {
Log.e(TAG, "Sim is not presented on the device");
return false;
}
-
Credential.SimCredential simCredential = config.getCredential().getSimCredential();
if (simCredential == null || simCredential.getImsi() == null) {
Log.e(TAG, "This is not for a carrier configuration using EAP-SIM/AKA/AKA'");
@@ -503,19 +617,16 @@ public class PasspointManager {
"It is not a valid format for Passpoint Configuration with EAP-SIM/AKA/AKA'");
return false;
}
-
String imsi = simCredential.getImsi();
if (imsi.length() < IMSIParameter.MCC_MNC_LENGTH) {
Log.e(TAG, "Invalid IMSI length: " + imsi.length());
return false;
}
-
int index = imsi.indexOf("*");
if (index == -1) {
Log.e(TAG, "missing * in imsi");
return false;
}
-
if (hasCarrierProvider(imsi.substring(0, index))) {
Log.e(TAG, "It is already in the Provider list");
return false;
@@ -523,12 +634,10 @@ public class PasspointManager {
// Create a provider and install the necessary certificates and keys.
PasspointProvider newProvider = mObjectFactory.makePasspointProvider(
- config, mKeyStore, mSimAccessor, mProviderIndex++, Process.WIFI_UID);
+ config, mKeyStore, mSimAccessor, mProviderIndex++, Process.WIFI_UID, null);
newProvider.setEphemeral(true);
-
Log.d(TAG, "installed PasspointConfiguration for carrier : "
+ config.getHomeSp().getFriendlyName());
-
mProviders.put(config.getHomeSp().getFqdn(), newProvider);
mWifiConfigManager.saveToStore(true /* forceWrite */);
return true;
@@ -542,15 +651,21 @@ public class PasspointManager {
*/
public boolean removeProvider(String fqdn) {
mWifiMetrics.incrementNumPasspointProviderUninstallation();
+ String packageName;
if (!mProviders.containsKey(fqdn)) {
Log.e(TAG, "Config doesn't exist");
return false;
}
-
mProviders.get(fqdn).uninstallCertsAndKeys();
+ packageName = mProviders.get(fqdn).getPackageName();
mProviders.remove(fqdn);
-
mWifiConfigManager.saveToStore(true /* forceWrite */);
+
+ // Stop monitoring the package if there is no Passpoint profile installed by the package.
+ if (mAppOpsChangedListenerPerApp.containsKey(packageName)
+ && getPasspointProviderWithPackage(packageName).size() == 0) {
+ stopTrackingAppOpsChange(packageName);
+ }
Log.d(TAG, "Removed Passpoint configuration: " + fqdn);
mWifiMetrics.incrementNumPasspointProviderUninstallSuccess();
return true;
@@ -603,7 +718,6 @@ public class PasspointManager {
if (allMatches == null) {
return null;
}
-
Pair<PasspointProvider, PasspointMatch> bestMatch = null;
for (Pair<PasspointProvider, PasspointMatch> match : allMatches) {
if (match.second == PasspointMatch.HomeProvider) {
@@ -614,7 +728,6 @@ public class PasspointManager {
bestMatch = match;
}
}
-
if (bestMatch != null) {
Log.d(TAG, String.format("Matched %s to %s as %s", scanResult.SSID,
bestMatch.first.getConfig().getHomeSp().getFqdn(),
@@ -656,7 +769,6 @@ public class PasspointManager {
ANQPNetworkKey anqpKey = ANQPNetworkKey.buildKey(scanResult.SSID, bssid, scanResult.hessid,
vsa.anqpDomainID);
ANQPData anqpEntry = mAnqpCache.getEntry(anqpKey);
-
if (anqpEntry == null) {
mAnqpRequestManager.requestANQPElements(bssid, anqpKey,
roamingConsortium.anqpOICount > 0,
@@ -664,16 +776,15 @@ public class PasspointManager {
Log.d(TAG, "ANQP entry not found for: " + anqpKey);
return allMatches;
}
-
for (Map.Entry<String, PasspointProvider> entry : mProviders.entrySet()) {
PasspointProvider provider = entry.getValue();
- PasspointMatch matchStatus = provider.match(anqpEntry.getElements(), roamingConsortium);
+ PasspointMatch matchStatus = provider.match(anqpEntry.getElements(),
+ roamingConsortium);
if (matchStatus == PasspointMatch.HomeProvider
|| matchStatus == PasspointMatch.RoamingProvider) {
allMatches.add(Pair.create(provider, matchStatus));
}
}
-
if (allMatches.size() != 0) {
for (Pair<PasspointProvider, PasspointMatch> match : allMatches) {
Log.d(TAG, String.format("Matched %s to %s as %s", scanResult.SSID,
@@ -686,7 +797,6 @@ public class PasspointManager {
Log.d(TAG, "No service providers found for " + scanResult.SSID);
}
}
-
return allMatches;
}
@@ -723,7 +833,7 @@ public class PasspointManager {
* will no longer be the case once we switch over to use wificond.
*/
public void notifyANQPDone(AnqpEvent anqpEvent) {
- mHandler.notifyANQPDone(anqpEvent);
+ mPasspointEventHandler.notifyANQPDone(anqpEvent);
}
/**
@@ -732,7 +842,7 @@ public class PasspointManager {
* will no longer be the case once we switch over to use wificond.
*/
public void notifyIconDone(IconEvent iconEvent) {
- mHandler.notifyIconDone(iconEvent);
+ mPasspointEventHandler.notifyIconDone(iconEvent);
}
/**
@@ -741,7 +851,7 @@ public class PasspointManager {
* will no longer be the case once we switch over to use wificond.
*/
public void receivedWnmFrame(WnmData data) {
- mHandler.notifyWnmFrameReceived(data);
+ mPasspointEventHandler.notifyWnmFrameReceived(data);
}
/**
@@ -749,7 +859,7 @@ public class PasspointManager {
* @return true if the request is sent successfully, false otherwise
*/
public boolean queryPasspointIcon(long bssid, String fileName) {
- return mHandler.requestIcon(bssid, fileName);
+ return mPasspointEventHandler.requestIcon(bssid, fileName);
}
/**
@@ -923,8 +1033,7 @@ public class PasspointManager {
Set<String> fqdnSet = new HashSet<>();
fqdnSet.addAll(fqdnList);
List<WifiConfiguration> configs = new ArrayList<>();
-
- for (String fqdn: fqdnSet) {
+ for (String fqdn : fqdnSet) {
PasspointProvider provider = mProviders.get(fqdn);
if (provider != null) {
configs.add(provider.getWifiConfig());
@@ -945,7 +1054,6 @@ public class PasspointManager {
Log.e(TAG, "Passpoint network connected without provider: " + fqdn);
return;
}
-
if (!provider.getHasEverConnected()) {
// First successful connection using this provider.
provider.setHasEverConnected(true);
@@ -1026,7 +1134,7 @@ public class PasspointManager {
// Note that for legacy configuration, the alias for client private key is the same as the
// alias for the client certificate.
PasspointProvider provider = new PasspointProvider(passpointConfig, mKeyStore,
- mSimAccessor, mProviderIndex++, wifiConfig.creatorUid,
+ mSimAccessor, mProviderIndex++, wifiConfig.creatorUid, null,
Arrays.asList(enterpriseConfig.getCaCertificateAlias()),
enterpriseConfig.getClientCertificateAlias(),
enterpriseConfig.getClientCertificateAlias(), null, false, false);
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java
index 216a04194..c083b86cc 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java
@@ -54,11 +54,14 @@ public class PasspointObjectFactory{
* @param keyStore Instance of {@link WifiKeyStore}
* @param config Configuration for the provider
* @param providerId Unique identifier for the provider
+ * @param packageName Package name of app adding/updating the {@code config}
* @return {@link PasspointProvider}
*/
public PasspointProvider makePasspointProvider(PasspointConfiguration config,
- WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid) {
- return new PasspointProvider(config, keyStore, simAccessor, providerId, creatorUid);
+ WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid,
+ String packageName) {
+ return new PasspointProvider(config, keyStore, simAccessor, providerId, creatorUid,
+ packageName);
}
/**
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java
index 38188b152..ca9814aa6 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java
@@ -16,6 +16,7 @@
package com.android.server.wifi.hotspot2;
+import android.annotation.Nullable;
import android.net.wifi.EAPConstants;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
@@ -84,6 +85,7 @@ public class PasspointProvider {
private final long mProviderId;
private final int mCreatorUid;
+ private final String mPackageName;
private final IMSIParameter mImsiParameter;
private final List<String> mMatchingSIMImsiList;
@@ -101,13 +103,13 @@ public class PasspointProvider {
private boolean mIsEphemeral = false;
public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore,
- SIMAccessor simAccessor, long providerId, int creatorUid) {
- this(config, keyStore, simAccessor, providerId, creatorUid, null, null, null, null, false,
- false);
+ SIMAccessor simAccessor, long providerId, int creatorUid, String packageName) {
+ this(config, keyStore, simAccessor, providerId, creatorUid, packageName, null, null, null,
+ null, false, false);
}
public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore,
- SIMAccessor simAccessor, long providerId, int creatorUid,
+ SIMAccessor simAccessor, long providerId, int creatorUid, String packageName,
List<String> caCertificateAliases,
String clientCertificateAlias, String clientPrivateKeyAlias,
String remediationCaCertificateAlias,
@@ -117,6 +119,7 @@ public class PasspointProvider {
mKeyStore = keyStore;
mProviderId = providerId;
mCreatorUid = creatorUid;
+ mPackageName = packageName;
mCaCertificateAliases = caCertificateAliases;
mClientCertificateAlias = clientCertificateAlias;
mClientPrivateKeyAlias = clientPrivateKeyAlias;
@@ -174,6 +177,11 @@ public class PasspointProvider {
return mCreatorUid;
}
+ @Nullable
+ public String getPackageName() {
+ return mPackageName;
+ }
+
public boolean getHasEverConnected() {
return mHasEverConnected;
}
@@ -505,6 +513,9 @@ public class PasspointProvider {
StringBuilder builder = new StringBuilder();
builder.append("ProviderId: ").append(mProviderId).append("\n");
builder.append("CreatorUID: ").append(mCreatorUid).append("\n");
+ if (mPackageName != null) {
+ builder.append("PackageName: ").append(mPackageName).append("\n");
+ }
builder.append("Configuration Begin ---\n");
builder.append(mConfig);
builder.append("Configuration End ---\n");
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);
}
/**