提交 4a654d9a 编写于 作者: Y yuyaozhi 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

### 1.0.0 (2022/03/09)
合并轻设备和富设备系统docker编译环境。
### 0.0.7 (2022/02/16)
增加安装doxygen工具。
......
### 1.0.0 (2022/03/09)
Combine the docker build environment of Mini-System Devices (reference memory ≥ 128 KB), Small-System Devices (reference memory ≥ 1 MB) and Standard-System Devices (reference memory ≥ 128 MB).
### 0.0.7 (2022/02/16)
Added the installation of doxygen.
### 0.0.6(2022/02/10)
### 0.0.6 (2022/02/10)
1\. Updated hb.
......
......@@ -12,80 +12,71 @@
# limitations under the License.
FROM ubuntu:20.04
MAINTAINER dongjinguang@huawei.com
FROM ubuntu:18.04
WORKDIR /home/openharmony
RUN apt-get update -y \
&& apt-get install curl wget -y \
&& apt-get install vim -y \
&& apt-get install ssh -y \
&& apt-get install git -y \
&& apt-get install python3.8 -y \
&& apt-get install python3-pip -y \
&& apt-get install dosfstools -y \
&& apt-get install mtools -y \
&& apt-get install scons -y \
&& apt-get install make -y \
&& apt-get install libffi-dev -y \
&& apt-get install zip -y \
&& apt-get install python3-distutils -y \
&& apt-get install binutils -y \
&& apt-get install mtd-utils -y \
&& apt-get install libc6-dev-x32 -y \
&& DEBIAN_FRONTEND="noninteractive" TZ="America/New_York" apt-get -y install tzdata \
&& apt-get install default-jre -y \
&& apt-get install default-jdk -y \
&& apt-get install bison -y \
&& apt-get install flex -y \
&& apt-get install bc -y \
&& apt-get install doxygen -y \
&& apt-get install u-boot-tools -y \
&& apt-get install gcc-arm-linux-gnueabi -y \
&& apt-get install build-essential \
&& apt-get install locales \
&& apt-get install ruby -y \
RUN sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list \
&& sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list \
&& apt-get update -y \
&& apt-get install -y apt-utils binutils bison flex bc build-essential make mtd-utils gcc-arm-linux-gnueabi u-boot-tools python3.8 python3-pip git zip unzip curl wget gcc g++ ruby=1:2.5.1 dosfstools mtools default-jre default-jdk scons python3.8-distutils perl openssl libssl-dev cpio git-lfs m4 ccache zlib1g-dev tar rsync liblz4-tool genext2fs binutils-dev device-tree-compiler e2fsprogs git-core gnupg gnutls-bin gperf lib32ncurses5-dev libffi-dev zlib* libelf-dev libx11-dev libgl1-mesa-dev lib32z1-dev xsltproc x11proto-core-dev libc6-dev-i386 libxml2-dev lib32z-dev libdwarf-dev \
&& apt-get install -y grsync xxd libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5 libncurses5-dev libncursesw5 libstdc++6 python2.7 gcc-arm-none-eabi \
&& apt-get install -y vim ssh locales \
&& apt-get install -y doxygen \
&& locale-gen "en_US.UTF-8" \
&& rm -rf /bin/sh /usr/bin/python /usr/bin/python3 \
&& rm -rf /bin/sh /usr/bin/python /usr/bin/python3 /usr/bin/python3m \
&& ln -s /bin/bash /bin/sh \
&& ln -s /usr/bin/python3.8 /usr/bin/python3 \
&& ln -s /usr/bin/python3.8 /usr/bin/python3m \
&& ln -s /usr/bin/python3.8 /usr/bin/python \
&& pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple setuptools \
&& pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple kconfiglib \
&& pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple pycryptodome \
&& pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple ecdsa \
&& pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple ohos-build \
&& curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/bin/repo \
&& chmod +x /usr/bin/repo \
&& pip3 install --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple requests setuptools pymongo kconfiglib pycryptodome ecdsa ohos-build pyyaml prompt_toolkit==1.0.14 redis json2html yagmail python-jenkins \
&& pip3 install esdk-obs-python --trusted-host pypi.org \
&& pip3 install six --upgrade --ignore-installed six \
&& mkdir -p /home/tools \
&& mkdir -p /home/tools/gn \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/compiler/clang/10.0.1-62608/linux/llvm.tar.gz \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/compiler/gn/1717/linux/gn-linux-x86-1717.tar.gz \
&& wget -P /home/tools https://mirrors.huaweicloud.com/nodejs/v12.20.0/node-v12.20.0-linux-x64.tar.gz \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/develop_tools/hmos_app_packing_tool.jar \
&& wget -P /home/tools https://repo.huaweicloud.com/harmonyos/develop_tools/hapsigntoolv2.jar \
&& tar xvf /home/tools/llvm.tar.gz -C /home/tools \
&& tar xvf /home/tools/hc-gen-0.65-linux.tar -C /home/tools \
&& tar xvf /home/tools/gcc_riscv32-linux-7.3.0.tar.gz -C /home/tools \
&& tar xvf /home/tools/ninja.1.9.0.tar -C /home/tools \
&& tar xvf /home/tools/gn-linux-x86-1717.tar.gz -C /home/tools \
&& tar xvf /home/tools/node-v12.20.0-linux-x64.tar.gz -C /home/tools \
&& wget -P /home/tools https://mirrors.huaweicloud.com/nodejs/v14.15.4/node-v14.15.4-linux-x64.tar.xz \
&& wget -P /home/tools https://hm-verify.obs.cn-north-4.myhuaweicloud.com/qemu-5.2.0.tar.xz \
&& tar -xvf /home/tools/llvm.tar.gz -C /home/tools \
&& tar -xvf /home/tools/hc-gen-0.65-linux.tar -C /home/tools \
&& tar -xvf /home/tools/gcc_riscv32-linux-7.3.0.tar.gz -C /home/tools \
&& tar -xvf /home/tools/ninja.1.9.0.tar -C /home/tools \
&& tar -xvf /home/tools/gn-linux-x86-1717.tar.gz -C /home/tools/gn \
&& tar -xJf /home/tools/node-v14.15.4-linux-x64.tar.xz -C /home/tools \
&& cp /home/tools/node-v14.15.4-linux-x64/bin/node /usr/local/bin \
&& ln -s /home/tools/node-v14.15.4-linux-x64/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s /home/tools/node-v14.15.4-linux-x64/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
&& tar -xJf /home/tools/qemu-5.2.0.tar.xz -C /home/tools \
&& sed -i '$aexport PATH=/home/tools/llvm/bin:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools/hc-gen:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools/gcc_riscv32/bin:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools/ninja:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools/node-v12.20.0-linux-x64/bin:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools/node-v14.15.4-linux-x64/bin:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/home/tools/gn:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH=/root/.local/bin:$PATH' /root/.bashrc \
&& export PATH=/home/tools/llvm/bin:$PATH \
&& export PATH=/home/tools/hc-gen:$PATH \
&& export PATH=/home/tools/gcc_riscv32/bin:$PATH \
&& export PATH=/home/tools/ninja:$PATH \
&& export PATH=/home/tools/node-v12.20.0-linux-x64/bin:$PATH \
&& export PATH=/home/tools:$PATH \
&& export PATH=/home/tools/gn:$PATH \
&& export PATH=/root/.local/bin:$PATH \
&& cd /home/tools/qemu-5.2.0 \
&& mkdir build \
&& cd build \
&& ../configure --target-list=arm-softmmu \
&& make -j \
&& make install \
&& cd /home/openharmony \
&& rm -rf /home/tools/*.tar \
&& rm -rf /home/tools/*.gz \
&& rm -rf /home/tools/*.xz \
&& rm -rf /home/tools/qemu-5.2.0 \
&& npm install -g @ohos/hpm-cli --registry https://mirrors.huaweicloud.com/repository/npm/
ENV LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8
......@@ -2,30 +2,29 @@
### Docker镜像简介
本文为小型和轻量系统类设备Docker使用指导,[点此查看](https://gitee.com/openharmony/docs/blob/master/docker/standard/Readme.md)标准系统类设备使用指导。
本文为OpenHarmony的Docker编译环境使用指导。
OpenHarmony的Docker镜像托管在**HuaweiCloud SWR**上,开发者可以通过该镜像在很大程度上简化编译前的环境配置。 目前容器化构建选项支持情况如下:
| Docker镜像仓库 | 标签 | 说明 |
| :----------------------------------------------------------- | :------ | :----------------------------------------------------------- |
| `swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker` | `0.0.7` | 已经预安装OpenHarmony版本的编译环境,支持轻量系统类设备(参考内存≥128KB)和小型系统类设备(参考内存≥1MB)的版本构建。 |
| Docker镜像仓库 | 标签 | 说明 |
| :----------------------------------------------------------- | :------ | :------------------------------------ |
| `swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker` | `1.0.0` | 已经预安装OpenHarmony版本的编译环境。 |
### 使用方式及步骤
开发者在配置好开发环境后,可以通过以下步骤来使用我们提供的Docker环境。详情请参见[Docker编译环境](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/gettools-acquire.md)
开发者在下载好源码后,可以通过以下步骤来使用我们提供的Docker环境。详情请参见[Docker编译环境](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/gettools-acquire.md)
1. 获取Docker镜像
```
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.7
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
```
2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境
```
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.7
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
```
3. 通过如下命令启动不同平台的编译
```
hb set #设置工作目录。
. #输入源码所在目录,点(.)表示当前目录。
在显示的页面中通过键盘上下键选择需要编译的平台,通过回车确定选择。
hb set #在显示的页面中通过键盘上下键选择需要编译的平台,通过回车确定选择。
hb build -f #执行编译。
```
......@@ -2,30 +2,28 @@
### Docker Image
This document provides guidance on building the Docker image for mini- and small-system devices. For details about how to build the Docker image for standard-system devices, see [OpenHarmony Docker Image](https://gitee.com/openharmony/docs/blob/master/docker/standard/Readme-en.md)
This document provides guidance on building the Docker image for mini- and small-system devices.
The Docker image of OpenHarmony is hosted on [HUAWEI Cloud SWR](https://auth.huaweicloud.com/authui/login.html?service=https%3A%2F%2Fconsole.huaweicloud.com%2Fswr%2F%3Fregion%3Dcn-south-1%26cloud_route_state%3D%2Fapp%2Fwarehouse%2FwarehouseMangeDetail%2Fgoldensir%2Fopenharmony-docker%2Fopenharmony-docker%3Ftype%3DownImage&locale=en-us#/login). Using the Docker image will help simplify environment configurations needed for the building. The following table lists container-based options needed for building in the standalone Docker environment.
| Docker Image Repository | Tag | Description |
| :----------------------------------------------------------- | :------ | :----------------------------------------------------------- |
| `swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker` | `0.0.7` | The OpenHarmony build environment has been pre-installed. This repository applies to Mini-System Devices (reference memory ≥ 128 KB) and Small-System Devices (reference memory ≥ 1 MB). |
| Docker Image Repository | Tag | Description |
| :----------------------------------------------------------- | :------ | :-------------------------------------------------------- |
| `swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker` | `1.0.0` | The OpenHarmony build environment has been pre-installed. |
### Usage
After configuring the development environments, perform the steps below to access the Docker environment.
After downloading the OpenHarmony code, perform the steps below to access the Docker environment.
1. Obtain the Docker image.
```
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.7
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
```
2. Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
```
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.7
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
```
3. Run the following script to start building for different platforms.
```
hb set # Set the working directory.
. # Enter the directory where the source code is stored. If the code is stored in the current directory, enter a period (.).
Press the Up or Down key to select the platform to build on, then press Enter.
hb set # Press the Up or Down key to select the platform to build on, then press Enter.
hb build -f # Start building.
```
......@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
docker build -t openharmony-docker:0.0.7 .
docker build -t openharmony-docker:1.0.0 .
### 0.0.8(2022/01/16)
新增安装doxygen。
### 0.0.7(2022/01/11)
新增安装genext2fs和liblz4-tool。
### 0.0.6(2022/01/04)
新增安装hb。
### 0.0.5(2021/10/28)
新增安装tar、binutils、git-lfs、gnutls-bin、python3.8、python3-pip、cpio。
### 0.0.4(2021/09/18)
1、删除编译依赖的工具预装。
2、增加安装ruby。
### 0.0.3(2021/08/30)
1、更新llvm版本从10.0.1-62608更新到10.0.1-69957。
2、增加安装gcc_aarch64。
### 0.0.2(2021/08/11)
新增安装llvm-10.0.1-62608和restool工具。
### 0.0.1(2021/06/02)
提供OpenHarmony 2.0版本docker编译环境,预装编译依赖工具。
### 0.0.8 (2022/01/16)
Added the installation of doxygen.
### 0.0.7 (2022/01/11)
Added the installation of genext2fs and liblz4-tool.
### 0.0.6 (2022/01/04)
Added the installation of hb.
### 0.0.5 (2021/10/28)
Added the installation of tar, binutils, git-lfs, gnutls-bin, python3.8, python3-pip, and cpio.
### 0.0.4 (2021/09/18)
1\. Removed pre-installed build dependency tools.
2\. Added the Ruby installation.
### 0.0.3 (2021/08/30)
1\. Updated LLVM from 10.0.1-62608 to 10.0.1-69957.
2\. Added the installation of gcc_aarch64.
### 0.0.2 (2021/08/11)
Added the installation of llvm-10.0.1-62608 and restool.
### 0.0.1 (2021/06/02)
Provided a Docker build environment for OpenHarmony 2.0 and pre-installed build dependency tools.
\ No newline at end of file
## Standalone Docker Environment
This document provides guidance on building the Docker image for standard-system devices. For details about how to build the Docker image for mini- and small-system devices, see [OpenHarmony Docker Image](https://gitee.com/openharmony/docs/blob/master/docker/README_en.md)
The Docker image of OpenHarmony is hosted on [HUAWEI Cloud SWR](https://auth.huaweicloud.com/authui/login.html?service=https%3A%2F%2Fconsole.huaweicloud.com%2Fswr%2F%3Fregion%3Dcn-south-1%26cloud_route_state%3D%2Fapp%2Fwarehouse%2FwarehouseMangeDetail%2Fgoldensir%2Fopenharmony-docker%2Fopenharmony-docker%3Ftype%3DownImage&locale=en-us#/login). Using the Docker image will help simplify environment configurations needed for the building. After configuring the development environments, perform the steps below to access the Docker environment. The following steps use Ubuntu as an example (Windows is also supported).
### Setting Up the Docker Environment for Standard-System Devices (reference memory ≥ 128 MB)
1. Obtain the Docker image.
```
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.8
```
2. Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
```
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.8
```
### Building for Standard-System Devices (reference memory ≥ 128 MB)
Run the following script to start building for Standard-System Devices (reference memory ≥ 128 MB)
```
./build.sh --product-name {product_name} --ccache
```
**{product_name}** indicates the platform supported by the current distribution, for example, Hi3516DV300, rk3568.
Files generated during compilation are stored in the **out/{device_name}/** directory, and the generated image is stored in the **out/{device_name}/packages/phone/images/** directory.
**Note**
You can exit Docker by simply running the **exit** command.
\ No newline at end of file
## 独立Docker环境
本文为标准系统类设备Docker使用指导,[点此查看](https://gitee.com/openharmony/docs/blob/master/docker/README.md)小型和轻量系统类设备使用指导。
OpenHarmony的Docker镜像托管在HuaweiCloud SWR上。开发者可以通过该镜像在很大程度上简化编译前的环境配置。开发者在配置好开发环境后,通过以下步骤来使用Docker环境。
### 搭建Docker环境-标准系统类设备(参考内存≥128MB)
1. 获取Docker镜像。
```
docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.8
```
2. 进入OpenHarmony代码根目录执行如下命令,从而进入Docker构建环境。
```
docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.8
```
### 编译源码-标准系统类设备(参考内存≥128MB)
通过如下编译脚本启动标准系统类设备(参考内存≥128MB)的编译。
```
./build.sh --product-name {product_name} --ccache
```
{product_name}为当前版本支持的平台。比如:Hi3516DV300、rk3568等。
编译所生成的文件都归档在out/{device_name}/目录下,结果镜像输出在 out/{device_name}/packages/phone/images/ 目录下。
**说明**
退出Docker执行exit命令即可。
\ No newline at end of file
#!/bin/bash
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
docker build -t openharmony-docker-standard:0.0.8 .
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM ubuntu:18.04
WORKDIR /home/openharmony
ARG DEBIAN_FRONTEND=noninteractive
ARG PREBUILTS_DIR=/home/prebuilts
ARG HOME_TOOLS=/home/tools
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
COPY sources.list /etc/apt
RUN apt-get update \
&& apt-get install -y \
apt-utils \
vim \
tar \
binutils \
software-properties-common \
openssh-server \
iputils-ping \
curl \
net-tools \
bsdmainutils \
kmod \
bc \
rsync \
gawk \
ssh \
ccache \
zip \
python-dev \
make \
m4 \
gcc-multilib \
ca-certificates-java \
unzip \
python3-yaml \
perl \
openssl \
libssl1.1 \
gnupg \
xsltproc \
x11proto-core-dev \
tcl \
python3-crypto \
python-yaml \
python-crypto \
libxml2-utils \
libxml2-dev \
libx11-dev \
libssl-dev \
libgl1-mesa-dev \
lib32z1-dev \
lib32ncurses5-dev \
g++-multilib \
flex \
bison \
doxygen \
git \
git-lfs \
subversion \
tofrodos \
pigz \
expect \
python3-xlrd \
python-xlrd \
wget \
git-core \
gperf \
build-essential \
zlib1g-dev \
libc6-dev-i386 \
lib32z-dev \
openjdk-8-jdk \
ruby \
gnutls-bin \
python3.8 \
python3-pip \
cpio \
genext2fs \
doxygen \
liblz4-tool \
&& rm -rf /bin/sh /usr/bin/python /usr/bin/python3 \
&& ln -s /bin/bash /bin/sh \
&& ln -s /usr/bin/python3.8 /usr/bin/python3 \
&& ln -s /usr/bin/python3.8 /usr/bin/python \
&& python3 -m pip install --user ohos-build \
&& mkdir -p $PREBUILTS_DIR/prebuilts $HOME_TOOLS
RUN wget -P $HOME_TOOLS https://mirrors.huaweicloud.com/nodejs/v12.18.4/node-v12.18.4-linux-x64.tar.gz \
&& wget -P $HOME_TOOLS https://mirrors.huaweicloud.com/nodejs/v12.18.4/node-v12.18.4-darwin-x64.tar.gz \
&& tar xvf $HOME_TOOLS/node-v12.18.4-linux-x64.tar.gz -C $PREBUILTS_DIR/prebuilts \
&& tar xvf $HOME_TOOLS/node-v12.18.4-darwin-x64.tar.gz -C $PREBUILTS_DIR/prebuilts \
&& sed -i '$aexport PATH='"$PREBUILTS_DIR"'/prebuilts/node-v12.18.4-linux-x64/bin:$PATH' /root/.bashrc \
&& sed -i '$aexport PATH='"$PREBUILTS_DIR"'/prebuilts/hc-gen:$PATH' /root/.bashrc \
&& export PATH=$PATH:$PREBUILTS_DIR/prebuilts/node-v12.18.4-linux-x64/bin \
&& export PATH=$PATH:$PREBUILTS_DIR/prebuilts/hc-gen \
&& rm -rf $HOME_TOOLS \
&& npm install -g @ohos/hpm-cli --registry https://registry.npm.taobao.org
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
deb http://mirrors.ustc.edu.cn/ubuntu/ bionic main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main multiverse restricted universe
\ No newline at end of file
......@@ -29,19 +29,19 @@
```javascript
export default {
onStart(want) {
console.log('SerivceAbility onStart');
console.log('ServiceAbility onStart');
},
onCommand(want, restart, startId) {
console.log('SerivceAbility onCommand');
console.log('ServiceAbility onCommand');
},
onConnect(want) {
console.log('SerivceAbility OnConnect');
console.log('ServiceAbility OnConnect');
},
onDisconnect() {
console.log('SerivceAbility OnDisConnect');
console.log('ServiceAbility OnDisConnect');
},
onStop() {
console.log('SerivceAbility onStop');
console.log('ServiceAbility onStop');
},
}
```
......@@ -170,17 +170,17 @@ export default {
mMyStub = new MyStub("ServiceAbility-test");
},
onCommand(want, restart, startId) {
console.log('SerivceAbility onCommand');
console.log('ServiceAbility onCommand');
},
onConnect(want) {
console.log('SerivceAbility OnConnect');
console.log('ServiceAbility OnConnect');
return mMyStub;
},
onDisconnect() {
console.log('SerivceAbility OnDisConnect');
console.log('ServiceAbility OnDisConnect');
},
onStop() {
console.log('SerivceAbility onStop');
console.log('ServiceAbility onStop');
},
}
```
......@@ -252,17 +252,17 @@ export default {
mMyStub = new MyStub("ServiceAbility-test");
},
onCommand(want, restart, startId) {
console.log('SerivceAbility onCommand');
console.log('ServiceAbility onCommand');
},
onConnect(want) {
console.log('SerivceAbility OnConnect');
console.log('ServiceAbility OnConnect');
return mMyStub;
},
onDisconnect() {
console.log('SerivceAbility OnDisConnect');
console.log('ServiceAbility OnDisConnect');
},
onStop() {
console.log('SerivceAbility onStop');
console.log('ServiceAbility onStop');
},
}
```
# Audio Overview<a name="EN-US_TOPIC_0000001147055469"></a>
OpenHarmony provides the audio module for your application to implement audio-related features, including audio playback and volume management.
You can use APIs provided by the audio module to implement audio-related features, including audio playback and volume management.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>![](../public_sys-resources/icon-note.gif) **NOTE**
>Due to permission issues, the above features are temporarily unavailable for the standard system.
## Basic Concepts<a name="section296512102281"></a>
......
......@@ -25,12 +25,16 @@ Obtains the local root directory of the application. This method uses a callback
If this method is called for the first time, a root directory is created.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | Yes| Callback used to return the local root directory of the application.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the local root directory of the application.|
**Example**
......@@ -52,9 +56,13 @@ Obtains the local root directory of the application. This method uses a promise
If this method is called for the first time, a root directory is created.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| ---------------- | ---------------------- |
| Promise\<string> | Promise used to return the local root directory of the application.|
......@@ -76,14 +84,18 @@ verifyPermission(permission: string, options: PermissionOptions, callback: Async
Verifies whether a specific PID and UID have the given permission. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ------------------------------------- |
| permission | string | Yes| Name of the permission to verify.|
| options | [PermissionOptions](#permissionoptions) | Yes| Permission options.|
| callback | AsyncCallback\<number> | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
| permission | string | Yes | Name of the permission to verify. |
| options | [PermissionOptions](#permissionoptions) | Yes | Permission options. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
**Example**
......@@ -107,10 +119,10 @@ Verifies whether the current PID and UID have the given permission. This method
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | ------------------------------------- |
| permission | string | Yes| Name of the permission to verify.|
| callback | AsyncCallback\<number> | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
| permission | string | Yes | Name of the permission to verify. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
**Example**
......@@ -126,17 +138,21 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
Verifies whether a specific PID and UID have the given permission. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- |
| permission | string | Yes| Name of the permission to verify.|
| options | [PermissionOptions](#permissionoptions) | No| Permission options.|
| permission | string | Yes | Name of the permission to verify.|
| options | [PermissionOptions](#permissionoptions) | No | Permission options. |
**Return value**
| Type| Description|
| Type | Description |
| ---------------- | ----------------------------------------------------------- |
| Promise\<number> | Promise used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
......@@ -160,14 +176,18 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res
Requests certain permissions from the system. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- |
| permissions | Array\<string> | Yes| Permissions to request. This parameter cannot be **null**.|
| requestCode | number | Yes| Request code to be passed to **PermissionRequestResult**.|
| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes| Permission request result.|
| permissions | Array\<string> | Yes | Permissions to request. This parameter cannot be **null**. |
| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.|
| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Permission request result. |
**Example**
```js
......@@ -194,11 +214,15 @@ getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>)
Obtains information about the current application. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<ApplicationInfo> | Yes| Callback used to return the application information.|
| callback | AsyncCallback\<ApplicationInfo> | Yes | Callback used to return the application information.|
**Example**
......@@ -216,9 +240,13 @@ getApplicationInfo(): Promise\<ApplicationInfo>
Obtains information about the current application. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| ------------------------- | ------------------ |
| Promise\<ApplicationInfo> | Promise used to return the application information.|
......@@ -241,11 +269,15 @@ getBundleName(callback: AsyncCallback\<string>): void
Obtains the bundle name of the current ability. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ----------------------------- |
| callback | AsyncCallback\<string> | Yes| Callback used to return the bundle name.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
**Example**
......@@ -263,9 +295,13 @@ getBundleName(): Promise\<string>
Obtains the bundle name of the current ability. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| ---------------- | ------------------------- |
| Promise\<string> | Promise used to return the bundle name.|
......@@ -288,11 +324,15 @@ getProcessInfo(callback: AsyncCallback\<ProcessInfo>)
Obtains information about the current process, including the PID and process name. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------- |
| callback | AsyncCallback\<ProcessInfo> | Yes| Callback used to return the process information.|
| callback | AsyncCallback\<ProcessInfo> | Yes | Callback used to return the process information.|
**Example**
......@@ -310,9 +350,13 @@ getProcessInfo(): Promise\<ProcessInfo>
Obtains information about the current process, including the PID and process name. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| --------------------- | -------------- |
| Promise\<ProcessInfo> | Promise used to return the process information.|
......@@ -337,11 +381,15 @@ Obtains the **ohos.bundle.ElementName** object of the current ability. This meth
This method is available only to Page abilities.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback\<ElementName> | Yes| Callback used to return the **ohos.bundle.ElementName** object.|
| callback | AsyncCallback\<ElementName> | Yes | Callback used to return the **ohos.bundle.ElementName** object.|
**Example**
......@@ -361,9 +409,13 @@ Obtains the **ohos.bundle.ElementName** object of the current ability. This meth
This method is available only to Page abilities.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| --------------------- | ------------------------------------------ |
| Promise\<ElementName> | Promise used to return the **ohos.bundle.ElementName** object.|
......@@ -384,9 +436,13 @@ getProcessName(callback: AsyncCallback\<string>): void
Obtains the name of the current process. This method uses a callback to return the result.
| Name| Type| Mandatory| Description|
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | Yes| Callback used to return the process name.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the process name.|
**Example**
......@@ -404,9 +460,13 @@ getProcessName(): Promise\<string>
Obtains the name of the current process. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| ---------------- | -------------------- |
| Promise\<string> | Promise used to return the process name.|
......@@ -429,11 +489,15 @@ getCallingBundle(callback: AsyncCallback\<string>): void
Obtains the bundle name of the calling ability. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback\<string> | Yes| Callback used to return the bundle name.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
**Example**
......@@ -451,9 +515,13 @@ getCallingBundle(): Promise\<string>
Obtains the bundle name of the calling ability. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| Type | Description |
| --------------- | ------------------------- |
| Promise\<string> | Promise used to return the bundle name.|
......@@ -470,15 +538,15 @@ context.getCallingBundle().then((data) => {
## PermissionOptions
| Name| Readable/Writable| Type| Mandatory| Description|
| Name| Readable/Writable| Type | Mandatory| Description |
| ---- | -------- | ------ | ---- | ------ |
| pid | Read-only| number | No| PID.|
| uid | Read-only| number | No| UID.|
| pid | Read-only | number | No | PID.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| uid | Read-only | number | No | UID.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
## PermissionRequestResult
| Name| Readable/Writable| Type| Mandatory| Description|
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------- | ---- | ------------------ |
| requestCode | Read-only| number | Yes| Request code passed.|
| permissions | Read-only| Array\<string> | Yes| Permissions passed.|
| authResults | Read-only| Array\<number> | Yes| Permission request result.|
| requestCode | Read-only | number | Yes | Request code passed.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| permissions | Read-only | Array\<string> | Yes | Permissions passed.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core |
| authResults | Read-only | Array\<number> | Yes | Permission request result.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core |
# AbilityContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements the ability context. This module is inherited from **Context**.
## Usage
Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.
```
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let context = this.context;
}
}
```
## Attributes
| Name| Type| Readable| Writable| Description|
......@@ -21,6 +38,10 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......@@ -42,14 +63,53 @@ Starts an ability. This method uses a callback to return the result.
## startAbility
startAbility(want: Want): Promise&lt;void&gt;;
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility"
};
var options = {
windowMode: 0,
};
this.context.startAbility(want, options, (error) => {
console.log("error.code = " + error.code)
})
```
## startAbility
startAbility(want: Want, options: StartOptions): Promise&lt;void&gt;;
Starts an ability. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
- Return value
| Type| Description|
......@@ -63,7 +123,10 @@ Starts an ability. This method uses a promise to return the result.
"bundleName": "com.extreme.test",
"abilityName": "com.extreme.test.MainAbility"
};
this.context.startAbility(want)
var options = {
windowMode: 0,
};
this.context.startAbility(want, options)
.then((data) => {
console.log('Operation successful.')
}).catch((error) => {
......@@ -78,11 +141,15 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
Starts an ability. This method uses a callback to return the execution result when the ability is terminated.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | Callback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example
......@@ -96,17 +163,55 @@ Starts an ability. This method uses a callback to return the execution result wh
);
```
## startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example
```
var options = {
windowMode: 0,
};
this.context.startAbilityForResult(
{bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options,
(error, result) => {
console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
}
);
```
## startAbilityForResult
startAbilityForResult(want: Want): Promise&lt;AbilityResult&gt;;
startAbilityForResult(want: Want, options: StartOptions): Promise&lt;AbilityResult&gt;;
Starts an ability. This method uses a promise to return the execution result when the ability is terminated.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
- Return value
| Type| Description|
......@@ -115,7 +220,10 @@ Starts an ability. This method uses a promise to return the execution result whe
- Example
```
this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}).then((result) => {
var options = {
windowMode: 0,
};
this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options).then((result) => {
console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode)
}, (error) => {
console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code)
......@@ -129,16 +237,20 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | No| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
- Example
```
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err);
}
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
......@@ -148,6 +260,10 @@ terminateSelf(): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Return value
| Type| Description|
| -------- | -------- |
......@@ -157,7 +273,7 @@ Terminates this ability. This method uses a promise to return the result.
```
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
......@@ -169,11 +285,15 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi
Terminates this ability. This method uses a callback to return the information to the caller of **startAbilityForResult**.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | Callback&lt;void&gt; | No| Callback used to return the information.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
......@@ -194,6 +314,10 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return information to the caller of **startAbilityForResult**.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......@@ -215,3 +339,157 @@ Terminates this ability. This method uses a promise to return information to the
}
)
```
## startAbilityByCall
startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;&gt; | Promise used to return the caller object to communicate with.|
- Example
```
import Ability from '@ohos.application.Ability';
var caller;
export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "com.example.myservice.MainAbility",
deviceId: ""
}).then((obj) => {
caller = obj;
console.log('Caller GetCaller Get ' + call);
}).catch((e) => {
console.log('Caller GetCaller error ' + e);
});
}
}
```
## requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;
Requests permissions from the user by displaying a pop-up window. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
- Example
```
this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
});
```
## requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;
Requests permissions from the user by displaying a pop-up window. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the method is successfully called.|
- Example
```
this.context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
## setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
Sets the label of the ability displayed in the task. This method uses a callback to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
- Example
```
this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
});
```
## setMissionLabel
setMissionLabel(label: string): Promise&lt;void&gt;
Sets the label of the ability displayed in the task. This method uses a promise to return the result.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
- Example
```
this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
# Linear Container ArrayList
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import ArrayList from '@ohos.util.ArrayList'
```
## System Capabilities
SystemCapability.Utils.Lang
## ArrayList
### Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Number of entries in an array list (called container later).|
### constructor
constructor()
A constructor used to create an **ArrayList** instance.
**Example**
```
let arrayList = new ArrayList();
```
### add
add(element: T): boolean
Adds an entry at the end of this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to add.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the entry is added successfully; returns **false** otherwise.|
**Example**
```
let arrayList = new ArrayList();
let result = arrayList.add("a");
let result1 = arrayList.add(1);
let b = [1, 2, 3];
let result2 = arrayList.add(b);
let c = {name: "lala", age: "13"};
let result3 = arrayList.add(false);
```
### insert
insert(element: T, index: number): void
Inserts an entry at the specified position in this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to insert.|
| index | number | Yes| Index of the position where the entry is to be inserted.|
**Example**
```
let arrayList = new ArrayList();
arrayList.insert("A", 0);
arrayList.insert(0, 1);
arrayList.insert(true, 2);
```
### has
has(element: T): boolean
Checks whether this container has the specified entry.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the specified entry is contained; returns **false** otherwise.|
**Example**
```
let arrayList = new ArrayList();
let result = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
arrayList.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
let result1 = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
```
### getIndexOf
getIndexOf(element: T): number
Obtains the index of the first occurrence of the specified entry in this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to query.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns the position index if obtained; returns **-1** if the specified entry is not found.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(2);
arrayList.add(1);
arrayList.add(2);
arrayList.add(4);
let result = arrayList.getIndexOf(2);
```
### getLastIndexOf
getLastIndexOf(element: T): number
Obtains the index of the last occurrence of the specified entry in this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to query.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns the position index if obtained; returns **-1** if the specified entry is not found.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(2);
arrayList.add(1);
arrayList.add(2);
arrayList.add(4);
let result = arrayList.getLastIndexOf(2);
```
### removeByIndex
removeByIndex(index: number): T
Removes an entry with the specified position from this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the entry to remove.|
**Return value**
| Type| Description|
| -------- | -------- |
| T | Entry removed.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(2);
arrayList.add(4);
let result = arrayList.removeByIndex(2);
```
### remove
remove(element: T): boolean
Removes the first occurrence of the specified entry from this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to remove.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the entry is removed successfully; returns **false** otherwise.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result = arrayList.remove(2);
```
### removeByRange
removeByRange(fromIndex: number, toIndex: number): void
Removes from this container all of the entries within a range, including the entry at the start position but not that at the end position.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fromIndex | number | Yes| Index of the start position.|
| toIndex | number | Yes| Index of the end position.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.removeByRange(2, 4);
arrayList.removeByRange(4, 3);
arrayList.removeByRange(2, 6);
```
### replaceAllElements
replaceAllElements(callbackfn: (value: T, index?: number, arrlist?: ArrayList&lt;T&gt;) => T,
thisArg?: Object): void
Replaces all entries in this container with new entries, and returns the new ones.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackfn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Value of the entry that is currently traversed.|
| index | number | No| Position index of the entry that is currently traversed.|
| arrlist | ArrayList&lt;T&gt; | No| Instance that invokes the **replaceAllElements** method.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.replaceAllElements((value, index) => {
return value = 2 * value;
});
arrayList.replaceAllElements((value, index) => {
return value = value - 2;
});
```
### forEach
forEach(callbackfn: (value: T, index?: number, arrlist?: ArrayList&lt;T&gt;) => void,
thisArg?: Object): void
Uses a callback to traverse the entries in this container and obtain their position indexes.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackfn | function | Yes| Callback invoked to traverse the entries in the container.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Value of the entry that is currently traversed.|
| index | number | No| Position index of the entry that is currently traversed.|
| arrlist | ArrayList&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.forEach((value, index) => {
console.log(value, index);
});
```
### sort
sort(comparator?: (firstValue: T, secondValue: T) => number): void
Sorts entries in this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| comparator | function | No| Callback invoked for sorting.|
comparator
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| firstValue | T | Yes| Previous entry.|
| secondValue | T | Yes| Next entry.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.sort(a, (b => a - b));
arrayList.sort(a, (b => b - a));
arrayList.sort();
```
### subArrayList
subArrayList(fromIndex: number, toIndex: number): ArrayList&lt;T&gt;
Obtains entries within a range in this container, including the entry at the start position but not that at the end position, and returns these entries as a new **ArrayList** instance.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fromIndex | number | Yes| Index of the start position.|
| toIndex | number | Yes| Index of the end position.|
**Return value**
| Type| Description|
| -------- | -------- |
| ArrayList&lt;T&gt; | New **ArrayList** instance obtained.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result1 = arrayList.subArrayList(2, 4);
let result2 = arrayList.subArrayList(4, 3);
let result3 = arrayList.subArrayList(2, 6);
```
### clear
clear(): void
Clears this container and sets its length to **0**.
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.clear();
```
### clone
clone(): ArrayList&lt;T&gt;
Clones this container and returns a copy. The modification to the copy does not affect the original instance.
**Return value**
| Type| Description|
| -------- | -------- |
| ArrayList&lt;T&gt; | New **ArrayList** instance obtained.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result = arrayList.clone();
```
### getCapacity
getCapacity(): number
Obtains the capacity of this container.
**Return value**
| Type| Description|
| -------- | -------- |
| number | Capacity obtained.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result = arrayList.getCapacity();
```
### convertToArray
convertToArray(): Array&lt;T&gt;
Converts this container into an array.
**Return value**
| Type| Description|
| -------- | -------- |
| Array&lt;T&gt; | Array obtained.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result = arrayList.convertToArray();
```
### isEmpty
isEmpty(): boolean
Checks whether this container is empty (contains no entry).
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
let result = arrayList.isEmpty();
```
### increaseCapacityTo
increaseCapacityTo(newCapacity: number): void
Increases the capacity of this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.increaseCapacityTo(2);
arrayList.increaseCapacityTo(8);
```
### trimToCurrentLength
trimToCurrentLength(): void
Trims the capacity of this container to its current length.
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.trimToCurrentLength();
```
### [Symbol.iterator]
[Symbol.iterator]\(): IterableIterator&lt;T&gt;
Obtains an iterator, each item of which is a JavaScript object.
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.|
**Example**
```
let arrayList = new ArrayList();
arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
// Method 1:
for (let item of arrayList) {
console.log(item);
}
// Method 2:
let iter = arrayList[Symbol.iterator]();
let temp = iter.next().value;
while(temp != undefined) {
console.log(temp);
temp = iter.next().value;
}
```
# Audio
This module provides the following functions: audio management, audio rendering and system sound management.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
......@@ -284,8 +285,18 @@ Enumerates audio device types.
</tbody>
</table>
## ActiveDeviceType
## AudioRingMode<sup>7+</sup><a name="section14948916131018"></a>
Enumerates the active device types.
| Name | Default Value | Default Value |
| ------------- | ------ | ------------------------------------------------------------ |
| SPEAKER | 2 | Speaker.<br/>**System capabilities:** SystemCapability.Multimedia.Audio.Device |
| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO link.<br/>**System capabilities:** SystemCapability.Multimedia.Audio.Device |
## AudioRingMode
Enumerates ringer modes.
......@@ -1028,7 +1039,7 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data)=>
## audioManager.mute
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void\>\): void<sup>7+</sup><a name="section13516136134613"></a>
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void\>\): void
Mutes a stream. This method uses an asynchronous callback to return the result.
......@@ -1096,7 +1107,7 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
## audioManager.mute
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise<void\><sup>7+</sup><a name="section7519036144616"></a>
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise<void\>
Mutes a stream. This method uses a promise to return the result.
......@@ -1164,7 +1175,7 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() =>
## audioManager.isMute
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void<sup>7+</sup><a name="section10684183819585"></a>
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void
Checks whether a stream is muted. This method uses an asynchronous callback to return the query result.
......@@ -1223,7 +1234,7 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
## audioManager.isMute
isMute\(volumeType: AudioVolumeType\): Promise<boolean\><sup>7+</sup><a name="section6920211145610"></a>
isMute\(volumeType: AudioVolumeType\): Promise<boolean\>
Checks whether a stream is muted. This method uses a promise to return the result.
......@@ -1282,7 +1293,7 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) =>
## audioManager.isActive
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void<sup>7+</sup><a name="section380012544121"></a>
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\)
Checks whether a stream is active. This method uses an asynchronous callback to return the query result.
......@@ -1341,7 +1352,7 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
## audioManager.isActive
isActive\(volumeType: AudioVolumeType\): Promise<boolean\><sup>7+</sup><a name="section1880315481216"></a>
isActive\(volumeType: AudioVolumeType\): Promise<boolean\>
Checks whether a stream is active. This method uses a promise to return the query result.
......@@ -1400,7 +1411,7 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) =>
## audioManager.setRingerMode
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback<void\>\): void<sup>7+</sup><a name="section18572131483613"></a>
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback<void\>\): void
Sets the ringer mode. This method uses an asynchronous callback to return the result.
......@@ -1459,7 +1470,7 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
## audioManager.setRingerMode
setRingerMode\(mode: AudioRingMode\): Promise<void\><sup>7+</sup><a name="section55741914143615"></a>
setRingerMode\(mode: AudioRingMode\): Promise<void\>
Sets the ringer mode. This method uses a promise to return the result.
......@@ -1518,7 +1529,7 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() =>
## audioManager.getRingerMode
getRingerMode\(callback: AsyncCallback<AudioRingMode\>\): void<sup>7+</sup><a name="section149044108162"></a>
getRingerMode\(callback: AsyncCallback<AudioRingMode\>\): void
Obtains the ringer mode. This method uses an asynchronous callback to return the query result.
......@@ -1568,7 +1579,7 @@ audioManager.getRingerMode((err, value) => {
## audioManager.getRingerMode
getRingerMode\(\): Promise<AudioRingMode\><sup>7+</sup><a name="section13908210101620"></a>
getRingerMode\(\): Promise<AudioRingMode\>
Obtains the ringer mode. This method uses a promise to return the query result.
......@@ -1606,7 +1617,7 @@ audioManager.getRingerMode().then((value) =>
## audioManager.setAudioParameter
setAudioParameter\(key: string, value: string, callback: AsyncCallback<void\>\): void<sup>7+</sup><a name="section1691957174818"></a>
setAudioParameter\(key: string, value: string, callback: AsyncCallback<void\>\): void
Sets an audio parameter. This method uses an asynchronous callback to return the result.
......@@ -1674,7 +1685,7 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
## audioManager.setAudioParameter
setAudioParameter\(key: string, value: string\): Promise<void\><sup>7+</sup><a name="section18121057174820"></a>
setAudioParameter\(key: string, value: string\): Promise<void\>
Sets an audio parameter. This method uses a promise to return the result.
......@@ -1742,7 +1753,7 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() =>
## audioManager.getAudioParameter
getAudioParameter\(key: string, callback: AsyncCallback<string\>\): void<sup>7+</sup><a name="section1415145714812"></a>
getAudioParameter\(key: string, callback: AsyncCallback<string\>\)
Obtains the value of an audio parameter. This method uses an asynchronous callback to return the query result.
......@@ -1801,7 +1812,7 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => {
## audioManager.getAudioParameter
getAudioParameter\(key: string\): Promise<string\><sup>7+</sup><a name="section3185577485"></a>
getAudioParameter\(key: string\): Promise<string\>
Obtains the value of an audio parameter. This method uses a promise to return the query result.
......@@ -1979,7 +1990,7 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data)=>
## audioManager.setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void\>\): void<sup>7+</sup><a name="section103558400222"></a>
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void\>\): void
Sets a device to the active state. This method uses an asynchronous callback to return the result.
......@@ -2048,7 +2059,7 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err)=> {
## audioManager.setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise<void\><sup>7+</sup><a name="section1235914401228"></a>
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise<void\>
Sets a device to the active state. This method uses a promise to return the result.
......@@ -2116,7 +2127,7 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(()=>
## audioManager.isDeviceActive
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback<boolean\>\): void<sup>7+</sup><a name="section12363240122219"></a>
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback<boolean\>\): void
Checks whether a device is active. This method uses an asynchronous callback to return the query result.
......@@ -2175,7 +2186,7 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
## audioManager.isDeviceActive
isDeviceActive\(deviceType: DeviceType\): Promise<boolean\><sup>7+</sup><a name="section18366184012213"></a>
isDeviceActive\(deviceType: DeviceType\): Promise<boolean\>
Checks whether a device is active. This method uses a promise to return the query result.
......@@ -2234,7 +2245,7 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) =>
## audioManager.setMicrophoneMute
setMicrophoneMute\(mute: boolean, callback: AsyncCallback<void\>\): void<sup>7+</sup><a name="section14703163618122"></a>
setMicrophoneMute\(mute: boolean, callback: AsyncCallback<void\>\): void
Mutes or unmutes the microphone. This method uses an asynchronous callback to return the result.
......@@ -2293,7 +2304,7 @@ audioManager.setMicrophoneMute(true, (err) => {
## audioManager.setMicrophoneMute
setMicrophoneMute\(mute: boolean\): Promise<void\><sup>7+</sup><a name="section56287111791"></a>
setMicrophoneMute\(mute: boolean\): Promise<void\>
Mutes or unmutes the microphone. This method uses a promise to return the result.
......@@ -2352,7 +2363,7 @@ audioManager.setMicrophoneMute(true).then(() =>
## audioManager.isMicrophoneMute
isMicrophoneMute\(callback: AsyncCallback<boolean\>\): void<sup>7+</sup><a name="section6632141119912"></a>
isMicrophoneMute\(callback: AsyncCallback<boolean\>\): void
Checks whether the microphone is muted. This method uses an asynchronous callback to return the query result.
......@@ -2402,7 +2413,7 @@ audioManager.isMicrophoneMute((err, value) => {
## audioManager.isMicrophoneMute
isMicrophoneMute\(\): Promise<boolean\><sup>7+</sup><a name="section196363111918"></a>
isMicrophoneMute\(\): Promise<boolean\>
Checks whether the microphone is muted. This method uses a promise to return the query result.
......@@ -4121,3 +4132,20 @@ None
```
await ringtonePlayer.release();
```
## AudioDeviceDescriptor
Describes an audio device.
| Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.<br/>**System capabilities:** SystemCapability.Multimedia.Audio.Device |
| deviceType | [DeviceType](#devicetype) | Yes | No | Device type.<br/>**System capabilities:** SystemCapability.Multimedia.Audio.Device |
## AudioDeviceDescriptors
| Name | Description |
| -------- | -------- |
| AudioDeviceDescriptors | Array of **AudioDeviceDescriptor** objects. It is read-only.<br/>**System capabilities:** SystemCapability.Multimedia.Audio.Device |
\ No newline at end of file
......@@ -17,7 +17,9 @@ dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
Initiates a call. This function uses an asynchronous callback to return the execution result.
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
**Required permission**: ohos.permission.PLACE\_CALL (a system permission)
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
......@@ -41,7 +43,9 @@ dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean
Initiates a call. You can set call options as needed. This function uses an asynchronous callback to return the execution result.
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
**Required permission**: ohos.permission.PLACE\_CALL (a system permission)
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
......@@ -68,7 +72,9 @@ dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\>
Initiates a call. You can set call options as needed. This function uses a promise to return the execution result.
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
**Required permission**: ohos.permission.PLACE\_CALL (a system permission)
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
......@@ -102,6 +108,8 @@ hasCall\(callback: AsyncCallback<boolean\>\): void
Checks whether a call is in progress. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -123,6 +131,8 @@ hasCall\(\): Promise<boolean\>
Checks whether a call is in progress. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Return value**
| Type| Description|
......@@ -147,6 +157,8 @@ getCallState\(callback: AsyncCallback<CallState\>\): void
Obtains the call status. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -168,6 +180,8 @@ getCallState\(\): Promise<CallState\>
Obtains the call status. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Return value**
| Type| Description|
......@@ -191,6 +205,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\)
Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -213,6 +229,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, ca
Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -236,6 +254,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\):
Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -266,6 +286,8 @@ formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void
Formats a phone number based on the specified ISO country code. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -288,6 +310,8 @@ formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback:
Formats a phone number based on specified formatting options. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -313,6 +337,8 @@ formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise
Formats a phone number based on specified formatting options. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -349,6 +375,8 @@ The phone number must match the specified country code. For example, for a China
All country codes are supported.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -378,6 +406,8 @@ The phone number must match the specified country code. For example, for a China
All country codes are supported.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name| Type| Mandatory| Description|
......@@ -407,30 +437,40 @@ promise.then(data => {
## DialOptions<a name=DialOptions></a>
Provides an option for determining whether a call is a video call.
| Parameter| Type| Mandatory| Description|
**System capability**: SystemCapability.Telephony.CallManager
| Name| Type| Mandatory| Description|
| ------ | ------- | ---- | ------------------------------------------------------------ |
| extras | boolean | No| Indication of a video call. The options are as follows: <br/> - **true**: video call <br/> - **false**: voice call|
## CallState<a name=CallState></a>
Enumerates call states.
| Variable| Value| Description|
| ------------------ | ---- | ------------------------------------------------------------ |
| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.|
| CALL_STATE_IDLE | 0 | No call is in progress.|
| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.|
| CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.|
| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown. <br />**System capability**: SystemCapability.Telephony.CallManager|
| CALL_STATE_IDLE | 0 | No call is in progress. <br />**System capability**: SystemCapability.Telephony.CallManager|
| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state. <br />**System capability**: SystemCapability.Telephony.CallManager|
| CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting. <br />**System capability**: SystemCapability.Telephony.CallManager|
## EmergencyNumberOptions<sup>7+</sup><a name=EmergencyNumberOptions></a>
Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot.
| Parameter| Type| Mandatory| Description|
**System capability**: SystemCapability.Telephony.CallManager
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ------------------------------------------ |
| slotId | number | No| SIM card slot ID.<br/> - **0**: slot 1 <br/> - **1**: slot 2|
## NumberFormatOptions<sup>7+</sup><a name=NumberFormatOptions></a>
Provides an option for number formatting.
| Parameter| Type| Mandatory| Description|
**System capability**: SystemCapability.Telephony.CallManager
| Name| Type| Mandatory| Description|
| ----------- | ------ | ---- | ---------------------------------------------------------- |
| countryCode | string | No| Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.|
# Camera<a name="EN-US_TOPIC_0000001149807881"></a>
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
......
......@@ -169,9 +169,9 @@ Publishes a common event with given attributes. This method uses a callback to r
```js
// Attributes of a common event.
var options = {
code: 0; // Result code of the common event
data: "initial data";// Result data of the common event
isOrdered: true; // The common event is an ordered one.
code: 0, // Result code of the common event
data: "initial data",// Result data of the common event
isOrdered: true // The common event is an ordered one.
}
// Callback for common event publication
function PublishCallBack(err) {
......
# Linear Container Deque
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import Deque from '@ohos.util.Deque'
```
## System Capabilities
SystemCapability.Utils.Lang
## Deque
### Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Number of entries in a double-ended queue (deque, called container later).|
### constructor
constructor()
A constructor used to create a **Deque** instance.
**Example**
```
let deque = new Deque();
```
### insertFront
insertFront(element: T): void
Inserts an entry at the front of this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to insert.|
**Example**
```
let deque = new Deque;
deque.insertFront("a");
deque.insertFront(1);
let b = [1, 2, 3];
deque.insertFront(b);
let c = {name : "lala", age : "13"};
deque.insertFront(false);
```
### insertEnd
insertEnd(element: T): void
Inserts an entry at the end of this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to insert.|
**Example**
```
let deque = new Deque;
deque.insertEnd("a");
deque.insertEnd(1);
let b = [1, 2, 3];
deque.insertEnd(b);
let c = {name : "lala", age : "13"};
deque.insertEnd(false);
```
### has
has(element: T): boolean
Checks whether this container has the specified entry.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| element | T | Yes| Entry to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the specified entry is contained; returns **false** otherwise.|
**Example**
```
let deque = new Deque();
let result = deque.has("Ahfbrgrbgnutfodgorrogorg");
deque.insertFront("Ahfbrgrbgnutfodgorrogorg");
let result1 = deque.has("Ahfbrgrbgnutfodgorrogorg");
```
### popFirst
popFirst(): T
Removes the first entry of this container.
**Return value**
| Type| Description|
| -------- | -------- |
| T | Entry removed.|
**Example**
```
let deque = new Deque();
deque.insertFront(2);
deque.insertFront(4);
deque.insertEnd(5);
deque.insertFront(2);
deque.insertFront(4);
let result = deque.popFirst();
```
### popLast
popLast(): T
Removes the last entry of this container.
**Return value**
| Type| Description|
| -------- | -------- |
| T | Entry removed.|
**Example**
```
let deque = new Deque();
deque.insertFront(2);
deque.insertEnd(4);
deque.insertFront(5);
deque.insertFront(2);
deque.insertFront(4);
deque.popLast();
let result = deque.popLast();
```
### forEach
forEach(callbackfn: (value: T, index?: number, deque?: Deque&lt;T&gt;) => void,
thisArg?: Object): void
Uses a callback to traverse the entries in this container and obtain their position indexes.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackfn | function | Yes| Callback invoked to traverse the entries in the container.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Value of the element that is currently traversed.|
| index | number | No| Position index of the entry that is currently traversed.|
| deque | Deque&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Example**
```
let deque = new Deque();
deque.insertFront(2);
deque.insertEnd(4);
deque.insertFront(5);
deque.insertEnd(4);
deque.forEach((value, index) => {
console.log(value, index);
});
```
### getFirst
getFirst(): T;
Obtains the first entry of this container.
**Return value**
| Type| Description|
| -------- | -------- |
| T | Entry obtained.|
**Example**
```
let deque = new Deque();
deque.insertEnd(2);
deque.insertEnd(4);
deque.insertFront(5);
deque.insertFront(4);
let result = deque.getFirst();
```
### getLast
getLast(): T
Obtains the last entry of this container.
**Return value**
| Type| Description|
| -------- | -------- |
| T | Entry obtained.|
**Example**
```
let deque = new Deque();
deque.insertFront(2);
deque.insertFront(4);
deque.insertFront(5);
deque.insertFront(4);
let result = deque.getLast();
```
### [Symbol.iterator]
[Symbol.iterator]\(): IterableIterator&lt;T&gt;
Obtains an iterator, each item of which is a JavaScript object.
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.|
**Example**
```
let deque = new Deque();
deque.insertFront(2);
deque.insertFront(4);
deque.insertFront(5);
deque.insertFront(4);
// Method 1:
for (let item of deque) {
console.log(item);
}
// Method 2:
let iter = deque[Symbol.iterator]();
let temp = iter.next().value;
while(temp != undefined) {
console.log(temp);
temp = iter.next().value;
}
```
......@@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
此差异已折叠。
......@@ -107,7 +107,7 @@ Obtains the size of the shared dirty memory of this process.
- **Example**
```
let sharedDirty = hidebug.getSharedDirty());
let sharedDirty = hidebug.getSharedDirty();
```
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -32,6 +32,10 @@ onCreate(want: Want): void;
Called when an extension is created to initialize the service logic.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......@@ -53,6 +57,10 @@ onDestroy(): void;
Called when this extension is destroyed to clear resources.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Example
```
class ServiceExt extends ServiceExtension {
......@@ -69,6 +77,10 @@ onRequest(want: Want, startId: number): void;
Called after **onCreate** is invoked when an ability is started by calling **startAbility**. The value of **startId** is incremented for each ability that is started.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......@@ -91,6 +103,10 @@ onConnect(want: Want): rpc.RemoteObject;
Called after **onCreate** is invoked when an ability is started by calling **connectAbility**. A **RemoteObject** object is returned for communication with the client.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......@@ -126,6 +142,10 @@ onDisconnect(want: Want): void;
Called when the ability is disconnected.
**System capabilities**
SystemCapability.Ability.AbilityRuntime.Core
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册