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 enum NetConnStatus { 51 NO_NETWORK, 52 ETHERNET_CONNECT, 53 WIFI_CONNECT, 54 CELLULAR_CONNECT, 55 NETWORK_AVAIL, 56 }; 57 static void InitNetworkSetManager(const std::string &bundleName, const int32_t userId); 58 static int32_t QueryCellularConnect(int32_t userId, const std::string &bundleName); 59 static int32_t QueryNetConnect(int32_t userId, const std::string &bundleName); 60 static void RegisterObserver(const std::string &bundleName, const int32_t userId, const int32_t type); 61 static void UnregisterObserver(const std::string &bundleName, const int32_t userId, const int32_t type); 62 static void GetCellularConnect(const std::string &bundleName, const int32_t userId); 63 static void GetNetConnect(const std::string &bundleName, const int32_t userId); 64 static void ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &helper); 65 static bool IsAllowCellularConnect(const std::string &bundleName, const int32_t userId); 66 static bool IsAllowNetConnect(const std::string &bundleName, const int32_t userId); 67 static bool GetConfigParams(const std::string &bundleName, const int32_t userId); 68 static void InitDataSyncManager(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 69 static void NetWorkChangeStopUploadTask(); 70 static void SetNetConnStatus(NetConnStatus netStatus); 71 static inline SafeMap<const std::string, bool> cellularNetMap_; 72 static inline SafeMap<const std::string, bool> netMap_; 73 private: 74 static inline std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager_; 75 static inline NetConnStatus netStatus_{NO_NETWORK}; 76 }; 77 } // OHOS 78 79 #endif // OHOS_FILEMGMT_CLOUD_SYNC_DATA_SHARE_H