Merge cherrypicks of ['googleplex-android-review.googlesource.com/22513714', 'googleplex-android-review.googlesource.com/22517511'] into sparse-9945958-L50800000960300293.
SPARSE_CHANGE: I843f28b80d7d372d2c995b77fd4e3acbd1edc35c
SPARSE_CHANGE: I57545bc8a227df751fdeff17be20aca08e96305b

Change-Id: Ibd6f2f22f4fe9ac837db40bb766592bc376a3b04
diff --git a/stats/Android.bp b/stats/Android.bp
index c1cde30..b4cbfc1 100644
--- a/stats/Android.bp
+++ b/stats/Android.bp
@@ -80,6 +80,7 @@
     "attribution_node.proto",
     "atoms/gps/*.proto",
     "atoms/adservices/*.proto",
+    "atoms/expresslog/*.proto",
     "atoms/providers/mediaprovider/*.proto",
     "atoms/wifi/*.proto",
     "atoms/bluetooth/*.proto",
diff --git a/stats/atoms.proto b/stats/atoms.proto
index 69e9a09..95ed442 100644
--- a/stats/atoms.proto
+++ b/stats/atoms.proto
@@ -777,6 +777,8 @@
 
     // Pushed atom extensions.
     // The atom definitions are under atoms/<feature>/<feature>_extension_atoms.proto
+    extensions 528; // ExpressEventReported express_event_reported
+    extensions 593; // ExpressHistogramSampleReported express_histogram_sample_reported
     extensions 598; // AdServicesBackCompatGetTopicsReported ad_services_back_compat_get_topics_reported
     extensions 599; // AdServicesBackCompatEpochComputationClassifierReported ad_services_back_compat_epoch_computation_classifier_reported
     extensions 613; // BluetoothHashedDeviceNameReported bluetooth_hashed_device_name_reported
@@ -785,8 +787,11 @@
     extensions 638; // WifiAwareNdpReported wifi_aware_ndp_reported
     extensions 639; // WifiAwareAttachReported wifi_aware_attach_reported
     extensions 640; // AdServicesMeasurementDebugKeys ad_services_measurement_debug_keys
+    extensions 644; // ExpressUidEventReported express_uid_event_reported
     extensions 650; // DailykeepaliveInfoReported daily_keepalive_info_reported
     extensions 656; // BluetoothLeSessionConnected bluetooth_le_session_connected
+    extensions 658; // ExpressUidHistogramSampleReported express_uid_histogram_sample_reported
+    extensions 662; // AdServicesErrorReported ad_services_error_reported
     extensions 9999; // Atom9999 atom_9999
 
     // Pulled events will start at field 10000.
diff --git a/stats/atoms/adservices/adservices_extension_atoms.proto b/stats/atoms/adservices/adservices_extension_atoms.proto
index de92827..abe4304 100644
--- a/stats/atoms/adservices/adservices_extension_atoms.proto
+++ b/stats/atoms/adservices/adservices_extension_atoms.proto
@@ -35,6 +35,9 @@
   optional AdServicesMeasurementDebugKeys
       ad_services_measurement_debug_keys = 640
         [(module) = "adservices", (truncate_timestamp) = true];
+  optional AdServicesErrorReported
+      ad_services_error_reported = 662
+        [(module) = "adservices", (truncate_timestamp) = true];
 }
 
 /**
@@ -130,3 +133,48 @@
   optional int64 join_key_hash_limit = 5;
 }
 
+/**
+ * Logs AdServices errors/exceptions.
+ */
+message AdServicesErrorReported {
+  // Enum representing an error/exception.  These errors can be common to all
+  // PPAPIs or specific to a particular API. We will group enums in blocks of
+  // 1000 like this below:
+  // - Common errors: 1-1000
+  // - Topics errors: 1001-2000
+  // - Measurement errors: 2001-3000
+  // - Fledge errors: 3001-4000
+  // - UX errors: 4001-5000
+  enum ErrorCode {
+    ERROR_CODE_UNSPECIFIED = 0;
+    DATABASE_READ_EXCEPTION = 1;
+    DATABASE_WRITE_EXCEPTION = 2;
+    API_REMOTE_EXCEPTION = 3;
+
+    // UX errors
+    CONSENT_REVOKED_ERROR = 4001;
+  }
+  // Enum representing an error/exception.
+  optional ErrorCode error_code = 1;
+
+  enum PpapiName {
+    PPAPI_NAME_UNSPECIFIED = 0;
+    TOPICS = 1;
+    MEASUREMENT = 2;
+    FLEDGE = 3;
+  }
+  // Name of the PPAPI if possible where error is occurring.
+  optional PpapiName ppapi_name = 2;
+
+  // Name of the class where we catch the exception or log the error.
+  optional string class_name = 3;
+
+  // Name of the method where we catch the exception or log the error.
+  optional string method_name = 4;
+
+  // Line number where we catch the exception or log the error.
+  optional int32 line_number = 5;
+
+  // The fully qualified name of the last encountered exception.
+  optional string last_observed_exception_name = 6;
+}
diff --git a/stats/atoms/expresslog/expresslog_extension_atoms.proto b/stats/atoms/expresslog/expresslog_extension_atoms.proto
new file mode 100644
index 0000000..d2172e2
--- /dev/null
+++ b/stats/atoms/expresslog/expresslog_extension_atoms.proto
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+
+package android.os.statsd.expresslog;
+
+import "frameworks/proto_logging/stats/atoms.proto";
+import "frameworks/proto_logging/stats/atom_field_options.proto";
+
+option java_package = "com.android.os.expresslog";
+option java_multiple_files = true;
+
+extend Atom {
+    optional ExpressEventReported express_event_reported =
+            528 [(module) = "framework", (module) = "expresslog"];
+    optional ExpressHistogramSampleReported express_histogram_sample_reported =
+            593 [(module) = "framework", (module) = "expresslog"];
+    optional ExpressUidEventReported express_uid_event_reported =
+            644 [(module) = "framework", (module) = "expresslog"];
+    optional ExpressUidHistogramSampleReported express_uid_histogram_sample_reported =
+            658 [(module) = "framework", (module) = "expresslog"];
+}
+
+/*
+ * Logs by Express library.
+ */
+message ExpressEventReported {
+    optional int64 metric_id = 1;
+
+    // for counter metric it is an incremental amount
+    optional int64 value = 2;
+}
+
+/*
+ * Logs by Express library.
+ */
+message ExpressUidEventReported {
+    optional int64 metric_id = 1;
+
+    // for counter metric it is an incremental amount
+    optional int64 value = 2;
+
+    // will be used as uid dimension.
+    optional int32 uid = 3 [(is_uid) = true];
+}
+
+/*
+ * Logs by Express library.
+ */
+message ExpressHistogramSampleReported {
+    optional int64 metric_id = 1;
+
+    // will be used as a samples count increment value per bin
+    optional int64 count = 2;
+
+    // will be used as a dimension to represent the bin index
+    // dim[0] .. dim[bins_count - 1] - valid samples count bins
+    // 2 extra bins reserved to represent underflow/overflow
+    // dim[bins_count] - could be considered as an underflow bin
+    // dim[bins_count + 1] - could be considered as an overflow bin
+    optional int32 bin_index = 3;
+}
+
+/*
+ * Logs by Express library.
+ */
+ message ExpressUidHistogramSampleReported {
+    optional int64 metric_id = 1;
+
+    // will be used as a samples count increment value per bin
+    optional int64 count = 2;
+
+    // will be used as a dimension to represent the bin index
+    // dim[0] .. dim[bins_count - 1] - valid samples count bins
+    // 2 extra bins reserved to represent underflow/overflow
+    // dim[bins_count] - could be considered as an underflow bin
+    // dim[bins_count + 1] - could be considered as an overflow bin
+    optional int32 bin_index = 3;
+
+    // will be used as uid dimension.
+    optional int32 uid = 4 [(is_uid) = true];
+}