1 /* 2 * Copyright (c) 2022-2023 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 OHOS_ABILITY_RUNTIME_EVENT_REPORT_H 17 #define OHOS_ABILITY_RUNTIME_EVENT_REPORT_H 18 19 #include <string> 20 21 #include "hisysevent.h" 22 23 using HiSysEventType = OHOS::HiviewDFX::HiSysEvent::EventType; 24 using HiSysEvent = OHOS::HiviewDFX::HiSysEvent; 25 26 namespace OHOS { 27 namespace AAFwk { 28 struct EventInfo { 29 int32_t pid = -1; 30 int32_t userId = -1; 31 int32_t extensionType = -1; 32 uint32_t versionCode = 0; 33 int32_t errCode = -1; 34 std::string versionName; 35 std::string bundleName; 36 std::string moduleName; 37 std::string abilityName; 38 std::string processName; 39 std::string callerProcessName; 40 std::string callerBundleName; 41 int32_t abilityType = -1; 42 int64_t time = 0; 43 int32_t callerUid = -1; 44 int32_t exitResult = -1; 45 int32_t bundleType = -1; 46 int32_t startType = 0; 47 int32_t appUid = -1; 48 int32_t callerState = -1; 49 uint32_t callerVersionCode = -1; 50 std::string callerVersionName; 51 std::string uri; 52 int32_t processType = -1; 53 }; 54 55 enum class EventName { 56 // fault event 57 START_ABILITY_ERROR, 58 TERMINATE_ABILITY_ERROR, 59 START_EXTENSION_ERROR, 60 STOP_EXTENSION_ERROR, 61 CONNECT_SERVICE_ERROR, 62 DISCONNECT_SERVICE_ERROR, 63 CLOSE_UI_ABILITY_BY_SCB_ERROR, 64 65 // ability behavior event 66 START_ABILITY, 67 TERMINATE_ABILITY, 68 CLOSE_ABILITY, 69 CLOSE_UI_ABILITY_BY_SCB, 70 ABILITY_ONFOREGROUND, 71 ABILITY_ONBACKGROUND, 72 ABILITY_ONACTIVE, 73 ABILITY_ONINACTIVE, 74 75 // serviceExtensionAbility behavior event 76 START_SERVICE, 77 STOP_SERVICE, 78 CONNECT_SERVICE, 79 DISCONNECT_SERVICE, 80 81 // app behavior event 82 APP_ATTACH, 83 APP_LAUNCH, 84 APP_FOREGROUND, 85 APP_BACKGROUND, 86 APP_TERMINATE, 87 PROCESS_START, 88 PROCESS_EXIT, 89 DRAWN_COMPLETED, 90 APP_STARTUP_TYPE, 91 92 // key behavior event 93 GRANT_URI_PERMISSION, 94 FA_SHOW_ON_LOCK, 95 START_PRIVATE_ABILITY, 96 RESTART_PROCESS_BY_SAME_APP, 97 }; 98 99 class EventReport { 100 public: 101 static void SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); 102 static void SendAbilityEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); 103 static void SendExtensionEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); 104 static void SendKeyEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo); 105 106 private: 107 static std::string ConvertEventName(const EventName &eventName); 108 }; 109 } // namespace AAFWK 110 } // namespace OHOS 111 #endif // OHOS_ABILITY_RUNTIME_EVENT_REPORT_H 112