arkui_ace_engine/adapter/ohos/osal/exception_handler.cpp
kangchongtao 8cf53ce63e 删除冗余头文件
Signed-off-by: kangchongtao <kangchongtao@huawei.com>
2024-08-26 01:30:19 +00:00

58 lines
2.0 KiB
C++

/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "base/log/exception_handler.h"
#include "app_mgr_client.h"
#include "application_data_manager.h"
#include "core/common/ace_application_info.h"
namespace OHOS::Ace {
const std::string NAME = "name";
const std::string MESSAGE = "message";
const std::string STACK = "stack";
static void KillApplicationByUid()
{
auto appMgrClient = std::make_unique<AppExecFwk::AppMgrClient>();
CHECK_NULL_VOID(appMgrClient);
auto result = appMgrClient->ConnectAppMgrService();
if (result != AppExecFwk::AppMgrResultCode::RESULT_OK) {
LOGE("failed to ConnectAppMgrService %{public}d", result);
return;
}
auto ret = appMgrClient->KillApplicationSelf();
if (ret != AppExecFwk::AppMgrResultCode::RESULT_OK) {
LOGE("Fail to kill application by uid. %{public}d", ret);
return;
}
}
void ExceptionHandler::HandleJsException(
const std::string& exceptionMsg, const JsErrorObject& errorInfo)
{
AppExecFwk::ErrorObject errorObject = {
.name = errorInfo.name,
.message = errorInfo.message,
.stack = errorInfo.stack
};
auto hasErrorObserver = AppExecFwk::ApplicationDataManager::GetInstance().NotifyUnhandledException(exceptionMsg);
auto isNotifySuccess = AppExecFwk::ApplicationDataManager::GetInstance().NotifyExceptionObject(errorObject);
if (!hasErrorObserver && !isNotifySuccess) {
KillApplicationByUid();
}
}
} // namespace OHOS::Ace