hilog整改

Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
xinking129 2024-03-25 19:56:45 +08:00
parent c8271af784
commit cc97d963e1
39 changed files with 984 additions and 930 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -15,6 +15,7 @@
#include "js_ability_auto_startup_callback.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_ability_auto_startup_manager_utils.h"
#include "js_runtime.h"
@ -32,23 +33,23 @@ JsAbilityAutoStartupCallBack::~JsAbilityAutoStartupCallBack() {}
void JsAbilityAutoStartupCallBack::OnAutoStartupOn(const AutoStartupInfo &info)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
JSCallFunction(info, METHOD_ON);
}
void JsAbilityAutoStartupCallBack::OnAutoStartupOff(const AutoStartupInfo &info)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
JSCallFunction(info, METHOD_OFF);
}
void JsAbilityAutoStartupCallBack::Register(napi_value value)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
std::lock_guard<std::mutex> lock(mutexlock);
for (const auto &callback : callbacks_) {
if (IsJsCallbackEquals(callback, value)) {
HILOG_ERROR("The current callback already exists.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The current callback already exists.");
return;
}
}
@ -60,12 +61,12 @@ void JsAbilityAutoStartupCallBack::Register(napi_value value)
void JsAbilityAutoStartupCallBack::UnRegister(napi_value value)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
napi_valuetype type = napi_undefined;
napi_typeof(env_, value, &type);
std::lock_guard<std::mutex> lock(mutexlock);
if (type == napi_undefined || type == napi_null) {
HILOG_DEBUG("jsCallback is nullptr, delete all callback.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "jsCallback is nullptr, delete all callback.");
callbacks_.clear();
return;
}
@ -91,7 +92,7 @@ void JsAbilityAutoStartupCallBack::JSCallFunction(const AutoStartupInfo &info, c
napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JsAbilityAutoStartupCallBack> obj = stub.promote();
if (obj == nullptr) {
HILOG_ERROR("Callback object is nullptr");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Callback object is nullptr");
return;
}
@ -107,19 +108,19 @@ void JsAbilityAutoStartupCallBack::JSCallFunctionWorker(const AutoStartupInfo &i
std::lock_guard<std::mutex> lock(mutexlock);
for (auto callback : callbacks_) {
if (callback == nullptr) {
HILOG_ERROR("callback is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "callback is nullptr.");
continue;
}
auto obj = callback->GetNapiValue();
if (obj == nullptr) {
HILOG_ERROR("Failed to get value.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get value.");
continue;
}
napi_value funcObject;
if (napi_get_named_property(env_, obj, methodName.c_str(), &funcObject) != napi_ok) {
HILOG_ERROR("Get function by name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Get function by name failed.");
continue;
}
@ -132,19 +133,19 @@ bool JsAbilityAutoStartupCallBack::IsJsCallbackEquals(const std::shared_ptr<Nati
napi_value value)
{
if (callback == nullptr) {
HILOG_ERROR("Invalid jsCallback.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid jsCallback.");
return false;
}
auto object = callback->GetNapiValue();
if (object == nullptr) {
HILOG_ERROR("Failed to get object.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get object.");
return false;
}
bool result = false;
if (napi_strict_equals(env_, object, value, &result) != napi_ok) {
HILOG_ERROR("Object does not match value.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Object does not match value.");
return false;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -14,6 +14,7 @@
*/
#include "js_ability_auto_startup_manager_utils.h"
#include "hilog_tag_wrapper.h"
#include "napi_common_util.h"
namespace OHOS {
@ -21,17 +22,17 @@ namespace AbilityRuntime {
bool UnwrapAutoStartupInfo(napi_env env, napi_value param, AutoStartupInfo &info)
{
if (!IsNormalObject(env, param)) {
HILOG_ERROR("param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "param is invalid.");
return false;
}
if (!AppExecFwk::UnwrapStringByPropertyName(env, param, "bundleName", info.bundleName)) {
HILOG_ERROR("Convert bundle name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert bundle name failed.");
return false;
}
if (!AppExecFwk::UnwrapStringByPropertyName(env, param, "abilityName", info.abilityName)) {
HILOG_ERROR("Convert ability name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert ability name failed.");
return false;
}
@ -42,17 +43,17 @@ bool UnwrapAutoStartupInfo(napi_env env, napi_value param, AutoStartupInfo &info
bool IsNormalObject(napi_env env, napi_value value)
{
if (value == nullptr) {
HILOG_ERROR("value is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "value is nullptr.");
return false;
}
napi_valuetype type;
napi_typeof(env, value, &type);
if (type == napi_undefined || type == napi_null) {
HILOG_ERROR("value is invalid type.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "value is invalid type.");
return false;
}
if (type != napi_object) {
HILOG_ERROR("Invalid type.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid type.");
return false;
}
return true;
@ -60,18 +61,18 @@ bool IsNormalObject(napi_env env, napi_value value)
napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStartupInfo> &infoList)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
napi_value arrayObj = nullptr;
napi_create_array(env, &arrayObj);
for (size_t i = 0; i < infoList.size(); ++i) {
auto object = CreateJsAutoStartupInfo(env, infoList.at(i));
if (object == nullptr) {
HILOG_ERROR("Convert object failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert object failed.");
return nullptr;
}
if (napi_set_element(env, arrayObj, i, object) != napi_ok) {
HILOG_ERROR("Inster object to array failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Inster object to array failed.");
return nullptr;
}
}
@ -81,34 +82,34 @@ napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStar
napi_value CreateJsAutoStartupInfo(napi_env env, const AutoStartupInfo &info)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
napi_value object = AppExecFwk::CreateJSObject(env);
if (object == nullptr) {
HILOG_ERROR("object is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "object is nullptr.");
return nullptr;
}
napi_value bundleName = AppExecFwk::WrapStringToJS(env, info.bundleName);
if (bundleName == nullptr) {
HILOG_ERROR("Convert bundle name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert bundle name failed.");
return nullptr;
}
napi_value abilityName = AppExecFwk::WrapStringToJS(env, info.abilityName);
if (abilityName == nullptr) {
HILOG_ERROR("Convert ability name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert ability name failed.");
return nullptr;
}
napi_value moduleName = AppExecFwk::WrapStringToJS(env, info.moduleName);
if (moduleName == nullptr) {
HILOG_ERROR("Convert module name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert module name failed.");
return nullptr;
}
napi_value abilityTypeName = AppExecFwk::WrapStringToJS(env, info.abilityTypeName);
if (abilityTypeName == nullptr) {
HILOG_ERROR("Convert ability type name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert ability type name failed.");
return nullptr;
}
@ -116,7 +117,7 @@ napi_value CreateJsAutoStartupInfo(napi_env env, const AutoStartupInfo &info)
AppExecFwk::SetPropertyValueByPropertyName(env, object, "abilityName", abilityName) &&
AppExecFwk::SetPropertyValueByPropertyName(env, object, "moduleName", moduleName) &&
AppExecFwk::SetPropertyValueByPropertyName(env, object, "abilityTypeName", abilityTypeName))) {
HILOG_ERROR("Create js AutoStartupInfo failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Create js AutoStartupInfo failed.");
return nullptr;
}
return object;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -18,6 +18,7 @@
#include "ability_manager_client.h"
#include "ability_manager_interface.h"
#include "auto_startup_info.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "js_ability_auto_startup_manager_utils.h"
@ -39,7 +40,7 @@ constexpr const char *ON_OFF_TYPE_SYSTEM = "systemAutoStartup";
void JsAbilityAutoStartupManager::Finalizer(napi_env env, void *data, void *hint)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
std::unique_ptr<JsAbilityAutoStartupManager>(static_cast<JsAbilityAutoStartupManager *>(data));
}
@ -72,7 +73,7 @@ bool JsAbilityAutoStartupManager::CheckCallerIsSystemApp()
{
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
HILOG_ERROR("Current app is not system app, not allow.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current app is not system app, not allow.");
return false;
}
return true;
@ -80,22 +81,22 @@ bool JsAbilityAutoStartupManager::CheckCallerIsSystemApp()
napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
if (info.argc < ARGC_TWO) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string type;
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], type) || type != ON_OFF_TYPE_SYSTEM) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("Current app is not system app");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current app is not system app");
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
}
@ -103,7 +104,7 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
if (jsAutoStartupCallback_ == nullptr) {
jsAutoStartupCallback_ = new (std::nothrow) JsAbilityAutoStartupCallBack(env);
if (jsAutoStartupCallback_ == nullptr) {
HILOG_ERROR("JsAutoStartupCallback_ is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "JsAutoStartupCallback_ is nullptr.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -112,7 +113,7 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
AbilityManagerClient::GetInstance()->RegisterAutoStartupSystemCallback(jsAutoStartupCallback_->AsObject());
if (ret != ERR_OK) {
jsAutoStartupCallback_ = nullptr;
HILOG_ERROR("Register auto start up listener wrong[%{public}d].", ret);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Register auto start up listener wrong[%{public}d].", ret);
if (ret == CHECK_PERMISSION_FAILED) {
ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT);
} else {
@ -128,16 +129,16 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info)
{
HILOG_DEBUG("OnUnregisterAutoStartupCallback Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "OnUnregisterAutoStartupCallback Called.");
if (info.argc < ARGC_ONE) {
HILOG_ERROR("The argument is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The argument is invalid.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string type;
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], type) || type != ON_OFF_TYPE_SYSTEM) {
HILOG_ERROR("Failed to parse type.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse type.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -148,7 +149,7 @@ napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env
}
if (jsAutoStartupCallback_ == nullptr) {
HILOG_ERROR("JsAutoStartupCallback_ is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "JsAutoStartupCallback_ is nullptr.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -173,15 +174,15 @@ napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env
napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env, NapiCallbackInfo &info)
{
HILOG_DEBUG("OnSetApplicationAutoStartup Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "OnSetApplicationAutoStartup Called.");
if (info.argc < ARGC_ONE) {
HILOG_ERROR("The argument is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The argument is invalid.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("Current app is not system app");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current app is not system app");
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
}
@ -195,19 +196,19 @@ napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env
auto retVal = std::make_shared<int32_t>(0);
NapiAsyncTask::ExecuteCallback execute = [autoStartupInfo, ret = retVal] () {
if (ret == nullptr) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
return;
}
*ret = AbilityManagerClient::GetInstance()->SetApplicationAutoStartup(autoStartupInfo);
};
NapiAsyncTask::CompleteCallback complete = [ret = retVal](napi_env env, NapiAsyncTask &task, int32_t status) {
if (ret == nullptr) {
HILOG_ERROR("The argument is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The argument is invalid.");
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(INNER_ERR)));
return;
}
if (*ret != ERR_OK) {
HILOG_ERROR("Wrong error:%{public}d.", *ret);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Wrong error:%{public}d.", *ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(*ret)));
return;
}
@ -223,15 +224,15 @@ napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env
napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env env, NapiCallbackInfo &info)
{
HILOG_DEBUG("OnCancelApplicationAutoStartup Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "OnCancelApplicationAutoStartup Called.");
if (info.argc < ARGC_ONE) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!CheckCallerIsSystemApp()) {
HILOG_ERROR("Current app is not system app.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current app is not system app.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
}
@ -245,7 +246,7 @@ napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env
auto retVal = std::make_shared<int32_t>(0);
NapiAsyncTask::ExecuteCallback execute = [autoStartupInfo, ret = retVal] () {
if (ret == nullptr) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
return;
}
*ret = AbilityManagerClient::GetInstance()->CancelApplicationAutoStartup(autoStartupInfo);
@ -253,12 +254,12 @@ napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env
NapiAsyncTask::CompleteCallback complete = [ret = retVal](napi_env env, NapiAsyncTask &task, int32_t status) {
if (ret == nullptr) {
HILOG_ERROR("The parameter is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The parameter is invalid.");
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(INNER_ERR)));
return;
}
if (*ret != ERR_OK) {
HILOG_ERROR("Failed error:%{public}d.", *ret);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed error:%{public}d.", *ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(*ret)));
return;
}
@ -274,7 +275,7 @@ napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env
napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_env env, const NapiCallbackInfo &info)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
if (!CheckCallerIsSystemApp()) {
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
@ -284,7 +285,7 @@ napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_e
auto infoList = std::make_shared<std::vector<AutoStartupInfo>>();
NapiAsyncTask::ExecuteCallback execute = [infos = infoList, ret = retVal] () {
if (ret == nullptr || infos == nullptr) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
return;
}
*ret = AbilityManagerClient::GetInstance()->QueryAllAutoStartupApplications(*infos);
@ -293,12 +294,12 @@ napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_e
NapiAsyncTask::CompleteCallback complete = [infos = infoList, ret = retVal](
napi_env env, NapiAsyncTask &task, int32_t status) {
if (ret == nullptr || infos == nullptr) {
HILOG_ERROR("The param is invalid.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(INNER_ERR)));
return;
}
if (*ret != ERR_OK) {
HILOG_ERROR("Failed error:%{public}d.", *ret);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed error:%{public}d.", *ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(*ret)));
return;
}
@ -314,9 +315,9 @@ napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_e
napi_value JsAbilityAutoStartupManagerInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
if (env == nullptr || exportObj == nullptr) {
HILOG_ERROR("Env or exportObj nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Env or exportObj nullptr.");
return nullptr;
}
@ -333,7 +334,7 @@ napi_value JsAbilityAutoStartupManagerInit(napi_env env, napi_value exportObj)
JsAbilityAutoStartupManager::CancelApplicationAutoStartup);
BindNativeFunction(env, exportObj, "queryAllAutoStartupApplications", moduleName,
JsAbilityAutoStartupManager::QueryAllAutoStartupApplications);
HILOG_DEBUG("End.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "End.");
return CreateJsUndefined(env);
}
} // namespace AbilityRuntime

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -14,6 +14,7 @@
*/
#include "ability_window_configuration.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "launch_param.h"
#include "mission_info.h"
@ -31,7 +32,7 @@ enum class MemoryLevel {
static napi_status SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_status status;
napi_value itemName;
napi_value itemValue;
@ -42,13 +43,13 @@ static napi_status SetEnumItem(napi_env env, napi_value object, const char* name
NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemName, itemValue), status);
NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemValue, itemName), status);
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return napi_ok;
}
static napi_value InitLaunchReasonObject(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
@ -61,13 +62,13 @@ static napi_value InitLaunchReasonObject(napi_env env)
NAPI_CALL(env, SetEnumItem(env, object, "AUTO_STARTUP", LAUNCHREASON_AUTO_STARTUP));
NAPI_CALL(env, SetEnumItem(env, object, "INSIGHT_INTENT", LAUNCHREASON_INSIGHT_INTENT));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
static napi_value InitLastExitReasonObject(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
@ -81,13 +82,13 @@ static napi_value InitLastExitReasonObject(napi_env env)
NAPI_CALL(env, SetEnumItem(env, object, "RESOURCE_CONTROL", LASTEXITREASON_RESOURCE_CONTROL));
NAPI_CALL(env, SetEnumItem(env, object, "UPGRADE", LASTEXITREASON_UPGRADE));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
static napi_value InitOnContinueResultObject(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
@ -95,7 +96,7 @@ static napi_value InitOnContinueResultObject(napi_env env)
NAPI_CALL(env, SetEnumItem(env, object, "REJECT", ONCONTINUE_REJECT));
NAPI_CALL(env, SetEnumItem(env, object, "MISMATCH", ONCONTINUE_MISMATCH));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
@ -112,7 +113,7 @@ static napi_value InitContinueStateObject(napi_env env)
static napi_value InitWindowModeObject(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
@ -122,14 +123,14 @@ static napi_value InitWindowModeObject(napi_env env)
NAPI_CALL(env, SetEnumItem(env, object, "WINDOW_MODE_SPLIT_SECONDARY", MULTI_WINDOW_DISPLAY_SECONDARY));
NAPI_CALL(env, SetEnumItem(env, object, "WINDOW_MODE_FLOATING", MULTI_WINDOW_DISPLAY_FLOATING));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
// AbilityConstant.OnSaveResult
static napi_value InitOnSaveResultEnum(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
NAPI_CALL(env, SetEnumItem(env, object, "ALL_AGREE", AppExecFwk::ALL_AGREE));
@ -138,25 +139,25 @@ static napi_value InitOnSaveResultEnum(napi_env env)
NAPI_CALL(env, SetEnumItem(env, object, "RECOVERY_AGREE", AppExecFwk::RECOVERY_AGREE));
NAPI_CALL(env, SetEnumItem(env, object, "RECOVERY_REJECT", AppExecFwk::RECOVERY_REJECT));
NAPI_CALL(env, SetEnumItem(env, object, "ALL_REJECT", AppExecFwk::ALL_REJECT));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
// AbilityConstant.StateType
static napi_value InitStateTypeEnum(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
NAPI_CALL(env, SetEnumItem(env, object, "CONTINUATION", AppExecFwk::CONTINUATION));
NAPI_CALL(env, SetEnumItem(env, object, "APP_RECOVERY", AppExecFwk::APP_RECOVERY));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
static napi_value InitMemoryLevelObject(napi_env env)
{
HILOG_DEBUG("start");
TAG_LOGD(AAFwkTag::JSNAPI, "start");
napi_value object;
NAPI_CALL(env, napi_create_object(env, &object));
@ -167,7 +168,7 @@ static napi_value InitMemoryLevelObject(napi_env env)
NAPI_CALL(env, SetEnumItem(env, object, "MEMORY_LEVEL_CRITICAL",
static_cast<int>(MemoryLevel::MEMORY_LEVEL_CRITICAL)));
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::JSNAPI, "end");
return object;
}
@ -178,49 +179,49 @@ static napi_value AbilityConstantInit(napi_env env, napi_value exports)
{
napi_value launchReason = InitLaunchReasonObject(env);
if (launchReason == nullptr) {
HILOG_ERROR("error to create launch reason object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create launch reason object");
return nullptr;
}
napi_value lastExitReason = InitLastExitReasonObject(env);
if (lastExitReason == nullptr) {
HILOG_ERROR("error to create last exit reason object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create last exit reason object");
return nullptr;
}
napi_value onContinueResult = InitOnContinueResultObject(env);
if (onContinueResult == nullptr) {
HILOG_ERROR("error to create onContinue result object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create onContinue result object");
return nullptr;
}
napi_value continueState = InitContinueStateObject(env);
if (continueState == nullptr) {
HILOG_ERROR("error to create continue state object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create continue state object");
return nullptr;
}
napi_value windowMode = InitWindowModeObject(env);
if (windowMode == nullptr) {
HILOG_ERROR("error to create window mode object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create window mode object");
return nullptr;
}
napi_value memoryLevel = InitMemoryLevelObject(env);
if (memoryLevel == nullptr) {
HILOG_ERROR("error to create memory level object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create memory level object");
return nullptr;
}
napi_value stateType = InitStateTypeEnum(env);
if (stateType == nullptr) {
HILOG_ERROR("error to create state type object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create state type object");
return nullptr;
}
napi_value saveResult = InitOnSaveResultEnum(env);
if (saveResult == nullptr) {
HILOG_ERROR("error to create save result object");
TAG_LOGE(AAFwkTag::JSNAPI, "error to create save result object");
return nullptr;
}
@ -236,7 +237,7 @@ static napi_value AbilityConstantInit(napi_env env, napi_value exports)
};
napi_status status = napi_define_properties(env, exports, sizeof(exportObjs) / sizeof(exportObjs[0]), exportObjs);
if (status != napi_ok) {
HILOG_ERROR("error to define properties for exports");
TAG_LOGE(AAFwkTag::JSNAPI, "error to define properties for exports");
return nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -15,6 +15,7 @@
#include "js_ability_foreground_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
@ -27,9 +28,9 @@ JSAbilityForegroundStateObserver::JSAbilityForegroundStateObserver(napi_env env)
void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
if (!valid_) {
HILOG_ERROR("The app manager may has destoryed.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "The app manager may has destoryed.");
return;
}
wptr<JSAbilityForegroundStateObserver> jsObserver = this;
@ -37,7 +38,7 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD
[jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAbilityForegroundStateObserver> jsObserverSptr = jsObserver.promote();
if (jsObserverSptr == nullptr) {
HILOG_ERROR("Js Observer Sptr is nullptr.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Js Observer Sptr is nullptr.");
return;
}
jsObserverSptr->HandleOnAbilityStateChanged(abilityStateData);
@ -49,7 +50,7 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD
void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
std::lock_guard<std::mutex> lock(mutexlock);
for (auto &item : jsObserverObjectSet_) {
if (item == nullptr) {
@ -64,35 +65,35 @@ void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const Ability
void JSAbilityForegroundStateObserver::CallJsFunction(
const napi_value &value, const char *methodName, const napi_value *argv, const size_t argc)
{
HILOG_DEBUG("Begin.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Begin.");
if (value == nullptr) {
HILOG_ERROR("Value is nullptr.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Value is nullptr.");
return;
}
napi_value method = nullptr;
napi_get_named_property(env_, value, methodName, &method);
if (method == nullptr) {
HILOG_ERROR("Get name from object Failed.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Get name from object Failed.");
return;
}
napi_value callResult = nullptr;
napi_status status = napi_call_function(env_, value, method, argc, argv, &callResult);
if (status != napi_ok) {
HILOG_ERROR("Call Js Function failed %{public}d.", status);
TAG_LOGE(AAFwkTag::ABILITYMGR, "Call Js Function failed %{public}d.", status);
}
HILOG_DEBUG("End.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "End.");
}
bool JSAbilityForegroundStateObserver::IsObserverObjectExsit(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null.");
return false;
}
if (GetObserverObject(jsObserverObject) == nullptr) {
HILOG_DEBUG("Observer is not exists.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Observer is not exists.");
return false;
}
return true;
@ -101,12 +102,12 @@ bool JSAbilityForegroundStateObserver::IsObserverObjectExsit(const napi_value &j
void JSAbilityForegroundStateObserver::AddJsObserverObject(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null.");
return;
}
if (IsObserverObjectExsit(jsObserverObject)) {
HILOG_DEBUG("Observer is exists.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Observer is exists.");
return;
}
napi_ref ref = nullptr;
@ -118,7 +119,7 @@ void JSAbilityForegroundStateObserver::AddJsObserverObject(const napi_value &jsO
void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null.");
return;
}
@ -140,19 +141,19 @@ void JSAbilityForegroundStateObserver::RemoveAllJsObserverObject()
std::shared_ptr<NativeReference> JSAbilityForegroundStateObserver::GetObserverObject(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null.");
return nullptr;
}
std::lock_guard<std::mutex> lock(mutexlock);
for (auto &observer : jsObserverObjectSet_) {
if (observer == nullptr) {
HILOG_ERROR("Invalid observer.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid observer.");
continue;
}
napi_value value = observer->GetNapiValue();
if (value == nullptr) {
HILOG_ERROR("Failed to get object.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to get object.");
continue;
}

View File

@ -25,6 +25,7 @@
#include "app_mgr_interface.h"
#include "errors.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
@ -70,7 +71,7 @@ public:
static void Finalizer(napi_env env, void* data, void* hint)
{
HILOG_INFO("JsAbilityManager::Finalizer is called");
TAG_LOGI(AAFwkTag::ABILITYMGR, "JsAbilityManager::Finalizer is called");
std::unique_ptr<JsAbilityManager>(static_cast<JsAbilityManager*>(data));
}
@ -143,14 +144,14 @@ private:
napi_value OnOn(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
if (argc < ARGC_TWO) {
HILOG_ERROR("Not enough params.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
HILOG_ERROR("Invalid param.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid param.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -168,7 +169,7 @@ private:
if (observerForeground_ == nullptr) {
observerForeground_ = new (std::nothrow) JSAbilityForegroundStateObserver(env);
if (observerForeground_ == nullptr) {
HILOG_ERROR("observerForeground_ is nullptr.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "observerForeground_ is nullptr.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -177,7 +178,7 @@ private:
if (observerForeground_->IsEmpty()) {
int32_t ret = GetAppManagerInstance()->RegisterAbilityForegroundStateObserver(observerForeground_);
if (ret != NO_ERROR) {
HILOG_ERROR("Failed error: %{public}d.", ret);
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed error: %{public}d.", ret);
ThrowErrorByNativeErr(env, ret);
return CreateJsUndefined(env);
}
@ -189,14 +190,14 @@ private:
napi_value OnOff(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
if (argc < ARGC_ONE) {
HILOG_ERROR("Not enough params when off.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (argc == ARGC_TWO && !AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
HILOG_ERROR("Invalid param.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid param.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -213,12 +214,12 @@ private:
const std::regex regexJsperf(R"(^\d*)");
std::match_results<std::string::const_iterator> matchResults;
if (numStr.empty() || !std::regex_match(numStr, matchResults, regexJsperf)) {
HILOG_ERROR("Number parsing error, %{public}s.", numStr.c_str());
TAG_LOGE(AAFwkTag::ABILITYMGR, "Number parsing error, %{public}s.", numStr.c_str());
return false;
}
if (MAX_UINT64_VALUE.length() < numStr.length() ||
(MAX_UINT64_VALUE.length() == numStr.length() && MAX_UINT64_VALUE.compare(numStr) < 0)) {
HILOG_ERROR("Number parsing error, %{public}s.", numStr.c_str());
TAG_LOGE(AAFwkTag::ABILITYMGR, "Number parsing error, %{public}s.", numStr.c_str());
return false;
}
return true;
@ -226,28 +227,28 @@ private:
napi_value OnNotifyDebugAssertResult(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
if (argc < ARGC_TWO) {
HILOG_ERROR("Not enough params when off.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string assertSessionStr;
if (!ConvertFromJsValue(env, argv[INDEX_ZERO], assertSessionStr) || !CheckIsNumString(assertSessionStr)) {
HILOG_ERROR("Convert session id error.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert session id error.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
uint64_t assertSessionId = std::stoull(assertSessionStr);
if (assertSessionId == 0) {
HILOG_ERROR("Convert session id failed.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert session id failed.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
int32_t userStatus;
if (!ConvertFromJsValue(env, argv[INDEX_ONE], userStatus)) {
HILOG_ERROR("Convert status failed.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Convert status failed.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -256,13 +257,13 @@ private:
[assertSessionId, userStatus](napi_env env, NapiAsyncTask &task, int32_t status) {
auto amsClient = AbilityManagerClient::GetInstance();
if (amsClient == nullptr) {
HILOG_ERROR("Ability manager service instance is nullptr.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Ability manager service instance is nullptr.");
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(AAFwk::INNER_ERR)));
return;
}
auto ret = amsClient->NotifyDebugAssertResult(assertSessionId, static_cast<AAFwk::UserStatus>(userStatus));
if (ret != ERR_OK) {
HILOG_ERROR("Notify user action result failed, error is %{public}d.", ret);
TAG_LOGE(AAFwkTag::ABILITYMGR, "Notify user action result failed, error is %{public}d.", ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
return;
}
@ -278,7 +279,7 @@ private:
napi_value OnOffAbilityForeground(napi_env env, size_t argc, napi_value *argv)
{
if (observerForeground_ == nullptr) {
HILOG_ERROR("Observer is nullptr.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is nullptr.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -291,7 +292,7 @@ private:
if (observerForeground_->IsEmpty()) {
int32_t ret = GetAppManagerInstance()->UnregisterAbilityForegroundStateObserver(observerForeground_);
if (ret != NO_ERROR) {
HILOG_ERROR("Failed error: %{public}d.", ret);
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed error: %{public}d.", ret);
ThrowErrorByNativeErr(env, ret);
return CreateJsUndefined(env);
}
@ -301,7 +302,7 @@ private:
napi_value OnGetAbilityRunningInfos(napi_env env, NapiCallbackInfo& info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s is called", __FUNCTION__);
NapiAsyncTask::CompleteCallback complete =
[](napi_env env, NapiAsyncTask &task, int32_t status) {
std::vector<AAFwk::AbilityRunningInfo> infos;
@ -328,9 +329,9 @@ private:
napi_value OnGetExtensionRunningInfos(napi_env env, NapiCallbackInfo& info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s is called", __FUNCTION__);
if (info.argc == 0) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params");
#ifdef ENABLE_ERRCODE
ThrowTooFewParametersError(env);
#endif
@ -371,12 +372,12 @@ private:
napi_value OnUpdateConfiguration(napi_env env, NapiCallbackInfo& info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s is called", __FUNCTION__);
NapiAsyncTask::CompleteCallback complete;
do {
if (info.argc == 0) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params");
#ifdef ENABLE_ERRCODE
ThrowTooFewParametersError(env);
#else
@ -425,11 +426,11 @@ private:
napi_value OnGetTopAbility(napi_env env, NapiCallbackInfo& info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s is called", __FUNCTION__);
#ifdef ENABLE_ERRCODE
auto selfToken = IPCSkeleton::GetSelfTokenID();
if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) {
HILOG_ERROR("This application is not system-app, can not use system-api");
TAG_LOGE(AAFwkTag::ABILITYMGR, "This application is not system-app, can not use system-api");
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
}
@ -453,7 +454,7 @@ private:
napi_value OnAcquireShareData(napi_env env, NapiCallbackInfo& info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s is called", __FUNCTION__);
if (info.argc < ARGC_ONE) {
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
@ -494,20 +495,20 @@ private:
napi_value OnNotifySaveAsResult(napi_env env, NapiCallbackInfo& info)
{
HILOG_INFO("called");
TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
NapiAsyncTask::CompleteCallback complete;
NapiAsyncTask::ExecuteCallback execute;
do {
if (info.argc < ARGC_TWO) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params");
ThrowTooFewParametersError(env);
break;
}
int reqCode = 0;
if (!ConvertFromJsValue(env, info.argv[1], reqCode)) {
HILOG_ERROR("Get requestCode param error");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Get requestCode param error");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
break;
}
@ -515,7 +516,7 @@ private:
AppExecFwk::Want want;
int resultCode = ERR_OK;
if (!AppExecFwk::UnWrapAbilityResult(env, info.argv[0], resultCode, want)) {
HILOG_ERROR("Unrwrap abilityResult param error");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Unrwrap abilityResult param error");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
break;
}
@ -543,14 +544,14 @@ private:
napi_value OnGetForegroundUIAbilities(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
NapiAsyncTask::CompleteCallback complete = [](napi_env env, NapiAsyncTask &task, int32_t status) {
std::vector<AppExecFwk::AbilityStateData> list;
int32_t ret = AbilityManagerClient::GetInstance()->GetForegroundUIAbilities(list);
if (ret == ERR_OK) {
task.ResolveWithNoError(env, CreateJsAbilityStateDataArray(env, list));
} else {
HILOG_ERROR("Failed error: %{public}d.", ret);
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed error: %{public}d.", ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
};
@ -564,9 +565,9 @@ private:
napi_value OnIsEmbeddedOpenAllowed(napi_env env, NapiCallbackInfo& info)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
if (info.argc < ARGC_TWO) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
@ -574,26 +575,26 @@ private:
bool stageMode = false;
napi_status status = OHOS::AbilityRuntime::IsStageContext(env, info.argv[0], stageMode);
if (status != napi_ok || !stageMode) {
HILOG_ERROR("it is not a stage mode");
TAG_LOGE(AAFwkTag::ABILITYMGR, "it is not a stage mode");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
auto context = OHOS::AbilityRuntime::GetStageModeContext(env, info.argv[0]);
if (context == nullptr) {
HILOG_ERROR("get context failed");
TAG_LOGE(AAFwkTag::ABILITYMGR, "get context failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
auto uiAbilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
if (uiAbilityContext == nullptr) {
HILOG_ERROR("convert to UIAbility context failed");
TAG_LOGE(AAFwkTag::ABILITYMGR, "convert to UIAbility context failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
std::string appId;
if (!ConvertFromJsValue(env, info.argv[1], appId)) {
HILOG_ERROR("OnOpenAtomicService, parse appId failed.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "OnOpenAtomicService, parse appId failed.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -616,7 +617,7 @@ private:
napi_value JsAbilityManagerInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
std::unique_ptr<JsAbilityManager> jsAbilityManager = std::make_unique<JsAbilityManager>();
napi_wrap(env, exportObj, jsAbilityManager.release(), JsAbilityManager::Finalizer, nullptr, nullptr);
@ -640,7 +641,7 @@ napi_value JsAbilityManagerInit(napi_env env, napi_value exportObj)
BindNativeFunction(
env, exportObj, "notifyDebugAssertResult", moduleName, JsAbilityManager::NotifyDebugAssertResult);
BindNativeFunction(env, exportObj, "isEmbeddedOpenAllowed", moduleName, JsAbilityManager::IsEmbeddedOpenAllowed);
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::ABILITYMGR, "end");
return CreateJsUndefined(env);
}
} // namespace AbilityRuntime

View File

@ -18,6 +18,7 @@
#include <cstdint>
#include "ability_state.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
@ -103,7 +104,7 @@ napi_value CreateJsExtensionRunningInfo(napi_env env, const AAFwk::ExtensionRunn
napi_value AbilityStateInit(napi_env env)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
@ -118,7 +119,7 @@ napi_value AbilityStateInit(napi_env env)
napi_value UserStatusInit(napi_env env)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
@ -131,11 +132,11 @@ napi_value UserStatusInit(napi_env env)
napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("ObjValue nullptr.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "ObjValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, abilityStateData.bundleName));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -20,6 +20,7 @@
#include "ability_manager_interface.h"
#include "app_mgr_interface.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
@ -54,7 +55,7 @@ public:
static void Finalizer(napi_env env, void* data, void* hint)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
std::unique_ptr<JsAppManager>(static_cast<JsAppManager*>(data));
}
@ -80,19 +81,19 @@ public:
static napi_value IsRunningInStabilityTest(napi_env env, napi_callback_info info)
{
HILOG_DEBUG("IsRunningInStabilityTest start.");
TAG_LOGD(AAFwkTag::APPMGR, "IsRunningInStabilityTest start.");
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnIsRunningInStabilityTest);
}
static napi_value KillProcessWithAccount(napi_env env, napi_callback_info info)
{
HILOG_DEBUG("KillProcessWithAccount start.");
TAG_LOGD(AAFwkTag::APPMGR, "KillProcessWithAccount start.");
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnKillProcessWithAccount);
}
static napi_value KillProcessesByBundleName(napi_env env, napi_callback_info info)
{
HILOG_DEBUG("KillProcessesByBundleName start.");
TAG_LOGD(AAFwkTag::APPMGR, "KillProcessesByBundleName start.");
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnkillProcessByBundleName);
}
@ -117,14 +118,14 @@ private:
napi_value OnRegisterApplicationStateObserver(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
// only support 1 or 2 params
if (argc != ARGC_ONE && argc != ARGC_TWO) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
return CreateJsUndefined(env);
}
if (appManager_ == nullptr) {
HILOG_ERROR("appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
return CreateJsUndefined(env);
}
static int64_t serialNumber = 0;
@ -138,7 +139,7 @@ private:
}
int32_t ret = appManager_->RegisterApplicationStateObserver(observer_, bundleNameList);
if (ret == 0) {
HILOG_DEBUG("success.");
TAG_LOGD(AAFwkTag::APPMGR, "success.");
int64_t observerId = serialNumber;
observer_->AddJsObserverObject(observerId, argv[INDEX_ZERO]);
if (serialNumber < INT32_MAX) {
@ -148,20 +149,20 @@ private:
}
return CreateJsValue(env, observerId);
} else {
HILOG_ERROR("failed error:%{public}d.", ret);
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d.", ret);
return CreateJsUndefined(env);
}
}
napi_value OnUnregisterApplicationStateObserver(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
int64_t observerId = -1;
// only support 1 or 2 params
if (argc != ARGC_ONE && argc != ARGC_TWO) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
} else {
// unwrap connectId
@ -169,9 +170,9 @@ private:
bool isExist = observer_->FindObserverByObserverId(observerId);
if (isExist) {
// match id
HILOG_DEBUG("find observer exist observer:%{public}d", static_cast<int32_t>(observerId));
TAG_LOGD(AAFwkTag::APPMGR, "find observer exist observer:%{public}d", static_cast<int32_t>(observerId));
} else {
HILOG_DEBUG("not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
TAG_LOGD(AAFwkTag::APPMGR, "not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
errCode = ERR_NOT_OK;
}
}
@ -184,16 +185,16 @@ private:
return;
}
if (observer == nullptr || appManager == nullptr) {
HILOG_ERROR("observer or appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr"));
return;
}
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
task.Resolve(env, CreateJsUndefined(env));
HILOG_DEBUG("success size:%{public}zu", observer->GetJsObserverMapSize());
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize());
} else {
HILOG_ERROR("failed error:%{public}d", ret);
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed"));
}
};
@ -207,12 +208,12 @@ private:
napi_value OnGetForegroundApplications(napi_env env, const size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
// only support 0 or 1 params
if (argc != ARGC_ZERO && argc != ARGC_ONE) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
@ -222,17 +223,17 @@ private:
return;
}
if (appManager == nullptr) {
HILOG_ERROR("appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
return;
}
std::vector<AppExecFwk::AppStateData> list;
int32_t ret = appManager->GetForegroundApplications(list);
if (ret == 0) {
HILOG_DEBUG("success.");
TAG_LOGD(AAFwkTag::APPMGR, "success.");
task.Resolve(env, CreateJsAppStateDataArray(env, list));
} else {
HILOG_ERROR("failed error:%{public}d", ret);
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed"));
}
};
@ -246,12 +247,12 @@ private:
napi_value OnGetProcessRunningInfos(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
// only support 0 or 1 params
if (argc != ARGC_ZERO && argc != ARGC_ONE) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
@ -278,12 +279,12 @@ private:
napi_value OnIsRunningInStabilityTest(napi_env env, const size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
// only support 0 or 1 params
if (argc != ARGC_ZERO && argc != ARGC_ONE) {
HILOG_ERROR("Not enough arguments");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough arguments");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
@ -293,12 +294,12 @@ private:
return;
}
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
HILOG_INFO("result:%{public}d", ret);
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.Resolve(env, CreateJsValue(env, ret));
};
@ -311,22 +312,22 @@ private:
napi_value OnkillProcessByBundleName(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("OnkillProcessByBundleName called");
TAG_LOGD(AAFwkTag::APPMGR, "OnkillProcessByBundleName called");
int32_t errCode = 0;
std::string bundleName;
// only support 1 or 2 params
if (argc != ARGC_ONE && argc != ARGC_TWO) {
HILOG_ERROR("Not enough arguments");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough arguments");
errCode = ERR_NOT_OK;
} else {
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("get bundleName failed!");
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName failed!");
errCode = ERR_NOT_OK;
}
}
HILOG_INFO("kill process [%{public}s]", bundleName.c_str());
TAG_LOGI(AAFwkTag::APPMGR, "kill process [%{public}s]", bundleName.c_str());
NapiAsyncTask::CompleteCallback complete =
[bundleName, abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task,
int32_t status) {
@ -335,7 +336,7 @@ private:
return;
}
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager null");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
@ -356,20 +357,20 @@ private:
napi_value OnClearUpApplicationData(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
std::string bundleName;
// only support 1 or 2 params
if (argc != ARGC_ONE && argc != ARGC_TWO) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
} else {
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("get bundleName failed!");
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName failed!");
errCode = ERR_NOT_OK;
} else {
HILOG_INFO("kill process [%{public}s]", bundleName.c_str());
TAG_LOGI(AAFwkTag::APPMGR, "kill process [%{public}s]", bundleName.c_str());
}
}
@ -381,7 +382,7 @@ private:
return;
}
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
@ -402,22 +403,22 @@ private:
napi_value OnKillProcessWithAccount(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
int32_t accountId = -1;
std::string bundleName;
// only support 2 or 3 params
if (argc != ARGC_TWO && argc != ARGC_THREE) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
} else {
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("Parse bundleName failed");
TAG_LOGE(AAFwkTag::APPMGR, "Parse bundleName failed");
errCode = ERR_NOT_OK;
}
if (!ConvertFromJsValue(env, argv[1], accountId)) {
HILOG_ERROR("Parse userId failed");
TAG_LOGE(AAFwkTag::APPMGR, "Parse userId failed");
errCode = ERR_NOT_OK;
}
}
@ -433,7 +434,7 @@ private:
if (ret == 0) {
task.Resolve(env, CreateJsUndefined(env));
} else {
HILOG_DEBUG("failed error:%{public}d", ret);
TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, ret, "Kill processes failed."));
}
};
@ -443,7 +444,7 @@ private:
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessWithAccount",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::APPMGR, "end");
}
napi_value OnGetAppMemorySize(napi_env env, const size_t argc, napi_value* argv)
@ -452,7 +453,7 @@ private:
// only support 0 or 1 params
if (argc != ARGC_ZERO && argc != ARGC_ONE) {
HILOG_ERROR("Insufficient params");
TAG_LOGE(AAFwkTag::APPMGR, "Insufficient params");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
@ -462,12 +463,12 @@ private:
return;
}
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
int32_t memorySize = abilityManager->GetAppMemorySize();
HILOG_INFO("memorySize:%{public}d", memorySize);
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
task.Resolve(env, CreateJsValue(env, memorySize));
};
@ -484,7 +485,7 @@ private:
// only support 0 or 1 params
if (argc != ARGC_ZERO && argc != ARGC_ONE) {
HILOG_ERROR("Not enough parameters");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough parameters");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
@ -494,12 +495,12 @@ private:
return;
}
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
bool ret = abilityManager->IsRamConstrainedDevice();
HILOG_INFO("result:%{public}d", ret);
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.Resolve(env, CreateJsValue(env, ret));
};
@ -531,9 +532,9 @@ OHOS::sptr<OHOS::AAFwk::IAbilityManager> GetAbilityManagerInstance()
napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("JsAppManagerInit start");
TAG_LOGD(AAFwkTag::APPMGR, "JsAppManagerInit start");
if (env == nullptr || exportObj == nullptr) {
HILOG_WARN("env or exportObj null");
TAG_LOGW(AAFwkTag::APPMGR, "env or exportObj null");
return nullptr;
}
@ -564,7 +565,7 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
JsAppManager::GetAppMemorySize);
BindNativeFunction(env, exportObj, "isRamConstrainedDevice", moduleName,
JsAppManager::IsRamConstrainedDevice);
HILOG_DEBUG("JsAppManagerInit end");
TAG_LOGD(AAFwkTag::APPMGR, "JsAppManagerInit end");
return CreateJsUndefined(env);
}
} // namespace AbilityRuntime

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -17,6 +17,7 @@
#include <cstdint>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "iapplication_state_observer.h"
#include "js_runtime.h"
@ -26,27 +27,27 @@ namespace OHOS {
namespace AbilityRuntime {
napi_value CreateJsAppStateData(napi_env env, const AppStateData &appStateData)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::APPMGR, "called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, appStateData.bundleName));
napi_set_named_property(env, object, "uid", CreateJsValue(env, appStateData.uid));
napi_set_named_property(env, object, "state", CreateJsValue(env, appStateData.state));
HILOG_INFO("end.");
TAG_LOGI(AAFwkTag::APPMGR, "end.");
return object;
}
napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::APPMGR, "called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, abilityStateData.bundleName));
@ -58,17 +59,17 @@ napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilit
napi_set_named_property(env, object, "abilityType", CreateJsValue(env, abilityStateData.abilityType));
napi_set_named_property(env, object, "isAtomicService", CreateJsValue(env, abilityStateData.isAtomicService));
HILOG_DEBUG("end.");
TAG_LOGD(AAFwkTag::APPMGR, "end.");
return object;
}
napi_value CreateJsProcessData(napi_env env, const ProcessData &processData)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::APPMGR, "called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, processData.bundleName));
@ -77,7 +78,7 @@ napi_value CreateJsProcessData(napi_env env, const ProcessData &processData)
napi_set_named_property(env, object, "state", CreateJsValue(env, processData.state));
napi_set_named_property(env, object, "isContinuousTask", CreateJsValue(env, processData.isContinuousTask));
napi_set_named_property(env, object, "isKeepAlive", CreateJsValue(env, processData.isKeepAlive));
HILOG_DEBUG("end.");
TAG_LOGD(AAFwkTag::APPMGR, "end.");
return object;
}
@ -108,7 +109,7 @@ napi_value CreateJsProcessRunningInfo(napi_env env, const RunningProcessInfo &in
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "processName", CreateJsValue(env, info.processName_));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -14,6 +14,7 @@
*/
#include "js_app_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
#include "js_app_manager_utils.h"
@ -33,7 +34,7 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
([jsObserver, appStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr null");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr null");
return;
}
jsObserverSptr->HandleOnForegroundApplicationChanged(appStateData);
@ -46,7 +47,8 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData)
{
HILOG_INFO("HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d.",
TAG_LOGI(AAFwkTag::APPMGR,
"HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d.",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
@ -63,7 +65,7 @@ void JSAppStateObserver::OnAbilityStateChanged(const AbilityStateData &abilitySt
([jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr null");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr null");
return;
}
jsObserverSptr->HandleOnAbilityStateChanged(abilityStateData);
@ -76,7 +78,7 @@ void JSAppStateObserver::OnAbilityStateChanged(const AbilityStateData &abilitySt
void JSAppStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -92,7 +94,7 @@ void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &ability
([jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr");
return;
}
jsObserverSptr->HandleOnExtensionStateChanged(abilityStateData);
@ -105,7 +107,7 @@ void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &ability
void JSAppStateObserver::HandleOnExtensionStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -121,7 +123,7 @@ void JSAppStateObserver::OnProcessCreated(const ProcessData &processData)
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr");
return;
}
jsObserverSptr->HandleOnProcessCreated(processData);
@ -134,7 +136,7 @@ void JSAppStateObserver::OnProcessCreated(const ProcessData &processData)
void JSAppStateObserver::HandleOnProcessCreated(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -150,7 +152,7 @@ void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr");
return;
}
jsObserverSptr->HandleOnProcessStateChanged(processData);
@ -163,7 +165,7 @@ void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
void JSAppStateObserver::HandleOnProcessStateChanged(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -179,7 +181,7 @@ void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr null");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr null");
return;
}
jsObserverSptr->HandleOnProcessDied(processData);
@ -192,7 +194,7 @@ void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
void JSAppStateObserver::HandleOnProcessDied(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -204,26 +206,26 @@ void JSAppStateObserver::HandleOnProcessDied(const ProcessData &processData)
void JSAppStateObserver::CallJsFunction(
napi_value value, const char *methodName, napi_value* argv, size_t argc)
{
HILOG_DEBUG("CallJsFunction start, method:%{public}s", methodName);
TAG_LOGD(AAFwkTag::APPMGR, "CallJsFunction start, method:%{public}s", methodName);
if (value == nullptr) {
HILOG_ERROR("Failed to get object");
TAG_LOGE(AAFwkTag::APPMGR, "Failed to get object");
return;
}
napi_value method = nullptr;
napi_get_named_property(env_, value, methodName, &method);
if (method == nullptr) {
HILOG_ERROR("Wrong to get from object");
TAG_LOGE(AAFwkTag::APPMGR, "Wrong to get from object");
return;
}
napi_value callResult = nullptr;
napi_call_function(env_, value, method, argc, argv, &callResult);
HILOG_DEBUG("CallJsFunction finish");
TAG_LOGD(AAFwkTag::APPMGR, "CallJsFunction finish");
}
void JSAppStateObserver::AddJsObserverObject(const int32_t observerId, napi_value jsObserverObject)
{
HILOG_DEBUG("AddJsObserverObject start.");
TAG_LOGD(AAFwkTag::APPMGR, "AddJsObserverObject start.");
napi_ref ref = nullptr;
napi_create_reference(env_, jsObserverObject, 1, &ref);
jsObserverObjectMap_.emplace(observerId, std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(ref)));
@ -231,7 +233,7 @@ void JSAppStateObserver::AddJsObserverObject(const int32_t observerId, napi_valu
bool JSAppStateObserver::RemoveJsObserverObject(const int32_t observerId)
{
HILOG_DEBUG("RemoveJsObserverObject start.");
TAG_LOGD(AAFwkTag::APPMGR, "RemoveJsObserverObject start.");
bool result = (jsObserverObjectMap_.erase(observerId) == 1);
return result;
}
@ -245,7 +247,7 @@ bool JSAppStateObserver::FindObserverByObserverId(const int32_t observerId)
size_t JSAppStateObserver::GetJsObserverMapSize()
{
HILOG_DEBUG("GetJsObserverMapSize start");
TAG_LOGD(AAFwkTag::APPMGR, "GetJsObserverMapSize start");
size_t length = jsObserverObjectMap_.size();
return length;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -21,6 +21,7 @@
#include "ability_business_error.h"
#include "application_data_manager.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_error_observer.h"
#include "js_error_utils.h"
@ -141,7 +142,7 @@ public:
static void Finalizer(napi_env env, void* data, void* hint)
{
HILOG_INFO("JsErrorManager Finalizer is called");
TAG_LOGI(AAFwkTag::JSNAPI, "JsErrorManager Finalizer is called");
std::unique_ptr<JsErrorManager>(static_cast<JsErrorManager*>(data));
ClearReference(env);
}
@ -195,14 +196,14 @@ public:
private:
napi_value OnOn(napi_env env, const size_t argc, napi_value* argv)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::JSNAPI, "called.");
std::string type = ParseParamType(env, argc, argv);
if (type == ON_OFF_TYPE_SYNC) {
return OnOnNew(env, argc, argv);
}
if (type == ON_OFF_TYPE_SYNC_LOOP) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
HILOG_ERROR("LoopObserver can only be set from main thread.");
TAG_LOGE(AAFwkTag::JSNAPI, "LoopObserver can only be set from main thread.");
ThrowInvaildCallerError(env);
return CreateJsUndefined(env);
}
@ -210,12 +211,12 @@ private:
}
if (type == ON_OFF_TYPE_UNHANDLED_REJECTION) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
HILOG_ERROR("UnhandledRejectionObserver can only be set from main thread.");
TAG_LOGE(AAFwkTag::JSNAPI, "UnhandledRejectionObserver can only be set from main thread.");
ThrowInvaildCallerError(env);
return CreateJsUndefined(env);
}
if (argc != ARGC_TWO) {
HILOG_ERROR("The number of params is invalid.");
TAG_LOGE(AAFwkTag::JSNAPI, "The number of params is invalid.");
ThrowInvalidNumParametersError(env);
return CreateJsUndefined(env);
}
@ -226,9 +227,9 @@ private:
napi_value OnOnOld(napi_env env, const size_t argc, napi_value* argv)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::JSNAPI, "called.");
if (argc != ARGC_TWO) {
HILOG_ERROR("The param is invalid, observers need.");
TAG_LOGE(AAFwkTag::JSNAPI, "The param is invalid, observers need.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
@ -236,7 +237,7 @@ private:
std::string type;
if (!ConvertFromJsValue(env, argv[INDEX_ZERO], type) || type != ON_OFF_TYPE) {
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
HILOG_ERROR("Parse type failed");
TAG_LOGE(AAFwkTag::JSNAPI, "Parse type failed");
return CreateJsUndefined(env);
}
int32_t observerId = serialNumber_;
@ -247,7 +248,7 @@ private:
}
if (observer_ == nullptr) {
HILOG_DEBUG("observer_ is null.");
TAG_LOGD(AAFwkTag::JSNAPI, "observer_ is null.");
// create observer
observer_ = std::make_shared<JsErrorObserver>(env);
AppExecFwk::ApplicationDataManager::GetInstance().AddErrorObserver(observer_);
@ -280,15 +281,15 @@ private:
napi_value OnOnNew(napi_env env, const size_t argc, napi_value* argv)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::JSNAPI, "called.");
if (argc < ARGC_TWO) {
HILOG_ERROR("The param is invalid, observers need.");
TAG_LOGE(AAFwkTag::JSNAPI, "The param is invalid, observers need.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!CheckTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
HILOG_ERROR("Invalid param");
TAG_LOGE(AAFwkTag::JSNAPI, "Invalid param");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -311,14 +312,14 @@ private:
napi_value OnOff(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::JSNAPI, "called.");
std::string type = ParseParamType(env, argc, argv);
if (type == ON_OFF_TYPE_SYNC) {
return OnOffNew(env, argc, argv);
}
if (type == ON_OFF_TYPE_SYNC_LOOP) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
HILOG_ERROR("LoopObserver can only be set from main thread.");
TAG_LOGE(AAFwkTag::JSNAPI, "LoopObserver can only be set from main thread.");
ThrowInvaildCallerError(env);
return CreateJsUndefined(env);
}
@ -326,12 +327,12 @@ private:
}
if (type == ON_OFF_TYPE_UNHANDLED_REJECTION) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
HILOG_ERROR("UnhandledRejectionObserver can only be unset from main thread.");
TAG_LOGE(AAFwkTag::JSNAPI, "UnhandledRejectionObserver can only be unset from main thread.");
ThrowInvaildCallerError(env);
return CreateJsUndefined(env);
}
if (argc != ARGC_TWO && argc != ARGC_ONE) {
HILOG_ERROR("The number of params is invalid.");
TAG_LOGE(AAFwkTag::JSNAPI, "The number of params is invalid.");
ThrowInvalidNumParametersError(env);
return CreateJsUndefined(env);
}
@ -342,19 +343,19 @@ private:
napi_value OnOffOld(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::JSNAPI, "called.");
int32_t observerId = -1;
if (argc != ARGC_TWO && argc != ARGC_THREE) {
ThrowTooFewParametersError(env);
HILOG_ERROR("unregister errorObserver error, not enough params.");
TAG_LOGE(AAFwkTag::JSNAPI, "unregister errorObserver error, not enough params.");
} else {
napi_get_value_int32(env, argv[INDEX_ONE], &observerId);
HILOG_INFO("unregister errorObserver called, observer:%{public}d", observerId);
TAG_LOGI(AAFwkTag::JSNAPI, "unregister errorObserver called, observer:%{public}d", observerId);
}
std::string type;
if (!ConvertFromJsValue(env, argv[INDEX_ZERO], type) || type != ON_OFF_TYPE) {
HILOG_ERROR("Parse type failed");
TAG_LOGE(AAFwkTag::JSNAPI, "Parse type failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -362,7 +363,7 @@ private:
NapiAsyncTask::CompleteCallback complete =
[&observer = observer_, observerId](
napi_env env, NapiAsyncTask& task, int32_t status) {
HILOG_INFO("Unregister errorObserver called.");
TAG_LOGI(AAFwkTag::JSNAPI, "Unregister errorObserver called.");
if (observerId == -1) {
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
@ -406,34 +407,34 @@ private:
return res;
}
}
HILOG_ERROR("Remove UnhandledRjectionObserver failed");
TAG_LOGE(AAFwkTag::JSNAPI, "Remove UnhandledRjectionObserver failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_OBSERVER_NOT_FOUND);
return res;
}
napi_value OnOffNew(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::JSNAPI, "called.");
if (argc < ARGC_TWO) {
ThrowTooFewParametersError(env);
HILOG_ERROR("unregister errorObserver error, not enough params.");
TAG_LOGE(AAFwkTag::JSNAPI, "unregister errorObserver error, not enough params.");
return CreateJsUndefined(env);
}
int32_t observerId = -1;
if (!ConvertFromJsValue(env, argv[INDEX_ONE], observerId)) {
HILOG_ERROR("Parse observerId failed");
TAG_LOGE(AAFwkTag::JSNAPI, "Parse observerId failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (observer_ == nullptr) {
HILOG_ERROR("observer is nullptr");
TAG_LOGE(AAFwkTag::JSNAPI, "observer is nullptr");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
if (observer_->RemoveJsObserverObject(observerId, true)) {
HILOG_DEBUG("RemoveJsObserverObject success");
TAG_LOGD(AAFwkTag::JSNAPI, "RemoveJsObserverObject success");
} else {
HILOG_ERROR("RemoveJsObserverObject failed");
TAG_LOGE(AAFwkTag::JSNAPI, "RemoveJsObserverObject failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_ID);
}
if (observer_->IsEmpty()) {
@ -446,16 +447,16 @@ private:
static void CallJsFunction(napi_env env, napi_value obj, const char* methodName,
napi_value const* argv, size_t argc)
{
HILOG_INFO("CallJsFunction begin methodName: %{public}s", methodName);
TAG_LOGI(AAFwkTag::JSNAPI, "CallJsFunction begin methodName: %{public}s", methodName);
if (obj == nullptr) {
HILOG_ERROR("Failed to get object");
TAG_LOGE(AAFwkTag::JSNAPI, "Failed to get object");
return;
}
napi_value method = nullptr;
napi_get_named_property(env, obj, methodName, &method);
if (method == nullptr) {
HILOG_ERROR("Failed to get method");
TAG_LOGE(AAFwkTag::JSNAPI, "Failed to get method");
return;
}
napi_value callResult = nullptr;
@ -467,15 +468,15 @@ private:
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
([number](napi_env env, NapiAsyncTask &task, int32_t status) {
if (loopObserver_ == nullptr) {
HILOG_ERROR("CallbackTimeout: loopObserver_ is null.");
TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: loopObserver_ is null.");
return;
}
if (loopObserver_->env == nullptr) {
HILOG_ERROR("CallbackTimeout: env is null.");
TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: env is null.");
return;
}
if (loopObserver_->observerObject == nullptr) {
HILOG_ERROR("CallbackTimeout: observerObject is null.");
TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: observerObject is null.");
return;
}
napi_value jsValue[] = { CreateJsValue(loopObserver_->env, number) };
@ -493,28 +494,28 @@ private:
napi_value OnSetLoopWatch(napi_env env, size_t argc, napi_value* argv)
{
if (argc != ARGC_THREE) {
HILOG_ERROR("OnSetLoopWatch: Not enough params.");
TAG_LOGE(AAFwkTag::JSNAPI, "OnSetLoopWatch: Not enough params.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!CheckTypeForNapiValue(env, argv[INDEX_ONE], napi_number)) {
HILOG_ERROR("OnSetLoopWatch: Invalid param");
TAG_LOGE(AAFwkTag::JSNAPI, "OnSetLoopWatch: Invalid param");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (!CheckTypeForNapiValue(env, argv[INDEX_TWO], napi_object)) {
HILOG_ERROR("OnSetLoopWatch: Invalid param");
TAG_LOGE(AAFwkTag::JSNAPI, "OnSetLoopWatch: Invalid param");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
int64_t number;
if (!ConvertFromJsNumber(env, argv[INDEX_ONE], number)) {
HILOG_ERROR("OnSetLoopWatch: Parse timeout failed");
TAG_LOGE(AAFwkTag::JSNAPI, "OnSetLoopWatch: Parse timeout failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (number <= 0) {
HILOG_ERROR("The timeout cannot be less than 0");
TAG_LOGE(AAFwkTag::JSNAPI, "The timeout cannot be less than 0");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -537,9 +538,9 @@ private:
if (loopObserver_) {
loopObserver_.reset();
loopObserver_ = nullptr;
HILOG_INFO("Remove loopObserver success");
TAG_LOGI(AAFwkTag::JSNAPI, "Remove loopObserver success");
} else {
HILOG_INFO("Unregister loopObserver Called.");
TAG_LOGI(AAFwkTag::JSNAPI, "Unregister loopObserver Called.");
}
return nullptr;
}
@ -558,7 +559,7 @@ private:
if (function == nullptr ||
CheckTypeForNapiValue(env, function, napi_null) ||
CheckTypeForNapiValue(env, function, napi_undefined)) {
HILOG_ERROR("function is invalid");
TAG_LOGE(AAFwkTag::JSNAPI, "function is invalid");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return false;
}
@ -572,16 +573,16 @@ private:
napi_value JsErrorManagerInit(napi_env env, napi_value exportObj)
{
HILOG_INFO("Js error manager Init.");
TAG_LOGI(AAFwkTag::JSNAPI, "Js error manager Init.");
if (env == nullptr || exportObj == nullptr) {
HILOG_INFO("env or exportObj null");
TAG_LOGI(AAFwkTag::JSNAPI, "env or exportObj null");
return nullptr;
}
std::unique_ptr<JsErrorManager> jsErrorManager = std::make_unique<JsErrorManager>();
jsErrorManager->SetRejectionCallback(env);
napi_wrap(env, exportObj, jsErrorManager.release(), JsErrorManager::Finalizer, nullptr, nullptr);
HILOG_INFO("JsErrorManager BindNativeFunction called");
TAG_LOGI(AAFwkTag::JSNAPI, "JsErrorManager BindNativeFunction called");
const char *moduleName = "JsErrorManager";
BindNativeFunction(env, exportObj, "on", moduleName, JsErrorManager::On);
BindNativeFunction(env, exportObj, "off", moduleName, JsErrorManager::Off);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -17,6 +17,7 @@
#include <cstdint>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
@ -31,7 +32,7 @@ JsErrorObserver::~JsErrorObserver() = default;
void JsErrorObserver::OnUnhandledException(const std::string errMsg)
{
HILOG_DEBUG("OnUnhandledException come.");
TAG_LOGD(AAFwkTag::JSNAPI, "OnUnhandledException come.");
std::weak_ptr<JsErrorObserver> thisWeakPtr(shared_from_this());
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
([thisWeakPtr, errMsg](napi_env env, NapiAsyncTask &task, int32_t status) {
@ -48,7 +49,7 @@ void JsErrorObserver::OnUnhandledException(const std::string errMsg)
void JsErrorObserver::HandleOnUnhandledException(const std::string &errMsg)
{
HILOG_DEBUG("HandleOnUnhandledException come.");
TAG_LOGD(AAFwkTag::JSNAPI, "HandleOnUnhandledException come.");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value value = (item.second)->GetNapiValue();
@ -65,16 +66,16 @@ void JsErrorObserver::HandleOnUnhandledException(const std::string &errMsg)
void JsErrorObserver::CallJsFunction(napi_value obj, const char* methodName, napi_value const* argv, size_t argc)
{
HILOG_DEBUG("called method:%{public}s", methodName);
TAG_LOGD(AAFwkTag::JSNAPI, "called method:%{public}s", methodName);
if (obj == nullptr) {
HILOG_ERROR("Failed to get object");
TAG_LOGE(AAFwkTag::JSNAPI, "Failed to get object");
return;
}
napi_value method = nullptr;
napi_get_named_property(env_, obj, methodName, &method);
if (method == nullptr) {
HILOG_ERROR("Failed to get method");
TAG_LOGE(AAFwkTag::JSNAPI, "Failed to get method");
return;
}
napi_value callResult = nullptr;
@ -113,7 +114,7 @@ bool JsErrorObserver::IsEmpty()
void JsErrorObserver::OnExceptionObject(const AppExecFwk::ErrorObject &errorObj)
{
HILOG_DEBUG("OnExceptionObject come.");
TAG_LOGD(AAFwkTag::JSNAPI, "OnExceptionObject come.");
std::weak_ptr<JsErrorObserver> thisWeakPtr(shared_from_this());
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
([thisWeakPtr, errorObj](napi_env env, NapiAsyncTask &task, int32_t status) {
@ -130,7 +131,7 @@ void JsErrorObserver::OnExceptionObject(const AppExecFwk::ErrorObject &errorObj)
void JsErrorObserver::HandleException(const AppExecFwk::ErrorObject &errorObj)
{
HILOG_DEBUG("HandleException come.");
TAG_LOGD(AAFwkTag::JSNAPI, "HandleException come.");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value jsObj = (item.second)->GetNapiValue();
@ -150,7 +151,7 @@ napi_value JsErrorObserver::CreateJsErrorObject(napi_env env, const AppExecFwk::
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
if (objValue == nullptr) {
HILOG_WARN("invalid object.");
TAG_LOGW(AAFwkTag::JSNAPI, "invalid object.");
return objValue;
}
napi_set_named_property(env, objValue, "name", CreateJsValue(env, errorObj.name));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -14,6 +14,7 @@
*/
#include "js_app_foreground_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_app_manager_utils.h"
#include "js_runtime_utils.h"
@ -27,9 +28,9 @@ JSAppForegroundStateObserver::JSAppForegroundStateObserver(napi_env env) : env_(
void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStateData)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
if (!valid_) {
HILOG_ERROR("The app manager may has destoryed.");
TAG_LOGE(AAFwkTag::APPMGR, "The app manager may has destoryed.");
return;
}
wptr<JSAppForegroundStateObserver> self = this;
@ -37,7 +38,7 @@ void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStat
[self, appStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppForegroundStateObserver> jsObserver = self.promote();
if (jsObserver == nullptr) {
HILOG_ERROR("Js Observer Sptr is nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "Js Observer Sptr is nullptr.");
return;
}
jsObserver->HandleOnAppStateChanged(appStateData);
@ -49,7 +50,7 @@ void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStat
void JSAppForegroundStateObserver::HandleOnAppStateChanged(const AppStateData &appStateData)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
for (auto &item : jsObserverObjectSet_) {
napi_value obj = item->GetNapiValue();
@ -61,30 +62,30 @@ void JSAppForegroundStateObserver::HandleOnAppStateChanged(const AppStateData &a
void JSAppForegroundStateObserver::CallJsFunction(
const napi_value value, const char *methodName, const napi_value *argv, const size_t argc)
{
HILOG_DEBUG("Begin.");
TAG_LOGD(AAFwkTag::APPMGR, "Begin.");
if (value == nullptr) {
HILOG_ERROR("value is nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "value is nullptr.");
return;
}
napi_value method = nullptr;
napi_get_named_property(env_, value, methodName, &method);
if (method == nullptr) {
HILOG_ERROR("Get name from object Failed.");
TAG_LOGE(AAFwkTag::APPMGR, "Get name from object Failed.");
return;
}
napi_value callResult = nullptr;
napi_status status = napi_call_function(env_, value, method, argc, argv, &callResult);
if (status != napi_ok) {
HILOG_ERROR("Call Js Function failed %{public}d.", status);
TAG_LOGE(AAFwkTag::APPMGR, "Call Js Function failed %{public}d.", status);
}
HILOG_DEBUG("End.");
TAG_LOGD(AAFwkTag::APPMGR, "End.");
}
void JSAppForegroundStateObserver::AddJsObserverObject(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
return;
}
@ -94,7 +95,7 @@ void JSAppForegroundStateObserver::AddJsObserverObject(const napi_value &jsObser
napi_create_reference(env_, jsObserverObject, 1, &ref);
jsObserverObjectSet_.emplace(std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref)));
} else {
HILOG_DEBUG("Observer is exists.");
TAG_LOGD(AAFwkTag::APPMGR, "Observer is exists.");
}
}
@ -107,7 +108,7 @@ void JSAppForegroundStateObserver::RemoveAllJsObserverObjects()
void JSAppForegroundStateObserver::RemoveJsObserverObject(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
return;
}
@ -121,20 +122,20 @@ void JSAppForegroundStateObserver::RemoveJsObserverObject(const napi_value &jsOb
std::shared_ptr<NativeReference> JSAppForegroundStateObserver::GetObserverObject(const napi_value &jsObserverObject)
{
if (jsObserverObject == nullptr) {
HILOG_ERROR("Observer is null.");
TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
return nullptr;
}
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
for (auto &observer : jsObserverObjectSet_) {
if (observer == nullptr) {
HILOG_ERROR("Invalid observer.");
TAG_LOGE(AAFwkTag::APPMGR, "Invalid observer.");
continue;
}
napi_value value = observer->GetNapiValue();
if (value == nullptr) {
HILOG_ERROR("Failed to get object.");
TAG_LOGE(AAFwkTag::APPMGR, "Failed to get object.");
continue;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -22,6 +22,7 @@
#include "ability_runtime_error_util.h"
#include "app_mgr_interface.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
@ -58,7 +59,7 @@ public:
~JsAppManager()
{
if (observer_ != nullptr) {
HILOG_INFO("Set valid false");
TAG_LOGI(AAFwkTag::APPMGR, "Set valid false");
observer_->SetValid(false);
}
if (observerForeground_ != nullptr) {
@ -68,7 +69,7 @@ public:
static void Finalizer(napi_env env, void* data, void* hint)
{
HILOG_INFO("JsAbilityContext::Finalizer is called");
TAG_LOGI(AAFwkTag::APPMGR, "JsAbilityContext::Finalizer is called");
std::unique_ptr<JsAppManager>(static_cast<JsAppManager*>(data));
}
@ -151,7 +152,7 @@ private:
napi_value OnOn(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("OnOn called");
TAG_LOGD(AAFwkTag::APPMGR, "OnOn called");
std::string type = ParseParamType(env, argc, argv);
if (type == ON_OFF_TYPE_SYNC) {
return OnOnNew(env, argc, argv);
@ -164,9 +165,9 @@ private:
napi_value OnOnOld(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("OnOnOld called");
TAG_LOGD(AAFwkTag::APPMGR, "OnOnOld called");
if (argc < ARGC_TWO) { // support 2 or 3 params, if > 3 params, ignore other params
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
@ -177,7 +178,7 @@ private:
}
if (appManager_ == nullptr) {
HILOG_ERROR("appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -192,7 +193,7 @@ private:
}
int32_t ret = appManager_->RegisterApplicationStateObserver(observer_, bundleNameList);
if (ret == 0) {
HILOG_DEBUG("success.");
TAG_LOGD(AAFwkTag::APPMGR, "success.");
int64_t observerId = serialNumber_;
observer_->AddJsObserverObject(observerId, argv[INDEX_ONE]);
if (serialNumber_ < INT32_MAX) {
@ -202,7 +203,7 @@ private:
}
return CreateJsValue(env, observerId);
} else {
HILOG_ERROR("wrong error:%{public}d.", ret);
TAG_LOGE(AAFwkTag::APPMGR, "wrong error:%{public}d.", ret);
ThrowErrorByNativeErr(env, ret);
return CreateJsUndefined(env);
}
@ -210,14 +211,14 @@ private:
napi_value OnOnNew(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_TWO) { // support 2 or 3 params, if > 3 params, ignore other params
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
HILOG_ERROR("Invalid param");
TAG_LOGE(AAFwkTag::APPMGR, "Invalid param");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -229,13 +230,13 @@ private:
observerSync_ = new JSAppStateObserver(env);
}
if (appManager_ == nullptr || observerSync_ == nullptr) {
HILOG_ERROR("appManager or observer is nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "appManager or observer is nullptr");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
int32_t ret = appManager_->RegisterApplicationStateObserver(observerSync_, bundleNameList);
if (ret == 0) {
HILOG_DEBUG("success.");
TAG_LOGD(AAFwkTag::APPMGR, "success.");
int32_t observerId = serialNumber_;
observerSync_->AddJsObserverObject(observerId, argv[INDEX_ONE]);
if (serialNumber_ < INT32_MAX) {
@ -245,7 +246,7 @@ private:
}
return CreateJsValue(env, observerId);
} else {
HILOG_ERROR("Wrong error:%{public}d.", ret);
TAG_LOGE(AAFwkTag::APPMGR, "Wrong error:%{public}d.", ret);
ThrowErrorByNativeErr(env, ret);
return CreateJsUndefined(env);
}
@ -253,14 +254,14 @@ private:
napi_value OnOnForeground(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
if (argc < ARGC_TWO) {
HILOG_ERROR("Not enough params.");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
HILOG_ERROR("Invalid param.");
TAG_LOGE(AAFwkTag::APPMGR, "Invalid param.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -269,7 +270,7 @@ private:
}
if (appManager_ == nullptr || observerForeground_ == nullptr) {
HILOG_ERROR("AppManager or observer is nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "AppManager or observer is nullptr.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -277,7 +278,7 @@ private:
if (observerForeground_->IsEmpty()) {
int32_t ret = appManager_->RegisterAppForegroundStateObserver(observerForeground_);
if (ret != NO_ERROR) {
HILOG_ERROR("Failed error: %{public}d.", ret);
TAG_LOGE(AAFwkTag::APPMGR, "Failed error: %{public}d.", ret);
ThrowErrorByNativeErr(env, ret);
return CreateJsUndefined(env);
}
@ -288,7 +289,7 @@ private:
napi_value OnOff(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
std::string type = ParseParamType(env, argc, argv);
if (type == ON_OFF_TYPE_SYNC) {
return OnOffNew(env, argc, argv);
@ -301,9 +302,9 @@ private:
napi_value OnOffOld(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_TWO) {
HILOG_ERROR("Not enough params when off.");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
@ -315,32 +316,32 @@ private:
int64_t observerId = -1;
napi_get_value_int64(env, argv[INDEX_ONE], &observerId);
if (observer_ == nullptr) {
HILOG_ERROR("observer_ is nullpter, please register first");
TAG_LOGE(AAFwkTag::APPMGR, "observer_ is nullpter, please register first");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (!observer_->FindObserverByObserverId(observerId)) {
HILOG_ERROR("not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
TAG_LOGE(AAFwkTag::APPMGR, "not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
HILOG_DEBUG("find observer exist observer:%{public}d", static_cast<int32_t>(observerId));
TAG_LOGD(AAFwkTag::APPMGR, "find observer exist observer:%{public}d", static_cast<int32_t>(observerId));
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, observer = observer_, observerId](
napi_env env, NapiAsyncTask& task, int32_t status) {
if (observer == nullptr || appManager == nullptr) {
HILOG_ERROR("observer or appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
HILOG_DEBUG("success size:%{public}zu",
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu",
observer->GetJsObserverMapSize());
} else {
HILOG_ERROR("failed error:%{public}d", ret);
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsErrorByNativeErr(env, ret));
}
};
@ -354,35 +355,35 @@ private:
napi_value OnOffNew(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_TWO) {
HILOG_ERROR("Not enough params when off.");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
int32_t observerId = -1;
if (!ConvertFromJsValue(env, argv[INDEX_ONE], observerId)) {
HILOG_ERROR("Parse observerId failed");
TAG_LOGE(AAFwkTag::APPMGR, "Parse observerId failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (observerSync_ == nullptr || appManager_ == nullptr) {
HILOG_ERROR("observer or appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
if (!observerSync_->FindObserverByObserverId(observerId)) {
HILOG_ERROR("not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
TAG_LOGE(AAFwkTag::APPMGR, "not find observer, observer:%{public}d", static_cast<int32_t>(observerId));
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
int32_t ret = appManager_->UnregisterApplicationStateObserver(observerSync_);
if (ret == 0 && observerSync_->RemoveJsObserverObject(observerId)) {
HILOG_DEBUG("success size:%{public}zu", observerSync_->GetJsObserverMapSize());
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observerSync_->GetJsObserverMapSize());
return CreateJsUndefined(env);
} else {
HILOG_ERROR("failed error:%{public}d", ret);
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -390,19 +391,19 @@ private:
napi_value OnOffForeground(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
if (argc < ARGC_ONE) {
HILOG_ERROR("Not enough params when off.");
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (argc == ARGC_TWO && !AppExecFwk::IsTypeForNapiValue(env, argv[INDEX_ONE], napi_object)) {
HILOG_ERROR("Invalid param.");
TAG_LOGE(AAFwkTag::APPMGR, "Invalid param.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (observerForeground_ == nullptr || appManager_ == nullptr) {
HILOG_ERROR("Observer or appManager nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "Observer or appManager nullptr.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER);
return CreateJsUndefined(env);
}
@ -415,7 +416,7 @@ private:
if (observerForeground_->IsEmpty()) {
int32_t ret = appManager_->UnregisterAppForegroundStateObserver(observerForeground_);
if (ret != NO_ERROR) {
HILOG_ERROR("Failed error: %{public}d.", ret);
TAG_LOGE(AAFwkTag::APPMGR, "Failed error: %{public}d.", ret);
ThrowErrorByNativeErr(env, ret);
return CreateJsUndefined(env);
}
@ -425,21 +426,21 @@ private:
napi_value OnGetForegroundApplications(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (appManager == nullptr) {
HILOG_ERROR("appManager nullptr");
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
std::vector<AppExecFwk::AppStateData> list;
int32_t ret = appManager->GetForegroundApplications(list);
if (ret == 0) {
HILOG_DEBUG("success.");
TAG_LOGD(AAFwkTag::APPMGR, "success.");
task.ResolveWithNoError(env, CreateJsAppStateDataArray(env, list));
} else {
HILOG_ERROR("failed error:%{public}d", ret);
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
};
@ -453,11 +454,11 @@ private:
napi_value OnGetRunningProcessInformation(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
@ -479,16 +480,16 @@ private:
napi_value OnIsRunningInStabilityTest(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
HILOG_INFO("result:%{public}d", ret);
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
};
@ -501,25 +502,25 @@ private:
napi_value OnkillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("OnkillProcessesByBundleName called");
TAG_LOGD(AAFwkTag::APPMGR, "OnkillProcessesByBundleName called");
if (argc < ARGC_ONE) {
HILOG_ERROR("Params not match");
TAG_LOGE(AAFwkTag::APPMGR, "Params not match");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("get bundleName error!");
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName error!");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
HILOG_INFO("kill process [%{public}s]", bundleName.c_str());
TAG_LOGI(AAFwkTag::APPMGR, "kill process [%{public}s]", bundleName.c_str());
NapiAsyncTask::CompleteCallback complete =
[bundleName, abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
@ -540,16 +541,16 @@ private:
napi_value OnClearUpApplicationData(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("OnClearUpApplicationData called");
TAG_LOGD(AAFwkTag::APPMGR, "OnClearUpApplicationData called");
if (argc < ARGC_ONE) {
HILOG_ERROR("arguments not match");
TAG_LOGE(AAFwkTag::APPMGR, "arguments not match");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("get bundleName failed!");
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName failed!");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -557,7 +558,7 @@ private:
NapiAsyncTask::CompleteCallback complete =
[bundleName, abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
@ -578,23 +579,23 @@ private:
napi_value OnIsSharedBundleRunning(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("OnIsSharedBundleRunning called");
TAG_LOGD(AAFwkTag::APPMGR, "OnIsSharedBundleRunning called");
if (argc < ARGC_TWO) {
HILOG_ERROR("Params not match");
TAG_LOGE(AAFwkTag::APPMGR, "Params not match");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("get bundleName wrong!");
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName wrong!");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
uint32_t versionCode = 0;
if (!ConvertFromJsValue(env, argv[1], versionCode)) {
HILOG_ERROR("get versionCode failed!");
TAG_LOGE(AAFwkTag::APPMGR, "get versionCode failed!");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -602,12 +603,12 @@ private:
NapiAsyncTask::CompleteCallback complete =
[bundleName, versionCode, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (appManager == nullptr) {
HILOG_WARN("appManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
bool ret = appManager->IsSharedBundleRunning(bundleName, versionCode);
HILOG_INFO("result:%{public}d", ret);
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
};
@ -620,22 +621,22 @@ private:
napi_value OnKillProcessWithAccount(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_TWO) {
HILOG_ERROR("Params not match");
TAG_LOGE(AAFwkTag::APPMGR, "Params not match");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("Parse bundleName failed");
TAG_LOGE(AAFwkTag::APPMGR, "Parse bundleName failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
int32_t accountId = -1;
if (!ConvertFromJsValue(env, argv[1], accountId)) {
HILOG_ERROR("Parse userId failed");
TAG_LOGE(AAFwkTag::APPMGR, "Parse userId failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -643,7 +644,7 @@ private:
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, bundleName, accountId](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr || appManager->GetAmsMgr() == nullptr) {
HILOG_WARN("appManager is nullptr or amsMgr is nullptr.");
TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr or amsMgr is nullptr.");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
@ -667,12 +668,12 @@ private:
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
int32_t memorySize = abilityManager->GetAppMemorySize();
HILOG_INFO("memorySize:%{public}d", memorySize);
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
task.ResolveWithNoError(env, CreateJsValue(env, memorySize));
};
@ -688,12 +689,12 @@ private:
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
HILOG_WARN("abilityManager nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
bool ret = abilityManager->IsRamConstrainedDevice();
HILOG_INFO("result:%{public}d", ret);
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
};
@ -706,16 +707,16 @@ private:
napi_value OnGetProcessMemoryByPid(napi_env env, size_t argc, napi_value* argv)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_ONE) {
HILOG_ERROR("Params not match");
TAG_LOGE(AAFwkTag::APPMGR, "Params not match");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
int32_t pid;
if (!ConvertFromJsValue(env, argv[0], pid)) {
HILOG_ERROR("get pid failed");
TAG_LOGE(AAFwkTag::APPMGR, "get pid failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -723,7 +724,7 @@ private:
NapiAsyncTask::CompleteCallback complete =
[pid, appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr) {
HILOG_WARN("appManager is nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
@ -754,7 +755,7 @@ private:
int userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE;
bool isPromiseType = false;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("First parameter must be string");
TAG_LOGE(AAFwkTag::APPMGR, "First parameter must be string");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -766,7 +767,7 @@ private:
}
} else if (argc == ARGC_THREE) {
if (!ConvertFromJsValue(env, argv[1], userId)) {
HILOG_WARN("Must input userid and use callback when argc is three.");
TAG_LOGW(AAFwkTag::APPMGR, "Must input userid and use callback when argc is three.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -798,16 +799,16 @@ private:
napi_value OnIsApplicationRunning(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
if (argc < ARGC_ONE) {
HILOG_ERROR("Params not match.");
TAG_LOGE(AAFwkTag::APPMGR, "Params not match.");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
HILOG_ERROR("Get bundle name wrong.");
TAG_LOGE(AAFwkTag::APPMGR, "Get bundle name wrong.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -819,7 +820,7 @@ private:
[bundleName, appManager, innerErrorCode, isRunning]() {
sptr<OHOS::AppExecFwk::IAppMgr> appMgr = appManager.promote();
if (appMgr == nullptr) {
HILOG_ERROR("App manager is nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "App manager is nullptr.");
*innerErrorCode = static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER);
return;
}
@ -848,18 +849,18 @@ private:
}
if (!AppExecFwk::IsTypeForNapiValue(env, argv[0], napi_string)) {
HILOG_ERROR("Param 0 is not string");
TAG_LOGE(AAFwkTag::APPMGR, "Param 0 is not string");
return false;
}
std::string type;
if (!ConvertFromJsValue(env, argv[0], type)) {
HILOG_ERROR("Parse on off type failed");
TAG_LOGE(AAFwkTag::APPMGR, "Parse on off type failed");
return false;
}
if (type != ON_OFF_TYPE) {
HILOG_ERROR("args[0] should be %{public}s.", ON_OFF_TYPE);
TAG_LOGE(AAFwkTag::APPMGR, "args[0] should be %{public}s.", ON_OFF_TYPE);
return false;
}
return true;
@ -895,9 +896,9 @@ OHOS::sptr<OHOS::AAFwk::IAbilityManager> GetAbilityManagerInstance()
napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (env == nullptr || exportObj == nullptr) {
HILOG_WARN("env or exportObj null");
TAG_LOGW(AAFwkTag::APPMGR, "env or exportObj null");
return nullptr;
}
@ -939,7 +940,7 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
JsAppManager::GetRunningProcessInfoByBundleName);
BindNativeFunction(env, exportObj, "isApplicationRunning", moduleName,
JsAppManager::IsApplicationRunning);
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::APPMGR, "end");
return CreateJsUndefined(env);
}
} // namespace AbilityRuntime

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -17,6 +17,7 @@
#include <cstdint>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "iapplication_state_observer.h"
#include "js_runtime.h"
@ -26,11 +27,11 @@ namespace OHOS {
namespace AbilityRuntime {
napi_value CreateJsAppStateData(napi_env env, const AppStateData &appStateData)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::APPMGR, "called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, appStateData.bundleName));
@ -38,17 +39,17 @@ napi_value CreateJsAppStateData(napi_env env, const AppStateData &appStateData)
napi_set_named_property(env, object, "state", CreateJsValue(env, appStateData.state));
napi_set_named_property(env, object, "isSplitScreenMode", CreateJsValue(env, appStateData.isSplitScreenMode));
napi_set_named_property(env, object, "isFloatingWindowMode", CreateJsValue(env, appStateData.isFloatingWindowMode));
HILOG_DEBUG("end.");
TAG_LOGD(AAFwkTag::APPMGR, "end.");
return object;
}
napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::APPMGR, "called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, abilityStateData.bundleName));
@ -65,11 +66,11 @@ napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilit
napi_value CreateJsProcessData(napi_env env, const ProcessData &processData)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::APPMGR, "called.");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, processData.bundleName));
@ -78,7 +79,7 @@ napi_value CreateJsProcessData(napi_env env, const ProcessData &processData)
napi_set_named_property(env, object, "state", CreateJsValue(env, processData.state));
napi_set_named_property(env, object, "isContinuousTask", CreateJsValue(env, processData.isContinuousTask));
napi_set_named_property(env, object, "isKeepAlive", CreateJsValue(env, processData.isKeepAlive));
HILOG_DEBUG("end.");
TAG_LOGD(AAFwkTag::APPMGR, "end.");
return object;
}
@ -109,7 +110,7 @@ napi_value CreateJsRunningProcessInfo(napi_env env, const RunningProcessInfo &in
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("objValue nullptr.");
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
@ -123,17 +124,17 @@ napi_value CreateJsRunningProcessInfo(napi_env env, const RunningProcessInfo &in
napi_value ApplicationStateInit(napi_env env)
{
HILOG_DEBUG("ApplicationStateInit enter");
TAG_LOGD(AAFwkTag::APPMGR, "ApplicationStateInit enter");
if (env == nullptr) {
HILOG_ERROR("Invalid input parameters");
TAG_LOGE(AAFwkTag::APPMGR, "Invalid input parameters");
return nullptr;
}
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("Wrong to get object");
TAG_LOGE(AAFwkTag::APPMGR, "Wrong to get object");
return nullptr;
}
@ -153,17 +154,17 @@ napi_value ApplicationStateInit(napi_env env)
napi_value ProcessStateInit(napi_env env)
{
HILOG_DEBUG("ProcessStateInit enter");
TAG_LOGD(AAFwkTag::APPMGR, "ProcessStateInit enter");
if (env == nullptr) {
HILOG_ERROR("Invalid input arguments");
TAG_LOGE(AAFwkTag::APPMGR, "Invalid input arguments");
return nullptr;
}
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
HILOG_ERROR("Failed to get object");
TAG_LOGE(AAFwkTag::APPMGR, "Failed to get object");
return nullptr;
}
napi_set_named_property(env, object, "STATE_CREATE",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -14,6 +14,7 @@
*/
#include "js_app_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
#include "js_app_manager_utils.h"
@ -28,10 +29,10 @@ JSAppStateObserver::~JSAppStateObserver() = default;
void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appStateData)
{
HILOG_DEBUG("onForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
TAG_LOGD(AAFwkTag::APPMGR, "onForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
if (!valid_) {
HILOG_ERROR("the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@ -39,7 +40,7 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
([jsObserver, appStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr");
return;
}
jsObserverSptr->HandleOnForegroundApplicationChanged(appStateData);
@ -52,7 +53,8 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData)
{
HILOG_DEBUG("HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
TAG_LOGD(AAFwkTag::APPMGR,
"HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
@ -64,9 +66,9 @@ void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData
void JSAppStateObserver::OnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
HILOG_ERROR("the app manager may has cancelled storage");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has cancelled storage");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@ -74,7 +76,7 @@ void JSAppStateObserver::OnAbilityStateChanged(const AbilityStateData &abilitySt
([jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr null");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr null");
return;
}
jsObserverSptr->HandleOnAbilityStateChanged(abilityStateData);
@ -87,7 +89,7 @@ void JSAppStateObserver::OnAbilityStateChanged(const AbilityStateData &abilitySt
void JSAppStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -98,9 +100,9 @@ void JSAppStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abi
void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
HILOG_ERROR("the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@ -108,7 +110,7 @@ void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &ability
([jsObserver, abilityStateData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr");
return;
}
jsObserverSptr->HandleOnExtensionStateChanged(abilityStateData);
@ -121,7 +123,7 @@ void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &ability
void JSAppStateObserver::HandleOnExtensionStateChanged(const AbilityStateData &abilityStateData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -132,9 +134,9 @@ void JSAppStateObserver::HandleOnExtensionStateChanged(const AbilityStateData &a
void JSAppStateObserver::OnProcessCreated(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
HILOG_ERROR("the app manager may has cancelled storage");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has cancelled storage");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@ -142,7 +144,7 @@ void JSAppStateObserver::OnProcessCreated(const ProcessData &processData)
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr null");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr null");
return;
}
jsObserverSptr->HandleOnProcessCreated(processData);
@ -155,7 +157,7 @@ void JSAppStateObserver::OnProcessCreated(const ProcessData &processData)
void JSAppStateObserver::HandleOnProcessCreated(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -166,9 +168,9 @@ void JSAppStateObserver::HandleOnProcessCreated(const ProcessData &processData)
void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
HILOG_ERROR("the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@ -176,7 +178,7 @@ void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr");
return;
}
jsObserverSptr->HandleOnProcessStateChanged(processData);
@ -189,7 +191,7 @@ void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
void JSAppStateObserver::HandleOnProcessStateChanged(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -200,9 +202,9 @@ void JSAppStateObserver::HandleOnProcessStateChanged(const ProcessData &processD
void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
HILOG_ERROR("the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@ -210,7 +212,7 @@ void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
([jsObserver, processData](napi_env env, NapiAsyncTask &task, int32_t status) {
sptr<JSAppStateObserver> jsObserverSptr = jsObserver.promote();
if (!jsObserverSptr) {
HILOG_WARN("jsObserverSptr nullptr.");
TAG_LOGW(AAFwkTag::APPMGR, "jsObserverSptr nullptr.");
return;
}
jsObserverSptr->HandleOnProcessDied(processData);
@ -223,7 +225,7 @@ void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
void JSAppStateObserver::HandleOnProcessDied(const ProcessData &processData)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
napi_value obj = (item.second)->GetNapiValue();
@ -235,21 +237,21 @@ void JSAppStateObserver::HandleOnProcessDied(const ProcessData &processData)
void JSAppStateObserver::CallJsFunction(
napi_value value, const char *methodName, napi_value* argv, size_t argc)
{
HILOG_DEBUG("called, method:%{public}s", methodName);
TAG_LOGD(AAFwkTag::APPMGR, "called, method:%{public}s", methodName);
if (value == nullptr) {
HILOG_ERROR("Failed to get object");
TAG_LOGE(AAFwkTag::APPMGR, "Failed to get object");
return;
}
napi_value method = nullptr;
napi_get_named_property(env_, value, methodName, &method);
if (method == nullptr) {
HILOG_ERROR("Failed to get from object");
TAG_LOGE(AAFwkTag::APPMGR, "Failed to get from object");
return;
}
napi_value callResult = nullptr;
napi_call_function(env_, value, method, argc, argv, &callResult);
HILOG_DEBUG("end");
TAG_LOGD(AAFwkTag::APPMGR, "end");
}
void JSAppStateObserver::AddJsObserverObject(const int32_t observerId, napi_value jsObserverObject)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -16,6 +16,7 @@
#include "app_recovery_api.h"
#include "app_recovery.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
@ -87,7 +88,8 @@ private:
napi_valuetype paramType;
napi_typeof(env, argv[i], &paramType);
if (paramType != napi_number) {
HILOG_ERROR("AppRecoveryApi argv[%{public}s] type isn't number", std::to_string(i).c_str());
TAG_LOGE(
AAFwkTag::RECOVERY, "AppRecoveryApi argv[%{public}s] type isn't number", std::to_string(i).c_str());
return result;
}
int32_t tmp = 0;
@ -110,18 +112,21 @@ private:
uint16_t restartFlag = params[0];
constexpr uint16_t restartMaxVal = 0x0003;
if ((restartFlag < 0 || restartFlag > restartMaxVal) && (restartFlag != RestartFlag::NO_RESTART)) {
HILOG_ERROR("AppRecoveryApi CheckParamsValid restartFlag: %{public}d is Invalid", restartFlag);
TAG_LOGE(
AAFwkTag::RECOVERY, "AppRecoveryApi CheckParamsValid restartFlag: %{public}d is Invalid", restartFlag);
return false;
}
uint16_t saveFlag = params[1];
constexpr uint16_t saveMaxVal = 0x0003;
if (saveFlag < SaveOccasionFlag::SAVE_WHEN_ERROR || saveFlag > saveMaxVal) {
HILOG_ERROR("AppRecoveryApi CheckParamsValid SaveOccasionFlag: %{public}d is Invalid", saveFlag);
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryApi CheckParamsValid SaveOccasionFlag: %{public}d is Invalid",
saveFlag);
return false;
}
uint16_t saveModeFlag = params[2];
if (saveModeFlag < SaveModeFlag::SAVE_WITH_FILE || saveModeFlag > SaveModeFlag::SAVE_WITH_SHARED_MEMORY) {
HILOG_ERROR("AppRecoveryApi CheckParamsValid saveModeFlag: %{public}d is Invalid", saveModeFlag);
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryApi CheckParamsValid saveModeFlag: %{public}d is Invalid",
saveModeFlag);
return false;
}
return true;
@ -130,14 +135,14 @@ private:
napi_value OnSaveAppState(napi_env env, const size_t argc, napi_value* argv)
{
if (argc > 1) {
HILOG_ERROR("AppRecoveryApi SaveAppState Incorrect number of parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryApi SaveAppState Incorrect number of parameters");
return CreateJsValue(env, false);
}
uintptr_t ability = 0;
if (argc == 1) {
napi_value value = argv[0];
if (value == nullptr) {
HILOG_ERROR("AppRecoveryApi Invalid abilityContext.");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryApi Invalid abilityContext.");
return CreateJsValue(env, false);
}
void* result = nullptr;
@ -153,7 +158,7 @@ private:
napi_value OnRestartApp(napi_env env, const size_t argc, napi_value* argv)
{
if (argc != 0) {
HILOG_ERROR("AppRecoveryApi OnRestartApp Incorrect number of parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryApi OnRestartApp Incorrect number of parameters");
return CreateJsUndefined(env);
}
@ -164,7 +169,7 @@ private:
napi_value OnSetRestartWant(napi_env env, const size_t argc, napi_value* argv)
{
if (argc != 1) {
HILOG_ERROR("AppRecoveryApi OnSetRestartWant Incorrect number of parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryApi OnSetRestartWant Incorrect number of parameters");
return CreateJsUndefined(env);
}
std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
@ -178,7 +183,7 @@ private:
napi_value AppRecoveryRestartFlagInit(napi_env env)
{
if (env == nullptr) {
HILOG_ERROR("AppRecoveryRestartFlagInit Invalid input parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryRestartFlagInit Invalid input parameters");
return nullptr;
}
@ -186,7 +191,7 @@ napi_value AppRecoveryRestartFlagInit(napi_env env)
napi_create_object(env, &objValue);
if (objValue == nullptr) {
HILOG_ERROR("AppRecoveryRestartFlagInit Failed to get object");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryRestartFlagInit Failed to get object");
return nullptr;
}
@ -202,7 +207,7 @@ napi_value AppRecoveryRestartFlagInit(napi_env env)
napi_value AppRecoveryStateSaveFlagInit(napi_env env)
{
if (env == nullptr) {
HILOG_ERROR("AppRecoveryStateSaveFlagInit Invalid input parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryStateSaveFlagInit Invalid input parameters");
return nullptr;
}
@ -210,7 +215,7 @@ napi_value AppRecoveryStateSaveFlagInit(napi_env env)
napi_create_object(env, &objValue);
if (objValue == nullptr) {
HILOG_ERROR("AppRecoveryStateSaveFlagInit Failed to get object");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoveryStateSaveFlagInit Failed to get object");
return nullptr;
}
@ -225,7 +230,7 @@ napi_value AppRecoveryStateSaveFlagInit(napi_env env)
napi_value AppRecoverySaveModeFlagInit(napi_env env)
{
if (env == nullptr) {
HILOG_ERROR("AppRecoverySaveModeFlagInit Invalid input parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoverySaveModeFlagInit Invalid input parameters");
return nullptr;
}
@ -233,7 +238,7 @@ napi_value AppRecoverySaveModeFlagInit(napi_env env)
napi_create_object(env, &objValue);
if (objValue == nullptr) {
HILOG_ERROR("AppRecoverySaveModeFlagInit Failed to get object");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecoverySaveModeFlagInit Failed to get object");
return nullptr;
}
napi_set_named_property(env, objValue, "SAVE_WITH_FILE",
@ -246,7 +251,7 @@ napi_value AppRecoverySaveModeFlagInit(napi_env env)
napi_value InitAppRecoveryApiModule(napi_env env, napi_value exportObj)
{
if (env == nullptr || exportObj == nullptr) {
HILOG_ERROR("AppRecovery API Invalid input parameters");
TAG_LOGE(AAFwkTag::RECOVERY, "AppRecovery API Invalid input parameters");
return nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -15,6 +15,7 @@
#include "js_insight_intent.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_error_utils.h"
#include "js_runtime_utils.h"
@ -32,7 +33,7 @@ const uint8_t NUMBER_OF_PARAMETERS_THREE = 3;
napi_value ExecuteModeInit(napi_env env)
{
if (env == nullptr) {
HILOG_ERROR("Invalid input parameters");
TAG_LOGE(AAFwkTag::INTENT, "Invalid input parameters");
return nullptr;
}
napi_value objValue = nullptr;
@ -52,9 +53,9 @@ napi_value ExecuteModeInit(napi_env env)
napi_value JsInsightIntentInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::INTENT, "called");
if (env == nullptr || exportObj == nullptr) {
HILOG_ERROR("Invalid input parameters");
TAG_LOGE(AAFwkTag::INTENT, "Invalid input parameters");
return nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -19,6 +19,7 @@
#include "ability_manager_client.h"
#include "event_handler.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "insight_intent_callback_interface.h"
#include "insight_intent_host_client.h"
@ -82,7 +83,7 @@ public:
static void Finalizer(napi_env env, void *data, void *hint)
{
HILOG_INFO("JsInsightIntentDriver::Finalizer is called");
TAG_LOGI(AAFwkTag::INTENT, "JsInsightIntentDriver::Finalizer is called");
std::unique_ptr<JsInsightIntentDriver>(static_cast<JsInsightIntentDriver*>(data));
}
@ -94,16 +95,16 @@ public:
private:
napi_value OnExecute(napi_env env, NapiCallbackInfo& info)
{
HILOG_DEBUG("called");
TAG_LOGD(AAFwkTag::INTENT, "called");
if (info.argc < ARGC_ONE) {
HILOG_ERROR("Params not match");
TAG_LOGE(AAFwkTag::INTENT, "Params not match");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
InsightIntentExecuteParam param;
if (!UnwrapExecuteParam(env, info.argv[INDEX_ZERO], param)) {
HILOG_ERROR("CheckOnOffType, Parse on off type failed");
TAG_LOGE(AAFwkTag::INTENT, "CheckOnOffType, Parse on off type failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -126,7 +127,7 @@ private:
}
if (asyncTask == nullptr) {
HILOG_ERROR("asyncTask is nullptr");
TAG_LOGE(AAFwkTag::INTENT, "asyncTask is nullptr");
return CreateJsUndefined(env);
}
auto client = std::make_shared<JsInsightIntentExecuteCallbackClient>(env, nativeDeferred, callbackRef);
@ -143,9 +144,9 @@ private:
napi_value JsInsightIntentDriverInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("JsInsightIntentDriverInit is called");
TAG_LOGD(AAFwkTag::INTENT, "JsInsightIntentDriverInit is called");
if (env == nullptr || exportObj == nullptr) {
HILOG_ERROR("Invalid input parameters");
TAG_LOGE(AAFwkTag::INTENT, "Invalid input parameters");
return nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -19,6 +19,7 @@
#include "child_process_manager.h"
#include "child_process_manager_error_utils.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_error_utils.h"
#include "js_runtime_utils.h"
@ -44,7 +45,7 @@ public:
static void Finalizer(napi_env env, void* data, void* hint)
{
HILOG_INFO("%{public}s::Finalizer is called", PROCESS_MANAGER_NAME);
TAG_LOGI(AAFwkTag::PROCESSMGR, "%{public}s::Finalizer is called", PROCESS_MANAGER_NAME);
std::unique_ptr<JsChildProcessManager>(static_cast<JsChildProcessManager*>(data));
}
@ -56,32 +57,32 @@ public:
private:
napi_value OnStartChildProcess(napi_env env, size_t argc, napi_value* argv)
{
HILOG_INFO("called.");
TAG_LOGI(AAFwkTag::PROCESSMGR, "called.");
if (ChildProcessManager::GetInstance().IsChildProcess()) {
HILOG_ERROR("Already in child process");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Already in child process");
ThrowError(env, AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED);
return CreateJsUndefined(env);
}
if (argc < ARGC_TWO) {
HILOG_ERROR("Not enough params");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Not enough params");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string srcEntry;
int32_t startMode;
if (!ConvertFromJsValue(env, argv[0], srcEntry)) {
HILOG_ERROR("Parse param srcEntry failed");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Parse param srcEntry failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
if (!ConvertFromJsValue(env, argv[1], startMode)) {
HILOG_ERROR("Parse param startMode failed");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Parse param startMode failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
HILOG_DEBUG("StartMode: %{public}d", startMode);
TAG_LOGD(AAFwkTag::PROCESSMGR, "StartMode: %{public}d", startMode);
if (startMode != MODE_SELF_FORK && startMode != MODE_APP_SPAWN_FORK) {
HILOG_ERROR("Not supported StartMode");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Not supported StartMode");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
return CreateJsUndefined(env);
}
@ -98,7 +99,7 @@ private:
static void ForkProcess(napi_env env, NapiAsyncTask &task, const std::string &srcEntry, const int32_t startMode)
{
HILOG_DEBUG("called.");
TAG_LOGD(AAFwkTag::PROCESSMGR, "called.");
pid_t pid = 0;
ChildProcessManagerErrorCode errorCode;
switch (startMode) {
@ -111,12 +112,13 @@ private:
break;
}
default: {
HILOG_ERROR("Not supported StartMode");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Not supported StartMode");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
}
HILOG_DEBUG("ChildProcessManager start resultCode: %{public}d, pid:%{public}d", errorCode, pid);
TAG_LOGD(
AAFwkTag::PROCESSMGR, "ChildProcessManager start resultCode: %{public}d, pid:%{public}d", errorCode, pid);
if (errorCode == ChildProcessManagerErrorCode::ERR_OK) {
task.ResolveWithNoError(env, CreateJsValue(env, pid));
} else {
@ -127,9 +129,9 @@ private:
napi_value JsChildProcessManagerInit(napi_env env, napi_value exportObj)
{
HILOG_INFO("called.");
TAG_LOGI(AAFwkTag::PROCESSMGR, "called.");
if (env == nullptr || exportObj == nullptr) {
HILOG_ERROR("Invalid input params");
TAG_LOGE(AAFwkTag::PROCESSMGR, "Invalid input params");
return nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -18,6 +18,7 @@
#include <uv.h>
#include <vector>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
#include "napi_common_ability.h"
@ -40,7 +41,7 @@ namespace AppExecFwk {
*/
napi_value NAPI_PAGetAppType(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_GetAppTypeCommon(env, info, AbilityType::UNKNOWN);
}
@ -54,7 +55,7 @@ napi_value NAPI_PAGetAppType(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAGetAbilityInfo(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_GetAbilityInfoCommon(env, info, AbilityType::UNKNOWN);
}
@ -68,7 +69,7 @@ napi_value NAPI_PAGetAbilityInfo(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAGetHapModuleInfo(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_GetHapModuleInfoCommon(env, info, AbilityType::UNKNOWN);
}
@ -82,7 +83,7 @@ napi_value NAPI_PAGetHapModuleInfo(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAGetContext(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_GetContextCommon(env, info, AbilityType::UNKNOWN);
}
@ -96,7 +97,7 @@ napi_value NAPI_PAGetContext(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAGetWant(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_GetWantCommon(env, info, AbilityType::UNKNOWN);
}
@ -110,7 +111,7 @@ napi_value NAPI_PAGetWant(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAGetAbilityName(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_GetAbilityNameCommon(env, info, AbilityType::UNKNOWN);
}
@ -124,7 +125,7 @@ napi_value NAPI_PAGetAbilityName(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAStopAbility(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
return NAPI_StopAbilityCommon(env, info, AbilityType::UNKNOWN);
}
@ -138,7 +139,7 @@ napi_value NAPI_PAStopAbility(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PAAcquireDataAbilityHelper(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s,called", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
return NAPI_AcquireDataAbilityHelperCommon(env, info, AbilityType::UNKNOWN);
}
@ -152,7 +153,7 @@ napi_value NAPI_PAAcquireDataAbilityHelper(napi_env env, napi_callback_info info
*/
napi_value NAPI_PAStartBackgroundRunning(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s,called", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
return NAPI_StartBackgroundRunningCommon(env, info);
}
@ -166,7 +167,7 @@ napi_value NAPI_PAStartBackgroundRunning(napi_env env, napi_callback_info info)
*/
napi_value NAPI_PACancelBackgroundRunning(napi_env env, napi_callback_info info)
{
HILOG_INFO("%{public}s,called", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
return NAPI_CancelBackgroundRunningCommon(env, info);
}
@ -180,7 +181,7 @@ napi_value NAPI_PACancelBackgroundRunning(napi_env env, napi_callback_info info)
*/
napi_value ParticleAbilityInit(napi_env env, napi_value exports)
{
HILOG_INFO("%{public}s called.", __func__);
TAG_LOGI(AAFwkTag::FA, "%{public}s called.", __func__);
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("getAppType", NAPI_PAGetAppType),
DECLARE_NAPI_FUNCTION("getAbilityInfo", NAPI_PAGetAbilityInfo),
@ -200,7 +201,7 @@ napi_value ParticleAbilityInit(napi_env env, napi_value exports)
void JsParticleAbility::Finalizer(napi_env env, void *data, void *hint)
{
HILOG_INFO("JsParticleAbility::Finalizer is called");
TAG_LOGI(AAFwkTag::FA, "JsParticleAbility::Finalizer is called");
std::unique_ptr<JsParticleAbility>(static_cast<JsParticleAbility*>(data));
}
@ -235,7 +236,7 @@ Ability* JsParticleAbility::GetAbility(napi_env env)
ret = napi_get_global(env, &global);
if (ret != napi_ok) {
napi_get_last_error_info(env, &errorInfo);
HILOG_ERROR("JsParticleAbility::GetAbility, get_global=%{public}d err:%{public}s",
TAG_LOGE(AAFwkTag::FA, "JsParticleAbility::GetAbility, get_global=%{public}d err:%{public}s",
ret, errorInfo->error_message);
return nullptr;
}
@ -243,7 +244,7 @@ Ability* JsParticleAbility::GetAbility(napi_env env)
ret = napi_get_named_property(env, global, "ability", &abilityObj);
if (ret != napi_ok) {
napi_get_last_error_info(env, &errorInfo);
HILOG_ERROR("JsParticleAbility::GetAbility, get_named_property=%{public}d err:%{public}s",
TAG_LOGE(AAFwkTag::FA, "JsParticleAbility::GetAbility, get_named_property=%{public}d err:%{public}s",
ret, errorInfo->error_message);
return nullptr;
}
@ -251,7 +252,7 @@ Ability* JsParticleAbility::GetAbility(napi_env env)
ret = napi_get_value_external(env, abilityObj, reinterpret_cast<void **>(&ability));
if (ret != napi_ok) {
napi_get_last_error_info(env, &errorInfo);
HILOG_ERROR("JsParticleAbility::GetAbility, get_value_external=%{public}d err:%{public}s",
TAG_LOGE(AAFwkTag::FA, "JsParticleAbility::GetAbility, get_value_external=%{public}d err:%{public}s",
ret, errorInfo->error_message);
return nullptr;
}
@ -260,14 +261,14 @@ Ability* JsParticleAbility::GetAbility(napi_env env)
napi_value JsParticleAbilityInit(napi_env env, napi_value exportObj)
{
HILOG_DEBUG("JsParticleAbility is called");
TAG_LOGD(AAFwkTag::FA, "JsParticleAbility is called");
if (env == nullptr || exportObj == nullptr) {
HILOG_ERROR("env or exportObj null");
TAG_LOGE(AAFwkTag::FA, "env or exportObj null");
return nullptr;
}
if (!CheckTypeForNapiValue(env, exportObj, napi_object)) {
HILOG_ERROR("object null");
TAG_LOGE(AAFwkTag::FA, "object null");
return nullptr;
}
@ -275,14 +276,14 @@ napi_value JsParticleAbilityInit(napi_env env, napi_value exportObj)
jsParticleAbility->ability_ = jsParticleAbility->GetAbility(env);
napi_wrap(env, exportObj, jsParticleAbility.release(), JsParticleAbility::Finalizer, nullptr, nullptr);
HILOG_DEBUG("JsParticleAbility BindNativeFunction called");
TAG_LOGD(AAFwkTag::FA, "JsParticleAbility BindNativeFunction called");
const char *moduleName = "JsParticleAbility";
BindNativeFunction(env, exportObj, "connectAbility", moduleName, JsParticleAbility::PAConnectAbility);
BindNativeFunction(env, exportObj, "disconnectAbility", moduleName, JsParticleAbility::PADisConnectAbility);
BindNativeFunction(env, exportObj, "startAbility", moduleName, JsParticleAbility::PAStartAbility);
BindNativeFunction(env, exportObj, "terminateSelf", moduleName, JsParticleAbility::PATerminateAbility);
HILOG_DEBUG("JsParticleAbility end");
TAG_LOGD(AAFwkTag::FA, "JsParticleAbility end");
return exportObj;
}
} // namespace AppExecFwk

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -15,6 +15,7 @@
#include "ability_auto_startup_client.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
@ -26,10 +27,10 @@ namespace AAFwk {
std::shared_ptr<AbilityAutoStartupClient> AbilityAutoStartupClient::instance_ = nullptr;
std::recursive_mutex AbilityAutoStartupClient::mutex_;
#define CHECK_POINTER_RETURN_NOT_CONNECTED(object) \
if (!object) { \
HILOG_ERROR("proxy is nullptr."); \
return ABILITY_SERVICE_NOT_CONNECTED; \
#define CHECK_POINTER_RETURN_NOT_CONNECTED(object) \
if (!(object)) { \
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "proxy is nullptr."); \
return ABILITY_SERVICE_NOT_CONNECTED; \
}
std::shared_ptr<AbilityAutoStartupClient> AbilityAutoStartupClient::GetInstance()
@ -67,33 +68,33 @@ ErrCode AbilityAutoStartupClient::Connect()
}
sptr<ISystemAbilityManager> systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (systemManager == nullptr) {
HILOG_ERROR("Fail to get registry.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Fail to get registry.");
return GET_ABILITY_SERVICE_FAILED;
}
sptr<IRemoteObject> remoteObj = systemManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
if (remoteObj == nullptr) {
HILOG_ERROR("Fail to connect ability manager service.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Fail to connect ability manager service.");
return GET_ABILITY_SERVICE_FAILED;
}
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new AbilityMgrDeathRecipient());
if (deathRecipient_ == nullptr) {
HILOG_ERROR("Failed to create AbilityMgrDeathRecipient!");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to create AbilityMgrDeathRecipient!");
return GET_ABILITY_SERVICE_FAILED;
}
if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(deathRecipient_))) {
HILOG_ERROR("Add death recipient to AbilityManagerService failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Add death recipient to AbilityManagerService failed.");
return GET_ABILITY_SERVICE_FAILED;
}
proxy_ = iface_cast<IAbilityManager>(remoteObj);
HILOG_DEBUG("Connect ability manager service success.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Connect ability manager service success.");
return ERR_OK;
}
ErrCode AbilityAutoStartupClient::SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
auto abms = GetAbilityManager();
CHECK_POINTER_RETURN_NOT_CONNECTED(abms);
return abms->SetApplicationAutoStartupByEDM(info, flag);
@ -101,7 +102,7 @@ ErrCode AbilityAutoStartupClient::SetApplicationAutoStartupByEDM(const AutoStart
ErrCode AbilityAutoStartupClient::CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
auto abms = GetAbilityManager();
CHECK_POINTER_RETURN_NOT_CONNECTED(abms);
return abms->CancelApplicationAutoStartupByEDM(info, flag);
@ -109,7 +110,7 @@ ErrCode AbilityAutoStartupClient::CancelApplicationAutoStartupByEDM(const AutoSt
ErrCode AbilityAutoStartupClient::QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
auto abms = GetAbilityManager();
CHECK_POINTER_RETURN_NOT_CONNECTED(abms);
return abms->QueryAllAutoStartupApplications(infoList);
@ -117,7 +118,7 @@ ErrCode AbilityAutoStartupClient::QueryAllAutoStartupApplications(std::vector<Au
void AbilityAutoStartupClient::AbilityMgrDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOG_INFO("AbilityMgrDeathRecipient handle remote died.");
TAG_LOGI(AAFwkTag::AUTO_STARTUP, "AbilityMgrDeathRecipient handle remote died.");
AbilityAutoStartupClient::GetInstance()->ResetProxy(remote);
}
@ -130,7 +131,7 @@ void AbilityAutoStartupClient::ResetProxy(wptr<IRemoteObject> remote)
auto serviceRemote = proxy_->AsObject();
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
HILOG_DEBUG("To remove death recipient.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "To remove death recipient.");
serviceRemote->RemoveDeathRecipient(deathRecipient_);
proxy_ = nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -19,6 +19,7 @@
#include <unistd.h>
#include "errors.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "nlohmann/json.hpp"
#include "types.h"
@ -60,11 +61,11 @@ DistributedKv::Status AbilityAutoStartupDataManager::GetKvStore()
DistributedKv::Status status = dataManager_.GetSingleKvStore(options, APP_ID, STORE_ID, kvStorePtr_);
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Return error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Return error: %{public}d.", status);
return status;
}
HILOG_DEBUG("Get kvStore success.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Get kvStore success.");
return status;
}
@ -79,7 +80,7 @@ bool AbilityAutoStartupDataManager::CheckKvStore()
if (status == DistributedKv::Status::SUCCESS && kvStorePtr_ != nullptr) {
return true;
}
HILOG_DEBUG("Try times: %{public}d.", tryTimes);
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Try times: %{public}d.", tryTimes);
usleep(CHECK_INTERVAL);
tryTimes--;
}
@ -90,16 +91,16 @@ int32_t AbilityAutoStartupDataManager::InsertAutoStartupData(
const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce)
{
if (info.bundleName.empty() || info.abilityName.empty()) {
HILOG_ERROR("Invalid value.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid value.");
return ERR_INVALID_VALUE;
}
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", info.bundleName.c_str(),
info.moduleName.c_str(), info.abilityName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
return ERR_NO_INIT;
}
}
@ -113,7 +114,7 @@ int32_t AbilityAutoStartupDataManager::InsertAutoStartupData(
}
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Insert data to kvStore error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Insert data to kvStore error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
return ERR_OK;
@ -123,16 +124,16 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData(
const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce)
{
if (info.bundleName.empty() || info.abilityName.empty()) {
HILOG_WARN("Invalid value!");
TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!");
return ERR_INVALID_VALUE;
}
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", info.bundleName.c_str(),
info.moduleName.c_str(), info.abilityName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
return ERR_NO_INIT;
}
}
@ -144,7 +145,7 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData(
status = kvStorePtr_->Delete(key);
}
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Delete data from kvStore error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Delete data from kvStore error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
DistributedKv::Value value = ConvertAutoStartupStatusToValue(isAutoStartup, isEdmForce, info.abilityTypeName);
@ -153,7 +154,7 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData(
status = kvStorePtr_->Put(key, value);
}
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Insert data to kvStore error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Insert data to kvStore error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
@ -163,16 +164,16 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData(
int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupInfo &info)
{
if (info.bundleName.empty() || info.abilityName.empty()) {
HILOG_WARN("Invalid value!");
TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!");
return ERR_INVALID_VALUE;
}
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", info.bundleName.c_str(),
info.moduleName.c_str(), info.abilityName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
return ERR_NO_INIT;
}
}
@ -185,7 +186,7 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupIn
}
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Delete data from kvStore error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Delete data from kvStore error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
return ERR_OK;
@ -194,15 +195,15 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupIn
int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &bundleName)
{
if (bundleName.empty()) {
HILOG_WARN("Invalid value!");
TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!");
return ERR_INVALID_VALUE;
}
HILOG_DEBUG("bundleName: %{public}s.", bundleName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s.", bundleName.c_str());
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
return ERR_NO_INIT;
}
}
@ -210,7 +211,7 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &
std::vector<DistributedKv::Entry> allEntries;
DistributedKv::Status status = kvStorePtr_->GetEntries(nullptr, allEntries);
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Get entries error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Get entries error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
@ -221,7 +222,7 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string &
status = kvStorePtr_->Delete(item.key);
}
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Delete data from kvStore error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Delete data from kvStore error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
}
@ -234,17 +235,17 @@ AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const Auto
{
AutoStartupStatus asustatus;
if (info.bundleName.empty() || info.abilityName.empty()) {
HILOG_WARN("Invalid value!");
TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Invalid value!");
asustatus.code = ERR_INVALID_VALUE;
return asustatus;
}
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", info.bundleName.c_str(),
info.moduleName.c_str(), info.abilityName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
asustatus.code = ERR_NO_INIT;
return asustatus;
}
@ -253,7 +254,7 @@ AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const Auto
std::vector<DistributedKv::Entry> allEntries;
DistributedKv::Status status = kvStorePtr_->GetEntries(nullptr, allEntries);
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Get entries error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Get entries error: %{public}d.", status);
asustatus.code = ERR_INVALID_OPERATION;
return asustatus;
}
@ -271,11 +272,11 @@ AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const Auto
int32_t AbilityAutoStartupDataManager::QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
return ERR_NO_INIT;
}
}
@ -283,7 +284,7 @@ int32_t AbilityAutoStartupDataManager::QueryAllAutoStartupApplications(std::vect
std::vector<DistributedKv::Entry> allEntries;
DistributedKv::Status status = kvStorePtr_->GetEntries(nullptr, allEntries);
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Get entries error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Get entries error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
@ -294,18 +295,18 @@ int32_t AbilityAutoStartupDataManager::QueryAllAutoStartupApplications(std::vect
infoList.emplace_back(ConvertAutoStartupInfoFromKeyAndValue(item.key, item.value));
}
}
HILOG_DEBUG("InfoList.size: %{public}zu.", infoList.size());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "InfoList.size: %{public}zu.", infoList.size());
return ERR_OK;
}
int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData(
const std::string &bundleName, std::vector<AutoStartupInfo> &infoList)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (!CheckKvStore()) {
HILOG_ERROR("kvStore is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore is nullptr.");
return ERR_NO_INIT;
}
}
@ -313,7 +314,7 @@ int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData(
std::vector<DistributedKv::Entry> allEntries;
DistributedKv::Status status = kvStorePtr_->GetEntries(nullptr, allEntries);
if (status != DistributedKv::Status::SUCCESS) {
HILOG_ERROR("Get entries error: %{public}d.", status);
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Get entries error: %{public}d.", status);
return ERR_INVALID_OPERATION;
}
@ -322,7 +323,7 @@ int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData(
infoList.emplace_back(ConvertAutoStartupInfoFromKeyAndValue(item.key, item.value));
}
}
HILOG_DEBUG("InfoList.size: %{public}zu.", infoList.size());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "InfoList.size: %{public}zu.", infoList.size());
return ERR_OK;
}
@ -335,7 +336,7 @@ DistributedKv::Value AbilityAutoStartupDataManager::ConvertAutoStartupStatusToVa
{ JSON_KEY_TYPE_NAME, abilityTypeName },
};
DistributedKv::Value value(jsonObject.dump());
HILOG_DEBUG("value: %{public}s.", value.ToString().c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "value: %{public}s.", value.ToString().c_str());
return value;
}
@ -344,7 +345,7 @@ void AbilityAutoStartupDataManager::ConvertAutoStartupStatusFromValue(
{
nlohmann::json jsonObject = nlohmann::json::parse(value.ToString(), nullptr, false);
if (jsonObject.is_discarded()) {
HILOG_ERROR("Failed to parse json string.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse json string.");
return;
}
if (jsonObject.contains(JSON_KEY_IS_AUTO_STARTUP) && jsonObject[JSON_KEY_IS_AUTO_STARTUP].is_boolean()) {
@ -363,7 +364,7 @@ DistributedKv::Key AbilityAutoStartupDataManager::ConvertAutoStartupDataToKey(co
{ JSON_KEY_ABILITY_NAME, info.abilityName },
};
DistributedKv::Key key(jsonObject.dump());
HILOG_DEBUG("key: %{public}s.", key.ToString().c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "key: %{public}s.", key.ToString().c_str());
return key;
}
@ -373,7 +374,7 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV
AutoStartupInfo info;
nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false);
if (jsonObject.is_discarded()) {
HILOG_ERROR("Failed to parse jsonObject.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse jsonObject.");
return info;
}
@ -391,7 +392,7 @@ AutoStartupInfo AbilityAutoStartupDataManager::ConvertAutoStartupInfoFromKeyAndV
nlohmann::json jsonValueObject = nlohmann::json::parse(value.ToString(), nullptr, false);
if (jsonValueObject.is_discarded()) {
HILOG_ERROR("Failed to parse jsonValueObject.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse jsonValueObject.");
return info;
}
@ -406,7 +407,7 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const
{
nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false);
if (jsonObject.is_discarded()) {
HILOG_ERROR("Failed to parse json string.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse json string.");
return false;
}
@ -435,7 +436,7 @@ bool AbilityAutoStartupDataManager::IsEqual(const DistributedKv::Key &key, const
{
nlohmann::json jsonObject = nlohmann::json::parse(key.ToString(), nullptr, false);
if (jsonObject.is_discarded()) {
HILOG_ERROR("Failed to parse json string.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse json string.");
return false;
}

View File

@ -24,6 +24,7 @@
#include "auto_startup_callback_proxy.h"
#include "auto_startup_info.h"
#include "auto_startup_interface.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "in_process_call_wrapper.h"
#include "ipc_skeleton.h"
@ -44,7 +45,7 @@ AbilityAutoStartupService::~AbilityAutoStartupService() {}
int32_t AbilityAutoStartupService::RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
int32_t code = CheckPermissionForSystem();
if (code != ERR_OK) {
return code;
@ -66,7 +67,7 @@ int32_t AbilityAutoStartupService::RegisterAutoStartupSystemCallback(const sptr<
SetDeathRecipient(
callback, new (std::nothrow) AbilityAutoStartupService::ClientDeathRecipient(weak_from_this()));
} else {
HILOG_DEBUG("Callback is already exist.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Callback is already exist.");
}
}
return ERR_OK;
@ -74,7 +75,7 @@ int32_t AbilityAutoStartupService::RegisterAutoStartupSystemCallback(const sptr<
int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
int32_t code = CheckPermissionForSystem();
if (code != ERR_OK) {
return code;
@ -93,7 +94,7 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt
}
}
if (!isFound) {
HILOG_DEBUG("Callback is not exist.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Callback is not exist.");
}
}
return ERR_OK;
@ -101,7 +102,7 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt
int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupInfo &info)
{
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
int32_t code = CheckPermissionForSystem();
if (code != ERR_OK) {
@ -111,12 +112,12 @@ int32_t AbilityAutoStartupService::SetApplicationAutoStartup(const AutoStartupIn
bool isVisible;
std::string abilityTypeName;
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
HILOG_ERROR("Failed to get ability data.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data.");
return INNER_ERR;
}
if (!isVisible) {
HILOG_ERROR("Current ability is not visible.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current ability is not visible.");
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
}
@ -131,13 +132,13 @@ int32_t AbilityAutoStartupService::InnerSetApplicationAutoStartup(const AutoStar
AutoStartupStatus status =
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) {
HILOG_ERROR("Query auto startup data failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Query auto startup data failed.");
return status.code;
}
int32_t result;
if (status.code == ERR_NAME_NOT_FOUND) {
HILOG_INFO("Query data is not exist.");
TAG_LOGI(AAFwkTag::AUTO_STARTUP, "Query data is not exist.");
result =
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->InsertAutoStartupData(info, true, false);
if (result == ERR_OK) {
@ -146,7 +147,7 @@ int32_t AbilityAutoStartupService::InnerSetApplicationAutoStartup(const AutoStar
return result;
}
if (status.isEdmForce) {
HILOG_ERROR("Edm application abnormal.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Edm application abnormal.");
return ERR_EDM_APP_CONTROLLED;
}
if (!status.isAutoStartup) {
@ -162,7 +163,7 @@ int32_t AbilityAutoStartupService::InnerSetApplicationAutoStartup(const AutoStar
int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartupInfo &info)
{
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
int32_t code = CheckPermissionForSystem();
if (code != ERR_OK) {
@ -172,12 +173,12 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartup(const AutoStartu
bool isVisible;
std::string abilityTypeName;
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
HILOG_ERROR("Failed to get ability data.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data.");
return INNER_ERR;
}
if (!isVisible) {
HILOG_ERROR("Current ability is not visible.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current ability is not visible.");
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
}
@ -192,12 +193,12 @@ int32_t AbilityAutoStartupService::InnerCancelApplicationAutoStartup(const AutoS
AutoStartupStatus status =
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
if (status.code != ERR_OK) {
HILOG_ERROR("Query auto startup data failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Query auto startup data failed.");
return status.code;
}
if (status.isEdmForce) {
HILOG_ERROR("Edm application abnormal.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Edm application abnormal.");
return ERR_EDM_APP_CONTROLLED;
}
@ -213,11 +214,11 @@ int32_t AbilityAutoStartupService::InnerCancelApplicationAutoStartup(const AutoS
int32_t AbilityAutoStartupService::QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
int32_t code = CheckPermissionForEDM();
code = code == ERR_OK ? code : CheckPermissionForSystem();
if (code != ERR_OK) {
HILOG_ERROR("Permission verification failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Permission verification failed.");
return code;
}
@ -227,9 +228,9 @@ int32_t AbilityAutoStartupService::QueryAllAutoStartupApplications(std::vector<A
int32_t AbilityAutoStartupService::QueryAllAutoStartupApplicationsWithoutPermission(
std::vector<AutoStartupInfo> &infoList)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
HILOG_ERROR("Product configuration item is disable.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Product configuration item is disable.");
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
}
@ -238,7 +239,7 @@ int32_t AbilityAutoStartupService::QueryAllAutoStartupApplicationsWithoutPermiss
int32_t AbilityAutoStartupService::DeleteAutoStartupData(const std::string &bundleName)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
return DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->DeleteAutoStartupData(bundleName);
}
@ -248,7 +249,7 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl
int32_t result = DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->GetCurrentAppAutoStartupData(
bundleName, infoList);
if (result != ERR_OK) {
HILOG_ERROR("Failed to get auto startup data.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get auto startup data.");
return result;
}
if (infoList.size() == 0) {
@ -272,7 +273,7 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl
}
if (!isFound) {
HILOG_DEBUG("Current bundleName not found in Datebase.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Current bundleName not found in Datebase.");
return DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->DeleteAutoStartupData(bundleName);
}
return ERR_OK;
@ -280,8 +281,8 @@ int32_t AbilityAutoStartupService::CheckAutoStartupData(const std::string &bundl
void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartupInfo &info)
{
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.", info.bundleName.c_str(),
info.moduleName.c_str(), info.abilityName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
for (auto item : callbackVector_) {
auto remoteSystemCallback = iface_cast<IAutoStartupCallBack>(item);
if (remoteSystemCallback != nullptr) {
@ -309,9 +310,9 @@ void AbilityAutoStartupService::ExecuteCallbacks(bool isCallOn, const AutoStartu
void AbilityAutoStartupService::SetDeathRecipient(
const sptr<IRemoteObject> &callback, const sptr<IRemoteObject::DeathRecipient> &deathRecipient)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
if (callback == nullptr || deathRecipient == nullptr) {
HILOG_ERROR("The callerToken or the deathRecipient is empty.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The callerToken or the deathRecipient is empty.");
return;
}
std::lock_guard<std::mutex> lock(deathRecipientsMutex_);
@ -321,15 +322,15 @@ void AbilityAutoStartupService::SetDeathRecipient(
callback->AddDeathRecipient(deathRecipient);
return;
}
HILOG_DEBUG("The deathRecipient has been added.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "The deathRecipient has been added.");
}
void AbilityAutoStartupService::CleanResource(const wptr<IRemoteObject> &remote)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
auto object = remote.promote();
if (object == nullptr) {
HILOG_ERROR("Remote object is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Remote object is nullptr.");
return;
}
@ -372,10 +373,10 @@ AbilityAutoStartupService::ClientDeathRecipient::ClientDeathRecipient(
void AbilityAutoStartupService::ClientDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
auto abilityAutoStartupService = weakPtr_.lock();
if (abilityAutoStartupService == nullptr) {
HILOG_ERROR("abilityAutoStartupService is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "abilityAutoStartupService is nullptr.");
return;
}
abilityAutoStartupService->CleanResource(remote);
@ -385,33 +386,33 @@ std::string AbilityAutoStartupService::GetSelfApplicationBundleName()
{
auto bundleMgrClient = GetBundleMgrClient();
if (bundleMgrClient == nullptr) {
HILOG_ERROR("Failed to get BundleMgrClient.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get BundleMgrClient.");
return "";
}
std::string bundleName;
int32_t callerUid = IPCSkeleton::GetCallingUid();
if (IN_PROCESS_CALL(bundleMgrClient->GetNameForUid(callerUid, bundleName)) != ERR_OK) {
HILOG_ERROR("Get Bundle Name failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Get Bundle Name failed.");
return "";
}
HILOG_DEBUG("Get bundle name: %{public}s.", bundleName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Get bundle name: %{public}s.", bundleName.c_str());
return bundleName;
}
bool AbilityAutoStartupService::CheckSelfApplication(const std::string &bundleName)
{
HILOG_DEBUG("Called, bundleName: %{public}s.", bundleName.c_str());
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s.", bundleName.c_str());
return GetSelfApplicationBundleName() == bundleName ? true : false;
}
bool AbilityAutoStartupService::GetBundleInfo(
const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo, int32_t uid)
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
auto bundleMgrClient = GetBundleMgrClient();
if (bundleMgrClient == nullptr) {
HILOG_ERROR("Failed to get BundleMgrClient.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get BundleMgrClient.");
return false;
}
@ -424,17 +425,17 @@ bool AbilityAutoStartupService::GetBundleInfo(
if (userId == 0) {
auto abilityMgr = DelayedSingleton<AbilityManagerService>::GetInstance();
if (abilityMgr == nullptr) {
HILOG_ERROR("The abilityMgr is nullptr.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The abilityMgr is nullptr.");
return false;
}
userId = abilityMgr->GetUserId();
}
HILOG_DEBUG("Current userId: %{public}d.", userId);
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Current userId: %{public}d.", userId);
auto flags =
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES | AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO;
if (!IN_PROCESS_CALL(bundleMgrClient->GetBundleInfo(
bundleName, static_cast<AppExecFwk::BundleFlag>(flags), bundleInfo, userId))) {
HILOG_ERROR("Failed to get bundle info.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get bundle info.");
return false;
}
@ -444,7 +445,7 @@ bool AbilityAutoStartupService::GetBundleInfo(
bool AbilityAutoStartupService::GetAbilityData(
const AutoStartupInfo &info, bool &isVisible, std::string &abilityTypeName)
{
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s.",
info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str());
AppExecFwk::BundleInfo bundleInfo;
if (!GetBundleInfo(info.bundleName, bundleInfo)) {
@ -456,7 +457,7 @@ bool AbilityAutoStartupService::GetAbilityData(
if (info.moduleName.empty() || (abilityInfo.moduleName == info.moduleName)) {
isVisible = abilityInfo.visible;
abilityTypeName = GetAbilityTypeName(abilityInfo);
HILOG_DEBUG("Get ability info success.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Get ability info success.");
return true;
}
}
@ -467,7 +468,7 @@ bool AbilityAutoStartupService::GetAbilityData(
if (info.moduleName.empty() || (extensionInfo.moduleName == info.moduleName)) {
isVisible = extensionInfo.visible;
abilityTypeName = GetExtensionTypeName(extensionInfo);
HILOG_DEBUG("Get extension info success.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Get extension info success.");
return true;
}
}
@ -495,7 +496,7 @@ std::string AbilityAutoStartupService::GetExtensionTypeName(AppExecFwk::Extensio
std::shared_ptr<AppExecFwk::BundleMgrClient> AbilityAutoStartupService::GetBundleMgrClient()
{
HILOG_DEBUG("Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
if (bundleMgrClient_ == nullptr) {
bundleMgrClient_ = DelayedSingleton<AppExecFwk::BundleMgrClient>::GetInstance();
}
@ -505,18 +506,18 @@ std::shared_ptr<AppExecFwk::BundleMgrClient> AbilityAutoStartupService::GetBundl
int32_t AbilityAutoStartupService::CheckPermissionForSystem()
{
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
HILOG_ERROR("Product configuration item is disable.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Product configuration item is disable.");
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
}
if (!PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
HILOG_ERROR("The caller is not system-app, can not use system-api.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The caller is not system-app, can not use system-api.");
return ERR_NOT_SYSTEM_APP;
}
if (!PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_MANAGE_APP_BOOT)) {
HILOG_ERROR("Not have PERMISSION_MANAGE_APP_BOOT approval.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Not have PERMISSION_MANAGE_APP_BOOT approval.");
return CHECK_PERMISSION_FAILED;
}
@ -526,12 +527,12 @@ int32_t AbilityAutoStartupService::CheckPermissionForSystem()
int32_t AbilityAutoStartupService::CheckPermissionForSelf(const std::string &bundleName)
{
if (!system::GetBoolParameter(PRODUCT_APPBOOT_SETTING_ENABLED, false)) {
HILOG_ERROR("Product configuration item is disable.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Product configuration item is disable.");
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
}
if (!CheckSelfApplication(bundleName)) {
HILOG_ERROR("Not self application.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Not self application.");
return ERR_NOT_SELF_APPLICATION;
}
return ERR_OK;
@ -541,12 +542,12 @@ int32_t AbilityAutoStartupService::GetAbilityInfo(const AutoStartupInfo &info, s
{
bool isVisible = false;
if (!GetAbilityData(info, isVisible, abilityTypeName)) {
HILOG_ERROR("Failed to get ability data.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get ability data.");
return INNER_ERR;
}
if (!isVisible) {
HILOG_ERROR("Current ability is not visible.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Current ability is not visible.");
return ABILITY_VISIBLE_FALSE_DENY_REQUEST;
}
@ -587,12 +588,13 @@ int32_t AbilityAutoStartupService::CancelApplicationAutoStartupByEDM(const AutoS
int32_t AbilityAutoStartupService::InnerApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool isSet, bool flag)
{
HILOG_DEBUG("Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, isSet: %{public}d.,"
TAG_LOGD(AAFwkTag::AUTO_STARTUP,
"Called, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s, isSet: %{public}d.,"
"flag: %{public}d.", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), isSet, flag);
AutoStartupStatus status =
DelayedSingleton<AbilityAutoStartupDataManager>::GetInstance()->QueryAutoStartupData(info);
if (status.code != ERR_OK && status.code != ERR_NAME_NOT_FOUND) {
HILOG_ERROR("Query auto startup data failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Query auto startup data failed.");
return status.code;
}
@ -628,7 +630,7 @@ int32_t AbilityAutoStartupService::CheckPermissionForEDM()
{
if (!PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_MANAGE_APP_BOOT_INTERNAL)) {
HILOG_ERROR("Not have ohos.permission.MANAGE_APP_BOOT_INTERNAL approval.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Not have ohos.permission.MANAGE_APP_BOOT_INTERNAL approval.");
return CHECK_PERMISSION_FAILED;
}
return ERR_OK;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -14,13 +14,14 @@
*/
#include "data_ability_caller_recipient.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AAFwk {
void DataAbilityCallerRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
HILOG_ERROR("recv DataAbilityCallerRecipient death notice");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "recv DataAbilityCallerRecipient death notice");
if (handler_) {
handler_(remote);
@ -29,12 +30,12 @@ void DataAbilityCallerRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
DataAbilityCallerRecipient::DataAbilityCallerRecipient(RemoteDiedHandler handler) : handler_(handler)
{
HILOG_ERROR("%{public}s", __func__);
TAG_LOGE(AAFwkTag::DATA_ABILITY, "%{public}s", __func__);
}
DataAbilityCallerRecipient::~DataAbilityCallerRecipient()
{
HILOG_ERROR("%{public}s", __func__);
TAG_LOGE(AAFwkTag::DATA_ABILITY, "%{public}s", __func__);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -21,6 +21,7 @@
#include "ability_manager_service.h"
#include "ability_util.h"
#include "connection_state_manager.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
@ -35,26 +36,26 @@ constexpr system_clock::duration DATA_ABILITY_LOAD_TIMEOUT = 11000ms;
DataAbilityManager::DataAbilityManager()
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
}
DataAbilityManager::~DataAbilityManager()
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
}
sptr<IAbilityScheduler> DataAbilityManager::Acquire(
const AbilityRequest &abilityRequest, bool tryBind, const sptr<IRemoteObject> &client, bool isNotHap)
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
if (abilityRequest.abilityInfo.type != AppExecFwk::AbilityType::DATA) {
HILOG_ERROR("Data ability manager acquire: not a data ability.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability manager acquire: not a data ability.");
return nullptr;
}
if (abilityRequest.abilityInfo.bundleName.empty() || abilityRequest.abilityInfo.name.empty()) {
HILOG_ERROR("Data ability manager acquire: invalid name.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability manager acquire: invalid name.");
return nullptr;
}
@ -64,13 +65,13 @@ sptr<IAbilityScheduler> DataAbilityManager::Acquire(
if (client && !isNotHap) {
clientAbilityRecord = Token::GetAbilityRecordByToken(client);
if (!clientAbilityRecord) {
HILOG_ERROR("Data ability manager acquire: invalid client token.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability manager acquire: invalid client token.");
return nullptr;
}
HILOG_INFO("Ability '%{public}s' acquiring data ability '%{public}s'...",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Ability '%{public}s' acquiring data ability '%{public}s'...",
clientAbilityRecord->GetAbilityInfo().name.c_str(), dataAbilityName.c_str());
} else {
HILOG_INFO("Loading data ability '%{public}s'...", dataAbilityName.c_str());
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Loading data ability '%{public}s'...", dataAbilityName.c_str());
}
std::lock_guard<ffrt::mutex> locker(mutex_);
@ -83,22 +84,23 @@ sptr<IAbilityScheduler> DataAbilityManager::Acquire(
auto it = dataAbilityRecordsLoaded_.find(dataAbilityName);
if (it == dataAbilityRecordsLoaded_.end()) {
HILOG_DEBUG("Acquiring data ability is not existed, loading...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Acquiring data ability is not existed, loading...");
dataAbilityRecord = LoadLocked(dataAbilityName, abilityRequest);
} else {
HILOG_DEBUG("Acquiring data ability is existed .");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Acquiring data ability is existed .");
dataAbilityRecord = it->second;
}
if (!dataAbilityRecord) {
HILOG_ERROR("Failed to load data ability '%{public}s'.", dataAbilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Failed to load data ability '%{public}s'.", dataAbilityName.c_str());
return nullptr;
}
auto scheduler = dataAbilityRecord->GetScheduler();
if (!scheduler) {
if (DEBUG_ENABLED) {
HILOG_ERROR("BUG: data ability '%{public}s' is not loaded, removing it...", dataAbilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "BUG: data ability '%{public}s' is not loaded, removing it...",
dataAbilityName.c_str());
}
auto it = dataAbilityRecordsLoaded_.find(dataAbilityName);
if (it != dataAbilityRecordsLoaded_.end()) {
@ -123,7 +125,7 @@ sptr<IAbilityScheduler> DataAbilityManager::Acquire(
int DataAbilityManager::Release(
const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &client, bool isNotHap)
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT);
CHECK_POINTER_AND_RETURN(client, ERR_NULL_OBJECT);
@ -140,13 +142,13 @@ int DataAbilityManager::Release(
if (it->second && it->second->GetScheduler() &&
it->second->GetScheduler()->AsObject() == scheduler->AsObject()) {
dataAbilityRecord = it->second;
HILOG_INFO("Releasing data ability '%{public}s'...", it->first.c_str());
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Releasing data ability '%{public}s'...", it->first.c_str());
break;
}
}
if (!dataAbilityRecord) {
HILOG_ERROR("Releasing not existed data ability.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Releasing not existed data ability.");
return ERR_UNKNOWN_OBJECT;
}
@ -156,12 +158,12 @@ int DataAbilityManager::Release(
CHECK_POINTER_AND_RETURN(abilityMs, GET_ABILITY_SERVICE_FAILED);
int result = abilityMs->JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo());
if (result != ERR_OK) {
HILOG_ERROR("JudgeAbilityVisibleControl error.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "JudgeAbilityVisibleControl error.");
return result;
}
if (dataAbilityRecord->GetClientCount(client) == 0) {
HILOG_ERROR("Release data ability with wrong client.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Release data ability with wrong client.");
return ERR_UNKNOWN_OBJECT;
}
@ -178,7 +180,7 @@ int DataAbilityManager::Release(
bool DataAbilityManager::ContainsDataAbility(const sptr<IAbilityScheduler> &scheduler)
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT);
@ -195,7 +197,7 @@ bool DataAbilityManager::ContainsDataAbility(const sptr<IAbilityScheduler> &sche
int DataAbilityManager::AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token)
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT);
CHECK_POINTER_AND_RETURN(token, ERR_NULL_OBJECT);
@ -206,7 +208,7 @@ int DataAbilityManager::AttachAbilityThread(const sptr<IAbilityScheduler> &sched
DumpLocked(__func__, __LINE__);
}
HILOG_INFO("Attaching data ability...");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Attaching data ability...");
auto record = Token::GetAbilityRecordByToken(token);
std::string abilityName = "";
@ -224,20 +226,22 @@ int DataAbilityManager::AttachAbilityThread(const sptr<IAbilityScheduler> &sched
}
if (!dataAbilityRecord) {
HILOG_ERROR("Attaching data ability '%{public}s' is not in loading state.", abilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Attaching data ability '%{public}s' is not in loading state.",
abilityName.c_str());
return ERR_UNKNOWN_OBJECT;
}
if (DEBUG_ENABLED && dataAbilityRecord->GetClientCount() > 0) {
HILOG_ERROR("BUG: Attaching data ability '%{public}s' has clients.", abilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "BUG: Attaching data ability '%{public}s' has clients.", abilityName.c_str());
}
if (DEBUG_ENABLED && dataAbilityRecord->GetScheduler()) {
HILOG_ERROR("BUG: Attaching data ability '%{public}s' has ready.", abilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "BUG: Attaching data ability '%{public}s' has ready.", abilityName.c_str());
}
if (DEBUG_ENABLED && dataAbilityRecordsLoaded_.count(it->first) != 0) {
HILOG_ERROR("BUG: The attaching data ability '%{public}s' has already existed.", abilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "BUG: The attaching data ability '%{public}s' has already existed.",
abilityName.c_str());
}
return dataAbilityRecord->Attach(scheduler);
@ -245,7 +249,7 @@ int DataAbilityManager::AttachAbilityThread(const sptr<IAbilityScheduler> &sched
int DataAbilityManager::AbilityTransitionDone(const sptr<IRemoteObject> &token, int state)
{
HILOG_DEBUG("Call");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call");
CHECK_POINTER_AND_RETURN(token, ERR_NULL_OBJECT);
@ -255,7 +259,7 @@ int DataAbilityManager::AbilityTransitionDone(const sptr<IRemoteObject> &token,
DumpLocked(__func__, __LINE__);
}
HILOG_INFO("Handling data ability transition done %{public}d...", state);
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Handling data ability transition done %{public}d...", state);
DataAbilityRecordPtrMap::iterator it;
DataAbilityRecordPtr dataAbilityRecord;
@ -271,7 +275,7 @@ int DataAbilityManager::AbilityTransitionDone(const sptr<IRemoteObject> &token,
}
}
if (!dataAbilityRecord) {
HILOG_ERROR("Attaching data ability '%{public}s' is not existed.", abilityName.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Attaching data ability '%{public}s' is not existed.", abilityName.c_str());
return ERR_UNKNOWN_OBJECT;
}
@ -291,7 +295,7 @@ void DataAbilityManager::OnAbilityRequestDone(const sptr<IRemoteObject> &token,
void DataAbilityManager::OnAbilityDied(const std::shared_ptr<AbilityRecord> &abilityRecord)
{
HILOG_INFO("Call");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Call");
CHECK_POINTER(abilityRecord);
{
@ -305,7 +309,7 @@ void DataAbilityManager::OnAbilityDied(const std::shared_ptr<AbilityRecord> &abi
if (it->second && it->second->GetAbilityRecord() == abilityRecord) {
DelayedSingleton<ConnectionStateManager>::GetInstance()->HandleDataAbilityDied(it->second);
it->second->KillBoundClientProcesses();
HILOG_DEBUG("Removing died data ability record...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Removing died data ability record...");
it = dataAbilityRecordsLoaded_.erase(it);
break;
} else {
@ -373,7 +377,7 @@ void DataAbilityManager::OnAppStateChanged(const AppInfo &info)
std::shared_ptr<AbilityRecord> DataAbilityManager::GetAbilityRecordById(int64_t id)
{
HILOG_DEBUG("Call.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call.");
std::lock_guard<ffrt::mutex> locker(mutex_);
@ -392,7 +396,7 @@ std::shared_ptr<AbilityRecord> DataAbilityManager::GetAbilityRecordById(int64_t
std::shared_ptr<AbilityRecord> DataAbilityManager::GetAbilityRecordByToken(const sptr<IRemoteObject> &token)
{
HILOG_DEBUG("Call.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call.");
CHECK_POINTER_AND_RETURN(token, nullptr);
@ -420,7 +424,7 @@ std::shared_ptr<AbilityRecord> DataAbilityManager::GetAbilityRecordByToken(const
std::shared_ptr<AbilityRecord> DataAbilityManager::GetAbilityRecordByScheduler(const sptr<IAbilityScheduler> &scheduler)
{
HILOG_DEBUG("Call.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call.");
CHECK_POINTER_AND_RETURN(scheduler, nullptr);
@ -438,7 +442,7 @@ std::shared_ptr<AbilityRecord> DataAbilityManager::GetAbilityRecordByScheduler(c
void DataAbilityManager::Dump(const char *func, int line)
{
HILOG_DEBUG("Call.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Call.");
std::lock_guard<ffrt::mutex> locker(mutex_);
@ -448,43 +452,43 @@ void DataAbilityManager::Dump(const char *func, int line)
DataAbilityManager::DataAbilityRecordPtr DataAbilityManager::LoadLocked(
const std::string &name, const AbilityRequest &req)
{
HILOG_DEBUG("name '%{public}s'", name.c_str());
TAG_LOGD(AAFwkTag::DATA_ABILITY, "name '%{public}s'", name.c_str());
DataAbilityRecordPtr dataAbilityRecord;
auto it = dataAbilityRecordsLoading_.find(name);
if (it == dataAbilityRecordsLoading_.end()) {
HILOG_INFO("Acquiring data ability is not in loading, trying to load it...");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Acquiring data ability is not in loading, trying to load it...");
dataAbilityRecord = std::make_shared<DataAbilityRecord>(req);
// Start data ability loading process asynchronously.
int startResult = dataAbilityRecord->StartLoading();
if (startResult != ERR_OK) {
HILOG_ERROR("Failed to load data ability %{public}d", startResult);
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Failed to load data ability %{public}d", startResult);
return nullptr;
}
auto insertResult = dataAbilityRecordsLoading_.insert({name, dataAbilityRecord});
if (!insertResult.second) {
HILOG_ERROR("Failed to insert data ability to loading map.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Failed to insert data ability to loading map.");
return nullptr;
}
} else {
HILOG_INFO("Acquired data ability is loading...");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Acquired data ability is loading...");
dataAbilityRecord = it->second;
}
if (!dataAbilityRecord) {
HILOG_ERROR("Failed to load data ability '%{public}s'.", name.c_str());
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Failed to load data ability '%{public}s'.", name.c_str());
return nullptr;
}
HILOG_INFO("Waiting for data ability loaded...");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Waiting for data ability loaded...");
// Waiting for data ability loaded.
int ret = dataAbilityRecord->WaitForLoaded(mutex_, DATA_ABILITY_LOAD_TIMEOUT);
if (ret != ERR_OK) {
HILOG_ERROR("Wait for data ability failed %{public}d.", ret);
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Wait for data ability failed %{public}d.", ret);
it = dataAbilityRecordsLoading_.find(name);
if (it != dataAbilityRecordsLoading_.end()) {
dataAbilityRecordsLoading_.erase(it);
@ -499,24 +503,24 @@ DataAbilityManager::DataAbilityRecordPtr DataAbilityManager::LoadLocked(
void DataAbilityManager::DumpLocked(const char *func, int line)
{
if (func && line >= 0) {
HILOG_INFO("Data ability manager dump at %{public}s(%{public}d)", func, line);
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Data ability manager dump at %{public}s(%{public}d)", func, line);
} else {
HILOG_INFO("Data ability manager dump");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Data ability manager dump");
}
HILOG_INFO("Available data ability count: %{public}zu", dataAbilityRecordsLoaded_.size());
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Available data ability count: %{public}zu", dataAbilityRecordsLoaded_.size());
for (auto it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) {
HILOG_INFO("'%{public}s':", it->first.c_str());
TAG_LOGI(AAFwkTag::DATA_ABILITY, "'%{public}s':", it->first.c_str());
if (it->second) {
it->second->Dump();
}
}
HILOG_INFO("Loading data ability count: %{public}zu", dataAbilityRecordsLoading_.size());
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Loading data ability count: %{public}zu", dataAbilityRecordsLoading_.size());
for (auto it = dataAbilityRecordsLoading_.begin(); it != dataAbilityRecordsLoading_.end(); ++it) {
HILOG_INFO("'%{public}s':", it->first.c_str());
TAG_LOGI(AAFwkTag::DATA_ABILITY, "'%{public}s':", it->first.c_str());
if (it->second) {
it->second->Dump();
}
@ -600,7 +604,7 @@ void DataAbilityManager::DumpSysState(std::vector<std::string> &info, bool isCli
void DataAbilityManager::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm)
{
HILOG_INFO("Get ability running infos");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Get ability running infos");
std::lock_guard<ffrt::mutex> locker(mutex_);
auto queryInfo = [&info, isPerm](DataAbilityRecordPtrMap::reference data) {
@ -638,7 +642,7 @@ void DataAbilityManager::RestartDataAbility(const std::shared_ptr<AbilityRecord>
bool getBundleInfos = bundleMgrHelper->GetBundleInfos(
OHOS::AppExecFwk::GET_BUNDLE_DEFAULT, bundleInfos, USER_ID_NO_HEAD);
if (!getBundleInfos) {
HILOG_ERROR("Handle ability died task, get bundle infos failed.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Handle ability died task, get bundle infos failed.");
return;
}
@ -661,7 +665,7 @@ void DataAbilityManager::RestartDataAbility(const std::shared_ptr<AbilityRecord>
bool getDataAbilityUri = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetDataAbilityUri(
hapModuleInfo.abilityInfos, mainElement, uriStr);
if (getDataAbilityUri) {
HILOG_INFO("restart data ability: %{public}s, uri: %{public}s.",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "restart data ability: %{public}s, uri: %{public}s.",
abilityRecord->GetAbilityInfo().name.c_str(), uriStr.c_str());
Uri uri(uriStr);
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->AcquireDataAbility(uri, true, nullptr);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -21,47 +21,48 @@
#include "ability_util.h"
#include "app_scheduler.h"
#include "connection_state_manager.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AAFwk {
DataAbilityRecord::DataAbilityRecord(const AbilityRequest &req) : request_(req)
{
HILOG_DEBUG("%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
TAG_LOGD(AAFwkTag::DATA_ABILITY, "%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
if (request_.abilityInfo.type != AppExecFwk::AbilityType::DATA) {
HILOG_ERROR("BUG: Construct a data ability with wrong ability type.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "BUG: Construct a data ability with wrong ability type.");
}
}
DataAbilityRecord::~DataAbilityRecord()
{
HILOG_DEBUG("%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
TAG_LOGD(AAFwkTag::DATA_ABILITY, "%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
}
int DataAbilityRecord::StartLoading()
{
HILOG_INFO("Start data ability loading...");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Start data ability loading...");
if (ability_ || scheduler_) {
HILOG_ERROR("Data ability already started.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability already started.");
return ERR_ALREADY_EXISTS;
}
if (request_.abilityInfo.type != AppExecFwk::AbilityType::DATA) {
HILOG_ERROR("Start a data ability with wrong ability type.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Start a data ability with wrong ability type.");
return ERR_INVALID_VALUE;
}
auto ability = AbilityRecord::CreateAbilityRecord(request_);
if (!ability) {
HILOG_ERROR("Failed to allocate ability for DataAbilityRecord.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Failed to allocate ability for DataAbilityRecord.");
return ERR_NO_MEMORY;
}
int ret = ability->LoadAbility();
if (ret != ERR_OK) {
HILOG_ERROR("Failed to start data ability loading.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Failed to start data ability loading.");
return ret;
}
@ -110,35 +111,35 @@ sptr<IAbilityScheduler> DataAbilityRecord::GetScheduler()
int DataAbilityRecord::Attach(const sptr<IAbilityScheduler> &scheduler)
{
HILOG_DEBUG("%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
TAG_LOGD(AAFwkTag::DATA_ABILITY, "%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
if (!scheduler) {
HILOG_ERROR("Attach data ability: invalid scheduler.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Attach data ability: invalid scheduler.");
return ERR_INVALID_DATA;
}
if (!ability_) {
HILOG_ERROR("Data ability attach: not startloading.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability attach: not startloading.");
return ERR_INVALID_STATE;
}
if (scheduler_) {
HILOG_ERROR("Attach data ability: already attached.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Attach data ability: already attached.");
return ERR_INVALID_STATE;
}
// INITIAL => ACTIVATING
if (ability_->GetAbilityState() != INITIAL) {
HILOG_ERROR("Attaching data ability: not in 'INITIAL' state.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Attaching data ability: not in 'INITIAL' state.");
return ERR_INVALID_STATE;
}
HILOG_DEBUG("Attaching data ability...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Attaching data ability...");
ability_->SetScheduler(scheduler);
scheduler_ = scheduler;
HILOG_INFO("Scheduling 'OnStart' for data ability '%{public}s|%{public}s'...",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Scheduling 'OnStart' for data ability '%{public}s|%{public}s'...",
ability_->GetApplicationInfo().bundleName.c_str(),
ability_->GetAbilityInfo().name.c_str());
@ -158,12 +159,12 @@ int DataAbilityRecord::OnTransitionDone(int state)
CHECK_POINTER_AND_RETURN(scheduler_, ERR_INVALID_STATE);
if (ability_->GetAbilityState() != ACTIVATING) {
HILOG_ERROR("Data ability on transition done: not in 'ACTIVATING' state.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability on transition done: not in 'ACTIVATING' state.");
return ERR_INVALID_STATE;
}
if (state != AbilityLifeCycleState::ABILITY_STATE_ACTIVE) {
HILOG_ERROR("Data ability on transition done: not ACTIVE.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability on transition done: not ACTIVE.");
ability_->SetAbilityState(INITIAL);
loadedCond_.notify_all();
return ERR_INVALID_STATE;
@ -175,7 +176,7 @@ int DataAbilityRecord::OnTransitionDone(int state)
ability_->SetAbilityState(ACTIVE);
loadedCond_.notify_all();
HILOG_INFO("Data ability '%{public}s|%{public}s' is loaded.",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Data ability '%{public}s|%{public}s' is loaded.",
ability_->GetApplicationInfo().bundleName.c_str(),
ability_->GetAbilityInfo().name.c_str());
@ -185,27 +186,27 @@ int DataAbilityRecord::OnTransitionDone(int state)
int DataAbilityRecord::AddClient(const sptr<IRemoteObject> &client, bool tryBind, bool isNotHap)
{
if (!client) {
HILOG_ERROR("Data ability add client: invalid param.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability add client: invalid param.");
return ERR_INVALID_STATE;
}
if (!ability_ || !scheduler_) {
HILOG_ERROR("Data ability add client: not attached.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability add client: not attached.");
return ERR_INVALID_STATE;
}
if (ability_->GetAbilityState() != ACTIVE) {
HILOG_ERROR("Data ability add client: not loaded.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability add client: not loaded.");
return ERR_INVALID_STATE;
}
auto appScheduler = DelayedSingleton<AppScheduler>::GetInstance();
if (!appScheduler) {
HILOG_ERROR("Data ability add client: failed to get app scheduler.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability add client: failed to get app scheduler.");
return ERR_NULL_OBJECT;
}
HILOG_INFO("add death monitoring for data ability caller.");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "add death monitoring for data ability caller.");
if (client != nullptr && callerDeathRecipient_ != nullptr) {
client->RemoveDeathRecipient(callerDeathRecipient_);
}
@ -234,32 +235,32 @@ int DataAbilityRecord::AddClient(const sptr<IRemoteObject> &client, bool tryBind
int DataAbilityRecord::RemoveClient(const sptr<IRemoteObject> &client, bool isNotHap)
{
HILOG_INFO("Removing data ability client...");
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Removing data ability client...");
if (!client) {
HILOG_ERROR("Data ability remove client: invalid client.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove client: invalid client.");
return ERR_INVALID_STATE;
}
if (!ability_ || !scheduler_) {
HILOG_ERROR("Data ability remove clients: not attached.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove clients: not attached.");
return ERR_INVALID_STATE;
}
if (ability_->GetAbilityState() != ACTIVE) {
HILOG_ERROR("Data ability remove client: not loaded.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove client: not loaded.");
return ERR_INVALID_STATE;
}
if (clients_.empty()) {
HILOG_DEBUG("BUG: Data ability record has no clients.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "BUG: Data ability record has no clients.");
return ERR_OK;
}
for (auto it(clients_.begin()); it != clients_.end(); ++it) {
if (it->client == client) {
clients_.erase(it);
HILOG_INFO("Data ability '%{public}s|%{public}s'.",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Data ability '%{public}s|%{public}s'.",
ability_->GetApplicationInfo().bundleName.c_str(),
ability_->GetAbilityInfo().name.c_str());
break;
@ -271,37 +272,37 @@ int DataAbilityRecord::RemoveClient(const sptr<IRemoteObject> &client, bool isNo
int DataAbilityRecord::RemoveClients(const std::shared_ptr<AbilityRecord> &client)
{
HILOG_DEBUG("%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
TAG_LOGD(AAFwkTag::DATA_ABILITY, "%{public}s(%{public}d)", __PRETTY_FUNCTION__, __LINE__);
if (!ability_ || !scheduler_) {
HILOG_ERROR("Data ability remove clients: not attached.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove clients: not attached.");
return ERR_INVALID_STATE;
}
if (ability_->GetAbilityState() != ACTIVE) {
HILOG_ERROR("Data ability remove clients: not loaded.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove clients: not loaded.");
return ERR_INVALID_STATE;
}
if (clients_.empty()) {
HILOG_DEBUG("Data ability remove clients: no clients.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Data ability remove clients: no clients.");
return ERR_OK;
}
auto appScheduler = DelayedSingleton<AppScheduler>::GetInstance();
if (!appScheduler) {
HILOG_ERROR("Data ability remove clients: invalid app scheduler.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove clients: invalid app scheduler.");
return ERR_NULL_OBJECT;
}
if (client) {
HILOG_DEBUG("Removing data ability clients with filter...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Removing data ability clients with filter...");
auto it = clients_.begin();
while (it != clients_.end()) {
if (!it->isNotHap) {
auto clientAbilityRecord = Token::GetAbilityRecordByToken(it->client);
if (!clientAbilityRecord) {
HILOG_ERROR("clientAbilityRecord is nullptr, continue.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "clientAbilityRecord is nullptr, continue.");
++it;
continue;
}
@ -309,7 +310,8 @@ int DataAbilityRecord::RemoveClients(const std::shared_ptr<AbilityRecord> &clien
appScheduler->AbilityBehaviorAnalysis(
ability_->GetToken(), clientAbilityRecord->GetToken(), 0, 0, 0);
it = clients_.erase(it);
HILOG_INFO("Ability '%{public}s|%{public}s' --X-> Data ability '%{public}s|%{public}s'.",
TAG_LOGI(AAFwkTag::DATA_ABILITY,
"Ability '%{public}s|%{public}s' --X-> Data ability '%{public}s|%{public}s'.",
client->GetApplicationInfo().bundleName.c_str(),
client->GetAbilityInfo().name.c_str(),
ability_->GetApplicationInfo().bundleName.c_str(),
@ -322,13 +324,13 @@ int DataAbilityRecord::RemoveClients(const std::shared_ptr<AbilityRecord> &clien
}
}
} else {
HILOG_DEBUG("Removing data ability clients...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "Removing data ability clients...");
auto it = clients_.begin();
while (it != clients_.end()) {
if (!it->isNotHap) {
auto clientAbilityRecord = Token::GetAbilityRecordByToken(it->client);
if (!clientAbilityRecord) {
HILOG_DEBUG("clientAbilityRecord is null,clear record");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "clientAbilityRecord is null,clear record");
it = clients_.erase(it);
continue;
}
@ -349,7 +351,7 @@ size_t DataAbilityRecord::GetClientCount(const sptr<IRemoteObject> &client) cons
CHECK_POINTER_AND_RETURN(scheduler_, 0);
if (ability_->GetAbilityState() != ACTIVE) {
HILOG_ERROR("Data ability get client count: not loaded.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability get client count: not loaded.");
return 0;
}
@ -367,13 +369,13 @@ int DataAbilityRecord::KillBoundClientProcesses()
CHECK_POINTER_AND_RETURN(scheduler_, ERR_INVALID_STATE);
if (ability_->GetAbilityState() != ACTIVE) {
HILOG_ERROR("Data ability kill bound clients: not loaded.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability kill bound clients: not loaded.");
return ERR_INVALID_STATE;
}
auto appScheduler = DelayedSingleton<AppScheduler>::GetInstance();
if (!appScheduler) {
HILOG_ERROR("Data ability kill bound clients: invalid app scheduler.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability kill bound clients: invalid app scheduler.");
return ERR_INVALID_STATE;
}
@ -381,7 +383,8 @@ int DataAbilityRecord::KillBoundClientProcesses()
if (it->tryBind && it->isNotHap == false) {
auto clientAbilityRecord = Token::GetAbilityRecordByToken(it->client);
CHECK_POINTER_CONTINUE(clientAbilityRecord);
HILOG_INFO("Killing bound client '%{public}s|%{public}s' of data ability '%{public}s|%{public}s'...",
TAG_LOGI(AAFwkTag::DATA_ABILITY,
"Killing bound client '%{public}s|%{public}s' of data ability '%{public}s|%{public}s'...",
clientAbilityRecord->GetApplicationInfo().bundleName.c_str(),
clientAbilityRecord->GetAbilityInfo().name.c_str(),
ability_->GetApplicationInfo().bundleName.c_str(),
@ -416,7 +419,8 @@ void DataAbilityRecord::Dump() const
{
CHECK_POINTER(ability_);
HILOG_INFO("attached: %{public}s, clients: %{public}zu, refcnt: %{public}d, state: %{public}s",
TAG_LOGI(AAFwkTag::DATA_ABILITY,
"attached: %{public}s, clients: %{public}zu, refcnt: %{public}d, state: %{public}s",
scheduler_ ? "true" : "false",
clients_.size(),
scheduler_ ? scheduler_->GetSptrRefCount() : 0,
@ -428,13 +432,13 @@ void DataAbilityRecord::Dump() const
if (it->isNotHap == false) {
auto clientAbilityRecord = Token::GetAbilityRecordByToken(it->client);
CHECK_POINTER_CONTINUE(clientAbilityRecord);
HILOG_INFO(" %{public}2d '%{public}s|%{public}s' - tryBind: %{public}s",
TAG_LOGI(AAFwkTag::DATA_ABILITY, " %{public}2d '%{public}s|%{public}s' - tryBind: %{public}s",
i++,
clientAbilityRecord->GetApplicationInfo().bundleName.c_str(),
clientAbilityRecord->GetAbilityInfo().name.c_str(),
it->tryBind ? "true" : "false");
} else {
HILOG_INFO(" %{public}2d '%{public}s' - tryBind: %{public}s",
TAG_LOGI(AAFwkTag::DATA_ABILITY, " %{public}2d '%{public}s' - tryBind: %{public}s",
i++,
"caller is system",
it->tryBind ? "true" : "false");
@ -472,18 +476,18 @@ void DataAbilityRecord::Dump(std::vector<std::string> &info) const
void DataAbilityRecord::OnSchedulerDied(const wptr<IRemoteObject> &remote)
{
HILOG_INFO("'%{public}s':", __func__);
TAG_LOGI(AAFwkTag::DATA_ABILITY, "'%{public}s':", __func__);
auto object = remote.promote();
DelayedSingleton<ConnectionStateManager>::GetInstance()->HandleDataAbilityCallerDied(GetDiedCallerPid(object));
if (clients_.empty()) {
HILOG_DEBUG("BUG: Data ability record has no clients.");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "BUG: Data ability record has no clients.");
return;
}
auto appScheduler = DelayedSingleton<AppScheduler>::GetInstance();
if (!appScheduler) {
HILOG_ERROR("Data ability remove clients: invalid app scheduler.");
TAG_LOGE(AAFwkTag::DATA_ABILITY, "Data ability remove clients: invalid app scheduler.");
return;
}
@ -491,9 +495,9 @@ void DataAbilityRecord::OnSchedulerDied(const wptr<IRemoteObject> &remote)
auto it = clients_.begin();
while (it != clients_.end()) {
if (it->client == object) {
HILOG_DEBUG("remove system caller record with filter...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "remove system caller record with filter...");
it = clients_.erase(it);
HILOG_INFO("Data ability '%{public}s|%{public}s'.",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Data ability '%{public}s|%{public}s'.",
ability_->GetApplicationInfo().bundleName.c_str(),
ability_->GetAbilityInfo().name.c_str());
} else {
@ -504,9 +508,9 @@ void DataAbilityRecord::OnSchedulerDied(const wptr<IRemoteObject> &remote)
auto it = clients_.begin();
while (it != clients_.end()) {
if (it->isNotHap) {
HILOG_DEBUG("remove system caller record...");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "remove system caller record...");
it = clients_.erase(it);
HILOG_INFO("Data ability '%{public}s|%{public}s'.",
TAG_LOGI(AAFwkTag::DATA_ABILITY, "Data ability '%{public}s|%{public}s'.",
ability_->GetApplicationInfo().bundleName.c_str(),
ability_->GetAbilityInfo().name.c_str());
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -24,6 +24,7 @@
#include "atomic_service_status_callback.h"
#include "distributed_client.h"
#include "free_install_observer_manager.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "in_process_call_wrapper.h"
@ -45,24 +46,24 @@ FreeInstallManager::FreeInstallManager(const std::weak_ptr<AbilityManagerService
bool FreeInstallManager::IsTopAbility(const sptr<IRemoteObject> &callerToken)
{
HILOG_INFO("%{public}s", __func__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s", __func__);
auto server = server_.lock();
CHECK_POINTER_AND_RETURN_LOG(server, false, "Get server failed!");
AppExecFwk::ElementName elementName = IN_PROCESS_CALL(server->GetTopAbility());
if (elementName.GetBundleName().empty() || elementName.GetAbilityName().empty()) {
HILOG_ERROR("GetBundleName or GetAbilityName empty!");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "GetBundleName or GetAbilityName empty!");
return false;
}
auto caller = Token::GetAbilityRecordByToken(callerToken);
if (caller == nullptr) {
HILOG_ERROR("Caller is null!");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Caller is null!");
return false;
}
auto type = caller->GetAbilityInfo().type;
if (type == AppExecFwk::AbilityType::SERVICE || type == AppExecFwk::AbilityType::EXTENSION) {
HILOG_INFO("The ability is service or extension ability.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The ability is service or extension ability.");
return true;
}
@ -73,7 +74,7 @@ bool FreeInstallManager::IsTopAbility(const sptr<IRemoteObject> &callerToken)
if (elementName.GetBundleName().compare(callerBundleName) == 0 &&
elementName.GetAbilityName().compare(callerAbilityName) == 0 &&
elementName.GetModuleName().compare(callerModuleName) == 0) {
HILOG_INFO("The ability is top ability.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The ability is top ability.");
return true;
}
@ -84,7 +85,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
const sptr<IRemoteObject> &callerToken, bool isAsync)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_INFO("StartFreeInstall called");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "StartFreeInstall called");
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall && !IsTopAbility(callerToken)) {
return NOT_TOP_ABILITY;
@ -105,12 +106,12 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
PostTimeoutTask(want);
}
if (IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(info.want, flag, info.userId, abilityInfo, callback))) {
HILOG_INFO("The app has installed.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The app has installed.");
}
std::string callingAppId = info.want.GetStringParam(PARAM_FREEINSTALL_APPID);
std::vector<std::string> callingBundleNames = info.want.GetStringArrayParam(PARAM_FREEINSTALL_BUNDLENAMES);
if (callingAppId.empty() && callingBundleNames.empty()) {
HILOG_INFO("callingAppId and callingBundleNames are empty");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "callingAppId and callingBundleNames are empty");
}
info.want.RemoveParam(PARAM_FREEINSTALL_APPID);
info.want.RemoveParam(PARAM_FREEINSTALL_BUNDLENAMES);
@ -132,7 +133,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int requestCode,
const sptr<IRemoteObject> &callerToken)
{
HILOG_INFO("RemoteFreeInstall called");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "RemoteFreeInstall called");
bool isFromRemote = want.GetBoolParam(FROM_REMOTE_KEY, false);
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall && !isFromRemote && !IsTopAbility(callerToken)) {
@ -182,9 +183,9 @@ FreeInstallInfo FreeInstallManager::BuildFreeInstallInfo(const Want &want, int32
int FreeInstallManager::StartRemoteFreeInstall(const Want &want, int requestCode, int32_t validUserId,
const sptr<IRemoteObject> &callerToken)
{
HILOG_INFO("%{public}s", __func__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s", __func__);
if (!want.GetBoolParam(Want::PARAM_RESV_FOR_RESULT, false)) {
HILOG_INFO("%{public}s: StartAbility freeInstall", __func__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s: StartAbility freeInstall", __func__);
return RemoteFreeInstall(want, validUserId, requestCode, callerToken);
}
int32_t missionId = DelayedSingleton<AbilityManagerService>::GetInstance()->
@ -194,7 +195,7 @@ int FreeInstallManager::StartRemoteFreeInstall(const Want &want, int requestCode
}
Want* newWant = const_cast<Want*>(&want);
newWant->SetParam(DMS_MISSION_ID, missionId);
HILOG_INFO("%{public}s: StartAbilityForResult freeInstall", __func__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s: StartAbilityForResult freeInstall", __func__);
return RemoteFreeInstall(*newWant, validUserId, requestCode, callerToken);
}
@ -203,7 +204,7 @@ int FreeInstallManager::NotifyDmsCallback(const Want &want, int resultCode)
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
std::lock_guard<ffrt::mutex> autoLock(distributedFreeInstallLock_);
if (dmsFreeInstallCbs_.empty()) {
HILOG_ERROR("Has no dms callback.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Has no dms callback.");
return ERR_INVALID_VALUE;
}
@ -213,25 +214,25 @@ int FreeInstallManager::NotifyDmsCallback(const Want &want, int resultCode)
for (auto it = dmsFreeInstallCbs_.begin(); it != dmsFreeInstallCbs_.end();) {
std::string abilityName = (*it).want.GetElement().GetAbilityName();
if (want.GetElement().GetAbilityName().compare(abilityName) == 0) {
HILOG_INFO("Handle DMS.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "Handle DMS.");
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_FREE_INSTALL_CALLBACK_TOKEN)) {
HILOG_ERROR("Write interface token failed.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Write interface token failed.");
return ERR_INVALID_VALUE;
}
if (!data.WriteInt32(resultCode)) {
HILOG_ERROR("Write resultCode error.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Write resultCode error.");
return ERR_INVALID_VALUE;
}
if (!data.WriteParcelable(&((*it).want))) {
HILOG_ERROR("want write failed.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "want write failed.");
return INNER_ERR;
}
if (!data.WriteInt32((*it).requestCode)) {
HILOG_ERROR("Write resultCode error.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Write resultCode error.");
return ERR_INVALID_VALUE;
}
@ -250,12 +251,12 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
std::lock_guard<ffrt::mutex> lock(freeInstallListLock_);
if (freeInstallList_.empty()) {
HILOG_INFO("Has no app callback.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "Has no app callback.");
return;
}
bool isFromRemote = want.GetBoolParam(FROM_REMOTE_KEY, false);
HILOG_INFO("isFromRemote = %{public}d", isFromRemote);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "isFromRemote = %{public}d", isFromRemote);
for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) {
std::string bundleName = (*it).want.GetElement().GetBundleName();
std::string abilityName = (*it).want.GetElement().GetAbilityName();
@ -273,7 +274,7 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod
}
if (resultCode == ERR_OK) {
HILOG_INFO("FreeInstall success.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall success.");
if (isAsync) {
Want newWant((*it).want);
newWant.SetFlags(want.GetFlags() ^ Want::FLAG_INSTALL_ON_DEMAND);
@ -282,14 +283,14 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod
auto result = DelayedSingleton<AbilityManagerService>::GetInstance()->StartAbilityByFreeInstall(newWant,
(*it).callerToken, (*it).userId, (*it).requestCode);
IPCSkeleton::SetCallingIdentity(identity);
HILOG_INFO("The result of StartAbility is %{public}d.", result);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The result of StartAbility is %{public}d.", result);
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(
bundleName, abilityName, startTime, result);
} else {
(*it).promise->set_value(resultCode);
}
} else {
HILOG_INFO("FreeInstall failed.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall failed.");
if (isAsync) {
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(
bundleName, abilityName, startTime, resultCode);
@ -305,9 +306,9 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod
int FreeInstallManager::FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback,
int32_t userId, int requestCode)
{
HILOG_INFO("%{public}s", __func__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s", __func__);
if (callback == nullptr) {
HILOG_ERROR("FreeInstallAbilityFromRemote callback is nullptr.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "FreeInstallAbilityFromRemote callback is nullptr.");
return ERR_INVALID_VALUE;
}
@ -325,7 +326,7 @@ int FreeInstallManager::FreeInstallAbilityFromRemote(const Want &want, const spt
auto result = StartFreeInstall(info.want, info.userId, info.requestCode, nullptr);
if (result != ERR_OK) {
HILOG_ERROR("StartFreeInstall failed, errCode: %{public}d", result);
TAG_LOGE(AAFwkTag::FREE_INSTALL, "StartFreeInstall failed, errCode: %{public}d", result);
NotifyDmsCallback(info.want, result);
}
return result;
@ -338,7 +339,7 @@ int FreeInstallManager::ConnectFreeInstall(const Want &want, int32_t userId,
CHECK_POINTER_AND_RETURN(bundleMgrHelper, GET_ABILITY_SERVICE_FAILED);
std::string wantDeviceId = want.GetElement().GetDeviceID();
if (!(localDeviceId == wantDeviceId || wantDeviceId.empty())) {
HILOG_ERROR("Failed to get device id.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Failed to get device id.");
return INVALID_PARAMETERS_ERR;
}
@ -347,14 +348,14 @@ int FreeInstallManager::ConnectFreeInstall(const Want &want, int32_t userId,
std::string wantAbilityName = want.GetElement().GetAbilityName();
std::string wantBundleName = want.GetElement().GetBundleName();
if (wantBundleName.empty() || wantAbilityName.empty()) {
HILOG_ERROR("The wantBundleName or wantAbilityName is empty.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "The wantBundleName or wantAbilityName is empty.");
return INVALID_PARAMETERS_ERR;
}
int callerUid = IPCSkeleton::GetCallingUid();
std::string localBundleName;
auto res = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callerUid, localBundleName));
if (res != ERR_OK || localBundleName != wantBundleName) {
HILOG_ERROR("The wantBundleName is not local BundleName.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "The wantBundleName is not local BundleName.");
return INVALID_PARAMETERS_ERR;
}
}
@ -365,13 +366,13 @@ int FreeInstallManager::ConnectFreeInstall(const Want &want, int32_t userId,
want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId, abilityInfo)) &&
!IN_PROCESS_CALL(bundleMgrHelper->QueryExtensionAbilityInfos(
want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId, extensionInfos))) {
HILOG_INFO("AbilityManagerService::ConnectFreeInstall. try to StartFreeInstall");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "AbilityManagerService::ConnectFreeInstall. try to StartFreeInstall");
int result = StartFreeInstall(want, userId, DEFAULT_INVAL_VALUE, callerToken);
if (result) {
HILOG_ERROR("AbilityManagerService::ConnectFreeInstall. StartFreeInstall error");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "AbilityManagerService::ConnectFreeInstall. StartFreeInstall error");
return result;
}
HILOG_INFO("AbilityManagerService::ConnectFreeInstall. StartFreeInstall success");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "AbilityManagerService::ConnectFreeInstall. StartFreeInstall success");
}
return ERR_OK;
}
@ -387,7 +388,7 @@ std::time_t FreeInstallManager::GetTimeStamp()
void FreeInstallManager::OnInstallFinished(int resultCode, const Want &want, int32_t userId, bool isAsync)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_INFO("%{public}s resultCode = %{public}d", __func__, resultCode);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s resultCode = %{public}d", __func__, resultCode);
if (isAsync) {
// remove timeout task
std::string bundleName = want.GetElement().GetBundleName();
@ -403,12 +404,13 @@ void FreeInstallManager::OnInstallFinished(int resultCode, const Want &want, int
void FreeInstallManager::PostUpgradeAtomicServiceTask(int resultCode, const Want &want, int32_t userId)
{
HILOG_INFO("PostUpgradeAtomicServiceTask begin.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "PostUpgradeAtomicServiceTask begin.");
std::weak_ptr<FreeInstallManager> thisWptr(shared_from_this());
if (resultCode == ERR_OK) {
auto updateAtmoicServiceTask = [want, userId, thisWptr, &timeStampMap = timeStampMap_]() {
auto sptr = thisWptr.lock();
HILOG_DEBUG("bundleName: %{public}s, moduleName: %{public}s", want.GetElement().GetBundleName().c_str(),
TAG_LOGD(AAFwkTag::FREE_INSTALL,
"bundleName: %{public}s, moduleName: %{public}s", want.GetElement().GetBundleName().c_str(),
want.GetElement().GetModuleName().c_str());
std::string nameKey = want.GetElement().GetBundleName() + want.GetElement().GetModuleName();
if (timeStampMap.find(nameKey) == timeStampMap.end() ||
@ -428,26 +430,26 @@ void FreeInstallManager::PostUpgradeAtomicServiceTask(int resultCode, const Want
void FreeInstallManager::OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId)
{
HILOG_INFO("%{public}s resultCode = %{public}d", __func__, resultCode);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s resultCode = %{public}d", __func__, resultCode);
NotifyFreeInstallResult(want, resultCode);
}
int FreeInstallManager::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
HILOG_INFO("Add FreeInstallObserver");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "Add FreeInstallObserver");
return DelayedSingleton<FreeInstallObserverManager>::GetInstance()->AddObserver(observer);
}
void FreeInstallManager::PostTimeoutTask(const Want &want)
{
HILOG_INFO("PostTimeoutTask begin.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "PostTimeoutTask begin.");
std::string bundleName = want.GetElement().GetBundleName();
std::string abilityName = want.GetElement().GetAbilityName();
std::string startTime = want.GetStringParam(Want::PARAM_RESV_START_TIME);
auto task = [weak = weak_from_this(), bundleName, abilityName, startTime]() {
auto self = weak.lock();
if (!self) {
HILOG_ERROR("this is nullptr");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "this is nullptr");
return;
}
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(bundleName, abilityName,
@ -467,7 +469,7 @@ void FreeInstallManager::RemoveTimeoutTask(const std::string &bundleName, const
// remove timeout task
std::string taskName = std::string("FreeInstallTimeout_") + bundleName + std::string("_") +
abilityName + std::string("_") + startTime;
HILOG_INFO("RemoveTimeoutTask task name:%{public}s", taskName.c_str());
TAG_LOGI(AAFwkTag::FREE_INSTALL, "RemoveTimeoutTask task name:%{public}s", taskName.c_str());
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
CHECK_POINTER_LOG(handler, "Fail to get AbilityTaskHandler.");
handler->CancelTask(taskName);
@ -476,17 +478,17 @@ void FreeInstallManager::RemoveTimeoutTask(const std::string &bundleName, const
void FreeInstallManager::OnRemoveTimeoutTask(const Want &want)
{
// only SA can call this interface
HILOG_INFO("OnRemoveTimeoutTask begin.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnRemoveTimeoutTask begin.");
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall) {
HILOG_ERROR("Permission verification failed.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Permission verification failed.");
return;
}
std::string bundleName = want.GetElement().GetBundleName();
std::string abilityName = want.GetElement().GetAbilityName();
std::string startTime = want.GetStringParam(Want::PARAM_RESV_START_TIME);
if (bundleName.empty() || abilityName.empty()) {
HILOG_ERROR("wantBundleName or wantAbilityName is empty");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "wantBundleName or wantAbilityName is empty");
return;
}
RemoveTimeoutTask(bundleName, abilityName, startTime);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -20,6 +20,7 @@
#include "ability_manager_service.h"
#include "ability_manager_errors.h"
#include "ability_util.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
@ -32,18 +33,18 @@ FreeInstallObserverManager::~FreeInstallObserverManager()
int32_t FreeInstallObserverManager::AddObserver(const sptr<IFreeInstallObserver> &observer)
{
HILOG_DEBUG("AddObserver begin.");
TAG_LOGD(AAFwkTag::FREE_INSTALL, "AddObserver begin.");
if (observer == nullptr) {
HILOG_ERROR("the observer is nullptr.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "the observer is nullptr.");
return ERR_INVALID_VALUE;
}
std::lock_guard<ffrt::mutex> lock(observerLock_);
if (ObserverExistLocked(observer)) {
HILOG_ERROR("Observer exist.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Observer exist.");
return ERR_INVALID_VALUE;
}
observerList_.emplace_back(observer);
HILOG_DEBUG("observerList_ size:%{public}zu", observerList_.size());
TAG_LOGD(AAFwkTag::FREE_INSTALL, "observerList_ size:%{public}zu", observerList_.size());
if (!deathRecipient_) {
std::weak_ptr<FreeInstallObserverManager> thisWeakPtr(shared_from_this());
@ -59,7 +60,7 @@ int32_t FreeInstallObserverManager::AddObserver(const sptr<IFreeInstallObserver>
auto observerObj = observer->AsObject();
if (!observerObj || !observerObj->AddDeathRecipient(deathRecipient_)) {
HILOG_ERROR("AddDeathRecipient failed.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "AddDeathRecipient failed.");
}
return ERR_OK;
@ -67,9 +68,9 @@ int32_t FreeInstallObserverManager::AddObserver(const sptr<IFreeInstallObserver>
int32_t FreeInstallObserverManager::RemoveObserver(const sptr<IFreeInstallObserver> &observer)
{
HILOG_DEBUG("RemoveObserver begin.");
TAG_LOGD(AAFwkTag::FREE_INSTALL, "RemoveObserver begin.");
if (observer == nullptr) {
HILOG_ERROR("the observer is nullptr.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "the observer is nullptr.");
return ERR_INVALID_VALUE;
}
std::lock_guard<ffrt::mutex> lock(observerLock_);
@ -79,10 +80,10 @@ int32_t FreeInstallObserverManager::RemoveObserver(const sptr<IFreeInstallObserv
});
if (it != observerList_.end()) {
observerList_.erase(it);
HILOG_INFO("observerList_ size:%{public}zu", observerList_.size());
TAG_LOGI(AAFwkTag::FREE_INSTALL, "observerList_ size:%{public}zu", observerList_.size());
return ERR_OK;
}
HILOG_ERROR("Observer not exist or has been removed.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Observer not exist or has been removed.");
return ERR_INVALID_VALUE;
}
@ -92,10 +93,10 @@ void FreeInstallObserverManager::OnInstallFinished(const std::string &bundleName
auto task = [weak = weak_from_this(), bundleName, abilityName, startTime, resultCode]() {
auto self = weak.lock();
if (self == nullptr) {
HILOG_ERROR("self is nullptr, OnInstallFinished failed.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "self is nullptr, OnInstallFinished failed.");
return;
}
HILOG_INFO("OnInstallFinished come.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnInstallFinished come.");
self->HandleOnInstallFinished(bundleName, abilityName, startTime, resultCode);
};
@ -107,7 +108,7 @@ void FreeInstallObserverManager::OnInstallFinished(const std::string &bundleName
void FreeInstallObserverManager::HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName,
const std::string &startTime, const int &resultCode)
{
HILOG_DEBUG("HandleOnInstallFinished begin.");
TAG_LOGD(AAFwkTag::FREE_INSTALL, "HandleOnInstallFinished begin.");
for (auto it = observerList_.begin(); it != observerList_.end(); ++it) {
if ((*it) == nullptr) {
continue;
@ -118,9 +119,9 @@ void FreeInstallObserverManager::HandleOnInstallFinished(const std::string &bund
bool FreeInstallObserverManager::ObserverExistLocked(const sptr<IFreeInstallObserver> &observer)
{
HILOG_DEBUG("ObserExist begin.");
TAG_LOGD(AAFwkTag::FREE_INSTALL, "ObserExist begin.");
if (observer == nullptr) {
HILOG_ERROR("The param observer is nullptr.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "The param observer is nullptr.");
return false;
}
auto it = std::find_if(observerList_.begin(), observerList_.end(),
@ -132,10 +133,10 @@ bool FreeInstallObserverManager::ObserverExistLocked(const sptr<IFreeInstallObse
void FreeInstallObserverManager::OnObserverDied(const wptr<IRemoteObject> &remote)
{
HILOG_INFO("OnObserverDied begin.");
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnObserverDied begin.");
auto remoteObj = remote.promote();
if (remoteObj == nullptr) {
HILOG_ERROR("observer is nullptr.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "observer is nullptr.");
return;
}
remoteObj->RemoveDeathRecipient(deathRecipient_);
@ -158,7 +159,7 @@ FreeInstallObserverRecipient::~FreeInstallObserverRecipient()
void FreeInstallObserverRecipient::OnRemoteDied(const wptr<IRemoteObject> &__attribute__((unused)) remote)
{
HILOG_ERROR("FreeInstallObserverRecipient On remote died.");
TAG_LOGE(AAFwkTag::FREE_INSTALL, "FreeInstallObserverRecipient On remote died.");
if (handler_) {
handler_(remote);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -14,6 +14,7 @@
*/
#include "mock_ability_manager_stub.h"
#include "hilog_tag_wrapper.h"
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
@ -25,31 +26,31 @@ const std::string STRING_BUNDLE_NAME_INVALID = "invalid_bundle";
int MockAbilityManagerStub::StartAbility(const Want& want, int32_t userId, int requestCode)
{
HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
TAG_LOGI(AAFwkTag::TEST, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
AppExecFwk::ElementName element = want.GetElement();
std::string abilityName = element.GetAbilityName();
HILOG_INFO("abilityName: %{public}s", abilityName.c_str());
TAG_LOGI(AAFwkTag::TEST, "abilityName: %{public}s", abilityName.c_str());
if (abilityName == STRING_ABILITY_NAME_INVALID) {
return RESOLVE_ABILITY_ERR;
}
std::string bundleName = element.GetBundleName();
HILOG_INFO("bundleName: %{public}s", bundleName.c_str());
TAG_LOGI(AAFwkTag::TEST, "bundleName: %{public}s", bundleName.c_str());
if (bundleName == STRING_BUNDLE_NAME_INVALID) {
return RESOLVE_APP_ERR;
}
auto isDebugApp = want.GetBoolParam("debugApp", false);
HILOG_INFO("isDebugApp: %{public}d", isDebugApp);
TAG_LOGI(AAFwkTag::TEST, "isDebugApp: %{public}d", isDebugApp);
return ERR_OK;
}
void MockAbilityManagerStub::DumpState(const std::string& args, std::vector<std::string>& state)
{
HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
TAG_LOGI(AAFwkTag::TEST, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
std::vector<std::string> argList;
SplitStr(args, " ", argList);
@ -71,18 +72,18 @@ void MockAbilityManagerStub::DumpState(const std::string& args, std::vector<std:
int MockAbilityManagerStub::StopServiceAbility(const Want& want, int32_t userId,
const sptr<IRemoteObject> &token)
{
HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
TAG_LOGI(AAFwkTag::TEST, "[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__);
AppExecFwk::ElementName element = want.GetElement();
std::string abilityName = element.GetAbilityName();
HILOG_INFO("abilityName: %{public}s", abilityName.c_str());
TAG_LOGI(AAFwkTag::TEST, "abilityName: %{public}s", abilityName.c_str());
if (abilityName == STRING_ABILITY_NAME_INVALID) {
return RESOLVE_ABILITY_ERR;
}
std::string bundleName = element.GetBundleName();
HILOG_INFO("bundleName: %{public}s", bundleName.c_str());
TAG_LOGI(AAFwkTag::TEST, "bundleName: %{public}s", bundleName.c_str());
if (bundleName == STRING_BUNDLE_NAME_INVALID) {
return RESOLVE_APP_ERR;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -20,6 +20,7 @@
#include "ability_manager_client.h"
#undef private
#include "ability_manager_interface.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "mock_ability_manager_stub.h"
@ -84,7 +85,7 @@ void AbilityCommandModuleTest::MakeMockObjects() const
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0100, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0100 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0100 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -104,7 +105,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0100, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0200, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0200 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0200 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -124,7 +125,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0200, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0300, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0300 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0300 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -143,7 +144,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0300, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0400, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0400 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0400 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -163,7 +164,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0400, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0500, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0500 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0500 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -184,7 +185,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0500, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0600, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0600 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0600 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -211,7 +212,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0600, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0700, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0700 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0700 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -232,7 +233,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0700, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0800, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0800 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0800 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -263,7 +264,7 @@ HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0800, Function |
*/
HWTEST_F(AbilityCommandModuleTest, Ability_Command_Module_Test_0900, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Module_Test_0900 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Module_Test_0900 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -23,6 +23,7 @@
#include "ability_manager_client.h"
#undef private
#include "ability_manager_interface.h"
#include "hilog_tag_wrapper.h"
using namespace testing::ext;
using namespace OHOS;
@ -109,7 +110,7 @@ void AaCommandStartTest::MakeMockObjects() const
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0100");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0100");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -129,7 +130,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0100, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0200");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0200");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -150,7 +151,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0200, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0300");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0300");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -171,7 +172,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0300, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0400, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0400");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0400");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -192,7 +193,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0400, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0500");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0500");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -213,7 +214,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0500, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0600");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0600");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -234,7 +235,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0600, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0700");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0700");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -255,7 +256,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0700, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0800");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0800");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -276,7 +277,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0800, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0900");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_0900");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -297,7 +298,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0900, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1000");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1000");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -319,7 +320,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1000, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1100");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1100");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -342,7 +343,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1100, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1200");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1200");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -366,7 +367,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1200, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1300");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1300");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -389,7 +390,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1300, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1400, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1400");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1400");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -413,7 +414,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1400, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1500");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1500");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -438,7 +439,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1500, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1600");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1600");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -464,7 +465,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1600, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1700");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1700");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -485,7 +486,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1700, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1800");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1800");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -508,7 +509,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1800, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1900");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_1900");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -532,7 +533,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1900, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2000");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2000");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -557,7 +558,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2000, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2100");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2100");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -583,7 +584,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2100, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2200");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2200");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -611,7 +612,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2200, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2300");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2300");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -634,7 +635,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2300, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2400, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2400");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2400");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -659,7 +660,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2400, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2500");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2500");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -686,7 +687,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2500, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2600");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2600");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -713,7 +714,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2600, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2700");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2700");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -742,7 +743,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2700, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2800");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2800");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -773,7 +774,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2800, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2900");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_2900");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -804,7 +805,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2900, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3000");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3000");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -835,7 +836,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3000, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3100");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3100");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -865,7 +866,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3100, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3200");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3200");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -889,7 +890,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3200, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3300");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3300");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -915,7 +916,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3300, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3500");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3500");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -939,7 +940,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3500, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3600");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3600");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -970,7 +971,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3600, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3700");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3700");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -1001,7 +1002,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3700, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3800");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3800");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -1033,7 +1034,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3800, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_3900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_3900");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_3900");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -1065,7 +1066,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_3900, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_4000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_4000");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_4000");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
@ -1096,7 +1097,7 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_4000, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_4100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_4100");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_Start_4100");
char* argv[] = {
(char*)TOOL_NAME.c_str(),

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -25,6 +25,7 @@
#include "ability_manager_client.h"
#undef private
#include "ability_manager_interface.h"
#include "hilog_tag_wrapper.h"
using namespace testing::ext;
using namespace OHOS;
@ -164,7 +165,7 @@ HWTEST_F(AaCommandTest, Aa_Command_0500, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_0600, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_3400 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_3400 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -181,7 +182,7 @@ HWTEST_F(AaCommandTest, Aa_Command_0600, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_0700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_0700 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_0700 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -198,7 +199,7 @@ HWTEST_F(AaCommandTest, Aa_Command_0700, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_0800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_0800 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_0800 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -215,7 +216,7 @@ HWTEST_F(AaCommandTest, Aa_Command_0800, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_0900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_0900 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_0900 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -232,7 +233,7 @@ HWTEST_F(AaCommandTest, Aa_Command_0900, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1000 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1000 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -250,7 +251,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1000, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1100 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1100 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -268,7 +269,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1100, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1200 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1200 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -286,7 +287,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1200, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1300 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1300 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -304,7 +305,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1300, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1400, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1400 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1400 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -322,7 +323,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1400, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1500 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1500 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -340,7 +341,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1500, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1600 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1600 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
@ -358,7 +359,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1600, Function | MediumTest | Level1)
*/
HWTEST_F(AaCommandTest, Aa_Command_1700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_1700 is called");
TAG_LOGI(AAFwkTag::TEST, "Aa_Command_1700 is called");
char* argv[] = { (char*)TOOL_NAME.c_str() };
int argc = sizeof(argv) / sizeof(argv[0]) - 1;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -20,6 +20,7 @@
#include "ability_manager_client.h"
#undef private
#include "ability_manager_interface.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "mock_ability_manager_stub.h"
@ -89,7 +90,7 @@ void AbilityCommandTest::MakeMockObjects() const
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0100, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0100 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0100 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -108,7 +109,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0100, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0200, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0200 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0200 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -127,7 +128,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0200, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0300, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0300 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0300 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -146,7 +147,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0300, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0400, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0400 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0400 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -165,7 +166,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0400, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0500, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0500 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0500 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -184,7 +185,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0500, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0600, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0600 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0600 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -203,7 +204,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0600, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0700, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0700 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0700 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -224,7 +225,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0700, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0800, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0800 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0800 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -245,7 +246,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0800, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_0900, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_0900 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_0900 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -265,7 +266,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_0900, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1000, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1000 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1000 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -285,7 +286,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1000, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1100, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1100 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1100 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -305,7 +306,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1100, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1200, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1200 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1200 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -327,7 +328,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1200, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1300, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1300 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1300 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -349,7 +350,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1300, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1400, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1400 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1400 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -373,7 +374,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1400, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1500, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1500 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1500 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -397,7 +398,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1500, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1600, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1600 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1600 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -427,7 +428,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1600, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1700, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1700 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1700 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -455,7 +456,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1700, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1800, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1800 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1800 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -483,7 +484,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1800, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_1900, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_1900 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_1900 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -512,7 +513,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_1900, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2000, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2000 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2000 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -536,7 +537,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2000, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2100, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2100 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2100 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -565,7 +566,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2100, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2200, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2200 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2200 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -594,7 +595,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2200, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2300, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2300 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2300 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -627,7 +628,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2300, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2400, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2400 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2400 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -659,7 +660,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2400, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2500, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2500 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2500 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -691,7 +692,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2500, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2600, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2600 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2600 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -724,7 +725,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2600, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2700, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2700 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2700 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -743,7 +744,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2700, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2800, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2800 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2800 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -762,7 +763,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2800, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_2900, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_2900 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_2900 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -782,7 +783,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_2900, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_3000, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_3000 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_3000 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -802,7 +803,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_3000, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_3100, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_3100 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_3100 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -822,7 +823,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_3100, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_3200, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_3200 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_3200 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),
@ -843,7 +844,7 @@ HWTEST_F(AbilityCommandTest, Ability_Command_Test_3200, Function | MediumTest |
*/
HWTEST_F(AbilityCommandTest, Ability_Command_Test_3300, Function | MediumTest | Level1)
{
HILOG_INFO("Ability_Command_Test_3300 is called");
TAG_LOGI(AAFwkTag::TEST, "Ability_Command_Test_3300 is called");
char* argv[] = {
(char*)TOOL_NAME.c_str(),
(char*)cmd_.c_str(),

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -14,6 +14,7 @@
*/
#include "mock_test_observer_stub.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
@ -23,18 +24,18 @@ MockTestObserverStub::~MockTestObserverStub()
void MockTestObserverStub::TestStatus(const std::string& msg, const int64_t& resultCode)
{
HILOG_INFO("MockTestObserverStub::TestStatus is called");
TAG_LOGI(AAFwkTag::TEST, "MockTestObserverStub::TestStatus is called");
}
void MockTestObserverStub::TestFinished(const std::string& msg, const int64_t& resultCode)
{
HILOG_INFO("MockTestObserverStub::TestFinished is called");
TAG_LOGI(AAFwkTag::TEST, "MockTestObserverStub::TestFinished is called");
}
ShellCommandResult MockTestObserverStub::ExecuteShellCommand(
const std::string& cmd, const int64_t timeoutMs)
{
HILOG_INFO("MockTestObserverStub::ExecuteShellCommand is called");
TAG_LOGI(AAFwkTag::TEST, "MockTestObserverStub::ExecuteShellCommand is called");
return ShellCommandResult();
}
} // namespace AAFwk

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -29,6 +29,7 @@
*/
#include <gtest/gtest.h>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "iremote_proxy.h"
#include "test_observer_proxy.h"
@ -128,11 +129,11 @@ public:
*/
HWTEST_F(TestObserverProxyTest, Test_Observer_Proxy_Test_0100, TestSize.Level1)
{
HILOG_INFO("Test_Observer_Proxy_Test_0100 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Proxy_Test_0100 start");
OHOS::sptr<OHOS::IRemoteObject> object = new OHOS::MockIRemoteObject();
TestObserverProxy testObserverProxy(object);
EXPECT_EQ(testObserverProxy.ExecuteShellCommand(CMD.c_str(), 0).stdResult.size(), 0);
HILOG_INFO("Test_Observer_Proxy_Test_0100 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Proxy_Test_0100 end");
}
/**
@ -142,12 +143,12 @@ HWTEST_F(TestObserverProxyTest, Test_Observer_Proxy_Test_0100, TestSize.Level1)
*/
HWTEST_F(TestObserverProxyTest, Test_Observer_Proxy_Test_0200, TestSize.Level1)
{
HILOG_INFO("Test_Observer_Proxy_Test_0200 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Proxy_Test_0200 start");
OHOS::sptr<OHOS::IRemoteObject> object = new OHOS::MockIRemoteObject();
ASSERT_NE(object, nullptr);
TestObserverProxy testObserverProxy(object);
testObserverProxy.TestStatus(CMD.c_str(), 0);
HILOG_INFO("Test_Observer_Proxy_Test_0200 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Proxy_Test_0200 end");
}
/**
@ -157,10 +158,10 @@ HWTEST_F(TestObserverProxyTest, Test_Observer_Proxy_Test_0200, TestSize.Level1)
*/
HWTEST_F(TestObserverProxyTest, Test_Observer_Proxy_Test_0300, TestSize.Level1)
{
HILOG_INFO("Test_Observer_Proxy_Test_0300 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Proxy_Test_0300 start");
OHOS::sptr<OHOS::IRemoteObject> object = new OHOS::MockIRemoteObject();
ASSERT_NE(object, nullptr);
TestObserverProxy testObserverProxy(object);
testObserverProxy.TestFinished(CMD.c_str(), 0);
HILOG_INFO("Test_Observer_Proxy_Test_0300 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Proxy_Test_0300 end");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -14,6 +14,7 @@
*/
#include <gtest/gtest.h>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "iremote_proxy.h"
#include "mock_test_observer_stub.h"
@ -50,7 +51,7 @@ void TestObserverStubTest::TearDown()
*/
HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0100, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Stub_Test_0100 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0100 start");
MessageParcel data;
MessageParcel reply;
@ -65,7 +66,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0100, Function | MediumTe
int res = stub.OnRemoteRequest(static_cast<uint32_t>(ITestObserver::Message::AA_TEST_STATUS), data, reply, option);
EXPECT_EQ(res, NO_ERROR);
HILOG_INFO("Test_Observer_Stub_Test_0100 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0100 end");
}
/**
@ -75,7 +76,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0100, Function | MediumTe
*/
HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0200, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Stub_Test_0200 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0200 start");
MessageParcel data;
MessageParcel reply;
@ -91,7 +92,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0200, Function | MediumTe
data, reply, option);
EXPECT_EQ(res, NO_ERROR);
HILOG_INFO("Test_Observer_Stub_Test_0200 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0200 end");
}
/**
@ -101,7 +102,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0200, Function | MediumTe
*/
HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0300, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Stub_Test_0300 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0300 start");
MessageParcel data;
MessageParcel reply;
@ -117,7 +118,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0300, Function | MediumTe
data, reply, option);
EXPECT_EQ(res, NO_ERROR);
HILOG_INFO("Test_Observer_Stub_Test_0300 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0300 end");
}
/**
@ -127,7 +128,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0300, Function | MediumTe
*/
HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0400, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Stub_Test_0400 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0400 start");
MessageParcel data;
MessageParcel reply;
@ -142,7 +143,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0400, Function | MediumTe
int res = stub.OnRemoteRequest(0, data, reply, option);
EXPECT_EQ(res, IPC_STUB_UNKNOW_TRANS_ERR);
HILOG_INFO("Test_Observer_Stub_Test_0400 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0400 end");
}
/**
@ -152,7 +153,7 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0400, Function | MediumTe
*/
HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0500, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Stub_Test_0500 start");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0500 start");
MessageParcel data;
MessageParcel reply;
@ -166,5 +167,5 @@ HWTEST_F(TestObserverStubTest, Test_Observer_Stub_Test_0500, Function | MediumTe
int res = stub.OnRemoteRequest(0, data, reply, option);
EXPECT_EQ(res, ERR_TRANSACTION_FAILED);
HILOG_INFO("Test_Observer_Stub_Test_0500 end");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Stub_Test_0500 end");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -19,6 +19,7 @@
#include <thread>
#include <unistd.h>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "system_time.h"
@ -65,9 +66,9 @@ void TestObserverTest::TearDown()
void TestObserverTest::thfunc(TestObserver& observer)
{
HILOG_INFO("thfunc");
TAG_LOGI(AAFwkTag::TEST, "thfunc");
sleep(1);
HILOG_INFO("after sleep 1s thfunc");
TAG_LOGI(AAFwkTag::TEST, "after sleep 1s thfunc");
observer.isFinished_ = true;
}
@ -78,7 +79,7 @@ void TestObserverTest::thfunc(TestObserver& observer)
*/
HWTEST_F(TestObserverTest, Test_Observer_Test_0100, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Test_0100 is called");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Test_0100 is called");
TestObserver observer;
observer.TestFinished(MSG.c_str(), RESULT_CODE);
EXPECT_TRUE(observer.isFinished_);
@ -91,7 +92,7 @@ HWTEST_F(TestObserverTest, Test_Observer_Test_0100, Function | MediumTest | Leve
*/
HWTEST_F(TestObserverTest, Test_Observer_Test_0200, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Test_0200 is called");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Test_0200 is called");
TestObserver observer;
EXPECT_EQ(observer.ExecuteShellCommand(CMD.c_str(), TIMEOUT).stdResult.size(), 0);
}
@ -103,7 +104,7 @@ HWTEST_F(TestObserverTest, Test_Observer_Test_0200, Function | MediumTest | Leve
*/
HWTEST_F(TestObserverTest, Test_Observer_Test_0300, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Test_0300 is called");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Test_0300 is called");
TestObserver observer;
std::thread th(&TestObserverTest::thfunc, std::ref(observer));
bool ret = observer.WaitForFinish(5000);
@ -118,7 +119,7 @@ HWTEST_F(TestObserverTest, Test_Observer_Test_0300, Function | MediumTest | Leve
*/
HWTEST_F(TestObserverTest, Test_Observer_Test_0400, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Test_0400 is called");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Test_0400 is called");
TestObserver observer;
observer.isFinished_ = false;
bool ret = observer.WaitForFinish(1);
@ -132,7 +133,7 @@ HWTEST_F(TestObserverTest, Test_Observer_Test_0400, Function | MediumTest | Leve
*/
HWTEST_F(TestObserverTest, Test_Observer_Test_0500, Function | MediumTest | Level1)
{
HILOG_INFO("Test_Observer_Test_0500 is called");
TAG_LOGI(AAFwkTag::TEST, "Test_Observer_Test_0500 is called");
std::shared_ptr<TestObserver> observer = std::make_shared<TestObserver>();
ASSERT_NE(observer, nullptr);
observer->TestStatus(MSG.c_str(), RESULT_CODE);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 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
@ -15,6 +15,7 @@
#include "freeze_util.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS::AbilityRuntime {
@ -68,6 +69,6 @@ void FreezeUtil::DeleteLifecycleEventInner(const LifecycleFlow &flow)
if (lifecycleFlow_.count(flow)) {
lifecycleFlow_.erase(flow);
}
HILOG_DEBUG("lifecycleFlow_ size: %{public}zu", lifecycleFlow_.size());
TAG_LOGD(AAFwkTag::DEFAULT, "lifecycleFlow_ size: %{public}zu", lifecycleFlow_.size());
}
} // namespace OHOS::AbilityRuntime