• 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 "storage_manager_ffi.h"
17 
18 #include "bundle_stats.h"
19 #include "cj_common_ffi.h"
20 #include "native/ffi_remote_data.h"
21 #include "storage_manager_impl.h"
22 
23 #include "storage_service_errno.h"
24 #include "storage_service_log.h"
25 
26 namespace OHOS {
27 namespace CJStorageManager {
28 
29 extern "C" {
FfiFileStorStatsGetCurrentBundleStats(NativeBundleStats * stats,int32_t * errCode)30 FFI_EXPORT void FfiFileStorStatsGetCurrentBundleStats(NativeBundleStats *stats, int32_t *errCode)
31 {
32     if (stats == nullptr) {
33         *errCode = E_NOOBJECT;
34         LOGE("FfiFileStorStatsGetCurrentBundleStats check failed");
35         return;
36     }
37     StorageManager::BundleStats bundleStats = {};
38     uint32_t statFlag = 0;
39     auto service = DelayedSingleton<CjStorageStatusService>::GetInstance();
40     if (service == nullptr) {
41         *errCode = E_IPCSS;
42         return;
43     }
44     int32_t errNum = service->GetCurrentBundleStats(bundleStats, statFlag);
45     if (errNum != E_OK) {
46         *errCode = Convert2CjErrNum(errNum);
47         return;
48     }
49     *errCode = E_OK;
50     stats->appSize = bundleStats.appSize_;
51     stats->cacheSize = bundleStats.cacheSize_;
52     stats->dataSize = bundleStats.dataSize_;
53     return;
54 }
55 
FfiFileStorStatsGetTotalSize(int32_t * errCode)56 FFI_EXPORT int64_t FfiFileStorStatsGetTotalSize(int32_t *errCode)
57 {
58     int64_t totalSize = 0;
59     auto service = DelayedSingleton<CjStorageStatusService>::GetInstance();
60     if (service == nullptr) {
61         *errCode = E_IPCSS;
62         return 0;
63     }
64     int32_t errNum = service->GetTotalSize(totalSize);
65     if (errNum != E_OK) {
66         *errCode = Convert2CjErrNum(errNum);
67         return 0;
68     }
69     *errCode = E_OK;
70     return totalSize;
71 }
72 
FfiFileStorStatsGetFreeSize(int32_t * errCode)73 FFI_EXPORT int64_t FfiFileStorStatsGetFreeSize(int32_t *errCode)
74 {
75     int64_t freeSize = 0;
76     auto service = DelayedSingleton<CjStorageStatusService>::GetInstance();
77     if (service == nullptr) {
78         *errCode = E_IPCSS;
79         return 0;
80     }
81     int32_t errNum = service->GetFreeSize(freeSize);
82     if (errNum != E_OK) {
83         *errCode = Convert2CjErrNum(errNum);
84         return 0;
85     }
86     *errCode = E_OK;
87     return freeSize;
88 }
89 }
90 
91 } // namespace CJStorageManager
92 } // namespace OHOS