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.h"
17 #include "telephony_log_wrapper.h"
18
19 namespace OHOS {
20 namespace Telephony {
OnCallStateUpdated(int32_t slotId,int32_t callState,const std::u16string & phoneNumber)21 void TelephonyObserver::OnCallStateUpdated(
22 int32_t slotId, int32_t callState, const std::u16string &phoneNumber) {}
23
OnSignalInfoUpdated(int32_t slotId,const std::vector<sptr<SignalInformation>> & vec)24 void TelephonyObserver::OnSignalInfoUpdated(
25 int32_t slotId, const std::vector<sptr<SignalInformation>> &vec) {}
26
OnNetworkStateUpdated(int32_t slotId,const sptr<NetworkState> & networkState)27 void TelephonyObserver::OnNetworkStateUpdated(
28 int32_t slotId, const sptr<NetworkState> &networkState) {}
29
OnCellInfoUpdated(int32_t slotId,const std::vector<sptr<CellInformation>> & vec)30 void TelephonyObserver::OnCellInfoUpdated(
31 int32_t slotId, const std::vector<sptr<CellInformation>> &vec) {}
32
OnSimStateUpdated(int32_t slotId,CardType type,SimState state,LockReason reason)33 void TelephonyObserver::OnSimStateUpdated(
34 int32_t slotId, CardType type, SimState state, LockReason reason) {}
35
OnCellularDataConnectStateUpdated(int32_t slotId,int32_t dataState,int32_t networkType)36 void TelephonyObserver::OnCellularDataConnectStateUpdated(
37 int32_t slotId, int32_t dataState, int32_t networkType) {}
38
OnCellularDataFlowUpdated(int32_t slotId,int32_t dataFlowType)39 void TelephonyObserver::OnCellularDataFlowUpdated(
40 int32_t slotId, int32_t dataFlowType) {}
41
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)42 int32_t TelephonyObserver::OnRemoteRequest(
43 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
44 {
45 TELEPHONY_LOGI("TelephonyObserver::OnRemoteRequest code = %{public}u......\n", code);
46 if (data.ReadInterfaceToken() != GetDescriptor()) {
47 TELEPHONY_LOGE("TelephonyObserver::OnRemoteRequest verify token failed!");
48 return OHOS::TRANSACTION_ERR;
49 }
50 switch (static_cast<ObserverBrokerCode>(code)) {
51 case ObserverBrokerCode::ON_CALL_STATE_UPDATED: {
52 OnCallStateUpdatedInner(data, reply);
53 break;
54 }
55 case ObserverBrokerCode::ON_SIGNAL_INFO_UPDATED: {
56 OnSignalInfoUpdatedInner(data, reply);
57 break;
58 }
59 case ObserverBrokerCode::ON_CELL_INFO_UPDATED: {
60 OnCellInfoUpdatedInner(data, reply);
61 break;
62 }
63 case ObserverBrokerCode::ON_NETWORK_STATE_UPDATED: {
64 OnNetworkStateUpdatedInner(data, reply);
65 break;
66 }
67 case ObserverBrokerCode::ON_SIM_STATE_UPDATED: {
68 OnSimStateUpdatedInner(data, reply);
69 break;
70 }
71 case ObserverBrokerCode::ON_CELLULAR_DATA_CONNECT_STATE_UPDATED: {
72 OnCellularDataConnectStateUpdatedInner(data, reply);
73 break;
74 }
75 case ObserverBrokerCode::ON_CELLULAR_DATA_FLOW_UPDATED: {
76 OnCellularDataFlowUpdatedInner(data, reply);
77 break;
78 }
79 default: {
80 return OHOS::UNKNOWN_TRANSACTION;
81 }
82 }
83 return OHOS::NO_ERROR;
84 }
85
OnCallStateUpdatedInner(MessageParcel & data,MessageParcel & reply)86 void TelephonyObserver::OnCallStateUpdatedInner(
87 MessageParcel &data, MessageParcel &reply)
88 {
89 int32_t slotId = data.ReadInt32();
90 int32_t callState = data.ReadInt32();
91 std::u16string phoneNumber = data.ReadString16();
92 OnCallStateUpdated(slotId, callState, phoneNumber);
93 }
94
OnSignalInfoUpdatedInner(MessageParcel & data,MessageParcel & reply)95 void TelephonyObserver::OnSignalInfoUpdatedInner(
96 MessageParcel &data, MessageParcel &reply)
97 {
98 int32_t slotId = data.ReadInt32();
99 std::vector<sptr<SignalInformation>> signalInfos;
100 ConvertSignalInfoList(data, signalInfos);
101 OnSignalInfoUpdated(slotId, signalInfos);
102 }
103
OnNetworkStateUpdatedInner(MessageParcel & data,MessageParcel & reply)104 void TelephonyObserver::OnNetworkStateUpdatedInner(
105 MessageParcel &data, MessageParcel &reply)
106 {
107 int32_t slotId = data.ReadInt32();
108 sptr<NetworkState> networkState = NetworkState::Unmarshalling(data);
109 OnNetworkStateUpdated(slotId, networkState);
110 }
111
OnCellInfoUpdatedInner(MessageParcel & data,MessageParcel & reply)112 void TelephonyObserver::OnCellInfoUpdatedInner(
113 MessageParcel &data, MessageParcel &reply)
114 {
115 int32_t slotId = data.ReadInt32();
116 std::vector<sptr<CellInformation>> cells;
117 ConvertCellInfoList(data, cells);
118 OnCellInfoUpdated(slotId, cells);
119 }
120
OnSimStateUpdatedInner(MessageParcel & data,MessageParcel & reply)121 void TelephonyObserver::OnSimStateUpdatedInner(
122 MessageParcel &data, MessageParcel &reply)
123 {
124 int32_t slotId = data.ReadInt32();
125 CardType type = static_cast<CardType>(data.ReadInt32());
126 SimState simState = static_cast<SimState>(data.ReadInt32());
127 LockReason reson = static_cast<LockReason>(data.ReadInt32());
128 OnSimStateUpdated(slotId, type, simState, reson);
129 }
130
OnCellularDataConnectStateUpdatedInner(MessageParcel & data,MessageParcel & reply)131 void TelephonyObserver::OnCellularDataConnectStateUpdatedInner(
132 MessageParcel &data, MessageParcel &reply)
133 {
134 int32_t slotId = data.ReadInt32();
135 int32_t dataState = data.ReadInt32();
136 int32_t networkType = data.ReadInt32();
137 OnCellularDataConnectStateUpdated(slotId, dataState, networkType);
138 }
139
OnCellularDataFlowUpdatedInner(MessageParcel & data,MessageParcel & reply)140 void TelephonyObserver::OnCellularDataFlowUpdatedInner(
141 MessageParcel &data, MessageParcel &reply)
142 {
143 int32_t slotId = data.ReadInt32();
144 int32_t flowType = data.ReadInt32();
145 OnCellularDataFlowUpdated(slotId, flowType);
146 }
147
ConvertSignalInfoList(MessageParcel & data,std::vector<sptr<SignalInformation>> & result)148 void TelephonyObserver::ConvertSignalInfoList(
149 MessageParcel &data, std::vector<sptr<SignalInformation>> &result)
150 {
151 int32_t size = data.ReadInt32();
152 size = (size > SIGNAL_NUM_MAX) ? SIGNAL_NUM_MAX : size;
153 SignalInformation::NetworkType type;
154 for (int i = 0; i < size; ++i) {
155 type = static_cast<SignalInformation::NetworkType>(data.ReadInt32());
156 switch (type) {
157 case SignalInformation::NetworkType::GSM: {
158 std::unique_ptr<GsmSignalInformation> signal = std::make_unique<GsmSignalInformation>();
159 if (signal != nullptr) {
160 signal->ReadFromParcel(data);
161 result.emplace_back(signal.release());
162 }
163 break;
164 }
165 case SignalInformation::NetworkType::CDMA: {
166 std::unique_ptr<CdmaSignalInformation> signal = std::make_unique<CdmaSignalInformation>();
167 if (signal != nullptr) {
168 signal->ReadFromParcel(data);
169 result.emplace_back(signal.release());
170 }
171 break;
172 }
173 case SignalInformation::NetworkType::LTE: {
174 std::unique_ptr<LteSignalInformation> signal = std::make_unique<LteSignalInformation>();
175 if (signal != nullptr) {
176 signal->ReadFromParcel(data);
177 result.emplace_back(signal.release());
178 }
179 break;
180 }
181 case SignalInformation::NetworkType::WCDMA: {
182 std::unique_ptr<WcdmaSignalInformation> signal = std::make_unique<WcdmaSignalInformation>();
183 if (signal != nullptr) {
184 signal->ReadFromParcel(data);
185 result.emplace_back(signal.release());
186 }
187 break;
188 }
189 default:
190 break;
191 }
192 }
193 }
194
ConvertCellInfoList(MessageParcel & data,std::vector<sptr<CellInformation>> & cells)195 void TelephonyObserver::ConvertCellInfoList(
196 MessageParcel &data, std::vector<sptr<CellInformation>> &cells)
197 {
198 int32_t size = data.ReadInt32();
199 size = (size > CELL_NUM_MAX) ? CELL_NUM_MAX : size;
200 CellInformation::CellType type;
201 for (int i = 0; i < size; ++i) {
202 type = static_cast<CellInformation::CellType>(data.ReadInt32());
203 switch (type) {
204 case CellInformation::CellType::CELL_TYPE_GSM: {
205 std::unique_ptr<GsmCellInformation> cell = std::make_unique<GsmCellInformation>();
206 if (cell != nullptr) {
207 cell->ReadFromParcel(data);
208 cells.emplace_back(cell.release());
209 }
210 break;
211 }
212 case CellInformation::CellType::CELL_TYPE_LTE: {
213 std::unique_ptr<LteCellInformation> cell = std::make_unique<LteCellInformation>();
214 if (cell != nullptr) {
215 cell->ReadFromParcel(data);
216 cells.emplace_back(cell.release());
217 }
218 break;
219 }
220 default:
221 break;
222 }
223 }
224 }
225 } // namespace Telephony
226 } // namespace OHOS
227