1# Matching Rules of Explicit Want and Implicit Want 2 3Both explicit [Want](../reference/apis-ability-kit/js-apis-app-ability-want.md) and implicit [Want](../reference/apis-ability-kit/js-apis-app-ability-want.md) can be used to match an application component to start based on certain rules. These rules determine how the parameters set in [want](../reference/apis-ability-kit/js-apis-app-ability-want.md) match the configuration file declared by the target application component. 4 5## Matching Rules of Explicit Want 6 7 8The table below describes the matching rules of explicit [Want](../reference/apis-ability-kit/js-apis-app-ability-want.md). 9 10| Name| Type| Matching Item| Mandatory| Rule Description| 11| -------- | -------- | -------- | -------- | -------- | 12| deviceId | string | Yes| No| If this field is unspecified, only application components on the local device are matched.| 13| bundleName | string | Yes| Yes| If **abilityName** is specified but **bundleName** is unspecified, the matching fails.| 14| moduleName | string | Yes| No| If this field is unspecified and multiple modules with the same ability name exist in the application, the first application component is matched by default.| 15| abilityName | string | Yes| Yes| To use explicit Want, this field must be specified.| 16| uri | string | No| No| This field is not used for matching. It is passed to the target application component as a parameter.| 17| type | string | No| No| This field is not used for matching. It is passed to the target application component as a parameter.| 18| action | string | No| No| This field is not used for matching. It is passed to the target application component as a parameter.| 19| entities | Array<string> | No| No| This field is not used for matching. It is passed to the target application component as a parameter.| 20| flags | number | No| No| This field is not used for matching and is directly transferred to the system for processing. It is generally used to set runtime information, such as URI data authorization.| 21| parameters | {[key: string]: Object} | No| No| This field is not used for matching. It is passed to the target application component as a parameter.| 22 23## Matching Rules of Implicit Want 24 25The table below describes the matching rules of implicit [Want](../reference/apis-ability-kit/js-apis-app-ability-want.md). 26 27| Name | Type | Matching Item| Mandatory| Rule Description | 28| ----------- | ------------------------------ | ------ | ---- | ------------------------------------------------------------ | 29| deviceId | string | Yes | No | Implicit invoking is not supported across devices. | 30| abilityName | string | No | No | To use implicit Want, this field must be left unspecified. | 31| bundleName | string | Yes | No | This field is used to match the target application component in the given bundle. | 32| moduleName | string | Yes | No | This field is used to match the target application component in the given module. | 33| uri | string | Yes | No | For details, see [Matching Rules of uri and type in the want Parameter](#matching-rules-of-uri-and-type-in-the-want-parameter). | 34| type | string | Yes | No | For details, see [Matching Rules of uri and type in the want Parameter](#matching-rules-of-uri-and-type-in-the-want-parameter). | 35| action | string | Yes | No | For details, see [Matching Rules of action in the want Parameter](#matching-rules-of-action-in-the-want-parameter). | 36| entities | Array<string> | Yes | No | For details, see [Matching Rules of entities in the want Parameter](#matching-rules-of-entities-in-the-want-parameter). | 37| flags | number | No | No | This field is not used for matching and is directly transferred to the system for processing. It is generally used to set runtime information, such as URI data authorization.| 38| parameters | {[key: string]: Object} | Yes | No | This field is used to transfer custom data to the target application component. Currently, only the parameter with the key set to **linkFeature** is used for matching. When **linkFeature** is not null, a matching against **linkFeature** is carried out preferentially.| 39 40Get familiar with the following about implicit Want: 41 42 43- The **want** parameter passed by the caller indicates the operation to be performed by the caller. It also provides data and application type restrictions. 44 45- The **skills** field declares the capabilities of the target application component. For details, see [the skills tag](../quick-start/module-configuration-file.md#skills) in the [module.json5 file](../quick-start/module-configuration-file.md). 46 47 48The system matches the **want** parameter (including the **action**, **entities**, **uri**, **type**, and **parameters** attributes) passed by the caller against the **skills** configuration (including the **actions**, **entities**, **uris**, and **type** attributes) of the application components. If none of the five attributes in the **want** parameter is configured, implicit matching fails. 49- If the **linkFeature** field in **parameters** is not null, a matching against **linkFeature** is carried out preferentially. 50 - If **linkFeature** is matched and **uri** or **type** in the **want** parameter is configured, the system continues to match **uri** or **type**. If they are matched, the implicit matching is successful. Otherwise, the matching fails. If neither **uri** nor **type** in the **want** parameter is configured, the implicit matching is successful. 51 - If **linkFeature** is not matched, no matching is performed and the matching fails. 52- If the **linkFeature** field in **parameters** is not specified or is null, the matching is successful only when the **action**, **entities**, **uri**, and **type** attributes are all matched. 53 54 55### Matching Rules of action in the want Parameter 56 57The system matches the **action** attribute in the **want** parameter passed by the caller against **actions** under **skills** of the application components. 58 59- If **action** in the passed **want** parameter is null and **actions** under **skills** of an application component is null, the matching fails. 60 61- If **action** in the passed **want** parameter is not null but **actions** under **skills** of an application component is null, the matching fails. 62 63- If **action** in the passed **want** parameter is null but **actions** under **skills** of an application component is not null, the matching is successful. 64 65- If **action** in the passed **want** parameter is not null, and **actions** under **skills** of an application component is not null and contains **action** in the passed **want** parameter, the matching is successful. 66 67- If **action** in the passed **want** parameter is not null, and **actions** under **skills** of an application component is not null but does not contain **action** in the passed **want** parameter, the matching fails. 68 69**Figure 1** Matching rules of action in the want parameter 70 71 72 73 74### Matching Rules of entities in the want Parameter 75 76The system matches the **entities** attribute in the **want** parameter passed by the caller against **entities** under **skills** of the application components. 77 78- If **entities** in the passed **want** parameter is null but **entities** under **skills** of an application component is not null, the matching is successful. 79 80- If **entities** in the passed **want** parameter is null but **entities** under **skills** of an application component is null, the matching is successful. 81 82- If **entities** in the passed **want** parameter is not null but **entities** under **skills** of an application component is null, the matching fails. 83 84- If **entities** in the passed **want** parameter is not null, and **entities** under **skills** of an application component is not null and contains **entities** in the passed **want** parameter, the matching is successful. 85 86- If **entities** in the passed **want** parameter is not null, and **entities** under **skills** of an application component is not null but does not contain **entities** in the passed **want** parameter, the matching fails. 87 88**Figure 2** Matching rules of entities in the want parameter 89 90 91 92 93### Matching Rules of uri and type in the want Parameter 94 95When the **uri** and **type** parameters are not null in the **want** parameter to initiate an application component startup request, the system traverses the list of installed components and matches the **uris** array under **skills** of the application components one by one. If one of the **uris** arrays under **skills** matches the **uri** and **type** in the passed **want**, the matching is successful. 96 97There are four combinations of **uri** and **type** settings. The matching rules are as follows: 98 99- Both **uri** and **type** are null in the **want** parameter. 100 - If the **uris** array under **skills** of an application component is null, the matching is successful. 101 - If the **uris** array under **skills** of an application component contains an URI element whose **scheme** and **type** are null, the matching is successful. 102 - In other cases, the matching fails. 103 104- Only **uri** is not null in the **want** parameter. 105 - If the **uris** array under **skills** of an application component is null, the matching fails. 106 - If the **uris** array under **skills** of an application component contains an element whose [uri is matched](#matching-rules-of-uri) and **type** is null, the matching is successful. Otherwise, the matching fails. 107 - If the matching fails for the preceding two scenarios and the input URI is a file path URI, the system obtains the MIME type of the file based on the file name extension. If the MIME type matches **type** configured under **skills**, the matching is successful. 108 109- Only **type** is not null in the **want** parameter. 110 - If the **uris** array under **skills** of an application component is null, the matching fails. 111 - If the **uris** array under **skills** of an application component contains an URI element whose **scheme** is null and [type is matched](#matching-rules-of-type), the matching is successful. Otherwise, the matching fails. 112 113- Both **uri** and **type** are not null in the **want** parameter, as shown below. 114 - If the **uris** array under **skills** of an application component is null, the matching fails. 115 - If the **uris** array under **skills** of an application component contains an element whose [uri is matched](#matching-rules-of-uri) and [type is matched](#matching-rules-of-type), the matching is successful. Otherwise, the matching fails. 116 117Leftmost URI matching: When only **scheme**, a combination of **scheme** and **host**, or a combination of **scheme**, **host**, and **port** is configured in the **uris** array under **skills** of the application component, the matching is successful only if the leftmost URI in the passed **want** parameter matches **scheme**, the combination of **scheme** and **host**, or the combination of **scheme**, **host**, and **port**. 118 119**Figure 3** Matching rules when uri and type are not null in the want parameter 120 121 122 123To simplify the description: 124 125- **uri** in the **want** parameter passed in by the caller is called **w_uri**; each element in the **uris** array under **skills** of the application component to match is called **s_uri**. 126- **type** in the **want** parameter passed in by the caller is called **w_type**; the type in the **uris** array under **skills** of the application component to match is called **s_type**. 127 128**Figure 4** Matching rules of uri and type in the want parameter 129 130 131 132 133### Matching Rules of uri 134 135The matching rules are as follows: 136 137- If **scheme** of **s_uri** is null and **w_uri** is null, the matching is successful. Otherwise, the matching fails. 138 139- If **host** of **s_uri** is null and **scheme** of **w_uri** and **scheme** of **s_uri** are the same, the matching is successful. Otherwise, the matching fails. 140 141- If **port** of **s_uri** is null and the combination of **scheme** and **host** of **w_uri** is the same as the combination of **scheme** and **host** of **s_uri**, the matching is successful. Otherwise, the matching fails. 142 143- If **path**, **pathStartWith**, and **pathRegex** of **s_uri** are null and the combination of **scheme**, **host**, and **port** of **w_uri** is the same as the combination of **scheme**, **host**, and **port** of **s_uri**, the matching is successful. Otherwise, the matching fails. 144 145- If **path** of **s_uri** is not null and the **full path expressions** of **w_uri** and **s_uri** are the same, the matching is successful. Otherwise, the matching of **pathStartWith** continues. 146 147- If **pathStartWith** of **s_uri** is not null and **w_uri** contains the prefix expression of **s_uri**, the matching is successful. Otherwise, **pathRegex** matching continues. 148 149- If **pathRegex** of **s_uri** is not null and **w_uri** meets the regular expression of **s_uri**, the matching is successful. Otherwise, the matching fails. 150 151> **NOTE** 152> 153> The **scheme**, **host**, **port**, **path**, **pathStartWith**, and **pathRegex** attributes of **uris** under **skills** of an application component are concatenated. If **path**, **pathStartWith**, and **pathRegex** are declared in sequence, **uris** can be concatenated into the following expressions: 154> 155> - **Prefix URI expression**: When only **scheme**, a combination of **scheme** and **host**, or a combination of **scheme**, **host**, and **port** is configured in the configuration file, the matching is successful if a URI prefixed with the configuration file is passed in. 156> * `scheme://` 157> * `scheme://host` 158> * `scheme://host:port` 159> - **Full path expression**: `scheme://host:port/path` 160> - **Prefix expression**: `scheme://host:port/pathStartWith` 161> - **Regular expression**: `scheme://host:port/pathRegex` 162> 163> For system applications, **scheme** of their URIs starts with **ohos**, for example, **ohosclock://**. The URI of a third-party application cannot be the same as that of a system application. Otherwise, the third-party application cannot be started using the URI. 164 165**Figure 5** Example of the matching rules of uri in the want parameter 166 167 168 169### Matching Rules of type 170 171> **NOTE** 172> 173> The matching rules of **type** described in this section are based on the fact that **type** in the **want** parameter is not null. If **type** is null, follow the [matching rules of uri and type in the want parameter](#matching-rules-of-uri-and-type-in-the-want-parameter). 174 175The matching rules are as follows: 176 177- If **s_type** is null, the matching fails. 178 179- If **s_type** or **w_type** contains the wildcard `*/*`, the matching is successful. 180 181- If the last character of **s_type** is the wildcard `*`, for example, `prefixType/*`, the matching is successful only when **w_type** contains `prefixType/`. 182 183- If the last character of **w_type** is the wildcard `*`, for example, `prefixType/*`, the matching is successful only when **s_type** contains `prefixType/`. 184 185### Matching Rules of linkFeature 186 187> **NOTE** 188> 189> The linkFeature matching rules described below apply to the scenario where **parameters** in the **want** parameter contains the **linkFeature** key and the value of the key is not null. 190 191The system matches **parameters** in the **want** parameter passed by the caller against **uris** under **skills** of the application components. To simplify the description, **linkFeature** in the **want** parameter passed in by the caller is called **w_linkFeature**. The matching rules are as follows: 192- If both **uri** and **type** in the **want** parameter are null, only **linkFeature** is used for matching. If the value of **w_linkFeature** matches that of **s_uri**, the matching is successful. Otherwise, the matching fails. 193- If **uri** or **type** in the **want** parameter is not null, the system matches **linkFeature**, **uri**, and **type** in sequence. For details, see [Matching Rules of uri and type in the want Parameter](#matching-rules-of-uri-and-type-in-the-want-parameter). If all the three fields are matched, the matching is successful. Otherwise, the matching fails. 194 195 196 197**Figure 6** Matching rules of linkFeature in the want parameter 198 199 200 201 202