未验证 提交 512d69ae 编写于 作者: O openharmony_ci 提交者: Gitee

!6845 翻译完成 5746:device-usage-statistics

Merge pull request !6845 from ester.zhou/TR-5746
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
## When to Use ## 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. 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. 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 ## Available APIs
...@@ -23,7 +22,7 @@ import stats from '@ohos.bundleState'; ...@@ -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(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 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 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 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 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.| | 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'; ...@@ -45,7 +44,7 @@ import stats from '@ohos.bundleState';
..., ...,
"reqPermissions": [ "reqPermissions": [
{ {
"name": "ohos.permission.BUNDLE_ACTIVE_INFO" "name": "ohos.permission.BUNDLE_ACTIVE_INFO"
} }
] ]
} }
...@@ -57,13 +56,13 @@ import stats from '@ohos.bundleState'; ...@@ -57,13 +56,13 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.queryBundleActiveStates(0, 20000000000000).then( res => { stats.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i])); 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); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
}); });
...@@ -87,7 +86,7 @@ import stats from '@ohos.bundleState'; ...@@ -87,7 +86,7 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.queryBundleStateInfos(0, 20000000000000).then( res => { stats.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1; let i = 1;
for (let key in res){ for (let key in res){
...@@ -95,7 +94,7 @@ import stats from '@ohos.bundleState'; ...@@ -95,7 +94,7 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++; i++;
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
}); });
...@@ -121,13 +120,13 @@ import stats from '@ohos.bundleState'; ...@@ -121,13 +120,13 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => { stats.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i])); 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); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
}); });
...@@ -151,13 +150,13 @@ import stats from '@ohos.bundleState'; ...@@ -151,13 +150,13 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => { stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i])); 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); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
}); });
...@@ -179,14 +178,14 @@ import stats from '@ohos.bundleState'; ...@@ -179,14 +178,14 @@ import stats from '@ohos.bundleState';
```js ```js
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.queryAppUsagePriorityGroup().then( res => { stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(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); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
}); });
// Callback mode // Callback mode
stats.queryAppUsagePriorityGroup((err, res) => { stats.queryAppUsagePriorityGroup((err, res) => {
if (err) { if (err) {
...@@ -196,16 +195,16 @@ import stats from '@ohos.bundleState'; ...@@ -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. 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 ```js
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // 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)); 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); console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
}); });
...@@ -225,18 +224,18 @@ import stats from '@ohos.bundleState'; ...@@ -225,18 +224,18 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.getRecentlyUsedModules(1000).then( res => { stats.getRecentlyUsedModules(1000).then(res => {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded'); console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise result ' + JSON.stringify(res[i])); 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); console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code);
}); });
// Promise mode when maxNum is not specified // Promise mode when maxNum is not specified
stats.getRecentlyUsedModules().then( res => { stats.getRecentlyUsedModules().then(res => {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded'); console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1));
...@@ -247,7 +246,7 @@ import stats from '@ohos.bundleState'; ...@@ -247,7 +246,7 @@ import stats from '@ohos.bundleState';
}); });
// Asynchronous callback mode // Asynchronous callback mode
stats.getRecentlyUsedModules(1000,(err, res) => { stats.getRecentlyUsedModules(1000, (err, res) => {
if(err) { if(err) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code);
} else { } else {
...@@ -261,7 +260,7 @@ import stats from '@ohos.bundleState'; ...@@ -261,7 +260,7 @@ import stats from '@ohos.bundleState';
// Asynchronous callback mode when maxNum is not specified // Asynchronous callback mode when maxNum is not specified
stats.getRecentlyUsedModules((err, res) => { stats.getRecentlyUsedModules((err, res) => {
if(err) { if (err) {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code);
} else { } else {
console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.'); console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.');
...@@ -279,10 +278,10 @@ import stats from '@ohos.bundleState'; ...@@ -279,10 +278,10 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // 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 success.');
console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise result ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise result ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise failed, because: ' + err.code);
}); });
...@@ -301,15 +300,15 @@ import stats from '@ohos.bundleState'; ...@@ -301,15 +300,15 @@ import stats from '@ohos.bundleState';
```js ```js
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // 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 success.');
console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise result ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise result ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise failed, because: ' + err.code);
}); });
// Asynchronous callback mode // Asynchronous callback mode
stats.queryBundleActiveEventStates(0, 20000000000000, (err, res) => { stats.queryBundleActiveEventStates(0, 20000000000000, (err, res) => {
if (err) { if (err) {
...@@ -325,14 +324,14 @@ import stats from '@ohos.bundleState'; ...@@ -325,14 +324,14 @@ import stats from '@ohos.bundleState';
```js ```js
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode without parameters // Promise mode without parameters
stats.queryAppUsagePriorityGroup().then( res => { stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(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); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
}); });
// Asynchronous callback mode without parameters // Asynchronous callback mode without parameters
stats.queryAppUsagePriorityGroup((err, res) => { stats.queryAppUsagePriorityGroup((err, res) => {
if (err) { if (err) {
...@@ -341,17 +340,17 @@ import stats from '@ohos.bundleState'; ...@@ -341,17 +340,17 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} }
}); });
// Promise mode with parameters // 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)); 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); console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
}); });
// Asynchronous callback mode with parameters // Asynchronous callback mode with parameters
stats.queryAppUsagePriorityGroup(this.bundleName, (err, res) => { stats.queryAppUsagePriorityGroup(this.bundleName, (err, res) => {
if(err) { if (err) {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
} else { } else {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res));
...@@ -363,16 +362,16 @@ import stats from '@ohos.bundleState'; ...@@ -363,16 +362,16 @@ import stats from '@ohos.bundleState';
```javascript ```javascript
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
stats.setBundleGroup(this.bundleName, this.newGroup).then( () => { stats.setBundleGroup(this.bundleName, this.newGroup).then(() => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise succeeded.'); console.log('BUNDLE_ACTIVE SetBundleGroup promise succeeded.');
}).catch( err => { }).catch( err => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code);
}); });
// Asynchronous callback mode // Asynchronous callback mode
stats.setBundleGroup(this.bundleName, this.newGroup, (err) => { stats.setBundleGroup(this.bundleName, this.newGroup, (err) => {
if(err) { if (err) {
console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code);
} else { } else {
console.log('BUNDLE_ACTIVE SetBundleGroup callback succeeded.'); console.log('BUNDLE_ACTIVE SetBundleGroup callback succeeded.');
...@@ -384,9 +383,9 @@ import stats from '@ohos.bundleState'; ...@@ -384,9 +383,9 @@ import stats from '@ohos.bundleState';
```javascript ```javascript
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// Promise mode // Promise mode
let onBundleGroupChanged = (err,res) =>{ let onBundleGroupChanged = (err,res) => {
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); 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 oldGroup is : ' + res.oldGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result newGroup is : ' + res.newGroup); console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result newGroup is : ' + res.newGroup);
...@@ -394,13 +393,13 @@ import stats from '@ohos.bundleState'; ...@@ -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 userId is : ' + res.userId);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result bundleName is : ' + res.bundleName); 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.'); console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise succeeded.');
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise failed. because: ' + err.code);
}); });
// Asynchronous callback mode // 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 callback success.');
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's oldGroup is : ' + res.oldGroup); 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 newGroup is : ' + res.newGroup);
...@@ -408,29 +407,29 @@ import stats from '@ohos.bundleState'; ...@@ -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 userId is : ' + res.userId);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's bundleName is : ' + res.bundleName); console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's bundleName is : ' + res.bundleName);
}; };
stats.registerGroupCallBack(onBundleGroupChanged, (err)=>{ stats.registerGroupCallBack(onBundleGroupChanged, (err) => {
if(err) { if (err) {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback failed, because: ' + err.code);
} else { } else {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback success.'); console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback success.');
} }
}); });
``` ```
13. Deregister the callback for application group changes. 13. Deregister the callback for application group changes.
```javascript ```javascript
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
//promise //promise
stats.unRegisterGroupCallBack().then( () => { stats.unRegisterGroupCallBack().then(() => {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise succeeded.'); console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise succeeded.');
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise failed. because: ' + err.code);
}); });
//callback //callback
stats.unRegisterGroupCallBack((err)=>{ stats.unRegisterGroupCallBack((err) => {
if(err) { if (err) {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback failed, because: ' + err.code);
} else { } else {
console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback success.'); console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback success.');
......
# Device Usage Statistics # Device Usage Statistics
> **NOTE**<br> 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. > 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. ...@@ -23,7 +41,7 @@ Checks whether the application specified by **bundleName** is in the idle state.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ---------------------------- | ---- | ---------------------------------------- | | ---------- | ---------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. | | bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. If the value of **bundleName** is valid, **null** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. If the value of <b class="+ topic/ph hi-d/b " id="b597417553714">bundleName</b> is valid, <b class="+ topic/ph hi-d/b " id="b1897411555719">null</b> will be returned.|
**Example** **Example**
...@@ -69,7 +87,7 @@ Checks whether the application specified by **bundleName** is in the idle state. ...@@ -69,7 +87,7 @@ Checks whether the application specified by **bundleName** is in the idle state.
## bundleState.queryAppUsagePriorityGroup ## bundleState.queryAppUsagePriorityGroup
queryAppUsagePriorityGroup(): Promise\<number> queryAppUsagePriorityGroup(): Promise&lt;number&gt;
Queries the priority group of this application. This API uses a promise to return the result. 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 ...@@ -79,7 +97,7 @@ Queries the priority group of this application. This API uses a promise to retur
| Type | Description | | Type | Description |
| --------------- | --------------------------- | | --------------- | --------------------------- |
| Promise\<number> | Promise used to return the result.| | Promise&lt;number&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -93,7 +111,7 @@ bundleState.queryAppUsagePriorityGroup().then( res => { ...@@ -93,7 +111,7 @@ bundleState.queryAppUsagePriorityGroup().then( res => {
## bundleState.queryAppUsagePriorityGroup ## bundleState.queryAppUsagePriorityGroup
queryAppUsagePriorityGroup(callback: AsyncCallback\<number>): void queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void
Queries the priority group of this application. This API uses an asynchronous callback to return the result. 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 ...@@ -103,20 +121,11 @@ Queries the priority group of this application. This API uses an asynchronous ca
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------- | ---- | -------------------------- | | -------- | --------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```javascript ```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) => { bundleState.queryAppUsagePriorityGroup((err, res) => {
if(err) { if(err) {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code); 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 ...@@ -523,7 +532,7 @@ Obtains the number of FA usage records specified by **maxNum**. This API uses an
## bundleState.queryAppUsagePriorityGroup<sup>9+</sup> ## bundleState.queryAppUsagePriorityGroup<sup>9+</sup>
queryAppUsagePriorityGroup(bundleName? : string): Promise<number> queryAppUsagePriorityGroup(bundleName? : string): Promise&lt;number&gt;
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. 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 ** ...@@ -543,13 +552,14 @@ Queries the priority group of the application specified by **bundleName**. If **
| Type | Description | | Type | Description |
| --------------- | --------------------------- | | --------------- | --------------------------- |
| Promise\<number> | Promise used to return the result.| | Promise&lt;number&gt; | Promise used to return the result.|
**Example** **Example**
```javascript ```javascript
// Promise with bundleName // 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)); 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); console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
...@@ -564,7 +574,7 @@ bundleState.queryAppUsagePriorityGroup().then( res => { ...@@ -564,7 +574,7 @@ bundleState.queryAppUsagePriorityGroup().then( res => {
## bundleState.queryAppUsagePriorityGroup<sup>9+</sup> ## bundleState.queryAppUsagePriorityGroup<sup>9+</sup>
queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback\<number>): void queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback&lt;number&gt;): 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. 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 ** ...@@ -579,13 +589,14 @@ Queries the priority group of the application specified by **bundleName**. If **
| Name | Type | Mandatory | Description | | 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.| | 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\<number> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result. |
**Example** **Example**
```javascript ```javascript
// Callback with bundleName // Callback with bundleName
bundleState.queryAppUsagePriorityGroup(this.bundleName, (err, res) => { let bundleName = "com.ohos.camera";
bundleState.queryAppUsagePriorityGroup(bundleName, (err, res) => {
if(err) { if(err) {
console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
} else { } else {
...@@ -604,7 +615,7 @@ bundleState.queryAppUsagePriorityGroup((err, res) => { ...@@ -604,7 +615,7 @@ bundleState.queryAppUsagePriorityGroup((err, res) => {
## bundleState.setBundleGroup<sup>9+</sup> ## bundleState.setBundleGroup<sup>9+</sup>
setBundleGroup(bundleName: string, newGroup: GroupType): Promise\<void> setBundleGroup(bundleName: string, newGroup: GroupType): Promise&lt;void&gt;
Sets the group for the application specified by **bundleName**. This API uses a promise to return the result. 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 ...@@ -618,22 +629,22 @@ Sets the group for the application specified by **bundleName**. This API uses a
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | --------- | ---- | ---- | | ---------- | --------- | ---- | ---- |
| bundleName | string | Yes | Bundle name of the target application.| | bundleName | string | Yes | Bundle name of an application.|
| newGroup | GroupType | Yes | Application group.| | newGroup | [GroupType](#grouptype) | Yes | Application group.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ------------------------- | | ------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```javascript ```javascript
this.bundleName = "com.example.deviceUsageStatistics"; let bundleName = "com.example.deviceUsageStatistics";
this.newGroup = stats.GroupType.ACTIVE_GROUP_DAILY; 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.'); console.log('BUNDLE_ACTIVE SetBundleGroup promise succeeded.');
}).catch( err => { }).catch( err => {
console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code);
...@@ -642,7 +653,7 @@ bundleState.setBundleGroup(this.bundleName, this.newGroup).then( () => { ...@@ -642,7 +653,7 @@ bundleState.setBundleGroup(this.bundleName, this.newGroup).then( () => {
## bundleState.setBundleGroup<sup>9+</sup> ## bundleState.setBundleGroup<sup>9+</sup>
setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback\<void>): void setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback&lt;void&gt;): void
Sets the group for the application specified by **bundleName**. This API uses an asynchronous callback to return the result. 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 ...@@ -656,17 +667,17 @@ Sets the group for the application specified by **bundleName**. This API uses an
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ------------------- | ---- | ------------------------- | | ---------- | ------------------- | ---- | ------------------------- |
| bundleName | string | Yes | Bundle name of the target application. | | bundleName | string | Yes | Bundle name of an application. |
| newGroup | GroupType | Yes | Application group. | | newGroup | [GroupType](#grouptype) | Yes | Application group. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```javascript ```javascript
this.bundleName = "com.example.deviceUsageStatistics"; let bundleName = "com.example.deviceUsageStatistics";
this.newGroup = stats.GroupType.ACTIVE_GROUP_DAILY; let newGroup = bundleState.GroupType.ACTIVE_GROUP_DAILY;
bundleState.setBundleGroup(this.bundleName, this.newGroup, (err) => { bundleState.setBundleGroup(bundleName, newGroup, (err) => {
if(err) { if(err) {
console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code);
} else { } else {
...@@ -677,9 +688,9 @@ bundleState.setBundleGroup(this.bundleName, this.newGroup, (err) => { ...@@ -677,9 +688,9 @@ bundleState.setBundleGroup(this.bundleName, this.newGroup, (err) => {
## bundleState.registerGroupCallBack<sup>9+</sup> ## bundleState.registerGroupCallBack<sup>9+</sup>
registerGroupCallBack(callback: Callback\<BundleActiveGroupCallbackInfo>): Promise\<void> registerGroupCallBack(callback: Callback&lt;BundleActiveGroupCallbackInfo&gt;): Promise&lt;void&gt;
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 **Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO
...@@ -689,26 +700,26 @@ Registers a callback for application group changes. When an application group of ...@@ -689,26 +700,26 @@ Registers a callback for application group changes. When an application group of
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ----------- | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
| callback | Callback\<BundleActiveGroupCallbackInfo> | Yes | Callback for application group changes.| | callback | Callback&lt;[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)&gt; | Yes | Callback used to return the application group changes.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ----------------------- | | ------------- | ----------------------- |
| Promise\<void> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```javascript ```javascript
let onBundleGroupChanged = (err,res) =>{ let onBundleGroupChanged = (err,res) =>{
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result oldGroup is : ' + res.oldGroup); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageOldGroup is : ' + res.appUsageOldGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result newGroup is : ' + res.newGroup); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageNewGroup is : ' + res.appUsageNewGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result changeReason is : ' + res.newGroup); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result changeReason is : ' + res.changeReason);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result userId is : ' + res.userId); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result userId is : ' + res.userId);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result bundleName is : ' + res.bundleName); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result bundleName is : ' + res.bundleName);
}; };
bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => { bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => {
console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise succeeded.'); console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise succeeded.');
...@@ -719,9 +730,9 @@ bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => { ...@@ -719,9 +730,9 @@ bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => {
## bundleState.registerGroupCallBack<sup>9+</sup> ## bundleState.registerGroupCallBack<sup>9+</sup>
registerGroupCallBack(callback: Callback\<BundleActiveGroupCallbackInfo>, callback: AsyncCallback\<void>): void registerGroupCallBack(callback: Callback&lt;BundleActiveGroupCallbackInfo&gt;, callback: AsyncCallback&lt;void&gt;): 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 **Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO
...@@ -731,21 +742,21 @@ Registers a callback for application group changes. When an application group of ...@@ -731,21 +742,21 @@ Registers a callback for application group changes. When an application group of
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------- | | -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
| callback | Callback\<BundleActiveGroupCallbackInfo> | Yes | Callback for application group changes. | | callback | Callback&lt;[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)&gt; | Yes | Callback used to return the application group changes. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```javascript ```javascript
let onBundleGroupChanged = (err,res) =>{ let onBundleGroupChanged = (err,res) =>{
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's oldGroup is : ' + res.oldGroup); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageOldGroup is : ' + res.appUsageOldGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's newGroup is : ' + res.newGroup); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageNewGroup is : ' + res.appUsageNewGroup);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's changeReason is : ' + res.newGroup); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result changeReason is : ' + res.changeReason);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's userId is : ' + res.userId); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result userId is : ' + res.userId);
console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack result's bundleName is : ' + res.bundleName); console.log('BUNDLE_ACTIVE RegisterGroupCallBack result bundleName is : ' + res.bundleName);
}; };
bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{ bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{
if(err) { if(err) {
...@@ -758,7 +769,7 @@ bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{ ...@@ -758,7 +769,7 @@ bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{
## bundleState.unRegisterGroupCallBack<sup>9+</sup> ## bundleState.unRegisterGroupCallBack<sup>9+</sup>
unRegisterGroupCallBack(): Promise\<void> unRegisterGroupCallBack(): Promise&lt;void&gt;
Deregisters the callback for application group changes. This API uses a promise to return the result. 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 ...@@ -774,7 +785,7 @@ Deregisters the callback for application group changes. This API uses a promise
| Type | Description | | Type | Description |
| ------------- | ------------------------ | | ------------- | ------------------------ |
| Promise\<void> | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -788,7 +799,7 @@ bundleState.unRegisterGroupCallBack().then( () => { ...@@ -788,7 +799,7 @@ bundleState.unRegisterGroupCallBack().then( () => {
## bundleState.unRegisterGroupCallBack<sup>9+</sup> ## bundleState.unRegisterGroupCallBack<sup>9+</sup>
unRegisterGroupCallBack(callback: AsyncCallback\<void>): void; unRegisterGroupCallBack(callback: AsyncCallback&lt;void&gt;): void;
Deregisters the callback for application group changes. This API uses an asynchronous callback to return the result. 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 ...@@ -802,7 +813,7 @@ Deregisters the callback for application group changes. This API uses an asynchr
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------- | ---- | -------------- | | -------- | ------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -870,7 +881,7 @@ Queries statistics about system events (hibernation, wakeup, unlocking, and scre ...@@ -870,7 +881,7 @@ Queries statistics about system events (hibernation, wakeup, unlocking, and scre
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| begin | number | Yes | Start time. | | begin | number | Yes | Start time. |
| end | number | Yes | End time. | | end | number | Yes | End time. |
| callback | AsyncCallback&lt;Array&lt;[BundleActiveEventState](#bundleactiveeventstate9)&gt;&gt; | Yes | Promise used to return the result.| | callback | AsyncCallback&lt;Array&lt;[BundleActiveEventState](#bundleactiveeventstate9)&gt;&gt; | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -982,7 +993,7 @@ Provides the FA widget usage information. ...@@ -982,7 +993,7 @@ Provides the FA widget usage information.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------------- | ------ | ---- | ----------- | | ---------------- | ------ | ---- | ----------- |
| formName | number | Yes | Widget name. | | formName | string | Yes | Widget name. |
| formDimension | number | Yes | Widget dimensions. | | formDimension | number | Yes | Widget dimensions. |
| formId | number | Yes | Widget ID. | | formId | number | Yes | Widget ID. |
| formLastUsedTime | number | Yes | Last time when the widget was clicked.| | formLastUsedTime | number | Yes | Last time when the widget was clicked.|
...@@ -992,15 +1003,15 @@ Provides the FA widget usage information. ...@@ -992,15 +1003,15 @@ Provides the FA widget usage information.
Provides the application group changes returned through a callback. 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 | | Name | Type | Mandatory| Description |
| ---------------- | ------ | ---- | -------- | | ---------------- | ------ | ---- | ---------------- |
| appUsageOldGroup | number | Yes | Application group before the change.| | appUsageOldGroup | number | Yes | Application group before the change.|
| appUsageNewGroup | number | Yes | Application group after the change.| | appUsageNewGroup | number | Yes | Application group after the change.|
| useId | number | Yes | User ID. | | userId | number | Yes | User ID. |
| changeReason | number | Yes | Reason for the group change. | | changeReason | number | Yes | Reason for the group change. |
| bundleName | string | Yes | Bundle name of an application. | | bundleName | string | Yes | Bundle name of an application. |
## BundleStateInfo ## BundleStateInfo
...@@ -1008,11 +1019,11 @@ Provides the usage duration information of applications. ...@@ -1008,11 +1019,11 @@ Provides the usage duration information of applications.
### Attributes ### Attributes
**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup **System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App
| Name | Type | Mandatory | Description | | 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. | | abilityPrevAccessTime | number | Yes | Last time when the application was used. |
| abilityInFgTotalTime | number | Yes | Total time that the application runs in the foreground. | | abilityInFgTotalTime | number | Yes | Total time that the application runs in the foreground. |
| id | number | No | User ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.| | id | number | No | User ID.<br>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 ...@@ -1029,8 +1040,6 @@ merge(toMerge: BundleStateInfo): void
Merges the application usage information that has the same bundle name. 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 **System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App
**Parameters** **Parameters**
...@@ -1047,7 +1056,7 @@ Provides information about an application event. ...@@ -1047,7 +1056,7 @@ Provides information about an application event.
| Name | Type | Mandatory | Description | | 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. | | stateType | number | Yes | Application event type. |
| stateOccurredTime | number | Yes | Timestamp when the application event occurs. | | stateOccurredTime | number | Yes | Timestamp when the application event occurs. |
| appUsagePriorityGroup | number | No | Usage priority group of the application.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.| | appUsagePriorityGroup | number | No | Usage priority group of the application.<br>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. ...@@ -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_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. | | BY_ANNUALLY | 4 | The system obtains the application usage duration statistics in the specified time frame on an annual basis. |
## GroupType ## GroupType<sup>9+</sup>
Enumerates the application group types. Enumerates the application group types.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册