1 /*
2 * Copyright (c) 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 "cloud_file_kit_impl.h"
17
18 #include <memory>
19
20 #include "cloud_database_impl.h"
21 #include "cloud_assets_downloader_impl.h"
22 #include "cloud_sync_helper_impl.h"
23 #include "data_sync_manager_impl.h"
24 #include "dfs_error.h"
25
26
27 namespace OHOS::FileManagement::CloudFile {
28
29 __attribute__((used)) static bool g_isInit =
30 CloudFileKit::RegisterCloudInstance(new (std::nothrow) CloudFileKitImpl());
31
32 using namespace std;
33
GetCloudUserInfo(const int32_t userId,CloudUserInfo & userInfo)34 int32_t CloudFileKitImpl::GetCloudUserInfo(const int32_t userId, CloudUserInfo &userInfo)
35 {
36 userInfo.enableCloud = true;
37 return E_OK;
38 }
39
GetSpaceInfo(const int32_t userId,const std::string & bundleName)40 std::pair<uint64_t, uint64_t> CloudFileKitImpl::GetSpaceInfo(const int32_t userId, const std::string &bundleName)
41 {
42 return std::make_pair(0, 0);
43 }
44
GetAppSwitchStatus(const std::string & bundleName,const int32_t userId,bool & switchStatus)45 int32_t CloudFileKitImpl::GetAppSwitchStatus(const std::string &bundleName,
46 const int32_t userId,
47 bool &switchStatus)
48 {
49 switchStatus = true;
50 return E_OK;
51 }
52
ResolveNotificationEvent(const int32_t userId,const std::string & extraData,std::string & appBundleName,std::string & prepareTraceId)53 int32_t CloudFileKitImpl::ResolveNotificationEvent(const int32_t userId,
54 const std::string &extraData,
55 std::string &appBundleName,
56 std::string &prepareTraceId)
57 {
58 appBundleName = "com.ohos.photos";
59 return E_OK;
60 }
61
GetDataSyncManager()62 std::shared_ptr<DataSyncManager> CloudFileKitImpl::GetDataSyncManager()
63 {
64 std::lock_guard<std::mutex> lck(dataSyncManagerMutex_);
65 if (dataSyncManager_ == nullptr) {
66 dataSyncManager_ = std::make_shared<DataSyncManagerImpl>();
67 }
68 return dataSyncManager_;
69 }
70
GetCloudAssetsDownloader(const int32_t userId,const std::string & bundleName)71 std::shared_ptr<CloudAssetsDownloader> CloudFileKitImpl::GetCloudAssetsDownloader(const int32_t userId,
72 const std::string &bundleName)
73 {
74 std::lock_guard<std::mutex> lck(cloudAssetsDownloaderMutex_);
75 if (cloudAssetsDownloader_ == nullptr) {
76 cloudAssetsDownloader_ = std::make_shared<CloudAssetsDownloaderImpl>(userId, bundleName);
77 }
78 return cloudAssetsDownloader_;
79 }
80
GetCloudSyncHelper(const int32_t userId,const std::string & bundleName)81 std::shared_ptr<CloudSyncHelper> CloudFileKitImpl::GetCloudSyncHelper(const int32_t userId,
82 const std::string &bundleName)
83 {
84 std::lock_guard<std::mutex> lck(cloudSyncHelperMutex_);
85 if (cloudSyncHelper_ == nullptr) {
86 std::shared_ptr<CloudSyncHelper> cloudSyncHelper = std::make_shared<CloudSyncHelperImpl>(userId, bundleName);
87 if (cloudSyncHelper->Init() == E_OK) {
88 cloudSyncHelper_ = cloudSyncHelper;
89 }
90 }
91 return cloudSyncHelper_;
92 }
93
GetCloudDatabase(const int32_t userId,const std::string & bundleName)94 std::shared_ptr<CloudDatabase> CloudFileKitImpl::GetCloudDatabase(const int32_t userId, const std::string &bundleName)
95 {
96 std::lock_guard<std::mutex> lck(cloudDatabaseMutex_);
97 if (cloudDatabase_ == nullptr) {
98 auto cloudDatabase = std::make_shared<CloudDatabaseImpl>(userId, bundleName);
99 if (cloudDatabase->Init() == E_OK) {
100 cloudDatabase_ = cloudDatabase;
101 }
102 }
103 return cloudDatabase_;
104 }
105
GetPrepareTraceId(const int32_t userId)106 std::string CloudFileKitImpl::GetPrepareTraceId(const int32_t userId)
107 {
108 return "";
109 }
110 } // namespace OHOS::FileManagement::CloudFile