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_CONNECT_H
17 #define OHOS_STORAGE_MANAGER_CONNECT_H
18 
19 #include <nocopyable.h>
20 #include <singleton.h>
21 
22 #include "istorage_manager.h"
23 #include "bundle_stats.h"
24 #include "storage_stats.h"
25 #include "volume_external.h"
26 
27 namespace OHOS {
28 namespace StorageManager {
29 class StorageManagerConnect : public NoCopyable {
30     DECLARE_DELAYED_SINGLETON(StorageManagerConnect);
31 public:
32     int32_t Connect();
33     int32_t GetBundleStats(std::string pkgName, BundleStats &bundleStats, int32_t appIndex, uint32_t statFlag);
34     int32_t GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize);
35     int32_t GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize);
36     int32_t Mount(std::string volumeId);
37     int32_t Unmount(std::string volumeId);
38     int32_t GetAllVolumes(std::vector<VolumeExternal> &vecOfVol);
39     int32_t GetSystemSize(int64_t &systemSize);
40     int32_t GetTotalSize(int64_t &totalSize);
41     int32_t GetFreeSize(int64_t &freeSize);
42     int32_t GetUserStorageStats(StorageStats &storageStats);
43     int32_t GetUserStorageStats(int32_t userId, StorageStats &storageStats);
44     int32_t GetUserStorageStatsByType(int32_t userId, StorageStats &storageStats, std::string type);
45     int32_t GetCurrentBundleStats(BundleStats &bundleStats, uint32_t statFlag);
46     int32_t GetVolumeByUuid(std::string uuid, VolumeExternal &vol);
47     int32_t GetVolumeById(std::string volumeId, VolumeExternal &vol);
48     int32_t SetVolumeDescription(std::string uuid, std::string description);
49     int32_t Format(std::string volumeId, std::string fsType);
50     int32_t Partition(std::string diskId, int32_t type);
51 
52     int32_t ResetProxy();
53 private:
54     sptr<StorageManager::IStorageManager> storageManager_ = nullptr;
55     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
56     std::mutex mutex_;
57 };
58 
59 class SmDeathRecipient : public IRemoteObject::DeathRecipient {
60 public:
61     SmDeathRecipient() = default;
62     virtual ~SmDeathRecipient() = default;
63 
64     virtual void OnRemoteDied(const wptr<IRemoteObject> &object);
65 };
66 
67 bool IsSystemApp();
68 int32_t Convert2JsErrNum(int32_t errNum);
69 } // StorageManager
70 } // OHOS
71 
72 #endif