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_proxy.h"
17
18 #include "message_option.h"
19 #include "message_parcel.h"
20
21 namespace OHOS {
22 namespace Telephony {
ImsCoreServiceCallbackProxy(const sptr<IRemoteObject> & impl)23 ImsCoreServiceCallbackProxy::ImsCoreServiceCallbackProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<ImsCoreServiceCallbackInterface>(impl) {}
25
UpdateImsServiceStatusChanged(int32_t slotId,const ImsServiceStatus & imsServiceStatus)26 int32_t ImsCoreServiceCallbackProxy::UpdateImsServiceStatusChanged(
27 int32_t slotId, const ImsServiceStatus &imsServiceStatus)
28 {
29 MessageParcel in;
30 int32_t ret = WriteCommonInfo(__FUNCTION__, in, slotId);
31 if (ret != TELEPHONY_SUCCESS) {
32 TELEPHONY_LOGE("[slot%{public}d]Write imsServiceStatus fail!", slotId);
33 return ret;
34 }
35 if (!in.WriteRawData((const void *)&imsServiceStatus, sizeof(ImsServiceStatus))) {
36 TELEPHONY_LOGE("[slot%{public}d]Write imsServiceStatus fail!", slotId);
37 return TELEPHONY_ERR_WRITE_DATA_FAIL;
38 }
39 return SendRequest(in, slotId,
40 static_cast<int32_t>(ImsCoreServiceCallbackInterfaceCode::IMS_SERVICE_STATUS_REPORT));
41 }
42
GetImsRegistrationStatusResponse(int32_t slotId,const ImsRegistrationStatus & imsRegStatus)43 int32_t ImsCoreServiceCallbackProxy::GetImsRegistrationStatusResponse(
44 int32_t slotId, const ImsRegistrationStatus &imsRegStatus)
45 {
46 MessageParcel in;
47 int32_t ret = WriteCommonInfo(__FUNCTION__, in, slotId);
48 if (ret != TELEPHONY_SUCCESS) {
49 TELEPHONY_LOGE("[slot%{public}d]Write WriteCommonInfo fail!", slotId);
50 return ret;
51 }
52 if (!in.WriteRawData((const void *)&imsRegStatus, sizeof(ImsRegistrationStatus))) {
53 TELEPHONY_LOGE("[slot%{public}d]Write imsRegStatus fail!", slotId);
54 return TELEPHONY_ERR_WRITE_DATA_FAIL;
55 }
56 return SendRequest(in, slotId,
57 static_cast<int32_t>(ImsCoreServiceCallbackInterfaceCode::IMS_GET_REGISTRATION_STATUS));
58 }
59
WriteCommonInfo(std::string funcName,MessageParcel & in,int32_t slotId)60 int32_t ImsCoreServiceCallbackProxy::WriteCommonInfo(std::string funcName, MessageParcel &in, int32_t slotId)
61 {
62 if (!in.WriteInterfaceToken(ImsCoreServiceCallbackProxy::GetDescriptor())) {
63 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write descriptor token fail!", slotId, funcName.c_str());
64 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
65 }
66 if (!in.WriteInt32(slotId)) {
67 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write slotId fail!", slotId, funcName.c_str());
68 return TELEPHONY_ERR_WRITE_DATA_FAIL;
69 }
70 return TELEPHONY_SUCCESS;
71 }
72
SendRequest(MessageParcel & in,int32_t slotId,int32_t eventId)73 int32_t ImsCoreServiceCallbackProxy::SendRequest(MessageParcel &in, int32_t slotId, int32_t eventId)
74 {
75 MessageParcel out;
76 MessageOption option;
77
78 sptr<IRemoteObject> remote = Remote();
79 if (remote == nullptr) {
80 TELEPHONY_LOGE("[slot%{public}d]Remote is null, eventId:%{public}d", slotId, eventId);
81 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
82 }
83
84 int32_t error = remote->SendRequest(eventId, in, out, option);
85 if (error == ERR_NONE) {
86 return out.ReadInt32();
87 }
88 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, eventId:%{public}d, error:%{public}d", slotId, eventId, error);
89 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
90 }
91 } // namespace Telephony
92 } // namespace OHOS
93