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