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

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

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

extend Atom {
    optional EmergencyNumberDialed emergency_number_dialed = 637 [(module) = "telecom"];
    optional CallStats call_stats = 10221 [(module) = "telecom"];
    optional CallAudioRouteStats call_audio_route_stats = 10222 [(module) = "telecom"];
    optional TelecomApiStats telecom_api_stats = 10223 [(module) = "telecom"];
    optional TelecomErrorStats telecom_error_stats = 10224 [(module) = "telecom"];
    optional TelecomEventStats telecom_event_stats = 10235 [(module) = "telecom"];
    optional CallSequencingStats call_sequencing_stats = 10242 [(module) = "telecom"];
    optional CallSequencingOperationStats call_sequencing_operation_stats = 10243 [(module) = "telecom"];
}

/**
 * Pushed atom to capture dialed emergency number details.
 */
message EmergencyNumberDialed {
    // the emergency number that was actually dialed (including any carrier prefix)
    optional string number = 1;

    // system dialer package for emergency call
    optional string system_dialer_package = 2;

    // sim mcc mnc
    optional string sim_mccmnc = 3;

    // mcc mnc of the latched network to make emergency call
    optional string network_mccmnc = 4;
}

/**
 * Pulled atom to capture stats of the calls
 */
message CallStats {
    // The call direction. Eg. INCOMING, OUTGOING, UNKNOWN
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallDirectionEnum call_direction = 1;

    // True if call is external. External calls are calls on connected Wear
    // devices but show up in Telecom so the user can pull them onto the device.
    optional bool external_call = 2;

    // True if call is emergency call.
    optional bool emergency_call = 3;

    // True if there are multiple audio routes available
    optional bool multiple_audio_available = 4;

    // The account type of the call. Eg. SIM, Managed, SelfManaged, VoipApi
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.AccountTypeEnum account_type = 5;

    // UID of the package to init the call. This should always be -1/unknown for
    // the private space calls
    optional int32 uid = 6 [(is_uid) = true];

    // Total number of the calls
    optional int32 count = 7;

    // Average elapsed time between CALL_STATE_ACTIVE to CALL_STATE_DISCONNECTED.
    optional int32 average_duration_ms = 8;

    // The disconnect cause of the call. Eg. ERROR, LOCAL, REMOTE, etc.
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.DisconnectCauseEnum disconnect_cause = 9;

    // The type of simultaneous call type. Eg. SINGLE, DUAL_SAME_ACCOUNT,
    // DUAL_DIFF_ACCOUNT, etc.
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.SimultaneousTypeEnum simultaneous_type = 10;

    // True if it is a video call
    optional bool video_call = 11;
}

/**
 * Pulled atom to capture stats of the call audio route
 */
message CallAudioRouteStats {
    // The source the call audio route. The types include CALL_AUDIO_ROUTE_UNSPECIFIED,
    // CALL_AUDIO_ROUTE_PHONE_SPEAKER, CALL_AUDIO_ROUTE_WATCH_SPEAKER,
    // CALL_AUDIO_ROUTE_BLUETOOTH, CALL_AUDIO_ROUTE_AUTO, or
    // CALL_AUDIO_ROUTE_BLUETOOTH_LE from
    // frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallAudioEnum route_source = 1;

    // The destination of the audio route. The types are defined in
    // frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallAudioEnum route_dest = 2;

    // True if the route is successful.
    optional bool success = 3;

    // True if the route is revert
    optional bool revert = 4;

    // Total number of the audio route
    optional int32 count = 5;

    // Average time from the audio route start to complete
    optional int32 average_latency_ms = 6;
}

/**
 * Pulled atom to capture stats of Telecom API usage
 */
message TelecomApiStats {
    // The api name
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.ApiNameEnum api_name = 1;

    // UID of the caller. This is always -1/unknown for the private space.
    optional int32 uid = 2 [(is_uid) = true];

    // The result of the API call
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.ApiResultEnum api_result = 3;

    // The number of times this event occurs
    optional int32 count = 4;
}

/**
 * Pulled atom to capture stats of Telecom module errors
 */
message TelecomErrorStats {
    // The sub module name
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.SubmoduleEnum submodule = 1;

    // The error name
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.ErrorEnum error = 2;

    // The number of times this error occurs
    optional int32 count = 3;
}

/**
 * Pulled atom to capture stats of Telecom critical events
 */
message TelecomEventStats {
    // The event name
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.EventEnum event = 1;

    // UID of the caller. This is always -1/unknown for the private space.
    optional int32 uid = 2 [(is_uid) = true];

    // The cause related to the event
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.EventCauseEnum event_cause = 3;

    // The number of times this event occurs
    optional int32 count = 4;
}

/**
 * Pulled atom to capture general stats of Telecom call sequencing information
 */
message CallSequencingStats {
    // The value should be converted to android.telecom.CallTypeEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallTypeEnum primary_call_type = 1;

    // The value should be converted to android.telecom.CallTypeEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallTypeEnum secondary_call_type = 2;

    // True if the primary call is an emergency call
    optional bool is_primary_call_emergency = 3;

    // True if the secondary call is an emergency call
    optional bool is_secondary_call_emergency = 4;

    // True if this event is tracking a secondary call
    optional bool has_secondary = 5;

    // True if primary and secondary call phone accounts are the same
    optional bool is_same_phone_account = 6;

    // Average elapsed time between CALL_STATE_ACTIVE to CALL_STATE_DISCONNECTED.
    optional int32 average_duration_ms = 7;

    // The number of times this stat occurs
    optional int32 count = 8;
}

/**
 * Pulled atom to capture stats of Telecom call sequencing operations
 */
message CallSequencingOperationStats {
    // The value should be converted to android.telecom.CallOperationTypeEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallOperationTypeEnum call_operation = 1;

    // The value should be converted to android.telecom.CallStateEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallStateEnum focus_call_state = 2;

    // The value should be converted to android.telecom.CallStateEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallStateEnum source_call_state = 3;

    // The value should be converted to android.telecom.CallTypeEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallTypeEnum focus_call_type = 4;

    // The value should be converted to android.telecom.CallTypeEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallTypeEnum source_call_type = 5;

    // Carrier name of focus call. This should always be empty/unknown for
    // the private space calls
    optional int32 focus_call_carrier_id = 6;

    // Carrier name of the source call. This should always be empty/unknown for
    // the private space calls or if source call isn’t defined
    optional int32 source_call_carrier_id = 7;

    // UID of the package to init the call. This should always be -1/unknown for
    // the private space calls
    optional int32 focus_call_uid = 8 [(is_uid) = true];

    // UID of the package to init the call. This should always be -1/unknown for
    // the private space calls or if source call isn’t defined
    optional int32 source_call_uid = 9 [(is_uid) = true];

    // True if the focus call is an emergency call
    optional bool is_focus_call_emergency = 10;

    // True if the source call is an emergency call
    optional bool is_source_call_emergency = 11;

    // The value should be converted to android.telecom.CallOperationResultEnum
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional android.telecom.CallOperationResultEnum operation_result = 12;

    // True if source call (provided that this is present) and focus call
    // are from same phone accounts
    optional bool is_same_phone_account = 13;

    // Duration (ms) taken for operation to complete
    optional int32 operation_duration_ms = 14;
}
