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