!8200 添加亮屏停止编译的监听事件

Merge pull request !8200 from 吴璋达/killer
This commit is contained in:
openharmony_ci 2024-07-22 09:14:53 +00:00 committed by Gitee
commit 2273411da9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 125 additions and 0 deletions

View File

@ -48,6 +48,7 @@
"safwk",
"samgr",
"common_event_service",
"power_manager",
"ffrt"
],
"third_party": [

View File

@ -47,6 +47,7 @@ ohos_shared_library("libcompiler_service") {
"src/aot_compiler_load_callback.cpp",
"src/aot_compiler_service.cpp",
"src/power_disconnected_listener.cpp",
"src/screen_status_listener.cpp",
]
external_deps = [
"access_token:libaccesstoken_sdk",
@ -60,6 +61,7 @@ ohos_shared_library("libcompiler_service") {
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",

View File

@ -42,6 +42,8 @@ public:
void HandlePowerDisconnected();
void HandleScreenOn();
private:
inline int32_t FindArgsIdxToInteger(const std::unordered_map<std::string, std::string> &argsMap,
const std::string &keyName, int32_t &bundleID);

View File

@ -27,6 +27,7 @@
#include "system_ability.h"
#include "power_disconnected_listener.h"
#include "screen_status_listener.h"
namespace OHOS::ArkCompiler {
enum class ServiceRunningState {
@ -51,12 +52,16 @@ private:
void RemoveUnloadTask(const std::string &taskId);
void DelayUnloadTask(const std::string &taskId, const int32_t delayTime);
void RegisterPowerDisconnectedListener();
void RegisterScreenStatusSubscriber();
void UnRegisterPowerDisconnectedListener();
void UnRegisterScreenStatusSubscriber();
std::shared_ptr<AppExecFwk::EventHandler> unLoadHandler_ { nullptr };
ServiceRunningState state_;
std::shared_ptr<PowerDisconnectedListener> powerDisconnectedListener_ { nullptr };
std::shared_ptr<ScreenStatusSubscriber> screenStatusSubscriber_ { nullptr };
bool isPowerEventSubscribered_ { false };
bool isScreenStatusSubscribered_ { false };
};
} // namespace OHOS::ArkCompiler
#endif // OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H

View File

@ -0,0 +1,31 @@
/*
* 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_SCREEN_STATUS_LISTENER_H
#define OHOS_ARKCOMPILER_SCREEN_STATUS_LISTENER_H
#include "common_event_manager.h"
#include "common_event_subscriber.h"
#include "common_event_support.h"
namespace OHOS::ArkCompiler {
class ScreenStatusSubscriber : public EventFwk::CommonEventSubscriber {
public:
explicit ScreenStatusSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo);
virtual ~ScreenStatusSubscriber() = default;
void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
};
} // namespace OHOS::ArkCompiler
#endif // OHOS_ARKCOMPILER_SCREEN_STATUS_LISTENER_H

View File

@ -5,6 +5,7 @@
OHOS::ArkCompiler::AotCompilerClient::AotCompiler*;
OHOS::ArkCompiler::AotCompilerClient::StopAotCompiler*;
OHOS::ArkCompiler::PowerDisconnectedListener::PowerDisconnectedListener*;
OHOS::ArkCompiler::ScreenStatusSubscriber::ScreenStatusSubscriber*;
OHOS::ArkCompiler::AotCompilerClient::GetAOTVersion*;
OHOS::ArkCompiler::AotCompilerClient::NeedReCompile*;
};

View File

@ -312,6 +312,17 @@ void AotCompilerImpl::HandlePowerDisconnected()
}).detach();
}
void AotCompilerImpl::HandleScreenOn()
{
LOG_SA(INFO) << "AotCompilerImpl::HandleScreenOn";
PauseAotCompiler();
std::thread([]() {
(void)AotCompilerImpl::GetInstance().StopAotCompiler();
sleep(40); // wait for 40 seconds
AotCompilerImpl::GetInstance().AllowAotCompiler();
}).detach();
}
void AotCompilerImpl::PauseAotCompiler()
{
LOG_SA(INFO) << "AotCompilerImpl::PauseAotCompiler";

View File

@ -69,6 +69,7 @@ void AotCompilerService::OnStart()
}
state_ = ServiceRunningState::STATE_RUNNING;
RegisterPowerDisconnectedListener();
RegisterScreenStatusSubscriber();
}
bool AotCompilerService::Init()
@ -116,6 +117,7 @@ void AotCompilerService::OnStop()
LOG_SA(INFO) << "aot compiler service has been onStop";
state_ = ServiceRunningState::STATE_NOT_START;
UnRegisterPowerDisconnectedListener();
UnRegisterScreenStatusSubscriber();
}
int32_t AotCompilerService::AotCompiler(const std::unordered_map<std::string, std::string> &argsMap,
@ -174,6 +176,22 @@ void AotCompilerService::RegisterPowerDisconnectedListener()
}
}
void AotCompilerService::RegisterScreenStatusSubscriber()
{
LOG_SA(DEBUG) << "AotCompilerService::RegisterScreenStatusSubscriber";
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
screenStatusSubscriber_ = std::make_shared<ScreenStatusSubscriber>(subscribeInfo);
if (!EventFwk::CommonEventManager::SubscribeCommonEvent(screenStatusSubscriber_)) {
LOG_SA(INFO) << "AotCompilerService::RegisterScreenStatusSubscriber failed";
screenStatusSubscriber_ = nullptr;
} else {
LOG_SA(INFO) << "AotCompilerService::RegisterScreenStatusSubscriber success";
isScreenStatusSubscribered_ = true;
}
}
void AotCompilerService::UnRegisterPowerDisconnectedListener()
{
LOG_SA(DEBUG) << "AotCompilerService::UnRegisterPowerDisconnectedListener";
@ -187,4 +205,18 @@ void AotCompilerService::UnRegisterPowerDisconnectedListener()
isPowerEventSubscribered_ = false;
LOG_SA(INFO) << "AotCompilerService::UnRegisterPowerDisconnectedListener done";
}
void AotCompilerService::UnRegisterScreenStatusSubscriber()
{
LOG_SA(DEBUG) << "AotCompilerService::UnRegisterScreenStatusSubscriber";
if (!isScreenStatusSubscribered_) {
return;
}
if (!EventFwk::CommonEventManager::UnSubscribeCommonEvent(screenStatusSubscriber_)) {
LOG_SA(INFO) << "AotCompilerService::UnRegisterScreenStatusSubscriber failed";
}
screenStatusSubscriber_ = nullptr;
isScreenStatusSubscribered_ = false;
LOG_SA(INFO) << "AotCompilerService::UnRegisterScreenStatusSubscriber done";
}
} // namespace OHOS::ArkCompiler

View File

@ -0,0 +1,35 @@
/*
* 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 "screen_status_listener.h"
#include "common_event_manager.h"
#include "common_event_support.h"
#include "aot_compiler_impl.h"
#include "ecmascript/log_wrapper.h"
namespace OHOS::ArkCompiler {
ScreenStatusSubscriber::ScreenStatusSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
: EventFwk::CommonEventSubscriber(subscribeInfo)
{
}
void ScreenStatusSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data)
{
LOG_SA(INFO) << "ScreenStatusSubscriber::OnReceiveEvent";
AotCompilerImpl::GetInstance().HandleScreenOn();
}
} // namespace OHOS::ArkCompiler

View File

@ -32,5 +32,6 @@ aot_compiler_service_sources = [
"${compiler_service_root}/src/aot_compiler_load_callback.cpp",
"${compiler_service_root}/src/aot_compiler_service.cpp",
"${compiler_service_root}/src/power_disconnected_listener.cpp",
"${compiler_service_root}/src/screen_status_listener.cpp",
"${compiler_service_root}/test/mock/src/ecmascript/log_wrapper.cpp",
]

View File

@ -38,6 +38,7 @@ ohos_fuzztest("AotCompilerArgsPrepareFuzzTest") {
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",

View File

@ -38,6 +38,7 @@ ohos_fuzztest("CompilerInterfaceStubFuzzTest") {
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",

View File

@ -41,6 +41,7 @@ ohos_unittest("AotCompilerClientUnitTest") {
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",

View File

@ -40,6 +40,7 @@ ohos_unittest("AotCompilerServiceUnitTest") {
"icu:shared_icui18n",
"icu:shared_icuuc",
"ipc:ipc_core",
"power_manager:powermgr_client",
"runtime_core:libarkfile_static",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",