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