1 /*
2 * Copyright (C) 2022 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 "telephony_errors.h"
21 #include "telephony_log_wrapper.h"
22
23 namespace OHOS {
24 namespace Telephony {
ImsCoreServiceCallbackStub()25 ImsCoreServiceCallbackStub::ImsCoreServiceCallbackStub()
26 {
27 TELEPHONY_LOGI("ImsCoreServiceCallbackStub");
28 InitFuncMap();
29 }
30
~ImsCoreServiceCallbackStub()31 ImsCoreServiceCallbackStub::~ImsCoreServiceCallbackStub()
32 {
33 requestFuncMap_.clear();
34 }
35
InitFuncMap()36 void ImsCoreServiceCallbackStub::InitFuncMap()
37 {
38 /****************** ims basic ability ******************/
39 requestFuncMap_[IMS_SERVICE_STATUS_REPORT] = &ImsCoreServiceCallbackStub::OnImsServiceStatusReportInner;
40 requestFuncMap_[IMS_GET_REGISTRATION_STATUS] = &ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner;
41 }
42
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)43 int32_t ImsCoreServiceCallbackStub::OnRemoteRequest(
44 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
45 {
46 std::u16string myDescriptor = ImsCoreServiceCallbackStub::GetDescriptor();
47 std::u16string remoteDescriptor = data.ReadInterfaceToken();
48 if (myDescriptor != remoteDescriptor) {
49 TELEPHONY_LOGE("OnRemoteRequest return, descriptor checked fail");
50 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
51 }
52 auto itFunc = requestFuncMap_.find(code);
53 if (itFunc != requestFuncMap_.end()) {
54 auto requestFunc = itFunc->second;
55 if (requestFunc != nullptr) {
56 return (this->*requestFunc)(data, reply);
57 }
58 }
59 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::OnRemoteRequest, default case, need check.");
60 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61 }
62
OnImsServiceStatusReportInner(MessageParcel & data,MessageParcel & reply)63 int32_t ImsCoreServiceCallbackStub::OnImsServiceStatusReportInner(MessageParcel &data, MessageParcel &reply)
64 {
65 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::onImsServiceStatusReportInner entry");
66 int32_t slotId = data.ReadInt32();
67 auto imsServiceStatus = (ImsServiceStatus *)data.ReadRawData(sizeof(ImsServiceStatus));
68 if (imsServiceStatus == nullptr) {
69 TELEPHONY_LOGE("onImsServiceStatusReportInner return, imsServiceStatus is nullptr.");
70 return TELEPHONY_ERR_ARGUMENT_INVALID;
71 }
72 reply.WriteInt32(UpdateImsServiceStatusChanged(slotId, *imsServiceStatus));
73 return TELEPHONY_SUCCESS;
74 }
75
UpdateImsServiceStatusChanged(int32_t slotId,const ImsServiceStatus & imsServiceStatus)76 int32_t ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged(
77 int32_t slotId, const ImsServiceStatus &imsServiceStatus)
78 {
79 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::UpdateImsServiceStatusChanged entry");
80 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient = DelayedSingleton<ImsCoreServiceClient>::GetInstance();
81 if (imsCoreServiceClient->GetHandler(slotId) == nullptr) {
82 TELEPHONY_LOGE("get handler was null! slotId is %{public}d", slotId);
83 return TELEPHONY_ERR_LOCAL_PTR_NULL;
84 }
85 std::shared_ptr<ImsServiceStatus> imsServiceState = std::make_shared<ImsServiceStatus>();
86 if (imsServiceState.get() == nullptr) {
87 TELEPHONY_LOGE("make_shared ImsServiceStatus failed!");
88 return TELEPHONY_ERR_LOCAL_PTR_NULL;
89 }
90
91 *imsServiceState = imsServiceStatus;
92 imsCoreServiceClient->GetHandler(slotId)->SendEvent(RadioEvent::RADIO_IMS_SERVICE_STATUS_UPDATE, imsServiceState);
93 return TELEPHONY_SUCCESS;
94 }
95
OnGetImsRegistrationStatusResponseInner(MessageParcel & data,MessageParcel & reply)96 int32_t ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner(MessageParcel &data, MessageParcel &reply)
97 {
98 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::OnGetImsRegistrationStatusResponseInner entry");
99 int32_t slotId = data.ReadInt32();
100 auto imsRegStatus = (ImsRegistrationStatus *)data.ReadRawData(sizeof(ImsRegistrationStatus));
101 if (imsRegStatus == nullptr) {
102 TELEPHONY_LOGE("imsRegStatus is nullptr.");
103 return TELEPHONY_ERR_ARGUMENT_INVALID;
104 }
105 reply.WriteInt32(GetImsRegistrationStatusResponse(slotId, *imsRegStatus));
106 return TELEPHONY_SUCCESS;
107 }
108
GetImsRegistrationStatusResponse(int32_t slotId,const ImsRegistrationStatus & imsRegStatus)109 int32_t ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse(
110 int32_t slotId, const ImsRegistrationStatus &imsRegStatus)
111 {
112 TELEPHONY_LOGI("ImsCoreServiceCallbackStub::GetImsRegistrationStatusResponse entry");
113 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient = DelayedSingleton<ImsCoreServiceClient>::GetInstance();
114 if (imsCoreServiceClient->GetHandler(slotId) == nullptr) {
115 TELEPHONY_LOGE("get handler was null! slotId is %{public}d", slotId);
116 return TELEPHONY_ERR_LOCAL_PTR_NULL;
117 }
118 std::shared_ptr<int32_t> isRegisterd = std::make_shared<int32_t>();
119 *isRegisterd = imsRegStatus.isRegisterd ? 1 : 0;
120 imsCoreServiceClient->GetHandler(slotId)->SendEvent(RadioEvent::RADIO_IMS_REGISTER_STATE_UPDATE, isRegisterd);
121 return TELEPHONY_SUCCESS;
122 }
123 } // namespace Telephony
124 } // namespace OHOS
125