1 /* 2 * Copyright (c) 2025 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_ANALYTICS_UTIL_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_ANALYTICS_UTIL_H 18 19 #include <string> 20 #include <map> 21 #include "notification_request.h" 22 23 namespace OHOS { 24 namespace Notification { 25 constexpr const int32_t PUBLISH_ERROR_EVENT_CODE = 0; 26 constexpr const int32_t ANS_CUSTOMIZE_CODE = 7; 27 constexpr const int32_t MODIFY_ERROR_EVENT_CODE = 6; 28 constexpr const int32_t DELETE_ERROR_EVENT_CODE = 5; 29 constexpr const int32_t OPERATION_DELETE_BRANCH = 2; 30 constexpr const int32_t BRANCH1_ID = 1; 31 constexpr const int32_t BRANCH2_ID = 2; 32 constexpr const int32_t BRANCH3_ID = 3; 33 constexpr const int32_t BRANCH4_ID = 4; 34 constexpr const int32_t BRANCH6_ID = 6; 35 constexpr const int32_t BRANCH7_ID = 7; 36 constexpr const int32_t BRANCH8_ID = 8; 37 constexpr const int32_t BRANCH9_ID = 9; 38 39 class AnalyticsUtil { 40 public: 41 static AnalyticsUtil& GetInstance(); 42 void InitHACallBack(std::function<void(int32_t, int32_t, uint32_t, std::string)> callback); 43 void InitSendReportCallBack(std::function<void(int32_t, int32_t, std::string)> callback); 44 void InitOperationCallback(std::function<void(const std::string&, int32_t, int32_t, std::string)> callback); 45 void SendHaReport(int32_t eventCode, int32_t errorCode, uint32_t branchId, 46 const std::string& errorReason, int32_t code = -1); 47 void SendEventReport(int32_t messageType, int32_t errCode, const std::string& errorReason); 48 void AbnormalReporting(int32_t eventCode, int result, uint32_t branchId, 49 const std::string &errorReason); 50 void OperationalReporting(int32_t deviceType, int32_t sceneType, int32_t slotType, 51 const std::string& reason = std::string()); 52 private: 53 AnalyticsUtil() = default; 54 ~AnalyticsUtil() = default; 55 std::function<void(int32_t, int32_t, uint32_t, std::string)> haCallback_ = nullptr; 56 std::function<void(int32_t, int32_t, std::string)> sendReportCallback_ = nullptr; 57 std::function<void(const std::string&, int32_t, int32_t, std::string)> operationCallback_ = nullptr; 58 }; 59 } // namespace Notification 60 } // namespace OHOS 61 62 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_ANALYTICS_UTIL_H 63