diff --git a/en/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md b/en/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
index c4e4fdf3850f4bd3b1b8f6902133835764414cb3..fb107049c515d0ff1961313a9f0bebb39c4e4c9d 100644
--- a/en/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
+++ b/en/application-dev/device-usage-statistics/device-usage-statistics-dev-guide.md
@@ -3,7 +3,6 @@
## When to Use
With device usage statistics APIs, you can have a better understanding of the application, notification, and system usage. For example, in application usage statistics, you can query the application usage, event log, and bundle group.
-
The application records (usage history statistics and event records) cached by components are updated to the database for persistent storage within 30 minutes after an event is reported.
## Available APIs
@@ -23,7 +22,7 @@ import stats from '@ohos.bundleState';
| function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void | Queries the priority group of this application. This API uses an asynchronous callback to return the result.|
| function queryAppUsagePriorityGroup(): Promise<number>; | Queries the priority group of this application. This API uses a promise to return the result.|
| function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void | Checks whether the application specified by **bundleName** is in the idle state. |
-| function getRecentlyUsedModules(maxNum: number, callback: AsyncCallback<BundleActiveModuleInfo>): void | Obtains the number of FA usage records specified by **maxNum**.|
+| function getRecentlyUsedModules(maxNum? : number, callback: AsyncCallback<BundleActiveModuleInfo>): void | Obtains the number of FA usage records specified by **maxNum**. If **maxNum** is not specified, the default value **1000** is used.|
| function queryAppNotificationNumber(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void | Queries the number of notifications from all applications based on the specified start time and end time.|
| function queryBundleActiveEventStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void | Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time.|
| function queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback<number>): void | Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses an asynchronous callback to return the result.|
@@ -45,7 +44,7 @@ import stats from '@ohos.bundleState';
...,
"reqPermissions": [
{
- "name": "ohos.permission.BUNDLE_ACTIVE_INFO"
+ "name": "ohos.permission.BUNDLE_ACTIVE_INFO"
}
]
}
@@ -57,13 +56,13 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState'
// Promise mode
- stats.queryBundleActiveStates(0, 20000000000000).then( res => {
+ stats.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
});
@@ -87,7 +86,7 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState'
// Promise mode
- stats.queryBundleStateInfos(0, 20000000000000).then( res => {
+ stats.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1;
for (let key in res){
@@ -95,7 +94,7 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++;
}
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
});
@@ -121,13 +120,13 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState'
// Promise mode
- stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => {
+ stats.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
});
@@ -151,13 +150,13 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState'
// Promise mode
- stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
+ stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
}
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
});
@@ -179,14 +178,14 @@ import stats from '@ohos.bundleState';
```js
import stats from '@ohos.bundleState'
-
+
// Promise mode
- stats.queryAppUsagePriorityGroup().then( res => {
+ stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
});
-
+
// Callback mode
stats.queryAppUsagePriorityGroup((err, res) => {
if (err) {
@@ -196,16 +195,16 @@ import stats from '@ohos.bundleState';
}
});
```
-
+
7. Check whether the application specified by **bundleName** is in the idle state. This requires no permission to be configured in the **config.json** file. A third-party application can only check the idle status of itself.
```js
import stats from '@ohos.bundleState'
// Promise mode
- stats.isIdleState("com.ohos.camera").then( res => {
+ stats.isIdleState("com.ohos.camera").then(res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
});
@@ -225,18 +224,18 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState'
// Promise mode
- stats.getRecentlyUsedModules(1000).then( res => {
+ stats.getRecentlyUsedModules(1000).then(res => {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise result ' + JSON.stringify(res[i]));
}
- }).catch( err=> {
+ }).catch(err=> {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code);
});
// Promise mode when maxNum is not specified
- stats.getRecentlyUsedModules().then( res => {
+ stats.getRecentlyUsedModules().then(res => {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1));
@@ -247,7 +246,7 @@ import stats from '@ohos.bundleState';
});
// Asynchronous callback mode
- stats.getRecentlyUsedModules(1000,(err, res) => {
+ stats.getRecentlyUsedModules(1000, (err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code);
} else {
@@ -261,7 +260,7 @@ import stats from '@ohos.bundleState';
// Asynchronous callback mode when maxNum is not specified
stats.getRecentlyUsedModules((err, res) => {
- if(err) {
+ if (err) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.');
@@ -279,10 +278,10 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState'
// Promise mode
- stats.queryAppNotificationNumber(0, 20000000000000).then( res => {
+ stats.queryAppNotificationNumber(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise success.');
console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise result ' + JSON.stringify(res));
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise failed, because: ' + err.code);
});
@@ -301,15 +300,15 @@ import stats from '@ohos.bundleState';
```js
import stats from '@ohos.bundleState'
-
+
// Promise mode
- stats.queryBundleActiveEventStates(0, 20000000000000).then( res => {
+ stats.queryBundleActiveEventStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise success.');
console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise result ' + JSON.stringify(res));
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise failed, because: ' + err.code);
});
-
+
// Asynchronous callback mode
stats.queryBundleActiveEventStates(0, 20000000000000, (err, res) => {
if (err) {
@@ -325,14 +324,14 @@ import stats from '@ohos.bundleState';
```js
import stats from '@ohos.bundleState'
-
+
// Promise mode without parameters
- stats.queryAppUsagePriorityGroup().then( res => {
+ stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
});
-
+
// Asynchronous callback mode without parameters
stats.queryAppUsagePriorityGroup((err, res) => {
if (err) {
@@ -341,17 +340,17 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
}
});
-
+
// Promise mode with parameters
- stats.queryAppUsagePriorityGroup(this.bundleName).then( res => {
+ stats.queryAppUsagePriorityGroup(this.bundleName).then(res => {
console.log('BUNDLE_ACTIVE QueryPackageGroup promise succeeded. result: ' + JSON.stringify(res));
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
});
-
+
// Asynchronous callback mode with parameters
stats.queryAppUsagePriorityGroup(this.bundleName, (err, res) => {
- if(err) {
+ if (err) {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res));
@@ -363,16 +362,16 @@ import stats from '@ohos.bundleState';
```javascript
import stats from '@ohos.bundleState'
-
+
// Promise mode
- stats.setBundleGroup(this.bundleName, this.newGroup).then( () => {
+ stats.setBundleGroup(this.bundleName, this.newGroup).then(() => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise succeeded.');
}).catch( err => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code);
});
// Asynchronous callback mode
stats.setBundleGroup(this.bundleName, this.newGroup, (err) => {
- if(err) {
+ if (err) {
console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE SetBundleGroup callback succeeded.');
@@ -384,9 +383,9 @@ import stats from '@ohos.bundleState';
```javascript
import stats from '@ohos.bundleState'
-
+
// Promise mode
- let onBundleGroupChanged = (err,res) =>{
+ let onBundleGroupChanged = (err,res) => {
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result oldGroup is : ' + res.oldGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result newGroup is : ' + res.newGroup);
@@ -394,13 +393,13 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result userId is : ' + res.userId);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result bundleName is : ' + res.bundleName);
};
- stats.registerGroupCallBack(onBundleGroupChanged).then( () => {
+ stats.registerGroupCallBack(onBundleGroupChanged).then(() => {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise succeeded.');
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise failed. because: ' + err.code);
});
// Asynchronous callback mode
- let onBundleGroupChanged = (err,res) =>{
+ let onBundleGroupChanged = (err,res) => {
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's oldGroup is : ' + res.oldGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's newGroup is : ' + res.newGroup);
@@ -408,29 +407,29 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's userId is : ' + res.userId);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's bundleName is : ' + res.bundleName);
};
- stats.registerGroupCallBack(onBundleGroupChanged, (err)=>{
- if(err) {
+ stats.registerGroupCallBack(onBundleGroupChanged, (err) => {
+ if (err) {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback success.');
}
});
```
-
+
13. Deregister the callback for application group changes.
```javascript
import stats from '@ohos.bundleState'
-
+
//promise
- stats.unRegisterGroupCallBack().then( () => {
+ stats.unRegisterGroupCallBack().then(() => {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise succeeded.');
- }).catch( err => {
+ }).catch(err => {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise failed. because: ' + err.code);
});
//callback
- stats.unRegisterGroupCallBack((err)=>{
- if(err) {
+ stats.unRegisterGroupCallBack((err) => {
+ if (err) {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback success.');
diff --git a/en/application-dev/reference/apis/js-apis-deviceUsageStatistics.md b/en/application-dev/reference/apis/js-apis-deviceUsageStatistics.md
index 2ae6d7b5a18696850e13d8d088f9a1300561742c..8d18622ce2eb432210858545308e2a607891b1f0 100644
--- a/en/application-dev/reference/apis/js-apis-deviceUsageStatistics.md
+++ b/en/application-dev/reference/apis/js-apis-deviceUsageStatistics.md
@@ -1,6 +1,24 @@
# Device Usage Statistics
-> **NOTE**
+This module provides APIs for collecting statistics on device usage.
+
+System applications can call these APIs to implement the following features:
+
+- Query the usage duration in different time segments, events (foreground, background, start and end of continuous tasks), and the number of notifications, on a per application basis.
+- Query statistics about system events (sleep, wakeup, unlock, and screen lock).
+- Query the bundle group information of applications, including the invoking application itself.
+- Query the idle status of applications, including the invoking application itself.
+- Set the bundle group for other applications.
+- Register and deregister the callback for application group changes.
+
+Third-party applications can call these APIs to implement the following features:
+
+- Query the idle status of the invoking application itself.
+- Query the bundle group information of the invoking application itself.
+- Query the events of the invoking application itself.
+
+> **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.
@@ -23,7 +41,7 @@ Checks whether the application specified by **bundleName** is in the idle state.
| Name | Type | Mandatory | Description |
| ---------- | ---------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
-| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the value of **bundleName** is valid, **null** will be returned.|
+| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the value of bundleName is valid, null will be returned.|
**Example**
@@ -69,7 +87,7 @@ Checks whether the application specified by **bundleName** is in the idle state.
## bundleState.queryAppUsagePriorityGroup
-queryAppUsagePriorityGroup(): Promise\
+queryAppUsagePriorityGroup(): Promise<number>
Queries the priority group of this application. This API uses a promise to return the result.
@@ -79,7 +97,7 @@ Queries the priority group of this application. This API uses a promise to retur
| Type | Description |
| --------------- | --------------------------- |
-| Promise\ | Promise used to return the result.|
+| Promise<number> | Promise used to return the result.|
**Example**
@@ -93,7 +111,7 @@ bundleState.queryAppUsagePriorityGroup().then( res => {
## bundleState.queryAppUsagePriorityGroup
-queryAppUsagePriorityGroup(callback: AsyncCallback\): void
+queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void
Queries the priority group of this application. This API uses an asynchronous callback to return the result.
@@ -103,20 +121,11 @@ Queries the priority group of this application. This API uses an asynchronous ca
| Name | Type | Mandatory | Description |
| -------- | --------------------- | ---- | -------------------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+| callback | AsyncCallback<number> | Yes | Callback used to return the result.|
**Example**
```javascript
-// Callback with bundleName
-bundleState.queryAppUsagePriorityGroup(this.bundleName, (err, res) => {
- if(err) {
- console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
- } else {
- console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res));
- }
-});
-// Callback without bundleName
bundleState.queryAppUsagePriorityGroup((err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
@@ -523,7 +532,7 @@ Obtains the number of FA usage records specified by **maxNum**. This API uses an
## bundleState.queryAppUsagePriorityGroup9+
-queryAppUsagePriorityGroup(bundleName? : string): Promise
+queryAppUsagePriorityGroup(bundleName? : string): Promise<number>
Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses a promise to return the result.
@@ -543,13 +552,14 @@ Queries the priority group of the application specified by **bundleName**. If **
| Type | Description |
| --------------- | --------------------------- |
-| Promise\ | Promise used to return the result.|
+| Promise<number> | Promise used to return the result.|
**Example**
```javascript
// Promise with bundleName
-bundleState.queryAppUsagePriorityGroup(this.bundleName).then( res => {
+let bundleName = "com.ohos.camera";
+bundleState.queryAppUsagePriorityGroup(bundleName).then( res => {
console.log('BUNDLE_ACTIVE QueryPackageGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
@@ -564,7 +574,7 @@ bundleState.queryAppUsagePriorityGroup().then( res => {
## bundleState.queryAppUsagePriorityGroup9+
-queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback\): void
+queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback<number>): void
Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses an asynchronous callback to return the result.
@@ -579,13 +589,14 @@ Queries the priority group of the application specified by **bundleName**. If **
| Name | Type | Mandatory | Description |
| ---------- | --------------------- | ---- | ---------------------------------------- |
| bundleName | string | No | Bundle name of the target application. If this parameter is not specified, the priority group of the current application is queried.|
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+| callback | AsyncCallback<number> | Yes | Callback used to return the result. |
**Example**
```javascript
// Callback with bundleName
-bundleState.queryAppUsagePriorityGroup(this.bundleName, (err, res) => {
+let bundleName = "com.ohos.camera";
+bundleState.queryAppUsagePriorityGroup(bundleName, (err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
} else {
@@ -604,7 +615,7 @@ bundleState.queryAppUsagePriorityGroup((err, res) => {
## bundleState.setBundleGroup9+
-setBundleGroup(bundleName: string, newGroup: GroupType): Promise\
+setBundleGroup(bundleName: string, newGroup: GroupType): Promise<void>
Sets the group for the application specified by **bundleName**. This API uses a promise to return the result.
@@ -618,22 +629,22 @@ Sets the group for the application specified by **bundleName**. This API uses a
| Name | Type | Mandatory | Description |
| ---------- | --------- | ---- | ---- |
-| bundleName | string | Yes | Bundle name of the target application.|
-| newGroup | GroupType | Yes | Application group.|
+| bundleName | string | Yes | Bundle name of an application.|
+| newGroup | [GroupType](#grouptype) | Yes | Application group.|
**Return value**
| Type | Description |
| ------------- | ------------------------- |
-| Promise\ | Promise used to return the result.|
+| Promise<void> | Promise used to return the result.|
**Example**
```javascript
-this.bundleName = "com.example.deviceUsageStatistics";
-this.newGroup = stats.GroupType.ACTIVE_GROUP_DAILY;
+let bundleName = "com.example.deviceUsageStatistics";
+let newGroup = bundleState.GroupType.ACTIVE_GROUP_DAILY;
-bundleState.setBundleGroup(this.bundleName, this.newGroup).then( () => {
+bundleState.setBundleGroup(bundleName, newGroup).then( () => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise succeeded.');
}).catch( err => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code);
@@ -642,7 +653,7 @@ bundleState.setBundleGroup(this.bundleName, this.newGroup).then( () => {
## bundleState.setBundleGroup9+
-setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback\): void
+setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void
Sets the group for the application specified by **bundleName**. This API uses an asynchronous callback to return the result.
@@ -656,17 +667,17 @@ Sets the group for the application specified by **bundleName**. This API uses an
| Name | Type | Mandatory | Description |
| ---------- | ------------------- | ---- | ------------------------- |
-| bundleName | string | Yes | Bundle name of the target application. |
-| newGroup | GroupType | Yes | Application group. |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+| bundleName | string | Yes | Bundle name of an application. |
+| newGroup | [GroupType](#grouptype) | Yes | Application group. |
+| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
**Example**
```javascript
-this.bundleName = "com.example.deviceUsageStatistics";
-this.newGroup = stats.GroupType.ACTIVE_GROUP_DAILY;
+let bundleName = "com.example.deviceUsageStatistics";
+let newGroup = bundleState.GroupType.ACTIVE_GROUP_DAILY;
-bundleState.setBundleGroup(this.bundleName, this.newGroup, (err) => {
+bundleState.setBundleGroup(bundleName, newGroup, (err) => {
if(err) {
console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code);
} else {
@@ -677,9 +688,9 @@ bundleState.setBundleGroup(this.bundleName, this.newGroup, (err) => {
## bundleState.registerGroupCallBack9+
-registerGroupCallBack(callback: Callback\): Promise\
+registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<void>
-Registers a callback for application group changes. When an application group of the user changes, **BundleActiveGroupCallbackInfo** is returned to all applications that have registered the callback. This API uses a promise to return the result.
+Registers a callback for application group changes. When an application group of the user changes, a **[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)** instance is returned to all applications that have registered the callback. This API uses a promise to return the result.
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO
@@ -689,26 +700,26 @@ Registers a callback for application group changes. When an application group of
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------------------- | ---- | ----------- |
-| callback | Callback\ | Yes | Callback for application group changes.|
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
+| callback | Callback<[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)> | Yes | Callback used to return the application group changes.|
**Return value**
| Type | Description |
| ------------- | ----------------------- |
-| Promise\ | Promise used to return the result.|
+| Promise<void> | Promise used to return the result.|
**Example**
```javascript
let onBundleGroupChanged = (err,res) =>{
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result oldGroup is : ' + res.oldGroup);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result newGroup is : ' + res.newGroup);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result changeReason is : ' + res.newGroup);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result userId is : ' + res.userId);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result bundleName is : ' + res.bundleName);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageOldGroup is : ' + res.appUsageOldGroup);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageNewGroup is : ' + res.appUsageNewGroup);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result changeReason is : ' + res.changeReason);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result userId is : ' + res.userId);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result bundleName is : ' + res.bundleName);
};
bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise succeeded.');
@@ -719,9 +730,9 @@ bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => {
## bundleState.registerGroupCallBack9+
-registerGroupCallBack(callback: Callback\, callback: AsyncCallback\): void
+registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<void>): void
-Registers a callback for application group changes. When an application group of the user changes, **BundleActiveGroupCallbackInfo** is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.
+Registers a callback for application group changes. When an application group of the user changes, a **[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)** instance is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO
@@ -731,21 +742,21 @@ Registers a callback for application group changes. When an application group of
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------------------- | ---- | ------------- |
-| callback | Callback\ | Yes | Callback for application group changes. |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
+| callback | Callback<[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)> | Yes | Callback used to return the application group changes. |
+| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
**Example**
```javascript
let onBundleGroupChanged = (err,res) =>{
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's oldGroup is : ' + res.oldGroup);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's newGroup is : ' + res.newGroup);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's changeReason is : ' + res.newGroup);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's userId is : ' + res.userId);
- console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's bundleName is : ' + res.bundleName);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageOldGroup is : ' + res.appUsageOldGroup);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageNewGroup is : ' + res.appUsageNewGroup);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result changeReason is : ' + res.changeReason);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result userId is : ' + res.userId);
+ console.log('BUNDLE_ACTIVE RegisterGroupCallBack result bundleName is : ' + res.bundleName);
};
bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{
if(err) {
@@ -758,7 +769,7 @@ bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{
## bundleState.unRegisterGroupCallBack9+
-unRegisterGroupCallBack(): Promise\
+unRegisterGroupCallBack(): Promise<void>
Deregisters the callback for application group changes. This API uses a promise to return the result.
@@ -774,7 +785,7 @@ Deregisters the callback for application group changes. This API uses a promise
| Type | Description |
| ------------- | ------------------------ |
-| Promise\ | Promise used to return the result.|
+| Promise<void> | Promise used to return the result.|
**Example**
@@ -788,7 +799,7 @@ bundleState.unRegisterGroupCallBack().then( () => {
## bundleState.unRegisterGroupCallBack9+
-unRegisterGroupCallBack(callback: AsyncCallback\): void;
+unRegisterGroupCallBack(callback: AsyncCallback<void>): void;
Deregisters the callback for application group changes. This API uses an asynchronous callback to return the result.
@@ -802,7 +813,7 @@ Deregisters the callback for application group changes. This API uses an asynchr
| Name | Type | Mandatory | Description |
| -------- | ------------------- | ---- | -------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
**Example**
@@ -870,7 +881,7 @@ Queries statistics about system events (hibernation, wakeup, unlocking, and scre
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| begin | number | Yes | Start time. |
| end | number | Yes | End time. |
-| callback | AsyncCallback<Array<[BundleActiveEventState](#bundleactiveeventstate9)>> | Yes | Promise used to return the result.|
+| callback | AsyncCallback<Array<[BundleActiveEventState](#bundleactiveeventstate9)>> | Yes | Callback used to return the result.|
**Example**
@@ -982,7 +993,7 @@ Provides the FA widget usage information.
| Name | Type | Mandatory | Description |
| ---------------- | ------ | ---- | ----------- |
-| formName | number | Yes | Widget name. |
+| formName | string | Yes | Widget name. |
| formDimension | number | Yes | Widget dimensions. |
| formId | number | Yes | Widget ID. |
| formLastUsedTime | number | Yes | Last time when the widget was clicked.|
@@ -992,15 +1003,15 @@ Provides the FA widget usage information.
Provides the application group changes returned through a callback.
-**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App
+**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
-| Name | Type | Mandatory | Description |
-| ---------------- | ------ | ---- | -------- |
-| appUsageOldGroup | number | Yes | Application group before the change.|
-| appUsageNewGroup | number | Yes | Application group after the change.|
-| useId | number | Yes | User ID. |
-| changeReason | number | Yes | Reason for the group change. |
-| bundleName | string | Yes | Bundle name of an application. |
+| Name | Type | Mandatory| Description |
+| ---------------- | ------ | ---- | ---------------- |
+| appUsageOldGroup | number | Yes | Application group before the change.|
+| appUsageNewGroup | number | Yes | Application group after the change.|
+| userId | number | Yes | User ID. |
+| changeReason | number | Yes | Reason for the group change. |
+| bundleName | string | Yes | Bundle name of an application. |
## BundleStateInfo
@@ -1008,11 +1019,11 @@ Provides the usage duration information of applications.
### Attributes
-**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
+**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App
| Name | Type | Mandatory | Description |
| ------------------------ | ------ | ---- | ---------------------------------------- |
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name of an application. |
| abilityPrevAccessTime | number | Yes | Last time when the application was used. |
| abilityInFgTotalTime | number | Yes | Total time that the application runs in the foreground. |
| id | number | No | User ID.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
@@ -1029,8 +1040,6 @@ merge(toMerge: BundleStateInfo): void
Merges the application usage information that has the same bundle name.
-This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
-
**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App
**Parameters**
@@ -1047,7 +1056,7 @@ Provides information about an application event.
| Name | Type | Mandatory | Description |
| --------------------- | ------ | ---- | ---------------------------------------- |
-| bundleName | string | Yes | Bundle name of the application. |
+| bundleName | string | Yes | Bundle name of an application. |
| stateType | number | Yes | Application event type. |
| stateOccurredTime | number | Yes | Timestamp when the application event occurs. |
| appUsagePriorityGroup | number | No | Usage priority group of the application.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
@@ -1092,7 +1101,7 @@ Enumerates the interval types for querying the application usage duration.
| BY_MONTHLY | 3 | The system obtains the application usage duration statistics in the specified time frame on a monthly basis. |
| BY_ANNUALLY | 4 | The system obtains the application usage duration statistics in the specified time frame on an annual basis. |
-## GroupType
+## GroupType9+
Enumerates the application group types.