1 /*
2 * Copyright (c) 2022 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 "bundle_active_event.h"
17 #include "bundle_active_log.h"
18
19 namespace OHOS {
20 namespace DeviceUsageStats {
BundleActiveEvent()21 BundleActiveEvent::BundleActiveEvent()
22 {
23 bundleName_ = "";
24 continuousTaskAbilityName_ = "";
25 abilityName_ = "";
26 abilityId_ = "";
27 moduleName_ = "";
28 formName_ = "";
29 formId_ = 0;
30 formDimension_ = 0;
31 timeStamp_ = 0;
32 eventId_ = DEFAULT_EVENT_ID;
33 uid_ = DEFAULT_UID_ID;
34 }
35
BundleActiveEvent(const BundleActiveEvent & orig)36 BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig)
37 {
38 bundleName_ = orig.bundleName_;
39 continuousTaskAbilityName_ = orig.continuousTaskAbilityName_;
40 abilityName_ = orig.abilityName_;
41 abilityId_ = orig.abilityId_;
42 moduleName_ = orig.moduleName_;
43 formName_ = orig.formName_;
44 formId_ = orig.formId_;
45 formDimension_ = orig.formDimension_;
46 timeStamp_ = orig.timeStamp_;
47 eventId_ = orig.eventId_;
48 uid_ = orig.uid_;
49 }
50
BundleActiveEvent(int32_t eventId,int64_t timeStamp)51 BundleActiveEvent::BundleActiveEvent(int32_t eventId, int64_t timeStamp)
52 {
53 bundleName_.clear();
54 continuousTaskAbilityName_.clear();
55 abilityName_.clear();
56 abilityId_.clear();
57 moduleName_.clear();
58 formName_.clear();
59 formDimension_ = 0;
60 formId_ = 0;
61 timeStamp_ = timeStamp;
62 eventId_ = eventId;
63 uid_ = DEFAULT_UID_ID;
64 }
65
BundleActiveEvent(const int32_t eventId,const std::string bundleName,const int32_t uid)66 BundleActiveEvent::BundleActiveEvent(const int32_t eventId, const std::string bundleName, const int32_t uid)
67 {
68 bundleName_ = bundleName;
69 continuousTaskAbilityName_.clear();
70 abilityName_.clear();
71 abilityId_.clear();
72 moduleName_.clear();
73 formName_.clear();
74 formDimension_ = 0;
75 formId_ = 0;
76 timeStamp_ = 0;
77 eventId_ = eventId;
78 uid_ = uid;
79 }
80
BundleActiveEvent(const std::string bundleName,const std::string continuousTaskAbilityName,const int32_t uid)81 BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName,
82 const int32_t uid)
83 {
84 bundleName_ = bundleName;
85 continuousTaskAbilityName_ = continuousTaskAbilityName;
86 abilityName_.clear();
87 abilityId_.clear();
88 moduleName_.clear();
89 formName_.clear();
90 formDimension_ = 0;
91 formId_ = 0;
92 timeStamp_ = 0;
93 eventId_ = DEFAULT_EVENT_ID;
94 uid_ = uid;
95 }
96
BundleActiveEvent(const std::string bundleName,const std::string abilityName,const std::string abilityId,const std::string moduleName,const int32_t uid)97 BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string abilityName,
98 const std::string abilityId, const std::string moduleName, const int32_t uid)
99 {
100 bundleName_ = bundleName;
101 continuousTaskAbilityName_.clear();
102 abilityName_ = abilityName;
103 abilityId_ = abilityId;
104 moduleName_ = moduleName;
105 formName_.clear();
106 formDimension_ = 0;
107 formId_ = 0;
108 timeStamp_ = 0;
109 eventId_ = DEFAULT_EVENT_ID;
110 uid_ = uid;
111 }
112
BundleActiveEvent(const std::string bundleName,const std::string moduleName,const std::string formName,const int32_t formDimension,const int64_t formId,const int32_t eventId,const int32_t uid)113 BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string moduleName,
114 const std::string formName, const int32_t formDimension,
115 const int64_t formId, const int32_t eventId, const int32_t uid)
116 {
117 bundleName_ = bundleName;
118 continuousTaskAbilityName_.clear();
119 abilityName_.clear();
120 abilityId_.clear();
121 moduleName_ = moduleName;
122 formName_ = formName;
123 formDimension_ = formDimension;
124 formId_ = formId;
125 timeStamp_ = 0;
126 eventId_ = eventId;
127 uid_ = uid;
128 }
129
operator =(const BundleActiveEvent & orig)130 BundleActiveEvent& BundleActiveEvent::operator=(const BundleActiveEvent& orig)
131 {
132 bundleName_ = orig.bundleName_;
133 continuousTaskAbilityName_ = orig.continuousTaskAbilityName_;
134 abilityName_ = orig.abilityName_;
135 abilityId_ = orig.abilityId_;
136 moduleName_ = orig.moduleName_;
137 formName_ = orig.formName_;
138 formDimension_ = orig.formDimension_;
139 formId_ = orig.formId_;
140 timeStamp_ = orig.timeStamp_;
141 eventId_ = orig.eventId_;
142 uid_ = orig.uid_;
143 return *this;
144 }
145
PrintEvent(const bool debug) const146 void BundleActiveEvent::PrintEvent(const bool debug) const
147 {
148 if (!debug) {
149 return;
150 }
151 BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, ability name is %{public}s, continue task ability is %{public}s, "
152 "module name is %{public}s, form name is %{public}s, form dimension is %{public}d, "
153 "form id is %{public}lld, event id is %{public}d, uid is %{public}d",
154 bundleName_.c_str(), abilityName_.c_str(), continuousTaskAbilityName_.c_str(), moduleName_.c_str(),
155 formName_.c_str(), formDimension_, (long long)formId_, eventId_, uid_);
156 }
157
Marshalling(Parcel & parcel) const158 bool BundleActiveEvent::Marshalling(Parcel &parcel) const
159 {
160 if (parcel.WriteString(bundleName_) &&
161 parcel.WriteString(continuousTaskAbilityName_) &&
162 parcel.WriteString(abilityName_) &&
163 parcel.WriteString(abilityId_) &&
164 parcel.WriteString(moduleName_) &&
165 parcel.WriteString(formName_) &&
166 parcel.WriteInt32(formDimension_) &&
167 parcel.WriteInt64(formId_) &&
168 parcel.WriteInt64(timeStamp_) &&
169 parcel.WriteInt32(eventId_) &&
170 parcel.WriteInt32(uid_)) {
171 return true;
172 }
173 return false;
174 }
175
UnMarshalling(Parcel & parcel)176 std::shared_ptr<BundleActiveEvent> BundleActiveEvent::UnMarshalling(Parcel &parcel)
177 {
178 std::shared_ptr<BundleActiveEvent> result = std::make_shared<BundleActiveEvent>();
179 result->bundleName_ = parcel.ReadString();
180 result->continuousTaskAbilityName_ = parcel.ReadString();
181 result->abilityName_ = parcel.ReadString();
182 result->abilityId_ = parcel.ReadString();
183 result->moduleName_ = parcel.ReadString();
184 result->formName_ = parcel.ReadString();
185 result->formDimension_ = parcel.ReadInt32();
186 result->formId_ = parcel.ReadInt64();
187 result->timeStamp_ = parcel.ReadInt64();
188 result->eventId_ = parcel.ReadInt32();
189 result->uid_ = parcel.ReadInt32();
190 return result;
191 }
192
ToString()193 std::string BundleActiveEvent::ToString()
194 {
195 return "bundle name is " + this->bundleName_ + ", uid is " + std::to_string(this->uid_)+ ", event is " +
196 std::to_string(this->eventId_) + ", timestamp is " + std::to_string(this->timeStamp_) + "\n";
197 }
198
IsBundleEvent(const int32_t eventId)199 bool BundleActiveEvent::IsBundleEvent(const int32_t eventId)
200 {
201 if (eventId == ABILITY_BACKGROUND ||
202 eventId == ABILITY_FOREGROUND ||
203 eventId == ABILITY_STOP ||
204 eventId == LONG_TIME_TASK_STARTTED ||
205 eventId == LONG_TIME_TASK_ENDED ||
206 eventId == END_OF_THE_DAY) {
207 return true;
208 }
209 return false;
210 }
211 } // namespace DeviceUsageStats
212 } // namespace OHOS
213
214