1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_EVENT_REPORT_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_EVENT_REPORT_H 18 19 #include <unordered_map> 20 21 #ifdef HAS_HISYSEVENT_PART 22 #include "hisysevent.h" 23 #endif 24 25 namespace OHOS { 26 namespace Notification { 27 namespace { 28 // event name 29 constexpr char SUBSCRIBE_ERROR[] = "SUBSCRIBE_ERROR"; 30 constexpr char ENABLE_NOTIFICATION_ERROR[] = "ENABLE_NOTIFICATION_ERROR"; 31 constexpr char ENABLE_NOTIFICATION_SLOT_ERROR[] = "ENABLE_NOTIFICATION_SLOT_ERROR"; 32 constexpr char PUBLISH_ERROR[] = "PUBLISH_ERROR"; 33 constexpr char EVENT_NOTIFICATION_ERROR[] = "EVENT_NOTIFICATION_ERROR"; 34 constexpr char FLOW_CONTROL_OCCUR[] = "FLOW_CONTROL_OCCUR"; 35 36 constexpr char SUBSCRIBE[] = "SUBSCRIBE"; 37 constexpr char UNSUBSCRIBE[] = "UNSUBSCRIBE"; 38 constexpr char ENABLE_NOTIFICATION[] = "ENABLE_NOTIFICATION"; 39 constexpr char ENABLE_NOTIFICATION_SLOT[] = "ENABLE_NOTIFICATION_SLOT"; 40 41 constexpr char PUBLISH[] = "PUBLISH"; 42 constexpr char CANCEL[] = "CANCEL"; 43 constexpr char REMOVE[] = "REMOVE"; 44 constexpr char STATIC_LIVE_VIEW_UPLOAD[] = "STATIC_LIVE_VIEW_UPLOAD"; 45 constexpr char USER_DATA_SIZE[] = "USER_DATA_SIZE"; 46 } // namespace 47 48 struct EventInfo { 49 int32_t notificationId = 0; 50 int32_t contentType = 0; 51 int32_t userId = -1; 52 int32_t pid = 0; 53 int32_t uid = 0; 54 int32_t slotType = 0; 55 int32_t errCode = 0; 56 bool enable = false; 57 std::string bundleName; 58 std::string notificationLabel; 59 int32_t operateFlag; 60 int32_t messageType; 61 std::string reason; 62 uint32_t reminderFlags = 0; 63 uint32_t notificationControlFlags = 0; 64 std::string classification; 65 }; 66 67 struct UserDataSizeInfo { 68 std::string componentName; 69 std::string partitionName; 70 std::uint64_t remainPartitionSize = 0; 71 std::vector<std::string> folderPath; 72 std::vector<std::uint64_t> folderSize; 73 }; 74 75 class EventReport { 76 public: 77 /** 78 * @brief send hisysevent 79 * 80 * @param eventName event name, corresponding to the document 'hisysevent.yaml' 81 * @param eventInfo event info 82 */ 83 static void SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo); 84 /** 85 * @brief send fileManager hisysevent 86 * 87 * @param eventInfo event info 88 */ 89 static void SendHiSysEvent(const UserDataSizeInfo &userDataSizeInfo); 90 91 private: 92 #ifdef HAS_HISYSEVENT_PART 93 // fault event 94 static void InnerSendSubscribeErrorEvent(const EventInfo &eventInfo); 95 static void InnerSendEnableNotificationErrorEvent(const EventInfo &eventInfo); 96 static void InnerSendEnableNotificationSlotErrorEvent(const EventInfo &eventInfo); 97 static void InnerSendPublishErrorEvent(const EventInfo &eventInfo); 98 static void InnerSendFlowControlOccurEvent(const EventInfo &eventInfo); 99 static void InnerSendNotificationSystemErrorEvent(const EventInfo &eventInfo); 100 101 // behavior event 102 static void InnerSendSubscribeEvent(const EventInfo &eventInfo); 103 static void InnerSendUnSubscribeEvent(const EventInfo &eventInfo); 104 static void InnerSendEnableNotificationEvent(const EventInfo &eventInfo); 105 static void InnerSendEnableNotificationSlotEvent(const EventInfo &eventInfo); 106 107 // statistic event 108 static void InnerSendPublishEvent(const EventInfo &eventInfo); 109 static void InnerSendCancelEvent(const EventInfo &eventInfo); 110 static void InnerSendRemoveEvent(const EventInfo &eventInfo); 111 static void InnerSendLiveviewUploadEvent(const EventInfo &eventInfo); 112 static void InnerSendUserDataSizeEvent(const UserDataSizeInfo &userDataSizeInfo); 113 114 template<typename... Types> 115 static void InnerEventWrite(const std::string &eventName, 116 HiviewDFX::HiSysEvent::EventType type, Types... keyValues); 117 118 static std::unordered_map<std::string, void (*)(const EventInfo &eventInfo)> ansSysEventFuncMap_; 119 #endif 120 }; 121 } // namespace Notification 122 } // namespace OHOS 123 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_EVENT_REPORT_H