• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 "call_ability_callback_proxy.h"
17 
18 #include "message_option.h"
19 #include "message_parcel.h"
20 
21 #include "call_manager_errors.h"
22 
23 namespace OHOS {
24 namespace Telephony {
CallAbilityCallbackProxy(const sptr<IRemoteObject> & impl)25 CallAbilityCallbackProxy::CallAbilityCallbackProxy(const sptr<IRemoteObject> &impl)
26     : IRemoteProxy<ICallAbilityCallback>(impl)
27 {}
28 
OnCallDetailsChange(const CallAttributeInfo & info)29 int32_t CallAbilityCallbackProxy::OnCallDetailsChange(const CallAttributeInfo &info)
30 {
31     MessageParcel dataParcel;
32     MessageParcel replyParcel;
33     MessageOption option;
34     if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
35         TELEPHONY_LOGE("write descriptor fail");
36         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
37     }
38     int32_t length = sizeof(CallAttributeInfo);
39     dataParcel.WriteInt32(length);
40     dataParcel.WriteRawData((const void *)&info, length);
41     if (Remote() == nullptr) {
42         TELEPHONY_LOGE("function Remote() return nullptr!");
43         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
44     }
45     int32_t error = Remote()->SendRequest(UPDATE_CALL_STATE_INFO, dataParcel, replyParcel, option);
46     if (error != TELEPHONY_SUCCESS) {
47         TELEPHONY_LOGE("update call state info failed, error: %{public}d", error);
48         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
49     }
50     return replyParcel.ReadInt32();
51 }
52 
OnCallEventChange(const CallEventInfo & info)53 int32_t CallAbilityCallbackProxy::OnCallEventChange(const CallEventInfo &info)
54 {
55     MessageParcel dataParcel;
56     MessageParcel replyParcel;
57     MessageOption option;
58     if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
59         TELEPHONY_LOGE("write descriptor fail");
60         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
61     }
62     int32_t length = sizeof(CallEventInfo);
63     dataParcel.WriteInt32(length);
64     dataParcel.WriteRawData((const void *)&info, length);
65     if (Remote() == nullptr) {
66         TELEPHONY_LOGE("function Remote() return nullptr!");
67         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
68     }
69     int32_t error = Remote()->SendRequest(UPDATE_CALL_EVENT, dataParcel, replyParcel, option);
70     if (error != TELEPHONY_SUCCESS) {
71         TELEPHONY_LOGE("update call event failed, error: %{public}d", error);
72         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
73     }
74     return replyParcel.ReadInt32();
75 }
76 
OnCallDisconnectedCause(const DisconnectedDetails & details)77 int32_t CallAbilityCallbackProxy::OnCallDisconnectedCause(const DisconnectedDetails &details)
78 {
79     MessageParcel dataParcel;
80     MessageParcel replyParcel;
81     MessageOption option;
82     if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
83         TELEPHONY_LOGE("write descriptor fail");
84         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
85     }
86     if (!dataParcel.WriteRawData((const void *)&details, sizeof(DisconnectedDetails))) {
87         TELEPHONY_LOGE("write DisconnectedDetails fail");
88         return TELEPHONY_ERR_WRITE_DATA_FAIL;
89     }
90     if (Remote() == nullptr) {
91         TELEPHONY_LOGE("function Remote() return nullptr!");
92         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
93     }
94     int32_t error = Remote()->SendRequest(UPDATE_CALL_DISCONNECTED_CAUSE, dataParcel, replyParcel, option);
95     if (error != TELEPHONY_SUCCESS) {
96         TELEPHONY_LOGE("report call disconnected cause failed, error: %{public}d", error);
97         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
98     }
99     return replyParcel.ReadInt32();
100 }
101 
OnReportAsyncResults(CallResultReportId reportId,AppExecFwk::PacMap & resultInfo)102 int32_t CallAbilityCallbackProxy::OnReportAsyncResults(CallResultReportId reportId, AppExecFwk::PacMap &resultInfo)
103 {
104     MessageParcel dataParcel;
105     MessageParcel replyParcel;
106     MessageOption option;
107     if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
108         TELEPHONY_LOGE("write descriptor fail");
109         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
110     }
111     PackDataParcel(reportId, resultInfo, dataParcel);
112     if (Remote() == nullptr) {
113         TELEPHONY_LOGE("function Remote() return nullptr!");
114         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
115     }
116     int32_t error = Remote()->SendRequest(UPDATE_CALL_ASYNC_RESULT_REQUEST, dataParcel, replyParcel, option);
117     if (error != TELEPHONY_SUCCESS) {
118         TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
119         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
120     }
121     return replyParcel.ReadInt32();
122 }
123 
OnReportMmiCodeResult(const MmiCodeInfo & info)124 int32_t CallAbilityCallbackProxy::OnReportMmiCodeResult(const MmiCodeInfo &info)
125 {
126     MessageParcel dataParcel;
127     MessageParcel replyParcel;
128     MessageOption option;
129     if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
130         TELEPHONY_LOGE("write descriptor fail");
131         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
132     }
133     int32_t length = sizeof(MmiCodeInfo);
134     dataParcel.WriteInt32(length);
135     dataParcel.WriteRawData((const void *)&info, length);
136     if (Remote() == nullptr) {
137         TELEPHONY_LOGE("function Remote() return nullptr!");
138         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
139     }
140     int32_t error = Remote()->SendRequest(UPDATE_MMI_CODE_RESULT_REQUEST, dataParcel, replyParcel, option);
141     if (error != TELEPHONY_SUCCESS) {
142         TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
143         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
144     }
145     return replyParcel.ReadInt32();
146 }
147 
PackDataParcel(CallResultReportId reportId,AppExecFwk::PacMap & resultInfo,MessageParcel & dataParcel)148 void CallAbilityCallbackProxy::PackDataParcel(
149     CallResultReportId reportId, AppExecFwk::PacMap &resultInfo, MessageParcel &dataParcel)
150 {
151     dataParcel.WriteInt32(static_cast<int32_t>(reportId));
152     dataParcel.WriteInt32(resultInfo.GetIntValue("result"));
153     switch (reportId) {
154         case CallResultReportId::GET_CALL_WAITING_REPORT_ID:
155         case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID:
156             dataParcel.WriteInt32(resultInfo.GetIntValue("status"));
157             dataParcel.WriteInt32(resultInfo.GetIntValue("classCw"));
158             break;
159         case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID:
160             dataParcel.WriteInt32(resultInfo.GetIntValue("status"));
161             dataParcel.WriteInt32(resultInfo.GetIntValue("classx"));
162             dataParcel.WriteString(resultInfo.GetStringValue("number"));
163             dataParcel.WriteInt32(resultInfo.GetIntValue("type"));
164             break;
165         case CallResultReportId::GET_CALL_CLIP_ID:
166             dataParcel.WriteInt32(resultInfo.GetIntValue("action"));
167             dataParcel.WriteInt32(resultInfo.GetIntValue("clipStat"));
168             break;
169         case CallResultReportId::GET_CALL_CLIR_ID:
170             dataParcel.WriteInt32(resultInfo.GetIntValue("action"));
171             dataParcel.WriteInt32(resultInfo.GetIntValue("clirStat"));
172             break;
173         case CallResultReportId::GET_IMS_CONFIG_REPORT_ID:
174         case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID:
175             dataParcel.WriteInt32(resultInfo.GetIntValue("value"));
176             break;
177         case CallResultReportId::START_RTT_REPORT_ID:
178             dataParcel.WriteInt32(resultInfo.GetIntValue("active"));
179             break;
180         case CallResultReportId::STOP_RTT_REPORT_ID:
181             dataParcel.WriteInt32(resultInfo.GetIntValue("inactive"));
182             break;
183         default:
184             break;
185     }
186 }
187 
OnOttCallRequest(OttCallRequestId requestId,AppExecFwk::PacMap & info)188 int32_t CallAbilityCallbackProxy::OnOttCallRequest(OttCallRequestId requestId, AppExecFwk::PacMap &info)
189 {
190     MessageParcel dataParcel;
191     MessageParcel replyParcel;
192     MessageOption option;
193     if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
194         TELEPHONY_LOGE("write descriptor fail");
195         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
196     }
197     dataParcel.WriteInt32(static_cast<int32_t>(requestId));
198     dataParcel.WriteString(info.GetStringValue("phoneNumber"));
199     dataParcel.WriteString(info.GetStringValue("bundleName"));
200     dataParcel.WriteInt32(info.GetIntValue("videoState"));
201     switch (requestId) {
202         case OttCallRequestId::OTT_REQUEST_INVITE_TO_CONFERENCE:
203             if (info.GetIntValue("listCnt") > 0) {
204                 dataParcel.WriteString(info.GetStringValue("number"));
205             }
206             break;
207         case OttCallRequestId::OTT_REQUEST_UPDATE_CALL_MEDIA_MODE:
208             dataParcel.WriteInt32(info.GetIntValue("callMediaMode"));
209             break;
210         default:
211             break;
212     }
213     if (Remote() == nullptr) {
214         TELEPHONY_LOGE("function Remote() return nullptr!");
215         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
216     }
217     int32_t error = Remote()->SendRequest(REPORT_OTT_CALL_REQUEST, dataParcel, replyParcel, option);
218     if (error != TELEPHONY_SUCCESS) {
219         TELEPHONY_LOGE("report ott call request failed, error: %{public}d", error);
220         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
221     }
222     return replyParcel.ReadInt32();
223 }
224 } // namespace Telephony
225 } // namespace OHOS
226