From 3abd4fec4c744c4af8693fd78d713472796cbb05 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Mon, 7 Mar 2022 21:30:26 +0800 Subject: [PATCH 1/4] modify @ohos.bundleState.d.ts Signed-off-by: wyuanchao --- .../bundlestats/js/@ohos.bundleState.d.ts | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index eb724fd..0734372 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -30,9 +30,7 @@ declare namespace bundleState { /** * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App */ interface BundleStateInfo { /** @@ -83,9 +81,7 @@ declare namespace bundleState { * The bundle name of both objects must be the same. * * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App * @param toMerge Indicates the {@link BundleActiveInfo} object to merge. * if the bundle names of the two {@link BundleActiveInfo} objects are different. */ @@ -94,9 +90,7 @@ declare namespace bundleState { /** * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App */ interface BundleActiveState { /** @@ -129,9 +123,7 @@ declare namespace bundleState { * Checks whether the application with a specified bundle name is in the idle state. * * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup * @param bundleName Indicates the bundle name of the application to query. * @return Returns {@code true} if the application is idle in a particular period; * returns {@code false} otherwise. The time range of the particular period is defined by the system, @@ -147,9 +139,7 @@ declare namespace bundleState { * for example, restricting the running of background tasks.

* * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup * @return Returns the usage priority group of the calling application. */ function queryAppUsagePriorityGroup(callback: AsyncCallback): void; @@ -157,9 +147,7 @@ declare namespace bundleState { /** * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App */ interface BundleActiveInfoResponse { [key: string]: BundleStateInfo; @@ -171,8 +159,8 @@ declare namespace bundleState { *

This method queries usage information at the {@link #BY_OPTIMIZED} interval by default.

* * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @permission ohos.permission.BUNDLE_ACTIVE_INFO * @systemapi Hide this for inner system use. * @param begin Indicates the start time of the query period, in milliseconds. * @param end Indicates the end time of the query period, in milliseconds. @@ -185,9 +173,7 @@ declare namespace bundleState { * Declares interval type. * * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App */ export enum IntervalType { /** @@ -220,8 +206,8 @@ declare namespace bundleState { * Queries usage information about each bundle within a specified period at a specified interval. * * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @permission ohos.permission.BUNDLE_ACTIVE_INFO * @systemapi Hide this for inner system use. * @param byInterval Indicates the interval at which the usage statistics are queried. * The value can be {@link #BY_OPTIMIZED}, {@link #BY_DAILY}, @@ -237,8 +223,8 @@ declare namespace bundleState { * Queries state data of all bundles within a specified period identified by the start and end time. * * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @permission ohos.permission.BUNDLE_ACTIVE_INFO * @systemapi Hide this for inner system use. * @param begin Indicates the start time of the query period, in milliseconds. * @param end Indicates the end time of the query period, in milliseconds. @@ -251,9 +237,7 @@ declare namespace bundleState { * Queries state data of the current bundle within a specified period. * * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App. - * @permission ohos.permission.BUNDLE_ACTIVE_INFO. - * @systemapi Hide this for inner system use. + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App * @param begin Indicates the start time of the query period, in milliseconds. * @param end Indicates the end time of the query period, in milliseconds. * @return Returns the {@link BundleActiveState} object Array containing the state data of the current bundle. -- Gitee From bbee1866c5a9c6b8ac15956f16de02a50867cdd3 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Mon, 7 Mar 2022 22:25:20 +0800 Subject: [PATCH 2/4] modify codex Signed-off-by: wyuanchao --- frameworks/src/bundle_state_query.cpp | 60 +++++++++++++-------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 2a30443..b9218b9 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -22,26 +22,26 @@ namespace OHOS { namespace DeviceUsageStats { -const u_int32_t Is_Idle_State_MIN_PARAMS = 1; -const u_int32_t Is_Idle_State_PARAMS = 2; -const u_int32_t Priority_Group_MIN_PARAMS = 0; -const u_int32_t Priority_Group_PARAMS = 1; -const u_int32_t States_MIN_PARAMS = 2; -const u_int32_t States_PARAMS = 3; -const u_int32_t App_Usage_MIN_PARAMS_BY_INTERVAL = 3; -const u_int32_t App_Usage_PARAMS_BY_INTERVAL = 4; -const u_int32_t App_Usage_MIN_PARAMS = 2; -const u_int32_t App_Usage_PARAMS = 3; +const u_int32_t IS_IDLE_STATE_MIN_PARAMS = 1; +const u_int32_t IS_IDLE_STATE_PARAMS = 2; +const u_int32_t PRIORITY_GROUP_MIN_PARAMS = 0; +const u_int32_t PRIORITY_GROUP_PARAMS = 1; +const u_int32_t STATES_MIN_PARAMS = 2; +const u_int32_t STATES_PARAMS = 3; +const u_int32_t APP_USAGE_MIN_PARAMS_BY_INTERVAL = 3; +const u_int32_t APP_USAGE_PARAMS_BY_INTERVAL = 4; +const u_int32_t APP_USAGE_MIN_PARAMS = 2; +const u_int32_t APP_USAGE_PARAMS = 3; const u_int32_t SECOND_ARG = 2; const u_int32_t THIRD_ARG = 3; napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_info &info, IsIdleStateParamsInfo ¶ms) { - size_t argc = Is_Idle_State_PARAMS; - napi_value argv[Is_Idle_State_PARAMS] = {nullptr}; + size_t argc = IS_IDLE_STATE_PARAMS; + napi_value argv[IS_IDLE_STATE_PARAMS] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - NAPI_ASSERT(env, argc == Is_Idle_State_MIN_PARAMS || argc == Is_Idle_State_PARAMS, + NAPI_ASSERT(env, argc == IS_IDLE_STATE_MIN_PARAMS || argc == IS_IDLE_STATE_PARAMS, "Invalid number of parameters"); // argv[0] : bundleName @@ -59,7 +59,7 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i } // argv[1]: callback - if (argc == Is_Idle_State_PARAMS) { + if (argc == IS_IDLE_STATE_PARAMS) { napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, @@ -129,14 +129,14 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) napi_value ParsePriorityGroupParameters(const napi_env &env, const napi_callback_info &info, PriorityGroupParamsInfo ¶ms) { - size_t argc = Priority_Group_PARAMS; - napi_value argv[Priority_Group_PARAMS] = {nullptr}; + size_t argc = PRIORITY_GROUP_PARAMS; + napi_value argv[PRIORITY_GROUP_PARAMS] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - NAPI_ASSERT(env, argc == Priority_Group_MIN_PARAMS || argc == Priority_Group_PARAMS, + NAPI_ASSERT(env, argc == PRIORITY_GROUP_MIN_PARAMS || argc == PRIORITY_GROUP_PARAMS, "Invalid number of parameters"); // argv[0]: callback - if (argc == Priority_Group_PARAMS) { + if (argc == PRIORITY_GROUP_PARAMS) { napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParsePriorityGroupParameters invalid parameter type. " @@ -198,10 +198,10 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info) napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info &info, StatesParamsInfo ¶ms) { - size_t argc = States_PARAMS; - napi_value argv[States_PARAMS] = {nullptr}; + size_t argc = STATES_PARAMS; + napi_value argv[STATES_PARAMS] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - NAPI_ASSERT(env, argc == States_MIN_PARAMS || argc == States_PARAMS, + NAPI_ASSERT(env, argc == STATES_MIN_PARAMS || argc == STATES_PARAMS, "Invalid number of parameters"); // argv[0] : beginTime @@ -233,7 +233,7 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info & } // argv[SECOND_ARG]: callback - if (argc == States_PARAMS) { + if (argc == STATES_PARAMS) { napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParseStatesParameters invalid parameter type. " @@ -377,10 +377,10 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_callback_info &info, AppUsageParamsByIntervalInfo ¶ms) { - size_t argc = App_Usage_PARAMS_BY_INTERVAL; - napi_value argv[App_Usage_PARAMS_BY_INTERVAL] = {nullptr}; + size_t argc = APP_USAGE_PARAMS_BY_INTERVAL; + napi_value argv[APP_USAGE_PARAMS_BY_INTERVAL] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - NAPI_ASSERT(env, argc == App_Usage_MIN_PARAMS_BY_INTERVAL || argc == App_Usage_PARAMS_BY_INTERVAL, + NAPI_ASSERT(env, argc == APP_USAGE_MIN_PARAMS_BY_INTERVAL || argc == APP_USAGE_PARAMS_BY_INTERVAL, "Invalid number of parameters"); // argv[0] : intervalType @@ -424,7 +424,7 @@ napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_cal } // argv[THIRD_ARG]: callback - if (argc == App_Usage_PARAMS_BY_INTERVAL) { + if (argc == APP_USAGE_PARAMS_BY_INTERVAL) { napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[THIRD_ARG], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParseAppUsageParametersByInterval invalid parameter type. " @@ -503,10 +503,10 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info &info, AppUsageParamsInfo ¶ms) { - size_t argc = App_Usage_PARAMS; - napi_value argv[App_Usage_PARAMS] = {nullptr}; + size_t argc = APP_USAGE_PARAMS; + napi_value argv[APP_USAGE_PARAMS] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - NAPI_ASSERT(env, argc == App_Usage_MIN_PARAMS || argc == App_Usage_PARAMS, + NAPI_ASSERT(env, argc == APP_USAGE_MIN_PARAMS || argc == APP_USAGE_PARAMS, "Invalid number of parameters"); // argv[0] : beginTime @@ -538,7 +538,7 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info } // argv[SECOND_ARG]: callback - if (argc == App_Usage_PARAMS) { + if (argc == APP_USAGE_PARAMS) { napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParseAppUsageParameters invalid parameter type. " -- Gitee From 12a091b23a416ec60d4f33df32a548fde244ea7b Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Tue, 8 Mar 2022 09:07:56 +0800 Subject: [PATCH 3/4] modify file Signed-off-by: wyuanchao --- README.md | 22 ++++++++++------------ README_ZH.md | 24 +++++++++++------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 23a3e1c..5337ed0 100644 --- a/README.md +++ b/README.md @@ -18,16 +18,15 @@ the component will be periodically refreshed to the database for persistent stor ``` /foundation/resourceschedule/device_usage_statistics -├── ohos.build # Compilation script ├── BUILD.gn # Module compilation script +├── LICENSE # Open source protocol +├── adapter # Adaptation directory +├── bundle.json # Component decoupling and compiling script +├── frameworks # Framework layer directory ├── interfaces -│ ├── innerkits # Internal interface directory -│ └── kits # External interface directory +│   ├── innerkits # Internal interface directory +│   └── kits # External interface directory ├── services # Service layer directory -├── frameworks -│ ├── JS # External JS interface implementation directory -│ └── native # External native interface implementation directory -├── adapter # Adaptation directory └── test # Testing case directory ``` @@ -45,20 +44,20 @@ Taking app usage interface as an example, the main exposed interfaces are as fol -

queryBundleActiveStates(begin::number, end::number, callback:AsyncCallback<Array<BundleActiveState>>):void

+

queryBundleActiveStates(begin:number, end:number, callback:AsyncCallback<Array<BundleActiveState>>):void

Queries the event collection of all applications through time interval.

-

queryBundleStateInfos(begin::number, end::number, callback:AsyncCallback<BundleStateInfoResponse>):void

+

queryBundleStateInfos(begin:number, end:number, callback:AsyncCallback<BundleStateInfoResponse>):void

Uses the start and end time to query the application usage time statistics.

-

queryCurrentBundleActiveStates(begin::number, end::number, callback:AsyncCallback<Array<BundleActiveState>>):void

+

queryCurrentBundleActiveStates(begin:number, end:number, callback:AsyncCallback<Array<BundleActiveState>>):void

Queries the event collection of the current application through the time interval.

-

queryBundleStateInfoByInterval(byInterval:intervalType, begin::number, end::number, callback:AsyncCallback<Array<BundleStateInfo>>):void

+

queryBundleStateInfoByInterval(byInterval:intervalType, begin:number, end:number, callback:AsyncCallback<Array<BundleStateInfo>>):void

Queries application usage duration statistics by time interval.

queryAppUsagePriorityGroup(callback:AsyncCallback<number>):void

@@ -76,7 +75,6 @@ Taking app usage interface as an example, the main exposed interfaces are as fol There are many interfaces for device usage statistics. Take app usage interface as an example to introduce the interface logic. -- **running process**:The device usage statistics service starts and runs in the foundation process. - **device usage statistics saving time**: >1. refreshing is triggered every 30 minutes; >2. refreshing is triggered when system time changes; diff --git a/README_ZH.md b/README_ZH.md index 8d12502..8692a54 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -16,16 +16,15 @@ ``` /foundation/resourceschedule/device_usage_statistics -├── ohos.build # 编译脚本 ├── BUILD.gn # 模块编译脚本 +├── LICENSE # 开源协议 +├── adapter # 适配目录 +├── bundle.json # 部件化解耦及编译脚本 +├── frameworks # 框架层目录 ├── interfaces -│ ├── innerkits # 对内接口目录 -│ └── kits # 对外接口目录 +│   ├── innerkits # 对内接口目录 +│   └── kits # 对外接口目录 ├── services # 服务层目录 -├── frameworks -│ ├── JS # 对外JS接口实现目录 -│ └── native # 对外Native接口实现目录 -├── adapter # 适配目录 └── test # 测试用例目录 ``` @@ -42,20 +41,20 @@ -

queryBundleActiveStates(begin::number, end::number, callback:AsyncCallback<Array<BundleActiveState>>):void

+

queryBundleActiveStates(begin:number, end:number, callback:AsyncCallback<Array<BundleActiveState>>):void

通过指定起始和结束时间查询所有应用的事件集合。

-

queryBundleStateInfos(begin::number, end::number, callback:AsyncCallback<BundleStateInfoResponse>):void

+

queryBundleStateInfos(begin:number, end:number, callback:AsyncCallback<BundleStateInfoResponse>):void

通过指定起始和结束时间查询应用使用时长统计信息。

-

queryCurrentBundleActiveStates(begin::number, end::number, callback:AsyncCallback<Array<BundleActiveState>>):void

+

queryCurrentBundleActiveStates(begin:number, end:number, callback:AsyncCallback<Array<BundleActiveState>>):void

通过指定起始和结束时间查询当前应用的事件集合。

-

queryBundleStateInfoByInterval(byInterval:intervalType, begin::number, end::number, callback:AsyncCallback<Array<BundleStateInfo>>):void

+

queryBundleStateInfoByInterval(byInterval:intervalType, begin:number, end:number, callback:AsyncCallback<Array<BundleStateInfo>>):void

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

queryAppUsagePriorityGroup(callback:AsyncCallback<number>):void

@@ -73,7 +72,6 @@ 设备使用信息统计接口众多,以应用使用详情(app usage)接口为例,介绍接口逻辑。 -- **运行进程**:设备使用信息统计服务在foundation进程启动和运行。 - **应用使用统计信息落盘时机**: >1. 每隔30分钟触发一次刷新; >2. 系统时间变更触发一次刷新; @@ -84,7 +82,7 @@ >3. 根据起止时间查询当前应用的事件集合; >4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长; >5. 查询调用者应用的优先级群组; ->5. 判断指定应用当前是否是空闲状态; +>6. 判断指定应用当前是否是空闲状态; ## 相关仓 -- Gitee From bb41f57a59c37ee77188bb659633aedba4d1a9e7 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Tue, 8 Mar 2022 17:22:27 +0800 Subject: [PATCH 4/4] modify file Signed-off-by: wyuanchao --- services/common/src/bundle_active_usage_database.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 8bd55c2..3e7b1dc 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -886,6 +886,7 @@ int32_t BundleActiveUsageDatabase::GetOptimalIntervalType(int64_t beginTime, int } } } + BUNDLE_ACTIVE_LOGI("optimalIntervalType is %{public}d", optimalIntervalType); return optimalIntervalType; } -- Gitee