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_stats.h" 17 18 namespace OHOS { 19 namespace DeviceUsageStats { 20 static const int32_t DEFAULT_UID_ID = -1; BundleActiveEventStats()21BundleActiveEventStats::BundleActiveEventStats() 22 { 23 eventId_ = 0; 24 beginTimeStamp_ = 0; 25 endTimeStamp_ = 0; 26 lastEventTime_ = 0; 27 totalTime_ = 0; 28 count_ = 0; 29 uid_ = DEFAULT_UID_ID; 30 name_.clear(); 31 } 32 BundleActiveEventStats(const BundleActiveEventStats & orig)33BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& orig) 34 { 35 eventId_ = orig.eventId_; 36 beginTimeStamp_ = orig.beginTimeStamp_; 37 endTimeStamp_ = orig.endTimeStamp_; 38 lastEventTime_ = orig.lastEventTime_; 39 totalTime_ = orig.totalTime_; 40 count_ = orig.count_; 41 name_ = orig.name_; 42 uid_ = orig.uid_; 43 } 44 GetEventId()45int32_t BundleActiveEventStats::GetEventId() 46 { 47 return eventId_; 48 } 49 GetFirstTimeStamp()50int64_t BundleActiveEventStats::GetFirstTimeStamp() 51 { 52 return beginTimeStamp_; 53 } 54 GetLastTimeStamp()55int64_t BundleActiveEventStats::GetLastTimeStamp() 56 { 57 return endTimeStamp_; 58 } 59 GetLastEventTime()60int64_t BundleActiveEventStats::GetLastEventTime() 61 { 62 return lastEventTime_; 63 } 64 GetTotalTime()65int64_t BundleActiveEventStats::GetTotalTime() 66 { 67 return totalTime_; 68 } 69 GetCount()70int32_t BundleActiveEventStats::GetCount() 71 { 72 return count_; 73 } 74 add(const BundleActiveEventStats & right)75void BundleActiveEventStats::add(const BundleActiveEventStats& right) 76 { 77 if (eventId_ != right.eventId_) { 78 return; 79 } 80 81 if (right.beginTimeStamp_ > beginTimeStamp_) { 82 lastEventTime_ = std::max(lastEventTime_, right.lastEventTime_); 83 } 84 beginTimeStamp_ = std::min(beginTimeStamp_, right.beginTimeStamp_); 85 endTimeStamp_ = std::max(endTimeStamp_, right.endTimeStamp_); 86 totalTime_ += right.totalTime_; 87 count_ += right.count_; 88 } 89 Marshalling(Parcel & parcel) const90bool BundleActiveEventStats::Marshalling(Parcel &parcel) const 91 { 92 if (parcel.WriteInt32(eventId_) && 93 parcel.WriteInt64(beginTimeStamp_) && 94 parcel.WriteInt64(endTimeStamp_) && 95 parcel.WriteInt64(lastEventTime_) && 96 parcel.WriteInt64(totalTime_) && 97 parcel.WriteInt32(count_) && 98 parcel.WriteString(name_) && 99 parcel.WriteInt32(uid_)) { 100 return true; 101 } 102 return false; 103 } 104 UnMarshalling(Parcel & parcel)105std::shared_ptr<BundleActiveEventStats> BundleActiveEventStats::UnMarshalling(Parcel &parcel) 106 { 107 std::shared_ptr<BundleActiveEventStats> result = std::make_shared<BundleActiveEventStats>(); 108 result->eventId_ = parcel.ReadInt32(); 109 result->beginTimeStamp_ = parcel.ReadInt64(); 110 result->endTimeStamp_ = parcel.ReadInt64(); 111 result->lastEventTime_ = parcel.ReadInt64(); 112 result->totalTime_ = parcel.ReadInt64(); 113 result->count_ = parcel.ReadInt32(); 114 result->name_ = parcel.ReadString(); 115 result->uid_ = parcel.ReadInt32(); 116 return result; 117 } 118 } // namespace DeviceUsageStats 119 } // namespace OHOS 120 121