/*
 * 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.adservices;

import "frameworks/proto_logging/stats/atoms.proto";
import "frameworks/proto_logging/stats/atom_field_options.proto";
import "frameworks/proto_logging/stats/enums/adservices/common/adservices_enums.proto";
import "frameworks/proto_logging/stats/enums/adservices/common/adservices_api_metrics_enums.proto";
import "frameworks/proto_logging/stats/enums/adservices/common/adservices_cel_enums.proto";
import "frameworks/proto_logging/stats/enums/app/job/job_enums.proto";
import "frameworks/proto_logging/stats/enums/adservices/enrollment/enums.proto";
import "frameworks/proto_logging/stats/enums/adservices/measurement/enums.proto";
import "frameworks/proto_logging/stats/enums/adservices/fledge/enums.proto";
import "frameworks/proto_logging/stats/enums/stats/mobiledatadownload/enums.proto";

option java_package = "com.android.os.adservices";
option java_multiple_files = true;

extend Atom {
  optional JSScriptEngineLatencyReported jsscriptengine_latency_reported = 483
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesApiCalled ad_services_api_called = 435
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesMeasurementReportsUploaded ad_services_mesurement_reports_uploaded = 436
  [(module) = "adservices", (truncate_timestamp) = true];

  optional MobileDataDownloadFileGroupDownloadStatusReported mobile_data_download_file_group_status_reported = 490
  [(module) = "adservices", (truncate_timestamp) = true];

  optional MobileDataDownloadDownloadResultReported mobile_data_download_download_result_reported = 502
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesSettingsUsageReported ad_services_settings_usage_reported = 493
  [(module) = "adservices", (truncate_timestamp) = true];

  optional BackgroundFetchProcessReported background_fetch_process_reported = 496
  [(module) = "adservices", (truncate_timestamp) = true];

  optional UpdateCustomAudienceProcessReported update_custom_audience_process_reported = 497
  [(module) = "adservices"];

  optional RunAdBiddingProcessReported run_ad_bidding_process_reported = 498
  [(module) = "adservices"];
  optional RunAdScoringProcessReported run_ad_scoring_process_reported = 499
  [(module) = "adservices"];
  optional RunAdSelectionProcessReported run_ad_selection_process_reported = 500
  [(module) = "adservices"];
  optional RunAdBiddingPerCAProcessReported run_ad_bidding_per_ca_process_reported = 501
  [(module) = "adservices"];

  optional MobileDataDownloadFileGroupStorageStatsReported mobile_data_download_file_group_storage_stats_reported = 503
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesMeasurementRegistrations ad_services_measurement_registrations =
      512 [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesGetTopicsReported ad_services_get_topics_reported = 535
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesEpochComputationGetTopTopicsReported ad_services_epoch_computation_get_top_topics_reported = 536
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesEpochComputationClassifierReported ad_services_epoch_computation_classifier_reported = 537
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesBackCompatGetTopicsReported
      ad_services_back_compat_get_topics_reported = 598
        [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesBackCompatEpochComputationClassifierReported
      ad_services_back_compat_epoch_computation_classifier_reported = 599
          [(module) = "adservices", (truncate_timestamp) = true];
  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];
  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];
  optional AdServicesMeasurementAdIdMatchForDebugKeys
      ad_services_measurement_ad_id_match_for_debug_keys = 695
        [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesEnrollmentDataStored ad_services_enrollment_data_stored = 697
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesEnrollmentFileDownloaded
      ad_services_enrollment_file_downloaded = 698
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesEnrollmentMatched ad_services_enrollment_matched = 699
      [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesConsentMigrated ad_services_consent_migrated = 702
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesEnrollmentFailed ad_services_enrollment_failed = 714
      [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesMeasurementClickVerification ad_services_measurement_click_verification = 756
      [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesEncryptionKeyFetched ad_services_encryption_key_fetched = 765
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesEncryptionKeyDbTransactionEnded ad_services_encryption_key_db_transaction_ended = 766
      [(module) = "adservices", (truncate_timestamp) = true];

  optional DestinationRegisteredBeacons destination_registered_beacons = 767
      [(module) = "adservices", (truncate_timestamp) = true];
  optional ReportInteractionApiCalled report_interaction_api_called = 768
      [(module) = "adservices", (truncate_timestamp) = true];
  optional InteractionReportingTableCleared interaction_reporting_table_cleared = 769
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AppManifestConfigHelperCalled app_manifest_config_helper_called = 788
      [(module) = "adservices", (truncate_timestamp) = true];

  optional AdFilteringProcessJoinCAReported ad_filtering_process_join_ca_reported = 793
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AdFilteringProcessAdSelectionReported ad_filtering_process_ad_selection_reported = 794
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AdCounterHistogramUpdaterReported ad_counter_histogram_updater_reported = 795
      [(module) = "adservices", (truncate_timestamp) = true];
  optional SignatureVerification signature_verification = 807
        [(module) = "adservices", (truncate_timestamp) = true];
  optional KAnonImmediateSignJoinStatusReported k_anon_immediate_sign_join_status_reported = 808
  [(module) = "adservices", (truncate_timestamp) = true];
  optional KAnonBackgroundJobStatusReported k_anon_background_job_status_reported = 809
  [(module) = "adservices", (truncate_timestamp) = true];
  optional KAnonInitializeStatusReported k_anon_initialize_status_reported = 810
  [(module) = "adservices", (truncate_timestamp) = true];
  optional KAnonSignStatusReported k_anon_sign_status_reported = 811
  [(module) = "adservices", (truncate_timestamp) = true];
  optional KAnonJoinStatusReported k_anon_join_status_reported= 812
  [(module) = "adservices", (truncate_timestamp) = true];
  optional KAnonKeyAttestationStatusReported k_anon_key_attestation_status_reported = 813
  [(module) = "adservices", (truncate_timestamp) = true];

  optional GetAdSelectionDataApiCalled get_ad_selection_data_api_called = 814
  [(module) = "adservices", (truncate_timestamp) = true];
  optional GetAdSelectionDataBuyerInputGenerated get_ad_selection_data_buyer_input_generated = 815
  [(module) = "adservices", (truncate_timestamp) = true];

  optional BackgroundJobSchedulingReported background_job_scheduling_reported = 834
  [(module) = "adservices", (truncate_timestamp) = true];

  optional TopicsEncryptionEpochComputationReported topics_encryption_epoch_computation_reported = 840
  [(module) = "adservices", (truncate_timestamp) = true];
  optional TopicsEncryptionGetTopicsReported topics_encryption_get_topics_reported = 841
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesShellCommandCalled adservices_shell_command_called = 842
  [(module) = "adservices", (truncate_timestamp) = true];

  optional UpdateSignalsApiCalled update_signals_api_called = 843
  [(module) = "adservices", (truncate_timestamp) = true];
  optional EncodingJobRun encoding_job_run = 844
  [(module) = "adservices", (truncate_timestamp) = true];
  optional EncodingJsFetch encoding_js_fetch = 845
  [(module) = "adservices", (truncate_timestamp) = true];
  optional EncodingJsExecution encoding_js_execution = 846
  [(module) = "adservices", (truncate_timestamp) = true];
  optional PersistAdSelectionResultCalled persist_ad_selection_result_called = 847
  [(module) = "adservices", (truncate_timestamp) = true];
  optional ServerAuctionKeyFetchCalled server_auction_key_fetch_called = 848
  [(module) = "adservices", (truncate_timestamp) = true];
  optional ServerAuctionBackgroundKeyFetchScheduled server_auction_background_key_fetch_enabled = 849
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesMeasurementProcessOdpRegistration ad_services_measurement_process_odp_registration = 864
      [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesMeasurementNotifyRegistrationToOdp ad_services_measurement_notify_registration_to_odp = 865
      [(module) = "adservices", (truncate_timestamp) = true];

  optional SelectAdsFromOutcomesApiCalled select_ads_from_outcomes_api_called = 876
  [(module) = "adservices", (truncate_timestamp) = true];
  optional ReportImpressionApiCalled report_impression_api_called = 877
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesEnrollmentTransactionStats ad_services_enrollment_transaction_stats = 885
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesCobaltLoggerEventReported ad_services_cobalt_logger_event_reported = 902
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesCobaltPeriodicJobEventReported ad_services_cobalt_periodic_job_event_reported = 903
  [(module) = "adservices", (truncate_timestamp) = true];

  optional UpdateSignalsProcessReported update_signals_process_reported = 905
  [(module) = "adservices", (truncate_timestamp) = true];

  optional TopicsScheduleEpochJobSettingReported topics_schedule_epoch_job_setting_reported = 930
  [(module) = "adservices", (truncate_timestamp) = true];

  optional ScheduledCustomAudienceUpdateScheduleAttempted scheduled_custom_audience_update_schedule_attempted = 967
  [(module) = "adservices", (truncate_timestamp) = true];
  optional ScheduledCustomAudienceUpdatePerformed scheduled_custom_audience_update_performed = 968
  [(module) = "adservices", (truncate_timestamp) = true];
  optional ScheduledCustomAudienceUpdatePerformedAttemptedFailureReported scheduled_custom_audience_update_performed_attempted_failure_reported = 969
  [(module) = "adservices", (truncate_timestamp) = true];
  optional ScheduledCustomAudienceUpdateBackgroundJobRan scheduled_custom_audience_update_background_job_ran = 970
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesProcessLifecycleReported ad_services_process_lifecycle_reported = 1006
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesProcessStableFlagsReported ad_services_process_stable_flags_reported = 1007
  [(module) = "adservices", (truncate_timestamp) = true];
  optional AdServicesFlagUpdateReported ad_services_flag_update_reported = 1008
  [(module) = "adservices", (truncate_timestamp) = true];

  optional ReportingWithDestinationPerformed reporting_with_destination_performed = 1013
  [(module) = "adservices", (truncate_timestamp) = true];
  optional NumberOfTypesOfReportingUrlsReceived number_of_types_of_reporting_url_received = 1014
  [(module) = "adservices", (truncate_timestamp) = true];

  optional MobileDataDownloadLatencyReported mobile_data_download_latency_reported = 1031
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdservicesMeasurementBackgroundJobInfo adservices_measurement_background_job_info = 1046
  [(module) = "adservices", (truncate_timestamp) = true];

  optional UnifiedTableEnabledReported unified_table_enable_reported = 1058
  [(module) = "adservices", (truncate_timestamp) = true];

  optional ProdDebugEnabledReported prod_debug_enabled_reported = 1059
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesMeasurementReportingOriginsPerEnrollmentCounted adservices_measurement_reporting_origins_per_enrollment_counted = 1062
  [(module) = "adservices", (truncate_timestamp) = true];

  optional AdServicesMeasurementReportingOriginsPerEnrllXDestCounted adservices_measurement_reporting_origins_per_enrll_x_dest_counted = 1063
  [(module) = "adservices", (truncate_timestamp) = true];
}

/**
 * Represents a list of topic IDs.
 */
message AdServicesTopicIds {
  repeated int32 topic_id = 1;
}

/**
 * Logs for AdServices GetTopics API call on R+.
 * This atom closely mimics AdServicesGetTopicsReported (for T+ logging) and
 * avoids usage of field types (e.g. repeated) that aren't supported on R/S.
 */
message AdServicesBackCompatGetTopicsReported {
  // Number of filtered duplicate topics.
  optional int32 duplicate_topic_count = 1;

  // Number of filtered blocked topics.
  optional int32 filtered_blocked_topic_count = 2;

  // Number of topic ids returned.
  optional int32 count_of_topic_ids = 3;

  // Topic ids returned, randomized using a random response mechanism.
  optional AdServicesTopicIds topic_ids = 4 [(log_mode) = MODE_BYTES];
}

/**
 * Logs for AdServices Epoch Computation Classifier on R+.
 * One atom should be logged for each app classification.
 * This atom closely mimics AdServicesEpochComputationClassifierReported (for T+ logging)
 * and avoids usage of field types (e.g. repeated) that can't be supported on R/S.
 */
message AdServicesBackCompatEpochComputationClassifierReported {
  // List of topics returned by the classifier for each app. The classification
  // does not depend on the user's usage of the app.
  optional AdServicesTopicIds topic_ids = 1 [(log_mode) = MODE_BYTES];

  // Build id of the assets.
  optional int32 build_id = 2;

  // Version of the assets used.
  optional string asset_version = 3;

  // Type of the classifier used for classifying apps.
  optional android.adservices.ClassifierType classifier_type = 4;

  // On Device classifier status.
  optional android.adservices.OnDeviceClassifierStatus on_device_classifier_status = 5;

  // Precomputed classifier status.
  optional android.adservices.PrecomputedClassifierStatus precomputed_classifier_status = 6;
}

/**
 * Logs debug keys match state when measurement reports are being generated.
 */
message AdServicesMeasurementDebugKeys {
  optional string adtech_enrollment_id = 1;
  optional android.adservices.AttributionType attribution_type = 2;
  optional bool is_matched = 3;
  optional int64 join_key_hash = 4;
  optional int64 join_key_hash_limit = 5;
  optional string app_package_name = 6;
}

/**
 * Logs AdServices errors/exceptions.
 */
message AdServicesErrorReported {
  optional android.adservices.common.ErrorCode error_code = 1;

  // Name of the PPAPI if possible where error is occurring.
  optional android.adservices.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;
}

/** 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_latency_ms = 2;

  // Time interval from the start of previous execution to the start of current execution of
  // a background job. It is on a minute basis.
  optional int32 execution_period_minute = 3;

  // Type of the result code that implies different execution results of Adservices background jobs.
  optional android.adservices.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;

  // Module name from which the job execution is being reported.
  optional android.adservices.ModuleName module_name = 6;

  // Indicates the scheduler type that schedules the job.
  optional android.adservices.SchedulerType scheduler_type = 7;
}

/** Logs background job Stats to monitor job scheduling in Rubidium. */
message BackgroundJobSchedulingReported {

  // A unique identifier for a background job.
  optional int32 job_id = 1;

  // Scheduling result code.
  optional android.adservices.JobSchedulingResultCode result_code = 2;

  // Indicates the scheduler type that schedules the job.
  optional android.adservices.SchedulerType scheduler_type = 3;

  // Module name from which the job execution is being reported.
  optional android.adservices.ModuleName module_name = 4;
}

/**
 * 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;
  optional string app_package_name = 3;
}

/**
 * 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;
  optional string app_package_name = 8;
  optional int32 aggregate_report_count = 9;
  optional int32 aggregate_debug_report_count = 10;
  optional int32 event_report_count = 11;
  optional int32 event_debug_report_count = 12;
  optional int32 retry_count = 13;
  // Number of null aggregate reports that were generated as a result of this
  // attribution. A null aggregate report is an aggregate report meant to
  // obscure the true number of aggregate reports sent to consumers of the
  // Attribution Reporting API. An aggregate report is an input to the Private
  // Aggregate API and contains detailed conversion data associated with an
  // attribution. Obscuring the true number of aggregate reports preserves
  // privacy.
  optional int32 null_aggregate_report_count = 14;
}

/**
 * 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;
  optional string app_package_name = 2;
}

/**
 * Logs Ad Id match state for debug keys when measurement reports are being generated.
 */
message AdServicesMeasurementAdIdMatchForDebugKeys {
  optional string adtech_enrollment_id = 1;
  optional android.adservices.AttributionType attribution_type = 2;
  optional bool is_matched = 3;
  optional int64 num_unique_ad_ids_used = 4;
  optional int64 num_unique_ad_id_limit = 5;
  optional string app_package_name = 6;
}

/**
 * Logs when AdServices enrollment data is stored.
 */
message AdServicesEnrollmentDataStored {
  optional android.stats.adservices.enrollment.TransactionType transaction_type = 1;
  optional bool success = 2;
  optional int32 build_id = 3; // id of the enrollment file downloaded via mdd
}

/**
 * Logs when AdServices enrollment file get downloaded.
 */
message AdServicesEnrollmentFileDownloaded {
  optional bool success = 1;
  optional int32 build_id = 2; // id of the enrollment file downloaded via mdd
}

/**
 * Logs when AdServices enrollment match occurs.
 */
message AdServicesEnrollmentMatched {
  optional bool success = 1;
  optional int32 build_id = 2; // id of the enrollment file downloaded via mdd
}

/**
 * Logs when AdServices enrollment fails.
 */
message AdServicesEnrollmentFailed {
  optional int32 build_id = 1; // id of the enrollment file downloaded via mdd
  optional android.stats.adservices.enrollment.DataFileGroupStatus data_file_group_status = 2;
  optional int32 enrollment_record_count_in_table = 3;
  optional string query_parameter = 4;
  optional android.stats.adservices.enrollment.ErrorCause error_cause = 5;
}

/**
 * Logs when AdServices enrollment database is accessed.
 */
message AdServicesEnrollmentTransactionStats {
  optional android.stats.adservices.enrollment.EnrollmentTransactionType transaction_type = 1;
  optional android.stats.adservices.enrollment.TransactionStatus transaction_status = 2;
  optional int32 transaction_parameter_count = 3;
  optional int32 transaction_result_count = 4;
  optional int32 query_result_count = 5;
  optional int32 datasource_record_count_pre = 6;
  optional int32 datasource_record_count_post = 7;
  optional int32 enrollment_file_latest_build_id = 8;
  optional int32 latency_ms = 9;
}

/**
 * Logs for AdServices Consent Migration after OTA.
 * This atom captures the event of consent migration when we OTA from S to T+.
 */
message AdServicesConsentMigrated {

  // Logs the Migration status
  enum MigrationStatus {
    UNSPECIFIED_MIGRATION_STATUS = 0;

    // Consent migration unsuccessful
    FAILURE = 1;

    // Consent migration successful with shared prefs updated
    SUCCESS_WITH_SHARED_PREF_UPDATED = 2;

    // Consent migration successful with shared prefs not updated
    SUCCESS_WITH_SHARED_PREF_NOT_UPDATED = 3;

  }

  // Logs the type of migration
  enum MigrationType {
    UNSPECIFIED_MIGRATION_TYPE = 0;

    // Migrating consent from PPAPI to system service
    PPAPI_TO_SYSTEM_SERVICE = 1;

    // Migrating consent from App Search to system service
    APPSEARCH_TO_SYSTEM_SERVICE = 2;

    // Migrating consent from AdServicesExtDataStorageService to system service
    ADEXT_SERVICE_TO_SYSTEM_SERVICE = 3;

    // Migrating consent from AdServicesExtDataStorageService to App Search
    ADEXT_SERVICE_TO_APPSEARCH = 4;
  }

  // Logs the opt-in/ opt-out value of measurement app
  optional bool is_measurement_consent_enabled = 1;

  // Logs the opt-in/ opt-out value of topics app
  optional bool is_topics_consent_enabled = 2;

  // Logs the opt-in/ opt-out value of fledge app
  optional bool is_fledge_consent_enabled = 3;

  // Logs the opt-in/ opt-out value for all apps in beta
  optional bool is_default_consent_enabled = 4;

  // Logs the type of migration
  optional MigrationType migration_type = 5;

  // Logs the region where the OTA took place
  optional android.adservices.AdServiceSettingRegion region = 6;

  // Logs the Migration status
  optional MigrationStatus migration_status = 7;
}

/**
 * Logs for AdServices click verification for measurement API calls.
 */
 message AdServicesMeasurementClickVerification {
  //  The final source type of the source.
  optional android.adservices.service.measurement.SourceType source_type = 1;

  // If an input event was included with the registration.
  // The calling app wanted a click event if an input event is present.
  optional bool input_event_present = 2;

  // If the system click verification passed.
  optional bool system_click_verification_passed = 3;

  // If the flag is set to enable the system click verification check.
  optional bool system_click_verification_enabled = 4;

  // The delay (in millis) from when the input event was created to when the API was called.
  optional int64 input_event_delay_millis = 5;

  // The max difference (in millis) between input event creation and API call for the source to not get downgraded.
  optional int64 valid_delay_window_millis = 6;

  // The package calling the API.
  optional string app_package_name = 7;

  optional bool click_dedup_enabled = 8;

  optional bool click_dedup_enforced = 9;

  optional int64 click_dedup_max_sources_per_click = 10;

  optional bool click_dedup_under_limit = 11;
}

message AdServicesMeasurementProcessOdpRegistration {
  optional android.adservices.service.measurement.OdpRegistrationType odp_registration_type = 1;
  optional android.adservices.service.measurement.OdpRegistrationStatus odp_registration_status = 2;
}

message AdServicesMeasurementNotifyRegistrationToOdp {
  optional int64 odp_api_latency_ms = 1;
  optional android.adservices.service.measurement.OdpApiCallStatus odp_api_call_status = 2;

}

/**
 * Logs for AdServices encryption key background job status.
 */
message AdServicesEncryptionKeyFetched {

  // Encryption key fetch job type.
  enum FetchJobType {
    UNKNOWN_JOB = 0;
    ENCRYPTION_KEY_DAILY_FETCH_JOB = 1;
    MDD_DOWNLOAD_JOB = 2;
  }

  // Encryption key fetch status.
  enum FetchStatus {
    UNKNOWN = 0;
    NULL_ENDPOINT = 1;
    INVALID_ENDPOINT = 2;
    IO_EXCEPTION = 3;
    BAD_REQUEST_EXCEPTION = 4;
    KEY_NOT_MODIFIED = 5;
    SUCCESS = 6;
  }

  // Encryption key fetch job type.
  optional FetchJobType fetch_job_type = 1;
  // Encryption key fetch status.
  optional FetchStatus fetch_status = 2;
  // Whether the key is fetched for the first time.
  optional bool is_first_time_fetch = 3;
  // Enrollment id for the adtech corresponding to the encryption key.
  // Example: "XYZABC"
  optional string adtech_enrollment_id = 4;
  // Company id for the adtech corresponding to this encryption key.
  // Example: "XYZCompany"
  optional string company_id = 5;
  // Encryption key url.
  optional string encryption_key_url = 6;
}

/**
 * Logs for AdServices encryption key datastore transaction status.
 */
message AdServicesEncryptionKeyDbTransactionEnded {

  // Encryption key datastore transaction type.
  enum DbTransactionType {
    UNKNOWN = 0;
    READ_TRANSACTION_TYPE = 1;
    WRITE_TRANSACTION_TYPE = 2;
  }

  // Encryption key datastore transaction status.
  enum DbTransactionStatus {
    UNKNOWN_EXCEPTION = 0;
    INVALID_KEY= 1;
    INSERT_EXCEPTION = 2;
    DELETE_EXCEPTION = 3;
    SEARCH_EXCEPTION = 4;
    SUCCESS = 5;
  }

  // Encryption key dao method names.
  enum MethodName {
    UNKNOWN_METHOD = 0;
    GET_KEY_FROM_ENROLLMENT_ID = 1;
    GET_KEY_FROM_ENROLLMENT_ID_AND_KEY_TYPE = 2;
    GET_KEY_FROM_ENROLLMENT_ID_AND_KEY_ID = 3;
    GET_KEY_FROM_REPORTING_ORIGIN = 4;
    GET_ALL_KEYS = 5;
    INSERT_KEY = 6;
    INSERT_KEYS = 7;
    DELETE_KEY = 8;
  }

  // Encryption key datastore transaction type.
  optional DbTransactionType db_transaction_type = 1;
  // Encryption key datastore transaction status.
  optional DbTransactionStatus  db_transaction_status = 2;
  // Encryption key DAO method name.
  optional MethodName method_name = 3;
}

/**
 * Logs for beacon level reporting for destination registered beacons.
 */
message DestinationRegisteredBeacons {

  // Logs the range of key size for interaction key.
  enum InteractionKeySizeRangeType {
    UNSET_TYPE = 0;
    // The key size is smaller than 50% maximum key size.
    MUCH_SMALLER_THAN_MAXIMUM_KEY_SIZE = 1;
    // The key size is equal or greater than 50% maximum key size but smaller than maximum key size.
    SMALLER_THAN_MAXIMUM_KEY_SIZE = 2;
    // The key size is equal to maximum key size.
    EQUAL_TO_MAXIMUM_KEY_SIZE = 3;
    // The key size is greater than maximum key size.
    LARGER_THAN_MAXIMUM_KEY_SIZE = 4;
  }

  // What kind of winner did the beacon come from?
  enum BeaconSource {
    UNSET = 0;
    PROTECTED_SIGNALS = 1;
    CUSTOM_AUDIENCE = 2;
  }

  // The entity who registered the beacons.
  optional android.adservices.service.BeaconReportingDestinationType destination = 1;

  // Number of beacons ad-tech tries to register during reportImpression.
  optional int32 attempted_registered_beacons = 2;

  // Key size range for interactionKey in every registerAdBeacon call.
  repeated InteractionKeySizeRangeType attempted_key_sizes = 3;

  // Size of registered_ad_interactions database after each update to it.
  optional int32 table_num_rows = 4;

  // The status response code in AdServices.
  optional int32 status_code = 5;

  // Which type of signals the beacon come from?
  optional BeaconSource beacon_source = 6;
}

/**
 * Logs for beacon level reporting for ReportInteraction API.
 */
message ReportInteractionApiCalled {
  // The entity who registered the beacons.
  optional android.adservices.service.BeaconReportingDestinationType destination = 1;

  // Number of matching uris for the reportInteraction request is found.
  optional int32 num_matching_uris = 2;
}

/**
 * Logs for beacon level reporting for clearing interaction reporting table.
 */
message InteractionReportingTableCleared {
  // Number of registered URIs cleared every 24 hours.
  optional int32 num_uris_cleared = 1;

  // Number of unreported URIs before clearing.
  optional int32 num_unreported_uris = 2;
}

/**
 * Logs a call to check if an app is allowed to call an AdServices API.
 */
message AppManifestConfigHelperCalled {
  // Package name of the app that has been queried about.
  optional string app_package_name = 1;
  // Which API was called
  optional android.adservices.AppApiAccessType api_access_type = 2;
  // Result of the call
  optional android.adservices.AppApiAccessResult api_access_result = 3;
}

/**
 * Logs for Ad filtering process during join CA.
 */
message AdFilteringProcessJoinCAReported {
  // The status response code in AdServices.
  optional int32 status_code = 1;

  // The following 5 fields are logging the count of Ads in each bucket
  // when joining CA with the keys.
  // The total number of Ads using keys less than the maximum number of keys limitation.
  optional int32 count_of_ads_with_keys_much_smaller_than_limitation = 2;

  // The total number of Ads using keys are equal or greater than
  // 50% maximum number of keys limitation but smaller than maximum number of keys limitation.
  optional int32 count_of_ads_with_keys_smaller_than_limitation = 3;

  // The total number of Ads using keys are equal to maximum number of keys limitation.
  optional int32 count_of_ads_with_keys_equal_to_limitation = 4;

  // The total number of Ads using keys greater than the maximum number of keys limitation.
  optional int32 count_of_ads_with_keys_larger_than_limitation = 5;

  // The total number of Ads using empty keys.
  optional int32 count_of_ads_with_empty_keys = 6;

  // The following 5 fields are logging the count of Ads in each bucket
  // when joining CA with the filters.
  // The total number of Ads using filters less than the maximum number of filters limitation.
  optional int32 count_of_ads_with_filters_much_smaller_than_limitation = 7;

  // The total number of Ads using filters are equal or greater than
  // 50% maximum number of filters limitation but smaller than maximum number of filters limitation.
  optional int32 count_of_ads_with_filters_smaller_than_limitation = 8;

  // The total number of Ads using filters are equal to maximum number of filters limitation.
  optional int32 count_of_ads_with_filters_equal_to_limitation = 9;

  // The total number of Ads using filters greater than the maximum number of filters limitation.
  optional int32 count_of_ads_with_filters_larger_than_limitation = 10;

  // The total number of Ads using empty filters.
  optional int32 count_of_ads_with_empty_filters = 11;

  // The total number of used Ad filtering keys per custom audience.
  optional int32 total_num_of_used_keys = 12;

  // The total number of used Ad filtering filters per custom audience.
  optional int32 total_num_of_used_filters = 13;
}

/**
 * Logs for Ad filtering process during ad selection.
 */
message AdFilteringProcessAdSelectionReported {
  // The process type of Ad filtering.
  enum FilterProcessType {
    FILTER_UNSET = 0;
    FILTER_CUSTOM_AUDIENCES = 1;
    FILTER_CONTEXTUAL_ADS = 2;
  }

  // Latency when running the whole Ad filtering process.
  optional int32 latency_in_millis_of_all_ad_filtering = 1;

  // Latency when calling app install filters in ad filters.
  optional int32 latency_in_millis_of_app_install_filtering = 2;

  // Latency when calling FCap filters in ad filters.
  optional int32 latency_in_millis_of_fcap_filters = 3;

  // The status response code in AdServices.
  optional int32 status_code = 4;

  // The number of Ads which are filtered out of bidding.
  // The field will be set as FIELD_UNSET if filter_process_type is FILTER_CONTEXTUAL_ADS
  optional int32 num_of_ads_filtered_out_of_bidding = 5;

  // The number of custom audiences which are filtered out of bidding.
  optional int32 num_of_custom_audiences_filtered_out_of_bidding = 6;

  // The total number of Ads before Ad filtering process.
  optional int32 total_num_of_ads_before_filtering = 7;

  // The total number of custom audiences before Ad filtering process.
  // The field will be set as FIELD_UNSET if filter_process_type is FILTER_CONTEXTUAL_ADS
  optional int32 total_num_of_custom_audiences_before_filtering = 8;

  // The number of app packages involve in app install filters.
  optional int32 num_of_package_in_app_install_filters = 9;

  // The number of database operations during ad selection.
  optional int32 num_of_db_operations = 10;

  // The process type when calling Ad filtering
  optional FilterProcessType filter_process_type = 11;

  // The number of Ads which are filtered during contextual ads.
  // The field will be set as FIELD_UNSET if filter_process_type is FILTER_CUSTOM_AUDIENCES
  optional int32 num_of_contextual_ads_filtered = 12;

  // The number of ad counter keys in fcap filters.
  optional int32 num_of_ad_counter_keys_in_fcap_filters = 13;

  // The number of contextual Ads filtered out of bidding because of invalid signatures.
  optional int32 num_of_contextual_ads_filtered_out_of_bidding_invalid_signatures = 14;

  //The number of contextual Ads filtered out of bidding because of no Ads.
  optional int32 num_of_contextual_ads_filtered_out_of_bidding_no_ads = 15;

  // The total number of contextual Ads before filtering.
  optional int32 total_num_of_contextual_ads_before_filtering = 16;
}

/**
 * Logs for Ad counter histogram updater per DB insertion
 */
message AdCounterHistogramUpdaterReported {
  // Latency when calling Ad counter histogram updater.
  optional int32 latency_in_millis = 1;

  // The status response code in AdServices.
  optional int32 status_code = 2;

  // The total number of Ad events in database after Ad counter histogram updater process.
  optional int32 total_num_of_events_in_database_after_insert = 3;

  // The number of histogram events were inserted in database
  // during Ad counter histogram updater process.
  optional int32 num_of_inserted_event = 4;

  // The number of histogram events were evicted from database
  // during Ad counter histogram updater process.
  optional int32 num_of_evicted_event = 5;
}

/**
 * Logs a request for signature verification for a buyer
 */
message SignatureVerification {
  // Latency of the serialization of a given SignedContextualAds object
  optional int64 serialization_latency = 1;

  // Latency of fetching the key from key management store
  optional int64 key_fetch_latency = 2;

  // Latency of the verifying the signature (only the signature verification, without including the
  // serialization and key fetch)
  optional int64 verification_latency = 3;

  // Number of keys fetched for a given ad tech
  optional int32 num_of_keys_fetched = 4;

  // End status of the verification request
  // A verification request can end in success or a failure
  optional android.adservices.service.VerificationStatus signature_verification_status = 5;

  // To log in case of failures
  // Enrollment id of the buyer that has a signature verification failure
  optional string failed_signature_buyer_enrollment_id = 6;

  // Enrollment id of the seller that has a signature verification failure
  optional string failed_signature_seller_enrollment_id = 7;

  // Caller package name that has a signature verification failure
  optional string failed_signature_caller_package_name = 8;

  // Key failure causes
  // Unknown error
  optional int32 failure_detail_unknown_error = 9;

  // Enrollment data not found for the buyer or was null
  optional int32 failure_detail_no_enrollment_data_for_buyer = 10;

  // Zero keys fetched for the buyer
  optional int32 failure_detail_no_keys_fetched_for_buyer = 11;

  // Signature is not formatted correctly
  optional int32 failure_detail_wrong_signature_format = 12;

  // Number of keys that has the wrong format
  optional int32 failure_detail_count_of_keys_with_wrong_format = 13;

  // Number of keys that failed to verified the signature
  optional int32 failure_detail_count_of_keys_failed_to_verify_signature = 14;
}

// The status of the event when we make a SignJoin call immediately on receiving an ad winner
message KAnonImmediateSignJoinStatusReported {

  // The result of the immediate sign join operation
  optional android.adservices.service.KAnonJobResult result = 1;

  // The total number of messages that the operation attempted to process
  optional int32 total_messages_attempted = 2;

  // The total number of messages that we failed to join
  optional int32 messages_failed_to_join = 3;

  // The total number of messages that we failed to sign
  optional int32 messages_failed_to_sign = 4;

  // The latency in milliseconds of the operation
  optional int32 latency_in_millis = 5;
}

// The status of the background job where we read messages from database and make
// batch sign join calls
message KAnonBackgroundJobStatusReported {

  // The result of the background sign join job
  optional android.adservices.service.KAnonJobResult result = 1;

  // The total number of messages that the operation attempted to process
  optional int32 total_messages_attempted = 2;

  // The total number of messages that are unprocessed in the database after the job run
  optional int32 messages_unprocessed_in_db_after_job = 3;

  // The total number of messages that we failed to join
  optional int32 messages_failed_to_join = 4;

  // The total number of messages that we failed to sign
  optional int32 messages_failed_to_sign = 5;

  // The latency in milliseconds of the operation
  optional int32 latency_in_millis = 6;
}

// The status of the K-Anonymous Initialize Operation
message KAnonInitializeStatusReported {

  // Marks true if the operation was completely successful
  optional bool was_successful = 1;

  // Marks the action due to which the initialize operation failed
  optional android.adservices.service.KAnonAction failed_action = 2;

  // Marks the reason for the action's failure
  optional android.adservices.service.KAnonActionResult failed_action_cause = 3;

  // The latency in milliseconds of the operation
  optional int32 latency_in_millis = 4;

}

// The status of an individual K-anon sign operation
message KAnonSignStatusReported {

  // Marks true if the operation was completely successful
  optional bool was_successful = 1;

  // Marks the action due to which the initialize operation failed
  optional android.adservices.service.KAnonAction failed_action = 2;

  optional android.adservices.service.KAnonActionResult failed_action_cause = 3;

  // The number of messages in a single sign batch
  optional int32  number_of_messages_in_batch = 4;

  // The latency in milliseconds of the operation
  optional int32 latency_in_millis = 5;
}

// The status of an individual K-Anon join operation
message KAnonJoinStatusReported {

  // Marks true if the operation was completely successful
  optional bool all_successful = 1;

  // The total number of messages corresponding to this log event
  optional int32 total_messages = 2;

  // The total number of messages we failed to join
  optional int32 messages_failed_to_join = 3;

  // The latency in milliseconds of the operation
  optional int32 latency_in_millis = 4;

}

// The status of the KAnon key attestation certificate generation operation
message KAnonKeyAttestationStatusReported {

  // The size in bytes of the X.509 certificate chain
  optional int32 certificate_size_in_bytes = 1;

  // Logs the result code of the Key Attestation operation
  optional android.adservices.service.KAnonKeyAttestationResult result_code = 2;

  // The latency in milliseconds of the operation
  optional int32 latency_in_millis = 3;
}

/*
 * Logs for per API call for GetAdSelectionData API.
 */
message GetAdSelectionDataApiCalled {
  // Size of the payload in KB
  optional int32 payload_size_kb = 1;

  // Number of buyers participating in this payload
  optional int32 num_buyers = 2;

  // The status response code in AdServices.
  optional int32 status_code = 3;

  // The source of the coordinator used, i.e., DEFAULT or provided via API
  optional android.adservices.service.ServerAuctionCoordinatorSource coordinator_source = 4;

  // Maximum size set by the seller
  optional int32 seller_max_size_kb = 5;

  // Result of payload optimization
  optional android.adservices.service.PayloadOptimizationResult payload_optimization_result = 6;

  // Latency of buyer input generation
  optional int32 input_generation_latency_ms = 7;

  // Version of compressed buyer input creator
  optional int32 compressed_buyer_input_creator_version = 8;

  // Number of times the entire payload was recompressed to update the current size estimation
  optional int32 num_re_estimations = 9;
}

/**
 * Logs per buyer input for GetAdSelectionData API.
 */
message GetAdSelectionDataBuyerInputGenerated {
  // Number of custom audiences in this buyer input
  optional int32 num_custom_audiences = 1;

  // Number of custom audiences opting into the omit-ads feature
  optional int32 num_custom_audiences_omit_ads = 2;

  // Mean of the size of a custom audience for this buyer input
  optional float custom_audience_size_mean = 3;

  // Variance of the size of a custom audience for this buyer input
  optional float custom_audience_size_variance = 4;

  // Mean of the size of the trusted bidding signals keys for this buyer input
  optional float trusted_bidding_signals_keys_size_mean = 5;

  // Variance of the size of the trusted bidding signals keys for this buyer input
  optional float trusted_bidding_signals_size_variance = 6;

  // Mean of the size of the user bidding signals for this buyer input
  optional float user_bidding_signals_size_mean = 7;

  // Variance of the size of the user bidding signals for this buyer input
  optional float user_bidding_signals_size_variance = 8;

  // Number of encoded signals payloads included in the auctions
  optional int32 num_encoded_signals = 9;

  // Mean size of encoded signals payloads
  optional int32 encoded_signals_size_mean = 10;

  // Max size of encoded signals payloads
  optional int32 encoded_signals_size_max = 11;

  // Min size of encoded signals payloads
  optional int32 encoded_signals_size_min = 12;

  // Number of custom audiences in this buyer input sending component ads
  optional int32 num_custom_audiences_with_component_ads = 13;
}

/*
 * Logged each time the updateSignals API is called.
 */
message UpdateSignalsApiCalled {
    enum JsonProcessingStatus {
        UNSET = 0;
        SUCCESS = 1;
        TOO_BIG = 2;
        SYNTACTIC_ERROR = 3;
        SEMANTIC_ERROR = 4;
        OTHER_ERROR = 5;
    }

    // Http response code
    optional int32 http_response_code = 1;

    // The size of the JSON
    optional android.adservices.service.Size json_size = 2;

    // The status of JSON processing
    optional JsonProcessingStatus json_processing_status = 3;

    // Uid of calling app, only included in error cases
    optional int32 uid = 4 [(is_uid) = true];

    // Adtech's eTLD+1, only included in error cases
    optional string adtech_id = 5;
}

/*
 * Logs per encoding background job run
 */
message EncodingJobRun {
    enum EncodingSourceType {
      UNSET = 0;
      PAS_ENCODING_JOB_SERVICE = 1;
      PAS_SERVICE_IMPL = 2;
    }

    // The number of adtechs who successfully encoded in this background job run
    optional int32 signal_encoding_successes = 1;

    // The number of adtechs who failed to encoded in this background job run
    optional int32 signal_encoding_failures = 2;

    // The number of adtechs skipped due to their signals being unmodified
    optional int32 signal_encoding_skips = 3;

    // The encoding resource type
    optional EncodingSourceType encoding_source_type = 4;
}

/*
 * Logs per download of the encoding javascript
 */
message EncodingJsFetch {
    enum JsFetchStatus {
        UNSET = 0;
        SUCCESS = 1;
        TOO_BIG = 2;
        TIMEOUT = 3;
        NETWORK_FAILURE = 4;
        OTHER_FAILURE = 5;
    }

    // The time to download the js
    optional android.adservices.service.Size js_download_time = 1;

    // Http response code
    optional int32 http_response_code = 2;

    // Was the JS rejected for being too big or taking too long?
    optional JsFetchStatus fetch_status = 3;

    // Adtech's eTLD+1, only included in error cases
    optional string adtech_id = 4;
}

/*
 * Logs per execution of the encoding javascript.
 */
message EncodingJsExecution {
    // The time to run the js
    optional android.adservices.service.Size js_latency = 1;

    // Encoded signals size in bytes
    optional android.adservices.service.Size encoded_signals_size = 2;

    // JS run status
    optional android.adservices.service.JsRunStatus run_status = 3;

    // How much memory did the JS use (if this is easy to gather)
    optional int32 js_memory_used = 4;

    // Adtech's eTLD+1, only included in error cases
    optional string adtech_id = 5;
}

/*
 * Logs per API call to persistAdSelectionResult.
 */
message PersistAdSelectionResultCalled {
    enum WinnerType {
        UNSET = 0;
        NO_WINNER = 1;
        CA_WINNER = 2;
        PAS_WINNER = 3;
    }

    // The type of auction winner
    optional WinnerType winner = 1;

    // Number of component ads in winner
    optional int32 num_component_ads = 2;
}

/** Logs for Topics encryption during epoch computation */
message TopicsEncryptionEpochComputationReported {
  // Number of topics before encryption during epoch computation process.
  optional int32 count_of_topics_before_encryption = 1;

  // Number of empty encrypted topics during epoch computation process.
  optional int32 count_of_empty_encrypted_topics = 2;

  // Number of encrypted topics during epoch computation process.
  optional int32 count_of_encrypted_topics = 3;

  // The latency in milliseconds of the whole encryption process during epoch computation.
  optional int32 latency_of_whole_encryption_process_ms = 4;

  // The latency in milliseconds of encryption of each topic.
  optional int32 latency_of_encryption_per_topic_ms = 5;

  // The latency in milliseconds of persisting encrypted topics to database
  // during epoch computation.
  optional int32 latency_of_persisting_encrypted_topics_to_db_ms = 6;
}

/** Logs for encrypted topics during getTopics() API calls */
message TopicsEncryptionGetTopicsReported {

  // Number of encrypted topics during getTopics() API calls.
  optional int32 count_of_encrypted_topics = 1;

  // The latency in milliseconds of reading encrypted topics from database
  // during getTopics() API calls.
  optional int32 latency_of_reading_encrypted_topics_from_db_ms = 2;

}
/**
 * Metrics for each shell command indicating success/failure, latency.
 */
message AdServicesShellCommandCalled {
  // Name of the shell command.
  optional android.adservices.Command command = 1;

  // Shell command result indicating success/failure.
  optional android.adservices.CommandResult result_code = 2;

  // Shell command execution latency in milli-second.
  optional int32 latency_millis = 3;
}

/**
 * Logs whenever we try to fetch the key from either the database or over network during server
 * auction
 */
message ServerAuctionKeyFetchCalled {
  // The source of key fetch. Eg: during auction, background fetch
  optional android.adservices.service.ServerAuctionKeyFetchSource source = 1;

  // Specifies whether the key was fetched over the network or the database
  optional android.adservices.service.ServerAuctionEncryptionKeySource encryption_key_source = 2;

  // Whether we used the default coordinator or adtech-provided coordinator via API call
  optional android.adservices.service.ServerAuctionCoordinatorSource coordinator_source = 3;

  // The status code of the network call
  optional int32 network_status_code = 4;

  // The latency of network key fetch
  optional int32 network_latency_millis = 5;
}

/** Logs whenever the background key fetch job is scheduled */
message ServerAuctionBackgroundKeyFetchScheduled {
  optional android.adservices.service.BackgroundKeyFetchStatus status = 1;

  optional int32 count_auction_urls = 2;

  optional int32 count_join_urls = 3;
}

/*
 * Logs for per API call for SelectAdsFromOutcomes API.
 */
message SelectAdsFromOutcomesApiCalled {
  // Number of IDs passed to the mediation call
  optional int32 count_ids = 1;

  // Number of non existing IDs during mediation call
  optional int32 count_non_existing_ids = 2;

  // Specified whether the truncation API call used a prebuilt script.
  optional bool used_prebuilt = 3;

  // Mediation script download result code.
  optional int32 download_result_code = 4;

  // Mediation script download latency in milliseconds.
  optional int32 download_latency_millis = 5;

  // Mediation script execution result code.
  optional android.adservices.service.JsRunStatus execution_result_code = 6;

  // Mediation script execution latency in milliseconds.
  optional int32 execution_latency_millis = 7;
}

/*
 * Logs for per API call for ReportImpression API.
 */
message ReportImpressionApiCalled {
  // Specified whether the BuyerContextualSignals contained ad cost
  optional bool reportWin_buyer_additional_signals_contained_ad_cost = 1;

  // Specified whether the BuyerContextualSignals contained data version
  optional bool reportWin_buyer_additional_signals_contained_data_version = 2;

  // Specified whether the SellerContextualSignals contained data version
  optional bool reportResult_seller_additional_signals_contained_data_version = 3;

  // Result code of the buyer JS script (reportWin)
  optional android.adservices.service.JsRunStatus reportWin_js_script_result_code = 4;

  // Result code of the seller JS script (reportResult)
  optional android.adservices.service.JsRunStatus reportResult_js_script_result_code = 5;
}


/*
 * Logs when JSScriptEngine is used to execute JavaScript code on device.
 *
 * Logged from Cell Broadcast module:
 *   packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/js/
 */
message JSScriptEngineLatencyReported {
  enum LatencyStat {
    UNKNOWN = 0;
    SANDBOX_INIT = 1;
    ISOLATE_CREATE = 2;
    JAVA_PROCESS_EXECUTION = 3;
    WEBVIEW_PROCESS_EXECUTION = 4;
  }

  optional LatencyStat stat = 1;
  optional int64 latency_millis = 2;
}


/**
 * Logs for AdServices GetTopics API call on T+ only due to repeated fields.
 * Keep in sync with AdServicesBackCompatGetTopicsReported for R+ logging.
 */
message AdServicesGetTopicsReported {
  // List of topic ids returned.
  repeated int32 topic_ids = 1;

  // Number of filtered duplicate topics.
  optional int32 duplicate_topic_count = 2;

  // Number of filtered blocked topics.
  optional int32 filtered_blocked_topic_count = 3;

  // Number of topic ids returned.
  optional int32 count_of_topic_ids = 4;
}

/**
 * Logs for AdServices Epoch computation GetTopTopics.
 */
message AdServicesEpochComputationGetTopTopicsReported {
  // Number of top topics generated.
  optional int32 top_topics_count = 1;

  // Number of padded random topics generated.
  optional int32 padded_random_topics_count = 2;

  // Number of apps considered for calculating top topics.
  optional int32 apps_considered_count = 3;

  // Number of sdks that called Topics API in the epoch.
  optional int32 sdks_considered_count = 4;
}

/**
 * Logs for AdServices Epoch Computation Classifier on T+ only due to repeated fields.
 * Keep in sync with AdServicesBackCompatEpochComputationClassifierReported for R+ logging.
 * One atom should be logged for each app classification.
 */
message AdServicesEpochComputationClassifierReported {

  // List of topics returned by the classifier for each app. The classification
  // does not depend on the user's usage of the app.
  repeated int32 topic_ids = 1;

  // Build id of the assets.
  optional int32 build_id = 2;

  // Version of the assets used.
  optional string asset_version = 3;

  // Type of the classifier used for classifying apps.
  enum ClassifierType {
    /** Unknown classifier option. */
    UNKNOWN_CLASSIFIER = 0;
    /** Only on-device classification. */
    ON_DEVICE_CLASSIFIER = 1;
    /** Only Precomputed classification. */
    PRECOMPUTED_CLASSIFIER = 2;
    /** Precomputed classification values are preferred over on-device classification values. */
    PRECOMPUTED_THEN_ON_DEVICE_CLASSIFIER = 3;
  }
  optional ClassifierType classifier_type = 4;

  // On Device classifier status.
  enum OnDeviceClassifierStatus {
    ON_DEVICE_CLASSIFIER_STATUS_UNSPECIFIED = 0;
    ON_DEVICE_CLASSIFIER_STATUS_NOT_INVOKED = 1;
    ON_DEVICE_CLASSIFIER_STATUS_SUCCESS = 2;
    ON_DEVICE_CLASSIFIER_STATUS_FAILURE = 3;
  }
  optional OnDeviceClassifierStatus on_device_classifier_status = 5;

  // Precomputed classifier status.
  enum PrecomputedClassifierStatus {
    PRECOMPUTED_CLASSIFIER_STATUS_UNSPECIFIED = 0;
    PRECOMPUTED_CLASSIFIER_STATUS_NOT_INVOKED = 1;
    PRECOMPUTED_CLASSIFIER_STATUS_SUCCESS = 2;
    PRECOMPUTED_CLASSIFIER_STATUS_FAILURE = 3;
  }
  optional PrecomputedClassifierStatus precomputed_classifier_status = 6;
}

/**
 * Logs registration response size when registration URI is pinged.
 */
message AdServicesMeasurementRegistrations {
  enum RegistrationType {
    UNKNOWN_REGISTRATION = 0;
    SOURCE = 1;
    TRIGGER = 2;
  }

  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;
  optional string app_package_name = 9;
  optional int32 retry_count = 10;
  optional int32 http_response_code = 11;
  optional bool is_redirect = 12;
  optional bool is_pa_request = 13;
  optional int32 num_entities_deleted = 14;
  optional bool is_event_level_epsilon_configured = 15;
  optional bool is_trigger_aggregatable_value_filters_configured = 16;
  optional bool is_trigger_filtering_id_configured = 17;
  optional bool is_trigger_context_id_configured = 18;
}


/**
 * Logs for the bidding stage of an ad selection process when the getBuyersCustomAudience() or
 * the runAdBidding() is called.
 */
message RunAdBiddingProcessReported {
  /* Logs when the getBuyersCustomAudience() is called. */
  optional int32 get_buyers_custom_audience_latency_in_millis = 1;
  optional int32 get_buyers_custom_audience_result_code = 2;
  optional int32 num_buyers_requested = 3;
  optional int32 num_buyers_fetched = 4;

  /* Logs when the runAdBidding() is called. */
  optional int32 num_of_ads_entering_bidding = 5;
  optional int32 num_of_cas_entering_bidding = 6;
  optional int32 num_of_cas_post_bidding = 7;
  optional float ratio_of_cas_selecting_rmkt_ads = 8;
  optional int32 run_ad_bidding_latency_in_millis = 9;
  optional int32 run_ad_bidding_result_code = 10;

  /* Time from the start of the getBuyersCustomAudience() to the end of the runAdBidding(). */
  optional int32 total_ad_bidding_stage_latency_in_millis = 11;
}

/**
 * Logs for the scoring stage of an ad selection process when the runAdScoring() is called.
 */
message RunAdScoringProcessReported {
  /* Logs when the getAdSelectionLogic() is called. */
  optional int32 get_ad_selection_logic_latency_in_millis = 1;
  optional int32 get_ad_selection_logic_result_code = 2;
  optional android.adservices.service.ScriptType get_ad_selection_logic_script_type = 3;
  optional int32 fetched_ad_selection_logic_script_size_in_bytes = 4;

  /* Logs when the getTrustedScoringSignals() is called. */
  optional int32 get_trusted_scoring_signals_latency_in_millis = 5;
  optional int32 get_trusted_scoring_signals_result_code = 6;
  optional int32 fetched_trusted_scoring_signals_data_size_in_bytes = 7;

  /* Logs when the getAdScores() is called. */
  // the total scoreAds script execution time when getAdScores() is called.
  optional int32 score_ads_latency_in_millis = 8;
  // the overall latency of the getAdScores().
  optional int32 get_ad_scores_latency_in_millis = 9;
  optional int32 get_ad_scores_result_code = 10;

  optional int32 num_of_cas_entering_scoring = 11;
  optional int32 num_of_remarketing_ads_entering_scoring = 12;
  optional int32 num_of_contextual_ads_entering_scoring = 13;
  // the overall latency of the runAdScoring process.
  optional int32 run_ad_scoring_latency_in_millis = 14;
  optional int32 run_ad_scoring_result_code = 15;

  /* Logs when data header is used in scoreAd. */
  optional bool scoreAd_seller_additional_signals_contained_data_version = 16;
  optional android.adservices.service.JsRunStatus scoreAd_js_script_result_code = 17;
}

/* Logs for the ad selection process when the runAdSelection() is called.*/
message RunAdSelectionProcessReported {
  /* Logs for the persisting ad selection process. */
  optional bool is_remarketing_ads_won = 1;
  optional int32 db_ad_selection_size_in_bytes = 2;
  optional int32 persist_ad_selection_latency_in_millis = 3;
  optional int32 persist_ad_selection_result_code = 4;

  /* Logs for the overall runAdSelection process. */
  optional int32 run_ad_selection_latency_in_millis = 5;
  optional int32 run_ad_selection_result_code = 6;
}

/**
 *  Logs for the bidding process on a single custom audience when the runAdBiddingPerCA() is called.
 */
message RunAdBiddingPerCAProcessReported {
  optional int32 num_of_ads_for_bidding = 1;
  optional int32 run_ad_bidding_per_ca_latency_in_millis = 2;
  optional int32 run_ad_bidding_per_ca_result_code = 3;

  /* Logs for the getting buyer's decision logic script process. */
  optional int32 get_buyer_decision_logic_latency_in_millis = 4;
  optional int32 get_buyer_decision_logic_result_code = 5;
  optional android.adservices.service.ScriptType buyer_decision_logic_script_type = 6;
  optional int32 fetched_buyer_decision_logic_script_size_in_bytes = 7;

  /* Logs for the getting trusted bidding signals process. */
  optional int32 num_of_keys_of_trusted_bidding_signals = 8;
  optional int32 fetched_trusted_bidding_signals_data_size_in_bytes = 9;
  optional int32 get_trusted_bidding_signals_latency_in_millis = 10;
  optional int32 get_trusted_bidding_signals_result_code = 11;

  /* Logs when runBidding() is called. */
  // the total generateBids script execution time when runBidding() is called..
  optional int32 generate_bids_latency_in_millis = 12;
  // the overall latency of runBidding().
  optional int32 run_bidding_latency_in_millis = 13;
  optional int32 run_bidding_result_code = 14;

  /* Logs when CPC is used. */
  optional bool run_ad_bidding_per_ca_returned_ad_cost = 15;

  /* Logs when data header is used in GenerateBid. */
  optional bool generateBid_buyer_additional_signals_contained_data_version = 16;
  optional android.adservices.service.JsRunStatus generateBid_js_script_result_code = 17;
}

/**
 *  Logs for an updating a single custom audience process when the updateCustomAudience() is called.
 */
message UpdateCustomAudienceProcessReported {
  optional int32 latency_in_millis = 1;
  optional int32 result_code = 2;
  optional int32 data_size_of_ads_in_bytes = 3;
  optional int32 num_of_ads = 4;
}


/**
 *  Logs for a background fetch process when the runBackgroundFetch() is called.
 */
message BackgroundFetchProcessReported {
  optional int32 latency_in_millis = 1;
  optional int32 num_of_eligible_to_update_cas = 2;
  optional int32 result_code = 3;
}

/**
 * Logs when various Privacy Sandbox settings are used.
 */
message AdServicesSettingsUsageReported {
  // Region of the user who interacted with AdServicesSettings UI.
  enum AdServiceSettingRegion {
    // fallback when getDeviceRegion call failed.
    REGION_UNSPECIFIED = 0;
    // European Union user (based on isoCountryInfo).
    EU = 1;
    // Non-European Union user (based on isoCountryInfo).
    ROW = 2;
  }
  // Region where the device was used.
  optional AdServiceSettingRegion region = 1;

  // UI settings page action performed by the user.
  enum AdServiceSettingsName {
    // fallback when getAction call failed.
    ACTION_UNSPECIFIED = 0;
    // notification was requested to be sent to the user.
    REQUESTED_NOTIFICATION = 1;
    // the notification landing page was displayed.
    LANDING_PAGE_DISPLAYED = 2;
    // user opt-in for PP API.
    OPT_IN_SELECTED = 3;
    // user opt-out of PP API.
    OPT_OUT_SELECTED = 4;
    // the topics page was displayed.
    MANAGE_TOPICS_SELECTED = 5;
    // the fledge page was displayed.
    MANAGE_APPS_SELECTED = 6;
    // user reset topics.
    RESET_TOPIC_SELECTED = 7;
    /// user reset fledge apps.
    RESET_APP_SELECTED = 8;
    // user blocked topics.
    BLOCK_TOPIC_SELECTED = 9;
    // user unblocked topics.
    UNBLOCK_TOPIC_SELECTED = 10;
    // user blocked fledge apps.
    BLOCK_APP_SELECTED = 11;
    // user unblocked fledge apps.
    UNBLOCK_APP_SELECTED = 12;
    // Measurement page and data reset.
    MANAGE_MEASUREMENT_SELECTED = 13;
    RESET_MEASUREMENT_SELECTED = 14;
    // user opt-in to topics.
    TOPICS_OPT_IN_SELECTED = 15;
    // user opt-out of topics.
    TOPICS_OPT_OUT_SELECTED = 16;
    // user opt-in to fledge.
    FLEDGE_OPT_IN_SELECTED = 17;
    // user opt-out of fledge.
    FLEDGE_OPT_OUT_SELECTED = 18;
    // user opt-in to measurement.
    MEASUREMENT_OPT_IN_SELECTED = 19;
    // user opt-out of measurement.
    MEASUREMENT_OPT_OUT_SELECTED = 20;
    // Notification and landing page for kids policy
    // notification was requested for GA  user.
    GA_UX_NOTIFICATION_REQUESTED = 21;
    // GA landing page was displayed.
    GA_UX_NOTIFICATION_LANDING_PAGE_DISPLAYED = 22;
    // GA confirmation page was displayed.
    GA_UX_NOTIFICATION_CONFIRMATION_PAGE_DISPLAYED = 23;
    // GA version of opt_in/out selected.
    // opt-in for GA user.
    NOTIFICATION_OPT_IN_SELECTED = 24;
    // opt-out for GA user.
    NOTIFICATION_OPT_OUT_SELECTED = 25;
    // user selected manage settings in consent notification.
    NOTIFICATION_MANAGE_SETTINGS_SELECTED = 26;
    // the privacy sandbox settings page was displayed.
    PRIVACY_SANDBOX_SETTINGS_PAGE_DISPLAYED = 27;
    // the confirmation page was displayed for a user.
    CONFIRMATION_PAGE_DISPLAYED = 28;
    // notification was blocked by a user.
    NOTIFICATION_DISABLED = 29;
    // notification was blocked by a GA user.
    GA_UX_NOTIFICATION_DISABLED = 30;
    // notification was displayed to a user.
    NOTIFICATION_DISPLAYED = 31;
    // notification was displayed to a GA user.
    GA_UX_NOTIFICATION_DISPLAYED = 32;
    // user clicked on the more button on the landing page.
    LANDING_PAGE_MORE_BUTTON_CLICKED = 33;
    // GA user clicked on the more button on the landing page.
    GA_UX_LANDING_PAGE_MORE_BUTTON_CLICKED = 34;
    // user clicked the additional info button on the landing page.
    LANDING_PAGE_ADDITIONAL_INFO_CLICKED = 35;
    // GA user clicked the additional info button on the landing page.
    GA_UX_LANDING_PAGE_ADDITIONAL_INFO_CLICKED = 36;
    // user scrolled the landing page.
    LANDING_PAGE_SCROLLED = 37;
    // GA user scrolled the landing page.
    GA_UX_LANDING_PAGE_SCROLLED = 38;
    // user scrolled to the bottom of the landing page.
    LANDING_PAGE_SCROLLED_TO_BOTTOM = 39;
    // GA user scrolled to the bottom of the landing page.
    GA_UX_LANDING_PAGE_SCROLLED_TO_BOTTOM = 40;
    // user clicked the settings button on the landing page.
    LANDING_PAGE_SETTINGS_BUTTON_CLICKED = 41;
    // GA user clicked the settings button on the landing page.
    GA_UX_LANDING_PAGE_SETTINGS_BUTTON_CLICKED = 42;
    // user clicked the got it button on the landing page.
    LANDING_PAGE_GOT_IT_BUTTON_CLICKED = 43;
    // GA user clicked the got it button on the landing page.
    GA_UX_LANDING_PAGE_GOT_IT_BUTTON_CLICKED = 44;
    // user clicked opt-out on the landing page.
    LANDING_PAGE_OPT_OUT_CLICKED = 45;
    // GA user clicked opt-out on the landing page.
    GA_UX_LANDING_PAGE_OPT_OUT_CLICKED = 46;
    // user dismissed the landing page.
    LANDING_PAGE_DISMISSED = 47;
    // GA user dismissed the landing page.
    GA_UX_LANDING_PAGE_DISMISSED = 48;
    // user opt-in from the landing page.
    LANDING_PAGE_OPT_IN = 49;
    // GA user opt-in from the landing page.
    GA_UX_LANDING_PAGE_OPT_IN = 50;
    // user clicked settings on the opt-in confirmation page.
    OPT_IN_CONFIRMATION_PAGE_SETTINGS_CLICKED = 51;
    // GA user clicked settings on the opt-in confirmation page.
    GA_UX_OPT_IN_CONFIRMATION_PAGE_SETTINGS_CLICKED = 52;
    // user clicked settings on the opt-out confirmation page.
    OPT_OUT_CONFIRMATION_PAGE_SETTINGS_CLICKED = 53;
    // GA user clicked settings on the opt-out confirmation page.
    GA_UX_OPT_OUT_CONFIRMATION_PAGE_SETTINGS_CLICKED = 54;
    // user clicked got it on the opt-in confirmation page.
    OPT_IN_CONFIRMATION_PAGE_GOT_IT_CLICKED = 55;
    // GA user clicked got it on the opt-in confirmation page.
    GA_UX_OPT_IN_CONFIRMATION_PAGE_GOT_IT_CLICKED = 56;
    // user clicked got it on the opt-out confirmation page.
    OPT_OUT_CONFIRMATION_PAGE_GOT_IT_CLICKED = 57;
    // GA user clicked got it on the opt-out confirmation page.
    GA_UX_OPT_OUT_CONFIRMATION_PAGE_GOT_IT_CLICKED = 58;
    // user dismissed confirmation page.
    CONFIRMATION_PAGE_DISMISSED = 59;
    // GA user dismissed confirmation page.
    GA_UX_CONFIRMATION_PAGE_DISMISSED = 60;
    // user clicked more info on the opt in confirmation page.
    OPT_IN_CONFIRMATION_PAGE_MORE_INFO_CLICKED = 61;
    // user clicked more info on the opt out confirmation page.
    OPT_OUT_CONFIRMATION_PAGE_MORE_INFO_CLICKED = 62;
    // GA user clicked more info on the opt in confirmation page.
    GA_UX_OPT_IN_CONFIRMATION_PAGE_MORE_INFO_CLICKED = 63;
    // GA user clicked more info on the opt out confirmation page.
    GA_UX_OPT_OUT_CONFIRMATION_PAGE_MORE_INFO_CLICKED = 64;
    // GA user clicked opt out on the landing page.
    GA_UX_LANDING_PAGE_OPT_OUT = 65;
    // user clicked opt out on the landing page.
    LANDING_PAGE_OPT_OUT = 66;
    // (enrolled) user clicked on the privacy sandbox entry point.
    PRIVACY_SANDBOX_ENTRY_POINT_CLICKED = 67;
    // daily maintenance job was run.
    DAILY_MAINTENANCE_JOB_FINISHED = 68;
    // GA user clicked the 2nd additional info button on the landing page.
    GA_UX_LANDING_PAGE_ADDITIONAL_INFO_2_CLICKED = 69;
  }
  // UI action performed by user.
  optional AdServiceSettingsName action = 2;

  enum AdServicesSettingsDefaultConsent {
    // fallback when getDefaultConsent failed.
    CONSENT_UNSPECIFIED = 0;
    // user was opted-in to PP API by default.
    PP_API_DEFAULT_OPT_IN = 1;
    // user was opted-out of PP API by default.
    PP_API_DEFAULT_OPT_OUT = 2;
    // user was opted-in to topics by default.
    TOPICS_DEFAULT_OPT_IN = 3;
    // user was opted-in to topics by default.
    TOPICS_DEFAULT_OPT_OUT = 4;
    // user was opted-in to fledge by default.
    FLEDGE_DEFAULT_OPT_IN = 5;
    // user was opted-in to fledge by default.
    FLEDGE_DEFAULT_OPT_OUT = 6;
    // user was opted-in to measurement by default.
    MEASUREMENT_DEFAULT_OPT_IN = 7;
    // user was opted-in to measurement by default.
    MEASUREMENT_DEFAULT_OPT_OUT = 8;
  }
  // AdServices consents of a user when consent notification was first sent.
  optional AdServicesSettingsDefaultConsent default_consent = 3;

  // AdId state of a user when consent notification was first sent.
  enum AdServicesSettingsDefaultAdIdState {
    // fallback when getDefaultAdId failed.
    STATE_UNSPECIFIED = 0;
    // AdId was not zeroed-out when user first received consent notification.
    AD_ID_ENABLED = 1;
    // AdId was zeroed-out when user first received consent notification.
    AD_ID_DISABLED = 2;
  }

  // Default ad id state when consent notification was first sent.
  optional AdServicesSettingsDefaultAdIdState default_ad_id_state = 4;

  // (Deprecated) Type of AdService feature running on device.
  enum PrivacySandboxFeatureType {
    // fallback when getFeature failed.
    FEATURE_UNSPECIFIED = 0;
    // the first consent feature is enabled.
    PRIVACY_SANDBOX_FIRST_CONSENT = 1;
    // the reconsent feature is enabled.
    PRIVACY_SANDBOX_RECONSENT = 2;
    // privacy sandbox is not yet supported on the device.
    PRIVACY_SANDBOX_UNSUPPORTED = 3;
    // privacy sandbox is already running on the device.
    PRIVACY_SANDBOX_ALREADY_RUNNING = 4;
    // the first consent feature with flipped flow is enabled.
    PRIVACY_SANDBOX_FIRST_CONSENT_FF = 5;
    // the reconsent feature with flipped flow is enabled.
    PRIVACY_SANDBOX_RECONSENT_FF = 6;
  }

  // (Deprecated) Privacy sandbox feature currently running on the device.
  optional PrivacySandboxFeatureType feature_type = 5 [deprecated = true];

  // Type of privacy sandbox UX.
  enum PrivacySandboxUx {
    // fallback when no UX can be selected.
    UNSUPPORTED_UX = 0;
    // all UXs that are not unspecified.
    UNSPECIFIED_UX = 1;
    // GA UX.
    GA_UX = 2;
    // Beta UX.
    BETA_UX = 3;
    // UX for Android RVC.
    RVC_UX = 4;
    // GA UX with Updated PAS APIs
    GA_UX_WITH_PAS = 5;
  }

  // Type of privacy sandbox UX.
  optional PrivacySandboxUx ux = 6;

  // Type of privacy sandbox enrollment channel.
  enum PrivacySandboxUxEnrollmentChannel {
    // fallback when no enrollment channel can be selected.
    UNSUPPORTED_CHANNEL = 0;
    // all enrollment channels that are unspecified.
    UNSPECIFIED_CHANNEL = 1;
    // already enrolled channel.
    ALREADY_ENROLLED_CHANNEL = 2;
    // consent notification debug channel.
    CONSENT_NOTIFICATION_DEBUG_CHANNEL = 3;
    // first consent notification.
    FIRST_CONSENT_NOTIFICATION_CHANNEL = 4;
    // reconsent notification.
    RECONSENT_NOTIFICATION_CHANNEL = 5;
    // consent notification reset channel.
    CONSENT_NOTIFICATION_RESET_CHANNEL = 6;
    // 2nd GA notification post R OTA.
    RVC_POST_OTA_NOTIFICATION_CHANNEL = 7;
    // PAS first notification channel
    PAS_FIRST_NOTIFICATION_CHANNEL = 8;
    // PAS renotify notification channel
    PAS_RENOTIFY_NOTIFICATION_CHANNEL = 9;
  }

  // Type of privacy sandbox enrollment channel.
  optional PrivacySandboxUxEnrollmentChannel enrollment_channel = 7;
}

/**
* Container for MobileDataDownloadFileGroupStorageStats
*/
message MobileDataDownloadStorageStats {
  repeated MobileDataDownloadFileGroupStorageStats mobile_data_download_file_group_storage_stats = 1;
}

/**
* Storage stats for a single file group. This is logged as a nested field and is not meant to be logged as a top level proto.
*/
message MobileDataDownloadFileGroupStorageStats {
  // The total number of bytes used by this file group
  optional int64 total_bytes_used = 1;
  // The total number of inline file bytes used by this file group
  optional int64 total_inline_bytes_used = 2;
  // The number of bytes used for the downloaded version of the file group
  optional int64 downloaded_group_bytes_used = 3;
  // Specifies which file group this storage is associated with
  optional MobileDataDownloadFileGroupStats file_group_stats = 4 [(log_mode) = MODE_BYTES];
}

/**
* Logs stats on the amount of storage being used by file groups.
*/
message MobileDataDownloadFileGroupStorageStatsReported {
  // Storage stats for all file groups in the MDD Instance
  optional MobileDataDownloadStorageStats storage_stats = 1  [(log_mode) = MODE_BYTES];
  // All the bytes used by mdd file groups
  optional int64 total_mdd_bytes_used = 2;
  // All the bytes used in the entire mdd directory
  optional int64 total_mdd_directory_bytes_used = 3;
}

/**
* Logs stats on the result of download attempts of file groups. Provides info on individual download attempts.
*/
message MobileDataDownloadDownloadResultReported {
  // The result of the download attempt
  optional android.stats.mobiledatadownload.DownloadResult download_result = 1;

  // Specifies which file group the download attempt was for
  optional MobileDataDownloadFileGroupStats file_group_stats = 2 [(log_mode) = MODE_BYTES];
}

/**
 * Logs stats on the download status of file groups. Provides information on
 * download latency and download penetration.
 */
message MobileDataDownloadFileGroupDownloadStatusReported {
  // The status of the file group on device: PENDING, DOWNLOADED, FAILED
  optional android.stats.mobiledatadownload.DownloadStatus
      file_group_download_status = 1;
  // Timestamp of when this file group was added to the device.
  optional int64 group_added_timestamp = 2;
  // Timestamp of when MDD completed downloading the file group.
  optional int64 group_downloaded_timestamp = 3;
  // Stats specific to the file group
  optional MobileDataDownloadFileGroupStats file_group_stats = 4 [(android.os.statsd.log_mode) = MODE_BYTES];
  // Number of days since the last time the device attempted to log file group download status for any file group.
  optional int32 days_since_last_log = 5;
}

/** Shared data among MobileDataDownload statistics. Not meant to be a top level atom proto.*/
message MobileDataDownloadFileGroupStats {
  // The name of the file group. This a string set server side used to retrieve
  // the files. Does not contain PII.
  optional string file_group_name = 1;
  // Allows the clients to identify a file group based on a given set of
  // properties. This string is set server side and does not contain PII.
  optional string variant_id = 2;
  // Identifier for the data file group created to identify the version of the
  // file group.
  optional int64 build_id = 3;
  // The number of files in the file group.
  optional int32 file_count = 4;
  // Whether the file group has an account associated with it.
  optional bool has_account = 5;
  // Inverse of the sampling rate used to sample this event.
  optional int32 sampling_interval = 6;
  // Note: we do not have owner_package since that's already transmitted.
}

/** Download latency stats logged after download completes. */
message MobileDataDownloadLatencyReported {
  // The number of download attempts needed to fully download the file group.
  optional int32 download_attempt_count = 1;

  // The download latency in milliseconds, which is the time elapsed between
  // download started and download complete.
  optional int64 download_latency_ms = 2;

  // The total MDD download latency in milliseconds, which is the time elapsed
  // between new config received and download complete.
  // True E2E download latency = Flag propagation latency + MDD total download
  // latency. Here we are talking about the later.
  optional int64 total_latency_ms = 3;
  optional MobileDataDownloadFileGroupStats file_group_stats = 4
  [(log_mode) = MODE_BYTES];
}

/**
 * Logs when an AdServices measurement reports are being uploaded.
 */
message AdServicesMeasurementReportsUploaded {
  enum ReportType {
    UNKNOWN_REPORT = 0;
    EVENT = 1;
    AGGREGATE = 2;
    DEBUG_EVENT = 3;
    DEBUG_AGGREGATE = 4;
    VERBOSE_DEBUG_SOURCE_DESTINATION_LIMIT = 5;
    VERBOSE_DEBUG_SOURCE_NOISED = 6;
    VERBOSE_DEBUG_SOURCE_STORAGE_LIMIT = 7;
    VERBOSE_DEBUG_SOURCE_SUCCESS = 8;
    VERBOSE_DEBUG_SOURCE_UNKNOWN_ERROR = 9;
    VERBOSE_DEBUG_SOURCE_FLEXIBLE_EVENT_REPORT_VALUE_ERROR = 10;
    VERBOSE_DEBUG_TRIGGER_AGGREGATE_DEDUPLICATED = 11;
    VERBOSE_DEBUG_TRIGGER_AGGREGATE_INSUFFICIENT_BUDGET = 12;
    VERBOSE_DEBUG_TRIGGER_AGGREGATE_NO_CONTRIBUTIONS = 13;
    VERBOSE_DEBUG_TRIGGER_AGGREGATE_REPORT_WINDOW_PASSED = 14;
    VERBOSE_DEBUG_TRIGGER_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT = 15;
    VERBOSE_DEBUG_TRIGGER_EVENT_DEDUPLICATED = 16;
    VERBOSE_DEBUG_TRIGGER_EVENT_EXCESSIVE_REPORTS = 17;
    VERBOSE_DEBUG_TRIGGER_EVENT_LOW_PRIORITY = 18;
    VERBOSE_DEBUG_TRIGGER_EVENT_NO_MATCHING_CONFIGURATIONS = 19;
    VERBOSE_DEBUG_TRIGGER_EVENT_NOISE = 20;
    VERBOSE_DEBUG_TRIGGER_EVENT_REPORT_WINDOW_PASSED = 21;
    VERBOSE_DEBUG_TRIGGER_NO_MATCHING_FILTER_DATA = 22;
    VERBOSE_DEBUG_TRIGGER_NO_MATCHING_SOURCE = 23;
    VERBOSE_DEBUG_TRIGGER_REPORTING_ORIGIN_LIMIT = 24;
    VERBOSE_DEBUG_TRIGGER_EVENT_STORAGE_LIMIT = 25;
    VERBOSE_DEBUG_TRIGGER_UNKNOWN_ERROR = 26;
    VERBOSE_DEBUG_TRIGGER_AGGREGATE_STORAGE_LIMIT = 27;
    VERBOSE_DEBUG_TRIGGER_AGGREGATE_EXCESSIVE_REPORTS = 28;
    VERBOSE_DEBUG_TRIGGER_EVENT_REPORT_WINDOW_NOT_STARTED = 29;
    VERBOSE_DEBUG_TRIGGER_EVENT_NO_MATCHING_TRIGGER_DATA = 30;
    VERBOSE_DEBUG_TRIGGER_EVENT_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT = 31;
    VERBOSE_DEBUG_TRIGGER_AGG_ATTRIBUTIONS_PER_SOURCE_DESTINATION_LIMIT = 32;
    VERBOSE_DEBUG_HEADER_ERROR = 33;
    AGGREGATE_DEBUG_REPORT = 34;
    VERBOSE_DEBUG_UNKNOWN = 9999;
  }

  optional ReportType type = 1;

  enum ReportUploadStatus {
    UNKNOWN_STATUS = 0;
    SUCCESS = 1;
    FAILURE = 2;
  }

  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;
  optional string app_package_name = 6;
  optional int32 retry_count = 7;
  optional int32 http_response_code = 8;
  optional bool is_marked_for_deletion = 9;
  optional bool is_fake_report = 10;
}

/**
 * Logs when an AdServices api is called.
 */
message AdServicesApiCalled {

  optional android.adservices.common.api.metrics.AdServicesApiClassType api_class = 1;

  // The actual name of the api within the 3 classes described above.
  optional android.adservices.common.api.metrics.AdServicesApiName api_name = 2;

  optional string app_package_name = 3;
  optional string sdk_package_name = 4;

  optional int32 latency_millis = 5;

  // response_code is the error code for the given api.
  optional int32 response_code = 6;
}

/**
 * Logs Cobalt logging events in AdServices. This provides information about
 * Cobalt operational metrics.
 */
message AdServicesCobaltLoggerEventReported{
  // The Cobalt metric id of the event that is being logged. The metric id is defined in
  // packages/modules/AdServices/adservices/libraries/cobalt/proto/metric_definition.proto
  optional int32 metric_id = 1;

  // The Cobalt report id of the event that is being logged. The report id is defined in
  // packages/modules/AdServices/adservices/libraries/cobalt/proto/report_definition.proto
  optional int32 report_id = 2;

  // Logging event which is over the defined threshold in the registry.
  optional android.adservices.CobaltLoggingEvent cobalt_logging_event = 3;
}

/**
 * Logs Cobalt periodic job execution events in AdServices. The periodic job
 * event contains
 * Cobalt metrics upload status.
 */
message AdServicesCobaltPeriodicJobEventReported {
  optional android.adservices.CobaltPeriodicJobEvent cobalt_periodic_job_event = 1;
}

// Logs when updateSignals api is called.
message UpdateSignalsProcessReported {
  // The updated signals process latency in milliseconds for this API call.
  optional int32 update_signals_process_latency_millis = 1;

  // Adservices api status code for this API call.
  optional int32 adservices_api_status_code = 2;

  // Number of signals written for this API call.
  optional int32 signals_written_count = 3;

  // Number of keys from downloaded JSON for this API call.
  optional int32 keys_stored_count = 4;

  // Number of values from downloaded JSON for this API call.
  optional int32 values_stored_count = 5;

  // Number of eviction rules for this API call.
  optional int32 eviction_rules_count = 6;

  // The bucketed size of the buyer who called the APIs signals.
  optional android.adservices.service.Size per_buyer_signal_size = 7;

  // The average size of raw protected signals per buyer in bytes.
  optional float mean_raw_protected_signals_size_bytes = 8;

  // The maximum size of raw protected signals per buyer in bytes.
  optional float max_raw_protected_signals_size_bytes = 9;

  // The minimum size of raw protected signals per buyer in bytes.
  optional float min_raw_protected_signals_size_bytes = 10;

  // A list of unique evictors used for an eviction.
  repeated android.adservices.service.SignalEvictor signal_evictors_used = 11;

  // A list of unique eviction priority values present across updated signals.
  // Integer values mapped to EvictionPriority. This is a repeated field to
  // avoid logging the same priority multiple times.
  repeated int32 updated_signal_eviction_priorities = 12;

  // A list of unique eviction priority values present across evicted signals.
  // Integer values mapped to EvictionPriority. This is a repeated field to
  // avoid logging the same priority multiple times.
  repeated int32 evicted_signal_eviction_priorities = 13;

  // The bucketed size of all evicted signals.
  optional android.adservices.service.Size per_buyer_evicted_signal_size = 14;

  // The number of unique keys with eviction priority explicitly set.
  optional int32 updated_signals_with_eviction_priority_count = 15;

  // A JSON can be fetched by requesting a provided URL from the AdTech, and later be used to guide
  // the signal updates. Per different signal eviction design, the JSON will be parsed differently
  // relaying on schema version comes with the response.
  optional int32 signal_update_schema_version = 16;
}

/** Logs for Topics epoch job setting during scheduling EpochJobService. */
message TopicsScheduleEpochJobSettingReported {
  // Status when forcing reschedule EpochJob.
  enum RescheduleEpochJobStatus {
    STATUS_UNSET = 0;
    RESCHEDULE_SUCCESS = 1;
    SKIP_RESCHEDULE_EMPTY_JOB_SCHEDULER = 2;
    SKIP_RESCHEDULE_EMPTY_PENDING_JOB = 3;
  }

  // Epoch job setting of the EpochJob.
  enum EpochJobBatteryConstraint {
    UNKNOWN_SETTING = 0;
    REQUIRES_CHARGING = 1;
    REQUIRES_BATTERY_NOT_LOW = 2;
  }

  // Status when forcing reschedule EpochJob.
  optional RescheduleEpochJobStatus reschedule_epoch_job_status = 1;

  // The previous epoch job setting.
  // This field will be UNKNOWN_SETTING when reschedule_epoch_job_status is not RESCHEDULE_SUCCESS.
  optional EpochJobBatteryConstraint previous_epoch_job_setting = 2;

  // The current epoch job setting.
  // This field will be UNKNOWN_SETTING when reschedule_epoch_job_status is not RESCHEDULE_SUCCESS.
  optional EpochJobBatteryConstraint current_epoch_job_setting = 3;

  // The epoch job setting when scheduling the epoch job in EpochJobService.scheduleIfNeeded().
  optional EpochJobBatteryConstraint schedule_if_needed_epoch_job_status = 4;
}

/**
 * Logs when an update for custom audience is scheduled using ScheduledCustomAudienceUpdate API.
 *
 * Pushed from:
 *   packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/customaudience/ScheduleCustomAudienceUpdateImpl.java
 */
message ScheduledCustomAudienceUpdateScheduleAttempted {
  // Denotes the existing status before the update is performed.
  enum ExistingUpdateStatus {
    UNKNOWN = 0;
    DID_OVERWRITE_EXISTING_UPDATE = 1;
    NO_EXISTING_UPDATE = 2;
    REJECTED_BY_EXISTING_UPDATE = 3;
  }

  // Number of partial custom audiences in the schedule CA update.
  optional int32 num_partial_custom_audiences = 1;

  // Delay in minutes after which custom audiences are scheduled to be updated.
  optional int32 min_delay_minutes = 2;

  // Field denoting if there was an already pending update in the database.
  optional ExistingUpdateStatus existing_update_status = 3;

  // Number of leave custom audience in the schedule CA update.
  optional int32 num_leave_custom_audiences = 4;

  // boolean denoting if the schedule CA update scheduled is for the second hop.
  optional bool is_second_hop = 5;
}

/**
 * Logs for ScheduledCustomAudienceUpdate after the update is performed.
 *
 * Pushed from:
 *   packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/customaudience/ScheduleUpdatesHandler.java
 */
message ScheduledCustomAudienceUpdatePerformed {
  // number of partial custom audience in the schedule ca update request.
  optional int32 num_partial_custom_audiences_in_request = 1;

  // number of custom audiences to be joined in the response from the server.
  optional int32 num_join_custom_audiences_in_response = 2;

  // number of custom audiences actually joined.
  optional int32 num_custom_audiences_joined = 3;

  // number of custom audiences to leave in schedule ca update request.
  optional int32 num_leave_custom_audiences_in_request = 4;

  // number of custom audience to in the response from the server.
  optional int32 num_leave_custom_audiences_in_response = 5;

  // number of actual custom audiences left.
  optional int32 num_custom_audiences_left = 6;

  // boolean denoting if the schedule CA update performed was the initial hop.
  optional bool was_initial_hop = 7;

  // number of schedule CA updates in the response from the server.
  optional int32 num_schedule_updates_in_response = 8;

  // number of CA schedules for a update.
  optional int32 num_updates_scheduled = 9;
}

/**
 * Logs for the scheduleCustomAudienceUpdate background job.
 *
 * Pushed from:
 *   packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/customaudience/ScheduleUpdatesHandler.java
 *
 * Estimated Logging Rate:
 *  Peak: 1 time in 1 hour | Avg: 24 per device per day.
 */
message ScheduledCustomAudienceUpdateBackgroundJobRan {
  // number of schedule custom audience update found in the queue (database).
  optional int32 num_updates_found = 1;

  // number of schedule custom audience updates performed successfully.
  optional int32 num_successful_updates = 2;
}

/**
 * Logs for failure during updating Scheduled custom audience.
 *
 * Pushed from:
 *   packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/customaudience/ScheduleUpdatesHandler.java
 */
message ScheduledCustomAudienceUpdatePerformedAttemptedFailureReported {
  // Enum denoting the type of failure logged.
  enum FailureType {
    UNKNOWN = 0;
    HTTP_UNKNOWN = 1;
    HTTP_TOO_MANY_REQUESTS = 2;
    HTTP_REDIRECTION = 3;
    HTTP_CLIENT_ERROR = 4;
    HTTP_SERVER_ERROR = 5;
    JSON_PARSING_ERROR = 6;
    INTERNAL_ERROR = 7;
    HTTP_IO_EXCEPTION = 8;
    HTTP_CONTENT_SIZE_EXCEPTION = 9;
  }
  /// Enum denoting the action that caused the failure.
  enum FailureAction {
    HTTP_CALL = 0;
    LEAVE_CUSTOM_AUDIENCE = 1;
    JOIN_CUSTOM_AUDIENCE = 2;
    SCHEDULE_CUSTOM_AUDIENCE = 3;
  }

  optional FailureType failure_type = 1;
  optional FailureAction failure_action = 2;
}

/**
 * Logs for the stats of AdServices process lifecycle.
 */
message AdServicesProcessLifecycleReported {
  // The type of an AdServices process event. It should be used to log the count of different types
  // of AdServices process events and will be aggregated to imply the frequency of each event.
  enum EventType {
    UNKNOWN = 0;

    // The AdServices process restarts.
    RESTART = 1;

    // The memory level of the AdServices process drops to a certain threshold.
    LOW_MEMORY_LEVEL = 2;
  }

  // The type of an AdServices process event.
  optional EventType event_type = 1;
}

/**
 * Logs for the stats for AdServices Process Stable Flags framework.
 */
message AdServicesProcessStableFlagsReported {
  // The latency to initialize flag values in microsecond.
  optional int64 initialization_latency_us = 1;
}

/**
 * Logs for the stats of AdServices flags updates.
 */
message AdServicesFlagUpdateReported {
  // The number of cache missed flags in an event of AdServices flag update.
  optional int32 num_of_cache_miss_flags = 1;
}

/**
 Logs the number of report impression requests for each destination along with its status.
*/
message ReportingWithDestinationPerformed {
  /* Type of reporting api: either report impression or report event */
  optional android.adservices.service.ReportingType reportingType = 1;

  /* Destination of this Report Impression call. */
  optional android.adservices.service.ReportingCallDestination destination = 2;

  /* Status of this Report Impression call. */
  optional android.adservices.service.ReportingCallStatus status = 3;
}

/**
Logs the number of different of reporting url returned by B&A
*/
message NumberOfTypesOfReportingUrlsReceived {
  /* Number of top level seller reporting urls. */
  optional int32 numberOfTopLevelSellerReportingUrl = 1;

  /* Number of buyer reporting urls. */
  optional int32 numberOfBuyerReportingUrl = 2;

  /* Number of component seller reporting urls. */
  optional int32 numberOfComponentSellerReportingUrl = 3;

  /* Number of buyer event reporting urls. */
  optional int32 numberOfBuyerEventReportingUrl = 4;

  /* Number of top level seller event reporting urls. */
  optional int32 numberOfTopLevelSellerEventReportingUrl = 5;

  /* Number of component event reporting urls. */
  optional int32 numberOfComponentEventReportingUrl = 6;
}

/** Logs the number of items processed per type per measurement background job. */
message MeasurementBackgroundItemsInfo {
  // Type of the items.
  optional int32 item_type = 1;

  // Number of items processed per type.
  optional int32 number_of_items = 2;

  // Timestamp of the oldest item processed per type per job.
  optional int64 oldest_item_timestamp = 3;
}

/** Wrapper to log the nested number of items processed per type per measurement background job. */
message RepeatedMeasurementBackgroundItemsInfo {
   repeated MeasurementBackgroundItemsInfo items_info = 1;
}

/**
 * Logging for Adservice's measurement background jobs information. Provides data for analyzing
 * measurement background jobs' health and workload.
 */
message AdservicesMeasurementBackgroundJobInfo {
  // A unique identifier for a background job
  optional int32 job_id = 1;

  // Information about items in the database before processing.
  optional RepeatedMeasurementBackgroundItemsInfo database_items_before_processing = 2
  [(log_mode) = MODE_BYTES];

  // Information about items being processed in the background job.
  // The number of items being processed doesn't always equal to items in the database before
  // processing because there may be redirects and retries.
  optional RepeatedMeasurementBackgroundItemsInfo items_processed = 3 [(log_mode) = MODE_BYTES];

  // Time interval from the start to the end of an execution of a background job.
  // It is on a milli-second basis.
  optional int32 job_duration = 4;

  // Type of the result code that implies different execution results of Adservices background jobs.
  optional android.adservices.ExecutionResultCode execution_result_code = 5;

  // 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 = 6;
}

/**
 * Used for checking if prod debug is enabled in auction server APIs.
 * Pushed from: packages/modules/AdServices/adservices
 */
message ProdDebugEnabledReported {
  optional bool is_enabled = 1;
}

/**
 * Used for checking if unified table is used in on device auction APIs.
 * Pushed from: packages/modules/AdServices/adservices
 */
message UnifiedTableEnabledReported {
  optional bool is_unified_table_enabled = 1;
  optional bool is_unified_dao_used = 2;
}

/**
* Logs the number of unique reporting origins per enrollment id in the past
* day when a source is registered.
* Logged from:
* packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/stats/StatsdAdServicesLogger.java
* Estimated Logging Rate:
*     Avg: 10x per device per day
*/
message AdServicesMeasurementReportingOriginsPerEnrollmentCounted {
 optional int64 unique_reporting_origins_count = 1;
}

/**
* Logs the number of unique reporting origins per enrollment id per
* destination in the past day when a source is registered.
* Logged from:
* packages/modules/AdServices/adservices/service-core/java/com/android/adservices/service/stats/StatsdAdServicesLogger.java
* Estimated Logging Rate:
*     Avg: 20x per device per day
*/
message AdServicesMeasurementReportingOriginsPerEnrllXDestCounted {
 optional int64 unique_reporting_origins_count = 1;
}
