[Passpoint] Add metrics to indicate OSU provisioned profile

Added a new boolean flag that indicates if the profile that is
currently used for a connection was provisioned by an OSU server.

Updated-PDD: TRUE
Bug: 156117292
Test: atest WifiMetricsTest
Test: dumpsys wifi
Change-Id: Ia555f9791b15be06f4bc0765315ab34d261bcf07
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index 72c52bd..a7544e0 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -44,6 +44,7 @@
 import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.telephony.TelephonyManager;
+import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Base64;
 import android.util.Log;
@@ -1111,6 +1112,7 @@
                 }
                 sb.append(", numConsecutiveConnectionFailure="
                         + mConnectionEvent.numConsecutiveConnectionFailure);
+                sb.append(", isOsuProvisioned=" + mConnectionEvent.isOsuProvisioned);
             }
             return sb.toString();
         }
@@ -1460,9 +1462,12 @@
                         mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(config.SSID);
                 mCurrentConnectionEvent.mConnectionEvent.networkType =
                         WifiMetricsProto.ConnectionEvent.TYPE_UNKNOWN;
+                mCurrentConnectionEvent.mConnectionEvent.isOsuProvisioned = false;
                 if (config.isPasspoint()) {
                     mCurrentConnectionEvent.mConnectionEvent.networkType =
                             WifiMetricsProto.ConnectionEvent.TYPE_PASSPOINT;
+                    mCurrentConnectionEvent.mConnectionEvent.isOsuProvisioned =
+                            !TextUtils.isEmpty(config.updateIdentifier);
                 } else if (WifiConfigurationUtil.isConfigForSaeNetwork(config)) {
                     mCurrentConnectionEvent.mConnectionEvent.networkType =
                             WifiMetricsProto.ConnectionEvent.TYPE_WPA3;
@@ -3097,7 +3102,7 @@
                 for (ConnectionEvent event : mConnectionEventList) {
                     String eventLine = event.toString();
                     if (event == mCurrentConnectionEvent) {
-                        eventLine += "CURRENTLY OPEN EVENT";
+                        eventLine += " CURRENTLY OPEN EVENT";
                     }
                     pw.println(eventLine);
                 }
diff --git a/service/proto/src/metrics.proto b/service/proto/src/metrics.proto
index e7c0ec8..9cb9244 100644
--- a/service/proto/src/metrics.proto
+++ b/service/proto/src/metrics.proto
@@ -1109,6 +1109,9 @@
   // middle won't break the streak count. The count is cleared after
   // a network disconnection event.
   optional int32 num_consecutive_connection_failure = 19 [default = -1];
+
+  // Indicates if the profile used for the connection was provisioned by Passpoint OSU server
+  optional bool is_osu_provisioned = 20;
 }
 
 // Number of occurrences of a specific RSSI poll rssi value
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index 198eb07..4e895e4 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -1762,10 +1762,11 @@
         assertEquals(1, mDecodedProto.connectionEvent.length);
         assertEquals(WifiMetricsProto.ConnectionEvent.TYPE_OPEN,
                 mDecodedProto.connectionEvent[0].networkType);
+        assertFalse(mDecodedProto.connectionEvent[0].isOsuProvisioned);
     }
 
     /**
-     * Verify the ConnectionEvent is labeled with networkType passpoint correctly.
+     * Verify the ConnectionEvent is labeled with networkType Passpoint correctly.
      */
     @Test
     public void testConnectionNetworkTypePasspoint() throws Exception {
@@ -1781,6 +1782,7 @@
         assertEquals(1, mDecodedProto.connectionEvent.length);
         assertEquals(WifiMetricsProto.ConnectionEvent.TYPE_PASSPOINT,
                 mDecodedProto.connectionEvent[0].networkType);
+        assertFalse(mDecodedProto.connectionEvent[0].isOsuProvisioned);
     }
 
     /**
@@ -4995,4 +4997,26 @@
         assertEquals(2, mDecodedProto.carrierWifiMetrics.numConnectionAuthFailure);
         assertEquals(3, mDecodedProto.carrierWifiMetrics.numConnectionNonAuthFailure);
     }
+
+    /**
+     * Verify the ConnectionEvent is labeled with networkType Passpoint correctly and that the OSU
+     * provisioned flag is set to true.
+     */
+    @Test
+    public void testConnectionNetworkTypePasspointFromOsu() throws Exception {
+        WifiConfiguration config = WifiConfigurationTestUtil.createPasspointNetwork();
+        config.updateIdentifier = "7";
+        mWifiMetrics.startConnectionEvent(config, "RED",
+                WifiMetricsProto.ConnectionEvent.ROAM_NONE);
+        mWifiMetrics.endConnectionEvent(
+                WifiMetrics.ConnectionEvent.FAILURE_ASSOCIATION_TIMED_OUT,
+                WifiMetricsProto.ConnectionEvent.HLF_NONE,
+                WifiMetricsProto.ConnectionEvent.FAILURE_REASON_UNKNOWN);
+        dumpProtoAndDeserialize();
+
+        assertEquals(1, mDecodedProto.connectionEvent.length);
+        assertEquals(WifiMetricsProto.ConnectionEvent.TYPE_PASSPOINT,
+                mDecodedProto.connectionEvent[0].networkType);
+        assertTrue(mDecodedProto.connectionEvent[0].isOsuProvisioned);
+    }
 }