mcu_hi3321_watch/tjd/ui/app/phone/call_app/TjdUiAppCallModel.cpp
2025-05-26 20:15:20 +08:00

118 lines
4.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
*
* Description: TjdUiAppCallModel.cpp
*
* Author: luziquan@ss-tjd.com
*
* Create: 2025-08-16
*--------------------------------------------------------------------------*/
#include "TjdUiAppCallModel.h"
#include "NativeAbility.h"
#include "TjdPhoneService.h"
#include "TjdUiAppCallPresenter.h"
#include "TjdUiAppIds.h"
#include "notification_manager.h"
#include "sys_config.h"
#define ENABLE_PRINT_INFO 1
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印一般常开
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#define static_print_debug(...)
#endif
namespace TJD {
static PhoneServiceCb g_phoneServiceCb;
static ContactsInfo *phoneCallInfo = nullptr;
// 通话状态改变回调函数
static void PhoneServiceCallChangedCb(const ContactsInfo *phoneCall)
{
phoneCallInfo = const_cast<ContactsInfo *>(phoneCall);
std::string number(reinterpret_cast<const char *>(phoneCall->tel), phoneCall->telLen);
// TjdUiAppCallModel::GetInstance().SetCallingTest(number);
TjdUiAppCallPresenter *presenter = TjdUiAppCallPresenter::GetInstance();
bool isShow = OHOS::NotificationManager::GetInstance()->HasNotifyShowing();
/* 手机接听,取消通知 */
if (phoneCall->operate == OPERATE_PHONE_ACTIVE) {
if (isShow) {
OHOS::NotificationManager::GetInstance()->StopNotify();
}
}
if (phoneCall->lastStatus == HFP_HF_CALL_STATE_FINISHED) {
phoneCallInfo = nullptr;
if (isShow) {
OHOS::NotificationManager::GetInstance()->StopNotify();
}
TjdUiAppCallModel::GetInstance().SetCallTime(0);
}
if (presenter == nullptr) {
static_print_error("TjdUiAppCallPresenter is nullptr");
return;
}
static_print_debug("PhoneServiceCallChangedCb name: %s, number: %s", number.c_str(), number.c_str());
presenter->PhoneServiceCallChangedCb(phoneCall->nameLen != 0 ? phoneCall->name : number, phoneCall->lastStatus);
}
// 电话服务失败回调函数
static void PhoneServiceErrorCb(PhoneServiceErrorType type, int volume)
{
static_print_debug("PhoneServiceErrorCb type: %d, volume: %d", type, volume);
}
// sco连接回调函数状态只有断开和连接两种状态 通话转移会导致sco连接和断连
static void PhoneServiceScoStatusCb(hfp_sco_connect_state_t state)
{
static_print_debug("PhoneServiceScoStatusCb state: %d", state);
TjdUiAppCallModel &model = TjdUiAppCallModel::GetInstance();
TjdUiAppCallPresenter *presenter = TjdUiAppCallPresenter::GetInstance();
if (state == HFP_SCO_STATE_CONNECTED) { // 通话转移:手机 -> 手表
if (presenter != nullptr) {
return;
} /* 如果通话界面不存在,切换到通话页面 */
if (phoneCallInfo == nullptr) {
return;
}
if (phoneCallInfo->unitCalls.state == HFP_HF_CALL_STATE_DIALING) {
model.SetShowViewType(ShowCallViewType::CALL_OUT_VIEW);
} else if (phoneCallInfo->unitCalls.state == HFP_HF_CALL_STATE_ACTIVE) {
/* 如果已经是接通状态则重新计算时间 */
model.SetCallTime(time(nullptr) - phoneCallInfo->activeTime);
model.SetShowViewType(ShowCallViewType::CALLING_VIEW);
}
static_print_debug("ChangeSlice TJD_APP_VIEW_CALL");
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_CALL);
} else if (state == HFP_SCO_STATE_DISCONNECTED) { // 通话转移:手表 -> 手机
/* 如果通话界面存在,取消页面 */
if (presenter != nullptr) {
if (TjdUiAppCallPresenter::quickChangeSlice != -1) {
OHOS::NativeAbility::GetInstance().ChangeSlice(TjdUiAppCallPresenter::quickChangeSlice);
TjdUiAppCallPresenter::quickChangeSlice = -1;
} else {
OHOS::NativeAbility::GetInstance().ChangePreSlice();
}
}
}
}
void TjdUiAppCallModel::InitCallService(void)
{
g_phoneServiceCb.callChanged = PhoneServiceCallChangedCb;
g_phoneServiceCb.phoneServiceErrorCb = PhoneServiceErrorCb;
g_phoneServiceCb.scoStatusCb = PhoneServiceScoStatusCb;
RegisterPhoneCallChangedCb(&g_phoneServiceCb);
}
} // namespace TJD