• 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 UninitSoftbusListener();
46 
47     int32_t InitDMServiceListener();
48 
49     void UninitDMServiceListener();
50 
51     int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
52                                  std::vector<DmDeviceInfo> &deviceList);
53 
54     int32_t GetLocalDeviceInfo(DmDeviceInfo &info);
55 
56     int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid);
57 
58     int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid);
59 
60     int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
61                                  const std::string &extra);
62 
63     int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId);
64 
65     int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo);
66 
67     int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId);
68 
69     int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
70                                const std::string &extra);
71 
72     int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId);
73 
74     int32_t VerifyAuthentication(const std::string &authParam);
75 
76     int32_t GetFaParam(std::string &pkgName, DmAuthParam &authParam);
77 
78     int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string &params);
79 
80     int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
81 
82     int32_t UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
83 
84     void HandleDeviceOnline(const DmDeviceInfo &info);
85 
86     void HandleDeviceOffline(const DmDeviceInfo &info);
87 
88     int OnSessionOpened(int sessionId, int result);
89 
90     void OnSessionClosed(int sessionId);
91 
92     void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen);
93 
94     bool IsDMServiceImplReady();
95 
96     bool IsDMServiceImplSoLoaded();
97 
98     int32_t DmHiDumper(const std::vector<std::string>& args, std::string &result);
99 
100     int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr);
101 
102     int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo);
103 
104     int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo);
105 
106     int32_t RegisterCredentialCallback(const std::string &pkgName);
107 
108     int32_t UnRegisterCredentialCallback(const std::string &pkgName);
109 
110     int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event);
111 
112     void LoadHardwareFwkService();
113 
114     int32_t GetEncryptedUuidByNetworkId(const std::string &pkgName, const std::string &networkId, std::string &uuid);
115 
116     int32_t GenerateEncryptedUuid(const std::string &pkgName, const std::string &uuid, const std::string &appId,
117         std::string &encryptedUuid);
118 private:
119     bool isImplsoLoaded_ = false;
120     std::mutex isImplLoadLock_;
121     std::mutex registerDevStateLock_;
122     std::map<std::string, std::string> registerDevStateMap_;
123     std::shared_ptr<SoftbusListener> softbusListener_;
124     std::shared_ptr<DeviceManagerServiceListener> listener_;
125     std::shared_ptr<IDeviceManagerServiceImpl> dmServiceImpl_;
126 };
127 } // namespace DistributedHardware
128 } // namespace OHOS
129 #endif // OHOS_DM_SERVICE_H