10826e83eSopenharmony_ci/* 20826e83eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 30826e83eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40826e83eSopenharmony_ci * you may not use this file except in compliance with the License. 50826e83eSopenharmony_ci * You may obtain a copy of the License at 60826e83eSopenharmony_ci * 70826e83eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80826e83eSopenharmony_ci * 90826e83eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100826e83eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110826e83eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120826e83eSopenharmony_ci * See the License for the specific language governing permissions and 130826e83eSopenharmony_ci * limitations under the License. 140826e83eSopenharmony_ci */ 150826e83eSopenharmony_ci 160826e83eSopenharmony_ci#include "ability_manager_client.h" 170826e83eSopenharmony_ci#include "application_context.h" 180826e83eSopenharmony_ci#include "hisysevent.h" 190826e83eSopenharmony_ci#include "nweb_hisysevent.h" 200826e83eSopenharmony_ci 210826e83eSopenharmony_cinamespace OHOS::NWeb { 220826e83eSopenharmony_cinamespace { 230826e83eSopenharmony_ciconst HiviewDFX::HiSysEvent::EventType EVENT_TYPES[] = { 240826e83eSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, 250826e83eSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, 260826e83eSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY, 270826e83eSopenharmony_ci OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, 280826e83eSopenharmony_ci}; 290826e83eSopenharmony_ci 300826e83eSopenharmony_cienum EventType { 310826e83eSopenharmony_ci FAULT = 0, 320826e83eSopenharmony_ci STATISTIC, 330826e83eSopenharmony_ci SECURITY, 340826e83eSopenharmony_ci BEHAVIOR, 350826e83eSopenharmony_ci}; 360826e83eSopenharmony_ci} 370826e83eSopenharmony_ci 380826e83eSopenharmony_ciconstexpr char INSTANCE_INITIALIZE_TIME[] = "INSTANCE_INITIALIZE_TIME"; 390826e83eSopenharmony_ciconstexpr char INSTANCE_ID[] = "INSTANCE_ID"; 400826e83eSopenharmony_ciconstexpr char USED_TIME[] = "USED_TIME"; 410826e83eSopenharmony_ci 420826e83eSopenharmony_cistatic std::string g_currentBundleName = ""; 430826e83eSopenharmony_citemplate<typename... Args> 440826e83eSopenharmony_cistatic int ForwardToHiSysEvent(const std::string& eventName, EventType type, const std::tuple<Args...>& tp) 450826e83eSopenharmony_ci{ 460826e83eSopenharmony_ci if (g_currentBundleName.empty()) { 470826e83eSopenharmony_ci auto appInfo = AbilityRuntime::ApplicationContext::GetInstance()->GetApplicationInfo(); 480826e83eSopenharmony_ci if (appInfo != nullptr) { 490826e83eSopenharmony_ci g_currentBundleName = appInfo->bundleName.c_str(); 500826e83eSopenharmony_ci } 510826e83eSopenharmony_ci } 520826e83eSopenharmony_ci std::tuple<const std::string, const std::string> sysData("BUNDLE_NAME", g_currentBundleName.c_str()); 530826e83eSopenharmony_ci auto mergeData = std::tuple_cat(sysData, tp); 540826e83eSopenharmony_ci 550826e83eSopenharmony_ci return std::apply( 560826e83eSopenharmony_ci [&](auto&&... args) { 570826e83eSopenharmony_ci return HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::WEBVIEW, eventName, EVENT_TYPES[type], args...); 580826e83eSopenharmony_ci }, 590826e83eSopenharmony_ci mergeData); 600826e83eSopenharmony_ci} 610826e83eSopenharmony_ci 620826e83eSopenharmony_ciint EventReport::ReportCreateWebInstanceTime(uint32_t nwebId, int64_t usedTime) 630826e83eSopenharmony_ci{ 640826e83eSopenharmony_ci auto data = std::make_tuple(INSTANCE_ID, nwebId, USED_TIME, usedTime); 650826e83eSopenharmony_ci return ForwardToHiSysEvent(INSTANCE_INITIALIZE_TIME, STATISTIC, data); 660826e83eSopenharmony_ci} 670826e83eSopenharmony_ci} // namespace OHOS::NWeb