/* * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * 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. */ #include "call_ability_callback_stub.h" #include #include "call_manager_errors.h" #include "telephony_log_wrapper.h" namespace OHOS { namespace Telephony { const int32_t MAX_LEN = 100000; CallAbilityCallbackStub::CallAbilityCallbackStub() { memberFuncMap_[UPDATE_CALL_STATE_INFO] = &CallAbilityCallbackStub::OnUpdateCallStateInfo; memberFuncMap_[UPDATE_CALL_EVENT] = &CallAbilityCallbackStub::OnUpdateCallEvent; memberFuncMap_[UPDATE_CALL_DISCONNECTED_CAUSE] = &CallAbilityCallbackStub::OnUpdateCallDisconnectedCause; memberFuncMap_[UPDATE_CALL_ASYNC_RESULT_REQUEST] = &CallAbilityCallbackStub::OnUpdateAysncResults; memberFuncMap_[REPORT_OTT_CALL_REQUEST] = &CallAbilityCallbackStub::OnUpdateOttCallRequest; memberFuncMap_[UPDATE_MMI_CODE_RESULT_REQUEST] = &CallAbilityCallbackStub::OnUpdateMmiCodeResults; } CallAbilityCallbackStub::~CallAbilityCallbackStub() { memberFuncMap_.clear(); } int32_t CallAbilityCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { std::u16string myDescriptor = CallAbilityCallbackStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (myDescriptor != remoteDescriptor) { TELEPHONY_LOGE("descriptor checked failed"); return TELEPHONY_ERR_DESCRIPTOR_MISMATCH; } TELEPHONY_LOGI("OnReceived, cmd = %{public}u", code); auto itFunc = memberFuncMap_.find(code); if (itFunc != memberFuncMap_.end()) { auto memberFunc = itFunc->second; if (memberFunc != nullptr) { return (this->*memberFunc)(data, reply); } } return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } int32_t CallAbilityCallbackStub::OnUpdateCallStateInfo(MessageParcel &data, MessageParcel &reply) { int32_t result = TELEPHONY_SUCCESS; const CallAttributeInfo *parcelPtr = nullptr; int32_t len = data.ReadInt32(); if (len <= 0 || len >= MAX_LEN) { TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len); return TELEPHONY_ERR_ARGUMENT_INVALID; } if (!data.ContainFileDescriptors()) { TELEPHONY_LOGW("sent raw data is less than 32k"); } if ((parcelPtr = reinterpret_cast(data.ReadRawData(len))) == nullptr) { TELEPHONY_LOGE("reading raw data failed, length = %{public}d", len); return TELEPHONY_ERR_LOCAL_PTR_NULL; } result = OnCallDetailsChange(*parcelPtr); if (!reply.WriteInt32(result)) { TELEPHONY_LOGE("writing parcel failed"); return TELEPHONY_ERR_WRITE_REPLY_FAIL; } return TELEPHONY_SUCCESS; } int32_t CallAbilityCallbackStub::OnUpdateCallEvent(MessageParcel &data, MessageParcel &reply) { int32_t result = TELEPHONY_SUCCESS; const CallEventInfo *parcelPtr = nullptr; int32_t len = data.ReadInt32(); if (len <= 0 || len >= MAX_LEN) { TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len); return TELEPHONY_ERR_ARGUMENT_INVALID; } if (!data.ContainFileDescriptors()) { TELEPHONY_LOGW("sent raw data is less than 32k"); } if ((parcelPtr = reinterpret_cast(data.ReadRawData(len))) == nullptr) { TELEPHONY_LOGE("reading raw data failed, length = %d", len); return TELEPHONY_ERR_LOCAL_PTR_NULL; } result = OnCallEventChange(*parcelPtr); if (!reply.WriteInt32(result)) { TELEPHONY_LOGE("writing parcel failed"); return TELEPHONY_ERR_WRITE_REPLY_FAIL; } return TELEPHONY_SUCCESS; } int32_t CallAbilityCallbackStub::OnUpdateCallDisconnectedCause(MessageParcel &data, MessageParcel &reply) { auto info = (DisconnectedDetails *)data.ReadRawData(sizeof(DisconnectedDetails)); int32_t result = OnCallDisconnectedCause(*info); if (!reply.WriteInt32(result)) { TELEPHONY_LOGE("writing parcel failed"); return TELEPHONY_ERR_WRITE_REPLY_FAIL; } return TELEPHONY_SUCCESS; } int32_t CallAbilityCallbackStub::OnUpdateAysncResults(MessageParcel &data, MessageParcel &reply) { int32_t result = TELEPHONY_SUCCESS; AppExecFwk::PacMap resultInfo; CallResultReportId reportId = static_cast(data.ReadInt32()); resultInfo.PutIntValue("result", data.ReadInt32()); switch (reportId) { case CallResultReportId::GET_CALL_WAITING_REPORT_ID: case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID: resultInfo.PutIntValue("status", data.ReadInt32()); resultInfo.PutIntValue("classCw", data.ReadInt32()); break; case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID: resultInfo.PutIntValue("status", data.ReadInt32()); resultInfo.PutIntValue("classx", data.ReadInt32()); resultInfo.PutStringValue("number", data.ReadString()); resultInfo.PutIntValue("type", data.ReadInt32()); resultInfo.PutIntValue("reason", data.ReadInt32()); resultInfo.PutIntValue("time", data.ReadInt32()); break; case CallResultReportId::GET_CALL_CLIP_ID: resultInfo.PutIntValue("action", data.ReadInt32()); resultInfo.PutIntValue("clipStat", data.ReadInt32()); break; case CallResultReportId::GET_CALL_CLIR_ID: resultInfo.PutIntValue("action", data.ReadInt32()); resultInfo.PutIntValue("clirStat", data.ReadInt32()); break; case CallResultReportId::START_RTT_REPORT_ID: resultInfo.PutIntValue("active", data.ReadInt32()); break; case CallResultReportId::GET_IMS_CONFIG_REPORT_ID: case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID: resultInfo.PutIntValue("value", data.ReadInt32()); break; case CallResultReportId::STOP_RTT_REPORT_ID: resultInfo.PutIntValue("inactive", data.ReadInt32()); break; default: break; } if (!data.ContainFileDescriptors()) { TELEPHONY_LOGW("sent raw data is less than 32k"); } result = OnReportAsyncResults(reportId, resultInfo); if (!reply.WriteInt32(result)) { TELEPHONY_LOGE("writing parcel failed"); return TELEPHONY_ERR_WRITE_REPLY_FAIL; } return TELEPHONY_SUCCESS; } int32_t CallAbilityCallbackStub::OnUpdateMmiCodeResults(MessageParcel &data, MessageParcel &reply) { int32_t result = TELEPHONY_SUCCESS; const MmiCodeInfo *parcelPtr = nullptr; int32_t len = data.ReadInt32(); if (len <= 0 || len >= MAX_LEN) { TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len); return TELEPHONY_ERR_ARGUMENT_INVALID; } if (!data.ContainFileDescriptors()) { TELEPHONY_LOGW("sent raw data is less than 32k"); } if ((parcelPtr = reinterpret_cast(data.ReadRawData(len))) == nullptr) { TELEPHONY_LOGE("reading raw data failed, length = %d", len); return TELEPHONY_ERR_LOCAL_PTR_NULL; } result = OnReportMmiCodeResult(*parcelPtr); if (!reply.WriteInt32(result)) { TELEPHONY_LOGE("writing parcel failed"); return TELEPHONY_ERR_WRITE_REPLY_FAIL; } return TELEPHONY_SUCCESS; } int32_t CallAbilityCallbackStub::OnUpdateOttCallRequest(MessageParcel &data, MessageParcel &reply) { int32_t result = TELEPHONY_SUCCESS; AppExecFwk::PacMap resultInfo; OttCallRequestId requestId = static_cast(data.ReadInt32()); resultInfo.PutStringValue("phoneNumber", data.ReadString()); resultInfo.PutStringValue("bundleName", data.ReadString()); resultInfo.PutIntValue("videoState", data.ReadInt32()); switch (requestId) { case OttCallRequestId::OTT_REQUEST_INVITE_TO_CONFERENCE: resultInfo.PutStringValue("number", data.ReadString()); break; case OttCallRequestId::OTT_REQUEST_UPDATE_CALL_MEDIA_MODE: resultInfo.PutIntValue("callMediaMode", data.ReadInt32()); break; default: break; } if (!data.ContainFileDescriptors()) { TELEPHONY_LOGW("sent raw data is less than 32k"); } result = OnOttCallRequest(requestId, resultInfo); if (!reply.WriteInt32(result)) { TELEPHONY_LOGE("writing parcel failed"); return TELEPHONY_ERR_WRITE_REPLY_FAIL; } return TELEPHONY_SUCCESS; } } // namespace Telephony } // namespace OHOS