1 /* 2 * Copyright (c) 2022 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 DEVICE_INFO_MANAGER_H 17 #define DEVICE_INFO_MANAGER_H 18 19 #include <string> 20 21 #include "accesstoken_log.h" 22 #include "data_validator.h" 23 #include "device_info_repository.h" 24 #include "ipc_skeleton.h" 25 #include "parameter.h" 26 #include "soft_bus_manager.h" 27 28 namespace OHOS { 29 namespace Security { 30 namespace AccessToken { 31 class DeviceInfoManager { 32 public: 33 static DeviceInfoManager &GetInstance(); 34 35 /** 36 * Get device info by device id. 37 * 38 * @param nodeId Device id. 39 * @param deviceIdType Device id type {@link DeviceIdType} 40 * @param deviceInfo Optional deviceInfo. 41 * @return True for success, false otherwise. 42 */ 43 bool GetDeviceInfo(const std::string &nodeId, DeviceIdType deviceIdType, DeviceInfo &deviceInfo) const; 44 45 /** 46 * Check device info exist. Online and local device info will be here. 47 * 48 * @param nodeId Device id. 49 * @param deviceIdType Device id type {@link DeviceIdType} 50 * @return True for exist, false otherwise. 51 */ 52 bool ExistDeviceInfo(const std::string &nodeId, DeviceIdType deviceIdType) const; 53 54 /** 55 * Add device info with device ids and device properties. 56 * 57 * @param networkId Device networkId. 58 * @param universallyUniqueId Device uuid. 59 * @param uniqueDeviceId Device udid. 60 * @param deviceName Device name. 61 * @param deviceType Device type. 62 */ 63 void AddDeviceInfo(const std::string &networkId, const std::string &universallyUniqueId, 64 const std::string &uniqueDeviceId, const std::string &deviceName, const std::string &deviceType); 65 66 /** 67 * Remote all device info. 68 */ 69 void RemoveAllRemoteDeviceInfo(); 70 71 /** 72 * Remove one device info. 73 * 74 * @param nodeId Device id. 75 * @param deviceIdType Device id type {@link DeviceIdType} 76 */ 77 void RemoveRemoteDeviceInfo(const std::string &nodeId, DeviceIdType deviceIdType); 78 79 /** 80 * Convert nodeId to deviceId(UUID) if possible. 81 * 82 * @param nodeId which is considered as indefinite id, maybe deviceId(UUID) or networkId. 83 * @return The deviceId if local or device online, otherwise return empty string. 84 */ 85 std::string ConvertToUniversallyUniqueIdOrFetch(const std::string &nodeId) const; 86 87 /** 88 * Convert nodeId to deviceId(UDID) if possible. 89 * 90 * @param nodeId which is considered as indefinite id, maybe deviceId(UDID) or networkId. 91 * @return The deviceId if local or device online, otherwise return empty string. 92 */ 93 std::string ConvertToUniqueDeviceIdOrFetch(const std::string &nodeId) const; 94 95 /** 96 * Check nodeId is uuid or not. 97 * 98 * @param nodeId Node id. 99 * @return True if node id is uuid. False otherwise. 100 */ 101 bool IsDeviceUniversallyUniqueId(const std::string &nodeId) const; 102 }; 103 } // namespace AccessToken 104 } // namespace Security 105 } // namespace OHOS 106 #endif // DEVICE_INFO_MANAGER_H 107