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 &ImsCoreServiceCallbackStub::OnImsServiceStatusReportInner;
42 requestFuncMap_[static_cast<uint32_t>(ImsCoreServiceCallbackInterfaceCode::IMS_GET_REGISTRATION_STATUS)] =
43 &ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner;
44 }
45
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int32_t ImsCoreServiceCallbackStub::OnRemoteRequest(
47 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
48 {
49 std::u16string myDescriptor = ImsCoreServiceCallbackStub::GetDescriptor();
50 std::u16string remoteDescriptor = data.ReadInterfaceToken();
51 if (myDescriptor != remoteDescriptor) {
52 TELEPHONY_LOGE("OnRemoteRequest return, descriptor checked fail");
53 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
54 }
55 auto itFunc = requestFuncMap_.find(code);
56 if (itFunc != requestFuncMap_.end()) {
57 auto requestFunc = itFunc->second;
58 if (requestFunc != nullptr) {
59 return (this->*requestFunc)(data, reply);
60 }
61 }
62 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::OnRemoteRequest, default case, need check.");
63 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
64 }
65
OnImsServiceStatusReportInner(MessageParcel & data,MessageParcel & reply)66 int32_t ImsCoreServiceCallbackStub::OnImsServiceStatusReportInner(MessageParcel &data, MessageParcel &reply)
67 {
68 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::onImsServiceStatusReportInner entry");
69 int32_t slotId = data.ReadInt32();
70 auto imsServiceStatus = (ImsServiceStatus *)data.ReadRawData(sizeof(ImsServiceStatus));
71 if (imsServiceStatus == nullptr) {
72 TELEPHONY_LOGE("onImsServiceStatusReportInner return, imsServiceStatus is nullptr.");
73 return TELEPHONY_ERR_ARGUMENT_INVALID;
74 }
75 reply.WriteInt32(UpdateImsServiceStatusChanged(slotId, *imsServiceStatus));
76 return TELEPHONY_SUCCESS;
77 }
78
UpdateImsServiceStatusChanged(int32_t slotId,const ImsServiceStatus & imsServiceStatus)79 int32_t ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged(
80 int32_t slotId, const ImsServiceStatus &imsServiceStatus)
81 {
82 TELEPHONY_LOGD("ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged entry");
83 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient = DelayedSingleton<ImsCoreServiceClient>::GetInstance();
84 if (imsCoreServiceClient->GetHandler(slotId) == nullptr) {
85 TELEPHONY_LOGE("get handler was null! slotId is %{public}d", slotId);
86 return TELEPHONY_ERR_LOCAL_PTR_NULL;
87 }
88 std::shared_ptr<ImsServiceStatus> imsServiceState = std::make_shared<ImsServiceStatus>();
89 if (imsServiceState.get() == nullptr) {
90 TELEPHONY_LOGE("make_shared ImsServiceStatus failed!");
91 return TELEPHONY_ERR_LOCAL_PTR_NULL;
92 }
93
94 *imsServiceState = imsServiceStatus;
95 TelEventHandler::SendTelEvent(
96 imsCoreServiceClient->GetHandler(slotId), RadioEvent::RADIO_IMS_SERVICE_STATUS_UPDATE, imsServiceState);
97 return TELEPHONY_SUCCESS;
98 }
99
OnGetImsRegistrationStatusResponseInner(MessageParcel & data,MessageParcel & reply)100 int32_t ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner(MessageParcel &data, MessageParcel &reply)
101 {
102 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner entry");
103 int32_t slotId = data.ReadInt32();
104 auto imsRegStatus = (ImsRegistrationStatus *)data.ReadRawData(sizeof(ImsRegistrationStatus));
105 if (imsRegStatus == nullptr) {
106 TELEPHONY_LOGE("imsRegStatus is nullptr.");
107 return TELEPHONY_ERR_ARGUMENT_INVALID;
108 }
109 reply.WriteInt32(GetImsRegistrationStatusResponse(slotId, *imsRegStatus));
110 return TELEPHONY_SUCCESS;
111 }
112
GetImsRegistrationStatusResponse(int32_t slotId,const ImsRegistrationStatus & imsRegStatus)113 int32_t ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse(
114 int32_t slotId, const ImsRegistrationStatus &imsRegStatus)
115 {
116 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse entry");
117 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient = DelayedSingleton<ImsCoreServiceClient>::GetInstance();
118 if (imsCoreServiceClient->GetHandler(slotId) == nullptr) {
119 TELEPHONY_LOGE("get handler was null! slotId is %{public}d", slotId);
120 return TELEPHONY_ERR_LOCAL_PTR_NULL;
121 }
122 std::shared_ptr<int32_t> isRegisterd = std::make_shared<int32_t>();
123 *isRegisterd = imsRegStatus.isRegisterd ? 1 : 0;
124 TelEventHandler::SendTelEvent(
125 imsCoreServiceClient->GetHandler(slotId), RadioEvent::RADIO_IMS_REGISTER_STATE_UPDATE, isRegisterd);
126 return TELEPHONY_SUCCESS;
127 }
128 } // namespace Telephony
129 } // namespace OHOS
130