Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosfileshare.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtHarmonyExtras/private/qohosoperationstatus_p.h>
7
8#include <QtCore/qscopeguard.h>
9#include <QtCore/private/qcore_ohos_p.h>
10#include <QtCore/private/qohoscommon_p.h>
11#include <QtCore/private/qohoslogger_p.h>
12#include <QtCore/private/qohospathutils_p.h>
13
14#include <cstdlib>
15#include <cstring>
16#include <memory>
17#include <optional>
18#include <string>
19#include <tuple>
20#include <vector>
21
22#include <filemanagement/fileshare/oh_file_share.h>
23
24QT_BEGIN_NAMESPACE
25
26namespace QtHarmonyExtras {
27
28using namespace Private;
29
30/*!
31 \namespace QtHarmonyExtras::FileShare
32 \inmodule QtHarmonyExtras
33 \since 5.12.12
34 \brief The FileShare to expose file permission API.
35
36 This API uses file system paths, which differ from the URIs used internally by HarmonyOS. For example, the path
37 \c /data/storage/el1/bundle/entry/resources/resfile/test.txt
38 will be converted to the URI
39 \c file://com.your.example/data/storage/el1/bundle/entry/resources/resfile/test.txt , where \c com.your.example is app bundle name.
40
41 To learn more about file paths and URIs in HarmonyOS, see
42 \l{https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/app-sandbox-directory-V5} {sandbox documentation}.
43
44 \warning
45 This API relies on the underlying OHOS implementation.
46 The following functions: persistPermission(), revokePermission(), activatePermission(), deactivatePermission(), and checkPersistent() may be unavailable on some devices.
47 Additionally, there may be limitations on the maximum number of policies, and certain permissions may need to be explicitly granted to the application.
48
49 For more details and limitations, refer to the
50 \l{https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/native-fileshare-guidelines-V14} {API documentation}.
51*/
52namespace FileShare {
53
54namespace {
55
56std::shared_ptr<char> makeSharedNullTerminatedString(std::string str)
57{
58 auto sharedStrData = QtOhos::moveToSharedPtr(std::move(str) + '\0');
59 return std::shared_ptr<char>(sharedStrData, &sharedStrData->front());
60}
61
62std::shared_ptr<char> makeSharedNullTerminatedString(const char *str)
63{
64 return makeSharedNullTerminatedString(std::string(str != nullptr ? str : ""));
65}
66
67std::shared_ptr<::FileShare_PolicyInfo> makeFileSharePolicyInfo(
68 std::string uri, unsigned operationMode)
69{
70 auto sharedUri = makeSharedNullTerminatedString(std::move(uri));
71
72 auto policyInfo = QtOhos::moveToSharedPtr(
73 ::FileShare_PolicyInfo{
74 .uri = sharedUri.get(),
75 .length = static_cast<unsigned>(std::strlen(sharedUri.get())),
76 .operationMode = operationMode,
77 });
78
79 return QtOhos::makeSharedPtrWithAttachedExtraData(
80 policyInfo, sharedUri);
81}
82
83std::vector<std::shared_ptr<::FileShare_PolicyInfo>> convertToFileSharePolicyInfos(
84 const QList<PathPolicy> &policies)
85{
86 std::vector<std::shared_ptr<::FileShare_PolicyInfo>> fileSharePolicies;
87
88 for (const auto &policy : policies) {
89 fileSharePolicies.push_back(
90 makeFileSharePolicyInfo(
91 tryMapPathToOhosFileUri(policy.path.toStdString()).value_or(""),
92 static_cast<unsigned>(policy.operationModes.toInt())));
93 }
94
95 return fileSharePolicies;
96}
97
98std::shared_ptr<::FileShare_PolicyErrorResult> makeFileSharePolicyErrorResultFromRawStruct(
99 const ::FileShare_PolicyErrorResult &inputStruct)
100{
101 auto sharedUri = makeSharedNullTerminatedString(inputStruct.uri);
102 auto sharedMessage = makeSharedNullTerminatedString(inputStruct.message);
103
104 auto policyErrorResult = QtOhos::moveToSharedPtr(
105 ::FileShare_PolicyErrorResult{
106 .uri = sharedUri.get(),
107 .code = inputStruct.code,
108 .message = sharedMessage.get(),
109 });
110
111 return QtOhos::makeSharedPtrWithAttachedExtraData(
112 policyErrorResult,
113 QtOhos::moveToSharedPtr(std::make_tuple(sharedUri, sharedMessage)));
114};
115
116std::vector<::FileShare_PolicyInfo> makePoliciesRawVectorView(
117 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies)
118{
119 std::vector<::FileShare_PolicyInfo> rawVectorView;
120 for (const auto &policyPtr : policies)
121 rawVectorView.push_back(*policyPtr);
122
123 return rawVectorView;
124}
125
126template<typename PermissionActionFunc>
127::FileManagement_ErrCode callFileSharePermissionActionFunc(
128 PermissionActionFunc permissionActionFunc,
129 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies,
130 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> &outResult)
131{
132 auto policiesRawVectorView = makePoliciesRawVectorView(policies);
133 ::FileShare_PolicyErrorResult *resultParam = nullptr;
134 unsigned resultNumParam = 0;
135 auto resultParamReleaseGuard = qScopeGuard(
136 [&]() {
137 if (resultParam != nullptr && resultNumParam != 0)
138 ::OH_FileShare_ReleasePolicyErrorResult(resultParam, resultNumParam);
139 });
140
141 auto errCode = permissionActionFunc(
142 policiesRawVectorView.data(), policiesRawVectorView.size(),
143 &resultParam, &resultNumParam);
144
145 outResult.clear();
146 if (resultParam != nullptr) {
147 for (unsigned i = 0; i < resultNumParam; ++i) {
148 outResult.push_back(
149 makeFileSharePolicyErrorResultFromRawStruct(resultParam[i]));
150 }
151 }
152
153 return errCode;
154}
155
156::FileManagement_ErrCode fileShareCheckPersistentPermission(
157 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies,
158 std::vector<bool> &outResult)
159{
160 auto policiesRawVectorView = makePoliciesRawVectorView(policies);
161 bool *resultParam = nullptr;
162 auto resultParamReleaseGuard = qScopeGuard(
163 [&]() {
164 ::free(resultParam);
165 });
166 unsigned resultNumParam = 0;
167
168 auto errCode = ::OH_FileShare_CheckPersistentPermission(
169 policiesRawVectorView.data(), policiesRawVectorView.size(),
170 &resultParam, &resultNumParam);
171
172 outResult.clear();
173 if (resultParam != nullptr) {
174 for (unsigned i = 0; i < resultNumParam; ++i)
175 outResult.push_back(resultParam[i]);
176 }
177
178 return errCode;
179}
180
181::FileManagement_ErrCode fileSharePersistPermission(
182 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies,
183 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> &outResult)
184{
185 return callFileSharePermissionActionFunc(
186 Q_OHOS_NAMED_FUNC(::OH_FileShare_PersistPermission),
187 policies, outResult);
188}
189
190::FileManagement_ErrCode fileShareRevokePermission(
191 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies,
192 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> &outResult)
193{
194 return callFileSharePermissionActionFunc(
195 Q_OHOS_NAMED_FUNC(::OH_FileShare_RevokePermission),
196 policies, outResult);
197}
198
199::FileManagement_ErrCode fileShareActivatePermission(
200 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies,
201 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> &outResult)
202{
203 return callFileSharePermissionActionFunc(
204 Q_OHOS_NAMED_FUNC(::OH_FileShare_ActivatePermission),
205 policies, outResult);
206}
207
208::FileManagement_ErrCode fileShareDeactivatePermission(
209 const std::vector<std::shared_ptr<::FileShare_PolicyInfo>> &policies,
210 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> &outResult)
211{
212 return callFileSharePermissionActionFunc(
213 Q_OHOS_NAMED_FUNC(::OH_FileShare_DeactivatePermission),
214 policies, outResult);
215}
216
217std::optional<PathPolicyError> tryMapFileSharePolicyErrorCode(::FileShare_PolicyErrorCode errorCode)
218{
219 switch (errorCode) {
220 case ::FileShare_PolicyErrorCode::PERSISTENCE_FORBIDDEN:
221 return std::make_optional(PathPolicyError::PersistenceForbidden);
222 case ::FileShare_PolicyErrorCode::INVALID_MODE:
223 return std::make_optional(PathPolicyError::InvalidMode);
224 case ::FileShare_PolicyErrorCode::INVALID_PATH:
225 return std::make_optional(PathPolicyError::InvalidPath);
226 case ::FileShare_PolicyErrorCode::PERMISSION_NOT_PERSISTED:
227 return std::make_optional(PathPolicyError::PermissionNotPersisted);
228 }
229 return std::nullopt;
230}
231
232QList<PathPolicyErrorInfo> convertToPathPolicyErrorInfos(
233 const std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> &policyErrorResults)
234{
235 QList<PathPolicyErrorInfo> result;
236 for (const auto &policyErrorResult : policyErrorResults) {
237 result.push_back({
238 .path = policyErrorResult->uri != nullptr
239 ? QString::fromStdString(tryMapOhosFileUriToPath(policyErrorResult->uri).value_or(""))
240 : QString(),
241 .error =
242 tryMapFileSharePolicyErrorCode(policyErrorResult->code)
243 .value_or(PathPolicyError::Unknown),
244 .errorMessage = QLatin1String(
245 policyErrorResult->message != nullptr ? policyErrorResult->message : ""),
246 });
247 }
248
249 return result;
250}
251
252QList<PathPolicyCheckResult> convertToPathPolicyCheckResults(
253 const std::vector<bool> &checkResults,
254 const QList<PathPolicy> &policies)
255{
256 QList<PathPolicyCheckResult> result;
257 for (std::size_t i = 0; i < checkResults.size() && policies.size(); ++i)
258 result.push_back({policies[i], checkResults[i]});
259
260 return result;
261}
262
263bool validateCheckResultsAgainstPolicies(
264 const std::vector<bool> &checkResults,
265 const QList<PathPolicy> &policies)
266{
267 return checkResults.size() == static_cast<std::size_t>(policies.size());
268}
269
270bool isSuccessErrorCode(::FileManagement_ErrCode errorCode)
271{
272 return errorCode == ::FileManagement_ErrCode::ERR_OK;
273}
274
275/*!
276 \class QtHarmonyExtras::FileShare::ActionResult
277 \inmodule QtHarmonyExtras
278 \since 5.12.12
279 \brief The ActionResult class encapsulates the result of all file requested access permission actions.
280
281 It contains any errors that occurred during the execution of these actions.
282
283 \sa persistPermission(), revokePermission(), activatePermission(), deactivatePermission()
284*/
285class ActionResultImpl : public ActionResult
286{
287public:
288 ActionResultImpl(bool successFlag, QList<PathPolicyErrorInfo> errorInfoList);
289 std::shared_ptr<OperationStatus> operationStatus() const override;
290 QList<PathPolicyErrorInfo> errorInfoList() const override;
291
292private:
293 std::shared_ptr<OperationStatus> m_operationStatus;
294 QList<PathPolicyErrorInfo> m_errorInfoList;
295};
296
297ActionResultImpl::ActionResultImpl(bool successFlag, QList<PathPolicyErrorInfo> errorInfoList)
298 : m_operationStatus(createOperationStatus(successFlag))
299 , m_errorInfoList(std::move(errorInfoList))
300{
301}
302
303/*!
304 \fn std::shared_ptr<OperationStatus> QtHarmonyExtras::FileShare::ActionResult::operationStatus() const
305
306 Returns the overall result of all requested file access permission actions.
307
308 \sa OperationStatus
309*/
310std::shared_ptr<OperationStatus> ActionResultImpl::operationStatus() const
311{
312 return m_operationStatus;
313}
314
315/*!
316 \fn QList<PathPolicyErrorInfo> QtHarmonyExtras::FileShare::ActionResult::errorInfoList() const
317
318 Returns a list of errors for each file access action.
319
320 Each entry in the list corresponds to a specific file operation that encountered an error.
321
322 \sa PathPolicyErrorInfo
323*/
324QList<PathPolicyErrorInfo> ActionResultImpl::errorInfoList() const
325{
326 return m_errorInfoList;
327}
328
329/*!
330 \class QtHarmonyExtras::FileShare::CheckResult
331 \inmodule QtHarmonyExtras
332 \since 5.12.12
333 \brief The CheckResult class encapsulates the result of all requested file access permission checks.
334
335 \sa checkPersistent()
336*/
337class CheckResultImpl : public CheckResult
338{
339public:
340 CheckResultImpl(
341 bool successFlag, const std::vector<bool> &checkResults,
342 const QList<PathPolicy> &policies);
343 std::shared_ptr<OperationStatus> operationStatus() const override;
344 QList<PathPolicyCheckResult> checkResultList() const override;
345
346private:
347 std::shared_ptr<OperationStatus> m_operationStatus;
348 QList<PathPolicyCheckResult> m_checkResultList;
349};
350
351CheckResultImpl::CheckResultImpl(
352 bool successFlag, const std::vector<bool> &checkResults,
353 const QList<PathPolicy> &policies)
354{
355 if (validateCheckResultsAgainstPolicies(checkResults, policies)) {
356 m_operationStatus = createOperationStatus(successFlag);
357 m_checkResultList = convertToPathPolicyCheckResults(checkResults, policies);
358 } else {
359 qOhosPrintfWarning(
360 "%s: didn't get check results for all requested paths. "
361 "Got %lld check results, but requested checks for %lld paths.",
362 Q_FUNC_INFO, static_cast<long long>(checkResults.size()),
363 static_cast<long long>(policies.size()));
364 m_operationStatus = createOperationStatus(false);
365 }
366}
367
368/*!
369 \fn std::shared_ptr<OperationStatus> QtHarmonyExtras::FileShare::CheckResult::operationStatus() const
370
371 Returns the overall result of all requested file access permission checks.
372
373 \sa OperationStatus
374*/
375std::shared_ptr<OperationStatus> CheckResultImpl::operationStatus() const
376{
377 return m_operationStatus;
378}
379
380/*!
381 \fn QList<PathPolicyCheckResult> QtHarmonyExtras::FileShare::CheckResult::checkResultList() const
382
383 Returns a list of results for each individual file access permission check.
384
385 Each entry in the list corresponds to a specific file and its check result.
386
387 \sa PathPolicyCheckResult
388*/
389QList<PathPolicyCheckResult> CheckResultImpl::checkResultList() const
390{
391 return m_checkResultList;
392}
393
394}
395
396/*!
397 \enum QtHarmonyExtras::FileShare::OperationMode
398 \since 5.12.12
399
400 Defines permissions on path. See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#fileshare_operationmode}
401 {FileShare_OperationMode}. The flags can be combined using bitwise operations.
402
403 \value Read Read on path
404 \value Write Write on path
405
406 \sa PathPolicy
407*/
408
409/*!
410 \enum QtHarmonyExtras::FileShare::PathPolicyError
411 \since 5.12.12
412
413 Defines permission policy error codes. See \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#fileshare_policyerrorcode}
414 {FileShare_PolicyErrorCode}.
415
416 \value Unknown Error type is unknown or not recognized
417 \value PersistenceForbidden The permission on the path cannot be persisted
418 \value InvalidMode Invalid operation mode
419 \value InvalidPath Invalid path
420 \value PermissionNotPersisted The permission is not persisted
421
422 \sa PathPolicyErrorInfo
423*/
424
425/*!
426 \class QtHarmonyExtras::FileShare::PathPolicy
427 \inmodule QtHarmonyExtras
428 \since 5.12.12
429 \brief The PathPolicy struct encapsulates information required to request file access permissions for a specified path.
430*/
431
432/*!
433 \variable QtHarmonyExtras::FileShare::PathPolicy::path
434 \brief The path for which access permission is requested.
435*/
436
437/*!
438 \variable QtHarmonyExtras::FileShare::PathPolicy::operationModes
439 \brief The types of access being requested for the file.
440
441 \sa OperationMode
442*/
443
444/*!
445 \class QtHarmonyExtras::FileShare::PathPolicyErrorInfo
446 \inmodule QtHarmonyExtras
447 \since 5.12.12
448 \brief The PathPolicyErrorInfo struct contains the result of a file access permission request for a specified path.
449
450 \sa ActionResult
451*/
452
453/*!
454 \variable QtHarmonyExtras::FileShare::PathPolicyErrorInfo::path
455 \brief The path for which access permission was requested.
456*/
457
458/*!
459 \variable QtHarmonyExtras::FileShare::PathPolicyErrorInfo::error
460 \brief The error code indicating the result of the file access permission request.
461
462 \sa PathPolicyError
463*/
464
465/*!
466 \variable QtHarmonyExtras::FileShare::PathPolicyErrorInfo::errorMessage
467 \brief Detailed error message.
468*/
469
470/*!
471 \class QtHarmonyExtras::FileShare::PathPolicyCheckResult
472 \inmodule QtHarmonyExtras
473 \since 5.12.12
474 \brief The PathPolicyCheckResult struct contains the result of a file permission check request for a specified path, indicating whether access is granted or denied.
475*/
476
477/*!
478 \variable QtHarmonyExtras::FileShare::PathPolicyCheckResult::policy
479 \brief The requested path and the corresponding operation mode information.
480
481 \sa PathPolicy
482*/
483
484/*!
485 \variable QtHarmonyExtras::FileShare::PathPolicyCheckResult::result
486 \brief The outcome of the permission check for the requested path and operation mode.
487*/
488
489ActionResult::ActionResult() = default;
490
491ActionResult::~ActionResult() = default;
492
493CheckResult::CheckResult() = default;
494
495CheckResult::~CheckResult() = default;
496
497/*!
498 \fn std::shared_ptr<ActionResult> QtHarmonyExtras::FileShare::persistPermission(const QList<PathPolicy> &policies)
499
500 Persists file or folder permissions from \a policies.
501 The success of the action can be determined from ActionResult.
502
503 This function calls \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_persistpermission} {OH_FileShare_PersistPermission}.
504 persistPermission() stores persistence data in the system database. After persistPermission() call, permissions are not yet active. Use activatePermission() to activate permissions.
505 persistPermission() must be called at least once before activatePermission().
506
507 To revoke a persistent permission, use revokePermission().
508
509 \sa ActionResult, PathPolicy, revokePermission(), activatePermission()
510*/
511std::shared_ptr<ActionResult> persistPermission(const QList<PathPolicy> &policies)
512{
513 auto actionResult = QOhosJsThreadGateway::eval(
514 [&](QOhosJsState &) {
515 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> outResults;
516 auto retCode = fileSharePersistPermission(
517 convertToFileSharePolicyInfos(policies), outResults);
518
519 return std::make_pair(isSuccessErrorCode(retCode), convertToPathPolicyErrorInfos(outResults));
520 },
521 Q_FUNC_INFO);
522 return std::make_shared<ActionResultImpl>(actionResult.first, actionResult.second);
523}
524
525/*!
526 \fn std::shared_ptr<ActionResult> QtHarmonyExtras::FileShare::revokePermission(const QList<PathPolicy> &policies)
527
528 Revokes file or folder permissions from \a policies.
529 The success of the action can be determined from ActionResult.
530
531 This function calls \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_revokepermission} {OH_FileShare_RevokePermission}.
532
533 To persist permission, use persistPermission().
534
535 \sa ActionResult, PathPolicy, persistPermission()
536*/
537std::shared_ptr<ActionResult> revokePermission(const QList<PathPolicy> &policies)
538{
539 auto actionResult = QOhosJsThreadGateway::eval(
540 [&](QOhosJsState &) {
541 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> outResults;
542 auto retCode = fileShareRevokePermission(
543 convertToFileSharePolicyInfos(policies), outResults);
544
545 return std::make_pair(isSuccessErrorCode(retCode), convertToPathPolicyErrorInfos(outResults));
546 },
547 Q_FUNC_INFO);
548 return std::make_shared<ActionResultImpl>(actionResult.first, actionResult.second);
549}
550
551/*!
552 \fn std::shared_ptr<ActionResult> QtHarmonyExtras::FileShare::activatePermission(const QList<PathPolicy> &policies)
553
554 Activates file or folder permissions from \a policies.
555 The success of the action can be determined from ActionResult.
556
557 This function calls \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_activatepermission} {OH_FileShare_ActivatePermission}.
558 Each time an application is started, its persistent permissions have not been loaded to the memory. Use this function to make a persistent permission active after the application is started.
559 If the activation fails because the permission has not been persisted, use persistPermission() first.
560
561 To deactivate an active permission, use deactivatePermission().
562
563 \sa ActionResult, PathPolicy, persistPermission(), deactivatePermission()
564*/
565std::shared_ptr<ActionResult> activatePermission(const QList<PathPolicy> &policies)
566{
567 auto actionResult = QOhosJsThreadGateway::eval(
568 [&](QOhosJsState &) {
569 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> outResults;
570 auto retCode = fileShareActivatePermission(
571 convertToFileSharePolicyInfos(policies), outResults);
572
573 return std::make_pair(isSuccessErrorCode(retCode), convertToPathPolicyErrorInfos(outResults));
574 },
575 Q_FUNC_INFO);
576 return std::make_shared<ActionResultImpl>(actionResult.first, actionResult.second);
577}
578
579/*!
580 \fn std::shared_ptr<ActionResult> QtHarmonyExtras::FileShare::deactivatePermission(const QList<PathPolicy> &policies)
581
582 Deactivates file or folder permissions from \a policies.
583 The success of the action can be determined from ActionResult.
584
585 This function calls \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_deactivatepermission} {OH_FileShare_DeactivatePermission}.
586
587 To activate permission, use activatePermission().
588
589 \sa ActionResult, PathPolicy, activatePermission()
590*/
591std::shared_ptr<ActionResult> deactivatePermission(const QList<PathPolicy> &policies)
592{
593 auto actionResult = QOhosJsThreadGateway::eval(
594 [&](QOhosJsState &) {
595 std::vector<std::shared_ptr<::FileShare_PolicyErrorResult>> outResults;
596 auto retCode = fileShareDeactivatePermission(
597 convertToFileSharePolicyInfos(policies), outResults);
598
599 return std::make_pair(isSuccessErrorCode(retCode), convertToPathPolicyErrorInfos(outResults));
600 },
601 Q_FUNC_INFO);
602 return std::make_shared<ActionResultImpl>(actionResult.first, actionResult.second);
603}
604
605/*!
606 \fn std::shared_ptr<CheckResult> QtHarmonyExtras::FileShare::checkPersistent(const QList<PathPolicy> &policies)
607
608 Checks if file or folder permissions from \a policies have persistent permissions.
609 The result check for each file or folder can be determined from CheckResult.
610 CheckResult::PathPolicyCheckResult::result will be set to \c true for each file or folder only for succesufull check and persistent permission found, \c false otherwise.
611
612 This function calls \l {https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_checkpersistentpermission} {OH_FileShare_CheckPersistentPermission}.
613
614 To persist permission, use persistPermission().
615
616 \sa CheckResult, PathPolicy, persistPermission()
617*/
618std::shared_ptr<CheckResult> checkPersistent(const QList<PathPolicy> &policies)
619{
620 auto checkResult = QOhosJsThreadGateway::eval(
621 [&](QOhosJsState &) {
622 std::vector<bool> outResults;
623 auto retCode = fileShareCheckPersistentPermission(
624 convertToFileSharePolicyInfos(policies), outResults);
625
626 return std::make_pair(isSuccessErrorCode(retCode), outResults);
627 },
628 Q_FUNC_INFO);
629 return std::make_shared<CheckResultImpl>(checkResult.first, checkResult.second, policies);
630}
631
632}
633
634}
635
636QT_END_NAMESPACE
std::shared_ptr< ActionResult > deactivatePermission(const QList< PathPolicy > &policies)
Deactivates file or folder permissions from policies.
std::shared_ptr< CheckResult > checkPersistent(const QList< PathPolicy > &policies)
Checks if file or folder permissions from policies have persistent permissions.
std::shared_ptr< ActionResult > revokePermission(const QList< PathPolicy > &policies)
Revokes file or folder permissions from policies.
std::shared_ptr< ActionResult > persistPermission(const QList< PathPolicy > &policies)
Persists file or folder permissions from policies.
std::shared_ptr< ActionResult > activatePermission(const QList< PathPolicy > &policies)
Activates file or folder permissions from policies.