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 }
29
BundleActiveFormRecord(const std::string formName,const int32_t formDimension,const int64_t formId,const int64_t timeStamp,const int32_t userId)30 BundleActiveFormRecord::BundleActiveFormRecord(const std::string formName, const int32_t formDimension,
31 const int64_t formId, const int64_t timeStamp, const int32_t userId)
32 {
33 formName_ = formName;
34 formDimension_ = formDimension;
35 formId_ = formId;
36 formLastUsedTime_ = timeStamp;
37 count_ = 1;
38 userId_ = userId;
39 }
40
BundleActiveFormRecord(const BundleActiveFormRecord & orig)41 BundleActiveFormRecord::BundleActiveFormRecord(const BundleActiveFormRecord& orig)
42 {
43 formName_ = orig.formName_;
44 formDimension_ = orig.formDimension_;
45 formId_ = orig.formId_;
46 formLastUsedTime_ = orig.formLastUsedTime_;
47 count_ = orig.count_;
48 userId_ = orig.userId_;
49 }
50
UpdateFormRecord(const int64_t timeStamp)51 void BundleActiveFormRecord::UpdateFormRecord(const int64_t timeStamp)
52 {
53 if (formLastUsedTime_ < timeStamp) {
54 formLastUsedTime_ = timeStamp;
55 count_++;
56 }
57 }
58
Marshalling(Parcel & parcel) const59 bool BundleActiveFormRecord::Marshalling(Parcel &parcel) const
60 {
61 if (parcel.WriteString(formName_) &&
62 parcel.WriteInt32(formDimension_) &&
63 parcel.WriteInt64(formId_) &&
64 parcel.WriteInt64(formLastUsedTime_) &&
65 parcel.WriteInt32(count_)) {
66 return true;
67 }
68 return false;
69 }
70
UnMarshalling(Parcel & parcel)71 std::shared_ptr<BundleActiveFormRecord> BundleActiveFormRecord::UnMarshalling(Parcel &parcel)
72 {
73 std::shared_ptr<BundleActiveFormRecord> result = std::make_shared<BundleActiveFormRecord>();
74 result->formName_ = parcel.ReadString();
75 result->formDimension_ = parcel.ReadInt32();
76 result->formId_ = parcel.ReadInt64();
77 result->formLastUsedTime_ = parcel.ReadInt64();
78 result->count_ = parcel.ReadInt32();
79 return result;
80 }
81
cmp(const BundleActiveFormRecord & formRecordA,const BundleActiveFormRecord & formRecordB)82 bool BundleActiveFormRecord::cmp(const BundleActiveFormRecord& formRecordA,
83 const BundleActiveFormRecord& formRecordB)
84 {
85 return formRecordA.count_ > formRecordB.count_;
86 }
87
ToString()88 std::string BundleActiveFormRecord::ToString()
89 {
90 return "form name is " + this->formName_ +
91 ", form dimension is " + std::to_string(this->formDimension_) +
92 ", form id is " + std::to_string(this->formId_) +
93 ", last used time stamp is" + std::to_string(this->formLastUsedTime_) +
94 ", touch count is " + std::to_string(this->count_) + "\n";
95 }
96 } // namespace DeviceUsageStats
97 } // namespace OHOS
98
99