>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The Battery Info module provides APIs for querying the charger type, battery health status, and battery charging status.
The Battery Info module provides APIs for querying the charger type, battery health status, and battery charging status.
> **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -13,67 +12,100 @@ The Battery Info module provides APIs for querying the charger type, battery hea
...
@@ -13,67 +12,100 @@ The Battery Info module provides APIs for querying the charger type, battery hea
importbatteryInfofrom'@ohos.batteryInfo';
importbatteryInfofrom'@ohos.batteryInfo';
```
```
## System Capabilities
SystemCapability.PowerManager.BatteryManager
## Attributes
## Attributes
Describes battery information.
Describes battery information.
| Name | Type | Readable | Writable | Description |
This module provides APIs for querying software and hardware power consumption statistics.
> **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.
>
> - The APIs provided by this module are system APIs.
| callback | AsyncCallback<Array<[BatteryStatsInfo](#batterystatsinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the array of power consumption information obtained. If the operation failed, **err** is an error object.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
> 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.
The Brightness module provides an API for setting the screen brightness.
The Brightness module provides an API for setting the screen brightness.
> **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.
>
> - The APIs provided by this module are system APIs.
## Modules to Import
## Modules to Import
...
@@ -18,18 +20,30 @@ setValue(value: number): void
...
@@ -18,18 +20,30 @@ setValue(value: number): void
Sets the screen brightness.
Sets the screen brightness.
This is a system API and cannot be called by third-party applications.
> 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.
The Power Manager module provides APIs for rebooting and shutting down the system, as well as querying the screen status.
The Power Manager module provides APIs for rebooting and shutting down the system, as well as querying the screen status.
> **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
## Modules to Import
...
@@ -12,42 +11,294 @@ The Power Manager module provides APIs for rebooting and shutting down the syste
...
@@ -12,42 +11,294 @@ The Power Manager module provides APIs for rebooting and shutting down the syste
importpowerfrom'@ohos.power';
importpowerfrom'@ohos.power';
```
```
## System Capability
## power.shutdown
SystemCapability.PowerManager.PowerManager.Core
## power.shutdownDevice
shutdown(reason: string): void
shutdownDevice(reason: string): void
Shuts down the system.
Shuts down the system.
This is a system API and cannot be called by third-party applications.
| mode | [DevicePowerMode](#devicepowermode9) | Yes | Power mode. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the power mode is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
| callback | AsyncCallback<boolean> | Yes | Callback used to obtain the return value.<br>Return value: The value **true** indicates that the screen is on, and the value **false** indicates the opposite.|
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the screen status obtained, where the value **true** indicates on and the value **false** indicates the opposite. Otherwise, **err** is an error object.|
**Example**
**Example**
```js
```js
power.isScreenOn((error,screenOn)=>{
power.isScreenOn((err,data)=>{
if(typeoferror==="undefined"){
if(typeoferr==='undefined'){
console.info('screenOn status is '+screenOn);
console.info('screen on status is '+data);
}else{
}else{
console.log('error: '+error);
console.error('check screen status failed, err: '+err);
}
}
})
})
```
```
## power.isScreenOn<sup>(deprecated)</sup>
## power.isScreenOn
isScreenOn(): Promise<boolean>
isScreenOn(): Promise<boolean>
Checks the screen status of the current device.
> This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
Checks the screen status of the current device. This API uses a promise to return the result.
| Promise<boolean> | Promise used to obtain the return value. <br/>Return value: The value **true** indicates that the screen is on, and the value **false** indicates the opposite.|
| Promise<boolean> | Promise used to return the result. The value **true** indicates that the screen is on, and the value **false** indicates the opposite.|
**Example**
**Example**
```js
```js
power.isScreenOn()
power.isScreenOn()
.then(screenOn=>{
.then(data=>{
console.info('screenOn status is '+screenOn);
console.info('screen on status is '+data);
})
})
.catch(error=>{
.catch(err=>{
console.log('error: '+error);
console.error('check screen status failed, err: '+err);
This module allows you to query the charging status and remaining power of a device.
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.batteryInfo`](js-apis-battery-info.md) instead.
>
> **NOTE**
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.batteryInfo`](js-apis-battery-info.md) instead.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -16,40 +17,46 @@ import battery from '@system.battery';
...
@@ -16,40 +17,46 @@ import battery from '@system.battery';
## battery.getStatus
## battery.getStatus
getStatus(Object): void
getStatus(options?: GetStatusOptions): void;
Obtains the current charging state and battery level.
Obtains the current charging state and battery level.
| success | (data: [BatteryResponse](#batteryresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BatteryResponse](#batteryresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## BatteryResponse
Defines a response that returns the charging status and remaining power of the device.
| Name| Type| Description|
| -------- | -------- | -------- |
| charging | boolean | Whether the battery is being charged.|
| level | number | Current battery level, which ranges from **0.00** to **1.00**.|
This module provides APIs for querying and adjusting the screen brightness and mode.
> **NOTE**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.brightness`](js-apis-brightness.md) instead.
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.brightness`](js-apis-brightness.md) instead.
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
@@ -16,7 +17,7 @@ import brightness from '@system.brightness';
...
@@ -16,7 +17,7 @@ import brightness from '@system.brightness';
## brightness.getValue
## brightness.getValue
getValue(Object): void
getValue(options?: GetBrightnessOptions): void
Obtains the current screen brightness.
Obtains the current screen brightness.
...
@@ -24,39 +25,27 @@ Obtains the current screen brightness.
...
@@ -24,39 +25,27 @@ Obtains the current screen brightness.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called when the execution is successful. |
| options | [GetBrightnessOptions](#getbrightnessoptions) | No | Options for obtaining the screen brightness.|
| fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called when the execution is complete |
The following values will be returned when the operation is successful.
| Name | Type | Description |
| -------- | -------- | -------- |
| value | number | Screen brightness, which ranges from 1 to 255. |
**Example**
**Example**
```js
```js
exportdefault{
brightness.getValue({
getValue(){
success:function(data){
brightness.getValue({
console.log('success get brightness value:'+data.value);
success:function(data){
console.log('success get brightness value:'+data.value);
| value | number | Yes | Screen brightness. The value is an integer ranging from 1 to 255.<br/>- If the value is less than or equal to **0**, value **1** will be used.<br/>- If the value is greater than **255**, value **255** will be used.<br/>- If the value contains decimals, the integral part of the value will be used. For example, if value **8.1** is set, value **8** will be used. |
| options | [SetBrightnessOptions](#setbrightnessoptions) | No | Options for setting the screen brightness.|
| success | Function | No | Called when the execution is successful. |
| fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called when the execution is complete. |
**Example**
**Example**
```js
```js
exportdefault{
brightness.setValue({
setValue(){
value:100,
brightness.setValue({
success:function(){
value:100,
console.log('handling set brightness success.');
success:function(){
},
console.log('handling set brightness success.');
fail:function(data,code){
},
console.error('handling set brightness value fail, code:'+code+', data: '+data);
fail:function(data,code){
}
console.log('handling set brightness value fail, code:'+code+', data: '+data);
});
},
```
});
},
}
```
## brightness.getMode
## brightness.getMode
getMode(Object): void
getMode(options?: GetBrightnessModeOptions: void
Obtains the screen brightness adjustment mode.
Obtains the screen brightness adjustment mode.
...
@@ -100,75 +82,57 @@ Obtains the screen brightness adjustment mode.
...
@@ -100,75 +82,57 @@ Obtains the screen brightness adjustment mode.
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| success | Function | No | Called when the execution is successful. |
| options | [GetBrightnessModeOptions](#getbrightnessmodeoptions) | No| Options for obtaining the screen brightness mode.|
| fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called when the execution is complete |
The following values will be returned when the operation is successful.
| Name | Type | Description |
| -------- | -------- | -------- |
| mode | number | The value can be **0** or **1**.<br/>- **0**: The screen brightness is manually adjusted.<br/>- **1**: The screen brightness is automatically adjusted. |
**Example**
**Example**
```js
```js
exportdefault{
brightness.getMode({
getMode(){
success:function(data){
brightness.getMode({
console.log('success get mode:'+data.mode);
success:function(data){
console.log('success get mode:'+data.mode);
},
fail:function(data,code){
console.log('handling get mode fail, code:'+code+', data: '+data);
},
},
});
fail:function(data,code){
},
console.error('handling get mode fail, code:'+code+', data: '+data);
>This API is no longer maintained since API version 7. It is recommended that you use [window.setKeepScreenOn](js-apis-window.md#setkeepscreenon) instead.
Sets whether to always keep the screen on. Call this API in **onShow()**.
Sets whether to always keep the screen on. Call this API in **onShow()**.
...
@@ -176,27 +140,88 @@ Sets whether to always keep the screen on. Call this API in **onShow()**.
...
@@ -176,27 +140,88 @@ Sets whether to always keep the screen on. Call this API in **onShow()**.
| success | (data: [BrightnessResponse](#brightnessresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessResponse](#brightnessresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## SetBrightnessOptions
Defines the options for setting the screen brightness.
| value | number | Yes | Screen brightness. The value is an integer ranging from **1** to **255**.<br>- If the value is less than or equal to **0**, value **1** will be used.<br>- If the value is greater than **255**, value **255** will be used.<br>- If the value contains decimals, the integral part of the value will be used. For example, if value **8.1** is set, value **8** will be used.|
| success | () => void | No | Called when API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## BrightnessResponse
Defines a response that returns the screen brightness.
| Parameter| Type | Description|
| -------- | -------- | -------- |
| value | number | Screen brightness. The value ranges from 1 to 255.|
## GetBrightnessModeOptions
Defines the options for obtaining the screen brightness mode.
| success | (data: [BrightnessModeResponse](#brightnessmoderesponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessModeResponse](#brightnessmoderesponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## SetBrightnessModeOptions
Defines the options for setting the screen brightness mode.
| mode | number | Yes | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
| success | () => void | No | Called when API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| complete | () => void | No | Called when API call is complete. |
## BrightnessModeResponse
Defines a response that returns the screen brightness mode.
| Name| Type | Description|
| -------- | -------- | -------- |
| mode | number | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
## SetKeepScreenOnOptions
Defines the options for setting the screen to be steady on.
| keepScreenOn | boolean | Yes | The value **true** means to keep the screen steady on, and the value **false** indicates the opposite. |
| success | () => void | No | Called when API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| complete | () => void | No | Called when API call is complete. |
> 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.
This module provides thermal level-related callback and query APIs to obtain the information required for thermal control.
This module provides thermal level-related callback and query APIs to obtain the information required for thermal control.
> **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
## Modules to Import
...
@@ -13,78 +11,168 @@ This module provides thermal level-related callback and query APIs to obtain the
...
@@ -13,78 +11,168 @@ This module provides thermal level-related callback and query APIs to obtain the
| WARM | 2 | The device is warm. You need to stop or delay some imperceptible services.|
| callback | Callback<ThermalLevel> | Yes | Callback used to return the result.|
| HOT | 3 | The device is heating up. You need to stop all imperceptible services and downgrade or reduce the load of other services.|
| OVERHEATED | 4 | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major services.|
**Error codes**
| WARNING | 5 | The device is overheated and is about to enter the emergency state. You need to stop all imperceptible services and downgrade major services to the maximum extent.|
| EMERGENCY | 6 | The device has entered the emergency state. You need to stop all services except those for the emergency help purposes.|
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
| Code | Error Message |
|---------|---------|
| 4800101 | Operation failed. Cannot connect to service.|
| callback | Callback<void> | No | Callback used to return the result. No value is returned. If this parameter is not set, this API unsubscribes from all callbacks.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
| Code | Error Message |
|---------|---------|
| 4800101 | Operation failed. Cannot connect to service.|
> This API is deprecated since API version 9. You are advised to use [thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9) instead.
| callback | AsyncCallback<ThermalLevel> | Yes | Callback used to obtain the return value.<br>The return value contains only one parameter, that is, thermal level. If an alarm is generated, you can use `// @ts-ignore` to suppress the alarm.|
| callback | AsyncCallback<ThermalLevel> | Yes | Callback used to return the result. The return value contains only one parameter, that is, thermal level. If an alarm is generated, you can use `// @ts-ignore` to suppress the alarm.|
> This API is deprecated since API version 9. You are advised to use [thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9) instead.
| callback | AsyncCallback<void> | No | Callback without a return value.|
| callback | AsyncCallback<void> | No | Callback used to return the result. No value is returned. If this parameter is not set, this API unsubscribes from all callbacks.|
| COOL | 0 | The device is cool, and services are not restricted. |
| NORMAL | 1 | The device is operational but is not cool. You need to pay attention to its heating.|
| WARM | 2 | The device is warm. You need to stop or delay some imperceptible services.|
| HOT | 3 | The device is heating up. You need to stop all imperceptible services and downgrade or reduce the load of other services.|
| OVERHEATED | 4 | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major services.|
| WARNING | 5 | The device is overheated and is about to enter the emergency state. You need to stop all imperceptible services and downgrade major services to the maximum extent.|
| EMERGENCY | 6 | The device has entered the emergency state. You need to stop all services except those for the emergency help purposes.|