mirror of
https://gitee.com/openharmony/hiviewdfx_hiview
synced 2024-11-23 09:09:49 +00:00
!2225 增加部分场景下系统事件查询和订阅的管控逻辑
Merge pull request !2225 from honghecun/master
This commit is contained in:
commit
deef23bf6a
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-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
|
||||
@ -40,6 +40,7 @@ ohos_source_set("sys_event_service_ohos") {
|
||||
|
||||
sources = [
|
||||
"src/ash_mem_utils.cpp",
|
||||
"src/compliant_event_checker.cpp",
|
||||
"src/data_publisher.cpp",
|
||||
"src/data_publisher_sys_event_callback.cpp",
|
||||
"src/data_share_dao.cpp",
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_HIVIEWDFX_COMPLIANT_EVENT_CHECKER_H
|
||||
#define OHOS_HIVIEWDFX_COMPLIANT_EVENT_CHECKER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
class CompliantEventChecker {
|
||||
public:
|
||||
CompliantEventChecker();
|
||||
~CompliantEventChecker() = default;
|
||||
|
||||
public:
|
||||
bool IsCompliantEvent(const std::string& domain, const std::string& eventName);
|
||||
|
||||
private:
|
||||
bool isSecureEnabeled_ = false;
|
||||
};
|
||||
} // namespace HiviewDFX
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_HIVIEWDFX_COMPLIANT_EVENT_CHECKER_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-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
|
||||
@ -51,7 +51,7 @@ private:
|
||||
|
||||
class BaseEventQueryWrapper {
|
||||
public:
|
||||
BaseEventQueryWrapper(std::shared_ptr<EventStore::SysEventQuery> query) : query_(query) {}
|
||||
BaseEventQueryWrapper(std::shared_ptr<EventStore::SysEventQuery> query);
|
||||
virtual ~BaseEventQueryWrapper() {}
|
||||
|
||||
public:
|
||||
@ -72,6 +72,13 @@ public:
|
||||
bool IsQueryComplete() const;
|
||||
bool NeedStartNextQuery();
|
||||
|
||||
protected:
|
||||
struct QuerierInfo {
|
||||
int32_t uid = 0;
|
||||
int32_t pid = 0;
|
||||
std::string processName;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void BuildQuery() = 0;
|
||||
virtual void Order() = 0;
|
||||
@ -91,6 +98,7 @@ protected:
|
||||
int32_t ignoredEventCnt_ = 0;
|
||||
std::shared_ptr<EventStore::SysEventQuery> query_ = nullptr;
|
||||
std::vector<SysEventQueryRule> queryRules_;
|
||||
QuerierInfo querierInfo_;
|
||||
|
||||
private:
|
||||
bool isFirstPartialQuery_ = true;
|
||||
|
@ -36,12 +36,6 @@
|
||||
#include "sys_event_service_stub.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
using CallbackObjectOhos = OHOS::sptr<OHOS::IRemoteObject>;
|
||||
using SysEventCallbackPtrOhos = OHOS::sptr<OHOS::HiviewDFX::ISysEventCallback>;
|
||||
using SysEventRuleGroupOhos = std::vector<OHOS::HiviewDFX::SysEventRule>;
|
||||
using SysEventQueryRuleGroupOhos = std::vector<OHOS::HiviewDFX::SysEventQueryRule>;
|
||||
using RegisteredListeners = std::map<CallbackObjectOhos, std::pair<int32_t, SysEventRuleGroupOhos>>;
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
using NotifySysEvent = std::function<void (std::shared_ptr<Event>)>;
|
||||
@ -68,28 +62,34 @@ public:
|
||||
virtual ~SysEventServiceOhos() = default;
|
||||
|
||||
static sptr<SysEventServiceOhos> GetInstance();
|
||||
static void StartService(SysEventServiceBase* service,
|
||||
const OHOS::HiviewDFX::NotifySysEvent notify);
|
||||
static SysEventServiceBase* GetSysEventService(
|
||||
OHOS::HiviewDFX::SysEventServiceBase* service = nullptr);
|
||||
void OnSysEvent(std::shared_ptr<OHOS::HiviewDFX::SysEvent>& sysEvent);
|
||||
int32_t AddListener(const SysEventRuleGroupOhos& rules, const SysEventCallbackPtrOhos& callback) override;
|
||||
int32_t RemoveListener(const SysEventCallbackPtrOhos& callback) override;
|
||||
int32_t Query(const QueryArgument& queryArgument, const SysEventQueryRuleGroupOhos& rules,
|
||||
const OHOS::sptr<OHOS::HiviewDFX::IQuerySysEventCallback>& callback) override;
|
||||
int32_t SetDebugMode(const SysEventCallbackPtrOhos& callback, bool mode) override;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote);
|
||||
static void StartService(SysEventServiceBase* service, const NotifySysEvent notify);
|
||||
static SysEventServiceBase* GetSysEventService(SysEventServiceBase* service = nullptr);
|
||||
void OnSysEvent(std::shared_ptr<SysEvent>& sysEvent);
|
||||
int32_t AddListener(const std::vector<SysEventRule>& rules, const OHOS::sptr<ISysEventCallback>& callback) override;
|
||||
int32_t RemoveListener(const OHOS::sptr<ISysEventCallback>& callback) override;
|
||||
int32_t Query(const QueryArgument& queryArgument, const std::vector<SysEventQueryRule>& rules,
|
||||
const OHOS::sptr<IQuerySysEventCallback>& callback) override;
|
||||
int32_t SetDebugMode(const OHOS::sptr<ISysEventCallback>& callback, bool mode) override;
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote);
|
||||
void BindGetTagFunc(const GetTagByDomainNameFunc& getTagFunc);
|
||||
void BindGetTypeFunc(const GetTypeByDomainNameFunc& getTypeFunc);
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
|
||||
int64_t AddSubscriber(const SysEventQueryRuleGroupOhos &rules) override;
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
int64_t AddSubscriber(const std::vector<SysEventQueryRule>& rules) override;
|
||||
int32_t RemoveSubscriber() override;
|
||||
int64_t Export(const QueryArgument &queryArgument, const SysEventQueryRuleGroupOhos &rules) override;
|
||||
int64_t Export(const QueryArgument& queryArgument, const std::vector<SysEventQueryRule>& rules) override;
|
||||
void SetWorkLoop(std::shared_ptr<EventLoop> looper);
|
||||
|
||||
private:
|
||||
struct ListenerInfo {
|
||||
int32_t pid = 0;
|
||||
int32_t uid = 0;
|
||||
std::vector<SysEventRule> rules;
|
||||
};
|
||||
|
||||
private:
|
||||
bool HasAccessPermission() const;
|
||||
bool BuildEventQuery(std::shared_ptr<EventQueryWrapperBuilder> builder, const SysEventQueryRuleGroupOhos& rules);
|
||||
bool BuildEventQuery(std::shared_ptr<EventQueryWrapperBuilder> builder,
|
||||
const std::vector<SysEventQueryRule>& rules);
|
||||
std::string GetTagByDomainAndName(const std::string& eventDomain, const std::string& eventName);
|
||||
uint32_t GetTypeByDomainAndName(const std::string& eventDomain, const std::string& eventName);
|
||||
void MergeEventList(const std::vector<SysEventQueryRule>& rules, std::vector<std::string>& events) const;
|
||||
@ -97,9 +97,9 @@ private:
|
||||
private:
|
||||
sptr<CallbackDeathRecipient> deathRecipient_;
|
||||
std::mutex listenersMutex_;
|
||||
RegisteredListeners registeredListeners_;
|
||||
std::map<OHOS::sptr<OHOS::IRemoteObject>, ListenerInfo> registeredListeners_;
|
||||
bool isDebugMode_;
|
||||
SysEventCallbackPtrOhos debugModeCallback_;
|
||||
OHOS::sptr<ISysEventCallback> debugModeCallback_;
|
||||
GetTagByDomainNameFunc getTagFunc_;
|
||||
GetTypeByDomainNameFunc getTypeFunc_;
|
||||
static OHOS::HiviewDFX::NotifySysEvent gISysEventNotify_;
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 "compliant_event_checker.h"
|
||||
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "hiview_logger.h"
|
||||
#include "parameter_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
namespace {
|
||||
DEFINE_LOG_TAG("CompliantEventChecker");
|
||||
|
||||
constexpr int64_t SECURE_ENABALED_VAL = 1;
|
||||
|
||||
std::unordered_map<std::string, std::list<std::string>> COMPLIANT_EVENT_CONFIGS {
|
||||
{"AAFWK", { "START_ABILITY", "ABILITY_ONFOREGROUND", "ABILITY_ONBACKGROUND", "ABILITY_ONACTIVE",
|
||||
"ABILITY_ONINACTIVE", "TERMINATE_ABILITY"}},
|
||||
{"ACE", {"INTERACTION_COMPLETED_LATENCY"}},
|
||||
{"AV_CODEC", {"CODEC_START_INFO"}},
|
||||
{"GRAPHIC", {"INTERACTION_COMPLETED_LATENCY"}},
|
||||
{"LOCATION", {"GNSS_STATE"}},
|
||||
{"PERFORMANCE", {}},
|
||||
{"RELIBILITY", {}},
|
||||
{"STABILITY", {"JS_ERROR", "CPP_CRASH", "APP_FREEZE", "MEMORY_LEAK", "FD_LEAK", "THREAD_LEAK", "ADDR_SANITIZER"}},
|
||||
{"WORKSCHEDULER", {"WORK_ADD", "WORK_REMOVE", "WORK_START", "WORK_STOP"}},
|
||||
};
|
||||
}
|
||||
|
||||
CompliantEventChecker::CompliantEventChecker()
|
||||
{
|
||||
isSecureEnabeled_ = (Parameter::GetInteger("const.secure", SECURE_ENABALED_VAL) == SECURE_ENABALED_VAL);
|
||||
HIVIEW_LOGD("value of const.secure is %{public}d", isSecureEnabeled_);
|
||||
}
|
||||
|
||||
bool CompliantEventChecker::IsCompliantEvent(const std::string& domain, const std::string& eventName)
|
||||
{
|
||||
if (!isSecureEnabeled_) {
|
||||
return true;
|
||||
}
|
||||
auto iter = COMPLIANT_EVENT_CONFIGS.find(domain);
|
||||
if (iter == COMPLIANT_EVENT_CONFIGS.end()) {
|
||||
return false;
|
||||
}
|
||||
if (iter->second.empty()) {
|
||||
HIVIEW_LOGD("event with domain [%{public}s] is compliant", domain.c_str());
|
||||
return true;
|
||||
}
|
||||
auto findRet = std::find(iter->second.begin(), iter->second.end(), eventName);
|
||||
if (findRet != iter->second.end()) {
|
||||
HIVIEW_LOGD("event [%{public}s|%{public}s] is compliant", domain.c_str(), eventName.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace HiviewDFX
|
||||
} // namespace OHOS
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-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
|
||||
@ -18,6 +18,7 @@
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
|
||||
#include "compliant_event_checker.h"
|
||||
#include "common_utils.h"
|
||||
#include "data_publisher.h"
|
||||
#include "hiview_event_common.h"
|
||||
@ -39,13 +40,7 @@ constexpr int32_t IGNORED_DEFAULT_CNT = 0;
|
||||
constexpr int MAX_QUERY_EVENTS = 1000; // The maximum number of queries is 1000 at one time
|
||||
constexpr int MAX_TRANS_BUF = 1024 * 770; // Max transmission at one time: 384KB * 2 + 2KB for extra fields
|
||||
constexpr size_t U16_CHAR_SIZE = sizeof(char16_t);
|
||||
|
||||
EventStore::QueryProcessInfo GetCallingProcessInfo()
|
||||
{
|
||||
std::string processName = CommonUtils::GetProcNameByPid(IPCSkeleton::GetCallingPid());
|
||||
processName = processName.empty() ? "unknown" : processName;
|
||||
return std::make_pair(IPCSkeleton::GetCallingPid(), processName);
|
||||
}
|
||||
constexpr int32_t HID_SHELL = 2000;
|
||||
}
|
||||
|
||||
bool ConditionParser::ParseCondition(const std::string& condStr, EventStore::Cond& condition)
|
||||
@ -179,6 +174,16 @@ bool ConditionParser::ParseQueryCondition(const std::string& condStr, EventStore
|
||||
return true;
|
||||
}
|
||||
|
||||
BaseEventQueryWrapper::BaseEventQueryWrapper(std::shared_ptr<EventStore::SysEventQuery> query)
|
||||
{
|
||||
query_ = query;
|
||||
|
||||
querierInfo_.uid = IPCSkeleton::GetCallingUid();
|
||||
querierInfo_.pid = IPCSkeleton::GetCallingPid();
|
||||
querierInfo_.processName = CommonUtils::GetProcNameByPid(querierInfo_.pid);
|
||||
HIVIEW_LOGI("uid is %{public}d, pid is %{public}d of querier", querierInfo_.uid, querierInfo_.pid);
|
||||
}
|
||||
|
||||
void BaseEventQueryWrapper::Query(const OHOS::sptr<OHOS::HiviewDFX::IQueryBaseCallback>& eventQueryCallback,
|
||||
int32_t& queryResult)
|
||||
{
|
||||
@ -193,7 +198,8 @@ void BaseEventQueryWrapper::Query(const OHOS::sptr<OHOS::HiviewDFX::IQueryBaseCa
|
||||
", endTime=%{public}" PRId64 ", maxEvents=%{public}d, fromSeq=%{public}" PRId64
|
||||
", toSeq=%{public}" PRId64 ", queryLimit=%{public}d.", argument_.beginTime, argument_.endTime,
|
||||
argument_.maxEvents, argument_.fromSeq, argument_.toSeq, queryLimit_);
|
||||
auto resultSet = query_->Execute(queryLimit_, { false, isFirstPartialQuery_ }, GetCallingProcessInfo(),
|
||||
auto resultSet = query_->Execute(queryLimit_, { false, isFirstPartialQuery_ },
|
||||
std::make_pair(querierInfo_.pid, querierInfo_.processName),
|
||||
[&queryResult] (EventStore::DbQueryStatus status) {
|
||||
std::unordered_map<EventStore::DbQueryStatus, int32_t> statusToCode {
|
||||
{ EventStore::DbQueryStatus::CONCURRENT, ERR_TOO_MANY_CONCURRENT_QUERIES },
|
||||
@ -251,12 +257,19 @@ void BaseEventQueryWrapper::TransportSysEvent(OHOS::HiviewDFX::EventStore::Resul
|
||||
const OHOS::sptr<OHOS::HiviewDFX::IQueryBaseCallback>& callback, std::pair<int64_t, int32_t>& details)
|
||||
{
|
||||
OHOS::HiviewDFX::EventStore::ResultSet::RecordIter iter;
|
||||
CompliantEventChecker compliantEventChecker;
|
||||
while (result.HasNext() && argument_.maxEvents > 0) {
|
||||
iter = result.Next();
|
||||
auto eventJsonStr = iter->AsJsonStr();
|
||||
if (eventJsonStr.empty()) {
|
||||
continue;
|
||||
}
|
||||
if ((querierInfo_.uid == HID_SHELL) &&
|
||||
!compliantEventChecker.IsCompliantEvent(iter->domain_, iter->eventName_)) {
|
||||
HIVIEW_LOGD("event [%{public}s|%{public}s] isn't compliant for the process with uid %{public}d",
|
||||
iter->domain_.c_str(), iter->eventName_.c_str(), querierInfo_.uid);
|
||||
continue;
|
||||
}
|
||||
std::u16string curJson = Str8ToStr16(eventJsonStr);
|
||||
int32_t eventJsonSize = static_cast<int32_t>((curJson.size() + 1) * U16_CHAR_SIZE); // 1 for '\0'
|
||||
if (eventJsonSize > MAX_TRANS_BUF) { // too large events, drop
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <set>
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "compliant_event_checker.h"
|
||||
#include "data_publisher.h"
|
||||
#include "event_query_wrapper_builder.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
@ -86,7 +87,7 @@ bool IsMatchedRule(const OHOS::HiviewDFX::SysEventRule& rule, const string& doma
|
||||
&& MatchEventType(rule.eventType, eventType);
|
||||
}
|
||||
|
||||
bool MatchRules(const SysEventRuleGroupOhos& rules, const string& domain, const string& eventName,
|
||||
bool MatchRules(const std::vector<SysEventRule>& rules, const string& domain, const string& eventName,
|
||||
const string& tag, uint32_t eventType)
|
||||
{
|
||||
return any_of(rules.begin(), rules.end(), [domain, eventName, tag, eventType] (auto& rule) {
|
||||
@ -112,26 +113,26 @@ int32_t CheckEventSubscriberAddingValidity(const std::vector<std::string>& event
|
||||
return IPC_CALL_SUCCEED;
|
||||
}
|
||||
|
||||
int32_t CheckEventQueryingValidity(const SysEventQueryRuleGroupOhos& rules, size_t limit)
|
||||
int32_t CheckEventQueryingValidity(const std::vector<SysEventQueryRule>& rules, size_t limit)
|
||||
{
|
||||
if (rules.size() > limit) {
|
||||
OHOS::HiviewDFX::RunningStatusLogUtil::LogTooManyQueryRules(rules);
|
||||
RunningStatusLogUtil::LogTooManyQueryRules(rules);
|
||||
return ERR_TOO_MANY_QUERY_RULES;
|
||||
}
|
||||
return IPC_CALL_SUCCEED;
|
||||
}
|
||||
}
|
||||
|
||||
OHOS::HiviewDFX::NotifySysEvent SysEventServiceOhos::gISysEventNotify_;
|
||||
sptr<OHOS::HiviewDFX::SysEventServiceOhos> SysEventServiceOhos::instance(new SysEventServiceOhos);
|
||||
NotifySysEvent SysEventServiceOhos::gISysEventNotify_;
|
||||
sptr<SysEventServiceOhos> SysEventServiceOhos::instance(new SysEventServiceOhos);
|
||||
|
||||
sptr<OHOS::HiviewDFX::SysEventServiceOhos> SysEventServiceOhos::GetInstance()
|
||||
sptr<SysEventServiceOhos> SysEventServiceOhos::GetInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
void SysEventServiceOhos::StartService(SysEventServiceBase *service,
|
||||
const OHOS::HiviewDFX::NotifySysEvent notify)
|
||||
const NotifySysEvent notify)
|
||||
{
|
||||
gISysEventNotify_ = notify;
|
||||
GetSysEventService(service);
|
||||
@ -166,23 +167,29 @@ uint32_t SysEventServiceOhos::GetTypeByDomainAndName(const string& eventDomain,
|
||||
return getTypeFunc_(eventDomain, eventName);
|
||||
}
|
||||
|
||||
void SysEventServiceOhos::OnSysEvent(std::shared_ptr<OHOS::HiviewDFX::SysEvent>& event)
|
||||
void SysEventServiceOhos::OnSysEvent(std::shared_ptr<SysEvent>& event)
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock(publisherMutex_);
|
||||
dataPublisher_->OnSysEvent(event);
|
||||
}
|
||||
lock_guard<mutex> lock(listenersMutex_);
|
||||
CompliantEventChecker compliantEventChecker;
|
||||
for (auto listener = registeredListeners_.begin(); listener != registeredListeners_.end(); ++listener) {
|
||||
SysEventCallbackPtrOhos callback = iface_cast<ISysEventCallback>(listener->first);
|
||||
OHOS::sptr<ISysEventCallback> callback = iface_cast<ISysEventCallback>(listener->first);
|
||||
if (callback == nullptr) {
|
||||
HIVIEW_LOGE("interface is null, no need to match rules.");
|
||||
continue;
|
||||
}
|
||||
bool isMatched = MatchRules(listener->second.second, event->domain_, event->eventName_,
|
||||
if ((listener->second.uid == HID_SHELL) &&
|
||||
!compliantEventChecker.IsCompliantEvent(event->domain_, event->eventName_)) {
|
||||
HIVIEW_LOGD("event [%{public}s|%{public}s] isn't compliant for the process with uid %{public}d",
|
||||
event->domain_.c_str(), event->eventName_.c_str(), listener->second.uid);
|
||||
continue;
|
||||
}
|
||||
bool isMatched = MatchRules(listener->second.rules, event->domain_, event->eventName_,
|
||||
event->GetTag(), event->eventType_);
|
||||
HIVIEW_LOGD("pid %{public}d rules match %{public}s.", listener->second.first,
|
||||
isMatched ? "success" : "fail");
|
||||
HIVIEW_LOGD("pid %{public}d rules match %{public}s.", listener->second.pid, isMatched ? "success" : "fail");
|
||||
if (isMatched) {
|
||||
callback->Handle(Str8ToStr16(event->domain_), Str8ToStr16(event->eventName_),
|
||||
static_cast<uint32_t>(event->eventType_), Str8ToStr16(event->AsJsonStr()));
|
||||
@ -202,7 +209,7 @@ void SysEventServiceOhos::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
return;
|
||||
}
|
||||
if (debugModeCallback_ != nullptr) {
|
||||
CallbackObjectOhos callbackObject = debugModeCallback_->AsObject();
|
||||
OHOS::sptr<OHOS::IRemoteObject> callbackObject = debugModeCallback_->AsObject();
|
||||
if (callbackObject == remoteObject && isDebugMode_) {
|
||||
HIVIEW_LOGE("quit debugmode.");
|
||||
auto event = std::make_shared<Event>("SysEventSource");
|
||||
@ -216,7 +223,7 @@ void SysEventServiceOhos::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
auto listener = registeredListeners_.find(remoteObject);
|
||||
if (listener != registeredListeners_.end()) {
|
||||
listener->first->RemoveDeathRecipient(deathRecipient_);
|
||||
HIVIEW_LOGE("pid %{public}d has died and remove listener.", listener->second.first);
|
||||
HIVIEW_LOGE("pid %{public}d has died and remove listener.", listener->second.pid);
|
||||
registeredListeners_.erase(listener);
|
||||
}
|
||||
}
|
||||
@ -266,30 +273,29 @@ int32_t SysEventServiceOhos::AddListener(const std::vector<SysEventRule>& rules,
|
||||
HIVIEW_LOGE("subscribe fail, callback is null.");
|
||||
return ERR_LISTENER_NOT_EXIST;
|
||||
}
|
||||
CallbackObjectOhos callbackObject = callback->AsObject();
|
||||
OHOS::sptr<OHOS::IRemoteObject> callbackObject = callback->AsObject();
|
||||
if (callbackObject == nullptr) {
|
||||
HIVIEW_LOGE("subscribe fail, object in callback is null.");
|
||||
return ERR_LISTENER_STATUS_INVALID;
|
||||
}
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
int32_t pid = IPCSkeleton::GetCallingPid();
|
||||
pair<int32_t, SysEventRuleGroupOhos> rulesPair(pid, rules);
|
||||
ListenerInfo listenerInfo {IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid(), rules};
|
||||
if (registeredListeners_.find(callbackObject) != registeredListeners_.end()) {
|
||||
registeredListeners_[callbackObject] = rulesPair;
|
||||
HIVIEW_LOGD("uid %{public}d pid %{public}d listener has been added and update rules.", uid, pid);
|
||||
registeredListeners_[callbackObject] = listenerInfo;
|
||||
HIVIEW_LOGD("uid %{public}d pid %{public}d listener has been added and update rules.",
|
||||
listenerInfo.uid, listenerInfo.pid);
|
||||
return IPC_CALL_SUCCEED;
|
||||
}
|
||||
if (!callbackObject->AddDeathRecipient(deathRecipient_)) {
|
||||
HIVIEW_LOGE("subscribe fail, can not add death recipient.");
|
||||
return ERR_ADD_DEATH_RECIPIENT;
|
||||
}
|
||||
registeredListeners_.insert(make_pair(callbackObject, rulesPair));
|
||||
registeredListeners_.insert(make_pair(callbackObject, listenerInfo));
|
||||
HIVIEW_LOGD("uid %{public}d pid %{public}d listener is added successfully, total is %{public}zu.",
|
||||
uid, pid, registeredListeners_.size());
|
||||
listenerInfo.uid, listenerInfo.pid, registeredListeners_.size());
|
||||
return IPC_CALL_SUCCEED;
|
||||
}
|
||||
|
||||
int32_t SysEventServiceOhos::RemoveListener(const SysEventCallbackPtrOhos& callback)
|
||||
int32_t SysEventServiceOhos::RemoveListener(const OHOS::sptr<ISysEventCallback>& callback)
|
||||
{
|
||||
if (!HasAccessPermission()) {
|
||||
return ERR_NO_PERMISSION;
|
||||
@ -303,7 +309,7 @@ int32_t SysEventServiceOhos::RemoveListener(const SysEventCallbackPtrOhos& callb
|
||||
HIVIEW_LOGE("callback is null.");
|
||||
return ERR_LISTENER_NOT_EXIST;
|
||||
}
|
||||
CallbackObjectOhos callbackObject = callback->AsObject();
|
||||
OHOS::sptr<OHOS::IRemoteObject> callbackObject = callback->AsObject();
|
||||
if (callbackObject == nullptr) {
|
||||
HIVIEW_LOGE("object in callback is null.");
|
||||
return ERR_LISTENER_STATUS_INVALID;
|
||||
@ -331,7 +337,7 @@ int32_t SysEventServiceOhos::RemoveListener(const SysEventCallbackPtrOhos& callb
|
||||
}
|
||||
|
||||
bool SysEventServiceOhos::BuildEventQuery(std::shared_ptr<EventQueryWrapperBuilder> builder,
|
||||
const SysEventQueryRuleGroupOhos& rules)
|
||||
const std::vector<SysEventQueryRule>& rules)
|
||||
{
|
||||
if (builder == nullptr) {
|
||||
return false;
|
||||
@ -369,8 +375,8 @@ bool SysEventServiceOhos::BuildEventQuery(std::shared_ptr<EventQueryWrapperBuild
|
||||
});
|
||||
}
|
||||
|
||||
int32_t SysEventServiceOhos::Query(const QueryArgument& queryArgument, const SysEventQueryRuleGroupOhos& rules,
|
||||
const OHOS::sptr<OHOS::HiviewDFX::IQuerySysEventCallback>& callback)
|
||||
int32_t SysEventServiceOhos::Query(const QueryArgument& queryArgument, const std::vector<SysEventQueryRule>& rules,
|
||||
const OHOS::sptr<IQuerySysEventCallback>& callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
return ERR_LISTENER_NOT_EXIST;
|
||||
@ -424,7 +430,7 @@ bool SysEventServiceOhos::HasAccessPermission() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t SysEventServiceOhos::SetDebugMode(const SysEventCallbackPtrOhos& callback, bool mode)
|
||||
int32_t SysEventServiceOhos::SetDebugMode(const OHOS::sptr<ISysEventCallback>& callback, bool mode)
|
||||
{
|
||||
if (!HasAccessPermission()) {
|
||||
return ERR_NO_PERMISSION;
|
||||
@ -464,7 +470,7 @@ void CallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
service->OnRemoteDied(remote);
|
||||
}
|
||||
|
||||
int64_t SysEventServiceOhos::AddSubscriber(const SysEventQueryRuleGroupOhos &rules)
|
||||
int64_t SysEventServiceOhos::AddSubscriber(const std::vector<SysEventQueryRule>& rules)
|
||||
{
|
||||
if (!HasAccessPermission()) {
|
||||
return ERR_NO_PERMISSION;
|
||||
@ -509,7 +515,7 @@ int32_t SysEventServiceOhos::RemoveSubscriber()
|
||||
return IPC_CALL_SUCCEED;
|
||||
}
|
||||
|
||||
int64_t SysEventServiceOhos::Export(const QueryArgument &queryArgument, const SysEventQueryRuleGroupOhos &rules)
|
||||
int64_t SysEventServiceOhos::Export(const QueryArgument &queryArgument, const std::vector<SysEventQueryRule>& rules)
|
||||
{
|
||||
if (!HasAccessPermission()) {
|
||||
return ERR_NO_PERMISSION;
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-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
|
||||
@ -18,7 +18,10 @@ module_output_path = "hiview/hiview"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":SysEventServiceOhosUnitTest" ]
|
||||
deps = [
|
||||
":EventCheckerUnitTest",
|
||||
":SysEventServiceOhosUnitTest",
|
||||
]
|
||||
}
|
||||
|
||||
config("unittest_config") {
|
||||
@ -65,3 +68,30 @@ ohos_unittest("SysEventServiceOhosUnitTest") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("EventCheckerUnitTest") {
|
||||
module_out_path = module_output_path
|
||||
configs = [ ":unittest_config" ]
|
||||
|
||||
sources = [ "unittest/common/event_checker_test.cpp" ]
|
||||
|
||||
cflags_cc = [ "-DTEST_LOCAL_SRC" ]
|
||||
|
||||
deps = [
|
||||
"$hiview_adapter/plugins/eventservice/service:sys_event_service_adapter",
|
||||
"$hiview_base:hiview_base",
|
||||
"$hiview_core:hiview_core",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"googletest:gtest_main",
|
||||
"hilog:libhilog",
|
||||
"init:libbeget_proxy",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_single",
|
||||
"jsoncpp:jsoncpp",
|
||||
"relational_store:native_rdb",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 "event_checker_test.h"
|
||||
|
||||
#include "parameter_ex.h"
|
||||
#include "compliant_event_checker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
|
||||
void EventCheckerTest::SetUpTestCase() {}
|
||||
|
||||
void EventCheckerTest::TearDownTestCase() {}
|
||||
|
||||
void EventCheckerTest::SetUp() {}
|
||||
|
||||
void EventCheckerTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: EventCheckerTest001
|
||||
* @tc.desc: Test isCompliantRule apis of RuleChecker
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIAPJKN
|
||||
*/
|
||||
HWTEST_F(EventCheckerTest, EventCheckerTest001, testing::ext::TestSize.Level3)
|
||||
{
|
||||
CompliantEventChecker eventChecker;
|
||||
if (Parameter::GetInteger("const.secure", 1) == 0) { // 1 and 0 is test value
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("AAFWK", ""));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("AAFWK", "START_ABILITY"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("ACE", "INTERACTION_COMPLETED_LATENCY"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("AV_CODEC", "CODEC_START_INFO"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("GRAPHIC", "INTERACTION_COMPLETED_LATENCY"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("LOCATION", "GNSS_STATE"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("PERFORMANCE", ""));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("RELIBILITY", ""));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("STABILITY", "JS_ERROR"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("STABILITY", "JS_ERROR_INVALID"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("WORKSCHEDULER", "WORK_ADD"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("STABILITY", "WORK_ADD_INVALID"));
|
||||
} else {
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("AAFWK", ""));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("AAFWK", "START_ABILITY"));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("ACE", "INTERACTION_COMPLETED_LATENCY"));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("AV_CODEC", "CODEC_START_INFO"));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("GRAPHIC", "INTERACTION_COMPLETED_LATENCY"));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("LOCATION", "GNSS_STATE"));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("PERFORMANCE", ""));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("RELIBILITY", ""));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("STABILITY", "JS_ERROR"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("STABILITY", "JS_ERROR_INVALID"));
|
||||
ASSERT_FALSE(eventChecker.IsCompliantEvent("WORKSCHEDULER", "WORK_ADD"));
|
||||
ASSERT_TRUE(eventChecker.IsCompliantEvent("STABILITY", "WORK_ADD_INVALID"));
|
||||
}
|
||||
}
|
||||
} //
|
||||
} //
|
@ -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 HIVIEWDFX_EVENT_CHECKER_TEST_H
|
||||
#define HIVIEWDFX_EVENT_CHECKER_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
class EventCheckerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace HiviewDFX
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // HIVIEWDFX_EVENT_CHECKER_TEST_H
|
@ -427,6 +427,8 @@
|
||||
"OHOS::HiviewDFX::HiViewConfigUtil::GetConfigFilePath(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
|
||||
"OHOS::HiviewDFX::HiviewUnzipUnit::UnzipFile() const";
|
||||
"OHOS::HiviewDFX::HiviewUnzipUnit::~HiviewUnzipUnit()";
|
||||
"OHOS::HiviewDFX::Parameter::GetInteger(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, long long)";
|
||||
"OHOS::HiviewDFX::Parameter::GetInteger(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, long)";
|
||||
};
|
||||
local:
|
||||
*;
|
||||
|
Loading…
Reference in New Issue
Block a user