Merge cherrypicks of ['googleplex-android-review.googlesource.com/22555708', 'googleplex-android-review.googlesource.com/22768635'] into sparse-10032660-L27900000960321115.
SPARSE_CHANGE: Ia22a120a5549c8d8c4188e54c39c6967ead7d8e9
SPARSE_CHANGE: I928cc0f666cb6cbcfc05d3a471af6a842d7015a5

Change-Id: I003cb0d3f08b3fc3f2bad8fbe218342b8eb9daf3
diff --git a/stats/Android.bp b/stats/Android.bp
index b4cbfc1..3e23d7a 100644
--- a/stats/Android.bp
+++ b/stats/Android.bp
@@ -23,6 +23,7 @@
 
 enum_protos = [
     "enums/adservices/fledge/*.proto",
+    "enums/adservices/measurement/*.proto",
     "enums/app/**/*.proto",
     "enums/contexthub/*.proto",
     "enums/debug/*.proto",
diff --git a/stats/atoms.proto b/stats/atoms.proto
index 95ed442..1a8b76e 100644
--- a/stats/atoms.proto
+++ b/stats/atoms.proto
@@ -27,6 +27,7 @@
 import "frameworks/proto_logging/stats/atoms/providers/mediaprovider/media_provider_atoms.proto";
 import "frameworks/proto_logging/stats/atom_field_options.proto";
 import "frameworks/proto_logging/stats/enums/adservices/fledge/enums.proto";
+import "frameworks/proto_logging/stats/enums/adservices/measurement/enums.proto";
 import "frameworks/proto_logging/stats/enums/app/enums.proto";
 import "frameworks/proto_logging/stats/enums/app/job/enums.proto";
 import "frameworks/proto_logging/stats/enums/app/remoteprovisioner_enums.proto";
@@ -792,6 +793,11 @@
     extensions 656; // BluetoothLeSessionConnected bluetooth_le_session_connected
     extensions 658; // ExpressUidHistogramSampleReported express_uid_histogram_sample_reported
     extensions 662; // AdServicesErrorReported ad_services_error_reported
+    extensions 663; // AdServicesBackgroundJobsExecutionReported ad_services_background_jobs_execution_reported
+    extensions 673; // AdServicesMeasurementDelayedSourceRegistration ad_services_measurement_delayed_source_registration
+    extensions 674; // AdServicesMeasurementAttribution ad_services_measurement_attribution
+    extensions 675; // AdServicesMeasurementJobs ad_services_measurement_jobs
+    extensions 676; // AdServicesMeasurementWipeout ad_services_measurement_wipeout
     extensions 9999; // Atom9999 atom_9999
 
     // Pulled events will start at field 10000.
@@ -21274,6 +21280,10 @@
     }
 
     optional ReportUploadStatus response_code = 2;
+    optional android.adservices.service.measurement.ReportUploadFailureType failure_type = 3;
+    optional android.adservices.service.measurement.ReportUploadMethod upload_method = 4;
+    // delay (in milliseconds) between scheduled delivery time and actual delivery time.
+    optional int64 reporting_delay_millis = 5;
 }
 
 /**
@@ -21289,6 +21299,12 @@
     optional RegistrationType type = 1;
     optional int64 response_size_in_bytes = 2;
     optional string adtech_url_domain_if_size_above_threshold = 3;
+    optional android.adservices.service.measurement.SourceType source_type = 4;
+    optional android.adservices.service.measurement.RegistrationSurfaceType surface_type = 5;
+    optional android.adservices.service.measurement.Status status = 6;
+    optional android.adservices.service.measurement.RegistrationFailureType failure_type = 7;
+    // delay (in milliseconds) between registration queue request and the time it gets processed
+    optional int64 registration_delay_millis = 8;
 }
 
 /**
diff --git a/stats/atoms/adservices/adservices_extension_atoms.proto b/stats/atoms/adservices/adservices_extension_atoms.proto
index abe4304..2c8cc23 100644
--- a/stats/atoms/adservices/adservices_extension_atoms.proto
+++ b/stats/atoms/adservices/adservices_extension_atoms.proto
@@ -20,6 +20,8 @@
 
 import "frameworks/proto_logging/stats/atoms.proto";
 import "frameworks/proto_logging/stats/atom_field_options.proto";
+import "frameworks/proto_logging/stats/enums/app/job/enums.proto";
+import "frameworks/proto_logging/stats/enums/adservices/measurement/enums.proto";
 
 option java_package = "com.android.os.adservices";
 option java_multiple_files = true;
@@ -38,6 +40,22 @@
   optional AdServicesErrorReported
       ad_services_error_reported = 662
         [(module) = "adservices", (truncate_timestamp) = true];
+  optional AdServicesBackgroundJobsExecutionReported
+      ad_services_background_jobs_execution_reported = 663
+        [(module) = "adservices"];
+
+  optional AdServicesMeasurementDelayedSourceRegistration
+      ad_services_measurement_delayed_source_registration = 673
+        [(module) = "adservices", (truncate_timestamp) = true];
+  optional AdServicesMeasurementAttribution
+      ad_services_measurement_attribution = 674
+        [(module) = "adservices", (truncate_timestamp) = true];
+  optional AdServicesMeasurementJobs
+      ad_services_measurement_jobs = 675
+        [(module) = "adservices", (truncate_timestamp) = true];
+  optional AdServicesMeasurementWipeout
+      ad_services_measurement_wipeout = 676
+        [(module) = "adservices", (truncate_timestamp) = true];
 }
 
 /**
@@ -178,3 +196,80 @@
   // The fully qualified name of the last encountered exception.
   optional string last_observed_exception_name = 6;
 }
+
+/** Logs background job stats to monitor the stability of Rubidium background jobs. */
+message AdServicesBackgroundJobsExecutionReported {
+  // A unique identifier for a background job
+  optional int32 job_id = 1;
+
+  // Time interval from the start to the end of an execution of a background job.
+  // It is on a milli-second basis.
+  optional int32 execution_duration_ms = 2;
+
+  // Time interval from the start of previous execution to the start of current execution of
+  // a background job. It is on a second basis.
+  optional int32 execution_frequency_second = 3;
+
+  // Type of the result code that implies different execution results.
+  enum ExecutionResultCode {
+     /** Unspecified result code. */
+     UNSPECIFIED_CODE = 0;
+     /** Successful execution. */
+     SUCCESSFUL = 1;
+     /** Failed execution with retrying the job. */
+     FAILED_WITH_RETRY = 2;
+     /** Failed execution without retrying the job. */
+     FAILED_WITHOUT_RETRY = 3;
+     /** OnJobStop() is invoked with retrying the job. */
+     ONSTOP_CALLED_WITH_RETRY = 4;
+     /** OnJobStop() is invoked without retrying the job. */
+     ONSTOP_CALLED_WITHOUT_RETRY = 5;
+     /** The execution is halted by system or device, leaving an open-ended start.. */
+     HALTED_BY_DEVICE = 6;
+  }
+  optional ExecutionResultCode execution_result_code = 4;
+
+  // The publicly returned reason onStopJob() was called.
+  // This is only applicable when the state is FINISHED, but may be undefined if
+  // JobService.onStopJob() was never called for the job.
+  // The default value is STOP_REASON_UNDEFINED.
+  optional android.app.job.StopReasonEnum public_stop_reason = 5;
+}
+
+/**
+ * Logs when an AdServices delayed source is fetched and registered.
+ */
+message AdServicesMeasurementDelayedSourceRegistration {
+  optional android.adservices.service.measurement.DelayedSourceRegistrationStatus registration_status = 1;
+  // delay (in milliseconds) between a source registration and a previously registered trigger with matching attribution destination
+  optional int64 missed_source_delay_millis = 2;
+}
+
+/**
+ * Logs when an AdServices trigger is attributed to a source.
+ */
+message AdServicesMeasurementAttribution {
+  optional android.adservices.service.measurement.SourceType source_type = 1;
+  optional android.adservices.service.measurement.AttributionSurfaceCombination attribution_surface_combination = 2;
+  optional android.adservices.service.measurement.Status status = 3;
+  optional android.adservices.service.measurement.AttributionFailureType failure_type = 4;
+  optional bool is_source_derived = 5;
+  optional bool is_install_attribution = 6;
+  // delay (in milliseconds) between trigger registration and a trigger becoming attributed.
+  optional int64 trigger_to_attribution_delay_millis = 7;
+}
+
+/**
+ * Logs AdServices job finish status
+ */
+message AdServicesMeasurementJobs {
+  optional android.adservices.service.measurement.Status status = 1;
+  optional android.adservices.service.measurement.JobType job_type = 2;
+}
+
+/**
+ * Logs when AdServices deletion API is called.
+ */
+message AdServicesMeasurementWipeout {
+  optional android.adservices.service.measurement.WipeoutCause wipeout_cause = 1;
+}
\ No newline at end of file
diff --git a/stats/enums/adservices/measurement/enums.proto b/stats/enums/adservices/measurement/enums.proto
new file mode 100644
index 0000000..261ccf7
--- /dev/null
+++ b/stats/enums/adservices/measurement/enums.proto
@@ -0,0 +1,141 @@
+/*
+ * 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.adservices.service.measurement;
+
+option java_outer_classname = "MeasurementProtoEnums";
+option java_multiple_files = true;
+
+/**
+ * Enum used by AdServicesMeasurement(Registration, Attribution).
+ */
+enum SourceType {
+  UNKNOWN_SOURCE_TYPE = 0;
+  EVENT_SOURCE_TYPE = 1;
+  NAVIGATION_SOURCE_TYPE = 2;
+}
+
+/**
+ * Enum used by AdServicesMeasurementRegistration.
+ */
+enum RegistrationSurfaceType {
+  UNKNOWN_REGISTRATION_SURFACE_TYPE = 0;
+  WEB_REGISTRATION_SURFACE_TYPE = 1;
+  APP_REGISTRATION_SURFACE_TYPE = 2;
+}
+
+/**
+ * Enum used by AdServicesMeasurement(Registration, Attribution, Reporting,
+ * Jobs)
+ */
+enum Status {
+  UNKNOWN_STATUS = 0;
+  SUCCESS_STATUS = 1;
+  FAILURE_STATUS = 2;
+}
+
+/**
+ * Enum used by AdServicesMeasurementRegistration.
+ */
+enum RegistrationFailureType {
+  UNKNOWN_REGISTRATION_FAILURE_TYPE = 0;
+  PARSING_REGISTRATION_FAILURE_TYPE = 1;
+  NETWORK_REQUEST_REGISTRATION_FAILURE_TYPE = 2;
+  ENROLLMENT_REGISTRATION_FAILURE_TYPE = 3;
+  REDIRECT_REGISTRATION_FAILURE_TYPE = 4;
+  STORAGE_REGISTRATION_FAILURE_TYPE = 5;
+}
+
+/**
+ * Enum used by AdServicesMeasurementReporting.
+ */
+enum ReportUploadFailureType {
+  UNKNOWN_REPORT_UPLOAD_FAILURE_TYPE = 0;
+  ENROLLMENT_NOT_FOUND_REPORT_UPLOAD_FAILURE_TYPE = 1;
+  NETWORK_ERROR_REPORT_UPLOAD_FAILURE_TYPE = 2;
+  DATASTORE_ERROR_REPORT_UPLOAD_FAILURE_TYPE = 3;
+  REPORT_NOT_PENDING_REPORT_UPLOAD_FAILURE_TYPE = 4;
+}
+
+/**
+ * Enum used by AdServicesMeasurementReporting.
+ */
+enum ReportUploadMethod {
+  UNKNOWN_REPORT_UPLOAD_METHOD = 0;
+  REGULAR_REPORT_UPLOAD_METHOD = 1;
+  FALLBACK_REPORT_UPLOAD_METHOD = 2;
+}
+
+/**
+ * Enum used by AdServicesMeasurementDelayedSourceRegistration.
+ */
+enum DelayedSourceRegistrationStatus {
+  UNKNOWN_DELAYED_SOURCE_REGISTRATION_STATUS = 0;
+  MISSING_DELAYED_SOURCE_REGISTRATION_STATUS = 1;
+  VALID_DELAYED_SOURCE_REGISTRATION_STATUS = 2;
+}
+
+/**
+ * Enum used by AdServicesMeasurementAttribution.
+ */
+enum AttributionSurfaceCombination {
+  UNKNOWN_ATTRIBUTION_SURFACE_COMBINATION = 0;
+  APP_APP_ATTRIBUTION_SURFACE_COMBINATION = 1;
+  APP_WEB_ATTRIBUTION_SURFACE_COMBINATION = 2;
+  WEB_APP_ATTRIBUTION_SURFACE_COMBINATION = 3;
+  WEB_WEB_ATTRIBUTION_SURFACE_COMBINATION = 4;
+}
+
+/**
+ * Enum used by AdServicesMeasurementAttribution.
+ */
+enum AttributionFailureType {
+  UNKNOWN_ATTRIBUTION_FAILURE_TYPE = 0;
+  TRIGGER_IGNORED_ATTRIBUTION_FAILURE_TYPE = 1;
+  TRIGGER_ALREADY_ATTRIBUTED_ATTRIBUTION_FAILURE_TYPE = 2;
+  TRIGGER_MARKED_FOR_DELETION_ATTRIBUTION_FAILURE_TYPE = 3;
+  NO_MATCHING_SOURCE_ATTRIBUTION_FAILURE_TYPE = 4;
+  NO_TOP_LEVEL_FILTER_MATCH_ATTRIBUTION_FAILURE_TYPE = 5;
+  RATE_LIMIT_EXCEEDED_ATTRIBUTION_FAILURE_TYPE = 6;
+  NO_REPORTS_GENERATED_ATTRIBUTION_FAILURE_TYPE = 7;
+}
+
+/**
+ * Enum used by AdServicesMeasurementJobs.
+ */
+enum JobType {
+  UNKNOWN_JOB_TYPE = 0;
+  ASYNC_REGISTRATION_JOB_TYPE = 1;
+  ASYNC_REGISTRATION_FALLBACK_JOB_TYPE = 2;
+  ATTRIBUTION_JOB_TYPE = 3;
+  AGGREGATION_REPORTING_JOB_TYPE = 4;
+  AGGREGATE_REPORTING_FALLBACK_JOB_TYPE = 5;
+  EVENT_REPORTING_JOB_TYPE = 6;
+  EVENT_REPORTING_FALLBACK_JOB_TYPE = 7;
+  DELETE_EXPIRED_JOB_TYPE = 8;
+  DELETE_UNINSTALLED_JOB_TYPE = 9;
+}
+
+/**
+ * Enum used by AdServicesMeasurementWipeout.
+ */
+enum WipeoutCause {
+  UNKNOWN_WIPEOUT_CAUSE = 0;
+  UNINSTALL_WIPEOUT_CAUSE = 1;
+  CONSENT_FLIP_WIPEOUT_CAUSE = 2;
+  CLEAR_DATA_WIPEOUT_CAUSE = 3;
+}
\ No newline at end of file