mirror of
https://gitee.com/openharmony/notification_common_event_service
synced 2024-11-26 17:50:42 +00:00
新增STATIC_SUBSCRIBER_START和STATIC_SUBSCRIBER_RUNTIME打点
Signed-off-by: markYao <yaozhiyuan@huawei.com>
This commit is contained in:
parent
f72d487cd9
commit
fbf4659526
@ -66,4 +66,23 @@ PUBLISH:
|
||||
BUNDLE_NAME_OF_PUBLISHER: {type: STRING, desc: bundle name of publisher}
|
||||
PID: {type: INT32, desc: publisher pid}
|
||||
UID: {type: INT32, desc: publisher uid}
|
||||
EVENT_NAME: {type: STRING, desc: published event name}
|
||||
EVENT_NAME: {type: STRING, desc: published event name}
|
||||
|
||||
STATIC_SUBSCRIBER_START:
|
||||
__BASE: {type: STATISTIC, level: MINOR, desc: static subscriber ability start}
|
||||
USER_ID: {type: INT32, desc: userId}
|
||||
BUNDLE_NAME_OF_SUBSCRIBER: {type: STRING, desc: bundle name of subscriber}
|
||||
PID: {type: INT32, desc: subscriber pid}
|
||||
UID: {type: INT32, desc: subscriber uid}
|
||||
EVENT_NAME: {type: STRING, desc: subscribed event name}
|
||||
ABILITY_NAME: {type: STRING, desc: the name of ability}
|
||||
|
||||
STATIC_SUBSCRIBER_RUNTIME:
|
||||
__BASE: {type: STATISTIC, level: MINOR, desc: static subscriber ability run time}
|
||||
USER_ID: {type: INT32, desc: userId}
|
||||
BUNDLE_NAME_OF_SUBSCRIBER: {type: STRING, desc: bundle name of subscriber}
|
||||
PID: {type: INT32, desc: subscriber pid}
|
||||
UID: {type: INT32, desc: subscriber uid}
|
||||
EVENT_NAME: {type: STRING, desc: subscribed event name}
|
||||
ABILITY_NAME: {type: STRING, desc: the name of ability}
|
||||
RESULT_CODE: {type: INT32, desc: ability disconnect result}
|
@ -34,18 +34,21 @@ constexpr char PUBLISH_ERROR[] = "PUBLISH_ERROR";
|
||||
constexpr char SUBSCRIBE[] = "SUBSCRIBE";
|
||||
constexpr char UNSUBSCRIBE[] = "UNSUBSCRIBE";
|
||||
constexpr char PUBLISH[] = "PUBLISH";
|
||||
constexpr char STATIC_SUBSCRIBER_START[] = "STATIC_SUBSCRIBER_START";
|
||||
constexpr char STATIC_SUBSCRIBER_RUNTIME[] = "STATIC_SUBSCRIBER_RUNTIME";
|
||||
} // namespace
|
||||
|
||||
struct EventInfo {
|
||||
int32_t userId;
|
||||
int32_t pid;
|
||||
int32_t uid;
|
||||
int32_t resultCode;
|
||||
uint32_t subscriberNum;
|
||||
std::string publisherName;
|
||||
std::string subscriberName;
|
||||
std::string eventName;
|
||||
|
||||
EventInfo() : userId(-1), pid(0), uid(0), subscriberNum(0) {}
|
||||
EventInfo() : userId(-1), pid(0), uid(0), resultCode(0), subscriberNum(0) {}
|
||||
};
|
||||
|
||||
class EventReport {
|
||||
@ -70,6 +73,8 @@ private:
|
||||
static void InnerSendSubscribeEvent(const EventInfo &eventInfo);
|
||||
static void InnerSendUnSubscribeEvent(const EventInfo &eventInfo);
|
||||
static void InnerSendPublishEvent(const EventInfo &eventInfo);
|
||||
static void InnerSendStaticSubStartEvent(const EventInfo &eventInfo);
|
||||
static void InnerSendStaticSubRunEvent(const EventInfo &eventInfo);
|
||||
|
||||
template<typename... Types>
|
||||
static void InnerEventWrite(const std::string &eventName,
|
||||
|
@ -101,6 +101,13 @@ private:
|
||||
const std::string &subscriberName, const std::string &eventName);
|
||||
bool IsDisableEvent(const std::string &bundleName, const std::string &event);
|
||||
int32_t UpdateDisableEvents(const std::string &bundleName, const std::vector<std::string> &events, bool enable);
|
||||
void PublishCommonEventConnecAbility(const CommonEventData &data, const sptr<IRemoteObject> &service,
|
||||
const int32_t &userId, const std::string &bundleName, const std::string &abilityName);
|
||||
void PublishCommonEventInner(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
|
||||
const Security::AccessToken::AccessTokenID &callerToken, const int32_t &userId,
|
||||
const sptr<IRemoteObject> &service, const std::string &bundleName);
|
||||
void SendStaticSubscriberStartHiSysEvent(int32_t userId, const std::string &publisherName,
|
||||
const std::string &subscriberName, const std::string &eventName);
|
||||
|
||||
std::map<std::string, std::vector<StaticSubscriberInfo>> validSubscribers_;
|
||||
std::map<std::string, StaticSubscriber> staticSubscribers_;
|
||||
|
@ -27,6 +27,8 @@ const std::string EVENT_PARAM_SUBSCRIBER_NUM = "SUBSCRIBER_NUM";
|
||||
const std::string EVENT_PARAM_BUNDLE_NAME_OF_PUBLISHER = "BUNDLE_NAME_OF_PUBLISHER";
|
||||
const std::string EVENT_PARAM_BUNDLE_NAME_OF_SUBSCRIBER = "BUNDLE_NAME_OF_SUBSCRIBER";
|
||||
const std::string EVENT_PARAM_EVENT_NAME = "EVENT_NAME";
|
||||
const std::string EVENT_PARAM_ABILITY_NAME = "ABILITY_NAME";
|
||||
const std::string EVENT_PARAM_RESULT_CODE = "RESULT_CODE";
|
||||
} // namespace
|
||||
|
||||
void EventReport::SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo)
|
||||
@ -66,6 +68,12 @@ std::unordered_map<std::string, void (*)(const EventInfo& eventInfo)> EventRepor
|
||||
{PUBLISH, [](const EventInfo& eventInfo) {
|
||||
InnerSendPublishEvent(eventInfo);
|
||||
}},
|
||||
{STATIC_SUBSCRIBER_START, [](const EventInfo& eventInfo) {
|
||||
InnerSendStaticSubStartEvent(eventInfo);
|
||||
}},
|
||||
{STATIC_SUBSCRIBER_RUNTIME, [](const EventInfo& eventInfo) {
|
||||
InnerSendStaticSubRunEvent(eventInfo);
|
||||
}},
|
||||
};
|
||||
|
||||
void EventReport::InnerSendOrderedEventProcTimeoutEvent(const EventInfo &eventInfo)
|
||||
@ -149,6 +157,33 @@ void EventReport::InnerSendPublishEvent(const EventInfo &eventInfo)
|
||||
EVENT_PARAM_EVENT_NAME, eventInfo.eventName);
|
||||
}
|
||||
|
||||
void EventReport::InnerSendStaticSubStartEvent(const EventInfo &eventInfo)
|
||||
{
|
||||
InnerEventWrite(
|
||||
STATIC_SUBSCRIBER_START,
|
||||
HiviewDFX::HiSysEvent::EventType::STATISTIC,
|
||||
EVENT_PARAM_USER_ID, eventInfo.userId,
|
||||
EVENT_PARAM_BUNDLE_NAME_OF_SUBSCRIBER, eventInfo.subscriberName,
|
||||
EVENT_PARAM_ABILITY_NAME, eventInfo.publisherName,
|
||||
EVENT_PARAM_PID, eventInfo.pid,
|
||||
EVENT_PARAM_UID, eventInfo.uid,
|
||||
EVENT_PARAM_EVENT_NAME, eventInfo.eventName);
|
||||
}
|
||||
|
||||
void EventReport::InnerSendStaticSubRunEvent(const EventInfo &eventInfo)
|
||||
{
|
||||
InnerEventWrite(
|
||||
STATIC_SUBSCRIBER_RUNTIME,
|
||||
HiviewDFX::HiSysEvent::EventType::STATISTIC,
|
||||
EVENT_PARAM_USER_ID, eventInfo.userId,
|
||||
EVENT_PARAM_BUNDLE_NAME_OF_SUBSCRIBER, eventInfo.subscriberName,
|
||||
EVENT_PARAM_ABILITY_NAME, eventInfo.publisherName,
|
||||
EVENT_PARAM_PID, eventInfo.pid,
|
||||
EVENT_PARAM_UID, eventInfo.uid,
|
||||
EVENT_PARAM_RESULT_CODE, eventInfo.resultCode,
|
||||
EVENT_PARAM_EVENT_NAME, eventInfo.eventName);
|
||||
}
|
||||
|
||||
template<typename... Types>
|
||||
void EventReport::InnerEventWrite(const std::string &eventName,
|
||||
HiviewDFX::HiSysEvent::EventType type, Types... keyValues)
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "ability_manager_helper.h"
|
||||
#include "event_log_wrapper.h"
|
||||
#include "event_report.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
@ -49,6 +50,12 @@ sptr<StaticSubscriberProxy> StaticSubscriberConnection::GetProxy(const sptr<IRem
|
||||
void StaticSubscriberConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
|
||||
{
|
||||
EVENT_LOGI_LIMIT("enter");
|
||||
EventInfo eventInfo;
|
||||
eventInfo.publisherName = element.GetAbilityName();
|
||||
eventInfo.subscriberName = element.GetBundleName();
|
||||
eventInfo.eventName = event_.GetWant().GetAction();
|
||||
eventInfo.resultCode = resultCode;
|
||||
EventReport::SendHiSysEvent(STATIC_SUBSCRIBER_RUNTIME, eventInfo);
|
||||
}
|
||||
} // namespace EventFwk
|
||||
} // namespace OHOS
|
||||
|
@ -138,32 +138,22 @@ bool StaticSubscriberManager::IsDisableEvent(const std::string &bundleName, cons
|
||||
return false;
|
||||
}
|
||||
|
||||
void StaticSubscriberManager::PublishCommonEvent(const CommonEventData &data,
|
||||
void StaticSubscriberManager::PublishCommonEventConnecAbility(const CommonEventData &data,
|
||||
const sptr<IRemoteObject> &service, const int32_t &userId,
|
||||
const std::string &bundleName, const std::string &abilityName)
|
||||
{
|
||||
AAFwk::Want want;
|
||||
want.SetElementName(bundleName, abilityName);
|
||||
EVENT_LOGD("Ready to connect to subscriber %{public}s in bundle %{public}s",
|
||||
abilityName.c_str(), bundleName.c_str());
|
||||
DelayedSingleton<AbilityManagerHelper>::GetInstance()->ConnectAbility(want, data, service, userId);
|
||||
SendStaticSubscriberStartHiSysEvent(userId, abilityName, bundleName, data.GetWant().GetAction());
|
||||
}
|
||||
|
||||
void StaticSubscriberManager::PublishCommonEventInner(const CommonEventData &data,
|
||||
const CommonEventPublishInfo &publishInfo, const Security::AccessToken::AccessTokenID &callerToken,
|
||||
const int32_t &userId, const sptr<IRemoteObject> &service, const std::string &bundleName)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
|
||||
EVENT_LOGD("enter, event = %{public}s, userId = %{public}d", data.GetWant().GetAction().c_str(), userId);
|
||||
|
||||
std::lock_guard<std::mutex> lock(subscriberMutex_);
|
||||
if (!hasInitAllowList_ && !InitAllowList()) {
|
||||
EVENT_LOGE("failed to init subscriber list");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!hasInitValidSubscribers_ ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_LOCKED_BOOT_COMPLETED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_USER_SWITCHED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_UID_REMOVED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_USER_STARTED) &&
|
||||
!InitValidSubscribers()) {
|
||||
EVENT_LOGE("failed to init Init valid subscribers map!");
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSubscriber(data);
|
||||
|
||||
auto targetSubscribers = validSubscribers_.find(data.GetWant().GetAction());
|
||||
if (targetSubscribers != validSubscribers_.end()) {
|
||||
for (auto subscriber : targetSubscribers->second) {
|
||||
@ -209,16 +199,40 @@ void StaticSubscriberManager::PublishCommonEvent(const CommonEventData &data,
|
||||
"bundleName = %{public}s", subscriber.bundleName.c_str(), publishInfo.GetBundleName().c_str());
|
||||
continue;
|
||||
}
|
||||
AAFwk::Want want;
|
||||
want.SetElementName(subscriber.bundleName, subscriber.name);
|
||||
EVENT_LOGD("Ready to connect to subscriber %{public}s in bundle %{public}s",
|
||||
subscriber.name.c_str(), subscriber.bundleName.c_str());
|
||||
DelayedSingleton<AbilityManagerHelper>::GetInstance()->
|
||||
ConnectAbility(want, data, service, subscriber.userId);
|
||||
PublishCommonEventConnecAbility(data, service, subscriber.userId, subscriber.bundleName, subscriber.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StaticSubscriberManager::PublishCommonEvent(const CommonEventData &data,
|
||||
const CommonEventPublishInfo &publishInfo, const Security::AccessToken::AccessTokenID &callerToken,
|
||||
const int32_t &userId, const sptr<IRemoteObject> &service, const std::string &bundleName)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
|
||||
EVENT_LOGD("enter, event = %{public}s, userId = %{public}d", data.GetWant().GetAction().c_str(), userId);
|
||||
|
||||
std::lock_guard<std::mutex> lock(subscriberMutex_);
|
||||
if (!hasInitAllowList_ && !InitAllowList()) {
|
||||
EVENT_LOGE("failed to init subscriber list");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!hasInitValidSubscribers_ ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_LOCKED_BOOT_COMPLETED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_USER_SWITCHED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_UID_REMOVED ||
|
||||
data.GetWant().GetAction() == CommonEventSupport::COMMON_EVENT_USER_STARTED) &&
|
||||
!InitValidSubscribers()) {
|
||||
EVENT_LOGE("failed to init Init valid subscribers map!");
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSubscriber(data);
|
||||
|
||||
PublishCommonEventInner(data, publishInfo, callerToken, userId, service, bundleName);
|
||||
}
|
||||
|
||||
bool StaticSubscriberManager::VerifyPublisherPermission(const Security::AccessToken::AccessTokenID &callerToken,
|
||||
const std::string &permission)
|
||||
{
|
||||
@ -457,6 +471,17 @@ void StaticSubscriberManager::SendStaticEventProcErrHiSysEvent(int32_t userId, c
|
||||
EventReport::SendHiSysEvent(STATIC_EVENT_PROC_ERROR, eventInfo);
|
||||
}
|
||||
|
||||
void StaticSubscriberManager::SendStaticSubscriberStartHiSysEvent(int32_t userId, const std::string &publisherName,
|
||||
const std::string &subscriberName, const std::string &eventName)
|
||||
{
|
||||
EventInfo eventInfo;
|
||||
eventInfo.userId = userId;
|
||||
eventInfo.publisherName = publisherName;
|
||||
eventInfo.subscriberName = subscriberName;
|
||||
eventInfo.eventName = eventName;
|
||||
EventReport::SendHiSysEvent(STATIC_SUBSCRIBER_START, eventInfo);
|
||||
}
|
||||
|
||||
int32_t StaticSubscriberManager::UpdateDisableEvents(
|
||||
const std::string &bundleName, const std::vector<std::string> &events, bool enable)
|
||||
{
|
||||
|
@ -310,6 +310,7 @@ ohos_unittest("static_subscriber_connection_unit_test") {
|
||||
deps = [
|
||||
"${ces_extension_path}:static_subscriber_ipc",
|
||||
"${ces_native_path}:cesfwk_innerkits",
|
||||
"${services_path}:cesfwk_services_static",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user