Feature: 增加灭锁屏事件监听

Signed-off-by: z00838083 <zhuhuixuan@huawei.com>
This commit is contained in:
z00838083 2023-10-24 11:44:28 +08:00
parent 9953436313
commit 3339d58056
8 changed files with 141 additions and 0 deletions

View File

@ -38,6 +38,7 @@
"ability_runtime",
"access_token",
"bundle_framework",
"common_event_service",
"c_utils",
"device_auth",
"device_info_manager",

View File

@ -66,6 +66,7 @@ ohos_shared_library("distributedschedsvr") {
"src/app_state_observer.cpp",
"src/bundle/bundle_manager_callback_stub.cpp",
"src/bundle/bundle_manager_internal.cpp",
"src/common_event_listener.cpp",
"src/connect_death_recipient.cpp",
"src/deviceManager/dms_device_info.cpp",
"src/dfx/dms_hisysevent_report.cpp",
@ -114,6 +115,7 @@ ohos_shared_library("distributedschedsvr") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"device_auth:deviceauth_sdk",
"device_info_manager:distributed_device_profile_client",
"device_manager:devicemanagersdk",

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 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_DTBSCHEDMGR_COMMON_EVENT_LISTENER_H
#define OHOS_DTBSCHEDMGR_COMMON_EVENT_LISTENER_H
#include "common_event_data.h"
#include "common_event_manager.h"
#include "common_event_support.h"
namespace OHOS {
namespace DistributedSchedule {
class CommonEventListener : public EventFwk::CommonEventSubscriber,
public std::enable_shared_from_this<CommonEventListener> {
public:
CommonEventListener(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
: EventFwk::CommonEventSubscriber(subscribeInfo) {}
virtual ~CommonEventListener() = default;
void OnReceiveEvent(const EventFwk::CommonEventData &eventData);
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DTBSCHEDMGR_COMMON_EVENT_LISTENER_H

View File

@ -25,6 +25,7 @@
#include <vector>
#include "bundle/bundle_manager_internal.h"
#include "common_event_listener.h"
#include "distributed_mission_broadcast_listener.h"
#include "distributed_mission_died_listener.h"
#include "distributed_mission_focused_listener.h"
@ -42,6 +43,11 @@ struct currentMissionInfo {
struct currentIconInfo {
std::string senderNetworkId;
std::string bundleName;
bool isEmpty()
{
return (this->senderNetworkId == "" && this->bundleName == "");
}
};
class DistributedSchedContinueManager {
@ -70,6 +76,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);
void NotifyScreenLockorOff();
private:
void AddCancelMissionFocusedTimer(const int32_t missionId);

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 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 "common_event_listener.h"
#include "dtbschedmgr_log.h"
#include "mission/distributed_sched_continue_manager.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "CommonEventListener";
}
void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventData)
{
HILOGD("OnReceiveEvent called");
DistributedSchedContinueManager::GetInstance().NotifyScreenLockorOff();
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -57,6 +57,14 @@ void DistributedSchedContinueManager::Init()
return;
}
missionDiedListener_ = new DistributedMissionDiedListener();
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED);
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
auto applyMonitor = std::make_shared<CommonEventListener>(subscribeInfo);
EventFwk::CommonEventManager::SubscribeCommonEvent(applyMonitor);
eventThread_ = std::thread(&DistributedSchedContinueManager::StartEvent, this);
std::unique_lock<std::mutex> lock(eventMutex_);
eventCon_.wait(lock, [this] {
@ -583,5 +591,38 @@ void DistributedSchedContinueManager::NotifyDeid(const sptr<IRemoteObject>& obj)
}
HILOGI("NotifyDeid end");
}
void DistributedSchedContinueManager::NotifyScreenLockorOff()
{
HILOGI("NotifyScreenLockorOff begin");
std::string senderNetworkId;
std::string bundleName;
{
std::lock_guard<std::mutex> currentIconLock(iconMutex_);
if (iconInfo_.isEmpty()) {
HILOGW("Saved iconInfo has already been cleared, task abort.");
return;
}
senderNetworkId = iconInfo_.senderNetworkId;
bundleName = iconInfo_.bundleName;
iconInfo_.senderNetworkId = "";
iconInfo_.bundleName = "";
}
HILOGI("Saved iconInfo cleared, networkId = %{public}s, bundleName = %{public}s",
DnetworkAdapter::AnonymizeNetworkId(senderNetworkId).c_str(), bundleName.c_str());
{
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
auto iterItem = registerOnListener_.find(onType_);
if (iterItem == registerOnListener_.end()) {
HILOGI("Get iterItem failed from registerOnListener_, nobody registed");
return;
}
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
for (auto iter : objs) {
NotifyRecvBroadcast(iter, senderNetworkId, bundleName, INACTIVE);
}
}
HILOGI("NotifyScreenLockorOff end");
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -46,6 +46,7 @@ dsched_external_deps = [
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"device_auth:deviceauth_sdk",
"device_info_manager:distributed_device_profile_client",
"device_manager:devicemanagersdk",
@ -100,6 +101,7 @@ dtbschedmgr_sources = [
"${distributed_service}/dtbschedmgr/src/app_state_observer.cpp",
"${distributed_service}/dtbschedmgr/src/bundle/bundle_manager_callback_stub.cpp",
"${distributed_service}/dtbschedmgr/src/bundle/bundle_manager_internal.cpp",
"${distributed_service}/dtbschedmgr/src/common_event_listener.cpp",
"${distributed_service}/dtbschedmgr/src/connect_death_recipient.cpp",
"${distributed_service}/dtbschedmgr/src/deviceManager/dms_device_info.cpp",
"${distributed_service}/dtbschedmgr/src/dfx/dms_hisysevent_report.cpp",

View File

@ -30,6 +30,7 @@ namespace {
const std::string TYPE = "type";
const std::string BUNDLENAME_01 = "bundleName01";
const std::string BUNDLENAME_02 = "bundleName02";
const std::string NETWORKID_01 = "networkId01";
constexpr int32_t MISSIONID_01 = 1;
constexpr int32_t MISSIONID_02 = 2;
constexpr int32_t ACTIVE = 0;
@ -517,5 +518,24 @@ HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness001, Tes
DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 end" << std::endl;
}
/**
* @tc.name: testNotifyScreenLockorOff001
* @tc.desc: test NotifyScreenLockorOff normal
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testNotifyScreenLockorOff001, TestSize.Level1)
{
DTEST_LOG << "DMSContinueManagerTest testNotifyScreenLockorOff001 start" << std::endl;
sptr<IRemoteObject> obj01 = new RemoteOnListenerStubTest();
DistributedSchedContinueManager::GetInstance().RegisterOnListener(TYPE, obj01);
EXPECT_NE(DistributedSchedContinueManager::GetInstance().registerOnListener_.size(), 0);
DistributedSchedContinueManager::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
DistributedSchedContinueManager::GetInstance().NotifyScreenLockorOff();
EXPECT_EQ(DistributedSchedContinueManager::GetInstance().iconInfo_.senderNetworkId, "");
DTEST_LOG << "DMSContinueManagerTest testNotifyScreenLockorOff001 end" << std::endl;
}
} // namespace DistributedSchedule
} // namespace OHOS