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