From 27a057847122f3cc7ce3e4879f7e4f8fa19b6d19 Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Sun, 6 Mar 2022 16:41:36 +0800
Subject: [PATCH 01/87] hapexception parameter handling
Signed-off-by: wyuanchao
---
frameworks/src/bundle_state_common.cpp | 45 ++--
frameworks/src/bundle_state_query.cpp | 213 ++++++++++--------
.../napi/include/bundle_state_common.h | 7 +-
.../napi/include/bundle_state_data.h | 8 +
.../napi/include/bundle_state_inner_errors.h | 54 +++++
.../src/bundle_active_usage_database.cpp | 2 +-
6 files changed, 215 insertions(+), 114 deletions(-)
create mode 100644 interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp
index 1beaff6..e1730a6 100644
--- a/frameworks/src/bundle_state_common.cpp
+++ b/frameworks/src/bundle_state_common.cpp
@@ -34,7 +34,7 @@ void BundleStateCommon::GetCallbackPromiseResult(const napi_env &env,
if (info.isCallback) {
SetCallbackInfo(env, info.callback, info.errorCode, result);
} else {
- SetPromiseInfo(env, info.deferred, result);
+ SetPromiseInfo(env, info.deferred, result, info.errorCode);
}
}
@@ -48,7 +48,7 @@ void BundleStateCommon::SetCallbackInfo(
napi_value resultout = nullptr;
napi_get_reference_value(env, callbackIn, &callback);
napi_value results[ARGS_TWO] = {nullptr};
- results[PARAM_FIRST] = GetCallbackErrorValue(env, errorCode);
+ results[PARAM_FIRST] = GetErrorValue(env, errorCode);
results[PARAM_SECOND] = result;
NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &results[PARAM_FIRST],
&resultout));
@@ -138,37 +138,44 @@ void BundleStateCommon::GetBundleStateInfoForResult(napi_env env,
}
}
-void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, const napi_value &result)
+void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred &deferred,
+ const napi_value &result, const int &errorCode)
{
- napi_resolve_deferred(env, deferred, result);
+ if (errorCode == ERR_OK) {
+ napi_resolve_deferred(env, deferred, result);
+ } else {
+ napi_reject_deferred(env, deferred, GetErrorValue(env, errorCode));
+ }
}
-napi_value BundleStateCommon::GetCallbackErrorValue(napi_env env, int errCode)
+napi_value BundleStateCommon::GetErrorValue(napi_env env, int errCode)
{
napi_value result = nullptr;
napi_value eCode = nullptr;
NAPI_CALL(env, napi_create_int32(env, errCode, &eCode));
NAPI_CALL(env, napi_create_object(env, &result));
- NAPI_CALL(env, napi_set_named_property(env, result, "data", eCode));
+ NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode));
return result;
}
-napi_value BundleStateCommon::JSParaError(const napi_env &env, const napi_ref &callback)
+napi_value BundleStateCommon::JSParaError(const napi_env &env, const napi_ref &callback, const int &errorCode)
{
if (callback) {
- return BundleStateCommon::NapiGetNull(env);
+ napi_value result = nullptr;
+ napi_create_array(env, &result);
+ SetCallbackInfo(env, callback, errorCode, result);
+ return result;
} else {
napi_value promise = nullptr;
napi_deferred deferred = nullptr;
napi_create_promise(env, &deferred, &promise);
- napi_resolve_deferred(env, deferred, BundleStateCommon::NapiGetNull(env));
+ napi_reject_deferred(env, deferred, GetErrorValue(env, errorCode));
return promise;
}
}
std::string BundleStateCommon::GetTypeStringValue(napi_env env, napi_value param, const std::string &result)
{
- BUNDLE_ACTIVE_LOGI("GetTypeStringValue start");
size_t size = 0;
if (napi_get_value_string_utf8(env, param, nullptr, 0, &size) != BUNDLE_STATE_OK) {
return result;
@@ -197,33 +204,31 @@ std::string BundleStateCommon::GetTypeStringValue(napi_env env, napi_value param
delete[] buf;
buf = nullptr;
- BUNDLE_ACTIVE_LOGI("string result: %{public}s", value.c_str());
return value;
}
napi_value BundleStateCommon::GetInt64NumberValue(const napi_env &env, const napi_value &value, int64_t &result)
{
- BUNDLE_ACTIVE_LOGI("GetInt64NumberValue start");
napi_valuetype valuetype = napi_undefined;
NAPI_CALL(env, napi_typeof(env, value, &valuetype));
- NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number or function expected.");
+ if (valuetype != napi_number) {
+ BUNDLE_ACTIVE_LOGE("Wrong argument type, number expected.");
+ return nullptr;
+ }
napi_get_value_int64(env, value, &result);
- BUNDLE_ACTIVE_LOGI("number result: %{public}lld", result);
-
return BundleStateCommon::NapiGetNull(env);
}
napi_value BundleStateCommon::GetInt32NumberValue(const napi_env &env, const napi_value &value, int32_t &result)
{
- BUNDLE_ACTIVE_LOGI("GetInt32NumberValue start");
napi_valuetype valuetype = napi_undefined;
-
NAPI_CALL(env, napi_typeof(env, value, &valuetype));
- NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number or function expected.");
+ if (valuetype != napi_number) {
+ BUNDLE_ACTIVE_LOGE("Wrong argument type. Number expected.");
+ return nullptr;
+ }
napi_get_value_int32(env, value, &result);
- BUNDLE_ACTIVE_LOGI("number result: %{public}d", result);
-
return BundleStateCommon::NapiGetNull(env);
}
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index 8d84091..dd94876 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -15,9 +15,10 @@
#include
-#include "bundle_state_common.h"
#include "bundle_active_log.h"
+#include "bundle_state_common.h"
#include "bundle_state_data.h"
+#include "bundle_state_inner_errors.h"
namespace OHOS {
namespace DeviceUsageStats {
@@ -41,26 +42,28 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i
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,
- "invalid number of parameters");
+ "Invalid number of parameters");
// argv[0] : bundleName
- napi_valuetype valuetype;
- NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
- NAPI_ASSERT(env, valuetype == napi_string, "ParseIsIdleStateParameters invalid parameter type. "
- "String expected.");
std::string result = "";
params.bundleName = BundleStateCommon::GetTypeStringValue(env, argv[0], result);
if (params.bundleName.empty()) {
- BUNDLE_ACTIVE_LOGI("ParseIsIdleStateParameters failed, bundleName is invalid.");
- return nullptr;
+ BUNDLE_ACTIVE_LOGE("ParseIsIdleStateParameters failed, bundleName is empty.");
+ params.errorCode = ERR_USAGE_STATS_BUNDLENAME_EMPTY;
+ }
+ napi_valuetype valuetype;
+ NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
+ if ((valuetype != napi_string) && (params.errorCode == ERR_OK)) {
+ BUNDLE_ACTIVE_LOGE("Wrong argument type, string expected.");
+ params.errorCode = ERR_USAGE_STATS_BUNDLENAME_TYPE;
}
// argv[1]: callback
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. "
- "Function expected.");
+ NAPI_ASSERT(env, valuetype == napi_function,
+ "ParseIsIdleStateParameters invalid parameter type, function expected.");
napi_create_reference(env, argv[1], 1, ¶ms.callback);
}
return BundleStateCommon::NapiGetNull(env);
@@ -69,36 +72,33 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i
napi_value IsIdleState(napi_env env, napi_callback_info info)
{
IsIdleStateParamsInfo params;
- if (ParseIsIdleStateParameters(env, info, params) == nullptr) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ ParseIsIdleStateParameters(env, info, params);
+ if (params.errorCode != ERR_OK) {
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
-
napi_value promise = nullptr;
AsyncCallbackInfoIsIdleState *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoIsIdleState {.env = env, .asyncWork = nullptr};
if (!asyncCallbackInfo) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
asyncCallbackInfo->bundleName = params.bundleName;
- BUNDLE_ACTIVE_LOGI("asyncCallbackInfo->bundleName: %{public}s", asyncCallbackInfo->bundleName.c_str());
BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise);
-
napi_value resourceName = nullptr;
napi_create_string_latin1(env, "IsIdleState", NAPI_AUTO_LENGTH, &resourceName);
-
napi_create_async_work(env,
nullptr,
resourceName,
[](napi_env env, void *data) {
- BUNDLE_ACTIVE_LOGI("IsIdleState, worker pool thread execute.");
AsyncCallbackInfoIsIdleState *asyncCallbackInfo = (AsyncCallbackInfoIsIdleState *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->state = BundleActiveClient::GetInstance().IsBundleIdle(
asyncCallbackInfo->bundleName);
} else {
+ asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("IsIdleState, asyncCallbackInfo == nullptr");
}
- BUNDLE_ACTIVE_LOGI("IsIdleState, worker pool thread execute end.");
},
[](napi_env env, napi_status status, void *data) {
AsyncCallbackInfoIsIdleState *asyncCallbackInfo = (AsyncCallbackInfoIsIdleState *)data;
@@ -118,9 +118,7 @@ napi_value IsIdleState(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 {
@@ -135,7 +133,7 @@ napi_value ParsePriorityGroupParameters(const napi_env &env, const napi_callback
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,
- "invalid number of parameters");
+ "Invalid number of parameters");
// argv[0]: callback
if (argc == Priority_Group_PARAMS) {
@@ -151,33 +149,28 @@ napi_value ParsePriorityGroupParameters(const napi_env &env, const napi_callback
napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info)
{
PriorityGroupParamsInfo params;
- if (ParsePriorityGroupParameters(env, info, params) == nullptr) {
- return BundleStateCommon::JSParaError(env, params.callback);
- }
-
+ ParsePriorityGroupParameters(env, info, params);
napi_value promise = nullptr;
AsyncCallbackInfoPriorityGroup *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoPriorityGroup {.env = env, .asyncWork = nullptr};
if (!asyncCallbackInfo) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise);
-
napi_value resourceName = nullptr;
napi_create_string_latin1(env, "QueryAppUsagePriorityGroup", NAPI_AUTO_LENGTH, &resourceName);
-
napi_create_async_work(env,
nullptr,
resourceName,
[](napi_env env, void *data) {
- BUNDLE_ACTIVE_LOGI("QueryAppUsagePriorityGroup, worker pool thread execute.");
AsyncCallbackInfoPriorityGroup *asyncCallbackInfo = (AsyncCallbackInfoPriorityGroup *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->priorityGroup = BundleActiveClient::GetInstance().QueryPackageGroup();
} else {
+ asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryAppUsagePriorityGroup, asyncCallbackInfo == nullptr");
}
- BUNDLE_ACTIVE_LOGI("QueryAppUsagePriorityGroup, worker pool thread execute end.");
},
[](napi_env env, napi_status status, void *data) {
AsyncCallbackInfoPriorityGroup *asyncCallbackInfo = (AsyncCallbackInfoPriorityGroup *)data;
@@ -185,11 +178,9 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info)
napi_value result = nullptr;
napi_create_int32(env, asyncCallbackInfo->priorityGroup, &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;
@@ -197,9 +188,7 @@ napi_value QueryAppUsagePriorityGroup(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 {
@@ -213,18 +202,33 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info &
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,
- "invalid number of parameters");
-
+ "Invalid number of parameters");
+
// argv[0] : beginTime
if (BundleStateCommon::GetInt64NumberValue(env, argv[0], params.beginTime) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, beginTime is invalid.");
- return nullptr;
+ BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, beginTime type is invalid.");
+ params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK)
+ && (params.beginTime < TIME_NUMBER_MIN)) {
+ BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, beginTime value is invalid.");
+ params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID;
}
// argv[1] : endTime
- if (BundleStateCommon::GetInt64NumberValue(env, argv[1], params.endTime) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, endTime is invalid.");
- return nullptr;
+ if ((params.errorCode == ERR_OK)
+ && (BundleStateCommon::GetInt64NumberValue(env, argv[1], params.endTime) == nullptr)) {
+ BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, endTime type is invalid.");
+ params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK)
+ && (params.endTime < TIME_NUMBER_MIN)) {
+ BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, endTime value is invalid.");
+ params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) {
+ BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}lld) <= beginTime(%{public}lld)", params.endTime, params.beginTime);
+ params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL;
}
// argv[SECOND_ARG]: callback
@@ -241,15 +245,16 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info &
napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info)
{
StatesParamsInfo params;
- if (ParseStatesParameters(env, info, params) == nullptr) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ ParseStatesParameters(env, info, params);
+ if (params.errorCode != ERR_OK) {
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
-
napi_value promise = nullptr;
AsyncCallbackInfoStates *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoStates {.env = env, .asyncWork = nullptr};
if (!asyncCallbackInfo) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
asyncCallbackInfo->beginTime = params.beginTime;
BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->beginTime: %{public}lld",
@@ -266,16 +271,15 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info)
nullptr,
resourceName,
[](napi_env env, void *data) {
- BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates, worker pool thread execute.");
AsyncCallbackInfoStates *asyncCallbackInfo = (AsyncCallbackInfoStates *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->BundleActiveState =
BundleActiveClient::GetInstance().QueryCurrentEvents(asyncCallbackInfo->beginTime,
asyncCallbackInfo->endTime);
} else {
+ asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryCurrentBundleActiveStates, asyncCallbackInfo == nullptr");
}
- BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates, worker pool thread execute end.");
},
[](napi_env env, napi_status status, void *data) {
AsyncCallbackInfoStates *asyncCallbackInfo = (AsyncCallbackInfoStates *)data;
@@ -288,7 +292,6 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info)
if (asyncCallbackInfo->info.callback != nullptr) {
napi_delete_reference(env, asyncCallbackInfo->info.callback);
}
-
napi_delete_async_work(env, asyncCallbackInfo->asyncWork);
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
@@ -309,15 +312,16 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info)
napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info)
{
StatesParamsInfo params;
- if (ParseStatesParameters(env, info, params) == nullptr) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ ParseStatesParameters(env, info, params);
+ if (params.errorCode != ERR_OK) {
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
-
napi_value promise = nullptr;
AsyncCallbackInfoStates *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoStates {.env = env, .asyncWork = nullptr};
if (!asyncCallbackInfo) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
asyncCallbackInfo->beginTime = params.beginTime;
BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->beginTime: %{public}lld",
@@ -334,16 +338,15 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info)
nullptr,
resourceName,
[](napi_env env, void *data) {
- BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates, worker pool thread execute.");
AsyncCallbackInfoStates *asyncCallbackInfo = (AsyncCallbackInfoStates *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->BundleActiveState =
BundleActiveClient::GetInstance().QueryEvents(asyncCallbackInfo->beginTime,
asyncCallbackInfo->endTime);
} else {
+ asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryBundleActiveStates, asyncCallbackInfo == nullptr");
}
- BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates, worker pool thread execute end.");
},
[](napi_env env, napi_status status, void *data) {
AsyncCallbackInfoStates *asyncCallbackInfo = (AsyncCallbackInfoStates *)data;
@@ -352,11 +355,9 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info)
napi_create_array(env, &result);
BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, 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;
@@ -364,9 +365,7 @@ napi_value QueryBundleActiveStates(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 {
@@ -381,24 +380,46 @@ napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_cal
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,
- "invalid number of parameters");
+ "Invalid number of parameters");
// argv[0] : intervalType
if (BundleStateCommon::GetInt32NumberValue(env, argv[0], params.intervalType) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, beginTime is invalid.");
- return nullptr;
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, intervalType is invalid.");
+ params.errorCode = ERR_USAGE_STATS_INTERVAL_TYPE;
+ }
+ if((params.errorCode == ERR_OK) && ((params.intervalType < INTERVAL_NUMBER_MIN)
+ || (params.intervalType > INTERVAL_NUMBER_MAX))) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, intervalType number is invalid.");
+ params.errorCode = ERR_USAGE_STATS_INTERVAL_NUMBER;
}
// argv[1] : beginTime
- if (BundleStateCommon::GetInt64NumberValue(env, argv[1], params.beginTime) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, beginTime is invalid.");
- return nullptr;
+ if ((params.errorCode == ERR_OK)
+ && (BundleStateCommon::GetInt64NumberValue(env, argv[1], params.beginTime) == nullptr)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, beginTime type is invalid.");
+ params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK)
+ && (params.beginTime < TIME_NUMBER_MIN)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, beginTime value is invalid.");
+ params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID;
}
// argv[SECOND_ARG] : endTime
- if (BundleStateCommon::GetInt64NumberValue(env, argv[SECOND_ARG], params.endTime) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, endTime is invalid.");
- return nullptr;
+ if ((params.errorCode == ERR_OK)
+ && (BundleStateCommon::GetInt64NumberValue(env, argv[SECOND_ARG], params.endTime) == nullptr)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, endTime type is invalid.");
+ params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK)
+ && (params.endTime < TIME_NUMBER_MIN)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, endTime value is invalid.");
+ params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval endTime(%{public}lld) <= beginTime(%{public}lld)",
+ params.endTime, params.beginTime);
+ params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL;
}
// argv[THIRD_ARG]: callback
@@ -415,15 +436,16 @@ napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_cal
napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info)
{
AppUsageParamsByIntervalInfo params;
- if (ParseAppUsageParametersByInterval(env, info, params) == nullptr) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ ParseAppUsageParametersByInterval(env, info, params);
+ if (params.errorCode != ERR_OK) {
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
-
napi_value promise = nullptr;
AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoAppUsageByInterval {.env = env, .asyncWork = nullptr};
if (!asyncCallbackInfo) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
asyncCallbackInfo->intervalType = params.intervalType;
BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->intervalType: %{public}d",
@@ -435,24 +457,21 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info)
BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->endTime: %{public}lld",
asyncCallbackInfo->endTime);
BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise);
-
napi_value resourceName = nullptr;
napi_create_string_latin1(env, "QueryBundleStateInfoByInterval", NAPI_AUTO_LENGTH, &resourceName);
-
napi_create_async_work(env,
nullptr,
resourceName,
[](napi_env env, void *data) {
- BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval, worker pool thread execute.");
AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo = (AsyncCallbackInfoAppUsageByInterval *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->packageStats =
BundleActiveClient::GetInstance().QueryPackageStats(asyncCallbackInfo->intervalType,
asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
} else {
+ asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryBundleStateInfoByInterval, asyncCallbackInfo == nullptr");
}
- BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval, worker pool thread execute end.");
},
[](napi_env env, napi_status status, void *data) {
AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo = (AsyncCallbackInfoAppUsageByInterval *)data;
@@ -473,9 +492,7 @@ napi_value QueryBundleStateInfoByInterval(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 {
@@ -489,18 +506,33 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info
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,
- "invalid number of parameters");
-
+ "Invalid number of parameters");
+
// argv[0] : beginTime
if (BundleStateCommon::GetInt64NumberValue(env, argv[0], params.beginTime) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, beginTime is invalid.");
- return nullptr;
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, beginTime type is invalid.");
+ params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK)
+ && (params.beginTime < TIME_NUMBER_MIN)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed failed, beginTime value is invalid.");
+ params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID;
}
// argv[1] : endTime
- if (BundleStateCommon::GetInt64NumberValue(env, argv[1], params.endTime) == nullptr) {
- BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, endTime is invalid.");
- return nullptr;
+ if ((params.errorCode == ERR_OK)
+ && (BundleStateCommon::GetInt64NumberValue(env, argv[1], params.endTime) == nullptr)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, endTime type is invalid.");
+ params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK)
+ && (params.endTime < TIME_NUMBER_MIN)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed failed, endTime value is invalid.");
+ params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
+ }
+ if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) {
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}lld) <= beginTime(%{public}lld)", params.endTime, params.beginTime);
+ params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL;
}
// argv[SECOND_ARG]: callback
@@ -517,14 +549,16 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info
napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
{
AppUsageParamsInfo params;
- if (ParseAppUsageParameters(env, info, params) == nullptr) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ ParseAppUsageParameters(env, info, params);
+ if (params.errorCode != ERR_OK) {
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
napi_value promise = nullptr;
AsyncCallbackInfoAppUsage *asyncCallbackInfo =
new (std::nothrow) AsyncCallbackInfoAppUsage {.env = env, .asyncWork = nullptr};
if (!asyncCallbackInfo) {
- return BundleStateCommon::JSParaError(env, params.callback);
+ params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
+ return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
asyncCallbackInfo->beginTime = params.beginTime;
BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->beginTime: %{public}lld",
@@ -539,15 +573,14 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
nullptr,
resourceName,
[](napi_env env, void *data) {
- BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos, worker pool thread execute.");
AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data;
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->packageStats =
BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
} else {
+ asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos asyncCallbackInfo == nullptr");
}
- BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos worker pool thread execute end.");
},
[](napi_env env, napi_status status, void *data) {
AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data;
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
index 5e8daf4..a8ff5e2 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
@@ -33,7 +33,7 @@ public:
static napi_value NapiGetUndefined(napi_env env);
- static napi_value GetCallbackErrorValue(napi_env env, int errCode);
+ static napi_value GetErrorValue(napi_env env, int errCode);
static void SettingCallbackPromiseInfo(
const napi_env &env, const napi_ref &callback, CallbackPromiseInfo &info, napi_value &promise);
@@ -53,9 +53,10 @@ public:
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);
+ static void SetPromiseInfo(const napi_env &env, const napi_deferred &deferred,
+ const napi_value &result, const int &errorCode);
- static napi_value JSParaError(const napi_env &env, const napi_ref &callback);
+ static napi_value JSParaError(const napi_env &env, const napi_ref &callback, const int &errorCode);
static std::string GetTypeStringValue(napi_env env, napi_value param, const std::string &result);
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h
index c854436..5d4f565 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h
@@ -39,6 +39,9 @@ namespace DeviceUsageStats {
#define BUNDLE_STATE_OK 0
#define INTERVAL_TYPE_DEFAULT 0
+#define INTERVAL_NUMBER_MIN 0
+#define INTERVAL_NUMBER_MAX 4
+#define TIME_NUMBER_MIN 0
struct CallbackPromiseInfo {
napi_ref callback = nullptr;
@@ -93,16 +96,19 @@ struct AsyncCallbackInfoAppUsage {
struct IsIdleStateParamsInfo {
std::string bundleName;
napi_ref callback = nullptr;
+ int errorCode = 0;
};
struct PriorityGroupParamsInfo {
napi_ref callback = nullptr;
+ int errorCode = 0;
};
struct StatesParamsInfo {
int64_t beginTime;
int64_t endTime;
napi_ref callback = nullptr;
+ int errorCode = 0;
};
struct AppUsageParamsByIntervalInfo {
@@ -110,12 +116,14 @@ struct AppUsageParamsByIntervalInfo {
int64_t beginTime;
int64_t endTime;
napi_ref callback = nullptr;
+ int errorCode = 0;
};
struct AppUsageParamsInfo {
int64_t beginTime;
int64_t endTime;
napi_ref callback = nullptr;
+ int errorCode = 0;
};
} // namespace DeviceUsageStats
} // namespace OHOS
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
new file mode 100644
index 0000000..c6cf602
--- /dev/null
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_INNER_ERRORS_H
+#define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_INNER_ERRORS_H
+
+#include "errors.h"
+
+namespace OHOS {
+namespace DeviceUsageStats {
+/**
+ * ErrCode layout
+ *
+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ * |Field|Reserved| Subsystem | Module | Code |
+ * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ */
+
+// DeviceUsageStats's module const defined.
+enum : int {
+ DEVICE_USAGE_STATS_MODULE_COMMON = 0x01,
+};
+
+// Offset of device usage stats sub-system's errcode base.
+constexpr ErrCode DEVICE_USAGE_STATS_COMMON_ERR_OFFSET =
+ ErrCodeOffset(SUBSYS_IAWARE, DEVICE_USAGE_STATS_MODULE_COMMON);
+// Device Usage Stats Common Error Code Defined.
+enum : int {
+ ERR_USAGE_STATS_BUNDLENAME_EMPTY = DEVICE_USAGE_STATS_COMMON_ERR_OFFSET + 1, //39911425
+ ERR_USAGE_STATS_BUNDLENAME_TYPE, //39911426
+ ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR, //39911427
+ ERR_USAGE_STATS_BEGIN_TIME_INVALID, //39911428
+ ERR_USAGE_STATS_END_TIME_INVALID, //39911429
+ ERR_USAGE_STATS_TIME_INTERVAL, //39911430
+ ERR_USAGE_STATS_INTERVAL_TYPE, //39911431
+ ERR_USAGE_STATS_INTERVAL_NUMBER, //39911432
+};
+} // namespace DeviceUsageStats
+} // namespace OHOS
+#endif // FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_INNER_ERRORS_H
\ No newline at end of file
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index 3db758c..8bd55c2 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -154,7 +154,7 @@ int32_t BundleActiveUsageDatabase::NearIndexOnOrAfterCurrentTime(int64_t current
int64_t tableTime = -1;
int32_t divisor = 2;
while (low <= high) {
- mid = (high - low) / divisor + low;
+ mid = (high + low) / divisor;
tableTime = sortedTableArray.at(mid);
if (currentTime > tableTime) {
low = mid + 1;
--
Gitee
From 2b33db5741e4a087316df90af40918377df2619c Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Sun, 6 Mar 2022 16:54:06 +0800
Subject: [PATCH 02/87] hapexception parameter handling
Signed-off-by: wyuanchao
---
frameworks/src/bundle_state_query.cpp | 8 +++++---
.../napi/include/bundle_state_inner_errors.h | 18 +++++++++---------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index dd94876..2a30443 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -227,7 +227,8 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info &
params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
}
if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) {
- BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}lld) <= beginTime(%{public}lld)", params.endTime, params.beginTime);
+ BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}lld) <= beginTime(%{public}lld)",
+ params.endTime, params.beginTime);
params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL;
}
@@ -387,7 +388,7 @@ napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_cal
BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, intervalType is invalid.");
params.errorCode = ERR_USAGE_STATS_INTERVAL_TYPE;
}
- if((params.errorCode == ERR_OK) && ((params.intervalType < INTERVAL_NUMBER_MIN)
+ if ((params.errorCode == ERR_OK) && ((params.intervalType < INTERVAL_NUMBER_MIN)
|| (params.intervalType > INTERVAL_NUMBER_MAX))) {
BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval failed, intervalType number is invalid.");
params.errorCode = ERR_USAGE_STATS_INTERVAL_NUMBER;
@@ -531,7 +532,8 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info
params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID;
}
if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) {
- BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}lld) <= beginTime(%{public}lld)", params.endTime, params.beginTime);
+ BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}lld) <= beginTime(%{public}lld)",
+ params.endTime, params.beginTime);
params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL;
}
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
index c6cf602..aa70a02 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
@@ -35,19 +35,19 @@ enum : int {
DEVICE_USAGE_STATS_MODULE_COMMON = 0x01,
};
-// Offset of device usage stats sub-system's errcode base.
+// Offset of device usage stats sub-system's errcode base, number : 39911424.
constexpr ErrCode DEVICE_USAGE_STATS_COMMON_ERR_OFFSET =
ErrCodeOffset(SUBSYS_IAWARE, DEVICE_USAGE_STATS_MODULE_COMMON);
// Device Usage Stats Common Error Code Defined.
enum : int {
- ERR_USAGE_STATS_BUNDLENAME_EMPTY = DEVICE_USAGE_STATS_COMMON_ERR_OFFSET + 1, //39911425
- ERR_USAGE_STATS_BUNDLENAME_TYPE, //39911426
- ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR, //39911427
- ERR_USAGE_STATS_BEGIN_TIME_INVALID, //39911428
- ERR_USAGE_STATS_END_TIME_INVALID, //39911429
- ERR_USAGE_STATS_TIME_INTERVAL, //39911430
- ERR_USAGE_STATS_INTERVAL_TYPE, //39911431
- ERR_USAGE_STATS_INTERVAL_NUMBER, //39911432
+ ERR_USAGE_STATS_BUNDLENAME_EMPTY = DEVICE_USAGE_STATS_COMMON_ERR_OFFSET + 1,
+ ERR_USAGE_STATS_BUNDLENAME_TYPE,
+ ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR,
+ ERR_USAGE_STATS_BEGIN_TIME_INVALID,
+ ERR_USAGE_STATS_END_TIME_INVALID,
+ ERR_USAGE_STATS_TIME_INTERVAL,
+ ERR_USAGE_STATS_INTERVAL_TYPE,
+ ERR_USAGE_STATS_INTERVAL_NUMBER,
};
} // namespace DeviceUsageStats
} // namespace OHOS
--
Gitee
From b75045b4a4c2cf91dca588346885ce12143347c0 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Mon, 7 Mar 2022 15:22:00 +0800
Subject: [PATCH 03/87] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=88=87=E6=8D=A2=E8=90=BD=E7=9B=98=E5=8A=9F=E8=83=BD=EF=BC=8C?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E6=97=A5=E5=BF=97=E6=89=93?=
=?UTF-8?q?=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/include/bundle_active_core.h | 4 +-
services/common/src/bundle_active_core.cpp | 60 +++++++++++++++----
.../include/bundle_active_group_controller.h | 1 +
.../src/bundle_active_group_controller.cpp | 12 ++++
.../include/bundle_active_report_handler.h | 4 +-
.../include/bundle_active_user_service.h | 2 +-
.../src/bundle_active_report_handler.cpp | 7 +--
.../src/bundle_active_user_service.cpp | 24 +++++---
8 files changed, 87 insertions(+), 27 deletions(-)
diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h
index 5464548..928e667 100644
--- a/services/common/include/bundle_active_core.h
+++ b/services/common/include/bundle_active_core.h
@@ -116,10 +116,11 @@ public:
const int64_t timeStamp);
// when received a USER_REMOVED commen event, call it to remove data.
void OnUserRemoved(const int userId);
+ void OnUserSwitched();
// force set app group.
void SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId);
// get all user in device
- void GetAllActiveUser(std::vector &osAccountInfos);
+ void GetAllActiveUser(std::vector& activatedOsAccountIds);
// when service stop, call it to unregister commen event and shutdown call back.
void UnRegisterSubscriber();
int64_t GetSystemTimeMs();
@@ -140,6 +141,7 @@ private:
void RegisterSubscriber();
std::shared_ptr commonEventSubscriber_;
void RestoreAllData();
+ int lastUsedUser_;
};
}
}
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 25fe675..4697d13 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -45,6 +45,7 @@ BundleActiveCore::BundleActiveCore()
{
systemTimeShot_ = -1;
realTimeShot_ = -1;
+ lastUsedUser_ = -1;
}
BundleActiveCore::~BundleActiveCore()
@@ -83,6 +84,11 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
if (!activeGroupController_.expired() && userId >= 0) {
activeGroupController_.lock()->PeriodCheckBundleState(userId);
}
+ } else if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
+ int32_t userId = data.GetCode();
+ BUNDLE_ACTIVE_LOGI("OnReceiveEvent receive switched user event, user id is %{public}d", userId);
+ auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER);
+ bundleActiveReportHandler_.lock()->SendEvent(event);
} else if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED ||
action == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) {
int32_t userId = data.GetWant().GetIntParam("userId", 0);
@@ -113,6 +119,7 @@ void BundleActiveCore::RegisterSubscriber()
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED);
+ matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
commonEventSubscriber_ = std::make_shared(subscriberInfo,
bundleGroupController_, handler_);
@@ -157,11 +164,15 @@ void BundleActiveCore::InitBundleGroupController()
BUNDLE_ACTIVE_LOGI("Init Set group controller and handler done");
}
RegisterSubscriber();
- std::vector osAccountInfos;
- GetAllActiveUser(osAccountInfos);
+ std::vector activatedOsAccountIds;
bundleGroupController_->bundleGroupEnable_ = true;
- for (uint32_t i = 0; i < osAccountInfos.size(); i++) {
- bundleGroupController_->PeriodCheckBundleState(osAccountInfos[i].GetLocalId());
+ GetAllActiveUser(activatedOsAccountIds);
+ if (activatedOsAccountIds.size() == 0) {
+ BUNDLE_ACTIVE_LOGI("query activated account failed, no account activated");
+ return;
+ }
+ for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) {
+ bundleGroupController_->PeriodCheckBundleState(activatedOsAccountIds[i]);
}
}
@@ -236,7 +247,7 @@ void BundleActiveCore::RestoreAllData()
bundleGroupController_->RestoreDurationToDatabase();
}
if (!handler_.expired()) {
- BUNDLE_ACTIVE_LOGI("RestoreToDatabaseLocked remove flush to disk event");
+ BUNDLE_ACTIVE_LOGI("RestoreAllData remove flush to disk event");
handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK);
}
}
@@ -322,7 +333,7 @@ int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int userId)
it->second->RenewTableTime(expectedSystemTime, actualSystemTime);
it->second->LoadActiveStats(actualSystemTime, true, true);
if (!handler_.expired()) {
- BUNDLE_ACTIVE_LOGI("RestoreToDatabaseLocked remove flush to disk event");
+ BUNDLE_ACTIVE_LOGI("CheckTimeChangeAndGetWallTime remove flush to disk event");
handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK);
}
}
@@ -352,9 +363,37 @@ void BundleActiveCore::OnUserRemoved(const int userId)
bundleGroupController_->OnUserRemoved(userId);
}
+void BundleActiveCore::OnUserSwitched()
+{
+ sptr timer = MiscServices::TimeServiceClient::GetInstance();
+ auto it = userStatServices_.find(lastUsedUser_);
+ if (it != userStatServices_.end()) {
+ if (it != userStatServices_.end()) {
+ BundleActiveEvent event;
+ event.eventId_ = BundleActiveEvent::FLUSH;
+ int64_t actualRealTime = timer->GetBootTimeMs();
+ event.timeStamp_ = (actualRealTime - realTimeShot_) + systemTimeShot_;
+ event.abilityId_ = "";
+ it->second->ReportEvent(event);
+ it->second->RestoreStats(true);
+ }
+ }
+ std::vector activatedOsAccountIds;
+ GetAllActiveUser(activatedOsAccountIds);
+ if (activatedOsAccountIds.size() == 0) {
+ BUNDLE_ACTIVE_LOGI("query activated account failed, no account activated");
+ return;
+ }
+ for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) {
+ BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]);
+ bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i]);
+ }
+}
+
int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId)
{
std::lock_guard lock(mutex_);
+ lastUsedUser_ = userId;
if (userId == 0) {
return -1;
}
@@ -468,14 +507,13 @@ int BundleActiveCore::IsBundleIdle(const std::string& bundleName, const int user
return bundleGroupController_->IsBundleIdle(bundleName, userId);
}
-void BundleActiveCore::GetAllActiveUser(std::vector &osAccountInfos)
+void BundleActiveCore::GetAllActiveUser(std::vector& activatedOsAccountIds)
{
- OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(osAccountInfos);
- if (ret != ERR_OK) {
- BUNDLE_ACTIVE_LOGI("GetAllActiveUser failed");
+ if (AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds) != ERR_OK) {
+ BUNDLE_ACTIVE_LOGI("query activated account failed");
return;
}
- if (osAccountInfos.size() == 0) {
+ if (activatedOsAccountIds.size() == 0) {
BUNDLE_ACTIVE_LOGI("GetAllActiveUser size is 0");
return;
}
diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h
index 1de660f..6763202 100644
--- a/services/packagegroup/include/bundle_active_group_controller.h
+++ b/services/packagegroup/include/bundle_active_group_controller.h
@@ -84,6 +84,7 @@ public:
int IsBundleIdle(const std::string& bundleName, const int userId);
int QueryPackageGroup(const int userId, const std::string& bundleName);
void ShutDown(const int64_t bootBasedTimeStamp);
+ void OnUserSwitched(const int userId);
private:
std::mutex mutex_;
diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp
index f89d4bf..519311f 100644
--- a/services/packagegroup/src/bundle_active_group_controller.cpp
+++ b/services/packagegroup/src/bundle_active_group_controller.cpp
@@ -45,6 +45,18 @@ void BundleActiveGroupController::OnUserRemoved(const int userId)
{
std::lock_guard lock(mutex_);
bundleUserHistory_->userHistory_.erase(userId);
+ if (!activeGroupHandler_.expired()) {
+ activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE);
+ }
+}
+
+void BundleActiveGroupController::OnUserSwitched(const int userId)
+{
+ std::lock_guard lock(mutex_);
+ if (!activeGroupHandler_.expired()) {
+ activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE);
+ }
+ PeriodCheckBundleState(userId);
}
void BundleActiveGroupController::OnScreenChanged(const bool& isScreenOn, const int64_t bootFromTimeStamp)
diff --git a/services/packageusage/include/bundle_active_report_handler.h b/services/packageusage/include/bundle_active_report_handler.h
index bc9ea44..ad2714d 100644
--- a/services/packageusage/include/bundle_active_report_handler.h
+++ b/services/packageusage/include/bundle_active_report_handler.h
@@ -39,8 +39,8 @@ public:
static const int MSG_REPORT_EVENT_TO_ALL_USER = 1;
static const int MSG_FLUSH_TO_DISK = 2;
static const int MSG_REMOVE_USER = 3;
- static const int MSG_DEVICE_SHUTDOWN = 4;
- static const int MSG_BUNDLE_UNINSTALLED = 5;
+ static const int MSG_BUNDLE_UNINSTALLED = 4;
+ static const int MSG_SWITCH_USER = 5;
private:
std::shared_ptr bundleActiveCore_;
diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h
index 6aa13e7..8ed4250 100644
--- a/services/packageusage/include/bundle_active_user_service.h
+++ b/services/packageusage/include/bundle_active_user_service.h
@@ -71,7 +71,7 @@ private:
BundleActiveCalendar::YEAR_MILLISECONDS};
void NotifyStatsChanged();
void NotifyNewUpdate();
- void printstat();
+ void PrintInMemStats();
};
}
}
diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp
index d02a40d..33b734d 100644
--- a/services/packageusage/src/bundle_active_report_handler.cpp
+++ b/services/packageusage/src/bundle_active_report_handler.cpp
@@ -61,10 +61,6 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point
bundleActiveCore_->OnUserRemoved(tmpHandlerobj.userId_);
break;
}
- case MSG_DEVICE_SHUTDOWN: {
- bundleActiveCore_->ShutDown();
- break;
- }
case MSG_BUNDLE_UNINSTALLED: {
BUNDLE_ACTIVE_LOGI("MSG_BUNDLE_UNINSTALLED CALLED");
auto ptrToHandlerobj = event->GetSharedObject();
@@ -72,6 +68,9 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point
bundleActiveCore_->OnBundleUninstalled(tmpHandlerobj.userId_, tmpHandlerobj.bundleName_);
break;
}
+ case MSG_SWITCH_USER: {
+ bundleActiveCore_->OnUserSwitched();
+ }
default: {
break;
}
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index 4686d76..5cadcf9 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -304,7 +304,12 @@ std::vector BundleActiveUserService::QueryPackageStats
return result;
}
int64_t truncatedEndTime = std::min(currentStats->beginTime_, endTime);
+ BUNDLE_ACTIVE_LOGI("Query package data in db from %{public}lld to %{public}lld, current begin %{public}lld",
+ beginTime, truncatedEndTime, currentStats->beginTime_);
result = database_.QueryDatabaseUsageStats(intervalType, beginTime, truncatedEndTime, userId);
+ BUNDLE_ACTIVE_LOGI("Query package data in db result size is %{public}d",
+ static_cast(result.size()));
+ PrintInMemStats();
// if we need a in-memory stats, combine current stats with result from database.
if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) {
BUNDLE_ACTIVE_LOGI("QueryPackageStats need in memory stats");
@@ -358,16 +363,19 @@ std::vector BundleActiveUserService::QueryEvents(const int64_
return result;
}
-void BundleActiveUserService::printstat()
+void BundleActiveUserService::PrintInMemStats()
{
- BUNDLE_ACTIVE_LOGI("printstat called");
+ BUNDLE_ACTIVE_LOGI("PrintInMemStats called");
int idx = 0;
for (auto it : currentStats_[idx]->bundleStats_) {
- BUNDLE_ACTIVE_LOGI("bundle name is %{public}s", it.first.c_str());
- int64_t lasttimeused = it.second->lastTimeUsed_;
- int64_t totalusedtime = it.second->totalInFrontTime_;
- BUNDLE_ACTIVE_LOGI("event stat is, totaltime is %{public}lld, lasttimeused is %{public}lld",
- totalusedtime, lasttimeused);
+ BUNDLE_ACTIVE_LOGI("In mem, bundle name is %{public}s", it.first.c_str());
+ int64_t lastTimeUsed = it.second->lastTimeUsed_;
+ int64_t totalUsedTime = it.second->totalInFrontTime_;
+ int64_t lastTimeContinuousTaskUsed = it.second->lastContiniousTaskUsed_;
+ int64_t totalTimeContinuousTaskUsed = it.second->totalContiniousTaskUsedTime_;
+ BUNDLE_ACTIVE_LOGI("In mem, event stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld"
+ "total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld",
+ totalUsedTime, lastTimeUsed, totalTimeContinuousTaskUsed, lastTimeContinuousTaskUsed);
}
int size = static_cast(currentStats_[idx]->events_.events_.size());
for (int i = 0; i < size; i++) {
@@ -376,7 +384,7 @@ void BundleActiveUserService::printstat()
std::string bundlename = currentStats_[idx]->events_.events_[i].bundleName_;
int eventid = currentStats_[idx]->events_.events_[i].eventId_;
int64_t timestamp = currentStats_[idx]->events_.events_[i].timeStamp_;
- BUNDLE_ACTIVE_LOGI("event stat is, abilityid is %{public}s, abilityname is %{public}s, "
+ BUNDLE_ACTIVE_LOGI("In mem, event stat is, abilityid is %{public}s, abilityname is %{public}s, "
"bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}lld",
abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, timestamp);
}
--
Gitee
From ce82f715aa566a681615849d0f35b157e2617d37 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Mon, 7 Mar 2022 15:56:49 +0800
Subject: [PATCH 04/87] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=88=87=E6=8D=A2=E8=90=BD=E7=9B=98=E5=8A=9F=E8=83=BD=EF=BC=8C?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E6=97=A5=E5=BF=97=E6=89=93?=
=?UTF-8?q?=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
.../include/bundle_active_user_service.h | 3 ++-
.../src/bundle_active_user_service.cpp | 18 ++++++++++++------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h
index 8ed4250..2bce5f3 100644
--- a/services/packageusage/include/bundle_active_user_service.h
+++ b/services/packageusage/include/bundle_active_user_service.h
@@ -71,7 +71,8 @@ private:
BundleActiveCalendar::YEAR_MILLISECONDS};
void NotifyStatsChanged();
void NotifyNewUpdate();
- void PrintInMemStats();
+ void PrintInMemPackageStats(const int idx);
+ void PrintInMemEventStats();
};
}
}
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index 5cadcf9..ed0dd0f 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -309,7 +309,7 @@ std::vector BundleActiveUserService::QueryPackageStats
result = database_.QueryDatabaseUsageStats(intervalType, beginTime, truncatedEndTime, userId);
BUNDLE_ACTIVE_LOGI("Query package data in db result size is %{public}d",
static_cast(result.size()));
- PrintInMemStats();
+ PrintInMemPackageStats(intervalType);
// if we need a in-memory stats, combine current stats with result from database.
if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) {
BUNDLE_ACTIVE_LOGI("QueryPackageStats need in memory stats");
@@ -344,9 +344,10 @@ std::vector BundleActiveUserService::QueryEvents(const int64_
if (beginTime >= currentStats->endTime_) {
return result;
}
- BUNDLE_ACTIVE_LOGI("QueryEvents bundle name is %{public}s", bundleName.c_str());
+ BUNDLE_ACTIVE_LOGI("Query event bundle name is %{public}s", bundleName.c_str());
result = database_.QueryDatabaseEvents(beginTime, endTime, userId, bundleName);
- BUNDLE_ACTIVE_LOGI("event database query size is %{public}d", result.size());
+ BUNDLE_ACTIVE_LOGI("Query event data in db result size is %{public}d", result.size());
+ PrintInMemEventStats();
// if we need a in-memory stats, combine current stats with result from database.
if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) {
BUNDLE_ACTIVE_LOGI("QueryEvents need in memory stats");
@@ -363,10 +364,9 @@ std::vector BundleActiveUserService::QueryEvents(const int64_
return result;
}
-void BundleActiveUserService::PrintInMemStats()
+void BundleActiveUserService::PrintInMemPackageStats(const int idx)
{
- BUNDLE_ACTIVE_LOGI("PrintInMemStats called");
- int idx = 0;
+ BUNDLE_ACTIVE_LOGI("PrintInMemPackageStats called");
for (auto it : currentStats_[idx]->bundleStats_) {
BUNDLE_ACTIVE_LOGI("In mem, bundle name is %{public}s", it.first.c_str());
int64_t lastTimeUsed = it.second->lastTimeUsed_;
@@ -377,6 +377,12 @@ void BundleActiveUserService::PrintInMemStats()
"total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld",
totalUsedTime, lastTimeUsed, totalTimeContinuousTaskUsed, lastTimeContinuousTaskUsed);
}
+}
+
+void BundleActiveUserService::PrintInMemEventStats()
+{
+ BUNDLE_ACTIVE_LOGI("PrintInMemEventStats called");
+ int idx = 0;
int size = static_cast(currentStats_[idx]->events_.events_.size());
for (int i = 0; i < size; i++) {
std::string abilityId = currentStats_[idx]->events_.events_[i].abilityId_;
--
Gitee
From b599d22a13731e212b50756cc8dc9bf45a5f0ef3 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Mon, 7 Mar 2022 16:03:25 +0800
Subject: [PATCH 05/87] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=88=87=E6=8D=A2=E8=90=BD=E7=9B=98=E5=8A=9F=E8=83=BD=EF=BC=8C?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E6=97=A5=E5=BF=97=E6=89=93?=
=?UTF-8?q?=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 4697d13..31b768e 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -78,12 +78,6 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REMOVE_USER, handlerobjToPtr);
bundleActiveReportHandler_.lock()->SendEvent(event);
}
- } else if (action == CommonEventSupport::COMMON_EVENT_USER_ADDED) {
- int32_t userId = data.GetCode();
- BUNDLE_ACTIVE_LOGI("OnReceiveEvent receive add user event, user id is %{public}d", userId);
- if (!activeGroupController_.expired() && userId >= 0) {
- activeGroupController_.lock()->PeriodCheckBundleState(userId);
- }
} else if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
int32_t userId = data.GetCode();
BUNDLE_ACTIVE_LOGI("OnReceiveEvent receive switched user event, user id is %{public}d", userId);
@@ -115,11 +109,10 @@ void BundleActiveCore::RegisterSubscriber()
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_ON);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED);
- matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_ADDED);
+ matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED);
- matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
commonEventSubscriber_ = std::make_shared(subscriberInfo,
bundleGroupController_, handler_);
--
Gitee
From 10b2b6a523f0e4bc971df283d4ae8e90789e512e Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Mon, 7 Mar 2022 18:15:38 +0800
Subject: [PATCH 06/87] js api test
Signed-off-by: wyuanchao
---
bundle.json | 3 +-
.../BUILD.gn | 26 ++
.../config.json | 74 ++++
.../device_usage_statistics_jsunit.test.js | 332 ++++++++++++++++++
.../ohos_device_usage_statistics.p7b | Bin 0 -> 3451 bytes
5 files changed, 434 insertions(+), 1 deletion(-)
create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn
create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/config.json
create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js
create mode 100644 interfaces/test/unittest/device_usage_statistics_jsunittest/ohos_device_usage_statistics.p7b
diff --git a/bundle.json b/bundle.json
index 014b937..374597e 100644
--- a/bundle.json
+++ b/bundle.json
@@ -67,7 +67,8 @@
}
],
"test": [
- "//foundation/resourceschedule/device_usage_statistics/test/unittest:unittest"
+ "//foundation/resourceschedule/device_usage_statistics/test/unittest:unittest",
+ "//foundation/resourceschedule/device_usage_statistics/interfaces/test/unittest/device_usage_statistics_jsunittest:js_unittest"
]
}
}
diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn b/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn
new file mode 100644
index 0000000..c505e9a
--- /dev/null
+++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn
@@ -0,0 +1,26 @@
+# Copyright (C) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/test.gni")
+module_output_path = "device_usage_statistics/interfaces"
+
+ohos_js_unittest("DeviceUsageStatisticsJsTest") {
+ module_out_path = module_output_path
+ hap_profile = "./config.json"
+ certificate_profile = "./ohos_device_usage_statistics.p7b"
+}
+
+group("js_unittest") {
+ testonly = true
+ deps = [ ":DeviceUsageStatisticsJsTest" ]
+}
diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json b/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json
new file mode 100644
index 0000000..88bddc0
--- /dev/null
+++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/config.json
@@ -0,0 +1,74 @@
+{
+ "app": {
+ "bundleName": "com.example.deviceUsageStatistics",
+ "vendor": "example",
+ "version": {
+ "code": 1,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 7,
+ "target": 8
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.example.deviceUsageStatistics",
+ "name": ".MyApplication",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "visible": true,
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "backgroundModes": [
+ "dataTransfer"
+ ],
+ "name": "com.example.deviceUsageStatistics.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "MyApplication",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index"
+ ],
+ "name": "default",
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": false
+ }
+ }
+ ],
+ "defPermissions": [
+ {
+ "name": "ohos.permission.BUNDLE_ACTIVE_INFO"
+ }
+ ],
+ "reqPermissions": [
+ {
+ "name": "ohos.permission.BUNDLE_ACTIVE_INFO"
+ }
+ ]
+ }
+ }
+
\ No newline at end of file
diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js
new file mode 100644
index 0000000..2b3c15c
--- /dev/null
+++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import bundleState from '@ohos.bundleState'
+
+import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
+
+describe("DeviceUsageStatisticsJsTest", function () {
+ beforeAll(function() {
+ /*
+ * @tc.setup: setup invoked before all testcases
+ */
+ console.info('beforeAll called')
+ })
+
+ afterAll(function() {
+ /*
+ * @tc.teardown: teardown invoked after all testcases
+ */
+ console.info('afterAll called')
+ })
+
+ beforeEach(function() {
+ /*
+ * @tc.setup: setup invoked before each testcases
+ */
+ console.info('beforeEach called')
+ })
+
+ afterEach(function() {
+ /*
+ * @tc.teardown: teardown invoked after each testcases
+ */
+ console.info('afterEach caled')
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest001
+ * @tc.desc: test isIdleState promise.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899
+ */
+ it("DeviceUsageStatisticsJsTest001", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest001---------------------------');
+ let bundleName = 'com.example.deviceUsageStatistics';
+ bundleState.isIdleState(bundleName).then((res) => {
+ console.info('BUNDLE_ACTIVE isIdleState promise success.');
+ expect(true).assertEqual(true);
+ }).catch((err) => {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE isIdleState promise failure.');
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest002
+ * @tc.desc: test isIdleState callback.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G
+ */
+ it("DeviceUsageStatisticsJsTest002", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest002---------------------------');
+ let bundleName = 'com.example.deviceUsageStatistics';
+ bundleState.isIdleState(bundleName, (err, res) => {
+ if(err.code === 0) {
+ console.info('BUNDLE_ACTIVE isIdleState callback success.');
+ expect(true).assertEqual(true);
+ } else {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE isIdleState callback failure.');
+ }
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest003
+ * @tc.desc: test queryAppUsagePriorityGroup promise.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899
+ */
+ it("DeviceUsageStatisticsJsTest003", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest003---------------------------');
+ bundleState.queryAppUsagePriorityGroup().then( res => {
+ console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise success.');
+ expect(true).assertEqual(true)
+ }).catch( err => {
+ expect(false).assertEqual(true)
+ console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failure.');
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest004
+ * @tc.desc: test queryAppUsagePriorityGroup callback.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G
+ */
+ it("DeviceUsageStatisticsJsTest004", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest004---------------------------');
+ bundleState.queryAppUsagePriorityGroup((err, res) => {
+ if(err.code === 0) {
+ console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback success.');
+ expect(true).assertEqual(true)
+ } else {
+ expect(false).assertEqual(true)
+ console.info('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failure.');
+ }
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest005
+ * @tc.desc: test queryBundleActiveStates promise.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899
+ */
+ it("DeviceUsageStatisticsJsTest005", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest005---------------------------');
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryBundleActiveStates(beginTime, endTime).then((res) => {
+ console.info('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
+ expect(true).assertEqual(true);
+ }).catch((err) => {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryBundleActiveStates promise failure.');
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest006
+ * @tc.desc: test queryBundleActiveStates callback.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G
+ */
+ it("DeviceUsageStatisticsJsTest006", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest006---------------------------');
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryBundleActiveStates(beginTime, endTime, (err, res) => {
+ if(err.code === 0) {
+ console.info('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
+ expect(true).assertEqual(true);
+ } else {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryBundleActiveStates callback failure.');
+ }
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest007
+ * @tc.desc: test queryBundleStateInfos promise.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899
+ */
+ it("DeviceUsageStatisticsJsTest007", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest007---------------------------');
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryBundleStateInfos(beginTime, endTime).then((res) => {
+ console.info('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
+ expect(true).assertEqual(true);
+ }).catch((err) => {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryBundleStateInfos promise failure.');
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest008
+ * @tc.desc: test queryBundleStateInfos callback.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G
+ */
+ it("DeviceUsageStatisticsJsTest008", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest008---------------------------');
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryBundleStateInfos(beginTime, endTime, (err, res) => {
+ if(err.code === 0) {
+ console.info('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
+ expect(true).assertEqual(true);
+ } else {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryBundleStateInfos callback failure.');
+ }
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest009
+ * @tc.desc: test queryCurrentBundleActiveStates promise.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899
+ */
+ it("DeviceUsageStatisticsJsTest009", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest009---------------------------');
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryCurrentBundleActiveStates(beginTime, endTime).then((res) => {
+ console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
+ expect(true).assertEqual(true);
+ }).catch((err) => {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failure.');
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest010
+ * @tc.desc: test queryCurrentBundleActiveStates callback.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G
+ */
+ it("DeviceUsageStatisticsJsTest010", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest010---------------------------');
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryCurrentBundleActiveStates(beginTime, endTime, (err, res) => {
+ if(err.code === 0) {
+ console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
+ expect(true).assertEqual(true);
+ } else {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failure.');
+ }
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest011
+ * @tc.desc: test queryBundleStateInfoByInterval promise.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89H AR000GH89I AR000GH899
+ */
+ it("DeviceUsageStatisticsJsTest011", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest011---------------------------');
+ let intervalType = 0;
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryBundleStateInfoByInterval(intervalType, beginTime, endTime).then((res) => {
+ console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
+ expect(true).assertEqual(true);
+ }).catch((err) => {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failure.');
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+
+ /*
+ * @tc.name: DeviceUsageStatisticsJsTest012
+ * @tc.desc: test queryBundleStateInfoByInterval callback.
+ * @tc.type: FUNC
+ * @tc.require: SR000GGTN7 AR000GH89E AR000GH89F AR000GH89G
+ */
+ it("DeviceUsageStatisticsJsTest012", 0, async function (done) {
+ console.info('----------------------DeviceUsageStatisticsJsTest012---------------------------');
+ let intervalType = 0;
+ let beginTime = 0;
+ let endTime = 20000000000000;
+ bundleState.queryBundleStateInfoByInterval(intervalType, beginTime, endTime, (err, res) => {
+ if(err.code === 0) {
+ console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
+ expect(true).assertEqual(true);
+ } else {
+ expect(false).assertEqual(true);
+ console.info('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failure.');
+ }
+ });
+
+ setTimeout(()=>{
+ done();
+ }, 500);
+ })
+})
\ No newline at end of file
diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/ohos_device_usage_statistics.p7b b/interfaces/test/unittest/device_usage_statistics_jsunittest/ohos_device_usage_statistics.p7b
new file mode 100644
index 0000000000000000000000000000000000000000..6d38035da96bab2ca3e7cdb4cc9d76c1d8cdd32f
GIT binary patch
literal 3451
zcmcgvYj6|S8MPjkF-Blwz(4^T;n)O_eOH!j$sq~5(&~j*FH5%Nh?w=
z2!x2njUhm33b+^(^D@w2k^vIq&V-~%10^Xi1j=M6kPzx=p)@oF0u2+|UE2klfghdB
zpdZ@#zI*Q8v)?`6xpP5E%!o4QwCY=Li+LIRu9P?cQerQk$AiQmOO&~|RnH>?LOu_q
z(x*HC^14##qlKw-(Gp2B5sd{Sq|_7f5|RpN-u(oLhuMS#Dh9Ia-WZYlq{NVp}5IWB1GUZf=%EQCG`elbTsIW)7*MP
zh)AqHNYaEqigQ^O*o=pQ-XPr~saPT*Bec{__##n`nL;I3mMLTk<-CDB?xTq)n=VtT
zUV0Yt=5GoLt8w$>Ufn-+v2WK#R)rF
zhanyv3^`DB0<+pnk&wGF5b%VdW;faBuhvxuT%_BMHehOW00k#7{9%-}7Gd1FP=mA9
zM!98jzZIa2KHxE74Jd;(z%48XyCGq=V~H9zYtl3(um&t~Ki7anFl&raTL(DmP{ydS
zH=qs-F%0qwV3jWNp*0gaJ6t>XoiRI#s+hVOg~3^Cq}?)w!l1QetF__&&
z>cK-ORLgjD3Cbzc0-UXdL2C@T+3)qp988TJwj+MeP<0ImS7{eHSZfSH7?T=??QW-8
zZM9N03ZJ*psW-_L&7igv*5e6C)?h)rs3sEA+6;9NQ5#N}oyjVli!?HrFQyMT94de+
zLk3{4b=HxlupfhBk>YvP6OBY5xYAO^#om{mUdJ|9P!f9
zs_OE%57qi`18qyf<^i--iNHQ3iolo}k;9ChtEdf_5yXjVEp#Fp4}@H#$A(yAMla*3
zYpRT^A|^+*AID%ur&c%VsxY~VovlHvum*==rp{_ez(yJe7ORYsYYg!cD&`_9F>j?>
z_jL-}Z>6*e&XsyHmGAwt!`l8B2;
z!XYhCYDl*+YBtkm(%Ph8^kz#)<3!|U+L1InjqGbY5ju*J#)L7civ>ztDm4c2VNUG4kRf7R%z|oNGv^
z#^8YOL`gg(S=yBn{R5=<^FfODL6?Bf!n$r@%X&=io%WwUa!hh_8a1RjQFftlQpAZP0EA()~!#Kn7%xjD0HVa>a5LBrAo6LO}gU5qrk|=r{2}?BM3x)wZmmxsXgf%DmfA8zw|25onc;c~N&fe6cEngvS&*S~AXU^|mzj*%A3~YD#Ey3sC
z9wGU2?Jwkg@P{tzy39!*zac*%AXgokylJ})SU?_2XZkGRWH4#@gg>|TN+$g&YwN<^
z3r{cU`!;>)HmMGb0ne^=6U=H&VVKf9Lx!*}&!
zo^9lw34&?B$A{APuGyEFa<}Z$7mP=){etKVi1t6#nayaQ|KZxU_TI0Nwchi-TbFj-
zytG(ciqd);JoImm4z2p2%KKB)2nnd7E6Jli-TGlm+S8Tp6HXgY*JMxVO4li8NC(YX2{Qgy^^VEwS
z+ZLq0fA6$Ys9S~U+Nll5&b?hX`|9u7yT^>Z;CXHB7rOD=Ulm_Gv~%0t`iXZ7^HxPK
zX;(v_-$tQ^BX(Q)*f8Duc&+U>XTy*RrJkxb@?1c(zSEzH0hQz
zpG1VSg3cnkgAWScD)@P1(cW1Zwh22{-|TuF7++}7{5y{JQ#+bFH{S#so6PH4&hE-R
zGq?MMZgOint0SD%QU8#RW)L4fHYF!C(<{{bc8k92xn4B&v$JoAe|xBW$1X^ED=Z&_u>>H=rXSUsWdGW!yd3UZJyR_zesbjkb;3LfGksA3w
zH1o9qnI(
zU#6V&YX7J5H=jLM45fGrSdq
Date: Mon, 7 Mar 2022 20:44:17 +0800
Subject: [PATCH 07/87] =?UTF-8?q?=E5=88=A0=E9=99=A4is?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_service.cpp | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 09eb93d..b34d312 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -214,15 +214,7 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName)
int result = -1;
OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId);
if (ret == ERR_OK && userId != -1) {
- BUNDLE_ACTIVE_LOGI("IsBundleIdle user id is %{public}d", userId);
- if (!GetBundleMgrProxy()) {
- BUNDLE_ACTIVE_LOGE("Get bundle manager proxy failed!");
- return true;
- }
- bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(callingUid);
- if (bundleIsSystemApp == true) {
- result = bundleActiveCore_->IsBundleIdle(bundleName, userId);
- }
+ result = bundleActiveCore_->IsBundleIdle(bundleName, userId);
}
if (result == 0) {
return false;
@@ -321,15 +313,9 @@ std::vector BundleActiveService::QueryCurrentEvents(const int
int userId = -1;
OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId);
if (ret == ERR_OK && userId != -1) {
- BUNDLE_ACTIVE_LOGI("QueryCurrentEvents userid is %{public}d", userId);
- if (!GetBundleMgrProxy()) {
- BUNDLE_ACTIVE_LOGE("QueryCurrentEvents get bundle manager proxy failed!");
- return result;
- }
std::string bundleName = "";
sptrBundleMgr_->GetBundleNameForUid(callingUid, bundleName);
- bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId);
- if (!bundleName.empty() && isSystemAppAndHasPermission == true) {
+ if (!bundleName.empty()) {
BUNDLE_ACTIVE_LOGI("QueryCurrentEvents buindle name is %{public}s",
bundleName.c_str());
result = bundleActiveCore_->QueryEvents(userId, beginTime, endTime, bundleName);
--
Gitee
From 3abd4fec4c744c4af8693fd78d713472796cbb05 Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Mon, 7 Mar 2022 21:30:26 +0800
Subject: [PATCH 08/87] 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 09/87] 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 10/87] 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 bbefb26a9b6db7159a7e2e4d9644ba1794d090e6 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 10:18:31 +0800
Subject: [PATCH 11/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9core=E7=B1=BBlastusedus?=
=?UTF-8?q?er=E5=8F=98=E9=87=8F=E8=B5=8B=E5=80=BC=E6=96=B9=E5=BC=8F?=
=?UTF-8?q?=EF=BC=8C=E9=80=82=E9=85=8DOH=E4=B8=8A=E5=85=88=E5=8F=91?=
=?UTF-8?q?=E9=80=81=E5=AD=90=E7=94=A8=E6=88=B7=E5=BA=94=E7=94=A8=E5=89=8D?=
=?UTF-8?q?=E5=8F=B0=E4=BA=8B=E4=BB=B6=EF=BC=8C=E5=86=8D=E5=88=87=E6=8D=A2?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E8=A1=8C=E4=B8=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/include/bundle_active_core.h | 3 +-
.../src/bundle_active_app_state_obsever.cpp | 3 +-
...bundle_active_continuous_task_observer.cpp | 3 +-
services/common/src/bundle_active_core.cpp | 30 ++++++++++++-------
services/common/src/bundle_active_service.cpp | 4 +--
.../src/bundle_active_report_handler.cpp | 5 +++-
6 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h
index 928e667..d5fc211 100644
--- a/services/common/include/bundle_active_core.h
+++ b/services/common/include/bundle_active_core.h
@@ -37,6 +37,7 @@ public:
int userId_;
std::string bundleName_;
BundleActiveReportHandlerObject();
+ BundleActiveReportHandlerObject(const int userId, const std::string bundleName);
BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig);
~BundleActiveReportHandlerObject() {};
};
@@ -116,7 +117,7 @@ public:
const int64_t timeStamp);
// when received a USER_REMOVED commen event, call it to remove data.
void OnUserRemoved(const int userId);
- void OnUserSwitched();
+ void OnUserSwitched(const int userId);
// force set app group.
void SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId);
// get all user in device
diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp
index 1bebdd5..0a9b881 100644
--- a/services/common/src/bundle_active_app_state_obsever.cpp
+++ b/services/common/src/bundle_active_app_state_obsever.cpp
@@ -44,12 +44,11 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData
std::stringstream stream;
stream << abilityStateData.token.GetRefPtr();
std::string abilityId = stream.str();
- BundleActiveReportHandlerObject tmpHandlerObject;
+ BundleActiveReportHandlerObject tmpHandlerObject(userId, "");
tmpHandlerObject.event_.bundleName_ = abilityStateData.bundleName;
tmpHandlerObject.event_.abilityName_ = abilityStateData.abilityName;
tmpHandlerObject.event_.abilityId_ = abilityStateData.abilityName;
tmpHandlerObject.event_.continuousTaskAbilityName_ = "";
- tmpHandlerObject.userId_ = userId;
sptr timer = MiscServices::TimeServiceClient::GetInstance();
tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs();
switch (abilityStateData.abilityState) {
diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp
index 459524f..a64c720 100644
--- a/services/common/src/bundle_active_continuous_task_observer.cpp
+++ b/services/common/src/bundle_active_continuous_task_observer.cpp
@@ -88,12 +88,11 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent(
OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
if (ret == ERR_OK && userId != -1 && !bundleName.empty()) {
std::stringstream stream;
- BundleActiveReportHandlerObject tmpHandlerObject;
+ BundleActiveReportHandlerObject tmpHandlerObject(userId, "");
tmpHandlerObject.event_.bundleName_ = bundleName;
tmpHandlerObject.event_.abilityName_ = "";
tmpHandlerObject.event_.abilityId_ = abilityId;
tmpHandlerObject.event_.continuousTaskAbilityName_ = abiliytName;
- tmpHandlerObject.userId_ = userId;
sptr timer = MiscServices::TimeServiceClient::GetInstance();
tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs();
if (isStart) {
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 31b768e..9a537fb 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -29,6 +29,12 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject()
bundleName_ = "";
}
+BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const int userId, const std::string bundleName)
+{
+ userId_ = userId;
+ bundleName_ = bundleName;
+}
+
BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig)
{
event_.bundleName_ = orig.event_.bundleName_;
@@ -71,8 +77,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
if (!bundleActiveReportHandler_.expired()) {
int32_t userId = data.GetCode();
BUNDLE_ACTIVE_LOGI("remove user id %{public}d", userId);
- BundleActiveReportHandlerObject tmpHandlerObject;
- tmpHandlerObject.userId_ = userId;
+ BundleActiveReportHandlerObject tmpHandlerObject(userId, "");
std::shared_ptr handlerobjToPtr =
std::make_shared(tmpHandlerObject);
auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REMOVE_USER, handlerobjToPtr);
@@ -81,7 +86,10 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
} else if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
int32_t userId = data.GetCode();
BUNDLE_ACTIVE_LOGI("OnReceiveEvent receive switched user event, user id is %{public}d", userId);
- auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER);
+ BundleActiveReportHandlerObject tmpHandlerObject(userId, "");
+ std::shared_ptr handlerobjToPtr =
+ std::make_shared(tmpHandlerObject);
+ auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_SWITCH_USER, handlerobjToPtr);
bundleActiveReportHandler_.lock()->SendEvent(event);
} else if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED ||
action == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) {
@@ -90,9 +98,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
BUNDLE_ACTIVE_LOGI("action is %{public}s, userID is %{public}d, bundlename is %{public}s",
action.c_str(), userId, bundleName.c_str());
if (!bundleActiveReportHandler_.expired()) {
- BundleActiveReportHandlerObject tmpHandlerObject;
- tmpHandlerObject.bundleName_ = bundleName;
- tmpHandlerObject.userId_ = userId;
+ BundleActiveReportHandlerObject tmpHandlerObject(userId, bundleName);
std::shared_ptr handlerobjToPtr =
std::make_shared(tmpHandlerObject);
auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED,
@@ -356,12 +362,13 @@ void BundleActiveCore::OnUserRemoved(const int userId)
bundleGroupController_->OnUserRemoved(userId);
}
-void BundleActiveCore::OnUserSwitched()
+void BundleActiveCore::OnUserSwitched(const int userId)
{
sptr timer = MiscServices::TimeServiceClient::GetInstance();
auto it = userStatServices_.find(lastUsedUser_);
if (it != userStatServices_.end()) {
if (it != userStatServices_.end()) {
+ BUNDLE_ACTIVE_LOGI("restore old user id %{public}d data when switch user", lastUsedUser_);
BundleActiveEvent event;
event.eventId_ = BundleActiveEvent::FLUSH;
int64_t actualRealTime = timer->GetBootTimeMs();
@@ -381,16 +388,19 @@ void BundleActiveCore::OnUserSwitched()
BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]);
bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i]);
}
+ OnStatsChanged(userId);
}
int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId)
{
std::lock_guard lock(mutex_);
- lastUsedUser_ = userId;
- if (userId == 0) {
+ if (userId == 0 || userId == -1) {
return -1;
}
- BUNDLE_ACTIVE_LOGI("ReportEvent called");
+ if (lastUsedUser_ == -1) {
+ lastUsedUser_ = userId;
+ BUNDLE_ACTIVE_LOGI("last used id change to %{public}d", lastUsedUser_);
+ }
BUNDLE_ACTIVE_LOGI("report event called bundle name %{public}s time %{public}lld userId %{public}d, "
"eventid %{public}d, in lock range", event.bundleName_.c_str(), event.timeStamp_, userId, event.eventId_);
sptr timer = MiscServices::TimeServiceClient::GetInstance();
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 09eb93d..468efa3 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -186,14 +186,12 @@ void BundleActiveService::OnStop()
int BundleActiveService::ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId,
const std::string& continuousTask, const int userId, const int eventId)
{
- BUNDLE_ACTIVE_LOGI("report event called123123");
- BundleActiveReportHandlerObject tmpHandlerObject;
+ BundleActiveReportHandlerObject tmpHandlerObject(userId, "");
tmpHandlerObject.event_.bundleName_ = bundleName;
tmpHandlerObject.event_.abilityName_ = abilityName;
tmpHandlerObject.event_.abilityId_ = abilityId;
tmpHandlerObject.event_.eventId_ = eventId;
tmpHandlerObject.event_.continuousTaskAbilityName_ = continuousTask;
- tmpHandlerObject.userId_ = userId;
sptr timer = MiscServices::TimeServiceClient::GetInstance();
tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs();
std::shared_ptr handlerobjToPtr =
diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp
index 33b734d..52206a8 100644
--- a/services/packageusage/src/bundle_active_report_handler.cpp
+++ b/services/packageusage/src/bundle_active_report_handler.cpp
@@ -69,7 +69,10 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point
break;
}
case MSG_SWITCH_USER: {
- bundleActiveCore_->OnUserSwitched();
+ BUNDLE_ACTIVE_LOGI("MSG_SWITCH_USER CALLED");
+ auto ptrToHandlerobj = event->GetSharedObject();
+ BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj;
+ bundleActiveCore_->OnUserSwitched(tmpHandlerobj.userId_);
}
default: {
break;
--
Gitee
From 9913b3300b99d76bf0e2a95a7245e38c877a4277 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 10:20:16 +0800
Subject: [PATCH 12/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9core=E7=B1=BBlastusedus?=
=?UTF-8?q?er=E5=8F=98=E9=87=8F=E8=B5=8B=E5=80=BC=E6=96=B9=E5=BC=8F?=
=?UTF-8?q?=EF=BC=8C=E9=80=82=E9=85=8DOH=E4=B8=8A=E5=85=88=E5=8F=91?=
=?UTF-8?q?=E9=80=81=E5=AD=90=E7=94=A8=E6=88=B7=E5=BA=94=E7=94=A8=E5=89=8D?=
=?UTF-8?q?=E5=8F=B0=E4=BA=8B=E4=BB=B6=EF=BC=8C=E5=86=8D=E5=88=87=E6=8D=A2?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E8=A1=8C=E4=B8=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 9a537fb..052dbfa 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -388,6 +388,7 @@ void BundleActiveCore::OnUserSwitched(const int userId)
BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]);
bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i]);
}
+ lastUsedUser_ = userId;
OnStatsChanged(userId);
}
--
Gitee
From 2d24e17a8f39a1ab08addb7bc09baa0b51b63eb1 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 10:33:27 +0800
Subject: [PATCH 13/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9core=E7=B1=BBlastusedus?=
=?UTF-8?q?er=E5=8F=98=E9=87=8F=E8=B5=8B=E5=80=BC=E6=96=B9=E5=BC=8F?=
=?UTF-8?q?=EF=BC=8C=E9=80=82=E9=85=8DOH=E4=B8=8A=E5=85=88=E5=8F=91?=
=?UTF-8?q?=E9=80=81=E5=AD=90=E7=94=A8=E6=88=B7=E5=BA=94=E7=94=A8=E5=89=8D?=
=?UTF-8?q?=E5=8F=B0=E4=BA=8B=E4=BB=B6=EF=BC=8C=E5=86=8D=E5=88=87=E6=8D=A2?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E8=A1=8C=E4=B8=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packageusage/src/bundle_active_report_handler.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp
index 52206a8..3fc4a79 100644
--- a/services/packageusage/src/bundle_active_report_handler.cpp
+++ b/services/packageusage/src/bundle_active_report_handler.cpp
@@ -69,7 +69,7 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point
break;
}
case MSG_SWITCH_USER: {
- BUNDLE_ACTIVE_LOGI("MSG_SWITCH_USER CALLED");
+ BUNDLE_ACTIVE_LOGI("MSG_SWITCH_USER CALLED");
auto ptrToHandlerobj = event->GetSharedObject();
BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj;
bundleActiveCore_->OnUserSwitched(tmpHandlerobj.userId_);
--
Gitee
From 2140bcb4de87aa887eabc209232ca3f90eddd903 Mon Sep 17 00:00:00 2001
From: ql
Date: Tue, 8 Mar 2022 11:07:52 +0800
Subject: [PATCH 14/87] remove dependency of dmsfwk
Signed-off-by: ql
Change-Id: Ic7f28074db3efa4d6a87d89af2006e127831f31d
---
BUILD.gn | 3 ---
bundle.json | 1 -
2 files changed, 4 deletions(-)
diff --git a/BUILD.gn b/BUILD.gn
index 7a44408..da4c675 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -34,7 +34,6 @@ ohos_shared_library("usagestatsinner") {
]
external_deps = [
- "dmsfwk_standard:zuri",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
@@ -68,7 +67,6 @@ ohos_shared_library("bundlestate") {
deps = [ "//foundation/resourceschedule/${device_usage_statistics_part_name}:usagestatsinner" ]
external_deps = [
- "dmsfwk_standard:zuri",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
@@ -124,7 +122,6 @@ ohos_shared_library("usagestatservice") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"ces_standard:cesfwk_innerkits",
- "dmsfwk_standard:zuri",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
diff --git a/bundle.json b/bundle.json
index 014b937..e60fd68 100644
--- a/bundle.json
+++ b/bundle.json
@@ -31,7 +31,6 @@
"want",
"appexecfwk_base",
"appexecfwk_core",
- "zuri",
"base",
"time_service",
"utils",
--
Gitee
From a16113db12d789cd5caae4312f6151dc37ee1d71 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 11:33:03 +0800
Subject: [PATCH 15/87] =?UTF-8?q?codex=EF=BC=8C=E5=86=85=E6=BA=90issue?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
interfaces/innerkits/src/bundle_active_client.cpp | 6 +++---
services/common/src/bundle_active_binary_search.cpp | 3 ++-
services/common/src/bundle_active_service.cpp | 2 +-
.../packagegroup/include/bundle_active_group_controller.h | 2 +-
.../packagegroup/src/bundle_active_group_controller.cpp | 2 +-
services/packagegroup/src/bundle_active_user_history.cpp | 1 +
services/packageusage/src/bundle_active_event_stats.cpp | 1 +
7 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp
index 1487c37..6a3f282 100644
--- a/interfaces/innerkits/src/bundle_active_client.cpp
+++ b/interfaces/innerkits/src/bundle_active_client.cpp
@@ -27,19 +27,19 @@ BundleActiveClient& BundleActiveClient::GetInstance()
bool BundleActiveClient::GetBundleActiveProxy()
{
sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
- if (samgr == nullptr) {
+ if (!samgr) {
BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager.");
return false;
}
sptr object = samgr->GetSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID);
- if (object == nullptr) {
+ if (!object) {
BUNDLE_ACTIVE_LOGE("Failed to get SystemAbility[1920] .");
return false;
}
bundleActiveProxy_ = iface_cast(object);
- if (bundleActiveProxy_ == nullptr) {
+ if (!bundleActiveProxy_) {
BUNDLE_ACTIVE_LOGE("Failed to get BundleActiveClient.");
return false;
}
diff --git a/services/common/src/bundle_active_binary_search.cpp b/services/common/src/bundle_active_binary_search.cpp
index f16cf93..28ce020 100644
--- a/services/common/src/bundle_active_binary_search.cpp
+++ b/services/common/src/bundle_active_binary_search.cpp
@@ -30,8 +30,9 @@ int32_t BundleActiveBinarySearch::BinarySearch(const std::vector &table
{
int32_t low = 0;
int32_t high = static_cast(tableNameArray.size() - 1);
+ int32_t divider = 2;
while (low <= high) {
- int32_t mid = (low + high) >> 1;
+ int32_t mid = (low + high) / divider;
int64_t midValue = tableNameArray.at(mid);
if (midValue < targetValue) {
low = mid + 1;
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 09eb93d..7853b3b 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -100,7 +100,7 @@ void BundleActiveService::InitNecessaryState()
}
try {
shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_);
- } catch(const std::bad_alloc &e) {
+ } catch (const std::bad_alloc &e) {
BUNDLE_ACTIVE_LOGE("Memory allocation failed");
return;
}
diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h
index 6763202..a5d57b3 100644
--- a/services/packagegroup/include/bundle_active_group_controller.h
+++ b/services/packagegroup/include/bundle_active_group_controller.h
@@ -94,7 +94,7 @@ private:
int64_t timeoutForDirectlyUse_ = debug_ ? THREE_MINUTE : ONE_HOUR;
int64_t timeoutForNotifySeen_ = debug_ ? ONE_MINUTE : TWELVE_HOUR;
int64_t timeoutForSystemInteraction_ = debug_ ? ONE_MINUTE : TEN_MINUTE;
- int64_t timeoutCalculated_;
+ int64_t timeoutCalculated_ = 0;
sptr sptrBundleMgr_;
bool calculationTimeOut(const std::shared_ptr& oneBundleHistory,
const int64_t bootBasedTimeStamp);
diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp
index 519311f..82062ab 100644
--- a/services/packagegroup/src/bundle_active_group_controller.cpp
+++ b/services/packagegroup/src/bundle_active_group_controller.cpp
@@ -221,7 +221,7 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co
return;
}
int64_t timeUntilNextCheck;
- int eventReason = EventToGroupReason(eventId);
+ uint32_t eventReason = EventToGroupReason(eventId);
switch (eventId) {
case BundleActiveEvent::NOTIFICATION_SEEN:
bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_DAILY,
diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp
index 5179f8f..599907d 100644
--- a/services/packagegroup/src/bundle_active_user_history.cpp
+++ b/services/packagegroup/src/bundle_active_user_history.cpp
@@ -31,6 +31,7 @@ BundleActivePackageHistory::BundleActivePackageHistory()
reasonInGroup_ = DeviceUsageStatsGroupConst::GROUP_CONTROL_REASON_DEFAULT;
bundleAliveTimeoutTimeStamp_ = 0;
bundleDailyTimeoutTimeStamp_ = 0;
+ lastCalculatedGroup_ = 60;
};
void BundleActiveUserHistory::WriteDeviceDuration()
diff --git a/services/packageusage/src/bundle_active_event_stats.cpp b/services/packageusage/src/bundle_active_event_stats.cpp
index 4dfa187..3bb55e0 100644
--- a/services/packageusage/src/bundle_active_event_stats.cpp
+++ b/services/packageusage/src/bundle_active_event_stats.cpp
@@ -19,6 +19,7 @@ namespace OHOS {
namespace DeviceUsageStats {
BundleActiveEventStats::BundleActiveEventStats()
{
+ eventId_ = 0;
beginTimeStamp_ = 0;
endTimeStamp_ = 0;
lastEventTime_ = 0;
--
Gitee
From 6510b5eb463885957bcbce9c795a3fb935849cbd Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 14:45:45 +0800
Subject: [PATCH 16/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=94=E7=94=A8?=
=?UTF-8?q?=E6=9C=80=E8=BF=91=E4=B8=80=E6=AC=A1=E4=BD=BF=E7=94=A8=E6=97=B6?=
=?UTF-8?q?=E9=97=B4=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C?=
=?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BA-1=EF=BC=8C=E5=90=8C?=
=?UTF-8?q?=E6=AD=A5=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93=E8=90=BD?=
=?UTF-8?q?=E7=9B=98/=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
.../src/bundle_active_usage_database.cpp | 33 ++++++++-----------
.../src/bundle_active_package_stats.cpp | 2 +-
2 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index cc0f7a2..fa9c2e3 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -685,13 +685,12 @@ void BundleActiveUsageDatabase::FlushPackageInfo(unsigned int databaseType, cons
queryCondition.push_back(to_string(stats.userId_));
queryCondition.push_back(iter->first);
valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_STARTED_COUNT, iter->second->bundleStartedCount_);
- valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, (iter->second->lastTimeUsed_ - stats.beginTime_));
- if (iter->second->lastContiniousTaskUsed_ == -1) {
- valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, (iter->second->lastContiniousTaskUsed_));
- } else {
- valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, (iter->second->lastContiniousTaskUsed_ -
- stats.beginTime_));
- }
+ int64_t lastTimeUsedAdjusted = iter->second->lastTimeUsed_ == -1 ?
+ iter->second->lastTimeUsed_ : iter->second->lastTimeUsed_ - stats.beginTime_;
+ valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, lastTimeUsedAdjusted);
+ int64_t lastContinuousTaskUsedAdjusted = iter->second->lastContiniousTaskUsed_ == -1 ?
+ iter->second->lastContiniousTaskUsed_ : iter->second->lastContiniousTaskUsed_ - stats.beginTime_;
+ valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, lastContinuousTaskUsedAdjusted);
valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME, iter->second->totalInFrontTime_);
valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK, iter->second->totalContiniousTaskUsedTime_);
rdbStore->Update(changeRow, tableName, valuesBucket, "userId = ? and bundleName = ?", queryCondition);
@@ -746,13 +745,11 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa
bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, usageStats->bundleName_);
bundleActiveResult->GetInt(BUNDLE_STARTED_COUNT_COLUMN_INDEX, usageStats->bundleStartedCount_);
bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, relativeLastTimeUsed);
- usageStats->lastTimeUsed_ = relativeLastTimeUsed + currentPackageTime;
+ usageStats->lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 :
+ relativeLastTimeUsed + currentPackageTime;
bundleActiveResult->GetLong(LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX, relativeLastTimeFrontServiceUsed);
- if (relativeLastTimeFrontServiceUsed == -1) {
- usageStats->lastContiniousTaskUsed_ = -1;
- } else {
- usageStats->lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed + currentPackageTime;
- }
+ usageStats->lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed == -1 ? -1 :
+ relativeLastTimeFrontServiceUsed + currentPackageTime;
bundleActiveResult->GetLong(TOTAL_TIME_COLUMN_INDEX, usageStats->totalInFrontTime_);
bundleActiveResult->GetLong(TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX, usageStats->totalContiniousTaskUsedTime_);
bundleStats.insert(pair>(usageStats->bundleName_,
@@ -1082,13 +1079,11 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt
bundleActiveResult->GetInt(BUNDLE_STARTED_COUNT_COLUMN_INDEX, usageStats.bundleStartedCount_);
bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, usageStats.lastTimeUsed_);
bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, relativeLastTimeUsed);
- usageStats.lastTimeUsed_ = relativeLastTimeUsed + packageTableTime;
+ usageStats->lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 :
+ relativeLastTimeUsed + packageTableTime;
bundleActiveResult->GetLong(LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX, relativeLastTimeFrontServiceUsed);
- if (relativeLastTimeFrontServiceUsed == -1) {
- usageStats.lastContiniousTaskUsed_ = -1;
- } else {
- usageStats.lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed + packageTableTime;
- }
+ usageStats.lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed == -1 ? -1 :
+ relativeLastTimeFrontServiceUsed + packageTableTime;
bundleActiveResult->GetLong(TOTAL_TIME_COLUMN_INDEX, usageStats.totalInFrontTime_);
bundleActiveResult->GetLong(TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX,
usageStats.totalContiniousTaskUsedTime_);
diff --git a/services/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp
index 95205f0..022bfc4 100644
--- a/services/packageusage/src/bundle_active_package_stats.cpp
+++ b/services/packageusage/src/bundle_active_package_stats.cpp
@@ -22,7 +22,7 @@ BundleActivePackageStats::BundleActivePackageStats()
bundleName_.clear();
beginTimeStamp_ = 0; // start time of counting
endTimeStamp_ = 0; // stop time of counting
- lastTimeUsed_ = 0; // the timestamp of last launch
+ lastTimeUsed_ = -1; // the timestamp of last launch
totalInFrontTime_ = 0; // the total time of bundle in front.
lastContiniousTaskUsed_ = -1; // the timestamp of bundle calling a continuous task.
totalContiniousTaskUsedTime_ = 0; // the total time of bundle use continuous tasks.
--
Gitee
From ab00994d6a6bf1a0bfd70142585f8770413746f4 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 15:10:27 +0800
Subject: [PATCH 17/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=94=E7=94=A8?=
=?UTF-8?q?=E6=9C=80=E8=BF=91=E4=B8=80=E6=AC=A1=E4=BD=BF=E7=94=A8=E6=97=B6?=
=?UTF-8?q?=E9=97=B4=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C?=
=?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BA-1=EF=BC=8C=E5=90=8C?=
=?UTF-8?q?=E6=AD=A5=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93=E8=90=BD?=
=?UTF-8?q?=E7=9B=98/=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
.../packageusage/src/bundle_active_user_service.cpp | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index ed0dd0f..60a4a4b 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -161,12 +161,15 @@ void BundleActiveUserService::RestoreStats(bool forced)
if (statsChanged_ || forced) {
BUNDLE_ACTIVE_LOGI("RestoreStats() stat changed is true");
for (uint32_t i = 0; i < currentStats_.size(); i++) {
- if (currentStats_[i] != nullptr) {
+ if (currentStats_[i]) {
+ if (currentStats_[i]->bundleStats_.empty() && currentStats_[i]->events_.events_.empty()) {
+ continue;
+ }
database_.UpdateUsageData(i, *(currentStats_[i]));
- }
- if (i == 0) {
- BUNDLE_ACTIVE_LOGI("RESOTRE EVENT SIZE IS %{public}d, USER ID IS %{public}d",
- currentStats_[i]->events_.Size(), userId_);
+ if (i == 0) {
+ BUNDLE_ACTIVE_LOGI("RESOTRE EVENT SIZE IS %{public}d, USER ID IS %{public}d",
+ currentStats_[i]->events_.Size(), userId_);
+ }
}
}
currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear();
--
Gitee
From 564e5bc0bd99d9c13eb308b3aa8477168f033225 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 15:36:09 +0800
Subject: [PATCH 18/87] =?UTF-8?q?codex=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packagegroup/src/bundle_active_user_history.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp
index 599907d..5055d7c 100644
--- a/services/packagegroup/src/bundle_active_user_history.cpp
+++ b/services/packagegroup/src/bundle_active_user_history.cpp
@@ -31,7 +31,7 @@ BundleActivePackageHistory::BundleActivePackageHistory()
reasonInGroup_ = DeviceUsageStatsGroupConst::GROUP_CONTROL_REASON_DEFAULT;
bundleAliveTimeoutTimeStamp_ = 0;
bundleDailyTimeoutTimeStamp_ = 0;
- lastCalculatedGroup_ = 60;
+ lastCalculatedGroup_ = ACTIVE_GROUP_NEVER;
};
void BundleActiveUserHistory::WriteDeviceDuration()
--
Gitee
From 0ede0ed85629558148ad8dd181bf0b6d8f8a5433 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 15:55:20 +0800
Subject: [PATCH 19/87] =?UTF-8?q?=E5=88=A0=E9=99=A4restoretostat=E6=97=A0?=
=?UTF-8?q?=E7=94=A8=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packageusage/src/bundle_active_user_service.cpp | 4 ----
1 file changed, 4 deletions(-)
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index 60a4a4b..db4022a 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -166,10 +166,6 @@ void BundleActiveUserService::RestoreStats(bool forced)
continue;
}
database_.UpdateUsageData(i, *(currentStats_[i]));
- if (i == 0) {
- BUNDLE_ACTIVE_LOGI("RESOTRE EVENT SIZE IS %{public}d, USER ID IS %{public}d",
- currentStats_[i]->events_.Size(), userId_);
- }
}
}
currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear();
--
Gitee
From e383808405e409b138c80367419ba4334e3f2e38 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 16:59:00 +0800
Subject: [PATCH 20/87] =?UTF-8?q?=E5=88=A0=E9=99=A4restoretostat=E6=97=A0?=
=?UTF-8?q?=E7=94=A8=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_usage_database.cpp | 2 +-
services/packageusage/src/bundle_active_user_service.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index fa9c2e3..718529d 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -1079,7 +1079,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt
bundleActiveResult->GetInt(BUNDLE_STARTED_COUNT_COLUMN_INDEX, usageStats.bundleStartedCount_);
bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, usageStats.lastTimeUsed_);
bundleActiveResult->GetLong(LAST_TIME_COLUMN_INDEX, relativeLastTimeUsed);
- usageStats->lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 :
+ usageStats.lastTimeUsed_ = relativeLastTimeUsed == -1 ? -1 :
relativeLastTimeUsed + packageTableTime;
bundleActiveResult->GetLong(LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX, relativeLastTimeFrontServiceUsed);
usageStats.lastContiniousTaskUsed_ = relativeLastTimeFrontServiceUsed == -1 ? -1 :
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index db4022a..9682bbc 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -372,7 +372,7 @@ void BundleActiveUserService::PrintInMemPackageStats(const int idx)
int64_t totalUsedTime = it.second->totalInFrontTime_;
int64_t lastTimeContinuousTaskUsed = it.second->lastContiniousTaskUsed_;
int64_t totalTimeContinuousTaskUsed = it.second->totalContiniousTaskUsedTime_;
- BUNDLE_ACTIVE_LOGI("In mem, event stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld"
+ BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld"
"total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld",
totalUsedTime, lastTimeUsed, totalTimeContinuousTaskUsed, lastTimeContinuousTaskUsed);
}
--
Gitee
From bb41f57a59c37ee77188bb659633aedba4d1a9e7 Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Tue, 8 Mar 2022 17:22:27 +0800
Subject: [PATCH 21/87] 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
From 5f15d35122b19e50ba848e62062b4b52b4e3fced Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 19:14:49 +0800
Subject: [PATCH 22/87] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?=
=?UTF-8?q?=E5=9C=A8alive=E4=BF=9D=E6=B4=BB=E6=9C=9F=E5=86=85=E4=B8=8D?=
=?UTF-8?q?=E9=99=8D=E7=BA=A7=E7=9A=84=E5=8E=9F=E5=9B=A0GROUP=5FEVENT=5FRE?=
=?UTF-8?q?ASON=5FALIVE=5FNOT=5FTIMEOUT=3D0x0009?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packagegroup/include/bundle_active_group_common.h | 1 +
services/packagegroup/src/bundle_active_group_controller.cpp | 2 ++
2 files changed, 3 insertions(+)
diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h
index d3fdef4..4d8fe0b 100644
--- a/services/packagegroup/include/bundle_active_group_common.h
+++ b/services/packagegroup/include/bundle_active_group_common.h
@@ -59,6 +59,7 @@ const uint32_t GROUP_EVENT_REASON_BACKGROUND = 0x0005;
const uint32_t GROUP_EVENT_REASON_ALIVE_TIMEOUT = 0x0006;
const uint32_t GROUP_EVENT_REASON_LONG_TIME_TASK_STARTTED = 0x0007;
const uint32_t GROUP_EVENT_REASON_CALCULATED_RESTORED = 0x0008;
+const uint32_t GROUP_EVENT_REASON_ALIVE_NOT_TIMEOUT = 0x0009;
}
}
}
diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp
index 519311f..9510045 100644
--- a/services/packagegroup/src/bundle_active_group_controller.cpp
+++ b/services/packagegroup/src/bundle_active_group_controller.cpp
@@ -281,6 +281,8 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN
bootBasedTimeStampAdjusted) {
newGroup = ACTIVE_GROUP_ALIVE;
groupReason = oneBundleHistory->reasonInGroup_;
+ groupReason = (newGroup == oldGroup) ? oneBundleHistory->reasonInGroup_ : GROUP_CONTROL_REASON_USAGE |
+ GROUP_EVENT_REASON_ALIVE_NOT_TIMEOUT;
} else if (newGroup >= ACTIVE_GROUP_DAILY && oneBundleHistory->bundleDailyTimeoutTimeStamp_ >
bootBasedTimeStampAdjusted) {
newGroup = ACTIVE_GROUP_DAILY;
--
Gitee
From 8ea895dbcee1f66961e7457d7a4fdca464c1bd64 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 8 Mar 2022 20:47:13 +0800
Subject: [PATCH 23/87] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8?=
=?UTF-8?q?=E5=9C=A8alive=E4=BF=9D=E6=B4=BB=E6=9C=9F=E5=86=85=E4=B8=8D?=
=?UTF-8?q?=E9=99=8D=E7=BA=A7=E7=9A=84=E5=8E=9F=E5=9B=A0GROUP=5FEVENT=5FRE?=
=?UTF-8?q?ASON=5FALIVE=5FNOT=5FTIMEOUT=3D0x0009?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_service.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 09eb93d..cb4241a 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -169,7 +169,6 @@ bool BundleActiveService::SubscribeContinuousTask()
return true;
}
-
void BundleActiveService::OnStop()
{
if (shutdownCallback_ != nullptr) {
--
Gitee
From c8c497a3b0eba9ebc15d2fac3a3d0929551169e6 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 9 Mar 2022 11:33:37 +0800
Subject: [PATCH 24/87] =?UTF-8?q?=E6=8E=A7=E5=88=B6handler=E5=88=B7?=
=?UTF-8?q?=E7=9B=98=E4=BA=8B=E4=BB=B6=E4=B8=8A=E6=8A=A5=EF=BC=8C=E8=8B=A5?=
=?UTF-8?q?handler=E5=86=85=E6=97=A0flush=E4=BA=8B=E4=BB=B6=EF=BC=8C?=
=?UTF-8?q?=E5=86=8D=E5=90=91handler=E5=8F=91=E9=80=81=E5=88=B7=E7=9B=98?=
=?UTF-8?q?=E4=BA=8B=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 31b768e..a7227bc 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -212,13 +212,16 @@ void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string&
void BundleActiveCore::OnStatsChanged(const int userId)
{
if (!handler_.expired()) {
- BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event");
BundleActiveReportHandlerObject tmpHandlerObject;
tmpHandlerObject.userId_ = userId;
std::shared_ptr handlerobjToPtr =
std::make_shared(tmpHandlerObject);
auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr);
- handler_.lock()->SendEvent(event, FLUSH_INTERVAL);
+ if (handler_.lock()->HasInnerEvent(static_cast(BundleActiveReportHandler::MSG_FLUSH_TO_DISK)) ==
+ false) {
+ BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event");
+ handler_.lock()->SendEvent(event, FLUSH_INTERVAL);
+ }
}
}
--
Gitee
From 539c12b9daaa9a2906b50a3dd203dadc60596049 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 9 Mar 2022 16:34:08 +0800
Subject: [PATCH 25/87] =?UTF-8?q?=E5=A2=9E=E5=8A=A0subscribeappstate?=
=?UTF-8?q?=E5=87=BD=E6=95=B0=E9=98=B2=E6=8A=A4=EF=BC=8C=E9=98=B2=E6=AD=A2?=
=?UTF-8?q?=E8=8E=B7=E5=8F=96appmanager=E5=A4=B1=E8=B4=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_service.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 09eb93d..3616e25 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -141,7 +141,7 @@ bool BundleActiveService::SubscribeAppState()
{
BUNDLE_ACTIVE_LOGI("SubscribeAppState called");
sptr appManager = GetAppManagerInstance();
- if (appStateObserver_ == nullptr) {
+ if (appStateObserver_ == nullptr || appManager == nullptr) {
BUNDLE_ACTIVE_LOGE("SubscribeAppState appstateobserver is null, return");
return false;
}
--
Gitee
From eca9aedbdbba5fadd9f1832cd2351898fa666bcf Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 9 Mar 2022 19:50:01 +0800
Subject: [PATCH 26/87] =?UTF-8?q?=E5=A2=9E=E5=8A=A0subscribeappstate?=
=?UTF-8?q?=E5=87=BD=E6=95=B0=E9=98=B2=E6=8A=A4=EF=BC=8C=E9=98=B2=E6=AD=A2?=
=?UTF-8?q?=E8=8E=B7=E5=8F=96appmanager=E5=A4=B1=E8=B4=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_service.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 3616e25..09eb93d 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -141,7 +141,7 @@ bool BundleActiveService::SubscribeAppState()
{
BUNDLE_ACTIVE_LOGI("SubscribeAppState called");
sptr appManager = GetAppManagerInstance();
- if (appStateObserver_ == nullptr || appManager == nullptr) {
+ if (appStateObserver_ == nullptr) {
BUNDLE_ACTIVE_LOGE("SubscribeAppState appstateobserver is null, return");
return false;
}
--
Gitee
From 3f53283947c8af67904642bffd257ff5950acecf Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 9 Mar 2022 20:05:06 +0800
Subject: [PATCH 27/87] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?=
=?UTF-8?q?=E5=88=B7=E7=9B=98=E6=97=B6=EF=BC=8C=E5=8F=AA=E6=9B=B4=E6=96=B0?=
=?UTF-8?q?=E6=9C=89=E5=8F=98=E5=8C=96=E7=9A=84=E5=BA=94=E7=94=A8=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=EF=BC=8C=E4=B8=8D=E6=9B=B4=E6=96=B0=E6=9C=AA=E5=8F=98?=
=?UTF-8?q?=E5=8C=96=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_usage_database.cpp | 9 ++++++++-
.../packagegroup/include/bundle_active_package_history.h | 1 +
services/packagegroup/src/bundle_active_user_history.cpp | 2 ++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index 091dd41..4433bcc 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -552,8 +552,11 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId,
int64_t outRowId = BUNDLE_ACTIVE_FAIL;
NativeRdb::ValuesBucket valuesBucket;
vector queryCondition;
+ int updatedcount = 0;
+ int unupdatedcount = 0;
for (auto iter = userHistory->begin(); iter != userHistory->end(); iter++) {
- if (iter->second == nullptr) {
+ if (iter->second == nullptr || !iter->second->isChanged_) {
+ unupdatedcount++;
continue;
}
queryCondition.push_back(to_string(userId));
@@ -576,7 +579,11 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId,
}
valuesBucket.Clear();
queryCondition.clear();
+ iter->second->isChanged_ = false;
+ updatedcount++;
}
+ BUNDLE_ACTIVE_LOGI("PutBundleHistoryData, update %{public}d bundles, keep %{public}d bundles group",
+ updatedcount, unupdatedcount);
}
shared_ptr |
-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<BundleActiveInfoResponse>): 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
+ |
queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void
|
Queries (returns) the priority group used by the current caller application.
- |
isIdleState(bundleName:string, callback:AsyncCallback<boolean>):void
+ |
isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void
|
Judges whether the application of the specified bundle name is currently idle.
|
diff --git a/README_ZH.md b/README_ZH.md
index 8692a54..dad7728 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -41,26 +41,26 @@
-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<BundleActiveInfoResponse>): 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
+ |
queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void
|
查询(返回)当前调用者应用的使用优先级群组。
- |
isIdleState(bundleName:string, callback:AsyncCallback<boolean>):void
+ |
isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void
|
判断指定Bundle Name的应用当前是否是空闲状态。
|
--
Gitee
From 2537b34fff0eb66ca4bb40ae74d657361b87545e Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Mon, 14 Mar 2022 22:50:36 +0800
Subject: [PATCH 56/87] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=88=A0=E9=99=A4=E6=95=B0=E6=8D=AE=E5=BA=93?=
=?UTF-8?q?=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=BA=93=E6=97=A0=E6=B3=95=E9=87=8D?=
=?UTF-8?q?=E6=96=B0=E5=88=9B=E5=BB=BA=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: wyuanchao
---
services/common/src/bundle_active_usage_database.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index aa11770..c8f9250 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -565,7 +565,6 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId,
}
shared_ptr rdbStore = GetBundleActiveRdbStore(APP_GROUP_DATABASE_INDEX);
if (rdbStore == nullptr) {
- BUNDLE_ACTIVE_LOGE("rdbStore is nullptr");
return;
}
CheckDatabaseFile(APP_GROUP_DATABASE_INDEX);
--
Gitee
From ab06ed30f203256a691f42188b3ab1ed19a719df Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 15 Mar 2022 09:45:11 +0800
Subject: [PATCH 57/87] =?UTF-8?q?=E6=B7=BB=E5=8A=A0debug=E6=A8=A1=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
BUILD.gn | 2 ++
.../common/include/bundle_active_constant.h | 11 ++++++-
services/common/include/bundle_active_core.h | 6 ++--
.../common/include/bundle_active_debug_mode.h | 26 ++++++++++++++++
.../include/bundle_active_usage_database.h | 2 ++
services/common/src/bundle_active_core.cpp | 28 ++++++++++-------
.../common/src/bundle_active_debug_mode.cpp | 30 +++++++++++++++++++
.../src/bundle_active_usage_database.cpp | 12 +++++++-
.../include/bundle_active_group_controller.h | 23 ++++----------
.../include/bundle_active_group_handler.h | 4 +--
.../include/bundle_active_user_history.h | 2 +-
.../src/bundle_active_group_controller.cpp | 19 ++++++++++--
.../src/bundle_active_group_handler.cpp | 9 ++++--
.../src/bundle_active_user_history.cpp | 3 +-
.../include/bundle_active_calendar.h | 15 +++++++---
.../include/bundle_active_user_service.h | 17 ++++++++---
.../src/bundle_active_calendar.cpp | 24 ++++++++++-----
.../src/bundle_active_user_service.cpp | 5 ++++
18 files changed, 182 insertions(+), 56 deletions(-)
create mode 100644 services/common/include/bundle_active_debug_mode.h
create mode 100644 services/common/src/bundle_active_debug_mode.cpp
diff --git a/BUILD.gn b/BUILD.gn
index 9505c91..6fb466c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -91,6 +91,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_debug_mode.cpp",
"services/common/src/bundle_active_log.cpp",
"services/common/src/bundle_active_open_callback.cpp",
"services/common/src/bundle_active_service.cpp",
@@ -138,6 +139,7 @@ ohos_shared_library("usagestatservice") {
"power_manager_native:powermgr_client",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
+ "startup_l2:syspara",
"time_native:time_service",
"utils_base:utils",
]
diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h
index 721da94..fcbce73 100644
--- a/services/common/include/bundle_active_constant.h
+++ b/services/common/include/bundle_active_constant.h
@@ -59,8 +59,17 @@ const int BOOT_BASED_DURATION_COLUMN_INDEX = 0;
const int SCREEN_ON_DURATION_COLUMN_INDEX = 1;
const int DURATION_FLAG_COLUMN_INDEX = 2;
const int TWO_SECONDS = 2 * 1000;
-const int64_t SIX_DAY_IN_MILLIS_MAX = 6 * 24 * 60 * 60 * 1000;
const int64_t THIRTY_MINUTE = 30 * 60 * 1000;
+const int64_t SIX_DAY_IN_MILLIS_MAX_DEBUG = (int64_t)6 * 1 * 10 * 60 * 1000;
+const int64_t SIX_DAY_IN_MILLIS_MAX = (int64_t)6 * 24 * 60 * 60 * 1000;
+const int64_t ONE_DAY_TIME_DEBUG = (int64_t)1 * 10 * 60 * 1000;
+const int64_t ONE_DAY_TIME = (int64_t)1 * 24 * 60 * 60 * 1000;
+const int64_t ONE_WEEK_TIME_DEBUG = (int64_t)1 * 20 * 60 * 1000;
+const int64_t ONE_WEEK_TIME = (int64_t)7 * 24 * 60 * 60 * 1000;
+const int64_t ONE_MONTH_TIME_DEBUG= (int64_t)1 * 30 * 60 * 1000;
+const int64_t ONE_MONTH_TIME = (int64_t)30 * 24 * 60 * 60 * 1000;
+const int64_t ONE_YEAR_TIME_DEBUG= (int64_t)1 * 40 * 60 * 1000;
+const int64_t ONE_YEAR_TIME = (int64_t)365 * 24 * 60 * 60 * 1000;
const int64_t LAST_TIME_IN_MILLIS_MIN = 0;
const int64_t EVENT_TIME_IN_MILLIS_MIN = 0;
const int64_t EVENT_BEGIN_TIME_INITIAL_VALUE = -1;
diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h
index bd1601e..c5949d2 100644
--- a/services/common/include/bundle_active_core.h
+++ b/services/common/include/bundle_active_core.h
@@ -22,6 +22,7 @@
#include "os_account_manager.h"
#include "ibundle_active_service.h"
+#include "bundle_active_debug_mode.h"
#include "bundle_active_stats_update_listener.h"
#include "bundle_active_user_service.h"
#include "bundle_active_group_controller.h"
@@ -114,7 +115,7 @@ public:
void ConvertToSystemTimeLocked(BundleActiveEvent& event);
// get or create BundleActiveUserService object for specifice user.
std::shared_ptr GetUserDataAndInitializeIfNeeded(const int userId,
- const int64_t timeStamp);
+ const int64_t timeStamp, const bool debug);
// when received a USER_REMOVED commen event, call it to remove data.
void OnUserRemoved(const int userId);
void OnUserSwitched(const int userId);
@@ -128,7 +129,7 @@ public:
int currentUsedUser_;
private:
- static const int64_t FLUSH_INTERVAL = THIRTY_MINUTE;
+ int64_t flushInterval_;
static const int64_t TIME_CHANGE_THRESHOLD_MILLIS = TWO_SECONDS;
const int DEFAULT_USER_ID = -1;
std::map visibleActivities_;
@@ -143,6 +144,7 @@ private:
void RegisterSubscriber();
std::shared_ptr commonEventSubscriber_;
void RestoreAllData();
+ bool debugCore_;
};
}
}
diff --git a/services/common/include/bundle_active_debug_mode.h b/services/common/include/bundle_active_debug_mode.h
new file mode 100644
index 0000000..3692b0e
--- /dev/null
+++ b/services/common/include/bundle_active_debug_mode.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BUNDLE_ACTIVE_DEBUG_MODE_H
+#define BUNDLE_ACTIVE_DEBUG_MODE_H
+
+#include
+
+namespace OHOS {
+namespace DeviceUsageStats {
+extern const bool DEBUG_ON;
+}
+}
+#endif
\ No newline at end of file
diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h
index f52a995..3b43610 100644
--- a/services/common/include/bundle_active_usage_database.h
+++ b/services/common/include/bundle_active_usage_database.h
@@ -56,6 +56,7 @@ public:
std::shared_ptr>>
GetBundleHistoryData(int userId);
void OnPackageUninstalled(const int userId, const std::string& bundleName);
+ void ChangeToDebug();
private:
void CheckDatabaseVersion();
@@ -96,6 +97,7 @@ private:
uint32_t currentVersion_;
std::mutex databaseMutex_;
std::int64_t eventBeginTime_;
+ bool debugDatabase_;
};
}
}
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 655043c..28f0434 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -53,6 +53,11 @@ BundleActiveCore::BundleActiveCore()
systemTimeShot_ = -1;
realTimeShot_ = -1;
currentUsedUser_ = -1;
+ if (DEBUG_ON) {
+ flushInterval_ = TWO_MINUTE;
+ } else {
+ flushInterval_ = THIRTY_MINUTE;
+ }
}
BundleActiveCore::~BundleActiveCore()
@@ -141,7 +146,7 @@ void BundleActiveCore::Init()
} while (realTimeShot_ == -1 && systemTimeShot_ == -1);
realTimeShot_ = timer->GetBootTimeMs();
systemTimeShot_ = GetSystemTimeMs();
- bundleGroupController_ = std::make_shared();
+ bundleGroupController_ = std::make_shared(debugCore_);
BUNDLE_ACTIVE_LOGI("system time shot is %{public}lld", systemTimeShot_);
}
@@ -154,7 +159,7 @@ void BundleActiveCore::InitBundleGroupController()
BUNDLE_ACTIVE_LOGE("report handler is null");
return;
}
- bundleGroupHandler_ = std::make_shared(runner);
+ bundleGroupHandler_ = std::make_shared(runner, debugCore_);
if (bundleGroupHandler_ == nullptr) {
return;
}
@@ -182,13 +187,13 @@ void BundleActiveCore::SetHandler(const std::shared_ptr BundleActiveCore::GetUserDataAndInitializeIfNeeded(const int userId,
- const int64_t timeStamp)
+ const int64_t timeStamp, const bool debug)
{
BUNDLE_ACTIVE_LOGI("GetUserDataAndInitializeIfNeeded called");
std::map>::iterator it = userStatServices_.find(userId);
if (it == userStatServices_.end()) {
BUNDLE_ACTIVE_LOGI("first initialize user service");
- std::shared_ptr service = std::make_shared(userId, *this);
+ std::shared_ptr service = std::make_shared(userId, *this, debug);
service->Init(timeStamp);
userStatServices_[userId] = service;
if (service == nullptr) {
@@ -208,7 +213,7 @@ void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string&
if (timeNow == -1) {
return;
}
- auto service = GetUserDataAndInitializeIfNeeded(userId, timeNow);
+ auto service = GetUserDataAndInitializeIfNeeded(userId, timeNow, debugCore_);
if (service == nullptr) {
return;
}
@@ -226,7 +231,7 @@ void BundleActiveCore::OnStatsChanged(const int userId)
auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr);
if (handler_.lock()->HasInnerEvent(static_cast(userId)) == false) {
BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event for user %{public}d", userId);
- handler_.lock()->SendEvent(event, FLUSH_INTERVAL);
+ handler_.lock()->SendEvent(event, flushInterval_);
}
}
}
@@ -405,6 +410,7 @@ void BundleActiveCore::OnUserSwitched(const int userId)
int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId)
{
+ BUNDLE_ACTIVE_LOGI("FLUSH interval is %{public}lld, debug is %{public}d", flushInterval_, debugCore_);
std::lock_guard lock(mutex_);
if (userId == 0 || userId == -1) {
return -1;
@@ -429,7 +435,7 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId)
return -1;
}
ConvertToSystemTimeLocked(event);
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow, debugCore_);
if (service == nullptr) {
BUNDLE_ACTIVE_LOGE("get user data service failed!");
return -1;
@@ -447,12 +453,12 @@ int BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event)
return -1;
}
if (userStatServices_.empty()) {
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(DEFAULT_USER_ID, timeNow);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(DEFAULT_USER_ID, timeNow, debugCore_);
}
for (std::map>::iterator it = userStatServices_.begin();
it != userStatServices_.end(); it++) {
ConvertToSystemTimeLocked(event);
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it->first, timeNow);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it->first, timeNow, debugCore_);
if (service == nullptr) {
BUNDLE_ACTIVE_LOGE("get user data service failed!");
return -1;
@@ -481,7 +487,7 @@ std::vector BundleActiveCore::QueryPackageStats(const
BUNDLE_ACTIVE_LOGI("QueryPackageStats time span illegal");
return result;
}
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow, debugCore_);
if (service == nullptr) {
BUNDLE_ACTIVE_LOGI("QueryPackageStats service is null, failed");
return result;
@@ -503,7 +509,7 @@ std::vector BundleActiveCore::QueryEvents(const int userId, c
if (beginTime > timeNow || beginTime >= endTime) {
return result;
}
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow, debugCore_);
if (service == nullptr) {
return result;
}
diff --git a/services/common/src/bundle_active_debug_mode.cpp b/services/common/src/bundle_active_debug_mode.cpp
new file mode 100644
index 0000000..19f1fe1
--- /dev/null
+++ b/services/common/src/bundle_active_debug_mode.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+
+#include "bundle_active_debug_mode.h"
+
+using OHOS::system::GetIntParameter;
+using OHOS::system::GetParameter;
+
+namespace OHOS {
+namespace DeviceUsageStats {
+constexpr int DEBUG_ON_DEFAULT = false;
+std::string DEBUG_MODE = "persist.sys.device_usage_debug_on";
+const bool DEBUG_ON = static_cast(GetIntParameter(DEBUG_MODE, DEBUG_ON_DEFAULT));
+}
+}
\ No newline at end of file
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index 4433bcc..b3f712e 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -53,6 +53,7 @@ BundleActiveUsageDatabase::BundleActiveUsageDatabase()
sortedTableArray_ = vector>(SORTED_TABLE_ARRAY_NUMBER);
calendar_ = make_shared();
eventBeginTime_ = EVENT_BEGIN_TIME_INITIAL_VALUE;
+ debugDatabase_ = false;
}
BundleActiveUsageDatabase::~BundleActiveUsageDatabase()
@@ -60,6 +61,10 @@ BundleActiveUsageDatabase::~BundleActiveUsageDatabase()
RdbHelper::ClearCache();
}
+void BundleActiveUsageDatabase::ChangeToDebug() {
+ calendar_->ChangeToDebug();
+ debugDatabase_ = true;
+}
void BundleActiveUsageDatabase::InitUsageGroupInfo(int32_t databaseType)
{
lock_guard lock(databaseMutex_);
@@ -276,7 +281,12 @@ void BundleActiveUsageDatabase::DeleteExcessiveTableData(unsigned int databaseTy
return;
}
int64_t eventTableTime = ParseStartTime(eventTableName_);
- int64_t deleteTimePoint = eventBeginTime_ - SIX_DAY_IN_MILLIS_MAX - eventTableTime;
+ int64_t deleteTimePoint = 0;
+ if (debugDatabase_) {
+ deleteTimePoint = eventBeginTime_ - SIX_DAY_IN_MILLIS_MAX_DEBUG - eventTableTime;
+ } else {
+ deleteTimePoint = eventBeginTime_ - SIX_DAY_IN_MILLIS_MAX - eventTableTime;
+ }
if (deleteTimePoint <= 0) {
return;
}
diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h
index 63d3b05..9d0c271 100644
--- a/services/packagegroup/include/bundle_active_group_controller.h
+++ b/services/packagegroup/include/bundle_active_group_controller.h
@@ -43,26 +43,15 @@ public:
using ApplicationFlag = OHOS::AppExecFwk::ApplicationFlag;
OHOS::AppExecFwk::ApplicationFlag flag = OHOS::AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO;
bool bundleGroupEnable_ = true;
- bool debug_ = false;
const int LEVEL_GROUP[4] = {
ACTIVE_GROUP_ALIVE,
ACTIVE_GROUP_DAILY,
ACTIVE_GROUP_FIXED,
ACTIVE_GROUP_RARE
};
- const int64_t SCREEN_TIME_LEVEL[4] = {
- 0,
- 0,
- debug_ ? TWO_MINUTE : ONE_HOUR,
- debug_ ? FOUR_MINUTE : TWO_HOUR
- };
- const int64_t BOOT_TIME_LEVEL[4] = {
- 0,
- debug_ ? TWO_MINUTE : TWELVE_HOUR,
- debug_ ? FOUR_MINUTE : TWENTY_FOUR_HOUR,
- debug_ ? SIXTEEN_MINUTE : FOURTY_EIGHT_HOUR
- };
- BundleActiveGroupController() {};
+ std::vector screenTimeLevel_ = {0, 0, 0, 0};
+ std::vector bootTimeLevel_ = {0, 0, 0, 0};
+ BundleActiveGroupController(const bool debug);
~BundleActiveGroupController() {};
std::shared_ptr bundleUserHistory_;
void SetHandlerAndCreateUserHistory(const std::shared_ptr& groupHandler,
@@ -91,9 +80,9 @@ private:
bool GetBundleMgrProxy();
std::weak_ptr activeGroupHandler_;
uint32_t EventToGroupReason(const int eventId);
- int64_t timeoutForDirectlyUse_ = debug_ ? THREE_MINUTE : ONE_HOUR;
- int64_t timeoutForNotifySeen_ = debug_ ? ONE_MINUTE : TWELVE_HOUR;
- int64_t timeoutForSystemInteraction_ = debug_ ? ONE_MINUTE : TEN_MINUTE;
+ int64_t timeoutForDirectlyUse_;
+ int64_t timeoutForNotifySeen_;
+ int64_t timeoutForSystemInteraction_;
int64_t timeoutCalculated_ = 0;
sptr sptrBundleMgr_;
bool calculationTimeOut(const std::shared_ptr& oneBundleHistory,
diff --git a/services/packagegroup/include/bundle_active_group_handler.h b/services/packagegroup/include/bundle_active_group_handler.h
index 737a9db..06c801b 100644
--- a/services/packagegroup/include/bundle_active_group_handler.h
+++ b/services/packagegroup/include/bundle_active_group_handler.h
@@ -36,7 +36,7 @@ public:
class BundleActiveGroupHandler : public AppExecFwk::EventHandler {
public:
- explicit BundleActiveGroupHandler(const std::shared_ptr &runner);
+ explicit BundleActiveGroupHandler(const std::shared_ptr &runner, const bool debug);
~BundleActiveGroupHandler() = default;
/**
* Process the event. Developers should override this method.
@@ -48,7 +48,7 @@ public:
static const int MSG_CHECK_BUNDLE_STATE = 0;
static const int MSG_ONE_TIME_CHECK_BUNDLE_STATE = 1;
static const int MSG_CHECK_IDLE_STATE = 2;
- static const int CHECK_IDLE_INTERVAL = THREE_HOUR;
+ int64_t checkIdleInterval_;
private:
std::shared_ptr bundleActiveGroupController_;
diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h
index 5449c0f..c86a545 100644
--- a/services/packagegroup/include/bundle_active_user_history.h
+++ b/services/packagegroup/include/bundle_active_user_history.h
@@ -52,7 +52,7 @@ public:
void SetBundleGroup(const std::string& bundleName, const int userId, const int64_t bootBasedTimeStamp,
int newGroup, uint32_t groupReason, const bool& resetTimeout);
int GetLevelIndex(const std::string& bundleName, const int userId, const int64_t bootBasedTimeStamp,
- const int64_t screenTimeLevel[4], const int64_t bootFromTimeLevel[4]);
+ const std::vector screenTimeLeve, const std::vector bootFromTimeLevel);
void WriteDeviceDuration();
void WriteBundleUsage(const int userId);
void printdata(int userId);
diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp
index 0f5ae55..c6500b5 100644
--- a/services/packagegroup/src/bundle_active_group_controller.cpp
+++ b/services/packagegroup/src/bundle_active_group_controller.cpp
@@ -29,6 +29,17 @@ BundleActiveGroupHandlerObject::BundleActiveGroupHandlerObject()
userId_ = -1;
}
+
+BundleActiveGroupController::BundleActiveGroupController(const bool debug)
+{
+ timeoutForDirectlyUse_ = debug ? THREE_MINUTE : ONE_HOUR;
+ timeoutForNotifySeen_ = debug ? ONE_MINUTE : TWELVE_HOUR;
+ timeoutForSystemInteraction_ = debug ? ONE_MINUTE : TEN_MINUTE;
+ screenTimeLevel_ = {0, 0, debug ? TWO_MINUTE : ONE_HOUR, debug ? FOUR_MINUTE : TWO_HOUR};
+ bootTimeLevel_ = {0, debug ? TWO_MINUTE : TWELVE_HOUR, debug ? FOUR_MINUTE : TWENTY_FOUR_HOUR,
+ debug ? SIXTEEN_MINUTE : FOURTY_EIGHT_HOUR};
+}
+
void BundleActiveGroupController::RestoreDurationToDatabase()
{
std::lock_guard lock(mutex_);
@@ -161,8 +172,8 @@ void BundleActiveGroupController::CheckIdleStatsOneTime()
int BundleActiveGroupController::GetNewGroup(const std::string& bundleName, const int userId,
const int64_t bootBasedTimeStamp)
{
- int groupIndex = bundleUserHistory_->GetLevelIndex(bundleName, userId, bootBasedTimeStamp, SCREEN_TIME_LEVEL,
- BOOT_TIME_LEVEL);
+ int groupIndex = bundleUserHistory_->GetLevelIndex(bundleName, userId, bootBasedTimeStamp, screenTimeLevel_,
+ bootTimeLevel_);
if (groupIndex < 0) {
return -1;
}
@@ -211,6 +222,10 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co
if (IsBundleInstalled(event.bundleName_, userId) == false) {
return;
}
+ BUNDLE_ACTIVE_LOGI("screen %{public}lld, %{public}lld, %{public}lld, %{public}lld",
+ screenTimeLevel_[0], screenTimeLevel_[1], screenTimeLevel_[2], screenTimeLevel_[3]);
+ BUNDLE_ACTIVE_LOGI("boot %{public}lld, %{public}lld, %{public}lld, %{public}lld",
+ bootTimeLevel_[0], bootTimeLevel_[1], bootTimeLevel_[2], bootTimeLevel_[3]);
int eventId = event.eventId_;
if (eventId == BundleActiveEvent::ABILITY_FOREGROUND ||
eventId == BundleActiveEvent::ABILITY_BACKGROUND ||
diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp
index 2b44748..53bef3c 100644
--- a/services/packagegroup/src/bundle_active_group_handler.cpp
+++ b/services/packagegroup/src/bundle_active_group_handler.cpp
@@ -27,8 +27,13 @@ BundleActiveGroupHandlerObject::BundleActiveGroupHandlerObject(const BundleActiv
}
BundleActiveGroupHandler::BundleActiveGroupHandler
- (const std::shared_ptr &runner) : AppExecFwk::EventHandler(runner)
+ (const std::shared_ptr &runner, const bool debug) : AppExecFwk::EventHandler(runner)
{
+ if (debug) {
+ checkIdleInterval_ = TWO_MINUTE;
+ } else {
+ checkIdleInterval_ = THREE_HOUR;
+ }
}
void BundleActiveGroupHandler::Init(const std::shared_ptr& bundleActiveController)
@@ -82,7 +87,7 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe
auto handlerEvent = AppExecFwk::InnerEvent::Get(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE,
handlerobjToPtr);
bundleActiveGroupController_->RestoreToDatabase(GroupHandlerObj.userId_);
- SendEvent(handlerEvent, CHECK_IDLE_INTERVAL);
+ SendEvent(handlerEvent, checkIdleInterval_);
}
break;
}
diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp
index 3d0f0f9..6479e6d 100644
--- a/services/packagegroup/src/bundle_active_user_history.cpp
+++ b/services/packagegroup/src/bundle_active_user_history.cpp
@@ -63,7 +63,8 @@ BundleActiveUserHistory::BundleActiveUserHistory(const int64_t bootBasedTimeStam
}
int BundleActiveUserHistory::GetLevelIndex(const string& bundleName, const int userId,
- const int64_t bootBasedTimeStamp, const int64_t screenTimeLevel[4], const int64_t bootFromTimeLevel[4])
+ const int64_t bootBasedTimeStamp, const std::vector screenTimeLevel,
+ const std::vector bootFromTimeLevel)
{
auto oneUserHistory = GetUserHistory(userId, false);
if (oneUserHistory == nullptr) {
diff --git a/services/packageusage/include/bundle_active_calendar.h b/services/packageusage/include/bundle_active_calendar.h
index 745d56e..b8c166c 100644
--- a/services/packageusage/include/bundle_active_calendar.h
+++ b/services/packageusage/include/bundle_active_calendar.h
@@ -18,20 +18,27 @@
#include
+#include "bundle_active_constant.h"
+
namespace OHOS {
namespace DeviceUsageStats {
class BundleActiveCalendar {
public:
static const int64_t ONE_SECOND_MILLISECONDS = 1000;
- static const int64_t DAY_MILLISECONDS = (int64_t)1 * 24 * 60 * 60 * 1000;
- static const int64_t WEEK_MILLISECONDS = (int64_t)7 * 24 * 60 * 60 * 1000;
- static const int64_t MONTH_MILLISECONDS = (int64_t)30 * 24 * 60 * 60 * 1000;
- static const int64_t YEAR_MILLISECONDS = (int64_t)365 * 24 * 60 * 60 * 1000;
+ int64_t dayMilliseconds_;
+ int64_t weekMilliseconds_;
+ int64_t monthMilliseconds_;
+ int64_t yearMilliseconds_;
BundleActiveCalendar(const int64_t timeStamp);
BundleActiveCalendar()
{
time_ = 0;
+ dayMilliseconds_ = ONE_DAY_TIME;
+ weekMilliseconds_ = ONE_WEEK_TIME;
+ monthMilliseconds_ = ONE_MONTH_TIME;
+ yearMilliseconds_ = ONE_YEAR_TIME;
}
+ void ChangeToDebug();
void TruncateToDay();
void TruncateToWeek();
void TruncateToMonth();
diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h
index 2bce5f3..420b6e1 100644
--- a/services/packageusage/include/bundle_active_user_service.h
+++ b/services/packageusage/include/bundle_active_user_service.h
@@ -25,6 +25,7 @@
#include "bundle_active_calendar.h"
#include "bundle_active_stats_combiner.h"
#include "bundle_active_usage_database.h"
+#include "bundle_active_constant.h"
namespace OHOS {
namespace DeviceUsageStats {
@@ -33,7 +34,7 @@ class BundleActiveCore;
class BundleActiveUserService {
public:
BundleActiveUserService() = delete;
- BundleActiveUserService(const int userId, BundleActiveCore& listener):listener_(listener)
+ BundleActiveUserService(const int userId, BundleActiveCore& listener, const bool debug):listener_(listener)
{
for (int i = 0; i < BundleActivePeriodStats::PERIOD_COUNT; i++) {
currentStats_.push_back(nullptr);
@@ -41,6 +42,15 @@ public:
userId_ = userId;
dailyExpiryDate_.SetMilliseconds(0);
statsChanged_ = false;
+ if (debug) {
+ dailyExpiryDate_.ChangeToDebug();
+ database_.ChangeToDebug();
+ debugUserService_ = true;
+ PERIOD_LENGTH = {ONE_DAY_TIME_DEBUG, ONE_WEEK_TIME_DEBUG, ONE_MONTH_TIME_DEBUG, ONE_YEAR_TIME_DEBUG};
+ } else {
+ debugUserService_ = false;
+ PERIOD_LENGTH = {ONE_DAY_TIME, ONE_WEEK_TIME, ONE_MONTH_TIME, ONE_YEAR_TIME};
+ }
}
void Init(const int64_t timeStamp);
~BundleActiveUserService() {};
@@ -64,11 +74,10 @@ private:
BundleActiveUsageDatabase database_;
std::vector> currentStats_;
bool statsChanged_;
+ bool debugUserService_;
std::string lastBackgroundBundle_;
BundleActiveCore& listener_;
- inline static const std::vector PERIOD_LENGTH = {BundleActiveCalendar::DAY_MILLISECONDS,
- BundleActiveCalendar::WEEK_MILLISECONDS, BundleActiveCalendar::MONTH_MILLISECONDS,
- BundleActiveCalendar::YEAR_MILLISECONDS};
+ std::vector PERIOD_LENGTH = {0, 0, 0, 0};
void NotifyStatsChanged();
void NotifyNewUpdate();
void PrintInMemPackageStats(const int idx);
diff --git a/services/packageusage/src/bundle_active_calendar.cpp b/services/packageusage/src/bundle_active_calendar.cpp
index 1806fac..fa79eff 100644
--- a/services/packageusage/src/bundle_active_calendar.cpp
+++ b/services/packageusage/src/bundle_active_calendar.cpp
@@ -25,42 +25,42 @@ BundleActiveCalendar::BundleActiveCalendar(const int64_t timeStamp)
void BundleActiveCalendar::TruncateToDay()
{
- time_ -= time_ % DAY_MILLISECONDS;
+ time_ -= time_ % dayMilliseconds_;
}
void BundleActiveCalendar::TruncateToWeek()
{
- time_ -= time_ % WEEK_MILLISECONDS;
+ time_ -= time_ % weekMilliseconds_;
}
void BundleActiveCalendar::TruncateToMonth()
{
- time_ -= time_ % MONTH_MILLISECONDS;
+ time_ -= time_ % monthMilliseconds_;
}
void BundleActiveCalendar::TruncateToYear()
{
- time_ -= time_ % YEAR_MILLISECONDS;
+ time_ -= time_ % yearMilliseconds_;
}
void BundleActiveCalendar::IncreaseDays(const int val)
{
- time_ += val * DAY_MILLISECONDS;
+ time_ += val * dayMilliseconds_;
}
void BundleActiveCalendar::IncreaseWeeks(const int val)
{
- time_ += val* WEEK_MILLISECONDS;
+ time_ += val* weekMilliseconds_;
}
void BundleActiveCalendar::IncreaseMonths(const int val)
{
- time_ += val * MONTH_MILLISECONDS;
+ time_ += val * monthMilliseconds_;
}
void BundleActiveCalendar::IncreaseYears(const int val)
{
- time_ += val * YEAR_MILLISECONDS;
+ time_ += val * yearMilliseconds_;
}
void BundleActiveCalendar::SetMilliseconds(const int64_t timeStamp)
@@ -73,6 +73,14 @@ int64_t BundleActiveCalendar::GetMilliseconds()
return time_;
}
+void BundleActiveCalendar::ChangeToDebug()
+{
+ dayMilliseconds_ = ONE_DAY_TIME_DEBUG;
+ weekMilliseconds_ = ONE_WEEK_TIME_DEBUG;
+ monthMilliseconds_ = ONE_MONTH_TIME_DEBUG;
+ yearMilliseconds_ = ONE_YEAR_TIME_DEBUG;
+}
+
void BundleActiveCalendar::TruncateTo(int intervalType)
{
switch (intervalType) {
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index 931d54f..721b5b9 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -86,6 +86,8 @@ void BundleActiveUserService::NotifyNewUpdate()
void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event)
{
+ BUNDLE_ACTIVE_LOGI("PERIOD %{public}lld, %{public}lld, %{public}lld, %{public}lld",
+ PERIOD_LENGTH[0], PERIOD_LENGTH[1], PERIOD_LENGTH[2], PERIOD_LENGTH[3]);
BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d,"
"event is %{public}d",
currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_, event.eventId_);
@@ -182,6 +184,9 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo
{
BUNDLE_ACTIVE_LOGI("LoadActiveStats called");
BundleActiveCalendar tmpCalendar(0);
+ if (debugUserService_ == true) {
+ tmpCalendar.ChangeToDebug();
+ }
tmpCalendar.SetMilliseconds(timeStamp);
tmpCalendar.TruncateTo(BundleActivePeriodStats::PERIOD_DAILY);
for (uint32_t intervalType = 0; intervalType < PERIOD_LENGTH.size(); intervalType++) {
--
Gitee
From 0d992c4467a8c20d76b1aebe8ef11bb8ae4c12a6 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 15 Mar 2022 09:49:23 +0800
Subject: [PATCH 58/87] =?UTF-8?q?=E6=B7=BB=E5=8A=A0debug=E6=A8=A1=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
.../packageusage/include/bundle_active_user_service.h | 6 +++---
.../packageusage/src/bundle_active_user_service.cpp | 10 +++++-----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h
index 420b6e1..8bf0fed 100644
--- a/services/packageusage/include/bundle_active_user_service.h
+++ b/services/packageusage/include/bundle_active_user_service.h
@@ -46,10 +46,10 @@ public:
dailyExpiryDate_.ChangeToDebug();
database_.ChangeToDebug();
debugUserService_ = true;
- PERIOD_LENGTH = {ONE_DAY_TIME_DEBUG, ONE_WEEK_TIME_DEBUG, ONE_MONTH_TIME_DEBUG, ONE_YEAR_TIME_DEBUG};
+ periodLength_ = {ONE_DAY_TIME_DEBUG, ONE_WEEK_TIME_DEBUG, ONE_MONTH_TIME_DEBUG, ONE_YEAR_TIME_DEBUG};
} else {
debugUserService_ = false;
- PERIOD_LENGTH = {ONE_DAY_TIME, ONE_WEEK_TIME, ONE_MONTH_TIME, ONE_YEAR_TIME};
+ periodLength_ = {ONE_DAY_TIME, ONE_WEEK_TIME, ONE_MONTH_TIME, ONE_YEAR_TIME};
}
}
void Init(const int64_t timeStamp);
@@ -77,7 +77,7 @@ private:
bool debugUserService_;
std::string lastBackgroundBundle_;
BundleActiveCore& listener_;
- std::vector PERIOD_LENGTH = {0, 0, 0, 0};
+ std::vector periodLength_ = {0, 0, 0, 0};
void NotifyStatsChanged();
void NotifyNewUpdate();
void PrintInMemPackageStats(const int idx);
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index 721b5b9..156eac8 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -87,7 +87,7 @@ void BundleActiveUserService::NotifyNewUpdate()
void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event)
{
BUNDLE_ACTIVE_LOGI("PERIOD %{public}lld, %{public}lld, %{public}lld, %{public}lld",
- PERIOD_LENGTH[0], PERIOD_LENGTH[1], PERIOD_LENGTH[2], PERIOD_LENGTH[3]);
+ periodLength_[0], periodLength_[1], periodLength_[2], periodLength_[3]);
BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d,"
"event is %{public}d",
currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_, event.eventId_);
@@ -189,7 +189,7 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo
}
tmpCalendar.SetMilliseconds(timeStamp);
tmpCalendar.TruncateTo(BundleActivePeriodStats::PERIOD_DAILY);
- for (uint32_t intervalType = 0; intervalType < PERIOD_LENGTH.size(); intervalType++) {
+ for (uint32_t intervalType = 0; intervalType < periodLength_.size(); intervalType++) {
if (!force && currentStats_[intervalType] != nullptr &&
currentStats_[intervalType]->beginTime_ == tmpCalendar.GetMilliseconds()) {
continue;
@@ -202,8 +202,8 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo
// 如果当前时间在stats的统计时间范围内,则可以从数据库加载数据
BUNDLE_ACTIVE_LOGI("interval type is %{public}d, database stat BEGIN time is %{public}lld, "
"timestamp is %{public}lld, expect end is %{public}lld",
- intervalType, stats->beginTime_, timeStamp, stats->beginTime_ + PERIOD_LENGTH[intervalType]);
- if (timeStamp > stats->beginTime_ && timeStamp < stats->beginTime_ + PERIOD_LENGTH[intervalType]) {
+ intervalType, stats->beginTime_, timeStamp, stats->beginTime_ + periodLength_[intervalType]);
+ if (timeStamp > stats->beginTime_ && timeStamp < stats->beginTime_ + periodLength_[intervalType]) {
currentStats_[intervalType] = stats;
}
}
@@ -306,7 +306,7 @@ std::vector BundleActiveUserService::QueryPackageStats
return result;
}
if (currentStats->endTime_ == 0) {
- if (beginTime > currentStats->beginTime_ + PERIOD_LENGTH[intervalType]) {
+ if (beginTime > currentStats->beginTime_ + periodLength_[intervalType]) {
return result;
} else {
result = database_.QueryDatabaseUsageStats(intervalType, beginTime, endTime, userId);
--
Gitee
From 6007b7c6ab19e4e995a5008abbdff2869338b8d5 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 15 Mar 2022 11:23:07 +0800
Subject: [PATCH 59/87] =?UTF-8?q?codex=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
LICENSE | 1 +
services/common/include/bundle_active_constant.h | 2 +-
services/common/include/bundle_active_debug_mode.h | 2 --
services/common/src/bundle_active_core.cpp | 9 ++++++---
services/common/src/bundle_active_usage_database.cpp | 3 ++-
.../packagegroup/src/bundle_active_group_controller.cpp | 4 ----
services/packageusage/src/bundle_active_user_service.cpp | 2 --
7 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/LICENSE b/LICENSE
index 66a27ec..e454a52 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,3 +1,4 @@
+
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h
index fcbce73..fd5c3ba 100644
--- a/services/common/include/bundle_active_constant.h
+++ b/services/common/include/bundle_active_constant.h
@@ -68,7 +68,7 @@ const int64_t ONE_WEEK_TIME_DEBUG = (int64_t)1 * 20 * 60 * 1000;
const int64_t ONE_WEEK_TIME = (int64_t)7 * 24 * 60 * 60 * 1000;
const int64_t ONE_MONTH_TIME_DEBUG= (int64_t)1 * 30 * 60 * 1000;
const int64_t ONE_MONTH_TIME = (int64_t)30 * 24 * 60 * 60 * 1000;
-const int64_t ONE_YEAR_TIME_DEBUG= (int64_t)1 * 40 * 60 * 1000;
+const int64_t ONE_YEAR_TIME_DEBUG = (int64_t)1 * 40 * 60 * 1000;
const int64_t ONE_YEAR_TIME = (int64_t)365 * 24 * 60 * 60 * 1000;
const int64_t LAST_TIME_IN_MILLIS_MIN = 0;
const int64_t EVENT_TIME_IN_MILLIS_MIN = 0;
diff --git a/services/common/include/bundle_active_debug_mode.h b/services/common/include/bundle_active_debug_mode.h
index 3692b0e..94786dd 100644
--- a/services/common/include/bundle_active_debug_mode.h
+++ b/services/common/include/bundle_active_debug_mode.h
@@ -16,8 +16,6 @@
#ifndef BUNDLE_ACTIVE_DEBUG_MODE_H
#define BUNDLE_ACTIVE_DEBUG_MODE_H
-#include
-
namespace OHOS {
namespace DeviceUsageStats {
extern const bool DEBUG_ON;
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 28f0434..c5467ed 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -193,7 +193,8 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial
std::map>::iterator it = userStatServices_.find(userId);
if (it == userStatServices_.end()) {
BUNDLE_ACTIVE_LOGI("first initialize user service");
- std::shared_ptr service = std::make_shared(userId, *this, debug);
+ std::shared_ptr service = std::make_shared(userId, *this,
+ debug);
service->Init(timeStamp);
userStatServices_[userId] = service;
if (service == nullptr) {
@@ -453,12 +454,14 @@ int BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event)
return -1;
}
if (userStatServices_.empty()) {
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(DEFAULT_USER_ID, timeNow, debugCore_);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(DEFAULT_USER_ID, timeNow,
+ debugCore_);
}
for (std::map>::iterator it = userStatServices_.begin();
it != userStatServices_.end(); it++) {
ConvertToSystemTimeLocked(event);
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it->first, timeNow, debugCore_);
+ std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it->first, timeNow,
+ debugCore_);
if (service == nullptr) {
BUNDLE_ACTIVE_LOGE("get user data service failed!");
return -1;
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index b3f712e..c6589c1 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -61,7 +61,8 @@ BundleActiveUsageDatabase::~BundleActiveUsageDatabase()
RdbHelper::ClearCache();
}
-void BundleActiveUsageDatabase::ChangeToDebug() {
+void BundleActiveUsageDatabase::ChangeToDebug()
+{
calendar_->ChangeToDebug();
debugDatabase_ = true;
}
diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp
index c6500b5..a837554 100644
--- a/services/packagegroup/src/bundle_active_group_controller.cpp
+++ b/services/packagegroup/src/bundle_active_group_controller.cpp
@@ -222,10 +222,6 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co
if (IsBundleInstalled(event.bundleName_, userId) == false) {
return;
}
- BUNDLE_ACTIVE_LOGI("screen %{public}lld, %{public}lld, %{public}lld, %{public}lld",
- screenTimeLevel_[0], screenTimeLevel_[1], screenTimeLevel_[2], screenTimeLevel_[3]);
- BUNDLE_ACTIVE_LOGI("boot %{public}lld, %{public}lld, %{public}lld, %{public}lld",
- bootTimeLevel_[0], bootTimeLevel_[1], bootTimeLevel_[2], bootTimeLevel_[3]);
int eventId = event.eventId_;
if (eventId == BundleActiveEvent::ABILITY_FOREGROUND ||
eventId == BundleActiveEvent::ABILITY_BACKGROUND ||
diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp
index 156eac8..fa0cad7 100644
--- a/services/packageusage/src/bundle_active_user_service.cpp
+++ b/services/packageusage/src/bundle_active_user_service.cpp
@@ -86,8 +86,6 @@ void BundleActiveUserService::NotifyNewUpdate()
void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event)
{
- BUNDLE_ACTIVE_LOGI("PERIOD %{public}lld, %{public}lld, %{public}lld, %{public}lld",
- periodLength_[0], periodLength_[1], periodLength_[2], periodLength_[3]);
BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d,"
"event is %{public}d",
currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_, event.eventId_);
--
Gitee
From edb10bfa26f1c9d2ef89a85b0427223e197e5e7f Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 15 Mar 2022 12:01:25 +0800
Subject: [PATCH 60/87] =?UTF-8?q?codex=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/include/bundle_active_constant.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h
index fd5c3ba..3f6d447 100644
--- a/services/common/include/bundle_active_constant.h
+++ b/services/common/include/bundle_active_constant.h
@@ -66,7 +66,7 @@ const int64_t ONE_DAY_TIME_DEBUG = (int64_t)1 * 10 * 60 * 1000;
const int64_t ONE_DAY_TIME = (int64_t)1 * 24 * 60 * 60 * 1000;
const int64_t ONE_WEEK_TIME_DEBUG = (int64_t)1 * 20 * 60 * 1000;
const int64_t ONE_WEEK_TIME = (int64_t)7 * 24 * 60 * 60 * 1000;
-const int64_t ONE_MONTH_TIME_DEBUG= (int64_t)1 * 30 * 60 * 1000;
+const int64_t ONE_MONTH_TIME_DEBUG = (int64_t)1 * 30 * 60 * 1000;
const int64_t ONE_MONTH_TIME = (int64_t)30 * 24 * 60 * 60 * 1000;
const int64_t ONE_YEAR_TIME_DEBUG = (int64_t)1 * 40 * 60 * 1000;
const int64_t ONE_YEAR_TIME = (int64_t)365 * 24 * 60 * 60 * 1000;
--
Gitee
From 77b3ec8d6887b4c8c2843ce79738a19c2a8a2574 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 15 Mar 2022 17:40:51 +0800
Subject: [PATCH 61/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9debugCore=E6=9C=AA?=
=?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 2 ++
services/packagegroup/src/bundle_active_group_handler.cpp | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index c5467ed..49800e0 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -55,8 +55,10 @@ BundleActiveCore::BundleActiveCore()
currentUsedUser_ = -1;
if (DEBUG_ON) {
flushInterval_ = TWO_MINUTE;
+ debugCore_ = true;
} else {
flushInterval_ = THIRTY_MINUTE;
+ debugCore_ = false;
}
}
diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp
index 53bef3c..5654ef1 100644
--- a/services/packagegroup/src/bundle_active_group_handler.cpp
+++ b/services/packagegroup/src/bundle_active_group_handler.cpp
@@ -30,7 +30,7 @@ BundleActiveGroupHandler::BundleActiveGroupHandler
(const std::shared_ptr &runner, const bool debug) : AppExecFwk::EventHandler(runner)
{
if (debug) {
- checkIdleInterval_ = TWO_MINUTE;
+ checkIdleInterval_ = ONE_MINUTE;
} else {
checkIdleInterval_ = THREE_HOUR;
}
--
Gitee
From 0cd7566ca492f534ce0f21d7e064cf562bfe67de Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Tue, 15 Mar 2022 23:00:10 +0800
Subject: [PATCH 62/87] =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?=
=?UTF-8?q?=E6=95=B4=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
frameworks/src/bundle_state_query.cpp | 10 ++--------
.../src/bundle_active_continuous_task_observer.cpp | 1 -
services/common/src/bundle_active_core.cpp | 13 ++++++++-----
services/common/src/bundle_active_service.cpp | 3 +--
.../common/src/bundle_active_usage_database.cpp | 4 +---
test/unittest/device_usage_statistics_test.cpp | 2 +-
6 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index b9218b9..a934198 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -96,7 +96,6 @@ napi_value IsIdleState(napi_env env, napi_callback_info info)
asyncCallbackInfo->state = BundleActiveClient::GetInstance().IsBundleIdle(
asyncCallbackInfo->bundleName);
} else {
- asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("IsIdleState, asyncCallbackInfo == nullptr");
}
},
@@ -168,7 +167,6 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info)
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->priorityGroup = BundleActiveClient::GetInstance().QueryPackageGroup();
} else {
- asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryAppUsagePriorityGroup, asyncCallbackInfo == nullptr");
}
},
@@ -203,7 +201,7 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info &
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
NAPI_ASSERT(env, argc == STATES_MIN_PARAMS || argc == STATES_PARAMS,
"Invalid number of parameters");
-
+
// argv[0] : beginTime
if (BundleStateCommon::GetInt64NumberValue(env, argv[0], params.beginTime) == nullptr) {
BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, beginTime type is invalid.");
@@ -278,7 +276,6 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info)
BundleActiveClient::GetInstance().QueryCurrentEvents(asyncCallbackInfo->beginTime,
asyncCallbackInfo->endTime);
} else {
- asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryCurrentBundleActiveStates, asyncCallbackInfo == nullptr");
}
},
@@ -345,7 +342,6 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info)
BundleActiveClient::GetInstance().QueryEvents(asyncCallbackInfo->beginTime,
asyncCallbackInfo->endTime);
} else {
- asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryBundleActiveStates, asyncCallbackInfo == nullptr");
}
},
@@ -470,7 +466,6 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info)
BundleActiveClient::GetInstance().QueryPackageStats(asyncCallbackInfo->intervalType,
asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
} else {
- asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryBundleStateInfoByInterval, asyncCallbackInfo == nullptr");
}
},
@@ -508,7 +503,7 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info
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,
"Invalid number of parameters");
-
+
// argv[0] : beginTime
if (BundleStateCommon::GetInt64NumberValue(env, argv[0], params.beginTime) == nullptr) {
BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, beginTime type is invalid.");
@@ -580,7 +575,6 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
asyncCallbackInfo->packageStats =
BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
} else {
- asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos asyncCallbackInfo == nullptr");
}
},
diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp
index a64c720..157f121 100644
--- a/services/common/src/bundle_active_continuous_task_observer.cpp
+++ b/services/common/src/bundle_active_continuous_task_observer.cpp
@@ -87,7 +87,6 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent(
}
OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
if (ret == ERR_OK && userId != -1 && !bundleName.empty()) {
- std::stringstream stream;
BundleActiveReportHandlerObject tmpHandlerObject(userId, "");
tmpHandlerObject.event_.bundleName_ = bundleName;
tmpHandlerObject.event_.abilityName_ = "";
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 49800e0..4a4c8c3 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -71,7 +71,6 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
std::lock_guard lock(mutex_);
std::string action = data.GetWant().GetAction();
BUNDLE_ACTIVE_LOGI("OnReceiveEvent action is %{public}s", action.c_str());
- auto want = data.GetWant();
if (action == CommonEventSupport::COMMON_EVENT_SCREEN_OFF ||
action == CommonEventSupport::COMMON_EVENT_SCREEN_ON) {
if (!activeGroupController_.expired()) {
@@ -111,8 +110,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da
std::make_shared(tmpHandlerObject);
auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED,
handlerobjToPtr);
- bundleActiveReportHandler_.lock()->SendEvent(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED,
- handlerobjToPtr);
+ bundleActiveReportHandler_.lock()->SendEvent(event);
}
}
}
@@ -164,6 +162,8 @@ void BundleActiveCore::InitBundleGroupController()
bundleGroupHandler_ = std::make_shared(runner, debugCore_);
if (bundleGroupHandler_ == nullptr) {
return;
+ } else {
+ return;
}
if (bundleGroupController_ != nullptr && bundleGroupHandler_ != nullptr) {
bundleGroupHandler_->Init(bundleGroupController_);
@@ -197,6 +197,9 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial
BUNDLE_ACTIVE_LOGI("first initialize user service");
std::shared_ptr service = std::make_shared(userId, *this,
debug);
+ if (service == nullptr) {
+ return nullptr;
+ }
service->Init(timeStamp);
userStatServices_[userId] = service;
if (service == nullptr) {
@@ -246,6 +249,7 @@ void BundleActiveCore::RestoreAllData()
std::shared_ptr service = it->second;
if (service == nullptr) {
BUNDLE_ACTIVE_LOGI("service in BundleActiveCore::RestoreToDatabaseLocked() is null");
+ return;
}
BUNDLE_ACTIVE_LOGI("userid is %{public}d ", service->userId_);
service->RestoreStats(true);
@@ -456,8 +460,7 @@ int BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event)
return -1;
}
if (userStatServices_.empty()) {
- std::shared_ptr service = GetUserDataAndInitializeIfNeeded(DEFAULT_USER_ID, timeNow,
- debugCore_);
+ return DEFAULT_USER_ID;
}
for (std::map>::iterator it = userStatServices_.begin();
it != userStatServices_.end(); it++) {
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 652450d..065fe97 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -75,8 +75,7 @@ void BundleActiveService::InitNecessaryState()
return;
}
- if (systemAbilityManager == nullptr
- || systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID) == nullptr
+ if (systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID) == nullptr
|| systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) == nullptr
|| systemAbilityManager->GetSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr
|| systemAbilityManager->GetSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index 2ade1f2..277adb3 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -375,8 +375,8 @@ int32_t BundleActiveUsageDatabase::DeleteInvalidTable(unsigned int databaseType,
int64_t BundleActiveUsageDatabase::ParseStartTime(const string &tableName)
{
- int64_t invalidStartTime(BUNDLE_ACTIVE_FAIL);
if (tableName.empty()) {
+ int64_t invalidStartTime(BUNDLE_ACTIVE_FAIL);
return invalidStartTime;
}
string tableTime = tableName;
@@ -984,7 +984,6 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime)
void BundleActiveUsageDatabase::RenewTableTime(int64_t changedTime)
{
lock_guard lock(databaseMutex_);
- string logInfo;
for (unsigned int i = 0; i < sortedTableArray_.size(); i++) {
if (sortedTableArray_.at(i).empty()) {
continue;
@@ -1187,7 +1186,6 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t
int32_t tableRowNumber;
bundleActiveResult->GetRowCount(tableRowNumber);
BundleActiveEvent event;
- string timeStamp;
string relativeTimeStamp;
for (int32_t i = 0; i < tableRowNumber; i++) {
bundleActiveResult->GoToRow(i);
diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp
index 693799d..af96e16 100644
--- a/test/unittest/device_usage_statistics_test.cpp
+++ b/test/unittest/device_usage_statistics_test.cpp
@@ -34,7 +34,7 @@ static std::string DEFAULT_BUNDLENAME = "com.ohos.camera";
static std::string DEFAULT_ABILITYID = "1234";
static std::string DEFAULT_ABILITYNAME = "testability";
static int DEFAULT_USERID = 0;
-static int LARGE_NUM = LARGE_NUM;
+static int64_t LARGE_NUM = 20000000000000;
class DeviceUsageStatisticsTest : public testing::Test {
public:
--
Gitee
From 9ec52a266c8e616f8fa18452ee5a75db71358c77 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 16 Mar 2022 09:12:13 +0800
Subject: [PATCH 63/87] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=89=AB=E6=8F=8F?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 4a4c8c3..6d9bcd5 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -162,13 +162,13 @@ void BundleActiveCore::InitBundleGroupController()
bundleGroupHandler_ = std::make_shared(runner, debugCore_);
if (bundleGroupHandler_ == nullptr) {
return;
- } else {
- return;
}
if (bundleGroupController_ != nullptr && bundleGroupHandler_ != nullptr) {
bundleGroupHandler_->Init(bundleGroupController_);
bundleGroupController_->SetHandlerAndCreateUserHistory(bundleGroupHandler_, realTimeShot_);
BUNDLE_ACTIVE_LOGI("Init Set group controller and handler done");
+ } else {
+ return;
}
RegisterSubscriber();
std::vector activatedOsAccountIds;
--
Gitee
From 7c803d218f924e3d3162d68aaab7a171b0b3440f Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 16 Mar 2022 09:45:56 +0800
Subject: [PATCH 64/87] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=89=AB=E6=8F=8F?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packagegroup/src/bundle_active_group_handler.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp
index 5654ef1..7bc412f 100644
--- a/services/packagegroup/src/bundle_active_group_handler.cpp
+++ b/services/packagegroup/src/bundle_active_group_handler.cpp
@@ -47,6 +47,9 @@ void BundleActiveGroupHandler::Init(const std::shared_ptrGetInnerEventId()) {
case MSG_CHECK_BUNDLE_STATE: {
auto ptrToHandlerobj = event->GetSharedObject();
--
Gitee
From 9d63eaf556b99f7fdab54efa9f89d77694c56406 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 16 Mar 2022 09:50:31 +0800
Subject: [PATCH 65/87] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=89=AB=E6=8F=8F?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packagegroup/src/bundle_active_group_handler.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp
index 7bc412f..559c820 100644
--- a/services/packagegroup/src/bundle_active_group_handler.cpp
+++ b/services/packagegroup/src/bundle_active_group_handler.cpp
@@ -68,7 +68,6 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe
return;
}
if (activatedOsAccountIds.size() == 0) {
- BUNDLE_ACTIVE_LOGI("GetAllActiveUser size is 0");
return;
}
for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) {
--
Gitee
From a4759b3181ddb84bf07ec3dc24c5bb0ea4d68835 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 16 Mar 2022 10:23:09 +0800
Subject: [PATCH 66/87] bugfix
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 4 ----
1 file changed, 4 deletions(-)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index 6d9bcd5..f8c2010 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -202,10 +202,6 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial
}
service->Init(timeStamp);
userStatServices_[userId] = service;
- if (service == nullptr) {
- BUNDLE_ACTIVE_LOGE("service is null");
- return nullptr;
- }
BUNDLE_ACTIVE_LOGI("service is not null");
return service;
}
--
Gitee
From 7b7053c0fd314a04800a61f61ac5015471c156dc Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 16 Mar 2022 10:26:40 +0800
Subject: [PATCH 67/87] bugfix
Signed-off-by: houdisheng
---
services/common/src/bundle_active_core.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp
index f8c2010..9b290d1 100644
--- a/services/common/src/bundle_active_core.cpp
+++ b/services/common/src/bundle_active_core.cpp
@@ -207,6 +207,7 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial
}
return it->second;
}
+
void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string& bundleName)
{
BUNDLE_ACTIVE_LOGI("OnBundleUninstalled CALLED");
--
Gitee
From ffa3dd152510fa31e219e5ffbfe624e2ea79ff76 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Wed, 16 Mar 2022 14:31:04 +0800
Subject: [PATCH 68/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9debug=E6=A8=A1=E5=BC=8F?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
services/packageusage/src/bundle_active_calendar.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/services/packageusage/src/bundle_active_calendar.cpp b/services/packageusage/src/bundle_active_calendar.cpp
index fa79eff..70c88f1 100644
--- a/services/packageusage/src/bundle_active_calendar.cpp
+++ b/services/packageusage/src/bundle_active_calendar.cpp
@@ -21,6 +21,10 @@ namespace DeviceUsageStats {
BundleActiveCalendar::BundleActiveCalendar(const int64_t timeStamp)
{
time_ = timeStamp;
+ dayMilliseconds_ = ONE_DAY_TIME;
+ weekMilliseconds_ = ONE_WEEK_TIME;
+ monthMilliseconds_ = ONE_MONTH_TIME;
+ yearMilliseconds_ = ONE_YEAR_TIME;
}
void BundleActiveCalendar::TruncateToDay()
--
Gitee
From 893f91e62cfcb1f8925f6f6720af58a00a692fbe Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Thu, 17 Mar 2022 19:07:18 +0800
Subject: [PATCH 69/87] =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=9E=9A=E4=B8=BE?=
=?UTF-8?q?=E5=B8=B8=E9=87=8F=EF=BC=8C=E6=9D=83=E9=99=90=E5=BC=82=E5=B8=B8?=
=?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: wyuanchao
---
frameworks/src/bundle_state_common.cpp | 4 +-
frameworks/src/bundle_state_init.cpp | 58 +++++++++++++++++++
frameworks/src/bundle_state_query.cpp | 8 +--
.../innerkits/include/bundle_active_client.h | 4 +-
.../innerkits/include/bundle_active_proxy.h | 4 +-
.../innerkits/src/bundle_active_client.cpp | 8 +--
.../innerkits/src/bundle_active_proxy.cpp | 8 ++-
.../napi/include/bundle_state_common.h | 2 +-
.../napi/include/bundle_state_condition.h | 36 ++++++++++++
.../napi/include/bundle_state_init.h | 2 +
.../napi/include/bundle_state_inner_errors.h | 2 +-
.../common/include/bundle_active_service.h | 6 +-
.../common/include/ibundle_active_service.h | 4 +-
services/common/src/bundle_active_service.cpp | 40 ++++++++-----
services/common/src/bundle_active_stub.cpp | 10 +++-
.../unittest/device_usage_statistics_test.cpp | 6 +-
16 files changed, 158 insertions(+), 44 deletions(-)
create mode 100644 interfaces/kits/bundlestats/napi/include/bundle_state_condition.h
diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp
index e1730a6..7f60fed 100644
--- a/frameworks/src/bundle_state_common.cpp
+++ b/frameworks/src/bundle_state_common.cpp
@@ -247,10 +247,10 @@ void BundleStateCommon::SettingCallbackPromiseInfo(
}
std::shared_ptr> BundleStateCommon::GetPackageStats(
- int64_t &beginTime, int64_t &endTime)
+ int64_t &beginTime, int64_t &endTime, int32_t &errCode)
{
std::vector packageStats =
- BundleActiveClient::GetInstance().QueryPackageStats(INTERVAL_TYPE_DEFAULT, beginTime, endTime);
+ BundleActiveClient::GetInstance().QueryPackageStats(INTERVAL_TYPE_DEFAULT, beginTime, endTime, errCode);
std::shared_ptr> mergedPackageStats =
std::make_shared>();
if (packageStats.empty()) {
diff --git a/frameworks/src/bundle_state_init.cpp b/frameworks/src/bundle_state_init.cpp
index 5208f25..eecee10 100644
--- a/frameworks/src/bundle_state_init.cpp
+++ b/frameworks/src/bundle_state_init.cpp
@@ -13,6 +13,7 @@
* limitations under the License.
*/
+#include "bundle_state_condition.h"
#include "bundle_state_init.h"
#include "bundle_state_query.h"
@@ -20,6 +21,10 @@ namespace OHOS {
namespace DeviceUsageStats {
EXTERN_C_START
+static const uint8_t ARG_FIRST = 1;
+
+napi_ref intervalTypeConstructor_ = nullptr;
+
/*
* Module export function
*/
@@ -38,9 +43,62 @@ static napi_value BundleStateInit(napi_env env, napi_value exports)
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
+
+ InitIntervalType(env, exports);
return exports;
}
+napi_value InitIntervalType(napi_env env, napi_value exports)
+{
+ napi_value by_optimized;
+ napi_value by_daily;
+ napi_value by_weekly;
+ napi_value by_monthly;
+ napi_value by_annually;
+ int32_t refCount = 1;
+
+ napi_create_uint32(env, static_cast(BundleStateCondition::IntervalType::BY_OPTIMIZED),
+ &by_optimized);
+ napi_create_uint32(env, static_cast(BundleStateCondition::IntervalType::BY_DAILY),
+ &by_daily);
+ napi_create_uint32(env, static_cast(BundleStateCondition::IntervalType::BY_WEEKLY),
+ &by_weekly);
+ napi_create_uint32(env, static_cast(BundleStateCondition::IntervalType::BY_MONTHLY),
+ &by_monthly);
+ napi_create_uint32(env, static_cast(BundleStateCondition::IntervalType::BY_ANNUALLY),
+ &by_annually);
+
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_STATIC_PROPERTY("BY_OPTIMIZED", by_optimized),
+ DECLARE_NAPI_STATIC_PROPERTY("BY_DAILY", by_daily),
+ DECLARE_NAPI_STATIC_PROPERTY("BY_WEEKLY", by_weekly),
+ DECLARE_NAPI_STATIC_PROPERTY("BY_MONTHLY", by_monthly),
+ DECLARE_NAPI_STATIC_PROPERTY("BY_ANNUALLY", by_annually),
+ };
+
+ napi_value result = nullptr;
+ napi_define_class(env, "IntervalType", NAPI_AUTO_LENGTH, EnumIntervalTypeConstructor,
+ nullptr, sizeof(desc) / sizeof(*desc), desc, &result);
+ napi_create_reference(env, result, refCount, &intervalTypeConstructor_);
+ napi_set_named_property(env, exports, "IntervalType", result);
+ return exports;
+}
+
+napi_value EnumIntervalTypeConstructor(napi_env env, napi_callback_info info)
+{
+ size_t argc = 0;
+ napi_value args[ARG_FIRST] = {0};
+ napi_value res = nullptr;
+ void *data = nullptr;
+
+ napi_status status = napi_get_cb_info(env, info, &argc, args, &res, &data);
+ if (status != napi_ok) {
+ return nullptr;
+ }
+
+ return res;
+}
+
/*
* Module register function
*/
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index a934198..7acbeab 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -340,7 +340,7 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info)
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->BundleActiveState =
BundleActiveClient::GetInstance().QueryEvents(asyncCallbackInfo->beginTime,
- asyncCallbackInfo->endTime);
+ asyncCallbackInfo->endTime, asyncCallbackInfo->info.errorCode);
} else {
BUNDLE_ACTIVE_LOGE("QueryBundleActiveStates, asyncCallbackInfo == nullptr");
}
@@ -464,7 +464,7 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info)
if (asyncCallbackInfo != nullptr) {
asyncCallbackInfo->packageStats =
BundleActiveClient::GetInstance().QueryPackageStats(asyncCallbackInfo->intervalType,
- asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
+ asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime, asyncCallbackInfo->info.errorCode);
} else {
BUNDLE_ACTIVE_LOGE("QueryBundleStateInfoByInterval, asyncCallbackInfo == nullptr");
}
@@ -572,8 +572,8 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
[](napi_env env, void *data) {
AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data;
if (asyncCallbackInfo != nullptr) {
- asyncCallbackInfo->packageStats =
- BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime);
+ asyncCallbackInfo->packageStats = BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime,
+ asyncCallbackInfo->endTime, asyncCallbackInfo->info.errorCode);
} else {
BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos asyncCallbackInfo == nullptr");
}
diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h
index ce2956a..d14ef81 100644
--- a/interfaces/innerkits/include/bundle_active_client.h
+++ b/interfaces/innerkits/include/bundle_active_client.h
@@ -28,8 +28,8 @@ public:
const std::string& continuousTask, const int userId, const int eventId);
bool IsBundleIdle(const std::string& bundleName);
std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
- const int64_t endTime);
- std::vector QueryEvents(const int64_t beginTime, const int64_t endTime);
+ const int64_t endTime, int32_t& errCode);
+ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode);
void SetBundleGroup(std::string bundleName, const int newGroup, const int userId);
std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime);
diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h
index 80eb641..1165c66 100644
--- a/interfaces/innerkits/include/bundle_active_proxy.h
+++ b/interfaces/innerkits/include/bundle_active_proxy.h
@@ -27,8 +27,8 @@ public:
const std::string& continuousTask, const int userId, const int eventId) override;
bool IsBundleIdle(const std::string& bundleName) override;
std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
- const int64_t endTime) override;
- std::vector QueryEvents(const int64_t beginTime, const int64_t endTime) override;
+ const int64_t endTime, int32_t& errCode) override;
+ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) override;
void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override;
std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime) override;
diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp
index 6a3f282..fd2975b 100644
--- a/interfaces/innerkits/src/bundle_active_client.cpp
+++ b/interfaces/innerkits/src/bundle_active_client.cpp
@@ -65,20 +65,20 @@ bool BundleActiveClient::IsBundleIdle(const std::string& bundleName)
}
std::vector BundleActiveClient::QueryPackageStats(const int intervalType,
- const int64_t beginTime, const int64_t endTime)
+ const int64_t beginTime, const int64_t endTime, int32_t& errCode)
{
if (!GetBundleActiveProxy()) {
return std::vector(0);
}
- return bundleActiveProxy_->QueryPackageStats(intervalType, beginTime, endTime);
+ return bundleActiveProxy_->QueryPackageStats(intervalType, beginTime, endTime, errCode);
}
-std::vector BundleActiveClient::QueryEvents(const int64_t beginTime, const int64_t endTime)
+std::vector BundleActiveClient::QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode)
{
if (!GetBundleActiveProxy()) {
return std::vector(0);
}
- return bundleActiveProxy_->QueryEvents(beginTime, endTime);
+ return bundleActiveProxy_->QueryEvents(beginTime, endTime, errCode);
}
void BundleActiveClient::SetBundleGroup(std::string bundleName, const int newGroup, const int userId)
diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp
index a550088..c3dbceb 100644
--- a/interfaces/innerkits/src/bundle_active_proxy.cpp
+++ b/interfaces/innerkits/src/bundle_active_proxy.cpp
@@ -56,7 +56,7 @@ bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName)
}
std::vector BundleActiveProxy::QueryPackageStats(const int intervalType,
- const int64_t beginTime, const int64_t endTime)
+ const int64_t beginTime, const int64_t endTime, int32_t& errCode)
{
MessageParcel data;
MessageParcel reply;
@@ -68,7 +68,9 @@ std::vector BundleActiveProxy::QueryPackageStats(const
data.WriteInt32(intervalType);
data.WriteInt64(beginTime);
data.WriteInt64(endTime);
+ data.WriteInt32(errCode);
Remote() -> SendRequest(QUERY_USAGE_STATS, data, reply, option);
+ errCode = reply.ReadInt32();
int32_t size = reply.ReadInt32();
std::shared_ptr tmp;
for (int i = 0; i < size; i++) {
@@ -88,7 +90,7 @@ std::vector BundleActiveProxy::QueryPackageStats(const
return result;
}
-std::vector BundleActiveProxy::QueryEvents(const int64_t beginTime, const int64_t endTime)
+std::vector BundleActiveProxy::QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode)
{
MessageParcel data;
MessageParcel reply;
@@ -99,7 +101,9 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi
}
data.WriteInt64(beginTime);
data.WriteInt64(endTime);
+ data.WriteInt32(errCode);
Remote() -> SendRequest(QUERY_EVENTS, data, reply, option);
+ errCode = reply.ReadInt32();
int32_t size = reply.ReadInt32();
std::shared_ptr tmp;
for (int i = 0; i < size; i++) {
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
index a8ff5e2..f8c7844 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h
@@ -65,7 +65,7 @@ public:
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);
+ int64_t &beginTime, int64_t &endTime, int32_t &errCode);
static void MergePackageStats(BundleActivePackageStats &left, const BundleActivePackageStats &right);
};
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h b/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h
new file mode 100644
index 0000000..9edd86e
--- /dev/null
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_condition.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_CONDITION_H
+#define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_CONDITION_H
+
+#include
+
+namespace OHOS {
+namespace DeviceUsageStats {
+class BundleStateCondition {
+public:
+ virtual ~BundleStateCondition() = default;
+
+ enum IntervalType {
+ BY_OPTIMIZED = 0,
+ BY_DAILY,
+ BY_WEEKLY,
+ BY_MONTHLY,
+ BY_ANNUALLY,
+ };
+};
+} // namespace DeviceUsageStats
+} // namespace OHOS
+#endif // FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_CONDITION_H
\ No newline at end of file
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_init.h b/interfaces/kits/bundlestats/napi/include/bundle_state_init.h
index 7547c2a..432c2ab 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_init.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_init.h
@@ -27,6 +27,8 @@ extern "C" {
__attribute__((constructor)) void RegisterModule(void);
static napi_value BundleStateInit(napi_env env, napi_value exports);
+static napi_value InitIntervalType(napi_env env, napi_value exports);
+static napi_value EnumIntervalTypeConstructor(napi_env env, napi_callback_info info);
#ifdef __cplusplus
}
diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
index aa70a02..5d03824 100644
--- a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
+++ b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h
@@ -35,7 +35,7 @@ enum : int {
DEVICE_USAGE_STATS_MODULE_COMMON = 0x01,
};
-// Offset of device usage stats sub-system's errcode base, number : 39911424.
+// Offset of device usage stats sub-system's errCode base, number : 39911424.
constexpr ErrCode DEVICE_USAGE_STATS_COMMON_ERR_OFFSET =
ErrCodeOffset(SUBSYS_IAWARE, DEVICE_USAGE_STATS_MODULE_COMMON);
// Device Usage Stats Common Error Code Defined.
diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h
index 64732cd..358571a 100644
--- a/services/common/include/bundle_active_service.h
+++ b/services/common/include/bundle_active_service.h
@@ -40,8 +40,8 @@ public:
const std::string& continuousTask, const int userId, const int eventId) override;
bool IsBundleIdle(const std::string& bundleName) override;
std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
- const int64_t endTime) override;
- std::vector QueryEvents(const int64_t beginTime, const int64_t endTime) override;
+ const int64_t endTime, int32_t& errCode) override;
+ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) override;
void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override;
std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime) override;
@@ -68,7 +68,7 @@ private:
void InitNecessaryState();
void InitService();
bool GetBundleMgrProxy();
- bool CheckBundleIsSystemAppAndHasPermission(const int uid, const int userId);
+ bool CheckBundleIsSystemAppAndHasPermission(const int uid, const int userId, int32_t& errCode);
void InitAppStateSubscriber(const std::shared_ptr& reportHandler);
void InitContinuousSubscriber(const std::shared_ptr& reportHandler);
bool SubscribeAppState();
diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h
index 147b0ee..7069db8 100644
--- a/services/common/include/ibundle_active_service.h
+++ b/services/common/include/ibundle_active_service.h
@@ -46,8 +46,8 @@ public:
const std::string& continuousTask, const int userId, const int eventId) = 0;
virtual bool IsBundleIdle(const std::string& bundleName) = 0;
virtual std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
- const int64_t endTime) = 0;
- virtual std::vector QueryEvents(const int64_t beginTime, const int64_t endTime) = 0;
+ const int64_t endTime, int32_t& errCode) = 0;
+ virtual std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) = 0;
virtual std::vector QueryCurrentPackageStats(const int intervalType,
const int64_t beginTime, const int64_t endTime) = 0;
virtual std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) = 0;
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 065fe97..6023e67 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -240,7 +240,7 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName)
}
std::vector BundleActiveService::QueryPackageStats(const int intervalType,
- const int64_t beginTime, const int64_t endTime)
+ const int64_t beginTime, const int64_t endTime, int32_t& errCode)
{
BUNDLE_ACTIVE_LOGI("QueryPackageStats stats called, intervaltype is %{public}d",
intervalType);
@@ -253,7 +253,7 @@ std::vector BundleActiveService::QueryPackageStats(con
OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId);
if (ret == ERR_OK && userId != -1) {
BUNDLE_ACTIVE_LOGI("QueryPackageStats user id is %{public}d", userId);
- bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId);
+ bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId, errCode);
if (isSystemAppAndHasPermission == true) {
int convertedIntervalType = ConvertIntervalType(intervalType);
result = bundleActiveCore_->QueryPackageStats(userId, convertedIntervalType, beginTime, endTime, "");
@@ -262,7 +262,7 @@ std::vector BundleActiveService::QueryPackageStats(con
return result;
}
-std::vector BundleActiveService::QueryEvents(const int64_t beginTime, const int64_t endTime)
+std::vector BundleActiveService::QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode)
{
BUNDLE_ACTIVE_LOGI("QueryEvents stats called");
std::vector result;
@@ -274,7 +274,7 @@ std::vector BundleActiveService::QueryEvents(const int64_t be
OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId);
if (ret == ERR_OK && userId != -1) {
BUNDLE_ACTIVE_LOGI("QueryEvents userid is %{public}d", userId);
- bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId);
+ bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId, errCode);
if (isSystemAppAndHasPermission == true) {
result = bundleActiveCore_->QueryEvents(userId, beginTime, endTime, "");
}
@@ -306,8 +306,9 @@ std::vector BundleActiveService::QueryCurrentPackageSt
return result;
}
std::string bundleName = "";
+ int32_t errCode = 0;
sptrBundleMgr_->GetBundleNameForUid(callingUid, bundleName);
- bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId);
+ bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId, errCode);
if (!bundleName.empty() && isSystemAppAndHasPermission == true) {
int convertedIntervalType = ConvertIntervalType(intervalType);
result = bundleActiveCore_->QueryPackageStats(userId, convertedIntervalType, beginTime, endTime,
@@ -403,22 +404,29 @@ int BundleActiveService::ConvertIntervalType(const int intervalType)
return -1;
}
-bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid, const int userId)
+bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid, const int userId, int32_t& errCode)
{
if (!GetBundleMgrProxy()) {
BUNDLE_ACTIVE_LOGE("Get bundle manager proxy failed!");
return false;
- }
- std::string bundleName = "";
- sptrBundleMgr_->GetBundleNameForUid(uid, bundleName);
- bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(uid);
- int bundleHasPermission = sptrBundleMgr_->CheckPermissionByUid(bundleName, NEEDED_PERMISSION, userId);
- BUNDLE_ACTIVE_LOGE(" %{public}s is system app %{public}d, "
- "has permission %{public}d", bundleName.c_str(), bundleIsSystemApp, bundleHasPermission);
- if (bundleIsSystemApp == true && bundleHasPermission == 0) {
- return true;
- }
+ }
+ std::string bundleName = "";
+ sptrBundleMgr_->GetBundleNameForUid(uid, bundleName);
+ bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(uid);
+ int bundleHasPermission = sptrBundleMgr_->CheckPermissionByUid(bundleName, NEEDED_PERMISSION, userId);
+ if (!bundleIsSystemApp) {
+ errCode = BUNDLE_ACTIVE_FAIL;
+ BUNDLE_ACTIVE_LOGE("%{public}s is not system app" , bundleName.c_str());
+ return false;
+ } else if (bundleHasPermission != 0) {
+ errCode = bundleHasPermission;
+ BUNDLE_ACTIVE_LOGE("%{public}s hasn't permission", bundleName.c_str());
return false;
+ } else {
+ BUNDLE_ACTIVE_LOGI(" %{public}s is system app %{public}d, "
+ "has permission %{public}d", bundleName.c_str(), bundleIsSystemApp, bundleHasPermission);
+ return true;
+ }
}
}
}
\ No newline at end of file
diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp
index 02c5beb..f24e1a2 100644
--- a/services/common/src/bundle_active_stub.cpp
+++ b/services/common/src/bundle_active_stub.cpp
@@ -49,7 +49,9 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me
intervalType);
int64_t beginTime = data.ReadInt64();
int64_t endTime = data.ReadInt64();
- result = QueryPackageStats(intervalType, beginTime, endTime);
+ int32_t errCode = data.ReadInt32();
+ result = QueryPackageStats(intervalType, beginTime, endTime, errCode);
+ reply.WriteInt32(errCode);
size = static_cast(result.size());
BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_USAGE_STATS result size is %{public}d", size);
reply.WriteInt32(size);
@@ -66,8 +68,10 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me
int size = 0;
int64_t beginTime = data.ReadInt64();
int64_t endTime = data.ReadInt64();
- result = QueryEvents(beginTime, endTime);
+ int32_t errCode = data.ReadInt32();
+ result = QueryEvents(beginTime, endTime, errCode);
size = static_cast(result.size());
+ reply.WriteInt32(errCode);
reply.WriteInt32(size);
for (int i = 0; i < size; i++) {
bool tmp = result[i].Marshalling(reply);
@@ -92,7 +96,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me
"is %{public}d", intervalType);
int64_t beginTime = data.ReadInt64();
int64_t endTime = data.ReadInt64();
- result = QueryPackageStats(intervalType, beginTime, endTime);
+ result = QueryCurrentPackageStats(intervalType, beginTime, endTime);
size = static_cast(result.size());
BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_CURRENT_USAGE_STATS result size "
"is %{public}d", size);
diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp
index af96e16..277df46 100644
--- a/test/unittest/device_usage_statistics_test.cpp
+++ b/test/unittest/device_usage_statistics_test.cpp
@@ -101,7 +101,8 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ReportEvent_001, F
*/
HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryEvents_001, Function | MediumTest | Level0)
{
- std::vector result = BundleActiveClient::GetInstance().QueryEvents(0, LARGE_NUM);
+ int32_t errCode = 0;
+ std::vector result = BundleActiveClient::GetInstance().QueryEvents(0, LARGE_NUM, errCode);
EXPECT_EQ(result.size(), 0);
}
@@ -125,8 +126,9 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryCurrentEvents
*/
HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackagesStats_001, Function | MediumTest | Level0)
{
+ int32_t errCode = 0;
std::vector result = BundleActiveClient::GetInstance().QueryPackageStats(4, 0,
- LARGE_NUM);
+ LARGE_NUM, errCode);
EXPECT_EQ(result.size(), 0);
}
--
Gitee
From cf23acf8d91bd1c82beea7fe528f37a97fc9c269 Mon Sep 17 00:00:00 2001
From: wyuanchao
Date: Thu, 17 Mar 2022 19:19:42 +0800
Subject: [PATCH 70/87] =?UTF-8?q?=E8=A7=A3=E6=9E=90=E6=9E=9A=E4=B8=BE?=
=?UTF-8?q?=E5=B8=B8=E9=87=8F=EF=BC=8C=E6=9D=83=E9=99=90=E5=BC=82=E5=B8=B8?=
=?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: wyuanchao
---
frameworks/src/bundle_state_init.cpp | 2 +-
interfaces/innerkits/include/bundle_active_proxy.h | 3 ++-
interfaces/innerkits/src/bundle_active_client.cpp | 3 ++-
interfaces/innerkits/src/bundle_active_proxy.cpp | 3 ++-
services/common/include/bundle_active_service.h | 3 ++-
services/common/include/ibundle_active_service.h | 3 ++-
services/common/src/bundle_active_service.cpp | 5 +++--
7 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/frameworks/src/bundle_state_init.cpp b/frameworks/src/bundle_state_init.cpp
index eecee10..c84be7f 100644
--- a/frameworks/src/bundle_state_init.cpp
+++ b/frameworks/src/bundle_state_init.cpp
@@ -14,8 +14,8 @@
*/
#include "bundle_state_condition.h"
-#include "bundle_state_init.h"
#include "bundle_state_query.h"
+#include "bundle_state_init.h"
namespace OHOS {
namespace DeviceUsageStats {
diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h
index 1165c66..2508e26 100644
--- a/interfaces/innerkits/include/bundle_active_proxy.h
+++ b/interfaces/innerkits/include/bundle_active_proxy.h
@@ -28,7 +28,8 @@ public:
bool IsBundleIdle(const std::string& bundleName) override;
std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime, int32_t& errCode) override;
- std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) override;
+ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime,
+ int32_t& errCode) override;
void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override;
std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime) override;
diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp
index fd2975b..32fbbea 100644
--- a/interfaces/innerkits/src/bundle_active_client.cpp
+++ b/interfaces/innerkits/src/bundle_active_client.cpp
@@ -73,7 +73,8 @@ std::vector BundleActiveClient::QueryPackageStats(cons
return bundleActiveProxy_->QueryPackageStats(intervalType, beginTime, endTime, errCode);
}
-std::vector BundleActiveClient::QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode)
+std::vector BundleActiveClient::QueryEvents(const int64_t beginTime,
+ const int64_t endTime, int32_t& errCode)
{
if (!GetBundleActiveProxy()) {
return std::vector(0);
diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp
index c3dbceb..21aef49 100644
--- a/interfaces/innerkits/src/bundle_active_proxy.cpp
+++ b/interfaces/innerkits/src/bundle_active_proxy.cpp
@@ -90,7 +90,8 @@ std::vector BundleActiveProxy::QueryPackageStats(const
return result;
}
-std::vector BundleActiveProxy::QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode)
+std::vector BundleActiveProxy::QueryEvents(const int64_t beginTime,
+ const int64_t endTime, int32_t& errCode)
{
MessageParcel data;
MessageParcel reply;
diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h
index 358571a..3c93f0a 100644
--- a/services/common/include/bundle_active_service.h
+++ b/services/common/include/bundle_active_service.h
@@ -41,7 +41,8 @@ public:
bool IsBundleIdle(const std::string& bundleName) override;
std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime, int32_t& errCode) override;
- std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) override;
+ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime,
+ int32_t& errCode) override;
void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override;
std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime) override;
diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h
index 7069db8..3740ca1 100644
--- a/services/common/include/ibundle_active_service.h
+++ b/services/common/include/ibundle_active_service.h
@@ -47,7 +47,8 @@ public:
virtual bool IsBundleIdle(const std::string& bundleName) = 0;
virtual std::vector QueryPackageStats(const int intervalType, const int64_t beginTime,
const int64_t endTime, int32_t& errCode) = 0;
- virtual std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) = 0;
+ virtual std::vector QueryEvents(const int64_t beginTime, const int64_t endTime,
+ int32_t& errCode) = 0;
virtual std::vector QueryCurrentPackageStats(const int intervalType,
const int64_t beginTime, const int64_t endTime) = 0;
virtual std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) = 0;
diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp
index 6023e67..d5dc82d 100644
--- a/services/common/src/bundle_active_service.cpp
+++ b/services/common/src/bundle_active_service.cpp
@@ -262,7 +262,8 @@ std::vector BundleActiveService::QueryPackageStats(con
return result;
}
-std::vector BundleActiveService::QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode)
+std::vector BundleActiveService::QueryEvents(const int64_t beginTime,
+ const int64_t endTime, int32_t& errCode)
{
BUNDLE_ACTIVE_LOGI("QueryEvents stats called");
std::vector result;
@@ -416,7 +417,7 @@ bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid,
int bundleHasPermission = sptrBundleMgr_->CheckPermissionByUid(bundleName, NEEDED_PERMISSION, userId);
if (!bundleIsSystemApp) {
errCode = BUNDLE_ACTIVE_FAIL;
- BUNDLE_ACTIVE_LOGE("%{public}s is not system app" , bundleName.c_str());
+ BUNDLE_ACTIVE_LOGE("%{public}s is not system app", bundleName.c_str());
return false;
} else if (bundleHasPermission != 0) {
errCode = bundleHasPermission;
--
Gitee
From e4f5a27b4775fef893f0a61edf1b37d073f21249 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Fri, 18 Mar 2022 17:03:58 +0800
Subject: [PATCH 71/87] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dkora=E6=89=AB=E6=8F=8F?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E7=89=88=E6=9D=83=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E5=B9=B4=E4=BB=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
OAT.xml | 2 +-
frameworks/src/bundle_state_common.cpp | 1 +
.../include/bundle_active_app_state_observer.h | 2 +-
.../bundle_active_continuous_task_observer.h | 2 +-
.../src/bundle_active_app_state_obsever.cpp | 2 +-
.../bundle_active_continuous_task_observer.cpp | 2 +-
services/common/src/bundle_active_core.cpp | 18 ++++++++----------
.../src/bundle_active_group_handler.cpp | 1 +
.../src/bundle_active_user_service.cpp | 5 +++--
9 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/OAT.xml b/OAT.xml
index b11daf5..b0ba076 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -1,5 +1,5 @@
-
device_usage_stats_service
diff --git a/services/common/include/bundle_active_app_state_observer.h b/services/common/include/bundle_active_app_state_observer.h
index 3c7b079..5e6d183 100644
--- a/services/common/include/bundle_active_app_state_observer.h
+++ b/services/common/include/bundle_active_app_state_observer.h
@@ -32,12 +32,7 @@ using OHOS::AppExecFwk::ProcessData;
class BundleActiveAppStateObserver : public ApplicationStateObserverStub {
public:
- void OnForegroundApplicationChanged(const AppStateData &appStateData) override;
void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override;
- void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override;
- void OnProcessCreated(const ProcessData &processData) override;
- void OnProcessDied(const ProcessData &processData) override;
- void OnApplicationStateChanged(const AppStateData &appStateData) override;
void Init(const std::shared_ptr& reportHandler);
private:
inline bool ValidateAppStateData(const AppStateData &appStateData) const
diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp
index 2b3422b..d598923 100644
--- a/services/common/src/bundle_active_app_state_obsever.cpp
+++ b/services/common/src/bundle_active_app_state_obsever.cpp
@@ -81,25 +81,5 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData
}
return;
}
-
-void BundleActiveAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appStateData)
-{
-}
-
-void BundleActiveAppStateObserver::OnExtensionStateChanged(const AbilityStateData &abilityStateData)
-{
-}
-
-void BundleActiveAppStateObserver::OnProcessCreated(const ProcessData &processData)
-{
-}
-
-void BundleActiveAppStateObserver::OnProcessDied(const ProcessData &processData)
-{
-}
-
-void BundleActiveAppStateObserver::OnApplicationStateChanged(const AppStateData &appStateData)
-{
-}
}
}
\ No newline at end of file
diff --git a/services/common/src/bundle_active_open_callback.cpp b/services/common/src/bundle_active_open_callback.cpp
index 6e1ce14..edb4774 100644
--- a/services/common/src/bundle_active_open_callback.cpp
+++ b/services/common/src/bundle_active_open_callback.cpp
@@ -35,6 +35,9 @@ int32_t BundleActiveOpenCallback::OnCreate(NativeRdb::RdbStore &rdbStore)
int32_t BundleActiveOpenCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion)
{
+ (void)rdbStore;
+ (void)oldVersion;
+ (void)newVersion;
BUNDLE_ACTIVE_LOGI("Upgrade success.");
return NativeRdb::E_OK;
};
diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp
index 2aa9713..c791314 100644
--- a/services/common/src/bundle_active_usage_database.cpp
+++ b/services/common/src/bundle_active_usage_database.cpp
@@ -305,7 +305,7 @@ void BundleActiveUsageDatabase::DeleteExcessiveTableData(unsigned int databaseTy
} else if (databaseType == APP_GROUP_DATABASE_INDEX) {
// 无数据删除
} else {
- BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType);
+ BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}u", databaseType);
}
}
@@ -314,7 +314,7 @@ std::unique_ptr> BundleActiveUsageDatabase::GetOverdueTable
{
std::unique_ptr> overdueTableCreateTime = std::make_unique>();
if (databaseType >= sortedTableArray_.size()) {
- BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType);
+ BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}u", databaseType);
return nullptr;
}
string queryDatabaseTableNames = "select * from sqlite_master where type = ?";
--
Gitee
From aed1e1b5c1db54f101a84c34c0eeae79b5f40e9c Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Sat, 19 Mar 2022 15:08:57 +0800
Subject: [PATCH 78/87] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E6=BA=90?=
=?UTF-8?q?=E6=A3=80=E8=A7=86issue?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
frameworks/src/bundle_state_query.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index 97ab0a4..5c13cda 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -164,7 +164,7 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info)
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
- if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoPriorityGroup), 0 , sizeof(AsyncCallbackInfoPriorityGroup))
+ if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoPriorityGroup), 0, sizeof(AsyncCallbackInfoPriorityGroup))
!= EOK) {
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
@@ -270,7 +270,7 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info)
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
- if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoStates), 0 , sizeof(AsyncCallbackInfoStates))
+ if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoStates), 0, sizeof(AsyncCallbackInfoStates))
!= EOK) {
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
@@ -343,7 +343,7 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info)
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
- if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoStates), 0 , sizeof(AsyncCallbackInfoStates))
+ if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoStates), 0, sizeof(AsyncCallbackInfoStates))
!= EOK) {
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
@@ -473,7 +473,7 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info)
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
- if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsageByInterval), 0 , sizeof(AsyncCallbackInfoAppUsageByInterval))
+ if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsageByInterval), 0, sizeof(AsyncCallbackInfoAppUsageByInterval))
!= EOK) {
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
@@ -593,7 +593,7 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info)
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
- if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsage), 0 , sizeof(AsyncCallbackInfoAppUsage))
+ if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsage), 0, sizeof(AsyncCallbackInfoAppUsage))
!= EOK) {
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
--
Gitee
From 44082be33d95e90c90583db18f309e0fc8fe5541 Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Sat, 19 Mar 2022 15:16:27 +0800
Subject: [PATCH 79/87] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E6=BA=90?=
=?UTF-8?q?=E6=A3=80=E8=A7=86issue?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
frameworks/src/bundle_state_query.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp
index 5c13cda..59bf313 100644
--- a/frameworks/src/bundle_state_query.cpp
+++ b/frameworks/src/bundle_state_query.cpp
@@ -473,8 +473,8 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info)
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
- if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsageByInterval), 0, sizeof(AsyncCallbackInfoAppUsageByInterval))
- != EOK) {
+ if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsageByInterval), 0,
+ sizeof(AsyncCallbackInfoAppUsageByInterval)) != EOK) {
params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED;
return BundleStateCommon::JSParaError(env, params.callback, params.errorCode);
}
--
Gitee
From 0cd38a3fb230223bb305ddcd06d933be02202fce Mon Sep 17 00:00:00 2001
From: houdisheng
Date: Sat, 19 Mar 2022 17:32:48 +0800
Subject: [PATCH 80/87] =?UTF-8?q?=E4=BF=AE=E6=94=B9oatxml=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E6=A0=BC=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: houdisheng
---
OAT.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/OAT.xml b/OAT.xml
index 96845bc..b0ba076 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -1,5 +1,6 @@