• 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             std::vector<string>::const_iterator it1;
66             for (it1 = devType_.cbegin(); it1 != devType_.cend(); it1++) {
67                 std::vector<string>::const_iterator it2;
68                 it2 = std::find(other.devType_.cbegin(), other.devType_.cend(), *it1);
69                 if (it2 == other.devType_.cend()) {
70                     return false;
71                 }
72             }
73             return true;
74         }
75         return true;
76     }
77     return false;
78 }
79 /**
80  * @brief A constructor used to create an {@code ExtraParams} instance based on the input parameters{@code devType},
81  * {@code targetBundleName}, and {@code description}.
82  *
83  * @param devType Indicates the type of devices to be matched. This parameter can be any combination of
84  * {@link #DEVICETYPE_SMART_PHONE}, {@link #DEVICETYPE_SMART_PAD}, {@link #DEVICETYPE_SMART_WATCH}, and
85  * {@link #DEVICETYPE_SMART_TV}.
86  *
87  * @param targetBundleName Indicates the bundle name of the target application where the ability will be migrated.
88  *
89  * @param description Indicates the description used for device filtering.
90  *
91  * @param jsonParams Indicates the custom JSON parameters to be used as filter conditions.
92  *
93  * @return none
94  */
ExtraParams(const std::vector<string> & devType,const string & targetBundleName,const string & description,const string & jsonParams)95 ExtraParams::ExtraParams(const std::vector<string> &devType, const string &targetBundleName, const string &description,
96     const string &jsonParams)
97 {
98     devType_ = devType;
99     targetBundleName_ = targetBundleName;
100     description_ = description;
101     jsonParams_ = jsonParams;
102 }
103 
104 /**
105  * @brief A destructor release an empty {@code ExtraParams} instance.
106  * @param none
107  */
~ExtraParams()108 ExtraParams::~ExtraParams()
109 {}
110 
111 /**
112  * @brief Sets the list of device types.
113  *
114  * @param devType Indicates the type of devices to be matched. This parameter can be any combination of
115  * {@link #DEVICETYPE_SMART_PHONE}, {@link #DEVICETYPE_SMART_PAD}, {@link #DEVICETYPE_SMART_WATCH}, and
116  * {@link #DEVICETYPE_SMART_TV}.
117  *
118  * @return none
119  */
SetDevType(const std::vector<string> & devType)120 void ExtraParams::SetDevType(const std::vector<string> &devType)
121 {
122     devType_ = devType;
123 }
124 
125 /**
126  * @brief Obtains the list of device types.
127  *
128  * @param none
129  *
130  * @return Returns the list of device types.
131  */
GetDevType() const132 std::vector<string> ExtraParams::GetDevType() const
133 {
134     return devType_;
135 }
136 
137 /**
138  * @brief Sets the bundle name of the target application where ability will be migrated.
139  *
140  * @param targetBundleName Indicates the bundle name of the target application to set.
141  *
142  * @return none
143  */
SetTargetBundleName(const string & targetBundleName)144 void ExtraParams::SetTargetBundleName(const string &targetBundleName)
145 {
146     targetBundleName_ = targetBundleName;
147 }
148 
149 /**
150  * @brief Obtains the bundle name of the target application where the ability will be migrated.
151  *
152  * @return Returns the bundle name of the target application.
153  */
GetTargetBundleName() const154 string ExtraParams::GetTargetBundleName() const
155 {
156     return targetBundleName_;
157 }
158 
159 /**
160  * @brief Sets the description used for device filtering.
161  *
162  * @param jsonParams Indicates the device description to set.
163  *
164  * @return none
165  */
SetJsonParams(const string & jsonParams)166 void ExtraParams::SetJsonParams(const string &jsonParams)
167 {
168     jsonParams_ = jsonParams;
169 }
170 
171 /**
172  * @brief Obtains the custom JSON parameters used as filter conditions.
173  *
174  * @param none
175  *
176  * @return Returns the custom JSON parameters.
177  */
GetJsonParams() const178 string ExtraParams::GetJsonParams() const
179 {
180     return jsonParams_;
181 }
182 
183 /**
184  * @brief Sets the custom JSON parameters to be used as filter conditions.
185  *
186  * @param description Indicates the custom JSON parameters to set.
187  *
188  */
SetDescription(const string & description)189 void ExtraParams::SetDescription(const string &description)
190 {
191     description_ = description;
192 }
193 
194 /**
195  * @brief Obtains the description used for device filtering.
196  *
197  * @param none
198  *
199  * @return Returns the description used for device filtering.
200  */
GetDescription() const201 string ExtraParams::GetDescription() const
202 {
203     return description_;
204 }
205 
206 /**
207  * @brief Marshals this {@code ExtraParams} object into a {@link ohos.utils.Parcel} object.
208  *
209  * @param parcel Indicates the {@code Parcel} object for marshalling.
210  *
211  * @return Returns {@code true} if the marshalling is successful; returns {@code false} otherwise.
212  */
Marshalling(Parcel & parcel) const213 bool ExtraParams::Marshalling(Parcel &parcel) const
214 {
215     bool ret = true;
216     // devType
217     bool ret1 = parcel.WriteStringVector(devType_);
218 
219     // targetBundleName
220     bool ret2 = parcel.WriteString16(Str8ToStr16(targetBundleName_));
221 
222     // description
223     bool ret3 = parcel.WriteString16(Str8ToStr16(description_));
224 
225     // jsonParams
226     bool ret4 = parcel.WriteString16(Str8ToStr16(jsonParams_));
227 
228     ret = (ret1 && ret2 && ret3 && ret4) ? true : false;
229     return ret;
230 }
231 
232 /**
233  * @brief Unmarshals this {@code ExtraParams} object from a {@link ohos.utils.Parcel} object.
234  *
235  * @param parcel Indicates the {@code Parcel} object for unmarshalling.
236  *
237  * @return Returns {@code true} if the unmarshalling is successful; returns {@code false} otherwise.
238  */
Unmarshalling(Parcel & parcel)239 ExtraParams *ExtraParams::Unmarshalling(Parcel &parcel)
240 {
241     // devType.
242     std::vector<string> devtype;
243     parcel.ReadStringVector(&devtype);
244 
245     // targetBundleName
246     string targetBundleName = Str16ToStr8(parcel.ReadString16());
247 
248     // description
249     string description = Str16ToStr8(parcel.ReadString16());
250 
251     // jsonParams
252     string jsonParams = Str16ToStr8(parcel.ReadString16());
253 
254     ExtraParams *extraParams = new (std::nothrow) ExtraParams(devtype, targetBundleName, description, jsonParams);
255 
256     return extraParams;
257 }
258 }  // namespace AppExecFwk
259 }  // namespace OHOS