1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#include <hisysevent.h>
17e0dac50fSopenharmony_ci#include "dms_reporter.h"
18e0dac50fSopenharmony_ci#include "window_manager_hilog.h"
19e0dac50fSopenharmony_ci
20e0dac50fSopenharmony_cinamespace OHOS {
21e0dac50fSopenharmony_cinamespace Rosen {
22e0dac50fSopenharmony_ciWM_IMPLEMENT_SINGLE_INSTANCE(DmsReporter)
23e0dac50fSopenharmony_ci
24e0dac50fSopenharmony_cienum class StageRes : int32_t {
25e0dac50fSopenharmony_ci    SUCCESS = 1,
26e0dac50fSopenharmony_ci    FAILED = 2,
27e0dac50fSopenharmony_ci};
28e0dac50fSopenharmony_ci
29e0dac50fSopenharmony_cienum class BizScene : int32_t {
30e0dac50fSopenharmony_ci    CONTINUE_APP = 10,
31e0dac50fSopenharmony_ci    QUERY_MISSION_INFO = 10,
32e0dac50fSopenharmony_ci    REGISTER = 12,
33e0dac50fSopenharmony_ci};
34e0dac50fSopenharmony_ci
35e0dac50fSopenharmony_cienum class BizStage : int32_t {
36e0dac50fSopenharmony_ci    REGISTER = 1,
37e0dac50fSopenharmony_ci    QUERY_MISSION_INFO = 7,
38e0dac50fSopenharmony_ci    CONTINUE_APP = 8,
39e0dac50fSopenharmony_ci};
40e0dac50fSopenharmony_ci
41e0dac50fSopenharmony_ciconstexpr const char APP_CONTINUE_DOMAIN[] = "APP_CONTINUE";
42e0dac50fSopenharmony_ciconstexpr const char APP_CONTINUE_EVENT_NAME[] = "APPLICATION_CONTINUE_BEHAVIOR";
43e0dac50fSopenharmony_ciconstexpr const char PKG_NAME_SCB[] = "com.ohos.sceneboard";
44e0dac50fSopenharmony_ciconstexpr const char PKG_NAME_ABILITY_MANAGER[] = "ohos.abilitymanagerservice";
45e0dac50fSopenharmony_ciconstexpr const char PKG_NAME_DMS[] = "ohos.distributedschedule";
46e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_ORG_PKG[] = "ORG_PKG";
47e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_HOST_PKG[] = "HOST_PKG";
48e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_FUNC[] = "FUNC";
49e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_BIZ_SCENE[] = "BIZ_SCENE";
50e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_BIZ_STAGE[] = "BIZ_STAGE";
51e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_STAGE_RES[] = "STAGE_RES";
52e0dac50fSopenharmony_ciconstexpr const char EVENT_KEY_ERROR_CODE[] = "ERROR_CODE";
53e0dac50fSopenharmony_ci
54e0dac50fSopenharmony_civoid DmsReporter::ReportRegisterSessionListener(bool isSuccess, int32_t errCode)
55e0dac50fSopenharmony_ci{
56e0dac50fSopenharmony_ci    TLOGI(WmsLogTag::WMS_LIFE, "[AppContinue]Report register session listener");
57e0dac50fSopenharmony_ci    int32_t ret = HiSysEventWrite(
58e0dac50fSopenharmony_ci        APP_CONTINUE_DOMAIN, APP_CONTINUE_EVENT_NAME,
59e0dac50fSopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
60e0dac50fSopenharmony_ci        EVENT_KEY_ORG_PKG, PKG_NAME_SCB,
61e0dac50fSopenharmony_ci        EVENT_KEY_FUNC, "RegisterSessionListener",
62e0dac50fSopenharmony_ci        EVENT_KEY_BIZ_SCENE, static_cast<int32_t>(BizScene::REGISTER),
63e0dac50fSopenharmony_ci        EVENT_KEY_BIZ_STAGE, static_cast<int32_t>(BizStage::REGISTER),
64e0dac50fSopenharmony_ci        EVENT_KEY_STAGE_RES, isSuccess ? static_cast<int32_t>(StageRes::SUCCESS) :
65e0dac50fSopenharmony_ci            static_cast<int32_t>(StageRes::FAILED),
66e0dac50fSopenharmony_ci        EVENT_KEY_ERROR_CODE, errCode,
67e0dac50fSopenharmony_ci        EVENT_KEY_HOST_PKG, PKG_NAME_ABILITY_MANAGER);
68e0dac50fSopenharmony_ci    if (ret != 0) {
69e0dac50fSopenharmony_ci        TLOGE(WmsLogTag::WMS_LIFE, "Write HiSysEvent error, ret:%{public}d", ret);
70e0dac50fSopenharmony_ci    }
71e0dac50fSopenharmony_ci}
72e0dac50fSopenharmony_ci
73e0dac50fSopenharmony_civoid DmsReporter::ReportQuerySessionInfo(bool isSuccess, int32_t errCode)
74e0dac50fSopenharmony_ci{
75e0dac50fSopenharmony_ci    TLOGI(WmsLogTag::WMS_LIFE, "[AppContinue]Report query session info");
76e0dac50fSopenharmony_ci    int32_t ret = HiSysEventWrite(
77e0dac50fSopenharmony_ci        APP_CONTINUE_DOMAIN, APP_CONTINUE_EVENT_NAME,
78e0dac50fSopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
79e0dac50fSopenharmony_ci        EVENT_KEY_ORG_PKG, PKG_NAME_SCB,
80e0dac50fSopenharmony_ci        EVENT_KEY_FUNC, "GetSessionInfoByContinueSessionId",
81e0dac50fSopenharmony_ci        EVENT_KEY_BIZ_SCENE, static_cast<int32_t>(BizScene::QUERY_MISSION_INFO),
82e0dac50fSopenharmony_ci        EVENT_KEY_BIZ_STAGE, static_cast<int32_t>(BizStage::QUERY_MISSION_INFO),
83e0dac50fSopenharmony_ci        EVENT_KEY_STAGE_RES, isSuccess ? static_cast<int32_t>(StageRes::SUCCESS) :
84e0dac50fSopenharmony_ci            static_cast<int32_t>(StageRes::FAILED),
85e0dac50fSopenharmony_ci        EVENT_KEY_ERROR_CODE, errCode,
86e0dac50fSopenharmony_ci        EVENT_KEY_HOST_PKG, PKG_NAME_DMS);
87e0dac50fSopenharmony_ci    if (ret != 0) {
88e0dac50fSopenharmony_ci        TLOGE(WmsLogTag::WMS_LIFE, "Write HiSysEvent error, ret:%{public}d", ret);
89e0dac50fSopenharmony_ci    }
90e0dac50fSopenharmony_ci}
91e0dac50fSopenharmony_ci
92e0dac50fSopenharmony_civoid DmsReporter::ReportContinueApp(bool isSuccess, int32_t errCode)
93e0dac50fSopenharmony_ci{
94e0dac50fSopenharmony_ci    TLOGI(WmsLogTag::WMS_LIFE, "[AppContinue]Report continue app pending session activation");
95e0dac50fSopenharmony_ci    int32_t ret = HiSysEventWrite(
96e0dac50fSopenharmony_ci        APP_CONTINUE_DOMAIN, APP_CONTINUE_EVENT_NAME,
97e0dac50fSopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
98e0dac50fSopenharmony_ci        EVENT_KEY_ORG_PKG, PKG_NAME_SCB,
99e0dac50fSopenharmony_ci        EVENT_KEY_FUNC, "PendingSessionActivation",
100e0dac50fSopenharmony_ci        EVENT_KEY_BIZ_SCENE, static_cast<int32_t>(BizScene::CONTINUE_APP),
101e0dac50fSopenharmony_ci        EVENT_KEY_BIZ_STAGE, static_cast<int32_t>(BizStage::CONTINUE_APP),
102e0dac50fSopenharmony_ci        EVENT_KEY_STAGE_RES, isSuccess ? static_cast<int32_t>(StageRes::SUCCESS) :
103e0dac50fSopenharmony_ci            static_cast<int32_t>(StageRes::FAILED),
104e0dac50fSopenharmony_ci        EVENT_KEY_ERROR_CODE, errCode,
105e0dac50fSopenharmony_ci        EVENT_KEY_HOST_PKG, PKG_NAME_ABILITY_MANAGER);
106e0dac50fSopenharmony_ci    if (ret != 0) {
107e0dac50fSopenharmony_ci        TLOGE(WmsLogTag::WMS_LIFE, "Write HiSysEvent error, ret:%{public}d", ret);
108e0dac50fSopenharmony_ci    }
109e0dac50fSopenharmony_ci}
110e0dac50fSopenharmony_ci
111e0dac50fSopenharmony_ci} // namespace Rosen
112e0dac50fSopenharmony_ci} // namespace OHOS
113