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_sms_callback_proxy.h"
17
18 #include "message_option.h"
19 #include "message_parcel.h"
20
21 namespace OHOS {
22 namespace Telephony {
ImsSmsCallbackProxy(const sptr<IRemoteObject> & impl)23 ImsSmsCallbackProxy::ImsSmsCallbackProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<ImsSmsCallbackInterface>(impl) {}
25
ImsSendMessageResponse(int32_t slotId,const SendSmsResultInfo & result)26 int32_t ImsSmsCallbackProxy::ImsSendMessageResponse(int32_t slotId, const SendSmsResultInfo &result)
27 {
28 MessageParcel in;
29 int32_t ret = WriteCommonInfo(__FUNCTION__, in, slotId);
30 if (ret != TELEPHONY_SUCCESS) {
31 return ret;
32 }
33 if (!in.WriteRawData((const void *)&result, sizeof(SendSmsResultInfo))) {
34 TELEPHONY_LOGE("[slot%{public}d]Write SendSmsResultInfo fail!", slotId);
35 return TELEPHONY_ERR_WRITE_DATA_FAIL;
36 }
37 return SendRequest(in, slotId, IMS_SEND_MESSAGE);
38 }
39
ImsSendMessageResponse(int32_t slotId,const HRilRadioResponseInfo & info)40 int32_t ImsSmsCallbackProxy::ImsSendMessageResponse(int32_t slotId, const HRilRadioResponseInfo &info)
41 {
42 return SendHRilRadioResponseInfo(__FUNCTION__, slotId, IMS_SEND_MESSAGE, info);
43 }
44
ImsSetSmsConfigResponse(int32_t slotId,const HRilRadioResponseInfo & info)45 int32_t ImsSmsCallbackProxy::ImsSetSmsConfigResponse(int32_t slotId, const HRilRadioResponseInfo &info)
46 {
47 return SendHRilRadioResponseInfo(__FUNCTION__, slotId, IMS_SET_SMS_CONFIG, info);
48 }
49
ImsGetSmsConfigResponse(int32_t slotId,int32_t imsSmsConfig)50 int32_t ImsSmsCallbackProxy::ImsGetSmsConfigResponse(int32_t slotId, int32_t imsSmsConfig)
51 {
52 MessageParcel in;
53 int32_t ret = WriteCommonInfo(__FUNCTION__, in, slotId);
54 if (ret != TELEPHONY_SUCCESS) {
55 return ret;
56 }
57 if (!in.WriteInt32(imsSmsConfig)) {
58 TELEPHONY_LOGE("[slot%{public}d]Write imsSmsConfig fail!", slotId);
59 return TELEPHONY_ERR_WRITE_DATA_FAIL;
60 }
61 return SendRequest(in, slotId, IMS_GET_SMS_CONFIG);
62 }
63
ImsGetSmsConfigResponse(int32_t slotId,const HRilRadioResponseInfo & info)64 int32_t ImsSmsCallbackProxy::ImsGetSmsConfigResponse(int32_t slotId, const HRilRadioResponseInfo &info)
65 {
66 return SendHRilRadioResponseInfo(__FUNCTION__, slotId, IMS_GET_SMS_CONFIG, info);
67 }
68
WriteCommonInfo(std::string funcName,MessageParcel & in,int32_t slotId)69 int32_t ImsSmsCallbackProxy::WriteCommonInfo(std::string funcName, MessageParcel &in, int32_t slotId)
70 {
71 if (!in.WriteInterfaceToken(ImsSmsCallbackProxy::GetDescriptor())) {
72 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write descriptor token fail!", slotId, funcName.c_str());
73 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
74 }
75 if (!in.WriteInt32(slotId)) {
76 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write slotId fail!", slotId, funcName.c_str());
77 return TELEPHONY_ERR_WRITE_DATA_FAIL;
78 }
79 return TELEPHONY_SUCCESS;
80 }
81
SendHRilRadioResponseInfo(std::string funcName,int32_t slotId,int32_t eventId,const HRilRadioResponseInfo & info)82 int32_t ImsSmsCallbackProxy::SendHRilRadioResponseInfo(
83 std::string funcName, int32_t slotId, int32_t eventId, const HRilRadioResponseInfo &info)
84 {
85 TELEPHONY_LOGI("[slot%{public}d]Send HRilRadioResponseInfo for eventId:%{public}d", slotId, eventId);
86 MessageParcel in;
87 int32_t ret = WriteCommonInfo(funcName, in, slotId);
88 if (ret != TELEPHONY_SUCCESS) {
89 return ret;
90 }
91 if (!in.WriteRawData((const void *)&info, sizeof(HRilRadioResponseInfo))) {
92 TELEPHONY_LOGE("[slot%{public}d]Write HRilRadioResponseInfo fail! eventId:%{public}d", slotId, eventId);
93 return TELEPHONY_ERR_WRITE_DATA_FAIL;
94 }
95 return SendRequest(in, slotId, eventId);
96 }
97
SendRequest(MessageParcel & in,int32_t slotId,int32_t eventId)98 int32_t ImsSmsCallbackProxy::SendRequest(MessageParcel &in, int32_t slotId, int32_t eventId)
99 {
100 MessageParcel out;
101 MessageOption option;
102
103 sptr<IRemoteObject> remote = Remote();
104 if (remote == nullptr) {
105 TELEPHONY_LOGE("[slot%{public}d]Remote is null, eventId:%{public}d", slotId, eventId);
106 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
107 }
108
109 int32_t error = remote->SendRequest(eventId, in, out, option);
110 if (error == ERR_NONE) {
111 return out.ReadInt32();
112 }
113 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, eventId:%{public}d, error:%{public}d", slotId, eventId, error);
114 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
115 }
116 } // namespace Telephony
117 } // namespace OHOS
118