1 /*
2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ims_core_service_callback_stub.h"
17
18 #include "ims_core_service_client.h"
19 #include "radio_event.h"
20 #include "tel_event_handler.h"
21 #include "telephony_errors.h"
22 #include "telephony_log_wrapper.h"
23
24 namespace OHOS {
25 namespace Telephony {
ImsCoreServiceCallbackStub()26 ImsCoreServiceCallbackStub::ImsCoreServiceCallbackStub()
27 {
28 TELEPHONY_LOGI("ImsCoreServiceCallbackStub");
29 InitFuncMap();
30 }
31
~ImsCoreServiceCallbackStub()32 ImsCoreServiceCallbackStub::~ImsCoreServiceCallbackStub()
33 {
34 requestFuncMap_.clear();
35 }
36
InitFuncMap()37 void ImsCoreServiceCallbackStub::InitFuncMap()
38 {
39 /****************** ims basic ability ******************/
40 requestFuncMap_[static_cast<uint32_t>(ImsCoreServiceCallbackInterfaceCode::IMS_SERVICE_STATUS_REPORT)] =
41 [this](MessageParcel &data, MessageParcel &reply) { return OnImsServiceStatusReportInner(data, reply); };
42 requestFuncMap_[static_cast<uint32_t>(ImsCoreServiceCallbackInterfaceCode::IMS_GET_REGISTRATION_STATUS)] =
43 [this](
44 MessageParcel &data, MessageParcel &reply) { return OnGetImsRegistrationStatusResponseInner(data, reply); };
45 }
46
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)47 int32_t ImsCoreServiceCallbackStub::OnRemoteRequest(
48 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
49 {
50 std::u16string myDescriptor = ImsCoreServiceCallbackStub::GetDescriptor();
51 std::u16string remoteDescriptor = data.ReadInterfaceToken();
52 if (myDescriptor != remoteDescriptor) {
53 TELEPHONY_LOGE("OnRemoteRequest return, descriptor checked fail");
54 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
55 }
56 auto itFunc = requestFuncMap_.find(code);
57 if (itFunc != requestFuncMap_.end()) {
58 auto requestFunc = itFunc->second;
59 if (requestFunc != nullptr) {
60 return requestFunc(data, reply);
61 }
62 }
63 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::OnRemoteRequest, default case, need check.");
64 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65 }
66
OnImsServiceStatusReportInner(MessageParcel & data,MessageParcel & reply)67 int32_t ImsCoreServiceCallbackStub::OnImsServiceStatusReportInner(MessageParcel &data, MessageParcel &reply)
68 {
69 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::onImsServiceStatusReportInner entry");
70 int32_t slotId = data.ReadInt32();
71 auto imsServiceStatus = (ImsServiceStatus *)data.ReadRawData(sizeof(ImsServiceStatus));
72 if (imsServiceStatus == nullptr) {
73 TELEPHONY_LOGE("onImsServiceStatusReportInner return, imsServiceStatus is nullptr.");
74 return TELEPHONY_ERR_ARGUMENT_INVALID;
75 }
76 reply.WriteInt32(UpdateImsServiceStatusChanged(slotId, *imsServiceStatus));
77 return TELEPHONY_SUCCESS;
78 }
79
UpdateImsServiceStatusChanged(int32_t slotId,const ImsServiceStatus & imsServiceStatus)80 int32_t ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged(
81 int32_t slotId, const ImsServiceStatus &imsServiceStatus)
82 {
83 TELEPHONY_LOGD("ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged entry");
84 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient = DelayedSingleton<ImsCoreServiceClient>::GetInstance();
85 if (imsCoreServiceClient->GetHandler(slotId) == nullptr) {
86 TELEPHONY_LOGE("get handler was null! slotId is %{public}d", slotId);
87 return TELEPHONY_ERR_LOCAL_PTR_NULL;
88 }
89 std::shared_ptr<ImsServiceStatus> imsServiceState = std::make_shared<ImsServiceStatus>();
90 if (imsServiceState.get() == nullptr) {
91 TELEPHONY_LOGE("make_shared ImsServiceStatus failed!");
92 return TELEPHONY_ERR_LOCAL_PTR_NULL;
93 }
94
95 *imsServiceState = imsServiceStatus;
96 TelEventHandler::SendTelEvent(
97 imsCoreServiceClient->GetHandler(slotId), RadioEvent::RADIO_IMS_SERVICE_STATUS_UPDATE, imsServiceState);
98 return TELEPHONY_SUCCESS;
99 }
100
OnGetImsRegistrationStatusResponseInner(MessageParcel & data,MessageParcel & reply)101 int32_t ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner(MessageParcel &data, MessageParcel &reply)
102 {
103 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner entry");
104 int32_t slotId = data.ReadInt32();
105 auto imsRegStatus = (ImsRegistrationStatus *)data.ReadRawData(sizeof(ImsRegistrationStatus));
106 if (imsRegStatus == nullptr) {
107 TELEPHONY_LOGE("imsRegStatus is nullptr.");
108 return TELEPHONY_ERR_ARGUMENT_INVALID;
109 }
110 reply.WriteInt32(GetImsRegistrationStatusResponse(slotId, *imsRegStatus));
111 return TELEPHONY_SUCCESS;
112 }
113
GetImsRegistrationStatusResponse(int32_t slotId,const ImsRegistrationStatus & imsRegStatus)114 int32_t ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse(
115 int32_t slotId, const ImsRegistrationStatus &imsRegStatus)
116 {
117 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse entry");
118 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient = DelayedSingleton<ImsCoreServiceClient>::GetInstance();
119 if (imsCoreServiceClient->GetHandler(slotId) == nullptr) {
120 TELEPHONY_LOGE("get handler was null! slotId is %{public}d", slotId);
121 return TELEPHONY_ERR_LOCAL_PTR_NULL;
122 }
123 std::shared_ptr<int32_t> isRegisterd = std::make_shared<int32_t>();
124 *isRegisterd = imsRegStatus.isRegisterd ? 1 : 0;
125 TelEventHandler::SendTelEvent(
126 imsCoreServiceClient->GetHandler(slotId), RadioEvent::RADIO_IMS_REGISTER_STATE_UPDATE, isRegisterd);
127 return TELEPHONY_SUCCESS;
128 }
129 } // namespace Telephony
130 } // namespace OHOS
131