1 /*
2 * Copyright (c) 2021-2024 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 "system_memory_attr.h"
17 #include "hilog_tag_wrapper.h"
18
19 namespace OHOS {
20 namespace AppExecFwk {
SystemMemoryAttr()21 SystemMemoryAttr::SystemMemoryAttr() : availSysMem_(0), totalSysMem_(0), threshold_(0), isSysInlowMem_(false)
22 {}
23
ReadFromParcel(Parcel & parcel)24 bool SystemMemoryAttr::ReadFromParcel(Parcel &parcel)
25 {
26 parcel.ReadInt64(availSysMem_);
27 parcel.ReadInt64(totalSysMem_);
28 parcel.ReadInt64(threshold_);
29 isSysInlowMem_ = parcel.ReadBool();
30
31 TAG_LOGD(AAFwkTag::APPMGR, "SystemMemoryAttr::ReadFromParcel %{public}zu %{public}zu %{public}zu %{public}s",
32 static_cast<size_t>(availSysMem_),
33 static_cast<size_t>(totalSysMem_),
34 static_cast<size_t>(threshold_),
35 (isSysInlowMem_ ? "true" : "false"));
36
37 return true;
38 }
39
Unmarshalling(Parcel & parcel)40 SystemMemoryAttr *SystemMemoryAttr::Unmarshalling(Parcel &parcel)
41 {
42 SystemMemoryAttr *info = new (std::nothrow) SystemMemoryAttr();
43 if (info == nullptr) {
44 return nullptr;
45 }
46
47 if (!info->ReadFromParcel(parcel)) {
48 delete info;
49 info = nullptr;
50 }
51 return info;
52 }
53
Marshalling(Parcel & parcel) const54 bool SystemMemoryAttr::Marshalling(Parcel &parcel) const
55 {
56 parcel.WriteInt64(availSysMem_);
57 parcel.WriteInt64(totalSysMem_);
58 parcel.WriteInt64(threshold_);
59 parcel.WriteBool(isSysInlowMem_);
60
61 TAG_LOGD(AAFwkTag::APPMGR, "SystemMemoryAttr::Marshalling %{public}zu %{public}zu %{public}zu %{public}s",
62 static_cast<size_t>(availSysMem_),
63 static_cast<size_t>(totalSysMem_),
64 static_cast<size_t>(threshold_),
65 (isSysInlowMem_ ? "true" : "false"));
66
67 return true;
68 }
69 } // namespace AppExecFwk
70 } // namespace OHOS
71