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