• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "apn_item.h"
17 #include "apn_attribute.h"
18 #include "parcel.h"
19 
20 namespace OHOS {
21 namespace Telephony {
22 
Marshalling(Parcel & parcel) const23 bool ApnAttribute::Marshalling(Parcel &parcel) const
24 {
25     if (!parcel.WriteString(types_)) {
26         return false;
27     }
28     if (!parcel.WriteString(numeric_)) {
29         return false;
30     }
31     if (!parcel.WriteInt32(profileId_)) {
32         return false;
33     }
34     if (!parcel.WriteString(protocol_)) {
35         return false;
36     }
37     if (!parcel.WriteString(roamingProtocol_)) {
38         return false;
39     }
40     if (!parcel.WriteInt32(authType_)) {
41         return false;
42     }
43     if (!parcel.WriteString(apn_)) {
44         return false;
45     }
46     if (!parcel.WriteString(apnName_)) {
47         return false;
48     }
49     if (!parcel.WriteString(user_)) {
50         return false;
51     }
52     if (!parcel.WriteString(password_)) {
53         return false;
54     }
55     if (!parcel.WriteBool(isRoamingApn_)) {
56         return false;
57     }
58     if (!parcel.WriteString(homeUrl_)) {
59         return false;
60     }
61     if (!parcel.WriteString(proxyIpAddress_)) {
62         return false;
63     }
64     if (!parcel.WriteString(mmsIpAddress_)) {
65         return false;
66     }
67     if (!parcel.WriteBool(isEdited_)) {
68         return false;
69     }
70     return true;
71 }
72 
UnmarshallingExt(Parcel & parcel,ApnAttribute * attribute)73 static bool UnmarshallingExt(Parcel &parcel, ApnAttribute* attribute)
74 {
75     if (!parcel.ReadString(attribute->apnName_)) {
76         return false;
77     }
78     if (!parcel.ReadString(attribute->user_)) {
79         return false;
80     }
81     if (!parcel.ReadString(attribute->password_)) {
82         return false;
83     }
84     if (!parcel.ReadBool(attribute->isRoamingApn_)) {
85         return false;
86     }
87     if (!parcel.ReadString(attribute->homeUrl_)) {
88         return false;
89     }
90     if (!parcel.ReadString(attribute->proxyIpAddress_)) {
91         return false;
92     }
93     if (!parcel.ReadString(attribute->mmsIpAddress_)) {
94         return false;
95     }
96     if (!parcel.ReadBool(attribute->isEdited_)) {
97         return false;
98     }
99     return true;
100 }
101 
Unmarshalling(Parcel & parcel)102 ApnAttribute* ApnAttribute::Unmarshalling(Parcel &parcel)
103 {
104     std::unique_ptr<ApnAttribute> attribute = std::make_unique<ApnAttribute>();
105     if (attribute == nullptr) {
106         return nullptr;
107     }
108     if (!parcel.ReadString(attribute->types_)) {
109         return nullptr;
110     }
111     if (!parcel.ReadString(attribute->numeric_)) {
112         return nullptr;
113     }
114     if (!parcel.ReadInt32(attribute->profileId_)) {
115         return nullptr;
116     }
117     if (!parcel.ReadString(attribute->protocol_)) {
118         return nullptr;
119     }
120     if (!parcel.ReadString(attribute->roamingProtocol_)) {
121         return nullptr;
122     }
123     if (!parcel.ReadInt32(attribute->authType_)) {
124         return nullptr;
125     }
126     if (!parcel.ReadString(attribute->apn_)) {
127         return nullptr;
128     }
129     if (!UnmarshallingExt(parcel, attribute.get())) {
130         return nullptr;
131     }
132     return attribute.release();
133 }
134 
TransferApnAttributeBeforeIpc(ApnItem::Attribute & apnAttr,ApnAttribute & apnAfterTrans)135 void ApnAttribute::TransferApnAttributeBeforeIpc(ApnItem::Attribute &apnAttr, ApnAttribute &apnAfterTrans)
136 {
137     apnAfterTrans.types_ = apnAttr.types_;
138     apnAfterTrans.numeric_ = apnAttr.numeric_;
139     apnAfterTrans.profileId_ = apnAttr.profileId_;
140     apnAfterTrans.protocol_ = apnAttr.protocol_;
141     apnAfterTrans.roamingProtocol_ = apnAttr.roamingProtocol_;
142     apnAfterTrans.authType_ = apnAttr.authType_;
143     apnAfterTrans.apn_ = apnAttr.apn_;
144     apnAfterTrans.apnName_ = apnAttr.apnName_;
145     apnAfterTrans.user_ = apnAttr.user_;
146     apnAfterTrans.password_ = apnAttr.password_;
147     apnAfterTrans.isRoamingApn_ = apnAttr.isRoamingApn_;
148     apnAfterTrans.homeUrl_ = apnAttr.homeUrl_;
149     apnAfterTrans.proxyIpAddress_ = apnAttr.proxyIpAddress_;
150     apnAfterTrans.mmsIpAddress_ = apnAttr.mmsIpAddress_;
151     apnAfterTrans.isEdited_ = apnAttr.isEdited_;
152 }
153 
TransferApnAttributeAfterIpc(ApnItem::Attribute & apnAttr,ApnAttribute & apnAfterTrans)154 void ApnAttribute::TransferApnAttributeAfterIpc(ApnItem::Attribute &apnAttr, ApnAttribute &apnAfterTrans)
155 {
156     apnAfterTrans.types_.copy(apnAttr.types_, apnAfterTrans.types_.size(), 0);
157     apnAfterTrans.numeric_.copy(apnAttr.numeric_, apnAfterTrans.numeric_.size(), 0);
158     apnAttr.profileId_ = apnAfterTrans.profileId_;
159     apnAfterTrans.protocol_.copy(apnAttr.protocol_, apnAfterTrans.protocol_.size(), 0);
160     apnAfterTrans.roamingProtocol_.copy(apnAttr.roamingProtocol_, apnAfterTrans.roamingProtocol_.size(), 0);
161     apnAttr.authType_ = apnAfterTrans.authType_;
162     apnAfterTrans.apn_.copy(apnAttr.apn_, apnAfterTrans.apn_.size(), 0);
163     apnAfterTrans.apnName_.copy(apnAttr.apnName_, apnAfterTrans.apnName_.size(), 0);
164     apnAfterTrans.user_.copy(apnAttr.user_, apnAfterTrans.user_.size(), 0);
165     apnAfterTrans.password_.copy(apnAttr.password_, apnAfterTrans.password_.size(), 0);
166     apnAttr.isRoamingApn_ = apnAfterTrans.isRoamingApn_;
167     apnAfterTrans.homeUrl_.copy(apnAttr.homeUrl_, apnAfterTrans.homeUrl_.size(), 0);
168     apnAfterTrans.proxyIpAddress_.copy(apnAttr.proxyIpAddress_, apnAfterTrans.proxyIpAddress_.size(), 0);
169     apnAfterTrans.mmsIpAddress_.copy(apnAttr.mmsIpAddress_, apnAfterTrans.mmsIpAddress_.size(), 0);
170     apnAttr.isEdited_ = apnAfterTrans.isEdited_;
171 }
172 }
173 }