• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "telephony_observer_proxy.h"
17 
18 #include "parcel.h"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace Telephony {
TelephonyObserverProxy(const sptr<IRemoteObject> & impl)23 TelephonyObserverProxy::TelephonyObserverProxy(const sptr<IRemoteObject> &impl)
24     : IRemoteProxy<TelephonyObserverBroker>(impl)
25 {}
26 
OnCallStateUpdated(int32_t slotId,int32_t callState,const std::u16string & phoneNumber)27 void TelephonyObserverProxy::OnCallStateUpdated(
28     int32_t slotId, int32_t callState, const std::u16string &phoneNumber)
29 {
30     MessageParcel dataParcel;
31     MessageParcel replyParcel;
32     MessageOption option;
33     option.SetFlags(MessageOption::TF_ASYNC);
34     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
35         TELEPHONY_LOGE("TelephonyObserverProxy::OnCallStateUpdated WriteInterfaceToken failed!");
36         return;
37     }
38     dataParcel.WriteInt32(slotId);
39     dataParcel.WriteInt32(callState);
40     dataParcel.WriteString16(phoneNumber);
41     sptr<IRemoteObject> remote = Remote();
42     if (remote == nullptr) {
43         TELEPHONY_LOGE("TelephonyObserverProxy::OnCallStateUpdated remote is null!");
44         return;
45     }
46     int code = remote->SendRequest(
47         static_cast<uint32_t>(ObserverBrokerCode::ON_CALL_STATE_UPDATED),
48         dataParcel, replyParcel, option);
49     TELEPHONY_LOGI("TelephonyObserverProxy::OnCallStateUpdated end ##error: %{public}d", code);
50 };
51 
OnSimStateUpdated(int32_t slotId,CardType type,SimState state,LockReason reason)52 void TelephonyObserverProxy::OnSimStateUpdated(
53     int32_t slotId, CardType type, SimState state, LockReason reason)
54 {
55     MessageParcel dataParcel;
56     MessageParcel replyParcel;
57     MessageOption option;
58     option.SetFlags(MessageOption::TF_ASYNC);
59     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
60         TELEPHONY_LOGE("TelephonyObserverProxy::OnSimStateUpdated WriteInterfaceToken failed!");
61         return;
62     }
63     dataParcel.WriteInt32(slotId);
64     dataParcel.WriteInt32(static_cast<int32_t>(type));
65     dataParcel.WriteInt32(static_cast<int32_t>(state));
66     dataParcel.WriteInt32(static_cast<int32_t>(reason));
67     sptr<IRemoteObject> remote = Remote();
68     if (remote == nullptr) {
69         TELEPHONY_LOGE("TelephonyObserverProxy::OnSimStateUpdated remote is null!");
70         return;
71     }
72     int code = remote->SendRequest(
73         static_cast<uint32_t>(ObserverBrokerCode::ON_SIM_STATE_UPDATED),
74         dataParcel, replyParcel, option);
75     TELEPHONY_LOGI("TelephonyObserverProxy::OnSimStateUpdated end ##error: %{public}d.", code);
76 }
77 
OnSignalInfoUpdated(int32_t slotId,const std::vector<sptr<SignalInformation>> & vec)78 void TelephonyObserverProxy::OnSignalInfoUpdated(
79     int32_t slotId, const std::vector<sptr<SignalInformation>> &vec)
80 {
81     MessageOption option;
82     MessageParcel dataParcel;
83     MessageParcel replyParcel;
84     option.SetFlags(MessageOption::TF_ASYNC);
85     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
86         TELEPHONY_LOGE("TelephonyObserverProxy::OnSignalInfoUpdated WriteInterfaceToken failed!");
87         return;
88     }
89     int32_t size = static_cast<int32_t>(vec.size());
90     if (size <= 0 || size > SignalInformation::MAX_SIGNAL_NUM) {
91         TELEPHONY_LOGE("TelephonyObserverProxy::OnSignalInfoUpdated size error!");
92         return;
93     }
94     dataParcel.WriteInt32(slotId);
95     dataParcel.WriteInt32(size);
96     for (const auto &v : vec) {
97         v->Marshalling(dataParcel);
98     }
99     sptr<IRemoteObject> remote = Remote();
100     if (remote == nullptr) {
101         TELEPHONY_LOGE("TelephonyObserverProxy::OnSignalInfoUpdated remote is null!");
102         return;
103     }
104     int code = remote->SendRequest(
105         static_cast<uint32_t>(ObserverBrokerCode::ON_SIGNAL_INFO_UPDATED),
106         dataParcel, replyParcel, option);
107     TELEPHONY_LOGI("TelephonyObserverProxy::OnSignalInfoUpdated##error: %{public}d.", code);
108 }
109 
OnCellInfoUpdated(int32_t slotId,const std::vector<sptr<CellInformation>> & vec)110 void TelephonyObserverProxy::OnCellInfoUpdated(
111     int32_t slotId, const std::vector<sptr<CellInformation>> &vec)
112 {
113     MessageOption option;
114     MessageParcel dataParcel;
115     MessageParcel replyParcel;
116     option.SetFlags(MessageOption::TF_ASYNC);
117     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
118         TELEPHONY_LOGE("TelephonyObserverProxy::OnCellInfoUpdated WriteInterfaceToken failed!");
119         return;
120     }
121     dataParcel.WriteInt32(slotId);
122     int32_t size = static_cast<int32_t>(vec.size());
123     if (size <= 0) {
124         TELEPHONY_LOGE("Cellinformation array length is less than or equal to 0!");
125         return;
126     }
127     if (size > CellInformation::MAX_CELL_NUM) {
128         TELEPHONY_LOGE("Cellinformation array length is greater than MAX_CELL_NUM!");
129         return;
130     }
131     if (!dataParcel.WriteInt32(size)) {
132         TELEPHONY_LOGE("Failed to write Cellinformation array size!");
133         return;
134     }
135     for (const auto &v : vec) {
136         v->Marshalling(dataParcel);
137     }
138     sptr<IRemoteObject> remote = Remote();
139     if (remote == nullptr) {
140         TELEPHONY_LOGE("IRemoteObject is nullptr!");
141         return;
142     }
143     int code = remote->SendRequest(
144         static_cast<uint32_t>(ObserverBrokerCode::ON_CELL_INFO_UPDATED),
145         dataParcel, replyParcel, option);
146     TELEPHONY_LOGI("TelephonyObserverProxy::OnCellInfoUpdated##error: %{public}d.", code);
147 }
148 
OnNetworkStateUpdated(int32_t slotId,const sptr<NetworkState> & networkState)149 void TelephonyObserverProxy::OnNetworkStateUpdated(
150     int32_t slotId, const sptr<NetworkState> &networkState)
151 {
152     MessageOption option;
153     MessageParcel dataParcel;
154     MessageParcel replyParcel;
155     option.SetFlags(MessageOption::TF_ASYNC);
156     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
157         TELEPHONY_LOGE("TelephonyObserverProxy::OnNetworkStateUpdated WriteInterfaceToken failed!");
158         return;
159     }
160     dataParcel.WriteInt32(slotId);
161     if (networkState != nullptr) {
162         networkState->Marshalling(dataParcel);
163     }
164     sptr<IRemoteObject> remote = Remote();
165     if (remote == nullptr) {
166         TELEPHONY_LOGE("TelephonyObserverProxy::OnNetworkStateUpdated remote is null!");
167         return;
168     }
169     int code = remote->SendRequest(
170         static_cast<uint32_t>(ObserverBrokerCode::ON_NETWORK_STATE_UPDATED),
171         dataParcel, replyParcel, option);
172     TELEPHONY_LOGI("TelephonyObserverProxy::OnNetworkStateUpdated##error: %{public}d.", code);
173 }
174 
OnCellularDataConnectStateUpdated(int32_t slotId,int32_t dataState,int32_t networkType)175 void TelephonyObserverProxy::OnCellularDataConnectStateUpdated(
176     int32_t slotId, int32_t dataState, int32_t networkType)
177 {
178     MessageOption option;
179     MessageParcel dataParcel;
180     MessageParcel replyParcel;
181     option.SetFlags(MessageOption::TF_ASYNC);
182     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
183         TELEPHONY_LOGE("TelephonyObserverProxy::OnCellularDataConnectStateUpdated WriteInterfaceToken failed!");
184         return;
185     }
186     dataParcel.WriteInt32(slotId);
187     dataParcel.WriteInt32(dataState);
188     dataParcel.WriteInt32(networkType);
189     sptr<IRemoteObject> remote = Remote();
190     if (remote == nullptr) {
191         TELEPHONY_LOGE("TelephonyObserverProxy::OnCellularDataConnectStateUpdated remote is null!");
192         return;
193     }
194     int code = remote->SendRequest(
195         static_cast<uint32_t>(ObserverBrokerCode::ON_CELLULAR_DATA_CONNECT_STATE_UPDATED),
196         dataParcel, replyParcel, option);
197     TELEPHONY_LOGI("TelephonyObserverProxy::OnCellularDataConnectStateUpdated##error: %{public}d.", code);
198 }
199 
OnCellularDataFlowUpdated(int32_t slotId,int32_t dataFlowType)200 void TelephonyObserverProxy::OnCellularDataFlowUpdated(
201     int32_t slotId, int32_t dataFlowType)
202 {
203     MessageOption option;
204     MessageParcel dataParcel;
205     MessageParcel replyParcel;
206     option.SetFlags(MessageOption::TF_ASYNC);
207     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
208         TELEPHONY_LOGE("TelephonyObserverProxy::OnCellularDataFlowUpdated WriteInterfaceToken failed!");
209         return;
210     }
211     dataParcel.WriteInt32(slotId);
212     dataParcel.WriteInt32(dataFlowType);
213     sptr<IRemoteObject> remote = Remote();
214     if (remote == nullptr) {
215         TELEPHONY_LOGE("TelephonyObserverProxy::OnCellularDataFlow remote is null!");
216         return;
217     }
218     int code = remote->SendRequest(
219         static_cast<uint32_t>(ObserverBrokerCode::ON_CELLULAR_DATA_FLOW_UPDATED),
220         dataParcel, replyParcel, option);
221     TELEPHONY_LOGI("TelephonyObserverProxy::OnCellularDataFlow##error: %{public}d.", code);
222 }
223 
OnCfuIndicatorUpdated(int32_t slotId,bool cfuResult)224 void TelephonyObserverProxy::OnCfuIndicatorUpdated(int32_t slotId, bool cfuResult)
225 {
226     MessageOption option;
227     MessageParcel dataParcel;
228     MessageParcel replyParcel;
229     option.SetFlags(MessageOption::TF_ASYNC);
230     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
231         TELEPHONY_LOGE("TelephonyObserverProxy::OnCfuIndicatorUpdated WriteInterfaceToken failed!");
232         return;
233     }
234     dataParcel.WriteInt32(slotId);
235     dataParcel.WriteBool(cfuResult);
236     sptr<IRemoteObject> remote = Remote();
237     if (remote == nullptr) {
238         TELEPHONY_LOGE("TelephonyObserverProxy::OnCfuIndicatorUpdated remote is null!");
239         return;
240     }
241     int32_t code = remote->SendRequest(
242         static_cast<uint32_t>(ObserverBrokerCode::ON_CFU_INDICATOR_UPDATED), dataParcel, replyParcel, option);
243     TELEPHONY_LOGI("TelephonyObserverProxy::OnCfuIndicatorUpdated##error: %{public}d.", code);
244 }
245 
OnVoiceMailMsgIndicatorUpdated(int32_t slotId,bool voiceMailMsgResult)246 void TelephonyObserverProxy::OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult)
247 {
248     MessageOption option;
249     MessageParcel dataParcel;
250     MessageParcel replyParcel;
251     option.SetFlags(MessageOption::TF_ASYNC);
252     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
253         TELEPHONY_LOGE("TelephonyObserverProxy::OnVoiceMailMsgIndicatorUpdated WriteInterfaceToken failed!");
254         return;
255     }
256     dataParcel.WriteInt32(slotId);
257     dataParcel.WriteBool(voiceMailMsgResult);
258     sptr<IRemoteObject> remote = Remote();
259     if (remote == nullptr) {
260         TELEPHONY_LOGE("TelephonyObserverProxy::OnVoiceMailMsgIndicatorUpdated remote is null!");
261         return;
262     }
263     int32_t code = remote->SendRequest(static_cast<uint32_t>(ObserverBrokerCode::ON_VOICE_MAIL_MSG_INDICATOR_UPDATED),
264         dataParcel, replyParcel, option);
265     TELEPHONY_LOGI("TelephonyObserverProxy::OnVoiceMailMsgIndicatorUpdated##error: %{public}d.", code);
266 }
267 
OnIccAccountUpdated()268 void TelephonyObserverProxy::OnIccAccountUpdated()
269 {
270     MessageParcel dataParcel;
271     if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
272         TELEPHONY_LOGE("WriteInterfaceToken failed!");
273         return;
274     }
275     sptr<IRemoteObject> remote = Remote();
276     if (remote == nullptr) {
277         TELEPHONY_LOGE("remote is null!");
278         return;
279     }
280     MessageOption option;
281     option.SetFlags(MessageOption::TF_ASYNC);
282     MessageParcel replyParcel;
283     int32_t code = remote->SendRequest(
284         static_cast<uint32_t>(ObserverBrokerCode::ON_ICC_ACCOUNT_UPDATED), dataParcel, replyParcel, option);
285     TELEPHONY_LOGI("result code: %{public}d.", code);
286 }
287 } // namespace Telephony
288 } // namespace OHOS
289