From f095f6d6f4da13323fe9067cfe589d70785e966e Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 10 Jun 2022 16:03:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Atdd=E4=BF=AE=E6=94=B9=E5=92=8Creadme=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- README.md | 6 +++ README_zh.md | 6 +++ .../src/bundle_active_group_observer.cpp | 46 ++++++++++--------- frameworks/src/bundle_state_query.cpp | 3 +- .../bundlestats/js/@ohos.bundleState.d.ts | 13 +++--- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 59fc520..1e6eb13 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

Queries application usage duration statistics by time interval(callback).

queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStateInfo>>

Queries application usage duration statistics by time interval(Promise).

+

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

+

Query the priority group of the application.

+

queryAppUsagePriorityGroup(): Promise<number>

+

Query the priority group of the application.

isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void

Judges whether the application of the specified bundle name is currently idle(callback).

isIdleState(bundleName: string): Promise<boolean>

@@ -98,6 +102,7 @@ Taking app usage interface as an example, the main exposed interfaces are as fol + ### Usage Guidelines There are many interfaces for device usage statistics. Take app usage interface as an example to introduce the interface logic. @@ -111,6 +116,7 @@ There are many interfaces for device usage statistics. Take app usage interface >2. Query the usage duration of the application according to the start and end time; >3. Query the event collection of the current application according to the start and end time; >4. Query the usage duration of the application according to the type of interval (day, week, month, year) and the start and end time; +>4. Query the priority group of the application; >5. Judge whether the specified application is currently idle; >6. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time; >7. Query the application notification times according to the start and end time; diff --git a/README_zh.md b/README_zh.md index dd85e86..e94f60a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -58,6 +58,10 @@

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(callback形式)。

queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStateInfo>>

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(Promise形式)。

+

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

+

查询当前应用的优先级分组(callback形式)。

+

queryAppUsagePriorityGroup(): Promise<number>

+

查询当前应用的优先级分组(Promise形式)。

isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void

判断指定Bundle Name的应用当前是否是空闲状态(callback形式)。

isIdleState(bundleName: string): Promise<boolean>

@@ -96,6 +100,7 @@ + ### 使用说明 设备使用信息统计接口众多,以应用使用详情(app usage)接口为例,介绍接口逻辑。 @@ -109,6 +114,7 @@ >2. 根据起止时间查询应用的使用时长; >3. 根据起止时间查询当前应用的事件集合; >4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长; +>4. 查询当前应用的优先级分组; >5. 判断指定应用当前是否是空闲状态; >6. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息; >7. 根据起止时间查询应用通知次数; diff --git a/frameworks/src/bundle_active_group_observer.cpp b/frameworks/src/bundle_active_group_observer.cpp index e30f620..1a15740 100644 --- a/frameworks/src/bundle_active_group_observer.cpp +++ b/frameworks/src/bundle_active_group_observer.cpp @@ -48,6 +48,27 @@ void BundleActiveGroupObserver::SetCallbackInfo(const napi_env &env, const napi_ bundleGroupCallbackInfo_.ref = ref; } +template +napi_value AsyncInit(napi_env env, PARAMT ¶ms, ASYNCT* &asyncCallbackInfo) +{ + if (params.errorCode != ERR_OK) { + return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + } + asyncCallbackInfo = new (std::nothrow) ASYNCT(env); + if (!asyncCallbackInfo) { + params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; + return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + } + if (memset_s(asyncCallbackInfo, sizeof(*asyncCallbackInfo), 0, sizeof(*asyncCallbackInfo)) + != EOK) { + params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + } + return BundleStateCommon::NapiGetNull(env); +} + napi_value SetBundleGroupChangedData(const CallbackReceiveDataWorker *commonEventDataWorkerData, napi_value &result) { BUNDLE_ACTIVE_LOGI("enter"); @@ -269,8 +290,7 @@ napi_value RegisterGroupCallBack(napi_env env, napi_callback_info info) AsyncRegisterCallbackInfo *asyncCallbackInfo = (AsyncRegisterCallbackInfo *)data; if (asyncCallbackInfo) { napi_value result = nullptr; - asyncCallbackInfo->state = (asyncCallbackInfo->errorCode == ERR_OK) ? true : false; - napi_get_boolean(env, asyncCallbackInfo->state, &result); + napi_get_null(env, &result); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -310,32 +330,17 @@ napi_value UnRegisterGroupCallBack(napi_env env, napi_callback_info info) { UnRegisterCallbackInfo params; ParseUnRegisterGroupCallBackParameters(env, info, params); - if (params.errorCode != ERR_OK) { - return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); - } if (!registerObserver) { BUNDLE_ACTIVE_LOGI("UnRegisterGroupCallBack observer is not exist"); params.errorCode = ERR_REGISTER_OBSERVER_IS_NULL; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } napi_value promise = nullptr; - AsyncUnRegisterCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncUnRegisterCallbackInfo(env); - if (!asyncCallbackInfo) { - params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; - return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); - } - if (memset_s(asyncCallbackInfo, sizeof(*asyncCallbackInfo), 0, sizeof(*asyncCallbackInfo)) - != EOK) { - params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); - } + AsyncUnRegisterCallbackInfo *asyncCallbackInfo = nullptr; + AsyncInit(env, params, asyncCallbackInfo); std::unique_ptr callbackPtr {asyncCallbackInfo}; callbackPtr->observer = registerObserver; BundleStateCommon::SettingAsyncWorkData(env, params.callback, *asyncCallbackInfo, promise); - BUNDLE_ACTIVE_LOGI("UnRegisterGroupCallBack will Async"); napi_value resourceName = nullptr; NAPI_CALL(env, napi_create_string_latin1(env, "UnRegisterGroupCallBack", NAPI_AUTO_LENGTH, &resourceName)); NAPI_CALL(env, napi_create_async_work(env, @@ -354,8 +359,7 @@ napi_value UnRegisterGroupCallBack(napi_env env, napi_callback_info info) AsyncUnRegisterCallbackInfo *asyncCallbackInfo = (AsyncUnRegisterCallbackInfo *)data; if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; - asyncCallbackInfo->state = (asyncCallbackInfo->errorCode == ERR_OK) ? true : false; - napi_get_boolean(env, asyncCallbackInfo->state, &result); + napi_get_null(env, &result); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index d0f35ed..b604db1 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -865,8 +865,7 @@ napi_value SetBundleGroup(napi_env env, napi_callback_info info) AsyncCallbackInfoSetBundleGroup *asyncCallbackInfo = (AsyncCallbackInfoSetBundleGroup *)data; if (asyncCallbackInfo) { napi_value result = nullptr; - asyncCallbackInfo->state = (asyncCallbackInfo->errorCode == ERR_OK) ? true : false; - napi_get_boolean(env, asyncCallbackInfo->state, &result); + napi_get_null(env, &result); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index 0518178..2def292 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -177,6 +177,7 @@ declare namespace bundleState { /** * @since 9 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @systemapi Hide this for inner system use. */ interface BundleActiveEventState { /** @@ -456,8 +457,8 @@ declare namespace bundleState { * @param newGroup,the group of the application whose name is bundleName. * @return Returns the result of setBundleGroup, true of false. */ - function setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback): void; - function setBundleGroup(bundleName: string, newGroup: GroupType): Promise; + function setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback): void; + function setBundleGroup(bundleName: string, newGroup: GroupType): Promise; /** * register callback to service. @@ -469,8 +470,8 @@ declare namespace bundleState { * @param Callback, callback when application group change,return the BundleActiveGroupCallbackInfo. * @return Returns BundleActiveGroupCallbackInfo when the group of bundle changed. the result of AsyncCallback is true or false. */ - function registerGroupCallBack(callback: Callback, callback: AsyncCallback): void; - function registerGroupCallBack(callback: Callback): Promise; + function registerGroupCallBack(callback: Callback, callback: AsyncCallback): void; + function registerGroupCallBack(callback: Callback): Promise; /** * unRegister callback from service. @@ -481,8 +482,8 @@ declare namespace bundleState { * @systemapi Hide this for inner system use. * @return Returns the result of unRegisterGroupCallBack, true of false. */ - function unRegisterGroupCallBack(callback: AsyncCallback): void; - function unRegisterGroupCallBack(): Promise; + function unRegisterGroupCallBack(callback: AsyncCallback): void; + function unRegisterGroupCallBack(): Promise; /* * Queries system event states data within a specified period identified by the start and end time. -- Gitee From d11fadb221b56912264abdd921ab3772cee8ec0a Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 10 Jun 2022 17:19:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Atdd=E4=BF=AE=E6=94=B9=E5=92=8Creadme=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1e6eb13..27262a6 100644 --- a/README.md +++ b/README.md @@ -84,17 +84,17 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

Query the group of the current application or the application of specified bundlename.

queryAppUsagePriorityGroup(bundleName? : string): Promise<number>

Query the group of the current application or the application of specified bundlename.

-

setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<boolean>): void

+

setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void

Set the group of the specified application as the group provided by the parameter(callback).

-

setBundleGroup(bundleName: string, newGroup: GroupType): Promise<boolean>

+

setBundleGroup(bundleName: string, newGroup: GroupType): Promise<void>

Set the group of the specified application as the group provided by the parameter(Promise).

-

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<boolean>): void

+

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<void>): void

Register callback for application group change(callback).

-

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<boolean>

+

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<void>

Register callback for application group change(Promise).

-

unRegisterGroupCallBack(callback: AsyncCallback<boolean>): void

+

unRegisterGroupCallBack(callback: AsyncCallback<void>): void

Unregister the registered application group callback(callback).

-

unRegisterGroupCallBack(): Promise<boolean>

+

unRegisterGroupCallBack(): Promise<void>

Unregister the registered application group callback(Promise).

@@ -116,14 +116,14 @@ There are many interfaces for device usage statistics. Take app usage interface >2. Query the usage duration of the application according to the start and end time; >3. Query the event collection of the current application according to the start and end time; >4. Query the usage duration of the application according to the type of interval (day, week, month, year) and the start and end time; ->4. Query the priority group of the application; ->5. Judge whether the specified application is currently idle; ->6. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time; ->7. Query the application notification times according to the start and end time; ->8. Query FA usage records. The maximum returned quantity does not exceed the value set by maxnum. FA usage records are sorted from near to far. The maximum maxnum is 1000. If the maxnum parameter is not filled in, the default maxnum is 1000; ->9. Query the group of the current application or the application of specified bundlename; ->10. Set the group of the specified application as the group provided by the parameter; ->11. Register callback for application group change; +>5. Query the priority group of the application; +>6. Judge whether the specified application is currently idle; +>7. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time; +>8. Query the application notification times according to the start and end time; +>9. Query FA usage records. The maximum returned quantity does not exceed the value set by maxnum. FA usage records are sorted from near to far. The maximum maxnum is 1000. If the maxnum parameter is not filled in, the default maxnum is 1000; +>10. Query the group of the current application or the application of specified bundlename; +>11. Set the group of the specified application as the group provided by the parameter; +>12. Register callback for application group change; >13. Unregister the registered application group callback; ## Repositories Involved -- Gitee From aa8da10b3d348d2f2c86568cdfe9de309388ca72 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 10 Jun 2022 17:21:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Atdd=E4=BF=AE=E6=94=B9=E5=92=8Creadme=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- README_zh.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README_zh.md b/README_zh.md index e94f60a..9fabc00 100644 --- a/README_zh.md +++ b/README_zh.md @@ -82,17 +82,17 @@

使用可选参数查询当前调用者应用的使用优先级群组(callback形式)。

queryAppUsagePriorityGroup(bundleName? : string): Promise<number>

使用可选参数查询当前调用者应用的使用优先级群组(Promise形式)。

-

setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<boolean>): void

+

setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void

将指定应用的分组设置为参数提供的分组(callback形式)。

-

setBundleGroup(bundleName: string, newGroup: GroupType): Promise<boolean>

+

setBundleGroup(bundleName: string, newGroup: GroupType): Promise<void>

将指定应用的分组设置为参数提供的分组(Promise形式)。

-

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<boolean>): void

+

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<void>): void

给应用分组变化注册回调(callback形式)。

-

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<boolean>

+

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<void>

给应用分组变化注册回调(Promise形式)。

-

unRegisterGroupCallBack(callback: AsyncCallback<boolean>): void

+

unRegisterGroupCallBack(callback: AsyncCallback<void>): void

将已注册过的应用分组回调解除注册(callback形式)。

-

unRegisterGroupCallBack(): Promise<boolean>

+

unRegisterGroupCallBack(): Promise<void>

将已注册过的应用分组回调解除注册(Promise形式)。

@@ -114,14 +114,14 @@ >2. 根据起止时间查询应用的使用时长; >3. 根据起止时间查询当前应用的事件集合; >4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长; ->4. 查询当前应用的优先级分组; ->5. 判断指定应用当前是否是空闲状态; ->6. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息; ->7. 根据起止时间查询应用通知次数; ->8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000; ->9. 查询当前应用或指定bundlename对应的应用的分组; ->10. 将指定应用的分组设置为参数提供的分组; ->11. 给应用分组变化注册回调; +>5. 查询当前应用的优先级分组; +>6. 判断指定应用当前是否是空闲状态; +>7. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息; +>8. 根据起止时间查询应用通知次数; +>9. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000; +>10. 查询当前应用或指定bundlename对应的应用的分组; +>11. 将指定应用的分组设置为参数提供的分组; +>12. 给应用分组变化注册回调; >13. 将已注册过的应用分组回调解除注册; ## 相关仓 -- Gitee