[WifiInstaller] Remove Passpoint profile before installing am: 3c67dc05cc

Change-Id: Ica7be6b4417f298b22f934445d8c388b7e0c8a2a
diff --git a/src/com/android/certinstaller/WiFiInstaller.java b/src/com/android/certinstaller/WiFiInstaller.java
index 90b8eb7..41827f6 100644
--- a/src/com/android/certinstaller/WiFiInstaller.java
+++ b/src/com/android/certinstaller/WiFiInstaller.java
@@ -93,6 +93,13 @@
                         public void run() {
                             boolean success = true;
                             try {
+                                mWifiManager.removePasspointConfiguration(
+                                        mPasspointConfig.getHomeSp().getFqdn());
+                            } catch (IllegalArgumentException e) {
+                                // Do nothing. This is expected if a profile with this FQDN does not
+                                // exist.
+                            }
+                            try {
                                 mWifiManager.addOrUpdatePasspointConfiguration(mPasspointConfig);
                             } catch (RuntimeException rte) {
                                 Log.w(TAG, "Caught exception while installing wifi config: " +