mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 01:59:58 +00:00
add stop ces event
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9LP4Z Signed-off-by: linxiang8 <linxiang8@huawei.com> Change-Id: I389a666da600e2dfcc5aa817dc56bd71d145ef41
This commit is contained in:
parent
56cfbeb728
commit
77154d20ea
@ -43,7 +43,8 @@
|
||||
"hisysevent",
|
||||
"ipc",
|
||||
"safwk",
|
||||
"samgr"
|
||||
"samgr",
|
||||
"common_event_service"
|
||||
],
|
||||
"third_party": [
|
||||
]
|
||||
|
@ -34,12 +34,14 @@ ohos_shared_library("libcompiler_service") {
|
||||
"src/aot_compiler_impl.cpp",
|
||||
"src/aot_compiler_load_callback.cpp",
|
||||
"src/aot_compiler_service.cpp",
|
||||
"src/power_disconnected_listener.cpp",
|
||||
]
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"code_signature:liblocal_code_sign_sdk",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
|
@ -5,8 +5,8 @@
|
||||
"ondemand" : true,
|
||||
"uid" : "compiler_service",
|
||||
"gid" : ["compiler_service"],
|
||||
"caps" : ["SETUID", "SETGID"],
|
||||
"secon" : "u:object_r:compiler_service:s0"
|
||||
"caps" : ["SETUID", "SETGID", "KILL"],
|
||||
"secon" : "u:r:compiler_service:s0"
|
||||
}
|
||||
]
|
||||
}
|
@ -35,6 +35,8 @@ public:
|
||||
std::vector<int16_t> &sigData);
|
||||
int32_t StopAotCompiler();
|
||||
|
||||
void HandlePowerDisconnected();
|
||||
|
||||
private:
|
||||
void PrepareArgs(const std::unordered_map<std::string, std::string> &argsMap);
|
||||
void DropCapabilities(const int32_t &bundleUid, const int32_t &bundleGid) const;
|
||||
@ -44,6 +46,9 @@ private:
|
||||
std::vector<int16_t> &sigData);
|
||||
void InitState(const pid_t childPid);
|
||||
void ResetState();
|
||||
void PauseAotCompiler();
|
||||
void AllowAotCompiler();
|
||||
|
||||
AotCompilerImpl() = default;
|
||||
~AotCompilerImpl() = default;
|
||||
|
||||
@ -65,6 +70,7 @@ private:
|
||||
bool running = false;
|
||||
pid_t childPid = -1;
|
||||
} state_;
|
||||
bool allowAotCompiler_ {true};
|
||||
};
|
||||
} // namespace OHOS::ArkCompiler
|
||||
#endif // OHOS_ARKCOMPILER_AOTCOMPILER_IMPL_H
|
@ -26,6 +26,8 @@
|
||||
#include "singleton.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
#include "power_disconnected_listener.h"
|
||||
|
||||
namespace OHOS::ArkCompiler {
|
||||
enum class ServiceRunningState {
|
||||
STATE_NOT_START,
|
||||
@ -45,8 +47,13 @@ protected:
|
||||
void OnStop() override;
|
||||
private:
|
||||
bool Init();
|
||||
void RegisterPowerDisconnectedListener();
|
||||
void UnRegisterPowerDisconnectedListener();
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventHandler> unLoadHandler_;
|
||||
ServiceRunningState state_;
|
||||
std::shared_ptr<PowerDisconnectedListener> powerDisconnectedListener_;
|
||||
bool isPowerEventSubscribered_ = false;
|
||||
};
|
||||
} // namespace OHOS::ArkCompiler
|
||||
#endif // OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H
|
33
compiler_service/include/power_disconnected_listener.h
Normal file
33
compiler_service/include/power_disconnected_listener.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ARKCOMPILER_POWER_DISCONNECTED_LISTENER_H
|
||||
#define OHOS_ARKCOMPILER_POWER_DISCONNECTED_LISTENER_H
|
||||
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_subscriber.h"
|
||||
#include "common_event_support.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ArkCompiler {
|
||||
class PowerDisconnectedListener : public EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
explicit PowerDisconnectedListener(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
|
||||
virtual ~PowerDisconnectedListener() = default;
|
||||
void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
|
||||
};
|
||||
} // namespace ArkCompiler
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ARKCOMPILER_POWER_DISCONNECTED_LISTENER_H
|
@ -4,6 +4,7 @@
|
||||
OHOS::ArkCompiler::AotCompilerClient::GetInstance*;
|
||||
OHOS::ArkCompiler::AotCompilerClient::AotCompiler*;
|
||||
OHOS::ArkCompiler::AotCompilerClient::StopAotCompiler*;
|
||||
OHOS::ArkCompiler::PowerDisconnectedListener::PowerDisconnectedListener*;
|
||||
};
|
||||
local:
|
||||
*;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
|
||||
#include "aot_compiler_constants.h"
|
||||
#include "aot_compiler_error_utils.h"
|
||||
@ -155,6 +156,9 @@ void AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret)
|
||||
int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
std::vector<int16_t> &sigData)
|
||||
{
|
||||
if (!allowAotCompiler_) {
|
||||
return ERR_AOT_COMPILER_PARAM_FAILED;
|
||||
}
|
||||
if (argsMap.empty()) {
|
||||
HiviewDFX::HiLog::Error(LABEL, "aot compiler arguments error");
|
||||
return ERR_AOT_COMPILER_PARAM_FAILED;
|
||||
@ -209,11 +213,40 @@ int32_t AotCompilerImpl::StopAotCompiler()
|
||||
return ERR_AOT_COMPILER_STOP_FAILED;
|
||||
}
|
||||
HiviewDFX::HiLog::Info(LABEL, "begin to kill child process : %{public}d", state_.childPid);
|
||||
(void)kill(state_.childPid, SIGKILL);
|
||||
auto result = kill(state_.childPid, SIGKILL);
|
||||
if (result != 0) {
|
||||
HiviewDFX::HiLog::Info(LABEL, "kill child process failed: %{public}d", result);
|
||||
} else {
|
||||
HiviewDFX::HiLog::Info(LABEL, "kill child process success");
|
||||
}
|
||||
ResetState();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AotCompilerImpl::HandlePowerDisconnected()
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::HandlePowerDisconnected");
|
||||
PauseAotCompiler();
|
||||
auto task = []() {
|
||||
AotCompilerImpl::GetInstance().StopAotCompiler();
|
||||
sleep(30);
|
||||
AotCompilerImpl::GetInstance().AllowAotCompiler();
|
||||
};
|
||||
std::thread(task).detach();
|
||||
}
|
||||
|
||||
void AotCompilerImpl::PauseAotCompiler()
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::PauseAotCompiler");
|
||||
allowAotCompiler_ = false;
|
||||
}
|
||||
|
||||
void AotCompilerImpl::AllowAotCompiler()
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerImpl::AllowAotCompiler");
|
||||
allowAotCompiler_ = true;
|
||||
}
|
||||
|
||||
void AotCompilerImpl::InitState(const pid_t childPid)
|
||||
{
|
||||
state_.running = true;
|
||||
|
@ -22,6 +22,13 @@
|
||||
#include "iremote_object.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "power_disconnected_listener.h"
|
||||
|
||||
#include "common_event_data.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_support.h"
|
||||
#include "common_event_subscriber.h"
|
||||
|
||||
namespace OHOS::ArkCompiler {
|
||||
namespace {
|
||||
const std::string TASK_ID = "UnLoadSA";
|
||||
@ -61,6 +68,7 @@ void AotCompilerService::OnStart()
|
||||
return;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
RegisterPowerDisconnectedListener();
|
||||
}
|
||||
|
||||
bool AotCompilerService::Init()
|
||||
@ -95,6 +103,7 @@ void AotCompilerService::OnStop()
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "aot compiler service has been onStop");
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
UnRegisterPowerDisconnectedListener();
|
||||
}
|
||||
|
||||
int32_t AotCompilerService::AotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
|
||||
@ -114,4 +123,34 @@ int32_t AotCompilerService::StopAotCompiler()
|
||||
DelayUnloadTask();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AotCompilerService::RegisterPowerDisconnectedListener()
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::RegisterPowerDisconnectedListener");
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED);
|
||||
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
powerDisconnectedListener_ = std::make_shared<PowerDisconnectedListener>(subscribeInfo);
|
||||
if (!EventFwk::CommonEventManager::SubscribeCommonEvent(powerDisconnectedListener_)) {
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::RegisterPowerDisconnectedListener failed");
|
||||
powerDisconnectedListener_ = nullptr;
|
||||
} else {
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::RegisterPowerDisconnectedListener success");
|
||||
isPowerEventSubscribered_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AotCompilerService::UnRegisterPowerDisconnectedListener()
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::UnRegisterPowerDisconnectedListener");
|
||||
if (!isPowerEventSubscribered_) {
|
||||
return;
|
||||
}
|
||||
if (!EventFwk::CommonEventManager::UnSubscribeCommonEvent(powerDisconnectedListener_)) {
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::UnRegisterPowerDisconnectedListener failed");
|
||||
}
|
||||
powerDisconnectedListener_ = nullptr;
|
||||
isPowerEventSubscribered_ = false;
|
||||
HiviewDFX::HiLog::Info(LABEL, "AotCompilerService::UnRegisterPowerDisconnectedListener done");
|
||||
}
|
||||
} // namespace OHOS::ArkCompiler
|
41
compiler_service/src/power_disconnected_listener.cpp
Normal file
41
compiler_service/src/power_disconnected_listener.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 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
|
||||
*
|
||||
* 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 "power_disconnected_listener.h"
|
||||
|
||||
#include "aot_compiler_impl.h"
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ArkCompiler {
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD001800, "aot_compiler_service"};
|
||||
} // namespace
|
||||
|
||||
PowerDisconnectedListener::PowerDisconnectedListener(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
|
||||
: EventFwk::CommonEventSubscriber(subscribeInfo)
|
||||
{
|
||||
}
|
||||
|
||||
void PowerDisconnectedListener::OnReceiveEvent(const EventFwk::CommonEventData &data)
|
||||
{
|
||||
HiviewDFX::HiLog::Info(LABEL, "PowerDisconnectedListener::OnReceiveEvent");
|
||||
AotCompilerImpl::GetInstance().HandlePowerDisconnected();
|
||||
}
|
||||
|
||||
} // namespace ArkCompiler
|
||||
} // namespace OHOS
|
@ -48,6 +48,7 @@ ohos_unittest("AotCompilerServiceTest") {
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"code_signature:liblocal_code_sign_sdk",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
|
Loading…
Reference in New Issue
Block a user