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 #ifndef OHOS_STORAGE_MANAGER_STORAGE_STATUS_SERVICE_H
17 #define OHOS_STORAGE_MANAGER_STORAGE_STATUS_SERVICE_H
18 
19 #include <vector>
20 #include <nocopyable.h>
21 #include <singleton.h>
22 #include <iostream>
23 #include "bundle_stats.h"
24 #include "storage_stats.h"
25 #include "iremote_object.h"
26 
27 namespace OHOS {
28 namespace StorageManager {
29 class StorageStatusService : public NoCopyable  {
30     DECLARE_DELAYED_SINGLETON(StorageStatusService);
31 
32 public:
33     int32_t GetBundleStats(const std::string &pkgName, BundleStats &bundleStats, int32_t appIndex, uint32_t statFlag);
34     int32_t GetUserStorageStats(StorageStats &storageStats);
35     int32_t GetUserStorageStats(int32_t userId, StorageStats &storageStats);
36     int32_t GetUserStorageStatsByType(int32_t userId, StorageStats &storageStats, std::string type);
37     int32_t GetCurrentBundleStats(BundleStats &bundleStats, uint32_t statFlag);
38     int32_t GetBundleStats(const std::string &pkgName, int32_t userId, BundleStats &bundleStats,
39         int32_t appIndex, uint32_t statFlag);
40     int32_t GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames,
41         const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes,
42         std::vector<int64_t> &incPkgFileSizes);
43 
44 private:
45     int GetCurrentUserId();
46     std::string GetCallingPkgName();
47     int32_t GetAppSize(int32_t userId, int64_t &size);
48     const std::vector<std::string> dataDir = {"app", "local", "distributed", "database", "cache"};
49     const int DEFAULT_USER_ID = 100;
50     const int DEFAULT_APP_INDEX = 0;
51     enum BUNDLE_STATS {APP = 0, LOCAL, DISTRIBUTED, DATABASE, CACHE};
52     enum BUNDLE_STATS_RESULT {APPSIZE = 0, CACHESIZE, DATASIZE};
53 };
54 } // StorageManager
55 } // OHOS
56 
57 #endif // OHOS_STORAGE_MANAGER_STORAGE_STATUS_SERVICE_H