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