1 /*
2 * Copyright (c) 2024 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 #include "notifictaion_load_utils.h"
17
18 #include <map>
19 #include <dlfcn.h>
20 #include "distributed_data_define.h"
21 #include "ans_log_wrapper.h"
22 #include "mock_device_manager_impl.h"
23
24 namespace OHOS {
25 namespace Notification {
26
27 static bool g_notificationProxyValid = false;
28 static std::map<std::string, std::string> g_deviceList;
29
ResetDeviceData()30 void DeviceCheck::ResetDeviceData()
31 {
32 return g_deviceList.clear();
33 }
34
CheckDeviceOnline()35 bool DeviceCheck::CheckDeviceOnline()
36 {
37 return !g_deviceList.empty();
38 }
39
GetDeviceNetworkId(std::string deviceId)40 std::string DeviceCheck::GetDeviceNetworkId(std::string deviceId)
41 {
42 if (g_deviceList.find(deviceId) == g_deviceList.end()) {
43 return std::string();
44 }
45 return g_deviceList[deviceId];
46 }
47
InitLocalDevice(const std::string & deviceId,uint16_t deviceType,DistributedDeviceConfig config,DistributedHaCallbacks callbacks)48 int32_t InitLocalDevice(const std::string &deviceId, uint16_t deviceType,
49 DistributedDeviceConfig config, DistributedHaCallbacks callbacks)
50 {
51 return 0;
52 }
53
AddDevice(const std::string & deviceId,const std::string & udid,uint16_t deviceType,const std::string & networkId)54 void AddDevice(const std::string &deviceId, const std::string &udid, uint16_t deviceType,
55 const std::string &networkId)
56 {
57 g_deviceList.insert({deviceId, networkId});
58 return;
59 }
60
DeviceStatusChange(const DeviceStatueChangeInfo & changeInfo)61 void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo)
62 {
63 return;
64 }
65
ReleaseDevice(const std::string & deviceId,uint16_t deviceType)66 void ReleaseDevice(const std::string &deviceId, uint16_t deviceType)
67 {
68 g_deviceList.erase(deviceId);
69 return;
70 }
71
RefreshDevice(const std::string & deviceId,uint16_t deviceType,const std::string & networkId)72 void RefreshDevice(const std::string &deviceId, uint16_t deviceType, const std::string &networkId)
73 {
74 if (g_deviceList.find(deviceId) == g_deviceList.end()) {
75 return;
76 }
77 g_deviceList[deviceId] = networkId;
78 return;
79 }
80
ReleaseLocalDevice()81 void ReleaseLocalDevice()
82 {
83 return;
84 }
85
InitHACallBack(std::function<void (int32_t,int32_t,uint32_t,std::string)> callback)86 void InitHACallBack(std::function<void(int32_t, int32_t, uint32_t, std::string)> callback)
87 {
88 return;
89 }
90
InitSendReportCallBack(std::function<void (int32_t,int32_t,std::string)> callback)91 void InitSendReportCallBack(std::function<void(int32_t, int32_t, std::string)> callback)
92 {
93 return;
94 }
95
NotificationLoadUtils(const std::string & path)96 NotificationLoadUtils::NotificationLoadUtils(const std::string& path) : path_(path)
97 {
98 g_notificationProxyValid = true;
99 return;
100 }
101
~NotificationLoadUtils()102 NotificationLoadUtils::~NotificationLoadUtils()
103 {
104 g_notificationProxyValid = false;
105 if (proxyHandle_ == nullptr) {
106 return;
107 }
108 int result = dlclose(proxyHandle_);
109 ANS_LOGI("Release symbol %{public}d, name: %{public}s", result, path_.c_str());
110 proxyHandle_ = nullptr;
111 }
112
GetProxyFunc(const std::string & func)113 void* NotificationLoadUtils::GetProxyFunc(const std::string& func)
114 {
115 if (func == "InitLocalDevice") {
116 return (void*)&InitLocalDevice;
117 }
118 if (func == "InitSendReportCallBack") {
119 return (void*)&InitSendReportCallBack;
120 }
121 if (func == "InitHACallBack") {
122 return (void*)&InitHACallBack;
123 }
124 if (func == "ReleaseLocalDevice") {
125 return (void*)&ReleaseLocalDevice;
126 }
127 if (func == "AddDevice") {
128 return (void*)&AddDevice;
129 }
130 if (func == "ReleaseDevice") {
131 return (void*)&ReleaseDevice;
132 }
133 if (func == "RefreshDevice") {
134 return (void*)&RefreshDevice;
135 }
136 if (func == "DeviceStatusChange") {
137 return (void*)&DeviceStatusChange;
138 }
139 return nullptr;
140 }
141
IsValid()142 bool NotificationLoadUtils::IsValid()
143 {
144 return g_notificationProxyValid;
145 }
146
147 }
148 }
149