1 /*
2  * Copyright (c) 2024 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 #include <hisysevent.h>
17 #include "dms_reporter.h"
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 WM_IMPLEMENT_SINGLE_INSTANCE(DmsReporter)
23 
24 enum class StageRes : int32_t {
25     SUCCESS = 1,
26     FAILED = 2,
27 };
28 
29 enum class BizScene : int32_t {
30     CONTINUE_APP = 10,
31     QUERY_MISSION_INFO = 10,
32     REGISTER = 12,
33 };
34 
35 enum class BizStage : int32_t {
36     REGISTER = 1,
37     QUERY_MISSION_INFO = 7,
38     CONTINUE_APP = 8,
39 };
40 
41 constexpr const char APP_CONTINUE_DOMAIN[] = "APP_CONTINUE";
42 constexpr const char APP_CONTINUE_EVENT_NAME[] = "APPLICATION_CONTINUE_BEHAVIOR";
43 constexpr const char PKG_NAME_SCB[] = "com.ohos.sceneboard";
44 constexpr const char PKG_NAME_ABILITY_MANAGER[] = "ohos.abilitymanagerservice";
45 constexpr const char PKG_NAME_DMS[] = "ohos.distributedschedule";
46 constexpr const char EVENT_KEY_ORG_PKG[] = "ORG_PKG";
47 constexpr const char EVENT_KEY_HOST_PKG[] = "HOST_PKG";
48 constexpr const char EVENT_KEY_FUNC[] = "FUNC";
49 constexpr const char EVENT_KEY_BIZ_SCENE[] = "BIZ_SCENE";
50 constexpr const char EVENT_KEY_BIZ_STAGE[] = "BIZ_STAGE";
51 constexpr const char EVENT_KEY_STAGE_RES[] = "STAGE_RES";
52 constexpr const char EVENT_KEY_ERROR_CODE[] = "ERROR_CODE";
53 
ReportRegisterSessionListener(bool isSuccess,int32_t errCode)54 void DmsReporter::ReportRegisterSessionListener(bool isSuccess, int32_t errCode)
55 {
56     TLOGI(WmsLogTag::WMS_LIFE, "[AppContinue]Report register session listener");
57     int32_t ret = HiSysEventWrite(
58         APP_CONTINUE_DOMAIN, APP_CONTINUE_EVENT_NAME,
59         OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
60         EVENT_KEY_ORG_PKG, PKG_NAME_SCB,
61         EVENT_KEY_FUNC, "RegisterSessionListener",
62         EVENT_KEY_BIZ_SCENE, static_cast<int32_t>(BizScene::REGISTER),
63         EVENT_KEY_BIZ_STAGE, static_cast<int32_t>(BizStage::REGISTER),
64         EVENT_KEY_STAGE_RES, isSuccess ? static_cast<int32_t>(StageRes::SUCCESS) :
65             static_cast<int32_t>(StageRes::FAILED),
66         EVENT_KEY_ERROR_CODE, errCode,
67         EVENT_KEY_HOST_PKG, PKG_NAME_ABILITY_MANAGER);
68     if (ret != 0) {
69         TLOGE(WmsLogTag::WMS_LIFE, "Write HiSysEvent error, ret:%{public}d", ret);
70     }
71 }
72 
ReportQuerySessionInfo(bool isSuccess,int32_t errCode)73 void DmsReporter::ReportQuerySessionInfo(bool isSuccess, int32_t errCode)
74 {
75     TLOGI(WmsLogTag::WMS_LIFE, "[AppContinue]Report query session info");
76     int32_t ret = HiSysEventWrite(
77         APP_CONTINUE_DOMAIN, APP_CONTINUE_EVENT_NAME,
78         OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
79         EVENT_KEY_ORG_PKG, PKG_NAME_SCB,
80         EVENT_KEY_FUNC, "GetSessionInfoByContinueSessionId",
81         EVENT_KEY_BIZ_SCENE, static_cast<int32_t>(BizScene::QUERY_MISSION_INFO),
82         EVENT_KEY_BIZ_STAGE, static_cast<int32_t>(BizStage::QUERY_MISSION_INFO),
83         EVENT_KEY_STAGE_RES, isSuccess ? static_cast<int32_t>(StageRes::SUCCESS) :
84             static_cast<int32_t>(StageRes::FAILED),
85         EVENT_KEY_ERROR_CODE, errCode,
86         EVENT_KEY_HOST_PKG, PKG_NAME_DMS);
87     if (ret != 0) {
88         TLOGE(WmsLogTag::WMS_LIFE, "Write HiSysEvent error, ret:%{public}d", ret);
89     }
90 }
91 
ReportContinueApp(bool isSuccess,int32_t errCode)92 void DmsReporter::ReportContinueApp(bool isSuccess, int32_t errCode)
93 {
94     TLOGI(WmsLogTag::WMS_LIFE, "[AppContinue]Report continue app pending session activation");
95     int32_t ret = HiSysEventWrite(
96         APP_CONTINUE_DOMAIN, APP_CONTINUE_EVENT_NAME,
97         OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
98         EVENT_KEY_ORG_PKG, PKG_NAME_SCB,
99         EVENT_KEY_FUNC, "PendingSessionActivation",
100         EVENT_KEY_BIZ_SCENE, static_cast<int32_t>(BizScene::CONTINUE_APP),
101         EVENT_KEY_BIZ_STAGE, static_cast<int32_t>(BizStage::CONTINUE_APP),
102         EVENT_KEY_STAGE_RES, isSuccess ? static_cast<int32_t>(StageRes::SUCCESS) :
103             static_cast<int32_t>(StageRes::FAILED),
104         EVENT_KEY_ERROR_CODE, errCode,
105         EVENT_KEY_HOST_PKG, PKG_NAME_ABILITY_MANAGER);
106     if (ret != 0) {
107         TLOGE(WmsLogTag::WMS_LIFE, "Write HiSysEvent error, ret:%{public}d", ret);
108     }
109 }
110 
111 } // namespace Rosen
112 } // namespace OHOS
113