Gated getProfileKey by SDK version

Keep only allow one profile per network on R.

Bug: 180734906
Test: atest FrameworksWifiTests FrameworksWifiApiTests on both R & S

Change-Id: I271f5e51bec84b8060668a10147e65ddf78d0d2b
diff --git a/framework/java/android/net/wifi/WifiConfiguration.java b/framework/java/android/net/wifi/WifiConfiguration.java
index 1765afa..deebd3d 100644
--- a/framework/java/android/net/wifi/WifiConfiguration.java
+++ b/framework/java/android/net/wifi/WifiConfiguration.java
@@ -43,6 +43,7 @@
 import android.util.SparseArray;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.modules.utils.build.SdkLevel;
 import com.android.net.module.util.MacAddressUtils;
 
 import java.lang.annotation.Retention;
@@ -3694,6 +3695,21 @@
      */
     @SystemApi
     @NonNull public String getProfileKey() {
+        if (!SdkLevel.isAtLeastS()) {
+            throw new UnsupportedOperationException();
+        }
+        return getProfileKeyInternal();
+    }
+
+    /**
+     * Get profile key for internal usage, if target level is less than S, will use the legacy
+     * {@link #getKey()} to generate the result.
+     * @hide
+     */
+    @NonNull public String getProfileKeyInternal() {
+        if (!SdkLevel.isAtLeastS()) {
+            return getKey();
+        }
         if (mPasspointUniqueId != null) {
             return mPasspointUniqueId;
         }
diff --git a/framework/java/android/net/wifi/WifiManager.java b/framework/java/android/net/wifi/WifiManager.java
index 051db14..f7baa7c 100644
--- a/framework/java/android/net/wifi/WifiManager.java
+++ b/framework/java/android/net/wifi/WifiManager.java
@@ -1519,7 +1519,7 @@
                             new ArrayList<>(results.keySet()));
             for (WifiConfiguration configuration : wifiConfigurations) {
                 Map<Integer, List<ScanResult>> scanResultsPerNetworkType =
-                        results.get(configuration.getProfileKey());
+                        results.get(configuration.getProfileKeyInternal());
                 if (scanResultsPerNetworkType != null) {
                     configs.add(Pair.create(configuration, scanResultsPerNetworkType));
                 }
diff --git a/framework/tests/src/android/net/wifi/WifiConfigurationTest.java b/framework/tests/src/android/net/wifi/WifiConfigurationTest.java
index bde44e7..876f436 100644
--- a/framework/tests/src/android/net/wifi/WifiConfigurationTest.java
+++ b/framework/tests/src/android/net/wifi/WifiConfigurationTest.java
@@ -36,6 +36,9 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
 
 import android.net.MacAddress;
 import android.net.wifi.WifiConfiguration.GroupCipher;
@@ -48,6 +51,7 @@
 
 import androidx.test.filters.SmallTest;
 
+import com.android.modules.utils.build.SdkLevel;
 import com.android.net.module.util.MacAddressUtils;
 
 import org.junit.Before;
@@ -748,11 +752,12 @@
     }
 
     /**
-     * Verifies that getProfileKey returns the correct String for networks of
+     * Verifies that getProfileKeyInternal returns the correct String for networks of
      * various different security types, the result should be stable.
      */
     @Test
     public void testGetProfileKeyString() {
+        assumeTrue(SdkLevel.isAtLeastS());
         WifiConfiguration config = new WifiConfiguration();
         final String mSsid = "TestAP";
         config.SSID = mSsid;
@@ -874,6 +879,33 @@
         assertEquals(TEST_PASSPOINT_UNIQUE_ID, config.getProfileKey());
     }
 
+    @Test
+    public void testGetProfileKeyInPreS() {
+        assumeFalse(SdkLevel.isAtLeastS());
+        WifiConfiguration config = new WifiConfiguration();
+        try {
+            config.getProfileKey();
+            fail("Expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException expected) {
+        }
+    }
+
+    @Test
+    public void testGetProfileKeyInternal() {
+        WifiConfiguration config = new WifiConfiguration();
+        final String mSsid = "TestAP";
+        config.SSID = mSsid;
+        config.carrierId = TEST_CARRIER_ID;
+        config.subscriptionId = TEST_SUB_ID;
+        config.creatorName = TEST_PACKAGE_NAME;
+
+        if (SdkLevel.isAtLeastS()) {
+            assertEquals(config.getProfileKey(), config.getProfileKeyInternal());
+        } else {
+            assertEquals(config.getKey(), config.getProfileKeyInternal());
+        }
+    }
+
     private String createProfileKey(String ssid, String keyMgmt, String providerName,
             int carrierId, int subId, boolean isFromSuggestion) {
         StringBuilder sb = new StringBuilder();
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 6a9172c..ca85e15 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -342,7 +342,7 @@
             }
         }
         if (mVerboseLoggingEnabled) {
-            logd(dbg + " clearTargetBssid " + bssid + " key=" + config.getProfileKey());
+            logd(dbg + " clearTargetBssid " + bssid + " key=" + config.getProfileKeyInternal());
         }
         mTargetBssid = bssid;
         return mWifiNative.setNetworkBSSID(mInterfaceName, bssid);
@@ -366,7 +366,8 @@
             }
         }
         if (mVerboseLoggingEnabled) {
-            Log.d(getTag(), "setTargetBssid set to " + bssid + " key=" + config.getProfileKey());
+            Log.d(getTag(), "setTargetBssid set to " + bssid + " key="
+                    + config.getProfileKeyInternal());
         }
         mTargetBssid = bssid;
         config.getNetworkSelectionStatus().setNetworkSelectionBSSID(bssid);
@@ -1640,7 +1641,7 @@
                 sb.append(cnm.result.getNetworkId());
                 config = mWifiConfigManager.getConfiguredNetwork(cnm.result.getNetworkId());
                 if (config != null) {
-                    sb.append(" ").append(config.getProfileKey());
+                    sb.append(" ").append(config.getProfileKeyInternal());
                     sb.append(" nid=").append(config.networkId);
                     if (config.hiddenSSID) {
                         sb.append(" hidden");
@@ -1671,7 +1672,7 @@
                 sb.append(" nid=").append(mLastNetworkId);
                 config = getConnectedWifiConfigurationInternal();
                 if (config != null) {
-                    sb.append(" ").append(config.getProfileKey());
+                    sb.append(" ").append(config.getProfileKeyInternal());
                 }
                 key = mWifiConfigManager.getLastSelectedNetworkConfigKey();
                 if (key != null) {
@@ -1741,7 +1742,7 @@
                 sb.append(Integer.toString(msg.arg2));
                 config = mWifiConfigManager.getConfiguredNetwork(msg.arg1);
                 if (config != null) {
-                    sb.append(" targetConfigKey=").append(config.getProfileKey());
+                    sb.append(" targetConfigKey=").append(config.getProfileKeyInternal());
                     sb.append(" BSSID=" + config.BSSID);
                 }
                 if (mTargetBssid != null) {
@@ -1750,7 +1751,7 @@
                 sb.append(" roam=").append(Boolean.toString(mIsAutoRoaming));
                 config = getConnectedWifiConfigurationInternal();
                 if (config != null) {
-                    sb.append(" currentConfigKey=").append(config.getProfileKey());
+                    sb.append(" currentConfigKey=").append(config.getProfileKeyInternal());
                 }
                 break;
             case CMD_START_ROAM:
@@ -3206,7 +3207,8 @@
             // Notify PasspointManager of Passpoint network connected event.
             WifiConfiguration currentNetwork = getConnectedWifiConfigurationInternal();
             if (currentNetwork != null && currentNetwork.isPasspoint()) {
-                mPasspointManager.onPasspointNetworkConnected(currentNetwork.getProfileKey());
+                mPasspointManager.onPasspointNetworkConnected(
+                        currentNetwork.getProfileKeyInternal());
             }
         }
     }
@@ -5439,7 +5441,7 @@
                     logd("CMD_START_ROAM sup state "
                             + " my state " + getCurrentState().getName()
                             + " nid=" + Integer.toString(netId)
-                            + " config " + config.getProfileKey()
+                            + " config " + config.getProfileKeyInternal()
                             + " targetRoamBSSID " + mTargetBssid);
 
                     reportConnectionAttemptStart(config, mTargetBssid,
@@ -6005,7 +6007,7 @@
                         != WifiConfiguration.RANDOMIZATION_NONE
                         && mWifiGlobals.isConnectedMacRandomizationEnabled();
         if (mVerboseLoggingEnabled) {
-            final String key = config.getProfileKey();
+            final String key = config.getProfileKeyInternal();
             log("startIpClient netId=" + Integer.toString(mLastNetworkId)
                     + " " + key + " "
                     + " roam=" + mIsAutoRoaming
diff --git a/service/java/com/android/server/wifi/ConfigurationMap.java b/service/java/com/android/server/wifi/ConfigurationMap.java
index 144ad38..e9f320b 100644
--- a/service/java/com/android/server/wifi/ConfigurationMap.java
+++ b/service/java/com/android/server/wifi/ConfigurationMap.java
@@ -128,7 +128,7 @@
             return null;
         }
         for (WifiConfiguration config : mPerIDForCurrentUser.values()) {
-            if (config.getProfileKey().equals(key)) {
+            if (config.getProfileKeyInternal().equals(key)) {
                 return config;
             }
         }
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java
index a40a0ae..d5c275a 100644
--- a/service/java/com/android/server/wifi/NetworkSuggestionNominator.java
+++ b/service/java/com/android/server/wifi/NetworkSuggestionNominator.java
@@ -112,14 +112,15 @@
     private void addOrUpdateSuggestionToWifiConfigManger(ExtendedWifiNetworkSuggestion ewns) {
         WifiConfiguration config = ewns.createInternalWifiConfiguration(mWifiCarrierInfoManager);
         WifiConfiguration wCmConfiguredNetwork =
-                mWifiConfigManager.getConfiguredNetwork(config.getProfileKey());
+                mWifiConfigManager.getConfiguredNetwork(config.getProfileKeyInternal());
         NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork(
                 config, ewns.perAppInfo.uid, ewns.perAppInfo.packageName);
         if (!result.isSuccess()) {
             mLocalLog.log("Failed to add network suggestion");
             return;
         }
-        mLocalLog.log(config.getProfileKey() + " is added/updated in the WifiConfigManager");
+        mLocalLog.log(config.getProfileKeyInternal()
+                + " is added/updated in the WifiConfigManager");
         mWifiConfigManager.allowAutojoin(result.getNetworkId(), config.allowAutojoin);
         WifiConfiguration currentWCmConfiguredNetwork =
                 mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
@@ -186,7 +187,7 @@
                                     config.getPasspointUniqueId())).findFirst();
             if (!matchingPasspointExtSuggestion.isPresent()) {
                 mLocalLog.log("Suggestion is missing for passpoint FQDN: " + config.FQDN
-                        + " profile key: " + config.getProfileKey());
+                        + " profile key: " + config.getProfileKeyInternal());
                 continue;
             }
             if (!isNetworkAvailableToAutoConnect(config, untrustedNetworkAllowed,
@@ -212,9 +213,10 @@
                 WifiConfiguration config = ewns.createInternalWifiConfiguration(
                         mWifiCarrierInfoManager);
                 WifiConfiguration wCmConfiguredNetwork =
-                        mWifiConfigManager.getConfiguredNetwork(config.getProfileKey());
+                        mWifiConfigManager.getConfiguredNetwork(config.getProfileKeyInternal());
                 if (wCmConfiguredNetwork == null) {
-                    mLocalLog.log(config.getProfileKey() + "hasn't add to WifiConfigManager?");
+                    mLocalLog.log(config.getProfileKeyInternal()
+                            + "hasn't add to WifiConfigManager?");
                     continue;
                 }
                 if (!wCmConfiguredNetwork.getNetworkSelectionStatus().isNetworkEnabled()
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index 130392e..3403605 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -965,7 +965,7 @@
                 Log.e(TAG, "Exception while saving config params: " + config, e);
             }
             if (!saveSuccess) {
-                loge("Failed to save variables for: " + config.getProfileKey());
+                loge("Failed to save variables for: " + config.getProfileKeyInternal());
                 if (!removeAllNetworks(ifaceName)) {
                     loge("Failed to remove all networks on failure.");
                 }
@@ -988,7 +988,7 @@
      */
     public boolean connectToNetwork(@NonNull String ifaceName, @NonNull WifiConfiguration config) {
         synchronized (mLock) {
-            logd("connectToNetwork " + config.getProfileKey());
+            logd("connectToNetwork " + config.getProfileKeyInternal());
             WifiConfiguration currentConfig = getCurrentNetworkLocalConfig(ifaceName);
             if (WifiConfigurationUtil.isSameNetwork(config, currentConfig)) {
                 String networkSelectionBSSID = config.getNetworkSelectionStatus()
@@ -1017,7 +1017,8 @@
                 Pair<SupplicantStaNetworkHal, WifiConfiguration> pair =
                         addNetworkAndSaveConfig(ifaceName, config);
                 if (pair == null) {
-                    loge("Failed to add/save network configuration: " + config.getProfileKey());
+                    loge("Failed to add/save network configuration: " + config
+                            .getProfileKeyInternal());
                     return false;
                 }
                 mCurrentNetworkRemoteHandles.put(ifaceName, pair.first);
@@ -1027,7 +1028,7 @@
                     checkSupplicantStaNetworkAndLogFailure(ifaceName, "connectToNetwork");
             if (networkHandle == null) {
                 loge("No valid remote network handle for network configuration: "
-                        + config.getProfileKey());
+                        + config.getProfileKeyInternal());
                 return false;
             }
 
@@ -1042,7 +1043,7 @@
             }
 
             if (!networkHandle.select()) {
-                loge("Failed to select network configuration: " + config.getProfileKey());
+                loge("Failed to select network configuration: " + config.getProfileKeyInternal());
                 return false;
             }
             return true;
@@ -1070,12 +1071,12 @@
                 return connectToNetwork(ifaceName, config);
             }
             String bssid = config.getNetworkSelectionStatus().getNetworkSelectionBSSID();
-            logd("roamToNetwork" + config.getProfileKey() + " (bssid " + bssid + ")");
+            logd("roamToNetwork" + config.getProfileKeyInternal() + " (bssid " + bssid + ")");
 
             SupplicantStaNetworkHal networkHandle =
                     checkSupplicantStaNetworkAndLogFailure(ifaceName, "roamToNetwork");
             if (networkHandle == null || !networkHandle.setBssid(bssid)) {
-                loge("Failed to set new bssid on network: " + config.getProfileKey());
+                loge("Failed to set new bssid on network: " + config.getProfileKeyInternal());
                 return false;
             }
             if (!reassociate(ifaceName)) {
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
index f9fec7f..76cc84c 100644
--- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
@@ -424,7 +424,7 @@
             if (config.isPasspoint()) {
                 metadata.put(ID_STRING_KEY_FQDN, config.FQDN);
             }
-            metadata.put(ID_STRING_KEY_CONFIG_KEY, config.getProfileKey());
+            metadata.put(ID_STRING_KEY_CONFIG_KEY, config.getProfileKeyInternal());
             metadata.put(ID_STRING_KEY_CREATOR_UID, Integer.toString(config.creatorUid));
             if (!setIdStr(createNetworkExtra(metadata))) {
                 Log.e(TAG, "failed to set id string");
diff --git a/service/java/com/android/server/wifi/WifiBlocklistMonitor.java b/service/java/com/android/server/wifi/WifiBlocklistMonitor.java
index 3de57a0..e2da9e0 100644
--- a/service/java/com/android/server/wifi/WifiBlocklistMonitor.java
+++ b/service/java/com/android/server/wifi/WifiBlocklistMonitor.java
@@ -1010,7 +1010,7 @@
         } else {
             setNetworkSelectionPermanentlyDisabled(config, reason);
         }
-        localLog("setNetworkSelectionStatus: configKey=" + config.getProfileKey()
+        localLog("setNetworkSelectionStatus: configKey=" + config.getProfileKeyInternal()
                 + " networkStatus=" + networkStatus.getNetworkStatusString() + " disableReason="
                 + networkStatus.getNetworkSelectionDisableReasonString());
     }
@@ -1022,7 +1022,7 @@
         NetworkSelectionStatus status = config.getNetworkSelectionStatus();
         if (status.getNetworkSelectionStatus()
                 != NetworkSelectionStatus.NETWORK_SELECTION_ENABLED) {
-            localLog("setNetworkSelectionEnabled: configKey=" + config.getProfileKey()
+            localLog("setNetworkSelectionEnabled: configKey=" + config.getProfileKeyInternal()
                     + " old networkStatus=" + status.getNetworkStatusString()
                     + " disableReason=" + status.getNetworkSelectionDisableReasonString());
         }
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 36b91c1..336d389 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -140,8 +140,8 @@
         /**
          * Invoked when user connect choice is set.
          * @param networks List of network profiles to set user connect choice.
-         * @param choiceKey Network key {@link WifiConfiguration#getProfileKey()} corresponding to
-         *                  the network which the user chose.
+         * @param choiceKey Network key {@link WifiConfiguration#getProfileKeyInternal()}
+         *                  corresponding to the network which the user chose.
          * @param rssi the signal strength of the user selected network
          */
         default void onConnectChoiceSet(@NonNull List<WifiConfiguration> networks,
@@ -840,14 +840,15 @@
         if (internalConfig != null) {
             return internalConfig;
         }
-        internalConfig = mConfiguredNetworks.getByConfigKeyForCurrentUser(config.getProfileKey());
+        internalConfig = mConfiguredNetworks.getByConfigKeyForCurrentUser(
+                config.getProfileKeyInternal());
         if (internalConfig != null) {
             return internalConfig;
         }
         internalConfig = getInternalConfiguredNetworkByUpgradableType(config);
         if (internalConfig == null) {
             Log.e(TAG, "Cannot find network with networkId " + config.networkId
-                    + " or configKey " + config.getProfileKey()
+                    + " or configKey " + config.getProfileKeyInternal()
                     + " or upgradable security type check");
         }
         return internalConfig;
@@ -1279,7 +1280,7 @@
             // {@link WifiConfiguration#allowedKeyMgmt} field, check again if we already have a
             // network with the the same configkey.
             existingInternalConfig =
-                    getInternalConfiguredNetwork(newInternalConfig.getProfileKey());
+                    getInternalConfiguredNetwork(newInternalConfig.getProfileKeyInternal());
         }
         // Existing network found. So, a network update.
         if (existingInternalConfig != null) {
@@ -1291,7 +1292,7 @@
             // Check for the app's permission before we let it update this network.
             if (!canModifyNetwork(existingInternalConfig, uid, packageName)) {
                 Log.e(TAG, "UID " + uid + " does not have permission to update configuration "
-                        + config.getProfileKey());
+                        + config.getProfileKeyInternal());
                 return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
             }
             if (mWifiPermissionsUtil.checkNetworkSettingsPermission(uid)
@@ -1309,7 +1310,7 @@
         if (WifiConfigurationUtil.hasProxyChanged(existingInternalConfig, newInternalConfig)
                 && !canModifyProxySettings(uid, packageName)) {
             Log.e(TAG, "UID " + uid + " does not have permission to modify proxy Settings "
-                    + config.getProfileKey() + ". Must have NETWORK_SETTINGS,"
+                    + config.getProfileKeyInternal() + ". Must have NETWORK_SETTINGS,"
                     + " or be device or profile owner.");
             return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
         }
@@ -1320,7 +1321,7 @@
                 && !(newInternalConfig.isPasspoint() && uid == newInternalConfig.creatorUid)
                 && !config.fromWifiNetworkSuggestion) {
             Log.e(TAG, "UID " + uid + " does not have permission to modify MAC randomization "
-                    + "Settings " + config.getProfileKey() + ". Must have "
+                    + "Settings " + config.getProfileKeyInternal() + ". Must have "
                     + "NETWORK_SETTINGS or NETWORK_SETUP_WIZARD or be the creator adding or "
                     + "updating a passpoint network.");
             return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
@@ -1381,7 +1382,7 @@
 
         localLog("addOrUpdateNetworkInternal: added/updated config."
                 + " netId=" + newInternalConfig.networkId
-                + " configKey=" + newInternalConfig.getProfileKey()
+                + " configKey=" + newInternalConfig.getProfileKeyInternal()
                 + " uid=" + Integer.toString(newInternalConfig.creatorUid)
                 + " name=" + newInternalConfig.creatorName);
         return result;
@@ -1487,7 +1488,7 @@
         // WifiConfigManager. Will remove that when profile is deleted from PassointManager or
         // WifiNetworkSuggestionsManager.
         if (!config.isPasspoint() && !config.fromWifiNetworkSuggestion) {
-            removeConnectChoiceFromAllNetworks(config.getProfileKey());
+            removeConnectChoiceFromAllNetworks(config.getProfileKeyInternal());
         }
         mConfiguredNetworks.remove(config.networkId);
         mScanDetailCaches.remove(config.networkId);
@@ -1497,7 +1498,7 @@
 
         localLog("removeNetworkInternal: removed config."
                 + " netId=" + config.networkId
-                + " configKey=" + config.getProfileKey()
+                + " configKey=" + config.getProfileKeyInternal()
                 + " uid=" + Integer.toString(uid)
                 + " name=" + mContext.getPackageManager().getNameForUid(uid));
         return true;
@@ -1521,7 +1522,7 @@
         }
         if (!canModifyNetwork(config, uid, packageName)) {
             Log.e(TAG, "UID " + uid + " does not have permission to delete configuration "
-                    + config.getProfileKey());
+                    + config.getProfileKeyInternal());
             return false;
         }
         if (!removeNetworkInternal(config, uid)) {
@@ -1626,11 +1627,11 @@
                 mConfiguredNetworks.valuesForAllUsers().toArray(new WifiConfiguration[0]);
         for (WifiConfiguration config : copiedConfigs) {
             if (config.isPasspoint()) {
-                Log.d(TAG, "Removing passpoint network config " + config.getProfileKey());
+                Log.d(TAG, "Removing passpoint network config " + config.getProfileKeyInternal());
                 removeNetwork(config.networkId, config.creatorUid, config.creatorName);
                 didRemove = true;
             } else if (config.ephemeral) {
-                Log.d(TAG, "Removing ephemeral network config " + config.getProfileKey());
+                Log.d(TAG, "Removing ephemeral network config " + config.getProfileKeyInternal());
                 removeNetwork(config.networkId, config.creatorUid, config.creatorName);
                 didRemove = true;
             }
@@ -1647,7 +1648,7 @@
     public boolean removeSuggestionConfiguredNetwork(@NonNull String configKey) {
         WifiConfiguration config = getInternalConfiguredNetwork(configKey);
         if (config != null && config.ephemeral && config.fromWifiNetworkSuggestion) {
-            Log.d(TAG, "Removing suggestion network config " + config.getProfileKey());
+            Log.d(TAG, "Removing suggestion network config " + config.getProfileKeyInternal());
             return removeNetwork(config.networkId, config.creatorUid, config.creatorName);
         }
         return false;
@@ -1662,7 +1663,7 @@
     public boolean removePasspointConfiguredNetwork(@NonNull String configKey) {
         WifiConfiguration config = getInternalConfiguredNetwork(configKey);
         if (config != null && config.isPasspoint()) {
-            Log.d(TAG, "Removing passpoint network config " + config.getProfileKey());
+            Log.d(TAG, "Removing passpoint network config " + config.getProfileKeyInternal());
             return removeNetwork(config.networkId, config.creatorUid, config.creatorName);
         }
         return false;
@@ -1821,7 +1822,7 @@
         }
         if (!canModifyNetwork(config, uid, packageName)) {
             Log.e(TAG, "UID " + uid + " does not have permission to update configuration "
-                    + config.getProfileKey());
+                    + config.getProfileKeyInternal());
             return false;
         }
         if (!updateNetworkSelectionStatus(
@@ -1858,7 +1859,7 @@
         }
         if (!canModifyNetwork(config, uid, packageName)) {
             Log.e(TAG, "UID " + uid + " does not have permission to update configuration "
-                    + config.getProfileKey());
+                    + config.getProfileKeyInternal());
             return false;
         }
         if (!updateNetworkSelectionStatus(
@@ -1890,7 +1891,7 @@
 
         config.allowAutojoin = choice;
         if (!choice) {
-            removeConnectChoiceFromAllNetworks(config.getProfileKey());
+            removeConnectChoiceFromAllNetworks(config.getProfileKeyInternal());
             clearConnectChoiceInternal(config);
         }
         sendConfiguredNetworkChangedBroadcast(WifiManager.CHANGE_REASON_CONFIG_CHANGE);
@@ -2207,7 +2208,7 @@
         if (config == null) {
             return "";
         }
-        return config.getProfileKey();
+        return config.getProfileKeyInternal();
     }
 
     /**
@@ -2304,7 +2305,7 @@
         }
         if (config != null) {
             if (mVerboseLoggingEnabled) {
-                Log.v(TAG, "getSavedNetworkFromScanDetail Found " + config.getProfileKey()
+                Log.v(TAG, "getSavedNetworkFromScanDetail Found " + config.getProfileKeyInternal()
                         + " for " + scanResult.SSID + "[" + scanResult.capabilities + "]");
             }
         }
@@ -2383,7 +2384,7 @@
                     Log.v(TAG, "Updating scan detail cache freq=" + result.frequency
                             + " BSSID=" + result.BSSID
                             + " RSSI=" + result.level
-                            + " for " + config.getProfileKey());
+                            + " for " + config.getProfileKeyInternal());
                 }
             }
         }
@@ -2475,8 +2476,8 @@
      */
     private void linkNetworks(WifiConfiguration network1, WifiConfiguration network2) {
         if (mVerboseLoggingEnabled) {
-            Log.v(TAG, "linkNetworks will link " + network2.getProfileKey()
-                    + " and " + network1.getProfileKey());
+            Log.v(TAG, "linkNetworks will link " + network2.getProfileKeyInternal()
+                    + " and " + network1.getProfileKeyInternal());
         }
         if (network2.linkedConfigurations == null) {
             network2.linkedConfigurations = new HashMap<>();
@@ -2486,8 +2487,8 @@
         }
         // TODO (b/30638473): This needs to become a set instead of map, but it will need
         // public interface changes and need some migration of existing store data.
-        network2.linkedConfigurations.put(network1.getProfileKey(), 1);
-        network1.linkedConfigurations.put(network2.getProfileKey(), 1);
+        network2.linkedConfigurations.put(network1.getProfileKeyInternal(), 1);
+        network1.linkedConfigurations.put(network2.getProfileKeyInternal(), 1);
     }
 
     /**
@@ -2498,20 +2499,20 @@
      */
     private void unlinkNetworks(WifiConfiguration network1, WifiConfiguration network2) {
         if (network2.linkedConfigurations != null
-                && (network2.linkedConfigurations.get(network1.getProfileKey()) != null)) {
+                && (network2.linkedConfigurations.get(network1.getProfileKeyInternal()) != null)) {
             if (mVerboseLoggingEnabled) {
-                Log.v(TAG, "unlinkNetworks un-link " + network1.getProfileKey()
-                        + " from " + network2.getProfileKey());
+                Log.v(TAG, "unlinkNetworks un-link " + network1.getProfileKeyInternal()
+                        + " from " + network2.getProfileKeyInternal());
             }
-            network2.linkedConfigurations.remove(network1.getProfileKey());
+            network2.linkedConfigurations.remove(network1.getProfileKeyInternal());
         }
         if (network1.linkedConfigurations != null
-                && (network1.linkedConfigurations.get(network2.getProfileKey()) != null)) {
+                && (network1.linkedConfigurations.get(network2.getProfileKeyInternal()) != null)) {
             if (mVerboseLoggingEnabled) {
-                Log.v(TAG, "unlinkNetworks un-link " + network2.getProfileKey()
-                        + " from " + network1.getProfileKey());
+                Log.v(TAG, "unlinkNetworks un-link " + network2.getProfileKeyInternal()
+                        + " from " + network1.getProfileKeyInternal());
             }
-            network1.linkedConfigurations.remove(network2.getProfileKey());
+            network1.linkedConfigurations.remove(network2.getProfileKeyInternal());
         }
     }
 
@@ -2534,7 +2535,7 @@
             return;
         }
         for (WifiConfiguration linkConfig : getInternalConfiguredNetworks()) {
-            if (linkConfig.getProfileKey().equals(config.getProfileKey())) {
+            if (linkConfig.getProfileKeyInternal().equals(config.getProfileKeyInternal())) {
                 continue;
             }
             if (linkConfig.ephemeral) {
@@ -2694,7 +2695,7 @@
                     mWifiMetrics.logUserActionEvent(
                             UserActionEvent.EVENT_DISCONNECT_WIFI, config.networkId);
                 }
-                removeConnectChoiceFromAllNetworks(config.getProfileKey());
+                removeConnectChoiceFromAllNetworks(config.getProfileKeyInternal());
             }
         }
     }
@@ -2938,7 +2939,7 @@
                 removedNetworkIds.add(config.networkId);
                 localLog("clearInternalUserData: removed config."
                         + " netId=" + config.networkId
-                        + " configKey=" + config.getProfileKey());
+                        + " configKey=" + config.getProfileKeyInternal());
                 mConfiguredNetworks.remove(config.networkId);
                 for (OnNetworkUpdateListener listener : mListeners) {
                     listener.onNetworkRemoved(
@@ -2974,7 +2975,8 @@
 
             WifiConfiguration existingConfiguration = getInternalConfiguredNetwork(configuration);
             if (null != existingConfiguration) {
-                Log.d(TAG, "Merging network from shared store " + configuration.getProfileKey());
+                Log.d(TAG, "Merging network from shared store "
+                        + configuration.getProfileKeyInternal());
                 mergeWithInternalWifiConfiguration(existingConfiguration, configuration);
                 continue;
             }
@@ -2982,7 +2984,8 @@
             configuration.networkId = mNextNetworkId++;
             WifiConfigurationUtil.addUpgradableSecurityTypeIfNecessary(configuration);
             if (mVerboseLoggingEnabled) {
-                Log.v(TAG, "Adding network from shared store " + configuration.getProfileKey());
+                Log.v(TAG, "Adding network from shared store "
+                        + configuration.getProfileKeyInternal());
             }
             try {
                 mConfiguredNetworks.put(configuration);
@@ -3009,7 +3012,8 @@
 
             WifiConfiguration existingConfiguration = getInternalConfiguredNetwork(configuration);
             if (null != existingConfiguration) {
-                Log.d(TAG, "Merging network from user store " + configuration.getProfileKey());
+                Log.d(TAG, "Merging network from user store "
+                        + configuration.getProfileKeyInternal());
                 mergeWithInternalWifiConfiguration(existingConfiguration, configuration);
                 continue;
             }
@@ -3017,7 +3021,8 @@
             configuration.networkId = mNextNetworkId++;
             WifiConfigurationUtil.addUpgradableSecurityTypeIfNecessary(configuration);
             if (mVerboseLoggingEnabled) {
-                Log.v(TAG, "Adding network from user store " + configuration.getProfileKey());
+                Log.v(TAG, "Adding network from user store "
+                        + configuration.getProfileKeyInternal());
             }
             try {
                 mConfiguredNetworks.put(configuration);
@@ -3425,7 +3430,7 @@
         localLog("userSelectNetwork: network ID=" + netId);
         WifiConfiguration selected = getInternalConfiguredNetwork(netId);
 
-        if (selected == null || selected.getProfileKey() == null) {
+        if (selected == null || selected.getProfileKeyInternal() == null) {
             localLog("userSelectNetwork: Invalid configuration with nid=" + netId);
             return false;
         }
@@ -3447,7 +3452,7 @@
         boolean change = false;
         Collection<WifiConfiguration> configuredNetworks = getInternalConfiguredNetworks();
         ArrayList<WifiConfiguration> networksInRange = new ArrayList<>();
-        String key = selected.getProfileKey();
+        String key = selected.getProfileKeyInternal();
         for (WifiConfiguration network : configuredNetworks) {
             WifiConfiguration.NetworkSelectionStatus status = network.getNetworkSelectionStatus();
             if (network.networkId == selected.networkId) {
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index ac79f11..6161848 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -2182,7 +2182,7 @@
 
         // If we have a single suggestion network, and we are connected to it, return true.
         WifiNetworkSuggestion network = suggestionsNetworks.iterator().next();
-        String suggestionKey = network.getWifiConfiguration().getProfileKey();
+        String suggestionKey = network.getWifiConfiguration().getProfileKeyInternal();
         WifiConfiguration config = mConfigManager.getConfiguredNetwork(suggestionKey);
         return (config != null && config.networkId == currentNetworkId);
     }
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index b82e616..3dc0c68 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -5586,7 +5586,7 @@
             meteredDetail.isMeteredOverrideSet = config.meteredOverride
                     != WifiConfiguration.METERED_OVERRIDE_NONE;
             meteredDetail.isFromSuggestion = config.fromWifiNetworkSuggestion;
-            mNetworkMap.put(config.getProfileKey(), meteredDetail);
+            mNetworkMap.put(config.getProfileKeyInternal(), meteredDetail);
         }
 
         void clear() {
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index 36adf46..586427c 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -818,7 +818,7 @@
     // If the network already exists, just return the network ID of the existing network.
     private int addNetworkToWifiConfigManager(@NonNull WifiConfiguration network) {
         WifiConfiguration existingSavedNetwork =
-                mWifiConfigManager.getConfiguredNetwork(network.getProfileKey());
+                mWifiConfigManager.getConfiguredNetwork(network.getProfileKeyInternal());
         if (existingSavedNetwork != null) {
             if (WifiConfigurationUtil.hasCredentialChanged(existingSavedNetwork, network)) {
                 // TODO (b/142035508): What if the user has a saved network with different
@@ -846,7 +846,7 @@
 
         if (network == null) return;
         WifiConfiguration wcmNetwork =
-                mWifiConfigManager.getConfiguredNetwork(network.getProfileKey());
+                mWifiConfigManager.getConfiguredNetwork(network.getProfileKeyInternal());
         if (wcmNetwork == null) {
             Log.e(TAG, "Network not present in config manager");
             return;
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index ef02438..d52092d 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -766,7 +766,7 @@
 
     private void removeNetworkFromScoreCard(WifiConfiguration wifiConfiguration) {
         WifiConfiguration existing =
-                mWifiConfigManager.getConfiguredNetwork(wifiConfiguration.getProfileKey());
+                mWifiConfigManager.getConfiguredNetwork(wifiConfiguration.getProfileKeyInternal());
         // If there is a saved network, do not remove from the score card.
         if (existing != null && !existing.fromWifiNetworkSuggestion) {
             return;
@@ -815,7 +815,7 @@
                         + "Removing from config manager...");
                 // will trigger a disconnect.
                 mWifiConfigManager.removeSuggestionConfiguredNetwork(
-                        activeWifiConfiguration.getProfileKey());
+                        activeWifiConfiguration.getProfileKeyInternal());
             }
         }
     }
@@ -860,7 +860,7 @@
     private void updateWifiConfigInWcmIfPresent(
             WifiConfiguration newConfig, int uid, String packageName) {
         WifiConfiguration configInWcm =
-                mWifiConfigManager.getConfiguredNetwork(newConfig.getProfileKey());
+                mWifiConfigManager.getConfiguredNetwork(newConfig.getProfileKeyInternal());
         if (configInWcm == null) return;
         // !suggestion
         if (!configInWcm.fromWifiNetworkSuggestion) return;
@@ -1249,7 +1249,8 @@
                 }
                 removeFromScanResultMatchInfoMapAndRemoveRelatedScoreCard(ewns);
                 mWifiConfigManager.removeConnectChoiceFromAllNetworks(ewns
-                        .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey());
+                        .createInternalWifiConfiguration(mWifiCarrierInfoManager)
+                        .getProfileKeyInternal());
             }
             removingSuggestions.add(ewns.wns);
         }
@@ -1461,7 +1462,8 @@
                     continue;
                 }
                 WifiConfiguration network = mWifiConfigManager
-                        .getConfiguredNetwork(ewns.wns.getWifiConfiguration().getProfileKey());
+                        .getConfiguredNetwork(ewns.wns.getWifiConfiguration()
+                                .getProfileKeyInternal());
                 if (network == null) {
                     network = ewns.createInternalWifiConfiguration(mWifiCarrierInfoManager);
                 }
@@ -1803,11 +1805,11 @@
                     continue;
                 }
                 WifiConfiguration wCmWifiConfig = mWifiConfigManager
-                        .getConfiguredNetwork(config.getProfileKey());
+                        .getConfiguredNetwork(config.getProfileKeyInternal());
                 if (wCmWifiConfig == null) {
                     continue;
                 }
-                if (networkKeys.add(wCmWifiConfig.getProfileKey())) {
+                if (networkKeys.add(wCmWifiConfig.getProfileKeyInternal())) {
                     sharedWifiConfigs.add(wCmWifiConfig);
                 }
             }
@@ -2028,7 +2030,8 @@
         for (ExtendedWifiNetworkSuggestion ewns : matchingSuggestions) {
             WifiConfiguration config = ewns
                     .createInternalWifiConfiguration(mWifiCarrierInfoManager);
-            if (config.getProfileKey().equals(network.getProfileKey())) {
+            if (config.getProfileKeyInternal().equals(network.getProfileKeyInternal())
+                    && config.creatorName.equals(network.creatorName)) {
                 matchingExtNetworkSuggestionsWithSameProfileKey.add(ewns);
             }
         }
@@ -2260,7 +2263,7 @@
         }
 
         if (config.isPasspoint()) {
-            if (!mWifiInjector.getPasspointManager().enableAutojoin(config.getProfileKey(),
+            if (!mWifiInjector.getPasspointManager().enableAutojoin(config.getProfileKeyInternal(),
                     null, choice)) {
                 return false;
             }
@@ -2437,7 +2440,7 @@
                 continue;
             }
             WifiConfiguration wcmConfig = mWifiConfigManager
-                    .getConfiguredNetwork(ewns.wns.wifiConfiguration.getProfileKey());
+                    .getConfiguredNetwork(ewns.wns.wifiConfiguration.getProfileKeyInternal());
             // Network selection is disabled, ignore.
             if (wcmConfig != null && !wcmConfig.getNetworkSelectionStatus().isNetworkEnabled()) {
                 continue;
@@ -2516,14 +2519,14 @@
             int rssi) {
         Set<String> networkKeys = networks.stream()
                 .filter(config -> config.fromWifiNetworkSuggestion)
-                .map(WifiConfiguration::getProfileKey)
+                .map(WifiConfiguration::getProfileKeyInternal)
                 .collect(Collectors.toSet());
         mActiveNetworkSuggestionsPerApp.values().stream()
                 .flatMap(e -> e.extNetworkSuggestions.stream())
                 .forEach(ewns -> {
                     String profileKey = ewns
                             .createInternalWifiConfiguration(mWifiCarrierInfoManager)
-                            .getProfileKey();
+                            .getProfileKeyInternal();
                     if (TextUtils.equals(profileKey, choiceKey)) {
                         ewns.connectChoice = null;
                         ewns.connectChoiceRssi = 0;
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 2bd6e0c..2abab4e 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -3898,7 +3898,8 @@
                                 mWifiConfigManager.addOrUpdateNetwork(configuration, callingUid)
                                         .getNetworkId();
                         if (networkId == WifiConfiguration.INVALID_NETWORK_ID) {
-                            Log.e(TAG, "Restore network failed: " + configuration.getProfileKey());
+                            Log.e(TAG, "Restore network failed: "
+                                    + configuration.getProfileKeyInternal());
                             continue;
                         }
                         // Enable all networks restored.
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
index f0894e6..fcbad02 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
@@ -289,7 +289,7 @@
     private void onUserConnectChoiceSet(List<WifiConfiguration> networks, String choiceKey,
             int rssi) {
         for (WifiConfiguration config : networks) {
-            PasspointProvider provider = mProviders.get(config.getProfileKey());
+            PasspointProvider provider = mProviders.get(config.getProfileKeyInternal());
             if (provider != null) {
                 provider.setUserConnectChoice(choiceKey, rssi);
             }
@@ -401,7 +401,7 @@
     private void updateWifiConfigInWcmIfPresent(
             WifiConfiguration newConfig, int uid, String packageName, boolean isFromSuggestion) {
         WifiConfiguration configInWcm =
-                mWifiConfigManager.getConfiguredNetwork(newConfig.getProfileKey());
+                mWifiConfigManager.getConfiguredNetwork(newConfig.getProfileKeyInternal());
         if (configInWcm == null) return;
         // suggestion != saved
         if (isFromSuggestion != configInWcm.fromWifiNetworkSuggestion) return;
@@ -517,7 +517,7 @@
             // New profile changes the credential, remove the related WifiConfig.
             if (!old.equals(newProvider)) {
                 mWifiConfigManager.removePasspointConfiguredNetwork(
-                        newProvider.getWifiConfig().getProfileKey());
+                        newProvider.getWifiConfig().getProfileKeyInternal());
             } else {
                 // If there is a config cached in WifiConfigManager, update it with new info.
                 updateWifiConfigInWcmIfPresent(
@@ -561,7 +561,7 @@
         String packageName = provider.getPackageName();
         // Remove any configs corresponding to the profile in WifiConfigManager.
         mWifiConfigManager.removePasspointConfiguredNetwork(
-                provider.getWifiConfig().getProfileKey());
+                provider.getWifiConfig().getProfileKeyInternal());
         String uniqueId = provider.getConfig().getUniqueId();
         mProviders.remove(uniqueId);
         mWifiConfigManager.removeConnectChoiceFromAllNetworks(uniqueId);
@@ -709,7 +709,7 @@
                                     : UserActionEvent.EVENT_CONFIGURE_MAC_RANDOMIZATION_OFF,
                             provider.isFromSuggestion(), true);
                     mWifiConfigManager.removePasspointConfiguredNetwork(
-                            provider.getWifiConfig().getProfileKey());
+                            provider.getWifiConfig().getProfileKeyInternal());
                 }
                 found = true;
             }
@@ -1038,7 +1038,8 @@
                     type = WifiManager.PASSPOINT_ROAMING_NETWORK;
                 }
                 Map<Integer, List<ScanResult>> scanResultsPerNetworkType =
-                        configs.computeIfAbsent(config.getProfileKey(), k -> new HashMap<>());
+                        configs.computeIfAbsent(config.getProfileKeyInternal(),
+                                k -> new HashMap<>());
                 List<ScanResult> matchingScanResults = scanResultsPerNetworkType.computeIfAbsent(
                         type, k -> new ArrayList<>());
                 matchingScanResults.add(scanResult);
@@ -1499,7 +1500,8 @@
             return;
         }
 
-        blockProvider(config.getProfileKey(), event.getBssid(), event.isEss(), event.getDelay());
+        blockProvider(config.getProfileKeyInternal(), event.getBssid(), event.isEss(),
+                event.getDelay());
     }
 
     /**
@@ -1524,7 +1526,7 @@
         if (!configuration.isPasspoint()) {
             return;
         }
-        PasspointProvider provider = mProviders.get(configuration.getProfileKey());
+        PasspointProvider provider = mProviders.get(configuration.getProfileKeyInternal());
         if (provider != null) {
             provider.setAnonymousIdentity(configuration.enterpriseConfig.getAnonymousIdentity());
             mWifiConfigManager.saveToStore(true);
@@ -1561,7 +1563,7 @@
                     + " from BSSID: " + Utils.macToString(event.getBssid()));
 
             // Block this provider for an hour, this unlikely issue may be resolved shortly
-            blockProvider(config.getProfileKey(), event.getBssid(), true, oneHourInSeconds);
+            blockProvider(config.getProfileKeyInternal(), event.getBssid(), true, oneHourInSeconds);
             return null;
         }
         // Reject URLs that are not HTTPS
@@ -1570,7 +1572,8 @@
                     + " from BSSID: " + Utils.macToString(event.getBssid()));
 
             // Block this provider for 24 hours, it is unlikely to be changed
-            blockProvider(config.getProfileKey(), event.getBssid(), true, twentyFourHoursInSeconds);
+            blockProvider(config.getProfileKeyInternal(), event.getBssid(), true,
+                    twentyFourHoursInSeconds);
             return null;
         }
         Log.i(TAG, "Captive network, Terms and Conditions URL: " + termsAndConditionsUrl
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java
index 76e0557..b461616 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java
@@ -196,7 +196,7 @@
             config.meteredHint = true;
         }
         WifiConfiguration existingNetwork = mWifiConfigManager.getConfiguredNetwork(
-                config.getProfileKey());
+                config.getProfileKeyInternal());
         if (existingNetwork != null) {
             WifiConfiguration.NetworkSelectionStatus status =
                     existingNetwork.getNetworkSelectionStatus();
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java
index 8398839..3753db6 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java
@@ -1147,7 +1147,8 @@
 
     /**
      * Set the user connect choice on the passpoint network.
-     * @param choice The {@link WifiConfiguration#getProfileKey()} of the user conncet network.
+     * @param choice The {@link WifiConfiguration#getProfileKeyInternal()} of the user connect
+     *               network.
      * @param rssi The signal strength of the network.
      */
     public void setUserConnectChoice(String choice, int rssi) {
diff --git a/service/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java b/service/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
index 7081139..896387f 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
@@ -189,7 +189,8 @@
         // visible to the current user.
         for (WifiConfiguration config : configsForCurrentUser) {
             assertEquals(config, mConfigs.getForCurrentUser(config.networkId));
-            assertEquals(config, mConfigs.getByConfigKeyForCurrentUser(config.getProfileKey()));
+            assertEquals(config, mConfigs.getByConfigKeyForCurrentUser(
+                    config.getProfileKeyInternal()));
             final boolean wasEphemeral = config.ephemeral;
             config.ephemeral = false;
             assertNull(getEphemeralForCurrentUser(config.SSID));
@@ -202,7 +203,7 @@
         // visible to the current user.
         for (WifiConfiguration config : configsNotForCurrentUser) {
             assertNull(mConfigs.getForCurrentUser(config.networkId));
-            assertNull(mConfigs.getByConfigKeyForCurrentUser(config.getProfileKey()));
+            assertNull(mConfigs.getByConfigKeyForCurrentUser(config.getProfileKeyInternal()));
             final boolean wasEphemeral = config.ephemeral;
             config.ephemeral = false;
             assertNull(getEphemeralForCurrentUser(config.SSID));
@@ -236,7 +237,7 @@
         WifiConfiguration retrievedConfig =
                 mConfigs.getByScanResultForCurrentUser(scanResult);
         assertNotNull(retrievedConfig);
-        assertEquals(config.getProfileKey(), retrievedConfig.getProfileKey());
+        assertEquals(config.getProfileKeyInternal(), retrievedConfig.getProfileKeyInternal());
     }
 
     /**
diff --git a/service/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java b/service/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
index 542311c..8447775 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
@@ -483,7 +483,7 @@
         assertTrue(connectableNetworks.isEmpty());
 
         verify(mWifiConfigManager).getConfiguredNetwork(eq(suggestions[0]
-                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey()));
+                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKeyInternal()));
         // Verify we did not try to add any new networks or other interactions with
         // WifiConfigManager.
         verifyNoMoreInteractions(mWifiConfigManager);
@@ -526,7 +526,7 @@
         setupAddToWifiConfigManager(suggestions[0]);
         // Existing saved network matching the credentials.
         when(mWifiConfigManager.getConfiguredNetwork(suggestions[0]
-                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey()))
+                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKeyInternal()))
                 .thenReturn(suggestions[0].wns.wifiConfiguration);
 
         List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
@@ -543,7 +543,8 @@
                 .isNetworkTemporarilyDisabledByUser(anyString());
         verify(mWifiConfigManager)
                 .getConfiguredNetwork(suggestions[0]
-                        .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey());
+                        .createInternalWifiConfiguration(mWifiCarrierInfoManager)
+                        .getProfileKeyInternal());
         verify(mWifiConfigManager).isNonCarrierMergedNetworkTemporarilyDisabled(any());
         // Verify we did not try to add any new networks or other interactions with
         // WifiConfigManager.
@@ -639,7 +640,7 @@
 
         // Existing network matching the credentials.
         when(mWifiConfigManager.getConfiguredNetwork(suggestions[0]
-                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey()))
+                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKeyInternal()))
                 .thenReturn(suggestions[0].wns.wifiConfiguration);
 
         List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>();
@@ -651,7 +652,7 @@
 
         assertTrue(connectableNetworks.isEmpty());
         verify(mWifiConfigManager).getConfiguredNetwork(eq(
-                suggestions[0].wns.wifiConfiguration.getProfileKey()));
+                suggestions[0].wns.wifiConfiguration.getProfileKeyInternal()));
         verify(mWifiConfigManager).tryEnableNetwork(eq(
                 suggestions[0].wns.wifiConfiguration.networkId));
         // Verify we did not try to add any new networks or other interactions with
@@ -700,7 +701,7 @@
                 NETWORK_SELECTION_TEMPORARY_DISABLED);
         // Existing network matching the credentials.
         when(mWifiConfigManager.getConfiguredNetwork(suggestions[0]
-                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey()))
+                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKeyInternal()))
                 .thenReturn(suggestions[0].wns.wifiConfiguration);
         when(mWifiConfigManager.tryEnableNetwork(suggestions[0].wns.wifiConfiguration.networkId))
                 .thenReturn(true);
@@ -717,7 +718,7 @@
         verify(mWifiConfigManager, times(suggestionSsids.length))
                 .isNetworkTemporarilyDisabledByUser(anyString());
         verify(mWifiConfigManager).getConfiguredNetwork(eq(suggestions[0]
-                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKey()));
+                .createInternalWifiConfiguration(mWifiCarrierInfoManager).getProfileKeyInternal()));
         verify(mWifiConfigManager).tryEnableNetwork(eq(
                 suggestions[0].wns.wifiConfiguration.networkId));
         verify(mWifiConfigManager).isNonCarrierMergedNetworkTemporarilyDisabled(any());
@@ -1421,7 +1422,7 @@
                     mock(WifiConfiguration.NetworkSelectionStatus.class);
             when(status.isNetworkEnabled()).thenReturn(true);
             candidate.setNetworkSelectionStatus(status);
-            when(mWifiConfigManager.getConfiguredNetwork(candidate.getProfileKey()))
+            when(mWifiConfigManager.getConfiguredNetwork(candidate.getProfileKeyInternal()))
                     .thenReturn(candidate);
         }
     }
diff --git a/service/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/service/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
index 15e9318..fced99c 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
@@ -1134,7 +1134,7 @@
         Map<String, String> networkExtras = new HashMap<>();
         assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras));
         WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig);
-        assertEquals(config.getProfileKey(),
+        assertEquals(config.getProfileKeyInternal(),
                 networkExtras.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY));
         assertEquals(
                 config.creatorUid,
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 8a07cea..9b751cd 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -875,8 +875,8 @@
         List<WifiConfiguration> retrievedNetworks =
                 mWifiConfigManager.getConfiguredNetworksWithPasswords();
         assertEquals(1, retrievedNetworks.size());
-        assertEquals(openNetworkSuggestion.getProfileKey(),
-                retrievedNetworks.get(0).getProfileKey());
+        assertEquals(openNetworkSuggestion.getProfileKeyInternal(),
+                retrievedNetworks.get(0).getProfileKeyInternal());
     }
 
     /**
@@ -1100,7 +1100,8 @@
         List<WifiConfiguration> retrievedSavedNetworks = mWifiConfigManager.getSavedNetworks(
                 Process.WIFI_UID);
         assertEquals(retrievedSavedNetworks.size(), 1);
-        assertEquals(retrievedSavedNetworks.get(0).getProfileKey(), pskNetwork.getProfileKey());
+        assertEquals(retrievedSavedNetworks.get(0).getProfileKeyInternal(),
+                pskNetwork.getProfileKeyInternal());
         assertPasswordsMaskedInWifiConfiguration(retrievedSavedNetworks.get(0));
     }
 
@@ -1125,7 +1126,8 @@
         List<WifiConfiguration> retrievedSavedNetworks = mWifiConfigManager.getSavedNetworks(
                 Process.WIFI_UID);
         assertEquals(retrievedSavedNetworks.size(), 1);
-        assertEquals(retrievedSavedNetworks.get(0).getProfileKey(), wepNetwork.getProfileKey());
+        assertEquals(retrievedSavedNetworks.get(0).getProfileKeyInternal(),
+                wepNetwork.getProfileKeyInternal());
         assertPasswordsMaskedInWifiConfiguration(retrievedSavedNetworks.get(0));
     }
 
@@ -2666,7 +2668,8 @@
                 if (otherNetwork == network) {
                     continue;
                 }
-                assertNotNull(network.linkedConfigurations.get(otherNetwork.getProfileKey()));
+                assertNotNull(network.linkedConfigurations.get(
+                        otherNetwork.getProfileKeyInternal()));
             }
         }
     }
@@ -2749,7 +2752,8 @@
                 if (otherNetwork == network) {
                     continue;
                 }
-                assertNotNull(network.linkedConfigurations.get(otherNetwork.getProfileKey()));
+                assertNotNull(network.linkedConfigurations.get(
+                        otherNetwork.getProfileKeyInternal()));
             }
         }
     }
@@ -2854,7 +2858,8 @@
                 if (otherNetwork == network) {
                     continue;
                 }
-                assertNotNull(network.linkedConfigurations.get(otherNetwork.getProfileKey()));
+                assertNotNull(network.linkedConfigurations.get(
+                        otherNetwork.getProfileKeyInternal()));
             }
         }
 
@@ -2925,9 +2930,10 @@
         List<WifiConfiguration> retrievedNetworks =
                 mWifiConfigManager.getConfiguredNetworksWithPasswords();
         for (WifiConfiguration network : retrievedNetworks) {
-            if (network.getProfileKey().equals(sharedNetwork1.getProfileKey())) {
+            if (network.getProfileKeyInternal().equals(sharedNetwork1.getProfileKeyInternal())) {
                 sharedNetwork1Id = network.networkId;
-            } else if (network.getProfileKey().equals(sharedNetwork2.getProfileKey())) {
+            } else if (network.getProfileKeyInternal().equals(
+                    sharedNetwork2.getProfileKeyInternal())) {
                 sharedNetwork2Id = network.networkId;
             }
         }
@@ -2953,9 +2959,10 @@
         int updatedSharedNetwork2Id = WifiConfiguration.INVALID_NETWORK_ID;
         retrievedNetworks = mWifiConfigManager.getConfiguredNetworksWithPasswords();
         for (WifiConfiguration network : retrievedNetworks) {
-            if (network.getProfileKey().equals(sharedNetwork1.getProfileKey())) {
+            if (network.getProfileKeyInternal().equals(sharedNetwork1.getProfileKeyInternal())) {
                 updatedSharedNetwork1Id = network.networkId;
-            } else if (network.getProfileKey().equals(sharedNetwork2.getProfileKey())) {
+            } else if (network.getProfileKeyInternal().equals(
+                    sharedNetwork2.getProfileKeyInternal())) {
                 updatedSharedNetwork2Id = network.networkId;
             }
         }
@@ -3008,7 +3015,7 @@
         List<WifiConfiguration> retrievedNetworks =
                 mWifiConfigManager.getConfiguredNetworksWithPasswords();
         for (WifiConfiguration network : retrievedNetworks) {
-            if (network.getProfileKey().equals(user1Network.getProfileKey())) {
+            if (network.getProfileKeyInternal().equals(user1Network.getProfileKeyInternal())) {
                 user1NetworkId = network.networkId;
             }
         }
@@ -3075,7 +3082,7 @@
         List<WifiConfiguration> retrievedNetworks =
                 mWifiConfigManager.getConfiguredNetworksWithPasswords();
         for (WifiConfiguration network : retrievedNetworks) {
-            if (network.getProfileKey().equals(ephemeralNetwork.getProfileKey())) {
+            if (network.getProfileKeyInternal().equals(ephemeralNetwork.getProfileKeyInternal())) {
                 ephemeralNetworkId = network.networkId;
             }
         }
@@ -3748,7 +3755,7 @@
         assertTrue(mWifiConfigManager.enableNetwork(
                 result.getNetworkId(), true, TEST_CREATOR_UID, TEST_CREATOR_NAME));
         assertEquals(result.getNetworkId(), mWifiConfigManager.getLastSelectedNetwork());
-        assertEquals(openNetwork.getProfileKey(),
+        assertEquals(openNetwork.getProfileKeyInternal(),
                 mWifiConfigManager.getLastSelectedNetworkConfigKey());
 
         assertTrue(mWifiConfigManager.removeNetwork(
@@ -3805,7 +3812,7 @@
         WifiConfiguration preferred = mWifiConfigManager.getConfiguredNetwork(preferredNetId);
         assertNull(preferred.getNetworkSelectionStatus().getConnectChoice());
         WifiConfiguration notPreferred = mWifiConfigManager.getConfiguredNetwork(notPreferredNetId);
-        assertEquals(preferred.getProfileKey(),
+        assertEquals(preferred.getProfileKeyInternal(),
                 notPreferred.getNetworkSelectionStatus().getConnectChoice());
         assertEquals(TEST_RSSI, notPreferred.getNetworkSelectionStatus().getConnectChoiceRssi());
     }
@@ -3829,7 +3836,7 @@
         WifiConfiguration retrievedNetwork =
                 mWifiConfigManager.getConfiguredNetwork(network1.networkId);
         assertEquals(
-                network2.getProfileKey(),
+                network2.getProfileKeyInternal(),
                 retrievedNetwork.getNetworkSelectionStatus().getConnectChoice());
 
         // Remove network 3 and ensure that the connect choice on network 1 is not removed.
@@ -3837,7 +3844,7 @@
                 network3.networkId, TEST_CREATOR_UID, TEST_CREATOR_NAME));
         retrievedNetwork = mWifiConfigManager.getConfiguredNetwork(network1.networkId);
         assertEquals(
-                network2.getProfileKey(),
+                network2.getProfileKeyInternal(),
                 retrievedNetwork.getNetworkSelectionStatus().getConnectChoice());
 
         // Now remove network 2 and ensure that the connect choice on network 1 is removed..
@@ -3845,7 +3852,7 @@
                 network2.networkId, TEST_CREATOR_UID, TEST_CREATOR_NAME));
         retrievedNetwork = mWifiConfigManager.getConfiguredNetwork(network1.networkId);
         assertNotEquals(
-                network2.getProfileKey(),
+                network2.getProfileKeyInternal(),
                 retrievedNetwork.getNetworkSelectionStatus().getConnectChoice());
 
         // This should have triggered 2 buffered writes. 1 for setting the connect choice, 1 for
@@ -3874,7 +3881,7 @@
         WifiConfiguration retrievedNetwork =
                 mWifiConfigManager.getConfiguredNetwork(network3.networkId);
         assertEquals(
-                network2.getProfileKey(),
+                network2.getProfileKeyInternal(),
                 retrievedNetwork.getNetworkSelectionStatus().getConnectChoice());
 
         // Disable network 3
@@ -3887,10 +3894,10 @@
         // Ensure that the connect choice on network 1 is not removed.
         retrievedNetwork = mWifiConfigManager.getConfiguredNetwork(network1.networkId);
         assertEquals(
-                network2.getProfileKey(),
+                network2.getProfileKeyInternal(),
                 retrievedNetwork.getNetworkSelectionStatus().getConnectChoice());
 
-        verify(mListener).onConnectChoiceRemoved(network3.getProfileKey());
+        verify(mListener).onConnectChoiceRemoved(network3.getProfileKeyInternal());
     }
 
     /**
@@ -3930,7 +3937,7 @@
         assertFalse(mWifiConfigManager.removeAllEphemeralOrPasspointConfiguredNetworks());
 
         // Suggestion and passpoint network will not trigger conncet choice remove.
-        verify(mListener).onConnectChoiceRemoved(ephemeralNetwork.getProfileKey());
+        verify(mListener).onConnectChoiceRemoved(ephemeralNetwork.getProfileKeyInternal());
     }
 
     /**
@@ -3944,7 +3951,7 @@
         verifyAddPasspointNetworkToWifiConfigManager(passpointNetwork);
 
         assertTrue(mWifiConfigManager.removePasspointConfiguredNetwork(
-                passpointNetwork.getProfileKey()));
+                passpointNetwork.getProfileKeyInternal()));
     }
 
     /**
@@ -3959,7 +3966,7 @@
         verifyAddEphemeralNetworkToWifiConfigManager(suggestedNetwork);
 
         assertTrue(mWifiConfigManager.removeSuggestionConfiguredNetwork(
-                suggestedNetwork.getProfileKey()));
+                suggestedNetwork.getProfileKeyInternal()));
     }
 
     /**
@@ -4797,7 +4804,7 @@
         WifiConfiguration retrievedSavedNetwork =
                 mWifiConfigManager.getConfiguredNetwork(savedNetwork.networkId);
         assertEquals(
-                passpointNetwork.getProfileKey(),
+                passpointNetwork.getProfileKeyInternal(),
                 retrievedSavedNetwork.getNetworkSelectionStatus().getConnectChoice());
 
         // Disable the passpoint network & ensure the user choice is now removed from saved network.
@@ -4805,7 +4812,7 @@
 
         retrievedSavedNetwork = mWifiConfigManager.getConfiguredNetwork(savedNetwork.networkId);
         assertNull(retrievedSavedNetwork.getNetworkSelectionStatus().getConnectChoice());
-        verify(mListener).onConnectChoiceRemoved(passpointNetwork.getProfileKey());
+        verify(mListener).onConnectChoiceRemoved(passpointNetwork.getProfileKeyInternal());
     }
 
     @Test
@@ -5229,7 +5236,8 @@
             WifiConfiguration configuration, List<WifiConfiguration> networkList) {
         boolean foundNetworkInStoreData = false;
         for (WifiConfiguration retrievedConfig : networkList) {
-            if (retrievedConfig.getProfileKey().equals(configuration.getProfileKey())) {
+            if (retrievedConfig.getProfileKeyInternal().equals(
+                    configuration.getProfileKeyInternal())) {
                 foundNetworkInStoreData = true;
                 break;
             }
@@ -5861,7 +5869,7 @@
 
         configInLastNetworkSelection = mWifiConfigManager.getConfiguredNetwork(
                 configInLastNetworkSelection.networkId);
-        assertEquals(selectedWifiConfig.getProfileKey(),
+        assertEquals(selectedWifiConfig.getProfileKeyInternal(),
                 configInLastNetworkSelection.getNetworkSelectionStatus().getConnectChoice());
 
         configNotInLastNetworkSelection = mWifiConfigManager.getConfiguredNetwork(
@@ -5871,7 +5879,7 @@
         ArgumentCaptor<List<WifiConfiguration>> listArgumentCaptor =
                 ArgumentCaptor.forClass(List.class);
         verify(mListener).onConnectChoiceSet(listArgumentCaptor.capture(),
-                eq(selectedWifiConfig.getProfileKey()), eq(TEST_RSSI));
+                eq(selectedWifiConfig.getProfileKeyInternal()), eq(TEST_RSSI));
         Collection<WifiConfiguration> networks = listArgumentCaptor.getValue();
         assertEquals(1, networks.size());
     }
@@ -5918,7 +5926,7 @@
         ArgumentCaptor<List<WifiConfiguration>> listArgumentCaptor =
                 ArgumentCaptor.forClass(List.class);
         verify(mListener).onConnectChoiceSet(listArgumentCaptor.capture(),
-                eq(selectedWifiConfig.getProfileKey()), eq(TEST_RSSI));
+                eq(selectedWifiConfig.getProfileKeyInternal()), eq(TEST_RSSI));
         Collection<WifiConfiguration> networks = listArgumentCaptor.getValue();
         assertEquals(2, networks.size());
     }
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/service/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
index 1931108..fafc2ad 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
@@ -858,10 +858,10 @@
             List<WifiConfiguration> expected, List<WifiConfiguration> actual) {
         assertEquals(expected.size(), actual.size());
         for (WifiConfiguration expectedConfiguration : expected) {
-            String expectedConfigKey = expectedConfiguration.getProfileKey();
+            String expectedConfigKey = expectedConfiguration.getProfileKeyInternal();
             boolean didCompare = false;
             for (WifiConfiguration actualConfiguration : actual) {
-                String actualConfigKey = actualConfiguration.getProfileKey();
+                String actualConfigKey = actualConfiguration.getProfileKeyInternal();
                 if (actualConfigKey.equals(expectedConfigKey)) {
                     assertConfigurationEqualForBackup(
                             expectedConfiguration, actualConfiguration);
@@ -881,10 +881,10 @@
             List<WifiConfiguration> expected, List<WifiConfiguration> actual) {
         assertEquals(expected.size(), actual.size());
         for (WifiConfiguration expectedConfiguration : expected) {
-            String expectedConfigKey = expectedConfiguration.getProfileKey();
+            String expectedConfigKey = expectedConfiguration.getProfileKeyInternal();
             boolean didCompare = false;
             for (WifiConfiguration actualConfiguration : actual) {
-                String actualConfigKey = actualConfiguration.getProfileKey();
+                String actualConfigKey = actualConfiguration.getProfileKeyInternal();
                 if (actualConfigKey.equals(expectedConfigKey)) {
                     assertConfigurationEqualForConfigManagerAddOrUpdate(
                             expectedConfiguration, actualConfiguration);
@@ -903,10 +903,10 @@
             List<WifiConfiguration> expected, List<WifiConfiguration> actual) {
         assertEquals(expected.size(), actual.size());
         for (WifiConfiguration expectedConfiguration : expected) {
-            String expectedConfigKey = expectedConfiguration.getProfileKey();
+            String expectedConfigKey = expectedConfiguration.getProfileKeyInternal();
             boolean didCompare = false;
             for (WifiConfiguration actualConfiguration : actual) {
-                String actualConfigKey = actualConfiguration.getProfileKey();
+                String actualConfigKey = actualConfiguration.getProfileKeyInternal();
                 if (actualConfigKey.equals(expectedConfigKey)) {
                     assertConfigurationEqualForConfigStore(
                             expectedConfiguration, actualConfiguration);
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index a016b08..0e1ffe4 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -2326,7 +2326,7 @@
         config.networkId = TEST_CONNECTED_NETWORK_ID;
         String networkKey = "NETWORK_KEY";
         when(mWifiConfigManager.getConfiguredNetwork(networkKey)).thenReturn(config);
-        when(mSuggestionConfig.getProfileKey()).thenReturn(networkKey);
+        when(mSuggestionConfig.getProfileKeyInternal()).thenReturn(networkKey);
         when(mWifiNetworkSuggestion.getWifiConfiguration()).thenReturn(mSuggestionConfig);
         Set<WifiNetworkSuggestion> suggestionNetworks = new HashSet<WifiNetworkSuggestion>();
         suggestionNetworks.add(mWifiNetworkSuggestion);
@@ -2377,7 +2377,7 @@
         config.networkId = TEST_CONNECTED_NETWORK_ID;
         String networkKey = "NETWORK_KEY";
         when(mWifiConfigManager.getConfiguredNetwork(networkKey)).thenReturn(config);
-        when(mSuggestionConfig.getProfileKey()).thenReturn(networkKey);
+        when(mSuggestionConfig.getProfileKeyInternal()).thenReturn(networkKey);
         when(mWifiNetworkSuggestion.getWifiConfiguration()).thenReturn(mSuggestionConfig);
         Set<WifiNetworkSuggestion> suggestionNetworks = new HashSet<WifiNetworkSuggestion>();
         suggestionNetworks.add(mWifiNetworkSuggestion);
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index cc0a725..2ceb3ee 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -1342,7 +1342,7 @@
         // Have a saved network with the same configuration.
         WifiConfiguration matchingSavedNetwork = new WifiConfiguration(mSelectedNetwork);
         matchingSavedNetwork.networkId = TEST_NETWORK_ID_1;
-        when(mWifiConfigManager.getConfiguredNetwork(mSelectedNetwork.getProfileKey()))
+        when(mWifiConfigManager.getConfiguredNetwork(mSelectedNetwork.getProfileKeyInternal()))
                 .thenReturn(matchingSavedNetwork);
 
         // Now trigger user selection to one of the network.
@@ -1995,7 +1995,7 @@
         wcmNetwork.shared = false;
         wcmNetwork.fromWifiNetworkSpecifier = true;
         wcmNetwork.ephemeral = true;
-        when(mWifiConfigManager.getConfiguredNetwork(wcmNetwork.getProfileKey()))
+        when(mWifiConfigManager.getConfiguredNetwork(wcmNetwork.getProfileKeyInternal()))
                 .thenReturn(wcmNetwork);
         mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
         // verify we canceled the timeout alarm.
@@ -2035,7 +2035,7 @@
         wcmNetwork.shared = false;
         wcmNetwork.fromWifiNetworkSpecifier = true;
         wcmNetwork.ephemeral = true;
-        when(mWifiConfigManager.getConfiguredNetwork(wcmNetwork.getProfileKey()))
+        when(mWifiConfigManager.getConfiguredNetwork(wcmNetwork.getProfileKeyInternal()))
                 .thenReturn(wcmNetwork);
         mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest);
         // Verify that we triggered a disconnect.
@@ -3365,7 +3365,7 @@
         @Override
         public boolean matches(WifiConfiguration otherConfig) {
             if (otherConfig == null) return false;
-            return mConfig.getProfileKey().equals(otherConfig.getProfileKey());
+            return mConfig.getProfileKeyInternal().equals(otherConfig.getProfileKeyInternal());
         }
     }
 
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
index 2a7ef15..de5a09f 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
@@ -870,7 +870,7 @@
         // set user connect choice
         userChoice.getNetworkSelectionStatus().setConnectChoice(null);
         networkSelectorChoice.getNetworkSelectionStatus()
-                .setConnectChoice(userChoice.getProfileKey());
+                .setConnectChoice(userChoice.getProfileKeyInternal());
 
         // After user connect choice is set, userChoice should override networkSelectorChoice.
         candidates = mWifiNetworkSelector.getCandidatesFromScan(
@@ -917,7 +917,7 @@
         userChoice.getNetworkSelectionStatus().setCandidate(scanDetails.get(1).getScanResult());
         userChoice.getNetworkSelectionStatus().setConnectChoice(null);
         networkSelectorChoice.getNetworkSelectionStatus()
-                .setConnectChoice(userChoice.getProfileKey());
+                .setConnectChoice(userChoice.getProfileKeyInternal());
         networkSelectorChoice.getNetworkSelectionStatus()
                 .setConnectChoiceRssi(observedUserChoiceRssi
                         + mScoringParams.getEstimateRssiErrorMargin());
@@ -976,7 +976,7 @@
         userChoice.getNetworkSelectionStatus().setCandidate(scanDetails.get(1).getScanResult());
         userChoice.getNetworkSelectionStatus().setConnectChoice(null);
         networkSelectorChoice.getNetworkSelectionStatus()
-                .setConnectChoice(userChoice.getProfileKey());
+                .setConnectChoice(userChoice.getProfileKeyInternal());
 
         // Verify that the user connect choice network is chosen.
         List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan(
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java
index f966414..1a341f5 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java
@@ -317,7 +317,7 @@
                 .then(new AnswerWithArguments() {
                     public WifiConfiguration answer(String configKey) {
                         for (WifiConfiguration config : configs) {
-                            if (TextUtils.equals(config.getProfileKey(), configKey)) {
+                            if (TextUtils.equals(config.getProfileKeyInternal(), configKey)) {
                                 return new WifiConfiguration(config);
                             }
                         }
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 5fa3991..73915c0 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -673,9 +673,9 @@
 
         // Nothing in WCM.
         when(mWifiConfigManager.getConfiguredNetwork(networkSuggestion1.wifiConfiguration
-                .getProfileKey())).thenReturn(null);
+                .getProfileKeyInternal())).thenReturn(null);
         when(mWifiConfigManager.getConfiguredNetwork(networkSuggestion2.wifiConfiguration
-                .getProfileKey())).thenReturn(null);
+                .getProfileKeyInternal())).thenReturn(null);
 
         // Modify the same suggestion to mark it auto-join disabled.
         WifiNetworkSuggestion networkSuggestion3 = createWifiNetworkSuggestion(
@@ -2114,7 +2114,7 @@
                 mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1,
                         TEST_PACKAGE_1));
         verify(mWifiConfigManager).removeSuggestionConfiguredNetwork(
-                networkSuggestion.wifiConfiguration.getProfileKey());
+                networkSuggestion.wifiConfiguration.getProfileKeyInternal());
     }
 
     /**
@@ -2150,7 +2150,7 @@
                 mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_UID_1,
                         TEST_PACKAGE_1));
         verify(mWifiConfigManager).removeSuggestionConfiguredNetwork(
-                networkSuggestion.wifiConfiguration.getProfileKey());
+                networkSuggestion.wifiConfiguration.getProfileKeyInternal());
     }
 
 
@@ -2198,7 +2198,7 @@
         // Now remove the current connected app and ensure we did trigger a disconnect.
         mWifiNetworkSuggestionsManager.removeApp(TEST_PACKAGE_1);
         verify(mWifiConfigManager).removeSuggestionConfiguredNetwork(
-                networkSuggestion1.wifiConfiguration.getProfileKey());
+                networkSuggestion1.wifiConfiguration.getProfileKeyInternal());
 
         // Now remove the other app and ensure we did not trigger a disconnect.
         mWifiNetworkSuggestionsManager.removeApp(TEST_PACKAGE_2);
@@ -3648,7 +3648,7 @@
     private void setupGetConfiguredNetworksFromWcm(WifiConfiguration...configs) {
         for (int i = 0; i < configs.length; i++) {
             WifiConfiguration config = configs[i];
-            when(mWifiConfigManager.getConfiguredNetwork(config.getProfileKey()))
+            when(mWifiConfigManager.getConfiguredNetwork(config.getProfileKeyInternal()))
                     .thenReturn(config);
         }
     }
@@ -4444,7 +4444,7 @@
                 mock(WifiConfiguration.NetworkSelectionStatus.class);
         when(status.isNetworkEnabled()).thenReturn(false);
         wcmConfig.setNetworkSelectionStatus(status);
-        when(mWifiConfigManager.getConfiguredNetwork(wcmConfig.getProfileKey()))
+        when(mWifiConfigManager.getConfiguredNetwork(wcmConfig.getProfileKeyInternal()))
                 .thenReturn(wcmConfig);
 
         List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2);
diff --git a/service/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
index 1c41174..d206417 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -629,7 +629,7 @@
 
         verify(provider).uninstallCertsAndKeys();
         verify(mWifiConfigManager, times(3)).removePasspointConfiguredNetwork(
-                provider.getWifiConfig().getProfileKey());
+                provider.getWifiConfig().getProfileKeyInternal());
         /**
          * 1 from |removeProvider| + 2 from |setAutojoinEnabled| + 2 from
          * |enableMacRandomization| + 2 from |setMeteredOverride| = 7 calls to |saveToStore|
@@ -715,7 +715,7 @@
         assertTrue(mManager.enableMacRandomization(provider.getConfig().getHomeSp().getFqdn(),
                 true));
         verify(mWifiConfigManager, times(2)).removePasspointConfiguredNetwork(
-                provider.getWifiConfig().getProfileKey());
+                provider.getWifiConfig().getProfileKeyInternal());
         verify(mWifiMetrics).logUserActionEvent(
                 UserActionEvent.EVENT_CONFIGURE_MAC_RANDOMIZATION_ON, false, true);
         verify(provider).setMacRandomizationEnabled(true);
@@ -773,7 +773,7 @@
         assertTrue(mManager.removeProvider(TEST_UID, true, null, TEST_FQDN));
         verify(provider).uninstallCertsAndKeys();
         verify(mWifiConfigManager).removePasspointConfiguredNetwork(
-                provider.getWifiConfig().getProfileKey());
+                provider.getWifiConfig().getProfileKeyInternal());
         verify(mWifiConfigManager).saveToStore(true);
         verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
         verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess();
@@ -862,7 +862,7 @@
         // Add same provider as existing suggestion provider
         // This should be no WifiConfig deletion
         WifiConfiguration origWifiConfig = origProvider.getWifiConfig();
-        when(mWifiConfigManager.getConfiguredNetwork(origWifiConfig.getProfileKey()))
+        when(mWifiConfigManager.getConfiguredNetwork(origWifiConfig.getProfileKeyInternal()))
                 .thenReturn(origWifiConfig);
         when(mWifiConfigManager.addOrUpdateNetwork(
                 origWifiConfig, TEST_CREATOR_UID, TEST_PACKAGE))
@@ -870,7 +870,7 @@
         assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE,
                 false, true));
         verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork(
-                origWifiConfig.getProfileKey());
+                origWifiConfig.getProfileKeyInternal());
         verify(mWifiConfigManager).addOrUpdateNetwork(
                 argThat((c) -> c.FQDN.equals(TEST_FQDN)), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE));
         verify(mWifiConfigManager).allowAutojoin(TEST_NETWORK_ID, origWifiConfig.allowAutojoin);
@@ -889,8 +889,8 @@
         when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore),
                 eq(mWifiCarrierInfoManager), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
                 eq(false), eq(mClock))).thenReturn(newProvider);
-        when(mWifiConfigManager.getConfiguredNetwork(origProvider.getWifiConfig().getProfileKey()))
-                .thenReturn(origWifiConfig);
+        when(mWifiConfigManager.getConfiguredNetwork(origProvider.getWifiConfig()
+                .getProfileKeyInternal())).thenReturn(origWifiConfig);
         assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE,
                 false, true));
 
@@ -1952,7 +1952,7 @@
 
         verify(mAppOpsManager).stopWatchingMode(mAppOpChangedListenerCaptor.getValue());
         verify(mWifiConfigManager).removePasspointConfiguredNetwork(
-                passpointProvider.getWifiConfig().getProfileKey());
+                passpointProvider.getWifiConfig().getProfileKeyInternal());
         assertTrue(mManager.getProviderConfigs(TEST_CREATOR_UID, true).isEmpty());
     }
 
@@ -2056,7 +2056,7 @@
         assertFalse(mManager.removeProvider(TEST_UID, false, null, TEST_FQDN));
         verify(provider, never()).uninstallCertsAndKeys();
         verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork(
-                provider.getWifiConfig().getProfileKey());
+                provider.getWifiConfig().getProfileKeyInternal());
         verify(mWifiConfigManager, never()).saveToStore(true);
         verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
         verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess();
@@ -2075,7 +2075,7 @@
         assertTrue(mManager.removeProvider(TEST_CREATOR_UID, false, null, TEST_FQDN));
         verify(provider).uninstallCertsAndKeys();
         verify(mWifiConfigManager).removePasspointConfiguredNetwork(
-                provider.getWifiConfig().getProfileKey());
+                provider.getWifiConfig().getProfileKeyInternal());
         verify(mWifiConfigManager).saveToStore(true);
         verify(mWifiMetrics).incrementNumPasspointProviderUninstallation();
         verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess();
@@ -2125,7 +2125,7 @@
         origWifiConfig.fromWifiNetworkSuggestion = true;
         origWifiConfig.creatorUid = TEST_CREATOR_UID;
         origWifiConfig.creatorName = TEST_PACKAGE;
-        when(mWifiConfigManager.getConfiguredNetwork(origWifiConfig.getProfileKey()))
+        when(mWifiConfigManager.getConfiguredNetwork(origWifiConfig.getProfileKeyInternal()))
                 .thenReturn(origWifiConfig);
         when(mWifiConfigManager.addOrUpdateNetwork(
                 origWifiConfig, TEST_CREATOR_UID, TEST_PACKAGE))
@@ -2133,7 +2133,7 @@
         assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE,
                 true, true));
         verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork(
-                origWifiConfig.getProfileKey());
+                origWifiConfig.getProfileKeyInternal());
         verify(mWifiConfigManager).addOrUpdateNetwork(
                 argThat((c) -> c.FQDN.equals(TEST_FQDN)), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE));
         verify(mWifiConfigManager).allowAutojoin(TEST_NETWORK_ID, origWifiConfig.allowAutojoin);
@@ -2573,13 +2573,13 @@
 
         verify(provider1).uninstallCertsAndKeys();
         verify(mWifiConfigManager, times(1)).removePasspointConfiguredNetwork(
-                provider1.getWifiConfig().getProfileKey());
+                provider1.getWifiConfig().getProfileKeyInternal());
         verify(provider2).uninstallCertsAndKeys();
         verify(mWifiConfigManager, times(1)).removePasspointConfiguredNetwork(
-                provider2.getWifiConfig().getProfileKey());
+                provider2.getWifiConfig().getProfileKeyInternal());
         verify(provider3).uninstallCertsAndKeys();
         verify(mWifiConfigManager, times(1)).removePasspointConfiguredNetwork(
-                provider3.getWifiConfig().getProfileKey());
+                provider3.getWifiConfig().getProfileKeyInternal());
 
         verify(mWifiMetrics, times(3)).incrementNumPasspointProviderUninstallation();
         verify(mWifiMetrics, times(3)).incrementNumPasspointProviderUninstallSuccess();