提交 e30701c6 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 c61c4424
# APIs<a name="EN-US_TOPIC_0000001162494631"></a>
- **[Console Logs](console-logs.md)**
- [Console Logs](console-logs.md)
- **[HiAppEvent](hiappevent.md)**
- [HiAppEvent](hiappevent.md)
- **[Page Routing](page-routing.md)**
- [Page Routing](page-routing.md)
- **[Pop-up Window](pop-up-window.md)**
- [Pop-up Window](pop-up-window.md)
- **[Timer](timer.md)**
- [Timer](timer.md)
- **[Audio Management](js-apis-audio.md)**
- [Audio Management](js-apis-audio.md)
- **[Audio Playback](audio-playback.md)**
- [Audio Playback](audio-playback.md)
- **[Device Information](device-information.md)**
- [Device Information](device-information.md)
- **[System Attribute](system-attribute.md)**
- [System Attribute](system-attribute.md)
- **[Battery and Charging](battery-and-charging.md)**
- [Battery and Charging](battery-and-charging.md)
- **[Screen Brightness](screen-brightness.md)**
- [Screen Brightness](screen-brightness.md)
- **[Globalization](globalization.md)**
- [Globalization](globalization.md)
- **[Resource Management](resource-management.md)**
- [Resource Management](resource-management.md)
- **[Updater](updater.md)**
- [Updater](updater.md)
- [URL String Parsing](js-apis-uri.md)
# URL String Parsing
> ![](../../public_sys-resources/icon-note.gif) **Note:**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import Url from '@ohos.url'
```
## Required Permissions
None
## URLSearchParams
### constructor
constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLSearchParams)
Creates a **URLSearchParams** instance.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| init | string[][]&nbsp;\|&nbsp;Record&lt;string,&nbsp;string&gt;&nbsp;\|&nbsp;string&nbsp;\|&nbsp;URLSearchParams | No| Input parameter objects, which include the following: <br/>-&nbsp;**string[][]**: two-dimensional string array<br/>-&nbsp;**Record&lt;string,&nbsp;string&gt;**: list of objects<br/>-&nbsp;**string**: string<br/>-&nbsp;**URLSearchParams**: object|
- Example
```
var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2});
var objectParams2 = new URLSearchParams('?fod=1&bard=2');
var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2');
var params = new URLSearchParams(urlObject .search);
```
### append
append(name: string, value: string): void
Appends a key-value pair into the query string.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key of the key-value pair to append.|
| value | string | Yes| Value of the key-value pair to append.|
- Example
```
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', 3);
```
### delete
delete(name: string): void
Deletes key-value pairs of the specified key.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key of the key-value pairs to delete.|
- Example
```
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new URLSearchParams(urlObject.search.slice(1));
paramsobject.delete('foo');
```
### getAll
getAll(name: string): string[]
Obtains all the key-value pairs based on the specified key.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key specified to obtain all key-value pairs.|
- Return values
| Type| Description|
| -------- | -------- |
| string[] | All key-value pairs matching the specified key.|
- Example
```
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', 3); // Add a second value for the foo parameter.
console.log(params.getAll('fod')) // Output ["1","3"].
```
### entries
entries(): IterableIterator&lt;[string, string]&gt;
Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively.
- Return values
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;[string,&nbsp;string]&gt; | An ES6 iterator.|
- Example
```
var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]);
}
```
### forEach
forEach(callbackfn: (value: string, key: string, searchParams: Object) =&gt; void, thisArg?: Object): void
Traverses the key-value pairs in the **URLSearchParams** instance by using a callback.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackfn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.|
| thisArg | Object | No| Value to use when the callback is invoked.|
**Table 1** callbackfn parameter description
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string | Yes| Value that is currently traversed.|
| key | string | Yes| Key that is currently traversed.|
| searchParams | Object | Yes| Instance that invokes the **forEach** method.|
- Example
```
const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.searchParams.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams);
});
```
### get
get(name: string): string | null
Obtains the value of the first key-value pair based on the specified key.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key specified to obtain the value.|
- Return values
| Type| Description|
| -------- | -------- |
| string | Returns the value of the first key-value pair if obtained.|
| null | Returns null if no value is obtained.|
- Example
```
var paramsOject = new URLSearchParams(document.location.search.substring(1));
var name = paramsOject.get("name"); // is the string "Jonathan"
var age = parseInt(paramsOject.get("age"), 10); // is the number 18
var address = paramsOject.get("address"); // null
```
### has
has(name: string): boolean
Checks whether a key has a value.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key specified to search for its value.|
- Return values
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value exists; returns **false** otherwise.|
- Example
```
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1));
paramsObject.has('bard') === true;
```
### set
set(name: string, value: string): void
Sets the value for a key. If key-value pairs matching the specified key exist, the value of the first key-value pair will be set to the specified value and other key-value pairs will be deleted. Otherwise, the key-value pair will be appended to the query string.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key of the value to set.|
| value | string | Yes| Value to set.|
- Example
```
let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new URLSearchParams(urlObject.search.slice(1));
paramsObject.set('baz', 3); // Add a third parameter.
```
### sort
sort(): void
Sorts all key-value pairs contained in this object based on the Unicode code points of the keys and returns undefined.排序顺序是根据键的Unicode代码点。This method uses a stable sorting algorithm, that is, the relative order between key-value pairs with equal keys is retained.
- Example
```
var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs
console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4
```
### keys
keys(): IterableIterator&lt;string&gt;
Obtains an ES6 iterator that contains the keys of all the key-value pairs.
- Return values
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;string&gt; | ES6 iterator that contains the keys of all the key-value pairs.|
- Example
```
var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs
console.log(key);
}
```
### values
values(): IterableIterator&lt;string&gt;
Obtains an ES6 iterator that contains the values of all the key-value pairs.
- Return values
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;string&gt; | ES6 iterator that contains the values of all the key-value pairs.|
- Example
```
var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) {
console.log(value);
}
```
### [Symbol.iterator]
[Symbol.iterator](): IterableIterator&lt;[string, string]&gt;
Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively.
- Return values
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;[string,&nbsp;string]&gt; | An ES6 iterator.|
- Example
```
const paramsObject = new URLSearchParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) {
console.log(name, value);
}
```
### tostring
toString(): string
Obtains search parameters that are serialized as a string and, if necessary, percent-encodes the characters in the string.
- Return values
| Type| Description|
| -------- | -------- |
| string | String of serialized search parameters, which is percent-encoded if necessary.|
- Example
```
let url = new URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new URLSearchParams(url.search.slice(1));
params.append('fod', 3);
console.log(params.toString());
```
## URL
### Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| hash | string | Yes| Yes| String that contains a harsh mark (#) followed by the fragment identifier of a URL.|
| host | string | Yes| Yes| Host information in a URL.|
| hostname | string | Yes| Yes| Hostname (without the port) in a URL.|
| href | string | Yes| Yes| String that contains the whole URL.|
| origin | string | Yes| No| Read-only string that contains the Unicode serialization of the origin of the represented URL.|
| password | string | Yes| Yes| Password in a URL.|
| pathname | string | Yes| Yes| Path in a URL.|
| port | string | Yes| Yes| Port in a URL.|
| protocol | string | Yes| Yes| Protocol in a URL.|
| search | string | Yes| Yes| Serialized query string in a URL.|
| searchParams | URLsearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.|
| username | string | Yes| Yes| Username in a URL.|
### constructor
constructor(url: string, base?: string | URL)
Creates a URL.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| url | string | Yes| Input object.|
| base | string&nbsp;\|&nbsp;URL | No| Input parameter, which can be any of the following: <br/>-&nbsp;**string**: string<br/>-&nbsp;**URL**: string or object|
- Example
```
var mm = 'http://username:password@host:8080';
var a = new URL("/", mm); // Output 'http://username:password@host:8080/';
var b = new URL(mm); // Output 'http://username:password@host:8080/';
new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1';
var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1';
new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1
new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL
new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/
new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/
```
### tostring
toString(): string
Converts the parsed URL into a string.
- Return values
| Type| Description|
| -------- | -------- |
| string | Website address in a serialized string.|
- Example
```
const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString()
```
### toJSON
toJSON(): string
Converts the parsed URL into a JSON string.
- Return values
| Type| Description|
| -------- | -------- |
| string | Website address in a serialized string.|
- Example
```
const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON()
```
......@@ -108,7 +108,7 @@ context.getOrCreateLocalDir().then((void) => {
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | ----------------------------------------------- | ---- | ----------------------------------- |
| permission | 只读 | string | 是 | 指定权限的名称 |
| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 是 | 进程id |
| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 是 | 权限选项 |
| callback | 只读 | AsyncCallback\<number> | 是 | 返回权限验证结果,0有权限,-1无权限 |
- 返回值
......@@ -132,7 +132,7 @@ context.verifyPermission("com.example.permission",datainfo.uid)
- 接口说明
验证系统中运行的特定pid和uid是否具有指定的权限(callback形式)
验证系统中运行的当前pid和uid是否具有指定的权限(callback形式)
- 参数描述
......@@ -167,13 +167,13 @@ context.verifyPermission("com.example.permission")
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | ----------------------------------------------- | ---- | -------------- |
| permission | 只读 | string | 是 | 指定权限的名称 |
| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 否 | 进程id |
| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 否 | 权限选项 |
- 返回值
| 类型 | 说明 |
| --------------- | ------------------------------------------------------------ |
| Promise<number> | 如果pid和uid具有权限,则使用{@code 0}进行异步回调;否则使用{@code-1}回调。 |
| Promise<number> | 如果pid和uid具有权限,则使用**0**进行异步回调;否则使用**-1**回调。 |
- 示例
......@@ -503,13 +503,13 @@ context.getProcessName().then((void) => {
- 接口说明
获取调用当前ability捆绑包名称(callback形式)
获取调用ability的包名称(callback形式)
- 参数描述
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ---------------------- | ---- | ------------------------- |
| callback | 只读 | AsyncCallback\<string> | 是 | 返回当前ability捆绑包名称 |
| callback | 只读 | AsyncCallback\<string> | 是 | 返回调用ability的包名称 |
- 返回值
......@@ -529,7 +529,7 @@ context.getCallingBundle()
- 接口说明
获取调用当前ability捆绑包名称(Promise形式)
获取调用ability的包名称(Promise形式)
- 参数描述
......@@ -539,7 +539,7 @@ context.getCallingBundle()
| 类型 | 说明 |
| --------------- | ------------------------- |
| Promise<string> | 调用当前ability捆绑包名称 |
| Promise<string> | 调用ability的包名称 |
......
......@@ -780,7 +780,7 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
- 方法说明
取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式)
清除当前公共事件的取消状态,仅对有序公共事件有效(callback形式)
- 参数
......@@ -804,7 +804,7 @@ CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
- 方法说明
取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式)
清除当前公共事件的取消状态,仅对有序公共事件有效(Promise形式)
- 示例
......
......@@ -668,7 +668,7 @@ var result = await featureAbility.disconnectAbility(connId);
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | 指定组件是否属于OHOS |
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | 指定是否启动某个能力 |
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | 指示URI上可能持久化的授权 |
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 将结果返回到源能力 |
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | 指示对URI前缀进行授权的权限 |
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | 支持分布式调度系统中的多设备启动 |
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | 指示无论主机应用程序是否已启动,都将启动使用服务模板的功能 |
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | 表示迁移是可拉回的。 |
......
......@@ -119,19 +119,19 @@ hdf_audio_codec_dev1
### 播放流程<a name="section3112"></a>
![=](figures/ADM播放流程图.png)
1. 播放音频时,Interface Lib层通过播放流服务下发Render Open指令,Render Stream Dispatch服务收到指令后分别调用各模块的函数接口对指令进行下发。
1. 播放音频时,Interface Lib层通过播放流服务下发Render Open指令,Audio Stream Dispatch服务收到指令后分别调用各模块的函数接口对指令进行下发。
2. Interface Lib层通过控制服务下发通路选择指令,Control Dispatch控制服务收到指令后调用Dai模块接口设置通路。
3. Interface Lib层通过播放流服务下发硬件参数,Render Stream Dispatch服务收到参数后分别调用各模块参数设置接口,对硬件参数进行设置。
3. Interface Lib层通过播放流服务下发硬件参数,Audio Stream Dispatch服务收到参数后分别调用各模块参数设置接口,对硬件参数进行设置。
4. Interface Lib层通过播放流服务下发播放启动指令,Render Stream Dispatch服务收到指令后分别调用各模块启动接口,对各模块进行启动设置。
4. Interface Lib层通过播放流服务下发播放启动指令,Audio Stream Dispatch服务收到指令后分别调用各模块启动接口,对各模块进行启动设置。
5. Interface Lib层通过播放流服务下发音频数据,Render Stream Dispatch服务收到数据后调用Platform AudioPcmWrite接口将音频数据传给Dma。
5. Interface Lib层通过播放流服务下发音频数据,Audio Stream Dispatch服务收到数据后调用Platform AudioPcmWrite接口将音频数据传给Dma。
6. Interface Lib层通过播放流服务下发播放停止指令,Render Stream Dispatch服务收到指令后分别调用各模块停止接口,对各模块进行停止设置。
6. Interface Lib层通过播放流服务下发播放停止指令,Audio Stream Dispatch服务收到指令后分别调用各模块停止接口,对各模块进行停止设置。
7. Interface Lib层通过播放流服务下发Render Close指令,Render Stream Dispatch服务收到指令后调用Platform AudioRenderClose对已申请资源进行释放。
7. Interface Lib层通过播放流服务下发Render Close指令,Audio Stream Dispatch服务收到指令后调用Platform AudioRenderClose对已申请资源进行释放。
### 控制流程<a name="section3113"></a>
......@@ -464,9 +464,9 @@ array index
6:External Codec Enable
7:Internally Codec Enable
8:Render Channel Mode
9:Captrue Channel Mode
9:Capture Channel Mode
iface
0:virtual dac devic
0:virtual dac device
1:virtual adc device
2:virtual adc device
3:virtual mixer device
......@@ -546,7 +546,7 @@ ctrlParamsSeqConfig:控制功能寄存器配置组,其中item与controlsConf
0x20, 0x20, 16, 16, 0x0, 0xF, 0x1F, 0, 0, //"Mic Left Gain"
0x20, 0x20, 24, 24, 0x0, 0xF, 0x1F, 0, 0, //"Mic Right Gain"
0x2000, 0x2000, 16, 16, 0x0, 0x7, 0x7, 0, 0, //"Render Channel Mode"
0x1000, 0x1000, 16, 16, 0x0, 0x7, 0x7, 0, 0 //"Captrue Channel Mode"
0x1000, 0x1000, 16, 16, 0x0, 0x7, 0x7, 0, 0 //"Capture Channel Mode"
];
/* 上层下发参数后,写入音频相关信息的寄存器
......@@ -661,8 +661,8 @@ int32_t CodecDeviceInit(struct AudioCard *audioCard, struct CodecDevice *codec)
代码路径:drivers/peripheral/audio/chipsets/tfa9879/accessory
SmartPA归属于Accessory驱动的一种,开发步骤类似于codec:
1. 定义填充一个具体的accesory
2. 实现accesory回调函数
1. 定义填充一个具体的accessory
2. 实现accessory回调函数
3. 注册绑定到HDF框架
4. 配置HCS和Makefile。
......@@ -672,7 +672,7 @@ Accessory模块需要填充如下3个结构体:
- g_tfa9879Data :accessory设备操作函数集,其中包含HCS文件中的配置信息,且定义与映射了accessory设备的初始化、读写寄存器的方法函数。
- g_tfa9879DaiDeviceOps :accessory设备DAI的数据集,其中定义与映射了accessory设备的数据访问接口的驱动名、初始化和操作集。
- g_tfa9879DaiDeviceOps :accessory设备DAI的数据集,其中定义与映射了accessory设备DAI的操作集。
- g_tfa9879DaiData :accessory设备DAI的数据集,其中定义与映射了accessory设备的数据访问接口的驱动名、初始化和操作集。
......@@ -1406,4 +1406,4 @@ static void *hal_main()
# 总结<a name="section9999"></a>
以上就是基于Audo驱动框架进行移植开发过程中,所涉及的所有关键适配点。重点介绍了 Audio驱动适配方法、HDI层接口使用方法。开发者可以根据不同芯片进行适配,方便简单。希望通过本次的文档,您能初步掌握基于HDF框架的Audio驱动开发。
\ No newline at end of file
以上就是基于Audio驱动框架进行移植开发过程中,所涉及的所有关键适配点。重点介绍了 Audio驱动适配方法、HDI层接口使用方法。开发者可以根据不同芯片进行适配,方便简单。希望通过本次的文档,您能初步掌握基于HDF框架的Audio驱动开发。
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册