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