• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_form_record.h"
17 
18 namespace OHOS {
19 namespace DeviceUsageStats {
BundleActiveFormRecord()20 BundleActiveFormRecord::BundleActiveFormRecord()
21 {
22     formName_ = "";
23     formDimension_ = 0;
24     formId_ = 0;
25     formLastUsedTime_ = -1;
26     count_ = 0;
27     userId_ = -1;
28     uid_ = -1;
29 }
30 
BundleActiveFormRecord(const std::string formName,const int32_t formDimension,const int64_t formId,const int64_t timeStamp,const int32_t userId,const int32_t uid)31 BundleActiveFormRecord::BundleActiveFormRecord(const std::string formName, const int32_t formDimension,
32     const int64_t formId, const int64_t timeStamp, const int32_t userId, const int32_t uid)
33 {
34     formName_ = formName;
35     formDimension_ = formDimension;
36     formId_ = formId;
37     formLastUsedTime_ = timeStamp;
38     count_ = 1;
39     userId_ = userId;
40     uid_ = uid;
41 }
42 
BundleActiveFormRecord(const BundleActiveFormRecord & orig)43 BundleActiveFormRecord::BundleActiveFormRecord(const BundleActiveFormRecord& orig)
44 {
45     formName_ = orig.formName_;
46     formDimension_ = orig.formDimension_;
47     formId_ = orig.formId_;
48     formLastUsedTime_ = orig.formLastUsedTime_;
49     count_ = orig.count_;
50     userId_ = orig.userId_;
51     uid_ = orig.uid_;
52 }
53 
UpdateFormRecord(const int64_t timeStamp)54 void BundleActiveFormRecord::UpdateFormRecord(const int64_t timeStamp)
55 {
56     if (formLastUsedTime_ < timeStamp) {
57         formLastUsedTime_ = timeStamp;
58         count_++;
59     }
60 }
61 
Marshalling(Parcel & parcel) const62 bool BundleActiveFormRecord::Marshalling(Parcel &parcel) const
63 {
64     if (parcel.WriteString(formName_) &&
65         parcel.WriteInt32(formDimension_) &&
66         parcel.WriteInt64(formId_) &&
67         parcel.WriteInt64(formLastUsedTime_) &&
68         parcel.WriteInt32(count_)) {
69         return true;
70     }
71     return false;
72 }
73 
Unmarshalling(Parcel & parcel)74 BundleActiveFormRecord *BundleActiveFormRecord::Unmarshalling(Parcel &parcel)
75 {
76     BundleActiveFormRecord *result = new (std::nothrow) BundleActiveFormRecord();
77     if (result == nullptr) {
78         return nullptr;
79     }
80     result->formName_ = parcel.ReadString();
81     result->formDimension_ = parcel.ReadInt32();
82     result->formId_ = parcel.ReadInt64();
83     result->formLastUsedTime_ = parcel.ReadInt64();
84     result->count_ = parcel.ReadInt32();
85     return result;
86 }
87 
cmp(const BundleActiveFormRecord & formRecordA,const BundleActiveFormRecord & formRecordB)88 bool BundleActiveFormRecord::cmp(const BundleActiveFormRecord& formRecordA,
89     const BundleActiveFormRecord& formRecordB)
90 {
91     return formRecordA.count_ > formRecordB.count_;
92 }
93 
ToString()94 std::string BundleActiveFormRecord::ToString()
95 {
96     return "form name is " + this->formName_ +
97         ", form dimension is " + std::to_string(this->formDimension_) +
98         ", form id is " + std::to_string(this->formId_) +
99         ", uid id is " + std::to_string(this->uid_) +
100         ", last used time stamp is" + std::to_string(this->formLastUsedTime_) +
101         ", touch count is " + std::to_string(this->count_) + "\n";
102 }
103 }  // namespace DeviceUsageStats
104 }  // namespace OHOS
105 
106