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 "ability_manager_radar.h"
17 
18 #include "ability_manager_errors.h"
19 #include "hisysevent.h"
20 #include "hilog_tag_wrapper.h"
21 
22 namespace OHOS {
23 namespace AAFWK {
24 namespace {
25 constexpr const char* ORG_PKG_NAME = "ohos.abilitymanagerservice";
26 constexpr const char* APPLICATION_CONTINUE_BEHAVIOR = "APPLICATION_CONTINUE_BEHAVIOR";
27 constexpr const char* DMS_PKG_NAME = "ohos.distributedschedule";
28 constexpr const char* ORG_PKG = "ORG_PKG";
29 constexpr const char* FUNC = "FUNC";
30 constexpr const char* BIZ_SCENE = "BIZ_SCENE";
31 constexpr const char* BIZ_STAGE = "BIZ_STAGE";
32 constexpr const char* STAGE_RES = "STAGE_RES";
33 constexpr const char* TO_CALL_PKG = "TO_CALL_PKG";
34 constexpr const char* ERROR_CODE = "ERROR_CODE";
35 constexpr char APP_CONTINUE_DOMAIN[] = "APP_CONTINUE";
36 static constexpr unsigned int FLAG_ABILITY_CONTINUATION = 0x00000008;
37 }
GetInstance()38 ContinueRadar &ContinueRadar::GetInstance()
39 {
40     static ContinueRadar instance;
41     return instance;
42 }
43 
ClickIconContinue(const std::string & func)44 bool ContinueRadar::ClickIconContinue(const std::string& func)
45 {
46     int32_t res = HiSysEventWrite(
47         APP_CONTINUE_DOMAIN,
48         APPLICATION_CONTINUE_BEHAVIOR,
49         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
50         ORG_PKG, ORG_PKG_NAME,
51         FUNC, func,
52         BIZ_SCENE, static_cast<int32_t>(BizScene::CLICK_ICON),
53         BIZ_STAGE, static_cast<int32_t>(ClickIcon::CLICKICON_CONTINUE),
54         STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
55     if (res != ERR_OK) {
56         TAG_LOGE(AAFwkTag::DEFAULT, "error, res:%{public}d", res);
57         return false;
58     }
59     return true;
60 }
61 
ClickIconStartAbility(const std::string & func,unsigned int flags,int32_t errCode)62 bool ContinueRadar::ClickIconStartAbility(const std::string& func, unsigned int flags, int32_t errCode)
63 {
64     if ((flags & FLAG_ABILITY_CONTINUATION) == 0) {
65         TAG_LOGD(AAFwkTag::DEFAULT, "StartAbility not support continuation!");
66         return false;
67     }
68     int32_t res = ERR_OK;
69     StageRes stageRes = (errCode == ERR_OK) ? StageRes::STAGE_SUCC : StageRes::STAGE_FAIL;
70     if (stageRes == StageRes::STAGE_SUCC) {
71         res = HiSysEventWrite(
72             APP_CONTINUE_DOMAIN,
73             APPLICATION_CONTINUE_BEHAVIOR,
74             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
75             ORG_PKG, ORG_PKG_NAME,
76             FUNC, func,
77             BIZ_SCENE, static_cast<int32_t>(BizScene::CLICK_ICON),
78             BIZ_STAGE, static_cast<int32_t>(ClickIcon::CLICKICON_STARTABILITY),
79             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
80     } else {
81         res = HiSysEventWrite(
82             APP_CONTINUE_DOMAIN,
83             APPLICATION_CONTINUE_BEHAVIOR,
84             HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
85             ORG_PKG, ORG_PKG_NAME,
86             FUNC, func,
87             BIZ_SCENE, static_cast<int32_t>(BizScene::CLICK_ICON),
88             BIZ_STAGE, static_cast<int32_t>(ClickIcon::CLICKICON_STARTABILITY),
89             STAGE_RES, static_cast<int32_t>(StageRes::STAGE_FAIL),
90             ERROR_CODE, errCode);
91     }
92     if (res != ERR_OK) {
93         TAG_LOGE(AAFwkTag::DEFAULT, "error, res:%{public}d", res);
94         return false;
95     }
96     return true;
97 }
98 
ClickIconRecvOver(const std::string & func)99 bool ContinueRadar::ClickIconRecvOver(const std::string& func)
100 {
101     int32_t res = ERR_OK;
102     res = HiSysEventWrite(
103         APP_CONTINUE_DOMAIN,
104         APPLICATION_CONTINUE_BEHAVIOR,
105         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
106         ORG_PKG, ORG_PKG_NAME,
107         FUNC, func,
108         BIZ_SCENE, static_cast<int32_t>(BizScene::CLICK_ICON),
109         BIZ_STAGE, static_cast<int32_t>(ClickIcon::CLICKICON_RECV_OVER),
110         STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
111     if (res != ERR_OK) {
112         TAG_LOGE(AAFwkTag::DEFAULT, "error, res:%{public}d", res);
113         return false;
114     }
115     return true;
116 }
117 
SaveDataContinue(const std::string & func)118 bool ContinueRadar::SaveDataContinue(const std::string& func)
119 {
120     int32_t res = HiSysEventWrite(
121         APP_CONTINUE_DOMAIN,
122         APPLICATION_CONTINUE_BEHAVIOR,
123         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
124         ORG_PKG, ORG_PKG_NAME,
125         FUNC, func,
126         BIZ_SCENE, static_cast<int32_t>(BizScene::SAVE_DATA),
127         BIZ_STAGE, static_cast<int32_t>(SaveData::SAVEDATA_CONTINUE),
128         STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
129     if (res != ERR_OK) {
130         TAG_LOGE(AAFwkTag::DEFAULT, "error, res:%{public}d", res);
131         return false;
132     }
133     return true;
134 }
135 
SaveDataRes(const std::string & func)136 bool ContinueRadar::SaveDataRes(const std::string& func)
137 {
138     int32_t res = HiSysEventWrite(
139         APP_CONTINUE_DOMAIN,
140         APPLICATION_CONTINUE_BEHAVIOR,
141         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
142         ORG_PKG, ORG_PKG_NAME,
143         FUNC, func,
144         BIZ_SCENE, static_cast<int32_t>(BizScene::SAVE_DATA),
145         BIZ_STAGE, static_cast<int32_t>(SaveData::SAVEDATA_RES),
146         STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC));
147     if (res != ERR_OK) {
148         TAG_LOGE(AAFwkTag::DEFAULT, "error, res:%{public}d", res);
149         return false;
150     }
151     return true;
152 }
153 
SaveDataRemoteWant(const std::string & func)154 bool ContinueRadar::SaveDataRemoteWant(const std::string& func)
155 {
156     int32_t res = HiSysEventWrite(
157         APP_CONTINUE_DOMAIN,
158         APPLICATION_CONTINUE_BEHAVIOR,
159         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
160         ORG_PKG, ORG_PKG_NAME,
161         FUNC, func,
162         BIZ_SCENE, static_cast<int32_t>(BizScene::SAVE_DATA),
163         BIZ_STAGE, static_cast<int32_t>(SaveData::SAVEDATA_REMOTE_WANT),
164         STAGE_RES, static_cast<int32_t>(StageRes::STAGE_SUCC),
165         TO_CALL_PKG, DMS_PKG_NAME);
166     if (res != ERR_OK) {
167         TAG_LOGE(AAFwkTag::DEFAULT, "error, res:%{public}d", res);
168         return false;
169     }
170     return true;
171 }
172 
173 } // namespace AAFWK
174 } // namespace OHOS