1 /* 2 * Copyright (c) 2025 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 FILEMANAGEMENT_DFS_SERVICE_DEVICE_PROFILE_ADAPTER_H 17 #define FILEMANAGEMENT_DFS_SERVICE_DEVICE_PROFILE_ADAPTER_H 18 19 #include <map> 20 #include <sstream> 21 #include <string> 22 23 namespace OHOS { 24 namespace Storage { 25 namespace DistributedFile { 26 enum class VersionPackageName { 27 DFS_VERSION = 1, 28 }; 29 30 struct DfsVersion { 31 uint32_t majorVersionNum = 0; 32 uint32_t minorVersionNum = 0; 33 uint32_t featureVersionNum = 0; 34 dumpDfsVersion35 std::string dump() const 36 { 37 std::stringstream ss; 38 ss << majorVersionNum << "." << minorVersionNum << "." << featureVersionNum; 39 return ss.str(); 40 } 41 }; 42 43 class DeviceProfileAdapter { 44 public: 45 ~DeviceProfileAdapter() = default; GetInstance()46 static DeviceProfileAdapter &GetInstance() 47 { 48 static DeviceProfileAdapter instance; 49 return instance; 50 } 51 bool IsRemoteDfsVersionLower(const std::string &remoteNetworkId, 52 VersionPackageName packageName = VersionPackageName::DFS_VERSION); 53 bool IsRemoteDfsVersionLower(const std::string &remoteNetworkId, 54 const DfsVersion& thresholdDfsVersion, VersionPackageName packageName = VersionPackageName::DFS_VERSION); 55 int32_t GetDfsVersionFromNetworkId(const std::string &networkId, 56 DfsVersion &dfsVersion, VersionPackageName packageName = VersionPackageName::DFS_VERSION); 57 bool CompareDfsVersion(const DfsVersion &dfsVersion, const DfsVersion &thresholdDfsVersion); 58 int32_t GetDeviceStatus(const std::string &networkId, bool &status); 59 int32_t PutDeviceStatus(bool status); 60 61 private: GetPackageName(VersionPackageName packageName)62 std::string GetPackageName(VersionPackageName packageName) 63 { 64 static std::map<VersionPackageName, std::string> packageNamesMap = { 65 {VersionPackageName::DFS_VERSION, "dfsVersion"}, 66 }; 67 auto it = packageNamesMap.find(packageName); 68 if (it == packageNamesMap.end()) { 69 return ""; 70 } 71 return it->second; 72 } 73 #ifdef SUPPORT_DEVICE_PROFILE 74 int32_t GetDfsVersionDataFromAppInfo(const std::string &packageNamesData, 75 const std::string &versionsData, VersionPackageName packageName, std::string &dfsVersionData); 76 int32_t GetAppInfoFromDP(const std::string &udid, const std::string &serviceName, std::string &appInfoJsonData); 77 int32_t GetDfsVersion(const std::string &udid, VersionPackageName packageName, 78 DfsVersion &dfsVersion, bool IsVerifyCode); 79 bool ParseDfsVersion(const std::string &dfsVersionData, DfsVersion &dfsVersion); 80 int32_t ParseAppInfo(const std::string &appInfoJsonData, std::string &packageNamesData, std::string &versionsData); 81 int32_t GetLocalDfsVersion(VersionPackageName packageName, DfsVersion &dfsVersion); 82 std::string GetUdidByNetworkId(const std::string &networkId); 83 #endif 84 }; 85 } // namespace DistributedFile 86 } // namespace Storage 87 } // namespace OHOS 88 #endif // FILEMANAGEMENT_DFS_SERVICE_ALL_CONNECT_MANAGER_H 89