[WifiKeyStore] Check needKeyStore before requesting keyStore service

Fix crash in WifiKeyStore#updateNetworkKeys casued when calling keyStore
API when there are no stored keys. Such do not exist for non-TLS
connections.

Bug: 130386682
Test: Add WPA3-Enterprise with PWD, confirm no crash
Test: Add WPA3-Enterprise with RSA 3072 cert, confirm connection
Change-Id: I6bd5b199121d248bbadb281956a800115d6af409
diff --git a/service/java/com/android/server/wifi/WifiKeyStore.java b/service/java/com/android/server/wifi/WifiKeyStore.java
index a22be9b..c1706a2 100644
--- a/service/java/com/android/server/wifi/WifiKeyStore.java
+++ b/service/java/com/android/server/wifi/WifiKeyStore.java
@@ -278,22 +278,24 @@
      */
     public boolean updateNetworkKeys(WifiConfiguration config, WifiConfiguration existingConfig) {
         WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
-        if (needsKeyStore(enterpriseConfig)) {
-            try {
-                /* config passed may include only fields being updated.
-                 * In order to generate the key id, fetch uninitialized
-                 * fields from the currently tracked configuration
-                 */
-                String keyId = config.getKeyIdForCredentials(existingConfig);
-                if (!installKeys(existingConfig != null
-                        ? existingConfig.enterpriseConfig : null, enterpriseConfig, keyId)) {
-                    Log.e(TAG, config.SSID + ": failed to install keys");
-                    return false;
-                }
-            } catch (IllegalStateException e) {
-                Log.e(TAG, config.SSID + " invalid config for key installation: " + e.getMessage());
+        if (!needsKeyStore(enterpriseConfig)) {
+            return true;
+        }
+
+        try {
+            /* config passed may include only fields being updated.
+             * In order to generate the key id, fetch uninitialized
+             * fields from the currently tracked configuration
+             */
+            String keyId = config.getKeyIdForCredentials(existingConfig);
+            if (!installKeys(existingConfig != null
+                    ? existingConfig.enterpriseConfig : null, enterpriseConfig, keyId)) {
+                Log.e(TAG, config.SSID + ": failed to install keys");
                 return false;
             }
+        } catch (IllegalStateException e) {
+            Log.e(TAG, config.SSID + " invalid config for key installation: " + e.getMessage());
+            return false;
         }
 
         // For WPA3-Enterprise 192-bit networks, set the SuiteBCipher field based on the