/*
 * Copyright (C) 2024 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.wear.time;

import "frameworks/proto_logging/stats/atoms.proto";
import "frameworks/proto_logging/stats/atom_field_options.proto";
import "frameworks/proto_logging/stats/enums/wear/time/enums.proto";

option java_package = "com.android.os.wear.time";
option java_multiple_files = true;

/**
 * All logs are logged from package:
 * vendor/google_clockwork/packages/Settings/src/com/google/android/clockwork/settings/time/
 */

extend Atom {
  optional WearTimeSyncRequested wear_time_sync_requested = 911 [(module) = "wear_settings"];
  optional WearTimeUpdateStarted wear_time_update_started = 912 [(module) = "wear_settings"];
  optional WearTimeSyncAttemptCompleted wear_time_sync_attempt_completed = 913 [(module) = "wear_settings"];
  optional WearTimeChanged wear_time_changed = 914 [(module) = "wear_settings"];
}

/**
 * Logged whenever there is a call to TimeService onHandleIntent for time sync.
 */
message WearTimeSyncRequested {

  // The type of time sync request that initiated this sync call
  // either an EVALUATE, a POLL, or COMPANION_CONNECTION event
  optional com.google.android.apps.wearable.settings.RequestTypeEnum request_type = 1;

  // The location from which the time sync service was started
  // either BOOT, OOBE, COMPANION_CONNECTION, TOGGLE, or PERIODIC_JOB
  optional com.google.android.apps.wearable.settings.SourceTypeEnum source_type = 2;
}

/**
 * Logged whenever a time sync is actually triggered from a specific origin.
 */
message WearTimeUpdateStarted {

  // The origin of the update ie. the source of the time that will be used in the update
  // either COMPANION, NETWORK, NITZ, or GNSS
  optional com.google.android.apps.wearable.settings.OriginTypeEnum origin_type = 1;

  // Whether the watch is standalone
  optional bool is_standalone = 2;

  // Whether or not sync from companion was attempted prior to fallbacks
  // If origin type for this event is COMPANION, this field will default to true
  // If device is standalone or didn't have a connection to its companion, this will be false
  optional bool is_phone_sync_attempted = 3;
}

/**
 * Logged whenever an attempt to time sync completes.
 */
message WearTimeSyncAttemptCompleted {

  // The origin of the update ie. the source of the time that was used in the update
  // either COMPANION, NETWORK, NITZ, or GNSS
  optional com.google.android.apps.wearable.settings.OriginTypeEnum origin_type = 1;

  // Whether the attempt to time sync was successful
  optional bool is_success = 2;

  // How many times sync was attempted prior to this event, for this request
  optional int32 number_of_retries = 3;

  // Reason why the sync failed, if the attempt was a failure
  // either TIMEOUT, LATENCY, or COMPANION_INVALID_RESPONSE
  // null if the attempt was successful
  optional com.google.android.apps.wearable.settings.FailureReasonEnum failure_reason = 4;
}

/**
 * Logged whenever time sync actually updates the time on the device.
 */
message WearTimeChanged {

  // The origin of the update ie. the source of the time that was used in the update
  // either COMPANION, NETWORK, NITZ, or GNSS
  optional com.google.android.apps.wearable.settings.OriginTypeEnum origin_type = 1;

  // The absolute difference (skew) in timestamps between the old and new times
  optional int64 time_difference_ms = 2;
}

