/*
 * Copyright (C) 2018 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.
 */

package android.hardware.audio@5.0;

import android.hardware.audio.common@5.0;
import IDevice;

interface IPrimaryDevice extends IDevice {
    /**
     * Sets the audio volume of a voice call.
     *
     * @param volume 1.0f means unity, 0.0f is zero.
     * @return retval operation completion status.
     */
    setVoiceVolume(float volume) generates (Result retval);

    /**
     * This method is used to notify the HAL about audio mode changes.
     *
     * @param mode new mode.
     * @return retval operation completion status.
     */
    setMode(AudioMode mode) generates (Result retval);

    /**
     * Sets the name of the current BT SCO headset. Calling this method
     * is equivalent to setting legacy "bt_headset_name" parameter.
     * The BT SCO headset name must only be used for debugging purposes.
     * Optional method
     *
     * @param name the name of the current BT SCO headset (can be empty).
     * @return retval operation completion status.
     */
    setBtScoHeadsetDebugName(string name) generates (Result retval);

    /**
     * Gets whether BT SCO Noise Reduction and Echo Cancellation are enabled.
     * Calling this method is equivalent to getting AUDIO_PARAMETER_KEY_BT_NREC
     * on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether BT SCO NR + EC are enabled.
     */
    getBtScoNrecEnabled() generates (Result retval, bool enabled);

    /**
     * Sets whether BT SCO Noise Reduction and Echo Cancellation are enabled.
     * Calling this method is equivalent to setting AUDIO_PARAMETER_KEY_BT_NREC
     * on the legacy HAL.
     * Optional method
     *
     * @param enabled whether BT SCO NR + EC are enabled.
     * @return retval operation completion status.
     */
    setBtScoNrecEnabled(bool enabled) generates (Result retval);

    /**
     * Gets whether BT SCO Wideband mode is enabled. Calling this method is
     * equivalent to getting AUDIO_PARAMETER_KEY_BT_SCO_WB on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether BT Wideband is enabled.
     */
    getBtScoWidebandEnabled() generates (Result retval, bool enabled);

    /**
     * Sets whether BT SCO Wideband mode is enabled. Calling this method is
     * equivalent to setting AUDIO_PARAMETER_KEY_BT_SCO_WB on the legacy HAL.
     * Optional method
     *
     * @param enabled whether BT Wideband is enabled.
     * @return retval operation completion status.
     */
    setBtScoWidebandEnabled(bool enabled) generates (Result retval);

    /**
     * Gets whether BT HFP (Hands-Free Profile) is enabled. Calling this method
     * is equivalent to getting "hfp_enable" parameter value on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether BT HFP is enabled.
     */
    getBtHfpEnabled() generates (Result retval, bool enabled);

    /**
     * Sets whether BT HFP (Hands-Free Profile) is enabled. Calling this method
     * is equivalent to setting "hfp_enable" parameter on the legacy HAL.
     * Optional method
     *
     * @param enabled whether BT HFP is enabled.
     * @return retval operation completion status.
     */
    setBtHfpEnabled(bool enabled) generates (Result retval);

    /**
     * Sets the sampling rate of BT HFP (Hands-Free Profile). Calling this
     * method is equivalent to setting "hfp_set_sampling_rate" parameter
     * on the legacy HAL.
     * Optional method
     *
     * @param sampleRateHz sample rate in Hz.
     * @return retval operation completion status.
     */
    setBtHfpSampleRate(uint32_t sampleRateHz) generates (Result retval);

    /**
     * Sets the current output volume Hz for BT HFP (Hands-Free Profile).
     * Calling this method is equivalent to setting "hfp_volume" parameter value
     * on the legacy HAL (except that legacy HAL implementations expect
     * an integer value in the range from 0 to 15.)
     * Optional method
     *
     * @param volume 1.0f means unity, 0.0f is zero.
     * @return retval operation completion status.
     */
    setBtHfpVolume(float volume) generates (Result retval);

    enum TtyMode : int32_t {
        OFF,
        VCO,
        HCO,
        FULL
    };

    /**
     * Gets current TTY mode selection. Calling this method is equivalent to
     * getting AUDIO_PARAMETER_KEY_TTY_MODE on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return mode TTY mode.
     */
    getTtyMode() generates (Result retval, TtyMode mode);

    /**
     * Sets current TTY mode. Calling this method is equivalent to setting
     * AUDIO_PARAMETER_KEY_TTY_MODE on the legacy HAL.
     *
     * @param mode TTY mode.
     * @return retval operation completion status.
     */
    setTtyMode(TtyMode mode) generates (Result retval);

    /**
     * Gets whether Hearing Aid Compatibility - Telecoil (HAC-T) mode is
     * enabled. Calling this method is equivalent to getting
     * AUDIO_PARAMETER_KEY_HAC on the legacy HAL.
     *
     * @return retval operation completion status.
     * @return enabled whether HAC mode is enabled.
     */
    getHacEnabled() generates (Result retval, bool enabled);

    /**
     * Sets whether Hearing Aid Compatibility - Telecoil (HAC-T) mode is
     * enabled. Calling this method is equivalent to setting
     * AUDIO_PARAMETER_KEY_HAC on the legacy HAL.
     * Optional method
     *
     * @param enabled whether HAC mode is enabled.
     * @return retval operation completion status.
     */
    setHacEnabled(bool enabled) generates (Result retval);

    enum Rotation : int32_t {
        DEG_0,
        DEG_90,
        DEG_180,
        DEG_270
    };

    /**
     * Updates HAL on the current rotation of the device relative to natural
     * orientation. Calling this method is equivalent to setting legacy
     * parameter "rotation".
     *
     * @param rotation rotation in degrees relative to natural device
     *     orientation.
     * @return retval operation completion status.
     */
    updateRotation(Rotation rotation) generates (Result retval);
};
