diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index f06222293da2b84077c6463467c409a2807d6951..91589741092c7f43de4c2468f495af7b5edda73b 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -84,15 +84,13 @@ napi_value ParseQueryAppGroupParameters(const napi_env &env, const napi_callback return BundleStateCommon::HandleParamErr(env, ERR_PARAMETERS_EMPTY, "bundleName"); } // argv[1]: callback - if (argc == PRIORITY_GROUP_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - if (valuetype != napi_function) { - params.errorCode = ERR_CALL_BACK_TYPE; - return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); - } - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + if (inputValueType != napi_function) { + params.errorCode = ERR_CALL_BACK_TYPE; + return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } + napi_create_reference(env, argv[1], 1, ¶ms.callback); } BundleStateCommon::AsyncInit(env, params, asyncCallbackInfo); return BundleStateCommon::NapiGetNull(env); @@ -195,9 +193,9 @@ napi_value ParseSetAppGroupParameters(const napi_env &env, const napi_callback_i } // argv[SECOND_ARG]: callback if (argc == APP_USAGE_PARAMS_BUNDLE_GROUP) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } @@ -259,7 +257,7 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) napi_value GetAppGroupChangeCallback(const napi_env &env, const napi_value &value) { napi_ref result = nullptr; - + registerObserver = new (std::nothrow) AppGroupObserver(); if (!registerObserver) { BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack callback is null"); @@ -281,7 +279,7 @@ napi_value ParseRegisterAppGroupCallBackParameters(const napi_env &env, const na params.errorCode = ERR_PARAMETERS_NUMBER; return BundleStateCommon::HandleParamErr(env, ERR_PARAMETERS_NUMBER, ""); } - + // arg[0] : callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); @@ -298,9 +296,9 @@ napi_value ParseRegisterAppGroupCallBackParameters(const napi_env &env, const na // argv[1]: asyncCallback if (argc == REGISTER_GROUP_CALLBACK_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 12a229201fcaa5175cee9e4cee6ffb587b0c0c32..5c486ca185e80e46d6583f2e8a7eab2308c19ccf 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -102,7 +102,7 @@ void BundleStateCommon::SetCallbackInfo( } void BundleStateCommon::GetBundleActiveEventForResult( - napi_env env, const std::vector &bundleActiveStates, napi_value result) + napi_env env, const std::vector &bundleActiveStates, napi_value result, bool isNewVersion) { int32_t index = 0; for (const auto &item : bundleActiveStates) { @@ -116,12 +116,19 @@ void BundleStateCommon::GetBundleActiveEventForResult( napi_value eventId = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.eventId_, &eventId)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); napi_value eventOccurredTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.timeStamp_, &eventOccurredTime)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", - eventOccurredTime)); + + if (isNewVersion) { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", + eventOccurredTime)); + } else { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateType", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateOccurredTime", + eventOccurredTime)); + } NAPI_CALL_RETURN_VOID(env, napi_set_element(env, result, index, bundleActiveState)); index++; @@ -359,8 +366,8 @@ napi_value BundleStateCommon::GetErrorValue(napi_env env, int32_t errCode) NAPI_CALL(env, napi_create_int32(env, reflectCode, &eCode)); NAPI_CALL(env, napi_create_string_utf8(env, errMsg.c_str(), errMsg.length(), &eMsg)); NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_set_named_property(env, result, "errCode", eCode)); - NAPI_CALL(env, napi_set_named_property(env, result, "errMessage", eMsg)); + NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode)); + NAPI_CALL(env, napi_set_named_property(env, result, "message", eMsg)); return result; } diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 3506569558e11d6952d58bfe22a1793649c798ff..edb88d86ffeebc953154eb00778fd6c81aa82758 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -63,9 +63,9 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i // 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, + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + NAPI_ASSERT(env, inputValueType == napi_function, "ParseIsIdleStateParameters invalid parameter type, function expected."); napi_create_reference(env, argv[1], 1, ¶ms.callback); } @@ -317,7 +317,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -383,7 +384,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 9847228032634f460311a6992fdb0622dcc778f0..e7e775d383740595353d72bc28751d0766a86cc7 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -183,9 +183,9 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i // argv[1]: callback if (argc == IS_IDLE_STATE_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - if (valuetype != napi_function) { + napi_valuetype inputValueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &inputValueType)); + if (inputValueType != napi_function) { params.errorCode = ERR_CALL_BACK_TYPE; return BundleStateCommon::HandleParamErr(env, ERR_CALL_BACK_TYPE, ""); } @@ -331,7 +331,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -386,7 +387,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index ae545d58b34370578bd45be3503726d6254ddd07..4b01289dcce2a27653f725347754a4a8a3275348 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -134,7 +134,6 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector result; if (!data.WriteInterfaceToken(GetDescriptor())) { return ERR_PARCEL_WRITE_FALIED; } @@ -204,7 +203,7 @@ ErrCode BundleActiveProxy::QueryAppGroup(int32_t& appGroup, std::string& bundleN if (!data.WriteInterfaceToken(GetDescriptor())) { return ERR_PARCEL_WRITE_FALIED; } - + data.WriteString(bundleName); data.WriteInt32(userId); Remote() -> SendRequest(QUERY_APP_GROUP, data, reply, option); diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index ab56949e1d5e0204e9899e727559292d2d6e6761..56db22bd57b2807d0f118d9645d54fd8f5cfe2c9 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -51,7 +51,7 @@ public: const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); static void GetBundleActiveEventForResult( - napi_env env, const std::vector &BundleActiveState, napi_value result); + napi_env env, const std::vector &BundleActiveState, napi_value result, bool isNewVersion); static void GetBundleStateInfoByIntervalForResult( napi_env env, const std::vector &packageStats, napi_value result); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index d872af43706f8288c74a93ed949db98793b1fd5c..6f878ee94a8642453b84e3f1543be7d445e77811 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -225,9 +225,6 @@ 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; BUNDLE_ACTIVE_LOGI("service is not null"); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 1b8ff5ce871496da7f762059714ac6e8e3a646ce..a0b50486b14fcb568dabb350e7e367cf9143e838 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -36,7 +36,6 @@ static const std::string PERMITTED_PROCESS_NAME = "foundation"; static const int32_t MAXNUM_UP_LIMIT = 1000; const int32_t EVENTS_PARAM = 5; static constexpr int32_t NO_DUMP_PARAM_NUMS = 0; -static constexpr int32_t MIN_DUMP_PARAM_NUMS = 1; const int32_t PACKAGE_USAGE_PARAM = 6; const int32_t MODULE_USAGE_PARAM = 4; const std::string NEEDED_PERMISSION = "ohos.permission.BUNDLE_ACTIVE_INFO"; @@ -320,7 +319,6 @@ ErrCode BundleActiveService::QueryBundleStatsInfoByInterval(std::vector& bundleActiveEvents, const int64_t beginTime, const int64_t endTime, int32_t userId) { - std::vector result; ErrCode ret = ERR_OK; int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); @@ -334,7 +332,7 @@ ErrCode BundleActiveService::QueryBundleEvents(std::vector& b ret = CheckSystemAppOrNativePermission(callingUid, tokenId); if (ret == ERR_OK) { ret = bundleActiveCore_->QueryBundleEvents(bundleActiveEvents, userId, beginTime, endTime, ""); - BUNDLE_ACTIVE_LOGI("QueryBundleEvents result is %{public}zu", result.size()); + BUNDLE_ACTIVE_LOGI("QueryBundleEvents result is %{public}zu", bundleActiveEvents.size()); } return ret; } @@ -682,7 +680,7 @@ int32_t BundleActiveService::Dump(int32_t fd, const std::vector int32_t ret = ERR_OK; if (argsInStr.size() == NO_DUMP_PARAM_NUMS) { DumpUsage(result); - } else if (argsInStr.size() >= MIN_DUMP_PARAM_NUMS) { + } else { std::vector infos; if (argsInStr[0] == "-h") { DumpUsage(result); diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index ce3d393a8cd5154141dc173b7dce726511b0c49b..9593b6271573de53d28d139635db1c14e321ec6f 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -237,12 +237,12 @@ void BundleActiveUsageDatabase::HandleTableInfo(uint32_t databaseType) } int32_t tableNameIndex; bundleActiveResult->GetColumnIndex(SQLITE_MASTER_NAME, tableNameIndex); - string tableName; if (databaseType >= 0 && databaseType < sortedTableArray_.size()) { if (!sortedTableArray_.at(databaseType).empty()) { sortedTableArray_.at(databaseType).clear(); } for (int32_t i = 0; i < tableNumber; i++) { + string tableName; bundleActiveResult->GoToRow(i); bundleActiveResult->GetString(tableNameIndex, tableName); sortedTableArray_.at(databaseType).push_back(ParseStartTime(tableName)); @@ -434,9 +434,8 @@ shared_ptr BundleActiveUsageDatabase::GetBundleActiveRdbSto void BundleActiveUsageDatabase::CheckDatabaseFile(uint32_t databaseType) { std::string databaseFileName = databaseFiles_.at(databaseType); - std::string dbFile; for (uint32_t i = 0; i < sizeof(SUFFIX_TYPE) / sizeof(SUFFIX_TYPE[0]); i++) { - dbFile = BUNDLE_ACTIVE_DATABASE_DIR + DATABASE_TYPE[databaseType] + SUFFIX_TYPE[i]; + std::string dbFile = BUNDLE_ACTIVE_DATABASE_DIR + DATABASE_TYPE[databaseType] + SUFFIX_TYPE[i]; if ((access(dbFile.c_str(), F_OK) != 0) && (bundleActiveRdbStoreCache_.find(databaseFileName) != bundleActiveRdbStoreCache_.end())) { bundleActiveRdbStoreCache_.erase(databaseFileName); @@ -1511,8 +1510,8 @@ void BundleActiveUsageDatabase::RemoveFormData(const int32_t userId, const std:: return; } int32_t deletedRows = BUNDLE_ACTIVE_FAIL; - vector queryCondition; if (formRecordsTableName_ != UNKNOWN_TABLE_NAME) { + vector queryCondition; queryCondition.emplace_back(to_string(userId)); queryCondition.emplace_back(bundleName); queryCondition.emplace_back(moduleName); diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index 6c6ec4290f260fcb62d3dfbca1fda5dad7067b60..fd897f75afe9a172c5c6b1eacf3b7db16c067aba 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -75,13 +75,13 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe BUNDLE_ACTIVE_LOGI("query activated account failed"); return; } + if (activatedOsAccountIds.size() == 0) { + return; + } #else // OS_ACCOUNT_PART_ENABLED activatedOsAccountIds.push_back(DEFAULT_OS_ACCOUNT_ID); BUNDLE_ACTIVE_LOGI("os account part not enabled, use default id."); #endif // OS_ACCOUNT_PART_ENABLED - if (activatedOsAccountIds.size() == 0) { - return; - } for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { bundleActiveGroupController_->CheckEachBundleState(activatedOsAccountIds[i]); bundleActiveGroupController_->RestoreToDatabase(activatedOsAccountIds[i]); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index d2dfaeae4081308ebed89ba0caacca682cffc339..cddfcf7053b78edc60b4afe8f8f35cfa3b8938b6 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -340,7 +340,7 @@ ErrCode BundleActiveUserService::QueryBundleStatsInfos(std::vectorendTime_ != 0 && endTime > currentStats->beginTime_) { + if (endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryBundleStatsInfos need in memory stats"); for (auto it : currentStats->bundleStats_) { if (bundleName.empty()) { @@ -375,8 +375,12 @@ ErrCode BundleActiveUserService::QueryBundleEvents(std::vectorendTime_ == 0) { + BUNDLE_ACTIVE_LOGI("QueryBundleEvents result in db is %{public}zu", bundleActiveEvent.size()); + return ERR_OK; + } // if we need a in-memory stats, combine current stats with bundleActiveEvent from database. - if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) { + if (endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryBundleEvents need in memory stats"); int32_t eventBeginIdx = currentStats->events_.FindBestIndex(beginTime); int32_t eventSize = currentStats->events_.Size(); @@ -388,7 +392,7 @@ ErrCode BundleActiveUserService::QueryBundleEvents(std::vector