1e1c44949Sopenharmony_ci/*
2e1c44949Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License.
5e1c44949Sopenharmony_ci * You may obtain a copy of the License at
6e1c44949Sopenharmony_ci *
7e1c44949Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e1c44949Sopenharmony_ci *
9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and
13e1c44949Sopenharmony_ci * limitations under the License.
14e1c44949Sopenharmony_ci */
15e1c44949Sopenharmony_ci
16e1c44949Sopenharmony_ci#include "bluetooth_call_policy.h"
17e1c44949Sopenharmony_ci
18e1c44949Sopenharmony_ci#include "call_manager_errors.h"
19e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h"
20e1c44949Sopenharmony_ci
21e1c44949Sopenharmony_cinamespace OHOS {
22e1c44949Sopenharmony_cinamespace Telephony {
23e1c44949Sopenharmony_ciBluetoothCallPolicy::BluetoothCallPolicy() {}
24e1c44949Sopenharmony_ci
25e1c44949Sopenharmony_ciBluetoothCallPolicy::~BluetoothCallPolicy() {}
26e1c44949Sopenharmony_ci
27e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::AnswerCallPolicy(int32_t &callId)
28e1c44949Sopenharmony_ci{
29e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_INCOMING, callId)) {
30e1c44949Sopenharmony_ci        TELEPHONY_LOGI("incoming call is exist, callId:%{public}d", callId);
31e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
32e1c44949Sopenharmony_ci    }
33e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_WAITING, callId)) {
34e1c44949Sopenharmony_ci        TELEPHONY_LOGI("waiting call is exist, callId:%{public}d", callId);
35e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
36e1c44949Sopenharmony_ci    }
37e1c44949Sopenharmony_ci    TELEPHONY_LOGW("AnswerCallPolicy failed");
38e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
39e1c44949Sopenharmony_ci}
40e1c44949Sopenharmony_ci
41e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::RejectCallPolicy(int32_t &callId)
42e1c44949Sopenharmony_ci{
43e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_INCOMING, callId)) {
44e1c44949Sopenharmony_ci        TELEPHONY_LOGI("incoming call is exist, callId:%{public}d", callId);
45e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
46e1c44949Sopenharmony_ci    }
47e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_WAITING, callId)) {
48e1c44949Sopenharmony_ci        TELEPHONY_LOGI("waiting call is exist, callId:%{public}d", callId);
49e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
50e1c44949Sopenharmony_ci    }
51e1c44949Sopenharmony_ci    TELEPHONY_LOGW("RejectCallPolicy failed");
52e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
53e1c44949Sopenharmony_ci}
54e1c44949Sopenharmony_ci
55e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::HoldCallPolicy(int32_t &callId)
56e1c44949Sopenharmony_ci{
57e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
58e1c44949Sopenharmony_ci        TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
59e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
60e1c44949Sopenharmony_ci    }
61e1c44949Sopenharmony_ci    TELEPHONY_LOGW("HoldCallPolicy failed");
62e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
63e1c44949Sopenharmony_ci}
64e1c44949Sopenharmony_ci
65e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::UnHoldCallPolicy(int32_t &callId)
66e1c44949Sopenharmony_ci{
67e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
68e1c44949Sopenharmony_ci        TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
69e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
70e1c44949Sopenharmony_ci    }
71e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
72e1c44949Sopenharmony_ci        TELEPHONY_LOGI("holding call is exist, callId:%{public}d", callId);
73e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
74e1c44949Sopenharmony_ci    }
75e1c44949Sopenharmony_ci    TELEPHONY_LOGW("HoldCallPolicy failed");
76e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
77e1c44949Sopenharmony_ci}
78e1c44949Sopenharmony_ci
79e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::HangUpPolicy(int32_t &callId)
80e1c44949Sopenharmony_ci{
81e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
82e1c44949Sopenharmony_ci        TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
83e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
84e1c44949Sopenharmony_ci    }
85e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_DIALING, callId)) {
86e1c44949Sopenharmony_ci        TELEPHONY_LOGI("dialing call is exist, callId:%{public}d", callId);
87e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
88e1c44949Sopenharmony_ci    }
89e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ALERTING, callId)) {
90e1c44949Sopenharmony_ci        TELEPHONY_LOGI("alerting call is exist, callId:%{public}d", callId);
91e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
92e1c44949Sopenharmony_ci    }
93e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_INCOMING, callId)) {
94e1c44949Sopenharmony_ci        TELEPHONY_LOGI("incoming call is exist, callId:%{public}d", callId);
95e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
96e1c44949Sopenharmony_ci    }
97e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_WAITING, callId)) {
98e1c44949Sopenharmony_ci        TELEPHONY_LOGI("waiting call is exist, callId:%{public}d", callId);
99e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
100e1c44949Sopenharmony_ci    }
101e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
102e1c44949Sopenharmony_ci        TELEPHONY_LOGI("holding call is exist, callId:%{public}d", callId);
103e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
104e1c44949Sopenharmony_ci    }
105e1c44949Sopenharmony_ci    TELEPHONY_LOGW("HangUpPolicy failed");
106e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
107e1c44949Sopenharmony_ci}
108e1c44949Sopenharmony_ci
109e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::SwitchCallPolicy(int32_t &callId)
110e1c44949Sopenharmony_ci{
111e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE) &&
112e1c44949Sopenharmony_ci        IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
113e1c44949Sopenharmony_ci        TELEPHONY_LOGI("active call and holding call are exist, callId:%{public}d", callId);
114e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
115e1c44949Sopenharmony_ci    }
116e1c44949Sopenharmony_ci    TELEPHONY_LOGW("SwitchCallPolicy failed");
117e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
118e1c44949Sopenharmony_ci}
119e1c44949Sopenharmony_ci
120e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::StartDtmfPolicy(int32_t &callId)
121e1c44949Sopenharmony_ci{
122e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId)) {
123e1c44949Sopenharmony_ci        TELEPHONY_LOGI("active call is exist, callId:%{public}d", callId);
124e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
125e1c44949Sopenharmony_ci    }
126e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ALERTING, callId)) {
127e1c44949Sopenharmony_ci        TELEPHONY_LOGI("alerting call is exist, callId:%{public}d", callId);
128e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
129e1c44949Sopenharmony_ci    }
130e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_DIALING, callId)) {
131e1c44949Sopenharmony_ci        TELEPHONY_LOGI("dialing call is exist, callId:%{public}d", callId);
132e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
133e1c44949Sopenharmony_ci    }
134e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_HOLDING, callId)) {
135e1c44949Sopenharmony_ci        TELEPHONY_LOGI("holding call is exist, callId:%{public}d", callId);
136e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
137e1c44949Sopenharmony_ci    }
138e1c44949Sopenharmony_ci    TELEPHONY_LOGW("StartDtmfPolicy failed");
139e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
140e1c44949Sopenharmony_ci}
141e1c44949Sopenharmony_ci
142e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::CombineConferencePolicy(int32_t &callId)
143e1c44949Sopenharmony_ci{
144e1c44949Sopenharmony_ci    if (IsCallExist(TelCallState::CALL_STATUS_ACTIVE, callId) &&
145e1c44949Sopenharmony_ci        IsCallExist(TelCallState::CALL_STATUS_HOLDING)) {
146e1c44949Sopenharmony_ci        TELEPHONY_LOGI("active call and holding call are exist, callId:%{public}d", callId);
147e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
148e1c44949Sopenharmony_ci    }
149e1c44949Sopenharmony_ci    TELEPHONY_LOGW("CombineConferencePolicy failed");
150e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
151e1c44949Sopenharmony_ci}
152e1c44949Sopenharmony_ci
153e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::SeparateConferencePolicy(int32_t &callId)
154e1c44949Sopenharmony_ci{
155e1c44949Sopenharmony_ci    if (IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_ACTIVE, callId) ||
156e1c44949Sopenharmony_ci        IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_HOLDING, callId)) {
157e1c44949Sopenharmony_ci        TELEPHONY_LOGI("conference call is exist, callId:%{public}d", callId);
158e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
159e1c44949Sopenharmony_ci    }
160e1c44949Sopenharmony_ci    TELEPHONY_LOGW("SeparateConferencePolicy failed");
161e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
162e1c44949Sopenharmony_ci}
163e1c44949Sopenharmony_ci
164e1c44949Sopenharmony_ciint32_t BluetoothCallPolicy::KickOutFromConferencePolicy(int32_t &callId)
165e1c44949Sopenharmony_ci{
166e1c44949Sopenharmony_ci    if (IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_ACTIVE, callId) ||
167e1c44949Sopenharmony_ci        IsConferenceCallExist(TelConferenceState::TEL_CONFERENCE_HOLDING, callId)) {
168e1c44949Sopenharmony_ci        TELEPHONY_LOGI("conference call is exist, callId:%{public}d", callId);
169e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
170e1c44949Sopenharmony_ci    }
171e1c44949Sopenharmony_ci    TELEPHONY_LOGW("KickOutFromConferencePolicy failed");
172e1c44949Sopenharmony_ci    return CALL_ERR_ILLEGAL_CALL_OPERATION;
173e1c44949Sopenharmony_ci}
174e1c44949Sopenharmony_ci} // namespace Telephony
175e1c44949Sopenharmony_ci} // namespace OHOS
176