• 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_priority_list.h"
17 #include "memmgr_log.h"
18 
19 namespace OHOS {
20 namespace Memory {
21 namespace {
22 const std::string TAG = "MemMgrClient";
23 }
24 
GetCount() const25 int32_t BundlePriorityList::GetCount() const
26 {
27     return count_;
28 }
29 
SetCount(int32_t count)30 void BundlePriorityList::SetCount(int32_t count)
31 {
32     count_ = count;
33 }
34 
GetList()35 const std::vector<BundlePriority>& BundlePriorityList::GetList()
36 {
37     return list_;
38 }
39 
Size() const40 int32_t BundlePriorityList::Size() const
41 {
42     return list_.size();
43 }
44 
AddBundleInfo(BundlePriority & bundleInfo)45 void BundlePriorityList::AddBundleInfo(BundlePriority &bundleInfo)
46 {
47     list_.push_back(bundleInfo);
48 }
49 
Show() const50 void BundlePriorityList::Show() const
51 {
52     HILOGI("     uid                                            name   priority   accountId");
53     for (auto bi : list_) {
54         HILOGI("%{public}8d\t%{public}42s\t%{public}5d\t%{public}3d",
55             bi.uid_, bi.name_.c_str(), bi.priority_, bi.accountId_);
56     }
57     HILOGI("-------------------------------------------------------------------------------");
58 }
59 
Marshalling(Parcel & parcel) const60 bool BundlePriorityList::Marshalling(Parcel &parcel) const
61 {
62     if (!parcel.WriteInt32(count_)) {
63         HILOGE("Failed to write count_");
64         return false;
65     }
66     for (auto i = 0; i < count_; ++i) {
67         if (!parcel.WriteInt32(list_[i].uid_)) {
68             HILOGE("Failed to write uid_");
69             return false;
70         }
71         if (!parcel.WriteString(list_[i].name_)) {
72             HILOGE("Failed to write ability name");
73             return false;
74         }
75         if (!parcel.WriteInt32(list_[i].priority_)) {
76             HILOGE("Failed to write priority_");
77             return false;
78         }
79         if (!parcel.WriteInt32(list_[i].accountId_)) {
80             HILOGE("Failed to write accountId_");
81             return false;
82         }
83     }
84     return true;
85 }
86 
Unmarshalling(Parcel & parcel)87 BundlePriorityList* BundlePriorityList::Unmarshalling(Parcel &parcel)
88 {
89     auto object = new (std::nothrow) BundlePriorityList();
90     if ((object != nullptr) && !object->ReadFromParcel(parcel)) {
91         delete object;
92         object = nullptr;
93     }
94 
95     return object;
96 }
97 
ReadFromParcel(Parcel & parcel)98 bool BundlePriorityList::ReadFromParcel(Parcel &parcel)
99 {
100     count_ = parcel.ReadInt32();
101     for (auto i = 0; i < count_; ++i) {
102         int32_t uid = parcel.ReadInt32();
103         std::string name;
104         if (!parcel.ReadString(name)) {
105             HILOGE("Failed to read creator ability name");
106             return false;
107         }
108         int32_t priority = parcel.ReadInt32();
109         int32_t accountId = parcel.ReadInt32();
110         list_.push_back(BundlePriority(uid, name, priority, accountId));
111     }
112     return true;
113 }
114 }
115 }
116 
117