wifi: support SAE password identifier in wifi dialog

Bug: 138305265
Test: atest FrameworksWifiApiTests
Test: atest FrameworksWifiTests
Test: connect to a WPA3 SAE access point with different
      password/identifer combinations.

Change-Id: Idf1f82faaafa9c5f2212a0fa1dcc2eec53a9dbd5
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index b9a910b..83a0833 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -311,6 +311,25 @@
                         style="@style/wifi_item_content"
                         android:text="@string/wifi_show_password" />
             </LinearLayout>
+
+            <LinearLayout android:id="@+id/sae_password_id_layout"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    style="@style/wifi_item"
+                    android:visibility="gone">
+                <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_label"
+                        android:text="@string/wifi_sae_password_id" />
+
+                <EditText android:id="@+id/sae_password_id"
+                          android:layout_width="match_parent"
+                          android:layout_height="wrap_content"
+                          style="@style/wifi_item_edit_content"
+                          android:singleLine="true"
+                          android:inputType="textNoSuggestions" />
+            </LinearLayout>
         </LinearLayout>
 
         <LinearLayout android:id="@+id/wifi_advanced_toggle"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 94eb5bf..6a15a94 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2143,6 +2143,8 @@
     <string name="wifi_eap_anonymous">Anonymous identity</string>
     <!-- Label for the password of the secured network -->
     <string name="wifi_password">Password</string>
+    <!-- Label for the sae password id of the secured network [CHAR LIMIT=32] -->
+    <string name="wifi_sae_password_id">SAE password identifier</string>
     <!-- Label for the check box to show password -->
     <string name="wifi_show_password">Show password</string>
     <!-- Label for the RadioGroup to choose wifi ap band -->
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index df6e470..83b7baf 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -131,6 +131,7 @@
     @VisibleForTesting
     int mAccessPointSecurity;
     private TextView mPasswordView;
+    private TextView mSaePasswordIdView;
     private ImageButton mSsidScanButton;
 
     private String mUnspecifiedCertString;
@@ -786,6 +787,11 @@
                     String password = mPasswordView.getText().toString();
                     config.preSharedKey = '"' + password + '"';
                 }
+                if (mSaePasswordIdView.length() != 0) {
+                    config.saePasswordId = mSaePasswordIdView.getText().toString();
+                } else {
+                    config.saePasswordId = null;
+                }
                 break;
 
             case AccessPoint.SECURITY_OWE:
@@ -968,6 +974,23 @@
             }
         }
 
+        if (mSaePasswordIdView == null) {
+            mSaePasswordIdView = (TextView) mView.findViewById(R.id.sae_password_id);
+            mSaePasswordIdView.setOnEditorActionListener(this);
+            mSaePasswordIdView.setOnKeyListener(this);
+        }
+
+        if (mAccessPointSecurity == AccessPoint.SECURITY_SAE) {
+            mView.findViewById(R.id.sae_password_id_layout).setVisibility(View.VISIBLE);
+            if (mAccessPoint != null && mAccessPoint.isSaved()) {
+                if (!TextUtils.isEmpty(mAccessPoint.getConfig().saePasswordId)) {
+                    mSaePasswordIdView.setText(mAccessPoint.getConfig().saePasswordId);
+                }
+            }
+        } else {
+            setSaePasswordIdInvisible();
+        }
+
         if (mAccessPointSecurity != AccessPoint.SECURITY_EAP &&
                 mAccessPointSecurity != AccessPoint.SECURITY_EAP_SUITE_B) {
             mView.findViewById(R.id.eap).setVisibility(View.GONE);
@@ -1249,6 +1272,11 @@
         mView.findViewById(R.id.show_password_layout).setVisibility(View.GONE);
     }
 
+    private void setSaePasswordIdInvisible() {
+        mSaePasswordIdView.setText("");
+        mView.findViewById(R.id.sae_password_id_layout).setVisibility(View.GONE);
+    }
+
     private void setEapMethodInvisible() {
         mView.findViewById(R.id.eap).setVisibility(View.GONE);
     }