Replace confirmConfiguration with updateLayer2Information.

Since updateLayer2Information has updated such BSSID, L2Key and
GroupHint information, we can check if the initial connection has
been established or L2 roaming happened with this method instead of
confirmConfiguration. Otherwise, it seems that we impose a calling
rule for the caller: *must* call updateLayer2Information first and
then confirmConfiguration followed. Ideally, we should deal with
this case only with one metohd.

Bug: 131797393
Test: atest FrameworksWifiTests

Merged-In: I623c83dbcc6b14ea59fda1d68e9b15f09fc64f06
Change-Id: I623c83dbcc6b14ea59fda1d68e9b15f09fc64f06
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 4ca7716..99fa7f5 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -3904,7 +3904,17 @@
                     // interest (e.g. routers); harmless if none are configured.
                     if (state == SupplicantState.COMPLETED) {
                         if (mIpClient != null) {
-                            mIpClient.confirmConfiguration();
+                            MacAddress lastBssid = null;
+                            try {
+                                lastBssid = (mLastBssid != null)
+                                        ? MacAddress.fromString(mLastBssid) : null;
+                            } catch (IllegalArgumentException e) {
+                                Log.e(TAG, "Invalid BSSID format: " + mLastBssid);
+                            }
+                            final Layer2Information info = new Layer2Information(
+                                    mLastL2KeyAndGroupHint.first, mLastL2KeyAndGroupHint.second,
+                                    lastBssid);
+                            mIpClient.updateLayer2Information(info);
                         }
                         mWifiScoreReport.noteIpCheck();
                     }
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 17fc1a7..66bde2f 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -3227,7 +3227,7 @@
         verify(mWifiScoreCard).noteIpConfiguration(any());
         ArgumentCaptor<Layer2InformationParcelable> captor =
                 ArgumentCaptor.forClass(Layer2InformationParcelable.class);
-        verify(mIpClient).updateLayer2Information(captor.capture());
+        verify(mIpClient, atLeastOnce()).updateLayer2Information(captor.capture());
         final Layer2InformationParcelable info = captor.getValue();
         assertEquals(info.l2Key, "Wad");
         assertEquals(info.groupHint, "Gab");