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
__anona840ee710102(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 if (scannerOptions->titles != nullptr) {
182 for (int i = 0; i < scannerOptions->optionCount; i++) {
183 DELETE_AND_NULLIFY(scannerOptions->titles[i])
184 }
185 DELETE_ARRAY_AND_NULLIFY(scannerOptions->titles)
186 }
187
188 if (scannerOptions->descriptions != nullptr) {
189 for (int i = 0; i < scannerOptions->optionCount; i++) {
190 DELETE_AND_NULLIFY(scannerOptions->descriptions[i])
191 }
192 DELETE_ARRAY_AND_NULLIFY(scannerOptions->descriptions)
193 }
194
195 if (scannerOptions->ranges != nullptr) {
196 for (int i = 0; i < scannerOptions->optionCount; i++) {
197 DELETE_AND_NULLIFY(scannerOptions->ranges[i])
198 }
199 DELETE_ARRAY_AND_NULLIFY(scannerOptions->ranges)
200 }
201
202 DELETE_AND_NULLIFY(scannerOptions)
203 }
204
CreateScannerOptions(int32_t & optionCount)205 Scan_ScannerOptions* CreateScannerOptions(int32_t &optionCount)
206 {
207 Scan_ScannerOptions* scannerOptions = new (std::nothrow) Scan_ScannerOptions();
208 if (scannerOptions == nullptr) {
209 SCAN_HILOGE("scannerOptions is a nullptr");
210 return nullptr;
211 }
212 int32_t scannerOptionsMemSize = sizeof(Scan_ScannerOptions);
213 if (memset_s(scannerOptions, scannerOptionsMemSize, 0, scannerOptionsMemSize) != 0) {
214 SCAN_HILOGW("memset_s fail");
215 FreeScannerOptionsMemory(scannerOptions);
216 return nullptr;
217 }
218 scannerOptions->titles = new (std::nothrow) char* [optionCount];
219 scannerOptions->descriptions = new (std::nothrow) char* [optionCount];
220 scannerOptions->ranges = new (std::nothrow) char* [optionCount];
221 scannerOptions->optionCount = optionCount;
222 if (scannerOptions->titles == nullptr || scannerOptions->descriptions == nullptr ||
223 scannerOptions->ranges == nullptr) {
224 FreeScannerOptionsMemory(scannerOptions);
225 return nullptr;
226 }
227 int32_t stringMemSize = optionCount * sizeof(char**);
228 if (memset_s(scannerOptions->titles, stringMemSize, 0, stringMemSize) != 0 ||
229 memset_s(scannerOptions->descriptions, stringMemSize, 0, stringMemSize) != 0 ||
230 memset_s(scannerOptions->ranges, stringMemSize, 0, stringMemSize) != 0) {
231 SCAN_HILOGW("memset_s fail");
232 FreeScannerOptionsMemory(scannerOptions);
233 return nullptr;
234 }
235 return scannerOptions;
236 }
237
CopySingleBuf(char * destBuf,const char * srcBuf,size_t bufferSize)238 bool CopySingleBuf(char* destBuf, const char* srcBuf, size_t bufferSize)
239 {
240 if (destBuf == nullptr || srcBuf == nullptr) {
241 SCAN_HILOGW("CopySingleBuf new fail");
242 return false;
243 }
244 if (memset_s(destBuf, bufferSize, 0, bufferSize) != 0) {
245 SCAN_HILOGE("CopySingleBuf memset_s fail");
246 return false;
247 }
248 if (strncpy_s(destBuf, bufferSize, srcBuf, bufferSize) != 0) {
249 SCAN_HILOGE("CopySingleBuf strncpy_s fail");
250 return false;
251 }
252
253 return true;
254 }
255
MemSetScannerOptions(Scan_ScannerOptions * scannerOptions,int32_t & optionCount,ScanParaTable & paraTable)256 bool MemSetScannerOptions(Scan_ScannerOptions* scannerOptions, int32_t &optionCount, ScanParaTable ¶Table)
257 {
258 for (int i = 0; i < optionCount; i++) {
259 auto bufferSize = paraTable.titBuff[i].length() + 1;
260 char* titBuff = new (std::nothrow) char[bufferSize];
261 if (!CopySingleBuf(titBuff, paraTable.titBuff[i].c_str(), bufferSize)) {
262 if (titBuff != nullptr) {
263 delete[] titBuff;
264 }
265 return false;
266 }
267 scannerOptions->titles[i] = titBuff;
268
269 bufferSize = paraTable.desBuff[i].length() + 1;
270 char* desBuff = new (std::nothrow) char[bufferSize];
271 if (!CopySingleBuf(desBuff, paraTable.desBuff[i].c_str(), bufferSize)) {
272 if (desBuff != nullptr) {
273 delete[] desBuff;
274 }
275 return false;
276 }
277 scannerOptions->descriptions[i] = desBuff;
278
279 bufferSize = paraTable.rangesBuff[i].length() + 1;
280 char* rangesBuff = new (std::nothrow) char[bufferSize];
281 if (!CopySingleBuf(rangesBuff, paraTable.rangesBuff[i].c_str(), bufferSize)) {
282 if (rangesBuff != nullptr) {
283 delete[] rangesBuff;
284 }
285 return false;
286 }
287 scannerOptions->ranges[i] = rangesBuff;
288 }
289 return true;
290 }
291
GetScanParaValue(ScanParaTable & paraTable)292 Scan_ScannerOptions* GetScanParaValue(ScanParaTable ¶Table)
293 {
294 int32_t optionCount = paraTable.lengthBuff;
295 if (optionCount <= 0) {
296 SCAN_HILOGE("optionCount <= 0");
297 return nullptr;
298 }
299 Scan_ScannerOptions* scannerOptions = CreateScannerOptions(optionCount);
300 if (scannerOptions == nullptr) {
301 SCAN_HILOGE("scannerOptions is a nullptr");
302 return nullptr;
303 }
304 if (!MemSetScannerOptions(scannerOptions, optionCount, paraTable)) {
305 SCAN_HILOGE("MemSetScannerOptions error");
306 FreeScannerOptionsMemory(scannerOptions);
307 return nullptr;
308 }
309 return scannerOptions;
310 }
311
GetScanOptionValue(const uint32_t & valueType,const ValueMap & valueMap,const char * value,ScanOptionValue & scanOptionValue)312 int32_t GetScanOptionValue(const uint32_t& valueType, const ValueMap& valueMap,
313 const char* value, ScanOptionValue& scanOptionValue)
314 {
315 std::string strvalue = std::string(value);
316 if (valueType == SCAN_INT_TYPE) {
317 if (!valueMap.numList.count(strvalue)) {
318 SCAN_HILOGE("not exit this value: %{public}s", strvalue.c_str());
319 return SCAN_ERROR_INVALID_PARAMETER;
320 }
321 int32_t intValue = 0;
322 if (!ScanUtil::ConvertToInt(strvalue, intValue)) {
323 SCAN_HILOGE("strvalue : %{public}s can not parse to number.", strvalue.c_str());
324 return SCAN_ERROR_GENERIC_FAILURE;
325 }
326 scanOptionValue.SetNumValue(intValue);
327 scanOptionValue.SetScanOptionValueType(SCAN_VALUE_NUM);
328 } else if (valueType == SCAN_STRING_TYPE) {
329 if (!valueMap.strList.count(strvalue)) {
330 SCAN_HILOGE("not exit this value: %{public}s", strvalue.c_str());
331 return SCAN_ERROR_INVALID_PARAMETER;
332 }
333 scanOptionValue.SetStrValue(strvalue);
334 scanOptionValue.SetScanOptionValueType(SCAN_VALUE_STR);
335 } else {
336 SCAN_HILOGE("not exist this type: %{public}u", valueType);
337 return SCAN_ERROR_GENERIC_FAILURE;
338 }
339 return SCAN_ERROR_NONE;
340 }
341
342 }
343
OH_Scan_Init()344 int32_t OH_Scan_Init()
345 {
346 SCAN_HILOGI("Enter OH_Scan_Init");
347 auto client = ScanManagerClient::GetInstance();
348 int32_t scanVersion = 0;
349 int32_t ret = client->InitScan(scanVersion);
350 if (ret != SCAN_ERROR_NONE) {
351 SCAN_HILOGE("InitScan failed, ErrorCode: [%{public}d]", ret);
352 return ret;
353 } else {
354 SCAN_HILOGI("InitScan successfully");
355 return SCAN_ERROR_NONE;
356 }
357 }
358
OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback)359 int32_t OH_Scan_StartScannerDiscovery(Scan_ScannerDiscoveryCallback callback)
360 {
361 g_discoverCallback = callback;
362 auto client = ScanManagerClient::GetInstance();
363 int32_t ret = SCAN_ERROR_NONE;
364 if (!g_isListening) {
365 OHOS::sptr<IScanCallback> call = new (std::nothrow) ScanCallback(callbackFunction);
366 if (call == nullptr) {
367 SCAN_HILOGE("call is null");
368 return SCAN_ERROR_GENERIC_FAILURE;
369 }
370 ret = client->On("", std::string(GET_SCANNER_DEVICE_LIST), call);
371 if (ret != SCAN_ERROR_NONE) {
372 SCAN_HILOGE("Failed to register event");
373 return ret;
374 }
375 g_isListening = true;
376 }
377 ret = client->GetScannerList();
378 if (ret != SCAN_ERROR_NONE) {
379 SCAN_HILOGE("Failed to GetScannerList");
380 return ret;
381 }
382 return SCAN_ERROR_NONE;
383 }
384
OH_Scan_OpenScanner(const char * scannerId)385 int32_t OH_Scan_OpenScanner(const char* scannerId)
386 {
387 if (scannerId == nullptr) {
388 SCAN_HILOGE("Invalid parameter.");
389 return SCAN_ERROR_INVALID_PARAMETER;
390 }
391 auto client = ScanManagerClient::GetInstance();
392 int32_t ret = client->OpenScanner(std::string(scannerId));
393 if (ret != SCAN_ERROR_NONE) {
394 SCAN_HILOGE("OpenScanner failed, ErrorCode: [%{public}d]", ret);
395 return ret;
396 } else {
397 SCAN_HILOGI("OpenScanner successfully");
398 return SCAN_ERROR_NONE;
399 }
400 }
401
OH_Scan_CloseScanner(const char * scannerId)402 int32_t OH_Scan_CloseScanner(const char* scannerId)
403 {
404 if (scannerId == nullptr) {
405 SCAN_HILOGE("Invalid parameter.");
406 return SCAN_ERROR_INVALID_PARAMETER;
407 }
408 auto client = ScanManagerClient::GetInstance();
409 int32_t ret = client->CloseScanner(std::string(scannerId));
410 if (ret != SCAN_ERROR_NONE) {
411 SCAN_HILOGE("CloseScanner failed, ErrorCode: [%{public}d]", ret);
412 return ret;
413 } else {
414 SCAN_HILOGI("CloseScanner successfully");
415 return SCAN_ERROR_NONE;
416 }
417 }
418
OH_Scan_GetScannerParameter(const char * scannerId,int32_t * errorCode)419 Scan_ScannerOptions* OH_Scan_GetScannerParameter(const char* scannerId, int32_t* errorCode)
420 {
421 if (scannerId == nullptr || errorCode == nullptr) {
422 SCAN_HILOGE("Invalid parameter.");
423 return nullptr;
424 }
425 std::string deviceId = std::string(scannerId);
426 if (g_scanParaTables.find(deviceId) != g_scanParaTables.end()) {
427 SCAN_HILOGW("Device parameters have been obtained.");
428 *errorCode = SCAN_ERROR_NONE;
429 return g_scanParaTables[deviceId];
430 }
431 int32_t status = SCAN_ERROR_NONE;
432 ScanOptionValue value;
433 status = GetScanParaDesc(deviceId, value);
434 if (status != SCAN_ERROR_NONE) {
435 SCAN_HILOGE("Failed to get scanner ScanOptionValue value.");
436 *errorCode = status;
437 return nullptr;
438 }
439 ScanParaTable paraTable;
440 status = GetScanParaValues(deviceId, value, paraTable);
441 if (status != SCAN_ERROR_NONE) {
442 SCAN_HILOGE("Failed to get scanner ScanParaTable paraTable.");
443 *errorCode = status;
444 return nullptr;
445 }
446
447 Scan_ScannerOptions* scaParaOptions = GetScanParaValue(paraTable);
448 if (scaParaOptions == nullptr) {
449 *errorCode = SCAN_ERROR_GENERIC_FAILURE;
450 return nullptr;
451 }
452 g_scanParaTables[scannerId] = scaParaOptions;
453 *errorCode = SCAN_ERROR_NONE;
454 return scaParaOptions;
455 }
456
OH_Scan_SetScannerParameter(const char * scannerId,const int32_t option,const char * value)457 int32_t OH_Scan_SetScannerParameter(const char* scannerId, const int32_t option, const char* value)
458 {
459 if (scannerId == nullptr || value == nullptr) {
460 SCAN_HILOGE("Invalid parameter.");
461 return SCAN_ERROR_INVALID_PARAMETER;
462 }
463 auto client = ScanManagerClient::GetInstance();
464 if (g_valueMap.find(scannerId) == g_valueMap.end() ||
465 g_valueMap[scannerId].find(option) == g_valueMap[scannerId].end()) {
466 SCAN_HILOGE("not exit this option: [%{public}d]", option);
467 return SCAN_ERROR_INVALID_PARAMETER;
468 }
469 auto t = g_valueMap[scannerId].find(option);
470 ScanOptionValue scanOptionValue;
471 uint32_t valueType = g_valueMap[scannerId][option].valueType;
472 int32_t ret = GetScanOptionValue(valueType, t->second, value, scanOptionValue);
473 if (ret != SCAN_ERROR_NONE) {
474 SCAN_HILOGE("GetScanOptionValue failed, ErxrorCode: [%{public}d]", ret);
475 return ret;
476 }
477
478 int32_t optionIndex = t->second.optionIndex;
479 int32_t info = 0;
480 ret = client->OpScanOptionValue(std::string(scannerId),
481 optionIndex, SCAN_ACTION_SET_VALUE, scanOptionValue, info);
482 if (ret != SCAN_ERROR_NONE) {
483 SCAN_HILOGE("SetScannerParameter failed, ErxrorCode: [%{public}d]", ret);
484 return ret;
485 } else {
486 SCAN_HILOGI("SetScannerParameter successfully");
487 return SCAN_ERROR_NONE;
488 }
489 return SCAN_ERROR_NONE;
490 }
491
OH_Scan_StartScan(const char * scannerId,bool batchMode)492 int32_t OH_Scan_StartScan(const char* scannerId, bool batchMode)
493 {
494 if (scannerId == nullptr) {
495 SCAN_HILOGE("Invalid parameter.");
496 return SCAN_ERROR_INVALID_PARAMETER;
497 }
498 auto client = ScanManagerClient::GetInstance();
499 int32_t ret = client->StartScan(std::string(scannerId), batchMode);
500 if (ret != SCAN_ERROR_NONE) {
501 SCAN_HILOGE("StartScan failed, ErxrorCode: [%{public}d]", ret);
502 return ret;
503 } else {
504 SCAN_HILOGI("StartScan successfully");
505 return SCAN_ERROR_NONE;
506 }
507 }
508
OH_Scan_CancelScan(const char * scannerId)509 int32_t OH_Scan_CancelScan(const char* scannerId)
510 {
511 if (scannerId == nullptr) {
512 SCAN_HILOGE("Invalid parameter.");
513 return SCAN_ERROR_INVALID_PARAMETER;
514 }
515 auto client = ScanManagerClient::GetInstance();
516 int32_t ret = client->CancelScan(std::string(scannerId));
517 if (ret != SCAN_ERROR_NONE) {
518 SCAN_HILOGE("CancelScan failed, ErxrorCode: [%{public}d]", ret);
519 return ret;
520 } else {
521 SCAN_HILOGI("CancelScan successfully");
522 return SCAN_ERROR_NONE;
523 }
524 }
525
OH_Scan_GetPictureScanProgress(const char * scannerId,Scan_PictureScanProgress * prog)526 int32_t OH_Scan_GetPictureScanProgress(const char* scannerId, Scan_PictureScanProgress* prog)
527 {
528 if (prog == nullptr) {
529 SCAN_HILOGE("Invalid parameter.");
530 return SCAN_ERROR_INVALID_PARAMETER;
531 }
532 ScanProgress scanProg;
533 auto client = ScanManagerClient::GetInstance();
534 int32_t ret = client->GetScanProgress(std::string(scannerId), scanProg);
535 if (ret != SCAN_ERROR_NONE) {
536 SCAN_HILOGE("GetScanProgress failed, ErrorCode: [%{public}d]", ret);
537 return ret;
538 } else {
539 prog->progress = scanProg.GetScanProgress();
540 prog->fd = scanProg.GetScanPictureFd();
541 prog->isFinal = scanProg.GetIsFinal();
542 SCAN_HILOGI("GetScanProgress successfully");
543 return SCAN_ERROR_NONE;
544 }
545 }
546
OH_Scan_Exit()547 int32_t OH_Scan_Exit()
548 {
549 auto client = ScanManagerClient::GetInstance();
550 int32_t ret = client->ExitScan();
551 if (ret != SCAN_ERROR_NONE) {
552 SCAN_HILOGE("ExitScan failed, ErrorCode: [%{public}d]", ret);
553 return ret;
554 }
555 for (auto table : g_scanParaTables) {
556 FreeScannerOptionsMemory(table.second);
557 }
558 g_scanParaTables.clear();
559 if (g_isListening) {
560 client->Off("", std::string(GET_SCANNER_DEVICE_LIST));
561 }
562 SCAN_HILOGI("ExitScan successfully");
563 return SCAN_ERROR_NONE;
564 }