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 #include <set>
16 #include <map>
17 #include <cstring>
18 #include <string>
19 #include <thread>
20 #include "securec.h"
21 #include "refbase.h"
22 #include "scan_callback.h"
23 #include "scan_manager_client.h"
24 #include "scan_constant.h"
25 #include "scan_log.h"
26 #include "scan_util.h"
27 #include "scanner_info.h"
28 #include "scan_option_value.h"
29 #include "ohscan.h"
30
31 using namespace OHOS::Scan;
32
33 struct ValueMap {
34 uint32_t valueType;
35 int32_t optionIndex;
36 std::set<std::string> numList;
37 std::set<std::string> strList;
38 };
39
40 struct ScanParaTable {
41 std::vector<std::string> titBuff;
42 std::vector<std::string> desBuff;
43 std::vector<std::string> rangesBuff;
44 int32_t lengthBuff;
45 };
46
47 static constexpr int32_t SCAN_INT_TYPE = 1;
48 static constexpr int32_t SCAN_STRING_TYPE = 3;
49 static constexpr int32_t SCAN_NUM_LIST = 2;
50 static constexpr int32_t SCAN_STRING_LIST = 3;
51 static std::map<std::string, std::map<int, ValueMap>> g_valueMap;
52 static std::map<std::string, Scan_ScannerOptions* > g_scanParaTables;
53 static bool g_isListening = false;
54 static const char* GET_SCANNER_DEVICE_LIST = "GET_SCANNER_DEVICE_LIST";
55 static Scan_ScannerDiscoveryCallback g_discoverCallback = nullptr;
56
57
FreeDeviceListMemory(Scan_ScannerDevice ** devices,int32_t deviceCount)58 static inline void FreeDeviceListMemory(Scan_ScannerDevice** devices, int32_t deviceCount)
59 {
60 for (int32_t i = 0; i < deviceCount; i++) {
61 DELETE_AND_NULLIFY(devices[i])
62 }
63 DELETE_ARRAY_AND_NULLIFY(devices)
64 }
65
__anona93dad690102(std::vector<ScanDeviceInfo> &infos) 66 auto callbackFunction = [](std::vector<ScanDeviceInfo> &infos) {
67 int32_t deviceCount = infos.size();
68 SCAN_HILOGI("deviceCount : [%{public}d]", deviceCount);
69 if (deviceCount == 0) {
70 SCAN_HILOGE("not found");
71 g_discoverCallback(nullptr, 0);
72 return;
73 }
74 Scan_ScannerDevice** devices = new (std::nothrow) Scan_ScannerDevice* [deviceCount];
75 if (devices == nullptr) {
76 SCAN_HILOGE("devices is a nullptr");
77 g_discoverCallback(nullptr, 0);
78 }
79 int32_t devicesMemSize = deviceCount * sizeof(Scan_ScannerDevice*);
80 if (memset_s(devices, devicesMemSize, 0, devicesMemSize) != 0) {
81 SCAN_HILOGW("memset_s fail");
82 FreeDeviceListMemory(devices, 0);
83 g_discoverCallback(nullptr, 0);
84 return;
85 }
86 for (int i = 0; i < deviceCount; i++) {
87 Scan_ScannerDevice* device = new (std::nothrow) Scan_ScannerDevice();
88 if (device == nullptr) {
89 SCAN_HILOGE("devices is a nullptr");
90 deviceCount = i;
91 break;
92 }
93 if (memset_s(device, sizeof(Scan_ScannerDevice), 0, sizeof(Scan_ScannerDevice)) != 0) {
94 SCAN_HILOGW("memset_s fail");
95 deviceCount = i;
96 break;
97 }
98 device->scannerId = infos[i].GetDeviceId().c_str();
99 device->manufacturer = infos[i].GetManufacturer().c_str();
100 device->model = infos[i].GetModel().c_str();
101 device->serialNumber = infos[i].GetSerialNumber().c_str();
102 device->discoverMode = infos[i].GetDiscoverMode().c_str();
103 devices[i] = device;
104 }
105 g_discoverCallback(devices, deviceCount);
106 FreeDeviceListMemory(devices, deviceCount);
107 };
108
109 namespace {
GetScanParaDesc(const std::string & deviceId,ScanOptionValue & value)110 int32_t GetScanParaDesc(const std::string &deviceId, ScanOptionValue &value)
111 {
112 auto client = ScanManagerClient::GetInstance();
113 ScanOptionDescriptor desc;
114 int32_t ret = client->GetScanOptionDesc(deviceId, 0, desc);
115 uint32_t optionType = desc.GetOptionType();
116 int32_t optionSize = desc.GetOptionSize();
117 value.SetScanOptionValueType(static_cast<ScanOptionValueType>(optionType));
118 value.SetValueSize(optionSize);
119 int32_t info = 0;
120 ret = client->OpScanOptionValue(deviceId, 0, SCAN_ACTION_GET_VALUE, value, info);
121 return ret;
122 }
123
GetScanParaValues(const std::string & deviceId,ScanOptionValue & value,ScanParaTable & paraTable)124 int32_t GetScanParaValues(const std::string &deviceId, ScanOptionValue &value, ScanParaTable ¶Table)
125 {
126 std::set<uint32_t> dataType = {SCAN_INT_TYPE, SCAN_STRING_TYPE};
127 int32_t lengthBuff = 0;
128 for (int i = 1 ; i < value.GetNumValue(); i++) {
129 ScanOptionDescriptor desc;
130 auto client = ScanManagerClient::GetInstance();
131 int32_t ret = client->GetScanOptionDesc(deviceId, i, desc);
132 if (ret != SCAN_ERROR_NONE) {
133 SCAN_HILOGE("Failed to get scanner parameters.");
134 return ret;
135 }
136 if (!dataType.count(desc.GetOptionType())) {
137 continue;
138 }
139 if (desc.GetOptionConstraintType() == SCAN_NUM_LIST) {
140 std::string tmp;
141 std::vector<std::int32_t> optionConstraintNumber;
142 desc.GetOptionConstraintNumber(optionConstraintNumber);
143 for (auto t : optionConstraintNumber) {
144 std::string numStr = std::to_string(t);
145 tmp.append(numStr).append(",");
146 g_valueMap[deviceId][lengthBuff].numList.insert(numStr);
147 g_valueMap[deviceId][lengthBuff].valueType = SCAN_INT_TYPE;
148 }
149 tmp.pop_back();
150 paraTable.rangesBuff.emplace_back(tmp);
151 } else if (desc.GetOptionConstraintType() == SCAN_STRING_LIST) {
152 std::string tmp;
153 std::vector<std::string> optionConstraintString;
154 desc.GetOptionConstraintString(optionConstraintString);
155 for (auto t : optionConstraintString) {
156 tmp.append(t).append(",");
157 g_valueMap[deviceId][lengthBuff].strList.insert(t);
158 g_valueMap[deviceId][lengthBuff].valueType = SCAN_STRING_TYPE;
159 }
160 tmp.pop_back();
161 paraTable.rangesBuff.emplace_back(tmp);
162 } else {
163 continue;
164 }
165 paraTable.titBuff.emplace_back(desc.GetOptionTitle());
166 paraTable.desBuff.emplace_back(desc.GetOptionDesc());
167 g_valueMap[deviceId][lengthBuff].optionIndex = i;
168 lengthBuff++;
169 }
170 paraTable.lengthBuff = lengthBuff;
171 return SCAN_ERROR_NONE;
172 }
173
FreeScannerOptionsMemory(Scan_ScannerOptions * scannerOptions)174 void FreeScannerOptionsMemory(Scan_ScannerOptions* scannerOptions)
175 {
176 if (scannerOptions == nullptr) {
177 SCAN_HILOGW("scannerOptions is a nullptr.");
178 return;
179 }
180
181 for (int i = 0; i < scannerOptions->optionCount; i++) {
182 DELETE_AND_NULLIFY(scannerOptions->titles[i])
183 }
184 DELETE_ARRAY_AND_NULLIFY(scannerOptions->titles)
185
186 for (int i = 0; i < scannerOptions->optionCount; i++) {
187 DELETE_AND_NULLIFY(scannerOptions->descriptions[i])
188 }
189 DELETE_ARRAY_AND_NULLIFY(scannerOptions->descriptions)
190
191 for (int i = 0; i < scannerOptions->optionCount; i++) {
192 DELETE_AND_NULLIFY(scannerOptions->ranges[i])
193 }
194 DELETE_ARRAY_AND_NULLIFY(scannerOptions->ranges)
195 DELETE_AND_NULLIFY(scannerOptions)
196 }
197
CreateScannerOptions(int32_t & optionCount)198 Scan_ScannerOptions* CreateScannerOptions(int32_t &optionCount)
199 {
200 Scan_ScannerOptions* scannerOptions = new (std::nothrow) Scan_ScannerOptions();
201 if (scannerOptions == nullptr) {
202 SCAN_HILOGE("scannerOptions is a nullptr");
203 return nullptr;
204 }
205 int32_t scannerOptionsMemSize = sizeof(Scan_ScannerOptions);
206 if (memset_s(scannerOptions, scannerOptionsMemSize, 0, scannerOptionsMemSize) != 0) {
207 SCAN_HILOGW("memset_s fail");
208 FreeScannerOptionsMemory(scannerOptions);
209 return nullptr;
210 }
211 scannerOptions->titles = new (std::nothrow) char* [optionCount];
212 scannerOptions->descriptions = new (std::nothrow) char* [optionCount];
213 scannerOptions->ranges = new (std::nothrow) char* [optionCount];
214 scannerOptions->optionCount = optionCount;
215 if (scannerOptions->titles == nullptr || scannerOptions->descriptions == nullptr ||
216 scannerOptions->ranges == nullptr) {
217 FreeScannerOptionsMemory(scannerOptions);
218 return nullptr;
219 }
220 int32_t stringMemSize = optionCount * sizeof(char**);
221 if (memset_s(scannerOptions->titles, stringMemSize, 0, stringMemSize) != 0 ||
222 memset_s(scannerOptions->descriptions, stringMemSize, 0, stringMemSize) != 0 ||
223 memset_s(scannerOptions->ranges, stringMemSize, 0, stringMemSize) != 0) {
224 SCAN_HILOGW("memset_s fail");
225 FreeScannerOptionsMemory(scannerOptions);
226 return nullptr;
227 }
228 return scannerOptions;
229 }
230
CopySingleBuf(char * destBuf,const char * srcBuf,size_t bufferSize)231 bool CopySingleBuf(char* destBuf, const char* srcBuf, size_t bufferSize)
232 {
233 if (destBuf == nullptr || srcBuf == nullptr) {
234 SCAN_HILOGW("CopySingleBuf new fail");
235 return false;
236 }
237 if (memset_s(destBuf, bufferSize, 0, bufferSize) != 0) {
238 SCAN_HILOGE("CopySingleBuf memset_s fail");
239 return false;
240 }
241 if (strncpy_s(destBuf, bufferSize, srcBuf, bufferSize) != 0) {
242 SCAN_HILOGE("CopySingleBuf strncpy_s fail");
243 return false;
244 }
245
246 return true;
247 }
248
MemSetScannerOptions(Scan_ScannerOptions * scannerOptions,int32_t & optionCount,ScanParaTable & paraTable)249 bool MemSetScannerOptions(Scan_ScannerOptions* scannerOptions, int32_t &optionCount, ScanParaTable ¶Table)
250 {
251 for (int i = 0; i < optionCount; i++) {
252 auto bufferSize = paraTable.titBuff[i].length() + 1;
253 char* titBuff = new (std::nothrow) char[bufferSize];
254 if (!CopySingleBuf(titBuff, paraTable.titBuff[i].c_str(), bufferSize)) {
255 if (titBuff != nullptr) {
256 delete[] titBuff;
257 }
258 return false;
259 }
260 scannerOptions->titles[i] = titBuff;
261
262 bufferSize = paraTable.desBuff[i].length() + 1;
263 char* desBuff = new (std::nothrow) char[bufferSize];
264 if (!CopySingleBuf(desBuff, paraTable.desBuff[i].c_str(), bufferSize)) {
265 if (desBuff != nullptr) {
266 delete[] desBuff;
267 }
268 return false;
269 }
270 scannerOptions->descriptions[i] = desBuff;
271
272 bufferSize = paraTable.rangesBuff[i].length() + 1;
273 char* rangesBuff = new (std::nothrow) char[bufferSize];
274 if (!CopySingleBuf(rangesBuff, paraTable.rangesBuff[i].c_str(), bufferSize)) {
275 if (rangesBuff != nullptr) {
276 delete[] rangesBuff;
277 }
278 return false;
279 }
280 scannerOptions->ranges[i] = rangesBuff;
281 }
282 return true;
283 }
284
GetScanParaValue(ScanParaTable & paraTable)285 Scan_ScannerOptions* GetScanParaValue(ScanParaTable ¶Table)
286 {
287 int32_t optionCount = paraTable.lengthBuff;
288 if (optionCount <= 0) {
289 SCAN_HILOGE("optionCount <= 0");
290 return nullptr;
291 }
292 Scan_ScannerOptions* scannerOptions = CreateScannerOptions(optionCount);
293 if (scannerOptions == nullptr) {
294 SCAN_HILOGE("scannerOptions is a nullptr");
295 return nullptr;
296 }
297 if (!MemSetScannerOptions(scannerOptions, optionCount, paraTable)) {
298 SCAN_HILOGE("MemSetScannerOptions error");
299 FreeScannerOptionsMemory(scannerOptions);
300 return nullptr;
301 }
302 return scannerOptions;
303 }
304
GetScanOptionValue(const uint32_t & valueType,const ValueMap & valueMap,const char * value,ScanOptionValue & scanOptionValue)305 int32_t GetScanOptionValue(const uint32_t& valueType, const ValueMap& valueMap,
306 const char* value, ScanOptionValue& scanOptionValue)
307 {
308 std::string strvalue = std::string(value);
309 if (valueType == SCAN_INT_TYPE) {
310 if (!valueMap.numList.count(strvalue)) {
311 SCAN_HILOGE("not exit this value: %{public}s", strvalue.c_str());
312 return SCAN_ERROR_INVALID_PARAMETER;
313 }
314 int32_t intValue = 0;
315 if (!ScanUtil::ConvertToInt(strvalue, intValue)) {
316 SCAN_HILOGE("strvalue : %{public}s can not parse to number.", strvalue.c_str());
317 return SCAN_ERROR_GENERIC_FAILURE;
318 }
319 scanOptionValue.SetNumValue(intValue);
320 scanOptionValue.SetScanOptionValueType(SCAN_VALUE_NUM);
321 } else if (valueType == SCAN_STRING_TYPE) {
322 if (!valueMap.strList.count(strvalue)) {
323 SCAN_HILOGE("not exit this value: %{public}s", strvalue.c_str());
324 return SCAN_ERROR_INVALID_PARAMETER;
325 }
326 scanOptionValue.SetStrValue(strvalue);
327 scanOptionValue.SetScanOptionValueType(SCAN_VALUE_STR);
328 } else {
329 SCAN_HILOGE("not exist this type: %{public}u", valueType);
330 return SCAN_ERROR_GENERIC_FAILURE;
331 }
332 return SCAN_ERROR_NONE;
333 }
334
335 }
336
OH_Scan_Init()337 int32_t OH_Scan_Init()
338 {
339 SCAN_HILOGI("Enter OH_Scan_Init");
340 auto client = ScanManagerClient::GetInstance();
341 int32_t scanVersion = 0;
342 int32_t ret = client->InitScan(scanVersion);
343 if (ret != SCAN_ERROR_NONE) {
344 SCAN_HILOGE("InitScan failed, ErrorCode: [%{public}d]", ret);
345 return ret;
346 } else {
347 SCAN_HILOGI("InitScan successfully");
348 return SCAN_ERROR_NONE;
349 }
350 }
351
OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback)352 int32_t OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback)
353 {
354 g_discoverCallback = callback;
355 auto client = ScanManagerClient::GetInstance();
356 int32_t ret = SCAN_ERROR_NONE;
357 if (!g_isListening) {
358 OHOS::sptr<IScanCallback> call = new (std::nothrow) ScanCallback(callbackFunction);
359 if (call == nullptr) {
360 SCAN_HILOGE("call is null");
361 return SCAN_ERROR_GENERIC_FAILURE;
362 }
363 ret = client->On("", std::string(GET_SCANNER_DEVICE_LIST), call);
364 if (ret != SCAN_ERROR_NONE) {
365 SCAN_HILOGE("Failed to register event");
366 return ret;
367 }
368 g_isListening = true;
369 }
370 ret = client->GetScannerList();
371 if (ret != SCAN_ERROR_NONE) {
372 SCAN_HILOGE("Failed to GetScannerList");
373 return ret;
374 }
375 return SCAN_ERROR_NONE;
376 }
377
OH_Scan_OpenScanner(const char * scannerId)378 int32_t OH_Scan_OpenScanner(const char* scannerId)
379 {
380 if (scannerId == nullptr) {
381 SCAN_HILOGE("Invalid parameter.");
382 return SCAN_ERROR_INVALID_PARAMETER;
383 }
384 auto client = ScanManagerClient::GetInstance();
385 int32_t ret = client->OpenScanner(std::string(scannerId));
386 if (ret != SCAN_ERROR_NONE) {
387 SCAN_HILOGE("OpenScanner failed, ErrorCode: [%{public}d]", ret);
388 return ret;
389 } else {
390 SCAN_HILOGI("OpenScanner successfully");
391 return SCAN_ERROR_NONE;
392 }
393 }
394
OH_Scan_CloseScanner(const char * scannerId)395 int32_t OH_Scan_CloseScanner(const char* scannerId)
396 {
397 if (scannerId == nullptr) {
398 SCAN_HILOGE("Invalid parameter.");
399 return SCAN_ERROR_INVALID_PARAMETER;
400 }
401 auto client = ScanManagerClient::GetInstance();
402 int32_t ret = client->CloseScanner(std::string(scannerId));
403 if (ret != SCAN_ERROR_NONE) {
404 SCAN_HILOGE("CloseScanner failed, ErrorCode: [%{public}d]", ret);
405 return ret;
406 } else {
407 SCAN_HILOGI("CloseScanner successfully");
408 return SCAN_ERROR_NONE;
409 }
410 }
411
OH_Scan_GetScannerParameter(const char * scannerId,int32_t * errorCode)412 Scan_ScannerOptions* OH_Scan_GetScannerParameter(const char* scannerId, int32_t* errorCode)
413 {
414 if (scannerId == nullptr || errorCode == nullptr) {
415 SCAN_HILOGE("Invalid parameter.");
416 return nullptr;
417 }
418 std::string deviceId = std::string(scannerId);
419 if (g_scanParaTables.find(deviceId) != g_scanParaTables.end()) {
420 SCAN_HILOGW("Device parameters have been obtained.");
421 *errorCode = SCAN_ERROR_NONE;
422 return g_scanParaTables[deviceId];
423 }
424 int32_t status = SCAN_ERROR_NONE;
425 ScanOptionValue value;
426 status = GetScanParaDesc(deviceId, value);
427 if (status != SCAN_ERROR_NONE) {
428 SCAN_HILOGE("Failed to get scanner ScanOptionValue value.");
429 *errorCode = status;
430 return nullptr;
431 }
432 ScanParaTable paraTable;
433 status = GetScanParaValues(deviceId, value, paraTable);
434 if (status != SCAN_ERROR_NONE) {
435 SCAN_HILOGE("Failed to get scanner ScanParaTable paraTable.");
436 *errorCode = status;
437 return nullptr;
438 }
439
440 Scan_ScannerOptions* scaParaOptions = GetScanParaValue(paraTable);
441 if (scaParaOptions == nullptr) {
442 *errorCode = SCAN_ERROR_GENERIC_FAILURE;
443 return nullptr;
444 }
445 g_scanParaTables[scannerId] = scaParaOptions;
446 *errorCode = SCAN_ERROR_NONE;
447 return scaParaOptions;
448 }
449
OH_Scan_SetScannerParameter(const char * scannerId,const int32_t option,const char * value)450 int32_t OH_Scan_SetScannerParameter(const char* scannerId, const int32_t option, const char* value)
451 {
452 if (scannerId == nullptr || value == nullptr) {
453 SCAN_HILOGE("Invalid parameter.");
454 return SCAN_ERROR_INVALID_PARAMETER;
455 }
456 auto client = ScanManagerClient::GetInstance();
457 if (g_valueMap.find(scannerId) == g_valueMap.end() ||
458 g_valueMap[scannerId].find(option) == g_valueMap[scannerId].end()) {
459 SCAN_HILOGE("not exit this option: [%{public}d]", option);
460 return SCAN_ERROR_INVALID_PARAMETER;
461 }
462 auto t = g_valueMap[scannerId].find(option);
463 ScanOptionValue scanOptionValue;
464 uint32_t valueType = g_valueMap[scannerId][option].valueType;
465 int32_t ret = GetScanOptionValue(valueType, t->second, value, scanOptionValue);
466 if (ret != SCAN_ERROR_NONE) {
467 SCAN_HILOGE("GetScanOptionValue failed, ErxrorCode: [%{public}d]", ret);
468 return ret;
469 }
470
471 int32_t optionIndex = t->second.optionIndex;
472 int32_t info = 0;
473 ret = client->OpScanOptionValue(std::string(scannerId),
474 optionIndex, SCAN_ACTION_SET_VALUE, scanOptionValue, info);
475 if (ret != SCAN_ERROR_NONE) {
476 SCAN_HILOGE("SetScannerParameter failed, ErxrorCode: [%{public}d]", ret);
477 return ret;
478 } else {
479 SCAN_HILOGI("SetScannerParameter successfully");
480 return SCAN_ERROR_NONE;
481 }
482 return SCAN_ERROR_NONE;
483 }
484
OH_Scan_StartScan(const char * scannerId,bool batchMode)485 int32_t OH_Scan_StartScan(const char* scannerId, bool batchMode)
486 {
487 if (scannerId == nullptr) {
488 SCAN_HILOGE("Invalid parameter.");
489 return SCAN_ERROR_INVALID_PARAMETER;
490 }
491 auto client = ScanManagerClient::GetInstance();
492 int32_t ret = client->StartScan(std::string(scannerId), batchMode);
493 if (ret != SCAN_ERROR_NONE) {
494 SCAN_HILOGE("StartScan failed, ErxrorCode: [%{public}d]", ret);
495 return ret;
496 } else {
497 SCAN_HILOGI("StartScan successfully");
498 return SCAN_ERROR_NONE;
499 }
500 }
501
OH_Scan_CancelScan(const char * scannerId)502 int32_t OH_Scan_CancelScan(const char* scannerId)
503 {
504 if (scannerId == nullptr) {
505 SCAN_HILOGE("Invalid parameter.");
506 return SCAN_ERROR_INVALID_PARAMETER;
507 }
508 auto client = ScanManagerClient::GetInstance();
509 int32_t ret = client->CancelScan(std::string(scannerId));
510 if (ret != SCAN_ERROR_NONE) {
511 SCAN_HILOGE("CancelScan failed, ErxrorCode: [%{public}d]", ret);
512 return ret;
513 } else {
514 SCAN_HILOGI("CancelScan successfully");
515 return SCAN_ERROR_NONE;
516 }
517 }
518
OH_Scan_GetPictureScanProgress(const char * scannerId,Scan_PictureScanProgress * prog)519 int32_t OH_Scan_GetPictureScanProgress(const char* scannerId, Scan_PictureScanProgress* prog)
520 {
521 if (prog == nullptr) {
522 SCAN_HILOGE("Invalid parameter.");
523 return SCAN_ERROR_INVALID_PARAMETER;
524 }
525 ScanProgress scanProg;
526 auto client = ScanManagerClient::GetInstance();
527 int32_t ret = client->GetScanProgress(std::string(scannerId), scanProg);
528 if (ret != SCAN_ERROR_NONE) {
529 SCAN_HILOGE("GetScanProgress failed, ErrorCode: [%{public}d]", ret);
530 return ret;
531 } else {
532 prog->progress = scanProg.GetScanProgress();
533 prog->fd = scanProg.GetScanPictureFd();
534 prog->isFinal = scanProg.GetIsFinal();
535 SCAN_HILOGI("GetScanProgress successfully");
536 return SCAN_ERROR_NONE;
537 }
538 }
539
OH_Scan_Exit()540 int32_t OH_Scan_Exit()
541 {
542 auto client = ScanManagerClient::GetInstance();
543 int32_t ret = client->ExitScan();
544 if (ret != SCAN_ERROR_NONE) {
545 SCAN_HILOGE("ExitScan failed, ErrorCode: [%{public}d]", ret);
546 return ret;
547 }
548 for (auto table : g_scanParaTables) {
549 FreeScannerOptionsMemory(table.second);
550 }
551 g_scanParaTables.clear();
552 if (g_isListening) {
553 client->Off("", std::string(GET_SCANNER_DEVICE_LIST));
554 }
555 SCAN_HILOGI("ExitScan successfully");
556 return SCAN_ERROR_NONE;
557 }