• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.h"
17 
18 #include "ims_sms_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 {
ImsSmsCallbackStub()25 ImsSmsCallbackStub::ImsSmsCallbackStub()
26 {
27     TELEPHONY_LOGI("ImsSmsCallbackStub");
28     InitFuncMap();
29 }
30 
InitFuncMap()31 void ImsSmsCallbackStub::InitFuncMap()
32 {
33     InitSmsBasicFuncMap();
34 }
35 
InitSmsBasicFuncMap()36 void ImsSmsCallbackStub::InitSmsBasicFuncMap()
37 {
38     /****************** sms basic ******************/
39     requestFuncMap_[IMS_SEND_MESSAGE] = &ImsSmsCallbackStub::OnImsSendMessageResponseInner;
40     requestFuncMap_[IMS_SET_SMS_CONFIG] = &ImsSmsCallbackStub::OnImsSetSmsConfigResponseInner;
41     requestFuncMap_[IMS_GET_SMS_CONFIG] = &ImsSmsCallbackStub::OnImsGetSmsConfigResponseInner;
42 }
43 
~ImsSmsCallbackStub()44 ImsSmsCallbackStub::~ImsSmsCallbackStub()
45 {
46     requestFuncMap_.clear();
47 }
48 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)49 int32_t ImsSmsCallbackStub::OnRemoteRequest(
50     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
51 {
52     std::u16string myDescriptor = ImsSmsCallbackStub::GetDescriptor();
53     std::u16string remoteDescriptor = data.ReadInterfaceToken();
54     if (myDescriptor != remoteDescriptor) {
55         TELEPHONY_LOGE("Descriptor check failed, return");
56         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
57     }
58     auto itFunc = requestFuncMap_.find(code);
59     if (itFunc != requestFuncMap_.end()) {
60         auto requestFunc = itFunc->second;
61         if (requestFunc != nullptr) {
62             return (this->*requestFunc)(data, reply);
63         }
64     }
65     TELEPHONY_LOGE("Do not found the requestFunc of code=%{public}d, need to check", code);
66     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67 }
68 
OnImsSendMessageResponseInner(MessageParcel & data,MessageParcel & reply)69 int32_t ImsSmsCallbackStub::OnImsSendMessageResponseInner(MessageParcel &data, MessageParcel &reply)
70 {
71     int32_t slotId = data.ReadInt32();
72     auto info = (HRilRadioResponseInfo *)data.ReadRawData(sizeof(HRilRadioResponseInfo));
73     if (info != nullptr) {
74         reply.WriteInt32(ImsSendMessageResponse(slotId, *info));
75         return TELEPHONY_SUCCESS;
76     }
77     auto result = (SendSmsResultInfo *)data.ReadRawData(sizeof(SendSmsResultInfo));
78     if (result == nullptr) {
79         TELEPHONY_LOGE("[slot%{public}d]SendSmsResultInfo is nullptr", slotId);
80         return TELEPHONY_ERR_ARGUMENT_INVALID;
81     }
82     reply.WriteInt32(ImsSendMessageResponse(slotId, *result));
83     return TELEPHONY_SUCCESS;
84 }
85 
OnImsSetSmsConfigResponseInner(MessageParcel & data,MessageParcel & reply)86 int32_t ImsSmsCallbackStub::OnImsSetSmsConfigResponseInner(MessageParcel &data, MessageParcel &reply)
87 {
88     int32_t slotId = data.ReadInt32();
89     auto info = (HRilRadioResponseInfo *)data.ReadRawData(sizeof(HRilRadioResponseInfo));
90     if (info == nullptr) {
91         TELEPHONY_LOGE("[slot%{public}d]HRilRadioResponseInfo is nullptr", slotId);
92         return TELEPHONY_ERR_ARGUMENT_INVALID;
93     }
94     reply.WriteInt32(ImsSetSmsConfigResponse(slotId, *info));
95     return TELEPHONY_SUCCESS;
96 }
97 
OnImsGetSmsConfigResponseInner(MessageParcel & data,MessageParcel & reply)98 int32_t ImsSmsCallbackStub::OnImsGetSmsConfigResponseInner(MessageParcel &data, MessageParcel &reply)
99 {
100     int32_t slotId = data.ReadInt32();
101     int32_t imsSmsConfig = data.ReadInt32();
102     reply.WriteInt32(ImsGetSmsConfigResponse(slotId, imsSmsConfig));
103     return TELEPHONY_SUCCESS;
104 }
105 
ImsSendMessageResponse(int32_t slotId,const SendSmsResultInfo & result)106 int32_t ImsSmsCallbackStub::ImsSendMessageResponse(int32_t slotId, const SendSmsResultInfo &result)
107 {
108     TELEPHONY_LOGI("[slot%{public}d]Entry with SendSmsResultInfo", slotId);
109     std::shared_ptr<SendSmsResultInfo> sendSmsResultInfo = std::make_shared<SendSmsResultInfo>();
110     if (sendSmsResultInfo == nullptr) {
111         TELEPHONY_LOGE("[slot%{public}d]make_shared SendSmsResultInfo failed", slotId);
112         return TELEPHONY_ERR_LOCAL_PTR_NULL;
113     }
114     *sendSmsResultInfo = result;
115     uint32_t item = RadioEvent::RADIO_SEND_IMS_GSM_SMS;
116     DelayedSingleton<ImsSmsClient>::GetInstance()->GetHandler(slotId)->SendEvent(item, sendSmsResultInfo);
117     return TELEPHONY_SUCCESS;
118 }
119 
ImsSendMessageResponse(int32_t slotId,const HRilRadioResponseInfo & info)120 int32_t ImsSmsCallbackStub::ImsSendMessageResponse(int32_t slotId, const HRilRadioResponseInfo &info)
121 {
122     return SendHRilRadioResponseInfo(slotId, static_cast<uint32_t>(RadioEvent::RADIO_SEND_IMS_GSM_SMS), info);
123 }
124 
ImsSetSmsConfigResponse(int32_t slotId,const HRilRadioResponseInfo & info)125 int32_t ImsSmsCallbackStub::ImsSetSmsConfigResponse(int32_t slotId, const HRilRadioResponseInfo &info)
126 {
127     return SendHRilRadioResponseInfo(slotId, static_cast<uint32_t>(RadioEvent::RADIO_SET_IMS_SMS), info);
128 }
129 
ImsGetSmsConfigResponse(int32_t slotId,int32_t imsSmsConfig)130 int32_t ImsSmsCallbackStub::ImsGetSmsConfigResponse(int32_t slotId, int32_t imsSmsConfig)
131 {
132     TELEPHONY_LOGI("[slot%{public}d]Entry", slotId);
133     std::shared_ptr<int32_t> imsSmsCfg = std::make_shared<int32_t>();
134     if (imsSmsCfg == nullptr) {
135         TELEPHONY_LOGE("[slot%{public}d]make_shared imsSmsConfig failed", slotId);
136         return TELEPHONY_ERR_LOCAL_PTR_NULL;
137     }
138     *imsSmsCfg = imsSmsConfig;
139     uint32_t item = RadioEvent::RADIO_GET_IMS_SMS;
140     DelayedSingleton<ImsSmsClient>::GetInstance()->GetHandler(slotId)->SendEvent(item, imsSmsCfg);
141     return TELEPHONY_SUCCESS;
142 }
143 
ImsGetSmsConfigResponse(int32_t slotId,const HRilRadioResponseInfo & info)144 int32_t ImsSmsCallbackStub::ImsGetSmsConfigResponse(int32_t slotId, const HRilRadioResponseInfo &info)
145 {
146     return SendHRilRadioResponseInfo(slotId, static_cast<uint32_t>(RadioEvent::RADIO_GET_IMS_SMS), info);
147 }
148 
SendHRilRadioResponseInfo(int32_t slotId,uint32_t eventId,const HRilRadioResponseInfo & info)149 int32_t ImsSmsCallbackStub::SendHRilRadioResponseInfo(
150     int32_t slotId, uint32_t eventId, const HRilRadioResponseInfo &info)
151 {
152     TELEPHONY_LOGI("[slot%{public}d]eventId=%{public}d response error:%{public}d", slotId, eventId, info.error);
153     std::shared_ptr<HRilRadioResponseInfo> hRilRadioResponseInfo = std::make_shared<HRilRadioResponseInfo>();
154     if (hRilRadioResponseInfo == nullptr) {
155         TELEPHONY_LOGE("[slot%{public}d]make_shared HRilRadioResponseInfo failed", slotId);
156         return TELEPHONY_ERR_LOCAL_PTR_NULL;
157     }
158     *hRilRadioResponseInfo = info;
159     DelayedSingleton<ImsSmsClient>::GetInstance()->GetHandler(slotId)->SendEvent(eventId, hRilRadioResponseInfo);
160     return TELEPHONY_SUCCESS;
161 }
162 } // namespace Telephony
163 } // namespace OHOS
164