• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "extra_params.h"
17 #include "string_ex.h"
18 
19 namespace OHOS {
20 namespace AppExecFwk {
21 /**
22  * @brief A default constructor used to create an empty {@code ExtraParams} instance.
23  * @param none
24  */
ExtraParams()25 ExtraParams::ExtraParams()
26 {}
27 /**
28  * @brief A copy constructor used to create an empty {@code ExtraParams} instance.
29  * @param other indicates object instance.
30  */
ExtraParams(const ExtraParams & other)31 ExtraParams::ExtraParams(const ExtraParams &other)
32 {
33     devType_ = other.devType_;
34     targetBundleName_ = other.targetBundleName_;
35     description_ = other.description_;
36     jsonParams_ = other.jsonParams_;
37 }
38 /**
39  * @brief Overloading assignment operators to create the same object instance.
40  * @param other Indicates object instance.
41  */
operator =(const ExtraParams & other)42 ExtraParams &ExtraParams::operator=(const ExtraParams &other)
43 {
44     if (this != &other) {
45         devType_ = other.devType_;
46         targetBundleName_ = other.targetBundleName_;
47         description_ = other.description_;
48         jsonParams_ = other.jsonParams_;
49     }
50     return *this;
51 }
52 /**
53  * @brief Judge whether the parameter of extraparam instance is equal to that of other instance parameter
54  * @param other Indicates object instance.
55  * @return returns true the parameter of extraparam instance is equal to that of other instance parameter
56  * otherwise false
57  */
operator ==(const ExtraParams & other) const58 bool ExtraParams::operator==(const ExtraParams &other) const
59 {
60     if (targetBundleName_ == other.targetBundleName_ && description_ == other.description_ &&
61         jsonParams_ == other.jsonParams_) {
62         if (devType_.size() != other.devType_.size()) {
63             return false;
64         } else if (devType_.size() > 0 && other.devType_.size() > 0 && devType_.size() == other.devType_.size()) {
65             for (std::vector<string>::const_iterator it1 = devType_.cbegin(); it1 != devType_.cend(); it1++) {
66                 std::vector<string>::const_iterator it2 =
67                     std::find(other.devType_.cbegin(), other.devType_.cend(), *it1);
68                 if (it2 == other.devType_.cend()) {
69                     return false;
70                 }
71             }
72             return true;
73         }
74     }
75     return false;
76 }
77 /**
78  * @brief A constructor used to create an {@code ExtraParams} instance based on the input parameters{@code devType},
79  * {@code targetBundleName}, and {@code description}.
80  *
81  * @param devType Indicates the type of devices to be matched. This parameter can be any combination of
82  * {@link #DEVICETYPE_SMART_PHONE}, {@link #DEVICETYPE_SMART_PAD}, {@link #DEVICETYPE_SMART_WATCH}, and
83  * {@link #DEVICETYPE_SMART_TV}.
84  *
85  * @param targetBundleName Indicates the bundle name of the target application where the ability will be migrated.
86  *
87  * @param description Indicates the description used for device filtering.
88  *
89  * @param jsonParams Indicates the custom JSON parameters to be used as filter conditions.
90  *
91  * @return none
92  */
ExtraParams(const std::vector<string> & devType,const string & targetBundleName,const string & description,const string & jsonParams)93 ExtraParams::ExtraParams(const std::vector<string> &devType, const string &targetBundleName, const string &description,
94     const string &jsonParams)
95 {
96     devType_ = devType;
97     targetBundleName_ = targetBundleName;
98     description_ = description;
99     jsonParams_ = jsonParams;
100 }
101 
102 /**
103  * @brief A destructor release an empty {@code ExtraParams} instance.
104  * @param none
105  */
~ExtraParams()106 ExtraParams::~ExtraParams()
107 {}
108 
109 /**
110  * @brief Sets the list of device types.
111  *
112  * @param devType Indicates the type of devices to be matched. This parameter can be any combination of
113  * {@link #DEVICETYPE_SMART_PHONE}, {@link #DEVICETYPE_SMART_PAD}, {@link #DEVICETYPE_SMART_WATCH}, and
114  * {@link #DEVICETYPE_SMART_TV}.
115  *
116  * @return none
117  */
SetDevType(const std::vector<string> & devType)118 void ExtraParams::SetDevType(const std::vector<string> &devType)
119 {
120     devType_ = devType;
121 }
122 
123 /**
124  * @brief Obtains the list of device types.
125  *
126  * @param none
127  *
128  * @return Returns the list of device types.
129  */
GetDevType() const130 std::vector<string> ExtraParams::GetDevType() const
131 {
132     return devType_;
133 }
134 
135 /**
136  * @brief Sets the bundle name of the target application where ability will be migrated.
137  *
138  * @param targetBundleName Indicates the bundle name of the target application to set.
139  *
140  * @return none
141  */
SetTargetBundleName(const string & targetBundleName)142 void ExtraParams::SetTargetBundleName(const string &targetBundleName)
143 {
144     targetBundleName_ = targetBundleName;
145 }
146 
147 /**
148  * @brief Obtains the bundle name of the target application where the ability will be migrated.
149  *
150  * @return Returns the bundle name of the target application.
151  */
GetTargetBundleName() const152 string ExtraParams::GetTargetBundleName() const
153 {
154     return targetBundleName_;
155 }
156 
157 /**
158  * @brief Sets the description used for device filtering.
159  *
160  * @param jsonParams Indicates the device description to set.
161  *
162  * @return none
163  */
SetJsonParams(const string & jsonParams)164 void ExtraParams::SetJsonParams(const string &jsonParams)
165 {
166     jsonParams_ = jsonParams;
167 }
168 
169 /**
170  * @brief Obtains the custom JSON parameters used as filter conditions.
171  *
172  * @param none
173  *
174  * @return Returns the custom JSON parameters.
175  */
GetJsonParams() const176 string ExtraParams::GetJsonParams() const
177 {
178     return jsonParams_;
179 }
180 
181 /**
182  * @brief Sets the custom JSON parameters to be used as filter conditions.
183  *
184  * @param description Indicates the custom JSON parameters to set.
185  *
186  */
SetDescription(const string & description)187 void ExtraParams::SetDescription(const string &description)
188 {
189     description_ = description;
190 }
191 
192 /**
193  * @brief Obtains the description used for device filtering.
194  *
195  * @param none
196  *
197  * @return Returns the description used for device filtering.
198  */
GetDescription() const199 string ExtraParams::GetDescription() const
200 {
201     return description_;
202 }
203 
204 /**
205  * @brief Marshals this {@code ExtraParams} object into a {@link ohos.utils.Parcel} object.
206  *
207  * @param parcel Indicates the {@code Parcel} object for marshalling.
208  *
209  * @return Returns {@code true} if the marshalling is successful; returns {@code false} otherwise.
210  */
Marshalling(Parcel & parcel) const211 bool ExtraParams::Marshalling(Parcel &parcel) const
212 {
213     // devType
214     bool writeDevType = parcel.WriteStringVector(devType_);
215 
216     // targetBundleName
217     bool writeTargetBundleName = parcel.WriteString16(Str8ToStr16(targetBundleName_));
218 
219     // description
220     bool writeDescription = parcel.WriteString16(Str8ToStr16(description_));
221 
222     // jsonParams
223     bool writeJsonParams = parcel.WriteString16(Str8ToStr16(jsonParams_));
224 
225     return writeDevType && writeTargetBundleName && writeDescription && writeJsonParams;
226 }
227 
228 /**
229  * @brief Unmarshals this {@code ExtraParams} object from a {@link ohos.utils.Parcel} object.
230  *
231  * @param parcel Indicates the {@code Parcel} object for unmarshalling.
232  *
233  * @return Returns {@code true} if the unmarshalling is successful; returns {@code false} otherwise.
234  */
Unmarshalling(Parcel & parcel)235 ExtraParams *ExtraParams::Unmarshalling(Parcel &parcel)
236 {
237     // devType.
238     std::vector<string> devtype;
239     parcel.ReadStringVector(&devtype);
240 
241     // targetBundleName
242     string targetBundleName = Str16ToStr8(parcel.ReadString16());
243 
244     // description
245     string description = Str16ToStr8(parcel.ReadString16());
246 
247     // jsonParams
248     string jsonParams = Str16ToStr8(parcel.ReadString16());
249 
250     ExtraParams *extraParams = new (std::nothrow) ExtraParams(devtype, targetBundleName, description, jsonParams);
251 
252     return extraParams;
253 }
254 }  // namespace AppExecFwk
255 }  // namespace OHOS
256