[Carrier Wi-Fi] Reset config identity on reboot or SIM in/out

For Carrier Wi-Fi configurations reset the complete configuration
identity - not just the anonymous identity. This will ensure that
the encrypted identity is queried for and used for the EAP-SIM
negotiations.

Bug: 118818180
Test: atest frameworks/opt/net/wifi/tests/wifitests
Test: integration/sanity testing passes, ref: b/119678669
Merged-In: I4ebf85a524473bf28ce2245b1e85ed933ba208c2
Change-Id: I4ebf85a524473bf28ce2245b1e85ed933ba208c2
(cherry picked from commit 6d37c0e7b156dc26b177858111eee2f33dad9582)
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 0b70dbf..7dc938b 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -2470,13 +2470,23 @@
                     currentIdentity = TelephonyUtil.getSimIdentity(mTelephonyManager,
                         new TelephonyUtil(), config);
                 }
+                if (mVerboseLoggingEnabled) {
+                    Log.d(TAG, "New identity for config " + config + ": " + currentIdentity);
+                }
+
                 // Update the loaded config
                 if (currentIdentity == null) {
-                    Log.d(TAG, "Identity is null");
-                    return;
+                    Log.d(TAG, "Identity is null for config:" + config);
+                    break;
                 }
-                config.enterpriseConfig.setIdentity(currentIdentity.first);
-                if (config.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.PEAP) {
+
+                if (config.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.PEAP) {
+                    config.enterpriseConfig.setIdentity(currentIdentity.first);
+                    // do not reset anonymous identity since it may be dependent on user-entry
+                    // (i.e. cannot re-request on every reboot/SIM re-entry)
+                } else {
+                    // reset identity as well: supplicant will ask us for it
+                    config.enterpriseConfig.setIdentity("");
                     config.enterpriseConfig.setAnonymousIdentity("");
                 }
             }