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