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 #ifndef OHOS_FILEMGMT_CLOUD_SYNC_DATA_SHARE_H 17 #define OHOS_FILEMGMT_CLOUD_SYNC_DATA_SHARE_H 18 19 #include <functional> 20 #include <iostream> 21 #include <map> 22 #include <string> 23 24 #include "datashare_helper.h" 25 #include "data_ability_observer_stub.h" 26 #include "data_sync_manager.h" 27 #include "safe_map.h" 28 29 namespace OHOS::FileManagement::CloudSync { 30 class MobileNetworkObserver : public AAFwk::DataAbilityObserverStub { 31 public: MobileNetworkObserver(const std::string & bundleName,const int32_t userId,const int32_t type)32 MobileNetworkObserver(const std::string &bundleName, const int32_t userId, const int32_t type) 33 : bundleName_(bundleName), userId_(userId), type_(type) {} ~MobileNetworkObserver()34 ~MobileNetworkObserver() {} 35 void OnChange() override; 36 using ObserverCallback = std::function<void()>; 37 private: 38 std::string bundleName_; 39 int32_t userId_ = -1; 40 int32_t type_ = -1; 41 ObserverCallback observerCallback_ = nullptr; 42 }; 43 44 class NetworkSetManager { 45 public: 46 enum PhotoType { 47 CELLULARCONNECT, 48 NETCONNECT, 49 }; 50 static void InitNetworkSetManager(const std::string &bundleName, const int32_t userId); 51 static int32_t QueryCellularConnect(int32_t userId, const std::string &bundleName); 52 static int32_t QueryNetConnect(int32_t userId, const std::string &bundleName); 53 static void RegisterObserver(const std::string &bundleName, const int32_t userId, const int32_t type); 54 static void UnregisterObserver(const std::string &bundleName, const int32_t userId, const int32_t type); 55 static void GetCellularConnect(const std::string &bundleName, const int32_t userId); 56 static void GetNetConnect(const std::string &bundleName, const int32_t userId); 57 static void ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper); 58 static bool IsAllowCellularConnect(const std::string &bundleName, const int32_t userId); 59 static bool IsAllowNetConnect(const std::string &bundleName, const int32_t userId); 60 static bool GetConfigParams(const std::string &bundleName, const int32_t userId); 61 static void InitDataSyncManager(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 62 static void NetWorkChangeStopUploadTask(); 63 static inline SafeMap<const std::string, bool> cellularNetMap_; 64 static inline SafeMap<const std::string, bool> netMap_; 65 private: 66 static inline std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager_; 67 }; 68 } // OHOS 69 70 #endif // OHOS_FILEMGMT_CLOUD_SYNC_DATA_SHARE_H