• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_storage_stats.h"
17 
18 #include "app_log_wrapper.h"
19 #include "parcel_macro.h"
20 #include "string_ex.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)24 bool BundleStorageStats::ReadFromParcel(Parcel &parcel)
25 {
26     bundleName = Str16ToStr8(parcel.ReadString16());
27     int32_t statsSize = 0;
28     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, statsSize);
29     CONTAINER_SECURITY_VERIFY(parcel, statsSize, &bundleStats);
30     for (auto i = 0; i < statsSize; i++) {
31         bundleStats.push_back(parcel.ReadInt64());
32     }
33     errCode = parcel.ReadInt32();
34     return true;
35 }
36 
Unmarshalling(Parcel & parcel)37 BundleStorageStats *BundleStorageStats::Unmarshalling(Parcel &parcel)
38 {
39     BundleStorageStats *stats = new (std::nothrow) BundleStorageStats();
40     if (stats && !stats->ReadFromParcel(parcel)) {
41         APP_LOGE("read from parcel failed");
42         delete stats;
43         stats = nullptr;
44     }
45     return stats;
46 }
47 
Marshalling(Parcel & parcel) const48 bool BundleStorageStats::Marshalling(Parcel &parcel) const
49 {
50     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
51     const auto statsSize = static_cast<int32_t>(bundleStats.size());
52     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, statsSize);
53     for (auto i = 0; i < statsSize; i++) {
54         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, bundleStats[i]);
55     }
56     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, errCode);
57     return true;
58 }
59 }
60 }