mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-27 00:20:44 +00:00
commit
bb3ebf48d3
@ -193,6 +193,8 @@ ohos_shared_library("distributedschedsvr") {
|
||||
if (dmsfwk_mmi_listener) {
|
||||
external_deps += [ "input:libmmi-client" ]
|
||||
sources += [ "src/adapter/mmi_adapter.cpp" ]
|
||||
} else {
|
||||
sources += [ "src/adapter/mmi_adapter_common.cpp" ]
|
||||
}
|
||||
|
||||
install_images = [ system_base_dir ]
|
||||
|
@ -16,13 +16,18 @@
|
||||
#ifndef OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
|
||||
#define OHOS_DTBSCHEDMGR_MMI_ADAPTER_H
|
||||
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
#include <thread>
|
||||
|
||||
#include "event_handler.h"
|
||||
|
||||
#include "i_input_event_consumer.h"
|
||||
#include "input_manager.h"
|
||||
#endif
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
|
||||
class MMIAdapter {
|
||||
public:
|
||||
DECLARE_SINGLE_INSTANCE_BASE(MMIAdapter);
|
||||
@ -30,17 +35,30 @@ public:
|
||||
MMIAdapter() = default;
|
||||
virtual ~MMIAdapter() = default;
|
||||
|
||||
class MMIEventCallback : public MMI::IInputEventConsumer {
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
};
|
||||
void Init();
|
||||
int32_t AddMMIListener();
|
||||
void RemoveMMIListener(int32_t monitorId);
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
class MMIEventCallback : public MMI::IInputEventConsumer {
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
};
|
||||
|
||||
private:
|
||||
void StartEvent();
|
||||
void PostRawMMIEvent();
|
||||
void PostUnfreezeMMIEvent();
|
||||
void HandleRawMMIEvent();
|
||||
void HandleUnfreezeMMIEvent();
|
||||
|
||||
std::thread eventThread_;
|
||||
std::condition_variable eventCon_;
|
||||
std::mutex eventMutex_;
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
|
||||
std::shared_ptr<MMI::IInputEventConsumer> mmiCallback_;
|
||||
bool isMMIFreezed_ = false;
|
||||
#endif
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -64,10 +64,7 @@ public:
|
||||
int32_t GetMissionId(const std::string& bundleName, int32_t& missionId);
|
||||
void NotifyDeid(const sptr<IRemoteObject>& obj);
|
||||
int32_t SetMissionContinueState(const int32_t missionId, const AAFwk::ContinueState& state);
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
void OnMMIEvent();
|
||||
void ResetMMIFlag();
|
||||
#endif
|
||||
|
||||
private:
|
||||
int32_t GetCurrentMissionId();
|
||||
@ -81,10 +78,8 @@ private:
|
||||
bool IsContinue(const int32_t& missionId, const std::string& bundleName);
|
||||
int32_t DealSetMissionContinueStateBusiness(const int32_t missionId, const AAFwk::ContinueState& state);
|
||||
int32_t CheckContinueState(const int32_t missionId);
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
void AddMMIListener();
|
||||
void RemoveMMIListener();
|
||||
#endif
|
||||
private:
|
||||
currentMissionInfo info_ = { INVALID_MISSION_ID, false };
|
||||
sptr<DistributedMissionFocusedListener> missionFocusedListener_;
|
||||
@ -97,12 +92,7 @@ private:
|
||||
std::mutex eventMutex_;
|
||||
std::mutex iconMutex_;
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
std::mutex mmiMutex_;
|
||||
int32_t mmiMonitorId_ = INVALID_MISSION_ID;
|
||||
int64_t lastMMIEvent_ = 0;
|
||||
bool needMMIBroadcast_ = false;
|
||||
#endif
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -15,6 +15,10 @@
|
||||
|
||||
#include "adapter/mmi_adapter.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/distributed_sched_continue_manager.h"
|
||||
|
||||
@ -23,6 +27,9 @@ namespace DistributedSchedule {
|
||||
|
||||
namespace {
|
||||
const std::string TAG = "MMIAdapter";
|
||||
const std::string MMI_ADAPTER = "mmi_adapter";
|
||||
const std::string FREEZE_MMI_EVENT_TASK = "task_freeze_mmi_event";
|
||||
constexpr int32_t FREEZE_MMI_EVENT_INTERVAL = 5000;
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(MMIAdapter);
|
||||
@ -31,21 +38,25 @@ void MMIAdapter::Init()
|
||||
{
|
||||
HILOGI("Init");
|
||||
mmiCallback_ = std::make_shared<MMIAdapter::MMIEventCallback>();
|
||||
eventThread_ = std::thread(&MMIAdapter::StartEvent, this);
|
||||
std::unique_lock<std::mutex> lock(eventMutex_);
|
||||
eventCon_.wait(lock, [this] {
|
||||
return eventHandler_ != nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void MMIAdapter::MMIEventCallback::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
|
||||
void MMIAdapter::StartEvent()
|
||||
{
|
||||
DistributedSchedContinueManager::GetInstance().OnMMIEvent();
|
||||
}
|
||||
|
||||
void MMIAdapter::MMIEventCallback::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
DistributedSchedContinueManager::GetInstance().OnMMIEvent();
|
||||
}
|
||||
|
||||
void MMIAdapter::MMIEventCallback::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
|
||||
{
|
||||
DistributedSchedContinueManager::GetInstance().OnMMIEvent();
|
||||
HILOGI("StartEvent start");
|
||||
prctl(PR_SET_NAME, MMI_ADAPTER.c_str());
|
||||
auto runner = AppExecFwk::EventRunner::Create();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(eventMutex_);
|
||||
eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
eventCon_.notify_one();
|
||||
runner->Run();
|
||||
HILOGI("StartEvent end");
|
||||
}
|
||||
|
||||
int32_t MMIAdapter::AddMMIListener()
|
||||
@ -53,6 +64,7 @@ int32_t MMIAdapter::AddMMIListener()
|
||||
HILOGD("AddMMIListener called");
|
||||
int32_t ret = MMI::InputManager::GetInstance()->AddMonitor(mmiCallback_);
|
||||
HILOGD("AddMMIListener result: %{public}d", ret);
|
||||
isMMIFreezed_ = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -62,5 +74,59 @@ void MMIAdapter::RemoveMMIListener(int32_t monitorId)
|
||||
MMI::InputManager::GetInstance()->RemoveMonitor(monitorId);
|
||||
return;
|
||||
}
|
||||
|
||||
void MMIAdapter::PostRawMMIEvent()
|
||||
{
|
||||
auto func = [this]() {
|
||||
HandleRawMMIEvent();
|
||||
};
|
||||
if (eventHandler_ != nullptr) {
|
||||
eventHandler_->PostTask(func);
|
||||
} else {
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
}
|
||||
}
|
||||
|
||||
void MMIAdapter::PostUnfreezeMMIEvent()
|
||||
{
|
||||
auto func = [this]() {
|
||||
HandleUnfreezeMMIEvent();
|
||||
};
|
||||
if (eventHandler_ != nullptr) {
|
||||
eventHandler_->PostTask(func, FREEZE_MMI_EVENT_TASK, FREEZE_MMI_EVENT_INTERVAL);
|
||||
} else {
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
}
|
||||
}
|
||||
|
||||
void MMIAdapter::HandleRawMMIEvent()
|
||||
{
|
||||
if (isMMIFreezed_) {
|
||||
return;
|
||||
}
|
||||
isMMIFreezed_ = true;
|
||||
DistributedSchedContinueManager::GetInstance().OnMMIEvent();
|
||||
PostUnfreezeMMIEvent();
|
||||
}
|
||||
|
||||
void MMIAdapter::HandleUnfreezeMMIEvent()
|
||||
{
|
||||
isMMIFreezed_ = false;
|
||||
}
|
||||
|
||||
void MMIAdapter::MMIEventCallback::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
|
||||
{
|
||||
MMIAdapter::GetInstance().PostRawMMIEvent();
|
||||
}
|
||||
|
||||
void MMIAdapter::MMIEventCallback::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
MMIAdapter::GetInstance().PostRawMMIEvent();
|
||||
}
|
||||
|
||||
void MMIAdapter::MMIEventCallback::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
|
||||
{
|
||||
MMIAdapter::GetInstance().PostRawMMIEvent();
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
41
services/dtbschedmgr/src/adapter/mmi_adapter_common.cpp
Normal file
41
services/dtbschedmgr/src/adapter/mmi_adapter_common.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 "adapter/mmi_adapter.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "MMIAdapter";
|
||||
}
|
||||
IMPLEMENT_SINGLE_INSTANCE(MMIAdapter);
|
||||
|
||||
void MMIAdapter::Init()
|
||||
{
|
||||
HILOGD("called");
|
||||
}
|
||||
int32_t MMIAdapter::AddMMIListener()
|
||||
{
|
||||
HILOGD("called");
|
||||
}
|
||||
|
||||
void MMIAdapter::RemoveMMIListener(int32_t monitorId)
|
||||
{
|
||||
HILOGD("called");
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -766,10 +766,6 @@ void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId
|
||||
if (resultCode == ERR_OK && dschedContinuation_->IsCleanMission(missionId)) {
|
||||
result = AbilityManagerClient::GetInstance()->CleanMission(missionId);
|
||||
HILOGD("clean mission result:%{public}d", result);
|
||||
} else {
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
DistributedSchedContinueManager::GetInstance().ResetMMIFlag();
|
||||
#endif
|
||||
}
|
||||
result = dschedContinuation_->NotifyMissionCenterResult(missionId, resultCode);
|
||||
} else {
|
||||
|
@ -16,9 +16,7 @@
|
||||
#include "mission/distributed_sched_continue_manager.h"
|
||||
|
||||
#include "adapter/dnetwork_adapter.h"
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
#include "adapter/mmi_adapter.h"
|
||||
#endif
|
||||
#include "datetime_ex.h"
|
||||
#include "distributed_sched_adapter.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
@ -52,9 +50,7 @@ void DistributedSchedContinueManager::Init()
|
||||
return;
|
||||
}
|
||||
missionDiedListener_ = new DistributedMissionDiedListener();
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
MMIAdapter::GetInstance().Init();
|
||||
#endif
|
||||
#ifdef SUPPORT_COMMON_EVENT_SERVICE
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
|
||||
@ -196,7 +192,6 @@ int32_t DistributedSchedContinueManager::SendSoftbusEvent(uint32_t accessTokenId
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
void DistributedSchedContinueManager::AddMMIListener()
|
||||
{
|
||||
if (mmiMonitorId_ >= 0) {
|
||||
@ -213,7 +208,6 @@ void DistributedSchedContinueManager::AddMMIListener()
|
||||
|
||||
void DistributedSchedContinueManager::RemoveMMIListener()
|
||||
{
|
||||
std::lock_guard<std::mutex> mmiEventLock(mmiMutex_);
|
||||
if (mmiMonitorId_ < 0) {
|
||||
HILOGI("No MMI listener to be removed, monitor id: %{public}d", mmiMonitorId_);
|
||||
return;
|
||||
@ -222,10 +216,8 @@ void DistributedSchedContinueManager::RemoveMMIListener()
|
||||
HILOGI("MMI listener has been removed, monitor id: %{public}d", mmiMonitorId_);
|
||||
|
||||
mmiMonitorId_ = INVALID_MISSION_ID;
|
||||
needMMIBroadcast_ = false;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t DistributedSchedContinueManager::DealFocusedBusiness(const int32_t missionId)
|
||||
{
|
||||
@ -292,40 +284,6 @@ int32_t DistributedSchedContinueManager::CheckContinueState(const int32_t missio
|
||||
void DistributedSchedContinueManager::DealTimerUnfocusedBussiness(const int32_t missionId)
|
||||
{
|
||||
HILOGI("DealTimerUnfocusedBussiness start, missionId: %{public}d", missionId);
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
int64_t interval = GetTickCount() - lastMMIEvent_;
|
||||
if (interval < CANCEL_FOCUSED_DELAYED) {
|
||||
HILOGD("Last MMI event happened in interval, keep mission focused.");
|
||||
auto refocusedTask = [this, missionId, interval]() {
|
||||
if (missionId == info_.currentMissionId && info_.currentIsContinuable) {
|
||||
AddCancelMissionFocusedTimer(missionId, CANCEL_FOCUSED_DELAYED - static_cast<int32_t>(interval));
|
||||
}
|
||||
DealFocusedBusiness(missionId);
|
||||
};
|
||||
if (eventHandler_ != nullptr) {
|
||||
eventHandler_->RemoveTask(CANCEL_FOCUSED_TASK);
|
||||
eventHandler_->PostTask(refocusedTask);
|
||||
} else {
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
}
|
||||
return;
|
||||
}
|
||||
{
|
||||
HILOGD("Last MMI event happened out of interval, set mission unfocused.");
|
||||
std::lock_guard<std::mutex> mmiEventLock(mmiMutex_);
|
||||
needMMIBroadcast_ = true;
|
||||
auto unfocusedTask = [this, missionId]() {
|
||||
DealUnfocusedBusiness(missionId, false);
|
||||
};
|
||||
if (eventHandler_ != nullptr) {
|
||||
eventHandler_->RemoveTask(CANCEL_FOCUSED_TASK);
|
||||
eventHandler_->PostTask(unfocusedTask);
|
||||
} else {
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
}
|
||||
return;
|
||||
}
|
||||
#else
|
||||
auto unfocusedTask = [this, missionId]() {
|
||||
DealUnfocusedBusiness(missionId, false);
|
||||
};
|
||||
@ -336,7 +294,6 @@ void DistributedSchedContinueManager::DealTimerUnfocusedBussiness(const int32_t
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t DistributedSchedContinueManager::DealUnfocusedBusiness(const int32_t missionId, bool isUnfocused)
|
||||
@ -477,14 +434,10 @@ int32_t DistributedSchedContinueManager::DealSetMissionContinueStateBusiness(con
|
||||
uint8_t type = DMS_FOCUSED_TYPE;
|
||||
if (state == AAFwk::ContinueState::CONTINUESTATE_INACTIVE) {
|
||||
type = DMS_UNFOCUSED_TYPE;
|
||||
}
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
if (state == AAFwk::ContinueState::CONTINUESTATE_INACTIVE) {
|
||||
RemoveMMIListener();
|
||||
} else {
|
||||
AddMMIListener();
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = SendSoftbusEvent(accessTokenId, type);
|
||||
if (ret != ERR_OK) {
|
||||
@ -522,26 +475,10 @@ void DistributedSchedContinueManager::NotifyDeid(const sptr<IRemoteObject>& obj)
|
||||
HILOGI("NotifyDeid end");
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
|
||||
void DistributedSchedContinueManager::OnMMIEvent()
|
||||
{
|
||||
std::lock_guard<std::mutex> mmiEventLock(mmiMutex_);
|
||||
lastMMIEvent_ = GetTickCount();
|
||||
|
||||
if (!needMMIBroadcast_) {
|
||||
return;
|
||||
}
|
||||
HILOGD("Need to resend focus broadcast, missionId = %{public}d", info_.currentMissionId);
|
||||
HILOGD("OnMMIEvent, missionId = %{public}d", info_.currentMissionId);
|
||||
DistributedSchedContinueManager::GetInstance().NotifyMissionFocused(info_.currentMissionId);
|
||||
needMMIBroadcast_ = false;
|
||||
}
|
||||
|
||||
void DistributedSchedContinueManager::ResetMMIFlag()
|
||||
{
|
||||
HILOGI("Reset MMI focus flag");
|
||||
std::lock_guard<std::mutex> mmiEventLock(mmiMutex_);
|
||||
needMMIBroadcast_ = true;
|
||||
}
|
||||
#endif
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user