• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_DM_SERVICE_H
17 #define OHOS_DM_SERVICE_H
18 
19 #include <string>
20 #include <memory>
21 #if defined(__LITEOS_M__)
22 #include "dm_mutex.h"
23 #else
24 #include <mutex>
25 #endif
26 
27 #include "device_manager_service_listener.h"
28 #include "idevice_manager_service_impl.h"
29 #include "single_instance.h"
30 #include "softbus_listener.h"
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 class DeviceManagerService {
35 DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerService);
36 public:
DeviceManagerService()37     DeviceManagerService() {}
38 
39     ~DeviceManagerService();
40 
41     int32_t Init();
42 
43     int32_t InitSoftbusListener();
44 
45     void RegisterDeviceManagerListener(const std::string &pkgName);
46 
47     void UnRegisterDeviceManagerListener(const std::string &pkgName);
48 
49     void UninitSoftbusListener();
50 
51     int32_t InitDMServiceListener();
52 
53     void UninitDMServiceListener();
54 
55     int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
56                                  std::vector<DmDeviceInfo> &deviceList);
57 
58     int32_t GetAvailableDeviceList(const std::string &pkgName,
59                                  std::vector<DmDeviceBasicInfo> &deviceBasicInfoList);
60 
61     int32_t ShiftLNNGear(const std::string &pkgName, const std::string &callerId, bool isRefresh);
62 
63     int32_t GetLocalDeviceInfo(DmDeviceInfo &info);
64 
65     int32_t GetLocalDeviceNetworkId(std::string &networkId);
66 
67     int32_t GetLocalDeviceId(const std::string &pkgName, std::string &deviceId);
68 
69     int32_t GetLocalDeviceType(int32_t &deviceType);
70 
71     int32_t GetLocalDeviceName(std::string &deviceName);
72 
73     int32_t GetDeviceInfo(const std::string &networkId, DmDeviceInfo &info);
74 
75     int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid);
76 
77     int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid);
78 
79     int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
80                                  const std::string &extra);
81 
82     int32_t StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeInfo,
83                                 const std::string &filterOptions);
84 
85     int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId);
86 
87     int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo);
88 
89     int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId);
90 
91     int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
92                                const std::string &extra);
93 
94     int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &networkId);
95 
96     int32_t BindDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
97         const std::string &bindParam);
98 
99     int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId);
100 
101     int32_t VerifyAuthentication(const std::string &authParam);
102 
103     int32_t GetFaParam(std::string &pkgName, DmAuthParam &authParam);
104 
105     int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string &params);
106 
107     int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
108 
109     int32_t UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
110 
111     void HandleDeviceOnline(DmDeviceInfo &info);
112 
113     void HandleDeviceOffline(DmDeviceInfo &info);
114 
115     void HandleDeviceNameChange(DmDeviceInfo &info);
116 
117     int OnSessionOpened(int sessionId, int result);
118 
119     void OnSessionClosed(int sessionId);
120 
121     void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen);
122 
123     bool IsDMServiceImplReady();
124 
125     bool IsDMServiceImplSoLoaded();
126 
127     int32_t DmHiDumper(const std::vector<std::string>& args, std::string &result);
128 
129     int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr);
130 
131     int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo);
132 
133     int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo);
134 
135     int32_t RegisterCredentialCallback(const std::string &pkgName);
136 
137     int32_t UnRegisterCredentialCallback(const std::string &pkgName);
138 
139     int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event);
140 
141     int32_t CheckApiPermission();
142 
143     int32_t CheckNewApiPermission();
144 
145     void LoadHardwareFwkService();
146 
147     int32_t GetEncryptedUuidByNetworkId(const std::string &pkgName, const std::string &networkId, std::string &uuid);
148 
149     int32_t GenerateEncryptedUuid(const std::string &pkgName, const std::string &uuid, const std::string &appId,
150         std::string &encryptedUuid);
151 
152     int32_t GetNetworkTypeByNetworkId(const std::string &pkgName, const std::string &netWorkId, int32_t &networkType);
153     int32_t RegisterUiStateCallback(const std::string &pkgName);
154     int32_t UnRegisterUiStateCallback(const std::string &pkgName);
155 
156 private:
157     bool isImplsoLoaded_ = false;
158     std::mutex isImplLoadLock_;
159     std::mutex registerDevStateLock_;
160     std::map<std::string, std::string> registerDevStateMap_;
161     std::shared_ptr<SoftbusListener> softbusListener_;
162     std::shared_ptr<DeviceManagerServiceListener> listener_;
163     std::shared_ptr<IDeviceManagerServiceImpl> dmServiceImpl_;
164     std::string localDeviceId_;
165 };
166 } // namespace DistributedHardware
167 } // namespace OHOS
168 #endif // OHOS_DM_SERVICE_H