diff --git a/BUILD.gn b/BUILD.gn
index 5a542017679de70b9e634a39e1ec2f3d6bde2da7..cf37d4bd1a33e1a6aee7b57d512f276d010cdd1d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -41,6 +41,9 @@ ohos_shared_library("usagestatsinner") {
"samgr_standard:samgr_proxy",
"utils_base:utils",
]
+
+ deps = [ ":usagestatservice" ]
+
part_name = "${device_usage_statistics_part_name}"
subsystem_name = "resourceschedule"
}
@@ -52,7 +55,7 @@ ohos_prebuilt_etc("device_usage_statistics_service_init") {
subsystem_name = "resourceschedule"
}
-ohos_shared_library("usagestatskit") {
+ohos_shared_library("bundlestate") {
sources = [
"frameworks/src/bundle_state_common.cpp",
"frameworks/src/bundle_state_init.cpp",
@@ -65,7 +68,10 @@ ohos_shared_library("usagestatskit") {
"services/packageusage/include",
]
- deps = [ "//foundation/resourceschedule/${device_usage_statistics_part_name}:usagestatsinner" ]
+ deps = [
+ ":usagestatservice",
+ ":usagestatsinner",
+ ]
external_deps = [
"dmsfwk_standard:zuri",
@@ -87,6 +93,7 @@ ohos_shared_library("usagestatservice") {
"services/common/src/bundle_active_binary_search.cpp",
"services/common/src/bundle_active_continuous_task_observer.cpp",
"services/common/src/bundle_active_core.cpp",
+ "services/common/src/bundle_active_log.cpp",
"services/common/src/bundle_active_open_callback.cpp",
"services/common/src/bundle_active_service.cpp",
"services/common/src/bundle_active_shutdown_callback_proxy.cpp",
diff --git a/bundle.json b/bundle.json
index 1dcaacce264cc21f1c00c5c2372a39d378288136..014b937c47539a991fbf1ee2fb9efc57e3ba89d0 100644
--- a/bundle.json
+++ b/bundle.json
@@ -52,7 +52,7 @@
"//foundation/resourceschedule/device_usage_statistics:usagestatservice",
"//foundation/resourceschedule/device_usage_statistics:device_usage_statistics_sa_profile",
"//foundation/resourceschedule/device_usage_statistics:device_usage_statistics_service_init",
- "//foundation/resourceschedule/device_usage_statistics:usagestatskit"
+ "//foundation/resourceschedule/device_usage_statistics:bundlestate"
],
"inner_kits": [
{
diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp
index b4908dca75b80f353ca56e4c4cb8e3d0ef00ba73..1beaff661e6df951717a28869afabec891d74600 100644
--- a/frameworks/src/bundle_state_common.cpp
+++ b/frameworks/src/bundle_state_common.cpp
@@ -109,28 +109,32 @@ void BundleStateCommon::GetBundleStateInfoByIntervalForResult(
}
}
-void BundleStateCommon::GetBundleStateInfoForResult(
- napi_env env, const std::vector &packageStats, napi_value result)
+void BundleStateCommon::GetBundleStateInfoForResult(napi_env env,
+ const std::shared_ptr> &packageStats, napi_value result)
{
- for (const auto &item : packageStats) {
+ if (packageStats == nullptr) {
+ BUNDLE_ACTIVE_LOGE("PackageStats is invalid");
+ return;
+ }
+ for (const auto &item : *packageStats) {
napi_value packageObject = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &packageObject));
napi_value bundleName = nullptr;
NAPI_CALL_RETURN_VOID(
- env, napi_create_string_utf8(env, item.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName));
+ env, napi_create_string_utf8(env, item.second.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, packageObject, "bundleName", bundleName));
napi_value abilityPrevAccessTime = nullptr;
- NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.lastTimeUsed_, &abilityPrevAccessTime));
+ NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.second.lastTimeUsed_, &abilityPrevAccessTime));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, packageObject, "abilityPrevAccessTime",
abilityPrevAccessTime));
napi_value abilityInFgTotalTime = nullptr;
- NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.totalInFrontTime_, &abilityInFgTotalTime));
+ NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.second.totalInFrontTime_, &abilityInFgTotalTime));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, packageObject, "abilityInFgTotalTime",
abilityInFgTotalTime));
- NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, item.bundleName_.c_str(), packageObject));
+ NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, item.first.c_str(), packageObject));
}
}
@@ -236,5 +240,42 @@ void BundleStateCommon::SettingCallbackPromiseInfo(
info.isCallback = false;
}
}
+
+std::shared_ptr> BundleStateCommon::GetPackageStats(
+ int64_t &beginTime, int64_t &endTime)
+{
+ std::vector packageStats =
+ BundleActiveClient::GetInstance().QueryPackageStats(INTERVAL_TYPE_DEFAULT, beginTime, endTime);
+ std::shared_ptr> mergedPackageStats =
+ std::make_shared>();
+ if (packageStats.empty()) {
+ return nullptr;
+ }
+ for (auto packageStat : packageStats) {
+ std::map::iterator iter =
+ mergedPackageStats->find(packageStat.bundleName_);
+ if (iter != mergedPackageStats->end()) {
+ MergePackageStats(iter->second, packageStat);
+ } else {
+ mergedPackageStats->
+ insert(std::pair(packageStat.bundleName_, packageStat));
+ }
+ }
+ return mergedPackageStats;
+}
+
+void BundleStateCommon::MergePackageStats(BundleActivePackageStats &left, const BundleActivePackageStats &right)
+{
+ if (left.bundleName_ != right.bundleName_) {
+ BUNDLE_ACTIVE_LOGE("Merge package stats failed, existing packageName : %{public}s,"
+ " new packageName : %{public}s,", left.bundleName_.c_str(), right.bundleName_.c_str());
+ return;
+ }
+ left.lastTimeUsed_ = std::max(left.lastTimeUsed_, right.lastTimeUsed_);
+ left.lastContiniousTaskUsed_ = std::max(left.lastContiniousTaskUsed_, right.lastContiniousTaskUsed_);
+ left.totalInFrontTime_ += right.totalInFrontTime_;
+ left.totalContiniousTaskUsedTime_ += right.totalContiniousTaskUsedTime_;
+ left.bundleStartedCount_ += right.bundleStartedCount_;
+}
} // namespace DeviceUsageStats
} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index a00cded8a064c498bdf34f8a77a6308783528747..00fd1aa3dc5813da329c39aea161ee54e7c452ef 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -17,32 +17,30 @@
#include "bundle_state_common.h"
#include "bundle_active_log.h"
-#include "bundle_active_client.h"
#include "bundle_state_data.h"
-#include "bundle_state_query.h"
namespace OHOS {
namespace DeviceUsageStats {
-static const int32_t Is_Idle_State_MIN_PARAMS = 1;
-static const int32_t Is_Idle_State_PARAMS = 2;
-static const int32_t Priority_Group_MIN_PARAMS = 0;
-static const int32_t Priority_Group_PARAMS = 1;
-static const int32_t States_MIN_PARAMS = 2;
-static const int32_t States_PARAMS = 3;
-static const int32_t App_Usage_MIN_PARAMS_BY_INTERVAL = 3;
-static const int32_t App_Usage_PARAMS_BY_INTERVAL = 4;
-static const int32_t App_Usage_MIN_PARAMS = 2;
-static const int32_t App_Usage_PARAMS = 3;
-static const int32_t SECOND_ARG = 2;
-static const int32_t THIRD_ARG = 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
@@ -58,7 +56,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, "ParseIsIdleStateParameters invalid parameter type. "
@@ -133,14 +131,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. "
@@ -211,10 +209,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
@@ -230,7 +228,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. "
@@ -379,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
@@ -404,7 +402,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. "
@@ -487,10 +485,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
@@ -506,7 +504,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. "
@@ -522,7 +520,6 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
if (ParseAppUsageParameters(env, info, params) == nullptr) {
return BundleStateCommon::JSParaError(env, params.callback);
}
-
napi_value promise = nullptr;
AsyncCallbackInfoAppUsage *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoAppUsage {.env = env, .asyncWork = nullptr};
@@ -536,10 +533,8 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->endTime: %{public}lld",
asyncCallbackInfo->endTime);
BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise);
-
napi_value resourceName = nullptr;
napi_create_string_latin1(env, "QueryBundleStateInfos", NAPI_AUTO_LENGTH, &resourceName);
-
napi_create_async_work(env,
nullptr,
resourceName,
@@ -548,10 +543,9 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->packageStats =
- BundleActiveClient::GetInstance().QueryPackageStats(INTERVAL_TYPE_DEFAULT,
- asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
+ BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
} else {
- BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos, asyncCallbackInfo == nullptr");
+ BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos asyncCallbackInfo == nullptr");
}
BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos worker pool thread execute end.");
},
@@ -559,14 +553,12 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data;
if (asyncCallbackInfo != nullptr) {
napi_value result = nullptr;
- napi_create_array(env, &result);
+ napi_create_object(env, &result);
BundleStateCommon::GetBundleStateInfoForResult(env, asyncCallbackInfo->packageStats, result);
BundleStateCommon::GetCallbackPromiseResult(env, asyncCallbackInfo->info, result);
-
if (asyncCallbackInfo->info.callback != nullptr) {
napi_delete_reference(env, asyncCallbackInfo->info.callback);
}
-
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
@@ -574,9 +566,7 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
},
(void *)asyncCallbackInfo,
&asyncCallbackInfo->asyncWork);
-
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
-
if (asyncCallbackInfo->info.isCallback) {
return BundleStateCommon::NapiGetNull(env);
} else {
diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp
index 068794f08f8d3a55148f756c3c173d4647faba60..a550088fb9f46ef5316bbc352168139d6020146a 100644
--- a/interfaces/innerkits/src/bundle_active_proxy.cpp
+++ b/interfaces/innerkits/src/bundle_active_proxy.cpp
@@ -51,7 +51,7 @@ bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName)
data.WriteString(bundleName);
Remote() -> SendRequest(IS_BUNDLE_IDLE, data, reply, option);
int32_t result = reply.ReadInt32();
- BUNDLE_ACTIVE_LOGI("BundleActiveProxy::IsBundleIdle result is %{public}d", result);
+ BUNDLE_ACTIVE_LOGI("result is %{public}d", result);
return result;
}
@@ -78,8 +78,8 @@ std::vector BundleActiveProxy::QueryPackageStats(const
}
result.push_back(*tmp);
}
- for (int i = 0; i < result.size(); i++) {
- BUNDLE_ACTIVE_LOGI("BundleActiveProxy::QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, "
+ for (uint32_t i = 0; i < result.size(); i++) {
+ BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, "
"lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, "
"totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld",
i + 1, result[i].bundleName_.c_str(), result[i].lastTimeUsed_, result[i].lastContiniousTaskUsed_,
@@ -109,8 +109,8 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi
}
result.push_back(*tmp);
}
- for (int i = 0; i < result.size(); i++) {
- BUNDLE_ACTIVE_LOGI("BundleActiveProxy::QueryEvents event id is %{public}d, bundle name is %{public}s, "
+ for (uint32_t i = 0; i < result.size(); i++) {
+ BUNDLE_ACTIVE_LOGI("QueryEvents event id is %{public}d, bundle name is %{public}s, "
"time stamp is %{public}lld", result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_);
}
return result;
@@ -153,8 +153,8 @@ std::vector BundleActiveProxy::QueryCurrentPackageStat
}
result.push_back(*tmp);
}
- for (int i = 0; i < result.size(); i++) {
- BUNDLE_ACTIVE_LOGI("BundleActiveProxy::QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, "
+ for (uint32_t i = 0; i < result.size(); i++) {
+ BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, "
"lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, "
"totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld",
i + 1, result[i].bundleName_.c_str(), result[i].lastTimeUsed_, result[i].lastContiniousTaskUsed_,
@@ -184,8 +184,9 @@ std::vector BundleActiveProxy::QueryCurrentEvents(const int64
}
result.push_back(*tmp);
}
- for (int i = 0; i < result.size(); i++) {
- BUNDLE_ACTIVE_LOGI("event id is %{public}d, bundle name is %{public}s, time stamp is %{public}lld",
+ for (uint32_t i = 0; i < result.size(); i++) {
+ BUNDLE_ACTIVE_LOGI("QueryCurrentEvents event id is %{public}d, bundle name is %{public}s,"
+ "time stamp is %{public}lld",
result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_);
}
return result;
@@ -201,7 +202,7 @@ int BundleActiveProxy::QueryPackageGroup()
}
Remote() -> SendRequest(QUERY_BUNDLE_GROUP, data, reply, option);
int32_t packageGroup = reply.ReadInt32();
- BUNDLE_ACTIVE_LOGI("BundleActiveProxy::QueryPackageGroup result is %{public}d", packageGroup);
+ BUNDLE_ACTIVE_LOGI("QueryPackageGroup result is %{public}d", packageGroup);
return packageGroup;
}
}
diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts
index e28bf6ccf5a6c0ef29c37cb7bb20b0f5f26b2119..eb724fd056044215e00f8d7b64e79b1b2906762e 100644
--- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts
+++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts
@@ -25,14 +25,14 @@ import { AsyncCallback } from './basic';
* then returns it to you.
*
* @since 7
- * @devices phone, tablet, tv, wearable, car
*/
declare namespace bundleState {
/**
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
*/
interface BundleStateInfo {
/**
@@ -83,8 +83,9 @@ declare namespace bundleState {
* The bundle name of both objects must be the same.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
* @param toMerge Indicates the {@link BundleActiveInfo} object to merge.
* if the bundle names of the two {@link BundleActiveInfo} objects are different.
*/
@@ -93,8 +94,9 @@ declare namespace bundleState {
/**
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
*/
interface BundleActiveState {
/**
@@ -127,8 +129,9 @@ declare namespace bundleState {
* Checks whether the application with a specified bundle name is in the idle state.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
* @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,
@@ -144,8 +147,9 @@ declare namespace bundleState {
* for example, restricting the running of background tasks.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
* @return Returns the usage priority group of the calling application.
*/
function queryAppUsagePriorityGroup(callback: AsyncCallback): void;
@@ -153,8 +157,9 @@ declare namespace bundleState {
/**
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
*/
interface BundleActiveInfoResponse {
[key: string]: BundleStateInfo;
@@ -166,8 +171,9 @@ declare namespace bundleState {
* This method queries usage information at the {@link #BY_OPTIMIZED} interval by default.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @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.
* @return Returns the {@link BundleActiveInfoResponse} objects containing the usage information about each bundle.
@@ -179,8 +185,9 @@ declare namespace bundleState {
* Declares interval type.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App.
+ * @permission ohos.permission.BUNDLE_ACTIVE_INFO.
+ * @systemapi Hide this for inner system use.
*/
export enum IntervalType {
/**
@@ -213,8 +220,9 @@ declare namespace bundleState {
* Queries usage information about each bundle within a specified period at a specified interval.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @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},
* {@link #BY_WEEKLY}, {@link #BY_MONTHLY}, or {@link #BY_ANNUALLY}.
@@ -229,8 +237,9 @@ 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
- * @devices phone, tablet, tv, wearable, car
+ * @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.
* @return Returns the list of {@link BundleActiveState} objects containing the state data of all bundles.
@@ -242,8 +251,9 @@ declare namespace bundleState {
* Queries state data of the current bundle within a specified period.
*
* @since 7
- * @sysCap SystemCapability.ResourceSchedule.UsageStatistics.App
- * @devices phone, tablet, tv, wearable, car
+ * @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.
* @return Returns the {@link BundleActiveState} object Array containing the state data of the current bundle.
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
index ce44bee4a78d0dfec0813df4731fb09f5b71c4a0..5e8daf4642d1195c4b1037b9515b09ffcf867404 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
@@ -16,11 +16,11 @@
#ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_COMMON_H
#define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_COMMON_H
-#include
-
+#include "bundle_active_client.h"
+#include "bundle_state_data.h"
+#include "bundle_state_query.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
-#include "bundle_state_data.h"
namespace OHOS {
namespace DeviceUsageStats {
@@ -50,8 +50,8 @@ public:
static void GetBundleStateInfoByIntervalForResult(
napi_env env, const std::vector &packageStats, napi_value result);
- static void GetBundleStateInfoForResult(
- napi_env env, const std::vector &packageStats, napi_value result);
+ static void GetBundleStateInfoForResult(napi_env env,
+ const std::shared_ptr> &packageStats, napi_value result);
static void SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, const napi_value &result);
@@ -62,6 +62,11 @@ public:
static napi_value GetInt64NumberValue(const napi_env &env, const napi_value &value, int64_t &result);
static napi_value GetInt32NumberValue(const napi_env &env, const napi_value &value, int32_t &result);
+
+ static std::shared_ptr> GetPackageStats(
+ int64_t &beginTime, int64_t &endTime);
+
+ static void MergePackageStats(BundleActivePackageStats &left, const BundleActivePackageStats &right);
};
} // namespace DeviceUsageStats
} // namespace OHOS
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h
index a44f85b3c6b3bb333ad492e3ff68e36c25a52e54..c854436457ebebaa61efb2b6335b29ef5ded1a4b 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h
@@ -16,6 +16,7 @@
#ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_DATA_H
#define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_DATA_H
+#include