• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef OHOS_DISTRIBUTEDWANT_WANT_H
17 #define OHOS_DISTRIBUTEDWANT_WANT_H
18 
19 #include <algorithm>
20 #include <string>
21 #include <vector>
22 #include "distributedWant/distributed_operation.h"
23 #include "distributedWant/distributed_want_params.h"
24 #include "element_name.h"
25 #include "nlohmann/json.hpp"
26 #include "parcel.h"
27 #include "uri.h"
28 #include "want.h"
29 
30 using DistributedOperation = OHOS::DistributedSchedule::DistributedOperation;
31 
32 namespace OHOS {
33 namespace DistributedSchedule {
34 class DistributedWant final : public Parcelable {
35 public:
36     /**
37      * Indicates the grant to perform read operations on the URI.
38      */
39     static constexpr unsigned int FLAG_AUTH_READ_URI_PERMISSION = 0x00000001;
40     /**
41      * Indicates the grant to perform write operations on the URI.
42      */
43     static constexpr unsigned int FLAG_AUTH_WRITE_URI_PERMISSION = 0x00000002;
44     /**
45      * Returns the result to the source ability.
46      */
47     static constexpr unsigned int FLAG_ABILITY_FORWARD_RESULT = 0x00000004;
48     /**
49      * Determines whether an ability on the local device can be migrated to a remote device.
50      */
51     static constexpr unsigned int FLAG_ABILITY_CONTINUATION = 0x00000008;
52     /**
53      * Specifies whether a component does not belong to OHOS.
54      */
55     static constexpr unsigned int FLAG_NOT_OHOS_COMPONENT = 0x00000010;
56     /**
57      * Specifies whether an ability is started.
58      */
59     static constexpr unsigned int FLAG_ABILITY_FORM_ENABLED = 0x00000020;
60     /**
61      * Indicates the grant for possible persisting on the URI.
62      */
63     static constexpr unsigned int FLAG_AUTH_PERSISTABLE_URI_PERMISSION = 0x00000040;
64     /**
65      * Returns the result to the source ability slice.
66      */
67     static constexpr unsigned int FLAG_AUTH_PREFIX_URI_PERMISSION = 0x00000080;
68     /**
69      * Supports multi-device startup in the distributed scheduling system.
70      */
71     static constexpr unsigned int FLAG_ABILITYSLICE_MULTI_DEVICE = 0x00000100;
72     /**
73      * Indicates that an ability using the Service template is started regardless of whether the host application has
74      * been started.
75      */
76     static constexpr unsigned int FLAG_START_FOREGROUND_ABILITY = 0x00000200;
77 
78     /**
79      * Indicates the continuation is reversible.
80      */
81     static constexpr unsigned int FLAG_ABILITY_CONTINUATION_REVERSIBLE = 0x00000400;
82 
83     /**
84      * Install the specified ability if it's not installed.
85      */
86     static constexpr unsigned int FLAG_INSTALL_ON_DEMAND = 0x00000800;
87     /**
88      * Returns the result to the source ability slice.
89      */
90     static constexpr unsigned int FLAG_ABILITYSLICE_FORWARD_RESULT = 0x04000000;
91     /**
92      * Install the specifiedi ability with background mode if it's not installed.
93      */
94     static constexpr unsigned int FLAG_INSTALL_WITH_BACKGROUND_MODE = 0x80000000;
95 
96     /**
97      * @description:  Default construcotr of DistributedWant class, which is used to initialzie flags and URI.
98      * @param None
99      * @return None
100      */
101     DistributedWant();
102 
103     /**
104      * @description: Default deconstructor of DistributedWant class
105      * @param None
106      * @return None
107      */
108     ~DistributedWant();
109 
110     /**
111      * @description: Copy construcotr of DistributedWant class, which is used to initialzie flags, URI, etc.
112      * @param want the source instance of DistributedWant.
113      * @return None
114      */
115     DistributedWant(const DistributedWant& want);
116     DistributedWant& operator=(const DistributedWant&);
117     DistributedWant(const AAFwk::Want& want);
118 
119     /**
120      * @description: Sets a flag in a DistributedWant.
121      * @param flags Indicates the flag to set.
122      * @return Returns this DistributedWant object containing the flag.
123      */
124     DistributedWant& SetFlags(unsigned int flags);
125 
126     /**
127      * @description: Obtains the description of flags in a DistributedWant.
128      * @return Returns the flag description in the DistributedWant.
129      */
130     unsigned int GetFlags() const;
131 
132     /**
133      * @description: Adds a flag to a DistributedWant.
134      * @param flags Indicates the flag to add.
135      * @return Returns the DistributedWant object with the added flag.
136      */
137     DistributedWant& AddFlags(unsigned int flags);
138 
139     /**
140      * @description: Removes the description of a flag from a DistributedWant.
141      * @param flags Indicates the flag to remove.
142      * @return Removes the description of a flag from a DistributedWant.
143      */
144     void RemoveFlags(unsigned int flag);
145 
146     /**
147      * @description: Sets the bundleName and abilityName attributes for this DistributedWant object.
148      * @param bundleName Indicates the bundleName to set for the operation attribute in the DistributedWant.
149      * @param abilityName Indicates the abilityName to set for the operation attribute in the DistributedWant.
150      * @return Returns this DistributedWant object that contains the specified bundleName and abilityName attributes.
151      */
152     DistributedWant& SetElementName(const std::string& bundleName, const std::string& abilityName);
153 
154     /**
155      * @description: Sets the bundleName and abilityName attributes for this DistributedWant object.
156      * @param deviceId Indicates the deviceId to set for the operation attribute in the DistributedWant.
157      * @param bundleName Indicates the bundleName to set for the operation attribute in the DistributedWant.
158      * @param abilityName Indicates the abilityName to set for the operation attribute in the DistributedWant.
159      * @return Returns this DistributedWant object that contains the specified bundleName and abilityName attributes.
160      */
161     DistributedWant& SetElementName(
162         const std::string& deviceId, const std::string& bundleName, const std::string& abilityName);
163 
164     /**
165      * @description: Sets an ElementName object in a DistributedWant.
166      * @param element Indicates the ElementName description.
167      * @return Returns this DistributedWant object containing the ElementName
168      */
169     DistributedWant& SetElement(const OHOS::AppExecFwk::ElementName& element);
170 
171     /**
172      * @description: Obtains the description of the ElementName object in a DistributedWant.
173      * @return Returns the ElementName description in the DistributedWant.
174      */
175     OHOS::AppExecFwk::ElementName GetElement() const;
176 
177     /**
178      * @description: Creates a DistributedWant with its corresponding attributes specified for
179      * starting the main ability of an application.
180      * @param ElementName  Indicates the ElementName object defining the deviceId, bundleName,
181      * and abilityName sub-attributes of the operation attribute in a DistributedWant.
182      * @return Returns the DistributedWant object used to start the main ability of an application.
183      */
184     static DistributedWant* MakeMainAbility(const OHOS::AppExecFwk::ElementName& elementName);
185 
186     /**
187      * @description: Creates a DistributedWant instance by using a given Uniform Resource Identifier (URI).
188      * This method parses the input URI and saves it in a DistributedWant object.
189      * @param uri Indicates the URI to parse.
190      * @return Returns a DistributedWant object containing the URI.
191      */
192     static DistributedWant* WantParseUri(const char* uri);
193 
194     /**
195      * @description: Creates a DistributedWant instance by using a given Uniform Resource Identifier (URI).
196      * This method parses the input URI and saves it in a DistributedWant object.
197      * @param uri Indicates the URI to parse.
198      * @return Returns a DistributedWant object containing the URI.
199      */
200     static DistributedWant* ParseUri(const std::string& uri);
201 
202     /**
203      * @description: Obtains the description of a URI in a DistributedWant.
204      * @return Returns the URI description in the DistributedWant.
205      */
206     OHOS::Uri GetUri() const;
207 
208     /**
209      * @description: Obtains the string representation of the URI in this DistributedWant.
210      * @return Returns the string of the URI.
211      */
212     std::string GetUriString() const;
213 
214     /**
215      * @description: Sets the description of a URI in a DistributedWant.
216      * @param uri Indicates the URI description.
217      * @return Returns this DistributedWant object containing the URI.
218      */
219     DistributedWant& SetUri(const std::string& uri);
220 
221     /**
222      * @description: Sets the description of a URI in a DistributedWant.
223      * @param uri Indicates the URI description.
224      * @return Returns this DistributedWant object containing the URI.
225      */
226     DistributedWant& SetUri(const OHOS::Uri& uri);
227 
228     /**
229      * @description: Sets the description of a URI and a type in this DistributedWant.
230      * @param uri Indicates the URI description.
231      * @param type Indicates the type description.
232      * @return Returns the DistributedWant object containing the URI and the type by setting.
233      */
234     DistributedWant& SetUriAndType(const OHOS::Uri& uri, const std::string& type);
235 
236     /**
237      * @description: Converts a DistributedWant into a URI string containing a representation of it.
238      * @param want Indicates the DistributedWant description.--DistributedWant.
239      * @return   Returns an encoding URI string describing the DistributedWant object.
240      */
241     std::string WantToUri(DistributedWant& want);
242 
243     /**
244      * @description: Converts parameter information in a DistributedWant into a URI string.
245      * @return Returns the URI string.
246      */
247     std::string ToUri() const;
248 
249     /**
250      * @description: Formats a specified URI.
251      * This method uses the Uri.getLowerCaseScheme() method to format a URI and then saves
252      * the formatted URI to this DistributedWant object.
253      * @param uri Indicates the string of URI to format.
254      * @return Returns this DistributedWant object that contains the formatted uri attribute.
255      */
256     DistributedWant& FormatUri(const std::string& uri);
257 
258     /**
259      * @description: Formats a specified URI.
260      * This method uses the Uri.getLowerCaseScheme() method to format a URI and then saves
261      * the formatted URI to this DistributedWant object.
262      * @param uri Indicates the URI to format.
263      * @return Returns this DistributedWant object that contains the formatted URI attribute.
264      */
265     DistributedWant& FormatUri(const OHOS::Uri& uri);
266 
267     /**
268      * @description: Obtains the description of an action in a DistributedWant.
269      * @return Returns a DistributedWant object that contains the action description.
270      */
271     std::string GetAction() const;
272 
273     /**
274      * @description: Sets the description of an action in a DistributedWant.
275      * @param action Indicates the action description to set.
276      * @return Returns a DistributedWant object that contains the action description.
277      */
278     DistributedWant& SetAction(const std::string& action);
279 
280     /**
281      * @description: Obtains the name of the specified bundle in a DistributedWant.
282      * @return Returns the specified bundle name in the DistributedWant.
283      */
284     std::string GetBundle() const;
285 
286     /**
287      * @description: Sets a bundle name in this DistributedWant.
288      * If a bundle name is specified in a DistributedWant, the DistributedWant will match only
289      * the abilities in the specified bundle. You cannot use this method and
290      * setPicker(ohos.aafwk.content.DistributedWant) on the same DistributedWant.
291      * @param bundleName Indicates the bundle name to set.
292      * @return Returns a DistributedWant object containing the specified bundle name.
293      */
294     DistributedWant& SetBundle(const std::string& bundleName);
295 
296     /**
297      * @description: Obtains the description of all entities in a DistributedWant
298      * @return Returns a set of entities
299      */
300     const std::vector<std::string>& GetEntities() const;
301 
302     /**
303      * @description: Adds the description of an entity to a DistributedWant
304      * @param entity Indicates the entity description to add
305      * @return {DistributedWant} Returns this DistributedWant object containing the entity.
306      */
307     DistributedWant& AddEntity(const std::string& entity);
308 
309     /**
310      * @description: Removes the description of an entity from a DistributedWant
311      * @param entity Indicates the entity description to remove.
312      * @return void
313      */
314     void RemoveEntity(const std::string& entity);
315 
316     /**
317      * @description: Checks whether a DistributedWant contains the given entity
318      * @param entity Indicates the entity to check
319      * @return Returns true if the given entity is contained; returns false otherwise
320      */
321     bool HasEntity(const std::string& key) const;
322 
323     /**
324      * @description: Obtains the number of entities in a DistributedWant
325      * @return Returns the entity quantity
326      */
327     int CountEntities();
328 
329     /**
330      * @description: Obtains the description of the URI scheme in this DistributedWant.
331      * @return Returns the URI scheme description in this DistributedWant.
332      */
333     const std::string GetScheme() const;
334 
335     /**
336      * @description: Obtains the description of the type in this DistributedWant
337      * @return Returns the type description in this DistributedWant
338      */
339     std::string GetType() const;
340 
341     /**
342      * @description: Sets the description of a type in this DistributedWant
343      * @param type Indicates the type description
344      * @return Returns this DistributedWant object containing the type
345      */
346     DistributedWant& SetType(const std::string& type);
347 
348     /**
349      * @description: Formats a specified MIME type. This method uses
350      * the formatMimeType(java.lang.String) method to format a MIME type
351      * and then saves the formatted type to this DistributedWant object.
352      * @param type Indicates the MIME type to format
353      * @return Returns this DistributedWant object that contains the formatted type attribute
354      */
355     DistributedWant& FormatType(const std::string& type);
356 
357     /**
358      * @description: Formats a specified URI and MIME type.
359      * This method works in the same way as formatUri(ohos.utils.net.URI)
360      * and formatType(java.lang.String).
361      * @param uri Indicates the URI to format.
362      * @param type Indicates the MIME type to format.
363      * @return Returns this DistributedWant object that contains the formatted URI and type attributes.
364      */
365     DistributedWant& FormatUriAndType(const OHOS::Uri& uri, const std::string& type);
366 
367     /**
368      * @description: This method formats data of a specified MIME type
369      * by removing spaces from the data and converting the data into
370      * lowercase letters. You can use this method to normalize
371      * the external data used to create DistributedWant information.
372      * @param type Indicates the MIME type to format
373      * @return Returns this DistributedWant object that contains the formatted type attribute
374      */
375     static std::string FormatMimeType(const std::string& mimeType);
376 
377     /**
378      * @description: clear the specific DistributedWant object.
379      * @param want Indicates the DistributedWant to clear
380      */
381     static void ClearWant(DistributedWant* want);
382 
383     /**
384      * @description: Obtains the description of the DistributedWantParams object in a DistributedWant
385      * @return Returns the DistributedWantParams description in the DistributedWant
386      */
387     const DistributedWantParams& GetParams() const;
388 
389     /**
390      * @description: Sets a DistributedWantParams object in a want.
391      * @param wantParams  Indicates the DistributedWantParams description.
392      * @return Returns this want object containing the DistributedWantParams.
393      */
394     DistributedWant& SetParams(const DistributedWantParams& wantParams);
395 
396     /**
397      * @description: Obtains a bool-type value matching the given key.
398      * @param key   Indicates the key of DistributedWantParams.
399      * @param defaultValue  Indicates the default bool-type value.
400      * @return Returns the bool-type value of the parameter matching the given key;
401      * returns the default value if the key does not exist.
402      */
403     bool GetBoolParam(const std::string& key, bool defaultValue) const;
404 
405     /**
406      * @description: Obtains a bool-type array matching the given key.
407      * @param key   Indicates the key of DistributedWantParams.
408      * @return Returns the bool-type array of the parameter matching the given key;
409      * returns null if the key does not exist.
410      */
411     std::vector<bool> GetBoolArrayParam(const std::string& key) const;
412 
413     /**
414      * @description: Sets a parameter value of the IRemoteObject type.
415      * @param key   Indicates the key matching the parameter.
416      * @param value Indicates the IRemoteObject value of the parameter.
417      * @return Returns this want object containing the parameter value.
418      */
419     DistributedWant& SetParam(const std::string& key, const sptr<IRemoteObject>& remoteObject);
420 
421     /**
422      * @description: Obtains a IRemoteObject-type value matching the given key.
423      * @param key   Indicates the key of WantParams.
424      * @param defaultValue  Indicates the default IRemoteObject-type value.
425      * @return Returns the IRemoteObject-type value of the parameter matching the given key;
426      * returns the nullptr if the key does not exist.
427      */
428     sptr<IRemoteObject> GetRemoteObject(const std::string& key) const;
429 
430     /**
431      * @description: Sets a parameter value of the boolean type.
432      * @param key   Indicates the key matching the parameter.
433      * @param value Indicates the boolean value of the parameter.
434      * @return Returns this DistributedWant object containing the parameter value.
435      */
436     DistributedWant& SetParam(const std::string& key, bool value);
437 
438     /**
439      * @description: Sets a parameter value of the boolean array type.
440      * @param key   Indicates the key matching the parameter.
441      * @param value Indicates the boolean array of the parameter.
442      * @return Returns this DistributedWant object containing the parameter value.
443      */
444     DistributedWant& SetParam(const std::string& key, const std::vector<bool>& value);
445 
446     /**
447      * @description: Obtains a byte-type value matching the given key.
448      * @param key   Indicates the key of DistributedWantParams.
449      * @param defaultValue  Indicates the default byte-type value.
450      * @return Returns the byte-type value of the parameter matching the given key;
451      * returns the default value if the key does not exist.
452      */
453     AAFwk::byte GetByteParam(const std::string& key, AAFwk::byte defaultValue) const;
454 
455     /**
456      * @description: Obtains a byte-type array matching the given key.
457      * @param key   Indicates the key of DistributedWantParams.
458      * @return Returns the byte-type array of the parameter matching the given key;
459      * returns null if the key does not exist.
460      */
461     std::vector<AAFwk::byte> GetByteArrayParam(const std::string& key) const;
462 
463     /**
464      * @description: Sets a parameter value of the byte type.
465      * @param key   Indicates the key matching the parameter.
466      * @param value Indicates the byte-type value of the parameter.
467      * @return Returns this DistributedWant object containing the parameter value.
468      */
469     DistributedWant& SetParam(const std::string& key, AAFwk::byte value);
470 
471     /**
472      * @description: Sets a parameter value of the byte array type.
473      * @param key   Indicates the key matching the parameter.
474      * @param value Indicates the byte array of the parameter.
475      * @return Returns this DistributedWant object containing the parameter value.
476      */
477     DistributedWant& SetParam(const std::string& key, const std::vector<AAFwk::byte>& value);
478 
479     /**
480      * @description: Obtains a char value matching the given key.
481      * @param key   Indicates the key of wnatParams.
482      * @param value Indicates the default char value.
483      * @return Returns the char value of the parameter matching the given key;
484      * returns the default value if the key does not exist.
485      */
486     AAFwk::zchar GetCharParam(const std::string& key, AAFwk::zchar defaultValue) const;
487 
488     /**
489      * @description: Obtains a char array matching the given key.
490      * @param key   Indicates the key of DistributedWantParams.
491      * @return Returns the char array of the parameter matching the given key;
492      * returns null if the key does not exist.
493      */
494     std::vector<AAFwk::zchar> GetCharArrayParam(const std::string& key) const;
495 
496     /**
497      * @description: Sets a parameter value of the char type.
498      * @param key   Indicates the key of DistributedWantParams.
499      * @param value Indicates the char value of the parameter.
500      * @return Returns this DistributedWant object containing the parameter value.
501      */
502     DistributedWant& SetParam(const std::string& key, AAFwk::zchar value);
503 
504     /**
505      * @description: Sets a parameter value of the char array type.
506      * @param key   Indicates the key of DistributedWantParams.
507      * @param value Indicates the char array of the parameter.
508      * @return Returns this DistributedWant object containing the parameter value.
509      */
510     DistributedWant& SetParam(const std::string& key, const std::vector<AAFwk::zchar>& value);
511 
512     /**
513      * @description: Obtains an int value matching the given key.
514      * @param key   Indicates the key of DistributedWantParams.
515      * @param value Indicates the default int value.
516      * @return Returns the int value of the parameter matching the given key;
517      * returns the default value if the key does not exist.
518      */
519     int GetIntParam(const std::string& key, int defaultValue) const;
520 
521     /**
522      * @description: Obtains an int array matching the given key.
523      * @param key   Indicates the key of DistributedWantParams.
524      * @return Returns the int array of the parameter matching the given key;
525      * returns null if the key does not exist.
526      */
527     std::vector<int> GetIntArrayParam(const std::string& key) const;
528 
529     /**
530      * @description: Sets a parameter value of the int type.
531      * @param key   Indicates the key matching the parameter.
532      * @param value Indicates the int value of the parameter.
533      * @return Returns this DistributedWant object containing the parameter value.
534      */
535     DistributedWant& SetParam(const std::string& key, int value);
536 
537     /**
538      * @description: Sets a parameter value of the int array type.
539      * @param key   Indicates the key matching the parameter.
540      * @param value Indicates the int array of the parameter.
541      * @return Returns this DistributedWant object containing the parameter value.
542      */
543     DistributedWant& SetParam(const std::string& key, const std::vector<int>& value);
544 
545     /**
546      * @description: Obtains a double value matching the given key.
547      * @param key   Indicates the key of DistributedWantParams.
548      * @param defaultValue  Indicates the default double value.
549      * @return Returns the double value of the parameter matching the given key;
550      * returns the default value if the key does not exist.
551      */
552     double GetDoubleParam(const std::string& key, double defaultValue) const;
553 
554     /**
555      * @description: Obtains a double array matching the given key.
556      * @param key   Indicates the key of DistributedWantParams.
557      * @return Returns the double array of the parameter matching the given key;
558      * returns null if the key does not exist.
559      */
560     std::vector<double> GetDoubleArrayParam(const std::string& key) const;
561 
562     /**
563      * @description: Sets a parameter value of the double type.
564      * @param key   Indicates the key matching the parameter.
565      * @param value Indicates the int value of the parameter.
566      * @return Returns this DistributedWant object containing the parameter value.
567      */
568     DistributedWant& SetParam(const std::string& key, double value);
569 
570     /**
571      * @description: Sets a parameter value of the double array type.
572      * @param key   Indicates the key matching the parameter.
573      * @param value Indicates the double array of the parameter.
574      * @return Returns this DistributedWant object containing the parameter value.
575      */
576     DistributedWant& SetParam(const std::string& key, const std::vector<double>& value);
577 
578     /**
579      * @description: Obtains a float value matching the given key.
580      * @param key   Indicates the key of wnatParams.
581      * @param value Indicates the default float value.
582      * @return Returns the float value of the parameter matching the given key;
583      * returns the default value if the key does not exist.
584      */
585     float GetFloatParam(const std::string& key, float defaultValue) const;
586 
587     /**
588      * @description: Obtains a float array matching the given key.
589      * @param key Indicates the key of DistributedWantParams.
590      * @return Obtains a float array matching the given key.
591      */
592     std::vector<float> GetFloatArrayParam(const std::string& key) const;
593 
594     /**
595      * @description: Sets a parameter value of the float type.
596      * @param key Indicates the key matching the parameter.
597      * @param value Indicates the byte-type value of the parameter.
598      * @return Returns this DistributedWant object containing the parameter value.
599      */
600     DistributedWant& SetParam(const std::string& key, float value);
601 
602     /**
603      * @description: Sets a parameter value of the float array type.
604      * @param key Indicates the key matching the parameter.
605      * @param value Indicates the byte-type value of the parameter.
606      * @return Returns this DistributedWant object containing the parameter value.
607      */
608     DistributedWant& SetParam(const std::string& key, const std::vector<float>& value);
609 
610     /**
611      * @description: Obtains a long value matching the given key.
612      * @param key Indicates the key of DistributedWantParams.
613      * @param value Indicates the default long value.
614      * @return Returns the long value of the parameter matching the given key;
615      * returns the default value if the key does not exist.
616      */
617     long GetLongParam(const std::string& key, long defaultValue) const;
618 
619     /**
620      * @description: Obtains a long array matching the given key.
621      * @param key Indicates the key of DistributedWantParams.
622      * @return Returns the long array of the parameter matching the given key;
623      * returns null if the key does not exist.
624      */
625     std::vector<long> GetLongArrayParam(const std::string& key) const;
626 
627     DistributedWant& SetParam(const std::string& key, long long value);
628 
629     /**
630      * @description: Sets a parameter value of the long type.
631      * @param key Indicates the key matching the parameter.
632      * @param value Indicates the byte-type value of the parameter.
633      * @return Returns this DistributedWant object containing the parameter value.
634      */
635     DistributedWant& SetParam(const std::string& key, long value);
636 
637     /**
638      * @description: Sets a parameter value of the long array type.
639      * @param key Indicates the key matching the parameter.
640      * @param value Indicates the byte-type value of the parameter.
641      * @return Returns this DistributedWant object containing the parameter value.
642      */
643     DistributedWant& SetParam(const std::string& key, const std::vector<long>& value);
644 
645     /**
646      * @description: a short value matching the given key.
647      * @param key Indicates the key of DistributedWantParams.
648      * @param defaultValue Indicates the default short value.
649      * @return Returns the short value of the parameter matching the given key;
650      * returns the default value if the key does not exist.
651      */
652     short GetShortParam(const std::string& key, short defaultValue) const;
653 
654     /**
655      * @description: Obtains a short array matching the given key.
656      * @param key Indicates the key of DistributedWantParams.
657      * @return Returns the short array of the parameter matching the given key;
658      * returns null if the key does not exist.
659      */
660     std::vector<short> GetShortArrayParam(const std::string& key) const;
661 
662     /**
663      * @description: Sets a parameter value of the short type.
664      * @param key Indicates the key matching the parameter.
665      * @param value Indicates the byte-type value of the parameter.
666      * @return Returns this DistributedWant object containing the parameter value.
667      */
668     DistributedWant& SetParam(const std::string& key, short value);
669 
670     /**
671      * @description: Sets a parameter value of the short array type.
672      * @param key Indicates the key matching the parameter.
673      * @param value Indicates the byte-type value of the parameter.
674      * @return Returns this DistributedWant object containing the parameter value.
675      */
676     DistributedWant& SetParam(const std::string& key, const std::vector<short>& value);
677 
678     /**
679      * @description: Obtains a string value matching the given key.
680      * @param key Indicates the key of DistributedWantParams.
681      * @return Returns the string value of the parameter matching the given key;
682      * returns null if the key does not exist.
683      */
684     std::string GetStringParam(const std::string& key) const;
685 
686     /**
687      * @description: Obtains a string array matching the given key.
688      * @param key Indicates the key of DistributedWantParams.
689      * @return Returns the string array of the parameter matching the given key;
690      * returns null if the key does not exist.
691      */
692     std::vector<std::string> GetStringArrayParam(const std::string& key) const;
693 
694     /**
695      * @description: Sets a parameter value of the string type.
696      * @param key Indicates the key matching the parameter.
697      * @param value Indicates the byte-type value of the parameter.
698      * @return Returns this DistributedWant object containing the parameter value.
699      */
700     DistributedWant& SetParam(const std::string& key, const std::string& value);
701 
702     /**
703      * @description: Sets a parameter value of the string array type.
704      * @param key Indicates the key matching the parameter.
705      * @param value Indicates the byte-type value of the parameter.
706      * @return Returns this DistributedWant object containing the parameter value.
707      */
708     DistributedWant& SetParam(const std::string& key, const std::vector<std::string>& value);
709 
710     /**
711      * @description: Checks whether a DistributedWant contains the parameter matching a given key.
712      * @param key Indicates the key.
713      * @return Returns true if the DistributedWant contains the parameter; returns false otherwise.
714      */
715     bool HasParameter(const std::string& key) const;
716 
717     /**
718      * @description: Replaces parameters in this Want object with those in the given DistributedWantParams object.
719      * @param wantParams Indicates the DistributedWantParams object containing the new parameters.
720      * @return Returns this Want object containing the new parameters.
721      */
722     DistributedWant* ReplaceParams(DistributedWantParams& wantParams);
723 
724     /**
725      * @description: Replaces parameters in this DistributedWant object with those in the given Want object.
726      * @param want Indicates the DistributedWant object containing the new parameters.
727      * @return Returns this DistributedWant object containing the new parameters.
728      */
729     DistributedWant* ReplaceParams(DistributedWant& want);
730 
731     /**
732      * @description: Removes the parameter matching the given key.
733      * @param key Indicates the key matching the parameter to be removed.
734      */
735     void RemoveParam(const std::string& key);
736 
737     /**
738      * @description: Gets the description of an operation in a DistributedWant.
739      * @return Returns the operation included in this DistributedWant.
740      */
741     DistributedOperation GetOperation() const;
742 
743     /**
744      * @description: Sets the description of an operation in a DistributedWant.
745      * @param operation Indicates the operation description.
746      */
747     void SetOperation(const DistributedOperation& operation);
748 
749     /**
750      * @description: Sets the description of an operation in a DistributedWant.
751      * @param want Indicates the DistributedWant object to compare.
752      * @return Returns true if the operation components of the two objects are equal; returns false otherwise.
753      */
754     bool OperationEquals(const DistributedWant& want);
755 
756     /**
757      * @description: Creates a DistributedWant object that contains only
758      * the operation component of this DistributedWant.
759      * @return Returns the created DistributedWant object.
760      */
761     DistributedWant* CloneOperation();
762 
763     /**
764      * @description: Marshals a DistributedWant into a Parcel.
765      * Fields in the DistributedWant are marshalled separately. If any field fails to be marshalled, false is returned.
766      * @param parcel Indicates the Parcel object for marshalling.
767      * @return Returns true if the marshalling is successful; returns false otherwise.
768      */
769     virtual bool Marshalling(Parcel& parcel) const;
770 
771     /**
772      * @description: Unmarshals a DistributedWant from a Parcel.
773      * Fields in the DistributedWant are unmarshalled separately.
774      * If any field fails to be unmarshalled, false is returned.
775      * @param parcel Indicates the Parcel object for unmarshalling.
776      * @return Returns true if the unmarshalling is successful; returns false otherwise.
777      */
778     static DistributedWant* Unmarshalling(Parcel& parcel);
779 
780     std::string ToString() const;
781 
782     static DistributedWant* FromString(std::string& string);
783 
784     std::shared_ptr<AAFwk::Want> ToWant();
785 
786     /**
787     * @description: Sets a device id in a DistributedWant.
788     * @param deviceId Indicates the device id to set.
789     * @return Returns this DistributedWant object containing the flag.
790     */
791     DistributedWant& SetDeviceId(const std::string& deviceId);
792 public:
793     static const std::string ACTION_PLAY;
794     static const std::string ACTION_HOME;
795     static const std::string ENTITY_HOME;
796     static const std::string ENTITY_VIDEO;
797     static const std::string FLAG_HOME_INTENT_FROM_SYSTEM;
798     static const std::string ENTITY_MUSIC;
799     static const std::string ENTITY_EMAIL;
800     static const std::string ENTITY_CONTACTS;
801     static const std::string ENTITY_MAPS;
802     static const std::string ENTITY_BROWSER;
803     static const std::string ENTITY_CALENDAR;
804     static const std::string ENTITY_MESSAGING;
805     static const std::string ENTITY_FILES;
806     static const std::string ENTITY_GALLERY;
807     static unsigned int FLAG_ABILITY_NEW_MISSION;
808     static unsigned int FLAG_ABILITY_CLEAR_MISSION;
809     static constexpr int HEX_STRING_BUF_LEN = 36;
810     static constexpr int HEX_STRING_LEN = 10;
811     static const std::string PARAM_RESV_WINDOW_MODE;
812     static const std::string PARAM_RESV_DISPLAY_ID;
813     static const std::string PARAM_RESV_CALLER_TOKEN;
814     static const std::string PARAM_RESV_CALLER_UID;
815     static const std::string PARAM_RESV_CALLER_PID;
816 
817 private:
818     DistributedWantParams parameters_;
819     DistributedOperation operation_;
820 
821     static const std::string OCT_EQUALSTO;
822     static const std::string OCT_SEMICOLON;
823     static const std::string MIME_TYPE;
824     static const std::string WANT_HEADER;
825 
826     static constexpr int VALUE_NULL = -1;
827     static constexpr int VALUE_OBJECT = 1;
828 
829 private:
830     static bool ParseFlag(const std::string& content, DistributedWant& want);
831     static std::string Decode(const std::string& str);
832     static std::string Encode(const std::string& str);
833     static bool ParseContent(const std::string& content, std::string& prop, std::string& value);
834     static bool ParseUriInternal(
835         const std::string& content, OHOS::AppExecFwk::ElementName& element, DistributedWant& want);
836     bool ReadFromParcel(Parcel& parcel);
837     static bool CheckAndSetParameters(
838         DistributedWant& want, const std::string& key, std::string& prop, const std::string& value);
839     OHOS::Uri GetLowerCaseScheme(const OHOS::Uri& uri);
840     void GenerateUriString(std::string& uriString) const;
841     void ToUriStringInner(std::string& uriString) const;
842     nlohmann::json ToJson() const;
843     bool ReadFromJson(nlohmann::json& wantJson);
844     bool CanReadFromJson(nlohmann::json& wantJson);
845     bool MarshallingWriteEntities(Parcel& parcel) const;
846     bool MarshallingWriteElement(Parcel& parcel) const;
847     bool MarshallingWriteParameters(Parcel& parcel) const;
848     bool MarshallingWriteUri(Parcel& parcel) const;
849     bool ReadUriFromParcel(Parcel& parcel);
850     bool ReadEntitiesFromParcel(Parcel& parcel);
851     bool ReadElementFromParcel(Parcel& parcel);
852     bool ReadParametersFromParcel(Parcel& parcel);
853 };
854 } // namespace DistributedSchedule
855 } // namespace OHOS
856 #endif // OHOS_DISTRIBUTEDWANT_WANT_H
857