openharmony 鸿蒙 js-apis-resourceschedule-systemload

2025-06-12 浏览 (1)

@ohos.resourceschedule.systemload (System Load Level Management)

The systemload module allows the system to determine the system load level based on the current temperature, load, and scenario, and notifies registered applications of level changes, if any.

NOTE

  • The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { systemLoad } from '@kit.BasicServicesKit';

systemLoad.on('systemLoadChange')

on(type: 'systemLoadChange', callback: Callback<SystemLoadLevel>): void

Enables listening for system load level changes. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.ResourceSchedule.SystemLoad

Parameters

NameTypeMandatoryDescription
typestringYesChange type. This parameter has a fixed value of systemLoadChange.
callbackAsyncCallback<SystemLoadLevel>YesCallback used to return the system load level.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible cause: 1. Callback parameter error; 2. Register a exist callback type; 3. Parameter verification failed.

Example

import { systemLoad } from '@kit.BasicServicesKit';

function onSystemLoadChange(res: systemLoad.SystemLoadLevel) {
    console.log(`system load changed, current level ` + res);
}

try {
    systemLoad.on('systemLoadChange', onSystemLoadChange);
    console.log(`register systemload callback succeeded. `);
} catch (err) {
    console.error(`register systemload callback failed: ` + JSON.stringify(err));
}

systemLoad.off('systemLoadChange')

off(type: 'systemLoadChange', callback?: Callback<SystemLoadLevel>): void

Disables listening for system load level changes. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.ResourceSchedule.SystemLoad

Parameters

NameTypeMandatoryDescription
typestringYesChange type. This parameter has a fixed value of systemLoadChange.
callbackAsyncCallback<SystemLoadLevel>NoCallback used to return the system load level.
Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible cause: 1. Callback parameter error; 2. Register a exist callback type; 3. Parameter verification failed.

Example

import { systemLoad } from '@kit.BasicServicesKit';

function onSystemLoadChange(res: systemLoad.SystemLoadLevel) {
    console.log(`system load changed, current level ` + res);
}

try {
    systemLoad.off('systemLoadChange', onSystemLoadChange);
    console.log(`unregister systemload callback succeeded:. `);
} catch (err) {
    console.error(`unregister systemload callback failed: ` + JSON.stringify(err));
}

systemLoad.getLevel

getLevel(): Promise<SystemLoadLevel>

Obtains the system load level. This API uses a promise to return the result.

System capability: SystemCapability.ResourceSchedule.SystemLoad

Return value

TypeDescription
Promise<SystemLoadLevel>Promise used to return the system load level.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { systemLoad } from '@kit.BasicServicesKit';

systemLoad.getLevel().then((res: systemLoad.SystemLoadLevel) => {
    console.log(`getLevel promise succeeded. result: ` + JSON.stringify(res));
}).catch((err: BusinessError) => {
    console.error(`getLevel promise failed. code is ${err.code} message is ${err.message}`);
})

SystemLoadLevel

Enumerates system load levels.

System capability: SystemCapability.ResourceSchedule.SystemLoad

NameValueDescription
LOW0The device temperature and load are low.
NORMAL1The device temperature and load are normal but are approaching the medium range. You need to downgrade or reduce the load of imperceptible services.
MEDIUM2One or more device temperature or load items are slightly high, or the device temperature is in the medium range but the load is high. You need to stop or delay some imperceptible services.
HIGH3The device temperature and load are relatively high. You need to stop all imperceptible services and downgrade or reduce the load of non-critical services.
OVERHEATED4The device temperature and load are high, and the device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major foreground services.
WARNING5The device is overheated or heavily loaded and is about to enter the Warning state. You need to stop all imperceptible services and downgrade major foreground services to the maximum extent.
EMERGENCY6The device is overheated or significantly heavy loaded and is about to enter the Emergency state. You need to stop all services except those for fundamental use.
ESCAPE7The device is overheated or extremely heavy loaded and is about to enter the Escape state. You need to stop all services and take necessary emergency measures such as data backup.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit

harmony 鸿蒙DeviceInfo

harmony 鸿蒙InitSync

harmony 鸿蒙OH_Print

harmony 鸿蒙OsAccount

harmony 鸿蒙Pasteboard

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/qHGMFr