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