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 "network_information.h"
17
18 #include "string_ex.h"
19
20 namespace OHOS {
21 namespace Telephony {
SetOperateInformation(const std::string & operatorLongName,const std::string & operatorShortName,const std::string & operatorNumeric,int32_t state,int32_t rat)22 void NetworkInformation::SetOperateInformation(const std::string &operatorLongName,
23 const std::string &operatorShortName, const std::string &operatorNumeric, int32_t state, int32_t rat)
24 {
25 operatorLongName_ = operatorLongName;
26 operatorShortName_ = operatorShortName;
27 operatorNumeric_ = operatorNumeric;
28 networkPlmnState_ = static_cast<NetworkPlmnState>(state);
29 rat_ = static_cast<NetworkRat>(rat);
30 }
31
GetNetworkState() const32 int32_t NetworkInformation::GetNetworkState() const
33 {
34 return static_cast<int32_t>(networkPlmnState_);
35 }
36
GetOperatorShortName() const37 std::string NetworkInformation::GetOperatorShortName() const
38 {
39 return operatorShortName_;
40 }
41
GetOperatorLongName() const42 std::string NetworkInformation::GetOperatorLongName() const
43 {
44 return operatorLongName_;
45 }
46
GetOperatorNumeric() const47 std::string NetworkInformation::GetOperatorNumeric() const
48 {
49 return operatorNumeric_;
50 }
51
GetRadioTech() const52 int32_t NetworkInformation::GetRadioTech() const
53 {
54 return static_cast<int32_t>(rat_);
55 }
56
ReadFromParcel(Parcel & parcel)57 bool NetworkInformation::ReadFromParcel(Parcel &parcel)
58 {
59 operatorLongName_ = Str16ToStr8(parcel.ReadString16());
60 operatorShortName_ = Str16ToStr8(parcel.ReadString16());
61 operatorNumeric_ = Str16ToStr8(parcel.ReadString16());
62
63 int32_t plmnState;
64 if (!parcel.ReadInt32(plmnState)) {
65 return false;
66 }
67 networkPlmnState_ = static_cast<NetworkPlmnState>(plmnState);
68
69 int32_t rat;
70 if (!parcel.ReadInt32(rat)) {
71 return false;
72 }
73 rat_ = static_cast<NetworkRat>(rat);
74 return true;
75 }
76
Marshalling(Parcel & parcel) const77 bool NetworkInformation::Marshalling(Parcel &parcel) const
78 {
79 if (!parcel.WriteString16(Str8ToStr16(operatorLongName_))) {
80 return false;
81 }
82 if (!parcel.WriteString16(Str8ToStr16(operatorShortName_))) {
83 return false;
84 }
85 if (!parcel.WriteString16(Str8ToStr16(operatorNumeric_))) {
86 return false;
87 }
88 if (!parcel.WriteInt32(static_cast<int32_t>(networkPlmnState_))) {
89 return false;
90 }
91 if (!parcel.WriteInt32(static_cast<int32_t>(rat_))) {
92 return false;
93 }
94 return true;
95 }
96
Unmarshalling(Parcel & parcel)97 NetworkInformation *NetworkInformation::Unmarshalling(Parcel &parcel)
98 {
99 std::unique_ptr<NetworkInformation> networkInfo = std::make_unique<NetworkInformation>();
100 if (networkInfo == nullptr) {
101 return nullptr;
102 }
103 if (!networkInfo->ReadFromParcel(parcel)) {
104 return nullptr;
105 }
106 return networkInfo.release();
107 }
108 } // namespace Telephony
109 } // namespace OHOS
110