• 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_state_registry_proxy.h"
17 
18 #include "cell_information.h"
19 #include "i_telephony_state_notify.h"
20 #include "ipc_types.h"
21 #include "iremote_object.h"
22 #include "message_option.h"
23 #include "message_parcel.h"
24 #include "network_state.h"
25 #include "refbase.h"
26 #include "signal_information.h"
27 #include "sim_state_type.h"
28 #include "string"
29 #include "telephony_errors.h"
30 #include "telephony_observer_broker.h"
31 #include "vector"
32 
33 namespace OHOS {
34 namespace Telephony {
UpdateCellularDataConnectState(int32_t slotId,int32_t dataStatus,int32_t networkForm)35 int32_t TelephonyStateRegistryProxy::UpdateCellularDataConnectState(
36     int32_t slotId, int32_t dataStatus, int32_t networkForm)
37 {
38     MessageOption option;
39     MessageParcel in;
40     MessageParcel out;
41     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
42         return TELEPHONY_ERR_FAIL;
43     }
44     if (!in.WriteInt32(slotId)) {
45         return TELEPHONY_ERR_FAIL;
46     }
47     if (!in.WriteInt32(dataStatus)) {
48         return TELEPHONY_ERR_FAIL;
49     }
50     if (!in.WriteInt32(networkForm)) {
51         return TELEPHONY_ERR_FAIL;
52     }
53     sptr<IRemoteObject> remote = Remote();
54     if (remote == nullptr) {
55         return TELEPHONY_ERR_FAIL;
56     }
57     int result = remote->SendRequest(
58         static_cast<uint32_t>(StateNotifyCode::CELLULAR_DATA_STATE), in, out, option);
59     if (result == ERR_NONE) {
60         result = out.ReadInt32();
61         return result;
62     }
63     return TELEPHONY_SUCCESS;
64 }
65 
UpdateCellularDataFlow(int32_t slotId,int32_t dataFlowType)66 int32_t TelephonyStateRegistryProxy::UpdateCellularDataFlow(
67     int32_t slotId, int32_t dataFlowType)
68 {
69     MessageOption option;
70     MessageParcel in;
71     MessageParcel out;
72     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
73         return TELEPHONY_ERR_FAIL;
74     }
75     if (!in.WriteInt32(slotId)) {
76         return TELEPHONY_ERR_FAIL;
77     }
78     if (!in.WriteInt32(dataFlowType)) {
79         return TELEPHONY_ERR_FAIL;
80     }
81     sptr<IRemoteObject> remote = Remote();
82     if (remote == nullptr) {
83         return TELEPHONY_ERR_FAIL;
84     }
85     int result = remote->SendRequest(
86         static_cast<uint32_t>(StateNotifyCode::CELLULAR_DATA_FLOW), in, out, option);
87     if (result == ERR_NONE) {
88         result = out.ReadInt32();
89         return result;
90     }
91     return TELEPHONY_SUCCESS;
92 }
93 
UpdateCallState(int32_t slotId,int32_t callStatus,const std::u16string & number)94 int32_t TelephonyStateRegistryProxy::UpdateCallState(
95     int32_t slotId, int32_t callStatus, const std::u16string &number)
96 {
97     MessageOption option;
98     MessageParcel in;
99     MessageParcel out;
100     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
101         return TELEPHONY_ERR_FAIL;
102     }
103     if (!in.WriteInt32(slotId)) {
104         return TELEPHONY_ERR_FAIL;
105     }
106     if (!in.WriteInt32(callStatus)) {
107         return TELEPHONY_ERR_FAIL;
108     }
109     if (!in.WriteString16(number)) {
110         return TELEPHONY_ERR_FAIL;
111     }
112     sptr<IRemoteObject> remote = Remote();
113     if (remote == nullptr) {
114         return TELEPHONY_ERR_FAIL;
115     }
116     int result = remote->SendRequest(
117         static_cast<uint32_t>(StateNotifyCode::CALL_STATE), in, out, option);
118     if (result == ERR_NONE) {
119         result = out.ReadInt32();
120         return result;
121     }
122     return TELEPHONY_SUCCESS;
123 }
124 
UpdateCallStateForSlotId(int32_t slotId,int32_t callId,int32_t callStatus,const std::u16string & number)125 int32_t TelephonyStateRegistryProxy::UpdateCallStateForSlotId(
126     int32_t slotId, int32_t callId, int32_t callStatus, const std::u16string &number)
127 {
128     MessageOption option;
129     MessageParcel in;
130     MessageParcel out;
131     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
132         return TELEPHONY_ERR_FAIL;
133     }
134     if (!in.WriteInt32(slotId)) {
135         return TELEPHONY_ERR_FAIL;
136     }
137     if (!in.WriteInt32(callId)) {
138         return TELEPHONY_ERR_FAIL;
139     }
140     if (!in.WriteInt32(callStatus)) {
141         return TELEPHONY_ERR_FAIL;
142     }
143     if (!in.WriteString16(number)) {
144         return TELEPHONY_ERR_FAIL;
145     }
146     sptr<IRemoteObject> remote = Remote();
147     if (remote == nullptr) {
148         return TELEPHONY_ERR_FAIL;
149     }
150     int result = remote->SendRequest(
151         static_cast<uint32_t>(StateNotifyCode::CALL_STATE_FOR_ID), in, out, option);
152     if (result == ERR_NONE) {
153         result = out.ReadInt32();
154         return result;
155     }
156     return TELEPHONY_SUCCESS;
157 }
158 
UpdateSignalInfo(int32_t slotId,const std::vector<sptr<SignalInformation>> & vec)159 int32_t TelephonyStateRegistryProxy::UpdateSignalInfo(
160     int32_t slotId, const std::vector<sptr<SignalInformation>> &vec)
161 {
162     MessageOption option;
163     MessageParcel in;
164     MessageParcel out;
165     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
166         return TELEPHONY_ERR_FAIL;
167     }
168     if (!in.WriteInt32(slotId)) {
169         return TELEPHONY_ERR_FAIL;
170     }
171     int32_t size = vec.size();
172     if (size <= 0 || size > SignalInformation::MAX_SIGNAL_NUM) {
173         return TELEPHONY_ERR_FAIL;
174     }
175     if (!in.WriteInt32(size)) {
176         return TELEPHONY_ERR_FAIL;
177     }
178     for (const auto &v : vec) {
179         v->Marshalling(in);
180     }
181     sptr<IRemoteObject> remote = Remote();
182     if (remote == nullptr) {
183         return TELEPHONY_ERR_FAIL;
184     }
185     int result = remote->SendRequest(
186         static_cast<uint32_t>(StateNotifyCode::SIGNAL_INFO), in, out, option);
187     if (result == ERR_NONE) {
188         result = out.ReadInt32();
189         return result;
190     }
191     return TELEPHONY_SUCCESS;
192 }
193 
UpdateCellInfo(int32_t slotId,const std::vector<sptr<CellInformation>> & vec)194 int32_t TelephonyStateRegistryProxy::UpdateCellInfo(
195     int32_t slotId, const std::vector<sptr<CellInformation>> &vec)
196 {
197     MessageOption option;
198     MessageParcel in;
199     MessageParcel out;
200     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
201         return TELEPHONY_ERR_FAIL;
202     }
203     if (!in.WriteInt32(slotId)) {
204         return TELEPHONY_ERR_FAIL;
205     }
206     int32_t size = vec.size();
207     if (size <= 0 || size > CellInformation::MAX_CELL_NUM) {
208         return TELEPHONY_ERR_FAIL;
209     }
210     if (!in.WriteInt32(size)) {
211         return TELEPHONY_ERR_FAIL;
212     }
213     for (const auto &v : vec) {
214         v->Marshalling(in);
215     }
216     sptr<IRemoteObject> remote = Remote();
217     if (remote == nullptr) {
218         return TELEPHONY_ERR_FAIL;
219     }
220     int result = remote->SendRequest(
221         static_cast<uint32_t>(StateNotifyCode::CELL_INFO), in, out, option);
222     if (result == ERR_NONE) {
223         result = out.ReadInt32();
224         return result;
225     }
226     return TELEPHONY_SUCCESS;
227 }
228 
UpdateNetworkState(int32_t slotId,const sptr<NetworkState> & networkState)229 int32_t TelephonyStateRegistryProxy::UpdateNetworkState(
230     int32_t slotId, const sptr<NetworkState> &networkState)
231 {
232     MessageOption option;
233     MessageParcel in;
234     MessageParcel out;
235     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
236         return TELEPHONY_ERR_FAIL;
237     }
238     if (!in.WriteInt32(slotId)) {
239         return TELEPHONY_ERR_FAIL;
240     }
241     if (networkState == nullptr || !networkState->Marshalling(in)) {
242         return TELEPHONY_ERR_FAIL;
243     }
244     sptr<IRemoteObject> remote = Remote();
245     if (remote == nullptr) {
246         return TELEPHONY_ERR_FAIL;
247     }
248     int result = remote->SendRequest(
249         static_cast<uint32_t>(StateNotifyCode::NET_WORK_STATE), in, out, option);
250     if (result == ERR_NONE) {
251         result = out.ReadInt32();
252         return result;
253     }
254     return TELEPHONY_SUCCESS;
255 }
256 
UpdateSimState(int32_t slotId,CardType type,SimState state,LockReason reason)257 int32_t TelephonyStateRegistryProxy::UpdateSimState(
258     int32_t slotId, CardType type, SimState state, LockReason reason)
259 {
260     MessageOption option;
261     MessageParcel in;
262     MessageParcel out;
263     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
264         return TELEPHONY_ERR_FAIL;
265     }
266     if (!in.WriteInt32(slotId)) {
267         return TELEPHONY_ERR_FAIL;
268     }
269     if (!in.WriteInt32(static_cast<int32_t>(type))) {
270         return TELEPHONY_ERR_FAIL;
271     }
272     if (!in.WriteInt32(static_cast<int32_t>(state))) {
273         return TELEPHONY_ERR_FAIL;
274     }
275     if (!in.WriteInt32(static_cast<int32_t>(reason))) {
276         return TELEPHONY_ERR_FAIL;
277     }
278     sptr<IRemoteObject> remote = Remote();
279     if (remote == nullptr) {
280         return TELEPHONY_ERR_FAIL;
281     }
282     int result = remote->SendRequest(
283         static_cast<uint32_t>(StateNotifyCode::SIM_STATE), in, out, option);
284     if (result == ERR_NONE) {
285         result = out.ReadInt32();
286         return result;
287     }
288     return TELEPHONY_SUCCESS;
289 }
290 
RegisterStateChange(const sptr<TelephonyObserverBroker> & callback,int32_t slotId,uint32_t mask,bool isUpdate)291 int32_t TelephonyStateRegistryProxy::RegisterStateChange(
292     const sptr<TelephonyObserverBroker> &callback, int32_t slotId, uint32_t mask, bool isUpdate)
293 {
294     MessageOption option;
295     MessageParcel in;
296     MessageParcel out;
297     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
298         return TELEPHONY_ERR_FAIL;
299     }
300     if (!in.WriteInt32(slotId)) {
301         return TELEPHONY_ERR_FAIL;
302     }
303     if (!in.WriteInt32(mask)) {
304         return TELEPHONY_ERR_FAIL;
305     }
306     if (!in.WriteBool(isUpdate)) {
307         return TELEPHONY_ERR_FAIL;
308     }
309     if (!in.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
310         return TELEPHONY_ERR_FAIL;
311     }
312     sptr<IRemoteObject> remote = Remote();
313     if (remote == nullptr) {
314         return TELEPHONY_ERR_FAIL;
315     }
316     int result = remote->SendRequest(
317         static_cast<uint32_t>(StateNotifyCode::ADD_OBSERVER), in, out, option);
318     if (result == ERR_NONE) {
319         result = out.ReadInt32();
320         return result;
321     }
322     return TELEPHONY_SUCCESS;
323 }
324 
UnregisterStateChange(int32_t slotId,uint32_t mask)325 int32_t TelephonyStateRegistryProxy::UnregisterStateChange(
326     int32_t slotId, uint32_t mask)
327 {
328     MessageOption option;
329     MessageParcel in;
330     MessageParcel out;
331     if (!in.WriteInterfaceToken(TelephonyStateRegistryProxy::GetDescriptor())) {
332         return TELEPHONY_ERR_FAIL;
333     }
334     if (!in.WriteInt32(slotId)) {
335         return TELEPHONY_ERR_FAIL;
336     }
337     if (!in.WriteInt32(mask)) {
338         return TELEPHONY_ERR_FAIL;
339     }
340     sptr<IRemoteObject> remote = Remote();
341     if (remote == nullptr) {
342         return TELEPHONY_ERR_FAIL;
343     }
344     int result = remote->SendRequest(
345         static_cast<uint32_t>(StateNotifyCode::REMOVE_OBSERVER), in, out, option);
346     if (result == ERR_NONE) {
347         result = out.ReadInt32();
348         return result;
349     }
350     return TELEPHONY_SUCCESS;
351 }
352 } // namespace Telephony
353 } // namespace OHOS