Jump to content

Qt for HarmonyOS/qtohosextras doc/FileShare Namespace: Difference between revisions

From Qt Wiki
No edit summary
Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
< [[Qt for HarmonyOS/qtohosextras doc/Qt Ohos Extras C++ Classes|Qt Ohos Extras C++ Classes]]
= FileShare Namespace =


= FileShare Namespace =
QtOhosExtras::FileShare


The FileShare to expose file permission API. [[#details|More...]]
The FileShare to expose file permission API. [[#details|More...]]
Line 7: Line 7:
{| class="wikitable"
{| class="wikitable"
|-
|-
! Header:
| Header:
| #include <FileShare>
| #include <FileShare>
|-
|-
! qmake:
| qmake:
| QT += ohosextras
| QT += ohosextras
|-
|-
! Since:
| Since:
| Qt 5.12.12
| Qt 5.12.12
|}
|}
This namespace was introduced in Qt 5.12.12.


== Classes ==
== Classes ==


{| class="wikitable" style="width:100%"
{| class="wikitable"
|-
|-
| class || '''[[Qt for HarmonyOS/qtohosextras doc/ActionResult Class|ActionResult]]'''
| class
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]]'''
|-
|-
| class || '''[[Qt for HarmonyOS/qtohosextras doc/CheckResult Class|CheckResult]]'''
| class
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/CheckResult_Class|CheckResult]]'''
|-
|-
| class || '''[[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]]'''
| struct
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]]'''
|-
|-
| class || '''[[Qt for HarmonyOS/qtohosextras doc/PathPolicyCheckResult Class|PathPolicyCheckResult]]'''
| struct
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyCheckResult_Class|PathPolicyCheckResult]]'''
|-
|-
| class || '''[[Qt for HarmonyOS/qtohosextras doc/PathPolicyErrorInfo Class|PathPolicyErrorInfo]]'''
| struct
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyErrorInfo_Class|PathPolicyErrorInfo]]'''
|}
|}


== Types ==
== Types ==


{| class="wikitable" style="width:100%"
{| class="wikitable"
|-
|-
| enum || '''[[#OperationMode-enum|OperationMode]]''' { Read, Write }
| enum class
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#OperationMode-enum|OperationMode]]''' { Read, Write }
|-
|-
| flags || '''[[#OperationMode-enum|OperationModes]]'''
| flags
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#OperationMode-enum|OperationModes]]'''
|-
|-
| enum || '''[[#PathPolicyError-enum|PathPolicyError]]''' { Unknown, PersistenceForbidden, InvalidMode, InvalidPath, PermissionNotPersisted }
| enum class
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#PathPolicyError-enum|PathPolicyError]]''' { Unknown, PersistenceForbidden, InvalidMode, InvalidPath, PermissionNotPersisted }
|}
|}


== Functions ==
== Functions ==


{| class="wikitable" style="width:100%"
{| class="wikitable"
|-
|-
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#activatePermission|activatePermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'')
| QSharedPointer<ActionResult>
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]]'''(const QList<PathPolicy> &''policies'')
|-
|-
| QSharedPointer<QtOhosExtras::FileShare::CheckResult> || '''[[#checkPersistent|checkPersistent]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'')
| QSharedPointer<CheckResult>
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#checkPersistent|checkPersistent]]'''(const QList<PathPolicy> &''policies'')
|-
|-
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#deactivatePermission|deactivatePermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'')
| QSharedPointer<ActionResult>
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#deactivatePermission|deactivatePermission]]'''(const QList<PathPolicy> &''policies'')
|-
|-
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#persistPermission|persistPermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'')
| QSharedPointer<ActionResult>
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]]'''(const QList<PathPolicy> &''policies'')
|-
|-
| const QMetaObject * || '''[[#qt_getEnumMetaObject|qt_getEnumMetaObject]]'''(QtOhosExtras::FileShare::OperationMode)
| QSharedPointer<ActionResult>
|-
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#revokePermission|revokePermission]]'''(const QList<PathPolicy> &''policies'')
| const char * || '''[[#qt_getEnumName|qt_getEnumName]]'''(QtOhosExtras::FileShare::OperationMode)
|-
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#revokePermission|revokePermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'')
|-
| QFlags<OperationModes::enum_type> || '''[[#operator-7c|operator\|]]'''(OperationModes::enum_type ''f1'', OperationModes::enum_type ''f2'')
|-
| QFlags<OperationModes::enum_type> || '''[[#operator-7c-1|operator\|]]'''(OperationModes::enum_type ''f1'', QFlags<OperationModes::enum_type> ''f2'')
|-
| QIncompatibleFlag || '''[[#operator-7c-2|operator\|]]'''(OperationModes::enum_type ''f1'', int ''f2'')
|}
|}


== Detailed Description ==
== Detailed Description ==
<span id="details"></span>
The FileShare to expose file permission API.


This API uses file system paths, which differ from the URIs used internally by HarmonyOS. For example, the path <code>/data/storage/el1/bundle/entry/resources/resfile/test.txt</code> will be converted to the URI <code>file://com.your.example/data/storage/el1/bundle/entry/resources/resfile/test.txt</code> , where <code>com.your.example</code> is app bundle name.
This API uses file system paths, which differ from the URIs used internally by HarmonyOS. For example, the path <code>/data/storage/el1/bundle/entry/resources/resfile/test.txt</code> will be converted to the URI <code>file://com.your.example/data/storage/el1/bundle/entry/resources/resfile/test.txt</code> , where <code>com.your.example</code> is app bundle name.
Line 77: Line 79:
To learn more about file paths and URIs in HarmonyOS, see [https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/app-sandbox-directory-V5 sandbox documentation].
To learn more about file paths and URIs in HarmonyOS, see [https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/app-sandbox-directory-V5 sandbox documentation].


'''Warning:''' This API relies on the underlying OHOS implementation. The following functions: [[#persistPermission|persistPermission()]], [[#revokePermission|revokePermission()]], [[#activatePermission|activatePermission()]], [[#deactivatePermission|deactivatePermission()]], and [[#checkPersistent|checkPersistent()]] may be unavailable on some devices. Additionally, there may be limitations on the maximum number of policies, and certain permissions may need to be explicitly granted to the application.
'''Warning: '''This API relies on the underlying OHOS implementation. The following functions: [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]](), [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#revokePermission|revokePermission]](), [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]](), [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#deactivatePermission|deactivatePermission]](), and [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#checkPersistent|checkPersistent]]() may be unavailable on some devices. Additionally, there may be limitations on the maximum number of policies, and certain permissions may need to be explicitly granted to the application.


For more details and limitations, refer to the [https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/native-fileshare-guidelines-V14 API documentation].
For more details and limitations, refer to the [https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V14/native-fileshare-guidelines-V14 API documentation].
== Classes ==
===  class [[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]] ===
The ActionResult class encapsulates the result of all file requested access permission actions. [[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class#details|More...]]
===  class [[Qt_for_HarmonyOS/qtohosextras_doc/CheckResult_Class|CheckResult]] ===
The CheckResult class encapsulates the result of all requested file access permission checks. [[Qt_for_HarmonyOS/qtohosextras_doc/CheckResult_Class#details|More...]]
===  class [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]] ===
The PathPolicy struct encapsulates information required to request file access permissions for a specified path. [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class#details|More...]]
===  class [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyCheckResult_Class|PathPolicyCheckResult]] ===
The PathPolicyCheckResult struct contains the result of a file permission check request for a specified path, indicating whether access is granted or denied. [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyCheckResult_Class#details|More...]]
===  class [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyErrorInfo_Class|PathPolicyErrorInfo]] ===
The PathPolicyErrorInfo struct contains the result of a file access permission request for a specified path. [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyErrorInfo_Class#details|More...]]


== Type Documentation ==
== Type Documentation ==


=== <span id="OperationMode-enum"></span>enum FileShare::OperationMode ===
=== <span id="OperationMode-enum"></span>enum class FileShare::OperationMode<br/>flags FileShare::OperationModes ===
=== <span id="OperationModes-flags"></span>flags FileShare::OperationModes ===


Defines permissions on path. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#fileshare_operationmode FileShare_OperationMode]. The flags can be combined using bitwise operations.
Defines permissions on path. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#fileshare_operationmode FileShare_OperationMode]. The flags can be combined using bitwise operations.


{| class="wikitable"
{| class="wikitable"
! Constant !! Value !! Description
|-
|-
| <code>QtOhosExtras::FileShare::Read</code> || <code>1 << 0</code> || Read on path
! Constant
! Value
! Description
|-
|-
| <code>QtOhosExtras::FileShare::Write</code> || <code>1 << 1</code> || Write on path
| <code>QtOhosExtras::FileShare::OperationMode::Read</code>
| <code>1 << 0</code>
| Read on path
|-
| <code>QtOhosExtras::FileShare::OperationMode::Write</code>
| <code>1 << 1</code>
| Write on path
|}
|}


This enum was introduced or modified in Qt 5.12.12.
This enum was introduced or modified in Qt 5.12.12.


The OperationModes type is a typedef for QFlags<OperationMode>. It stores an OR combination of OperationMode values.
The OperationModes type is a typedef for [https://doc.qt.io/qt-5/qflags.html QFlags]<OperationMode>. It stores an OR combination of OperationMode values.


'''See also:''' [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]].
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]].


=== <span id="PathPolicyError-enum"></span>enum FileShare::PathPolicyError ===
=== <span id="PathPolicyError-enum"></span>enum class FileShare::PathPolicyError ===


Defines permission policy error codes. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#fileshare_policyerrorcode FileShare_PolicyErrorCode].
Defines permission policy error codes. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#fileshare_policyerrorcode FileShare_PolicyErrorCode].


{| class="wikitable"
{| class="wikitable"
! Constant !! Value !! Description
|-
|-
| <code>QtOhosExtras::FileShare::Unknown</code> || 0 || Error type is unknown or not recognized
! Constant
! Value
! Description
|-
| <code>QtOhosExtras::FileShare::PathPolicyError::Unknown</code>
| <code>0</code>
| Error type is unknown or not recognized
|-
|-
| <code>QtOhosExtras::FileShare::PersistenceForbidden</code> || 1 || The permission on the path cannot be persisted
| <code>QtOhosExtras::FileShare::PathPolicyError::PersistenceForbidden</code>
| <code>1</code>
| The permission on the path cannot be persisted
|-
|-
| <code>QtOhosExtras::FileShare::InvalidMode</code> || 2 || Invalid operation mode
| <code>QtOhosExtras::FileShare::PathPolicyError::InvalidMode</code>
| <code>2</code>
| Invalid operation mode
|-
|-
| <code>QtOhosExtras::FileShare::InvalidPath</code> || 3 || Invalid path
| <code>QtOhosExtras::FileShare::PathPolicyError::InvalidPath</code>
| <code>3</code>
| Invalid path
|-
|-
| <code>QtOhosExtras::FileShare::PermissionNotPersisted</code> || 4 || The permission is not persisted
| <code>QtOhosExtras::FileShare::PathPolicyError::PermissionNotPersisted</code>
| <code>4</code>
| The permission is not persisted
|}
|}


This enum was introduced or modified in Qt 5.12.12.
This enum was introduced or modified in Qt 5.12.12.


'''See also:''' [[Qt for HarmonyOS/qtohosextras doc/PathPolicyErrorInfo Class|PathPolicyErrorInfo]].
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicyErrorInfo_Class|PathPolicyErrorInfo]].


== Function Documentation ==
== Function Documentation ==


=== <span id="activatePermission"></span>QSharedPointer<ActionResult> FileShare::activatePermission(const QList<PathPolicy> &''policies'') ===
=== <span id="activatePermission"></span>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]]> FileShare::activatePermission(const [https://doc.qt.io/qt-5/qlist.html QList]<[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]]> &''policies'') ===


Activates file or folder permissions from ''policies''. The success of the action can be determined from [[ActionResult_Class|ActionResult]].
Activates file or folder permissions from ''policies''. The success of the action can be determined from [[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]].


This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_activatepermission OH_FileShare_ActivatePermission]. 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. If the activation fails because the permission has not been persisted, use [[#persistPermission|persistPermission()]] first.
This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_activatepermission OH_FileShare_ActivatePermission]. 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. If the activation fails because the permission has not been persisted, use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]]() first.


To deactivate an active permission, use [[#deactivatePermission|deactivatePermission()]].
To deactivate an active permission, use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#deactivatePermission|deactivatePermission]]().


'''See also:''' [[ActionResult_Class|ActionResult]], [[PathPolicy_Struct|PathPolicy]], [[#persistPermission|persistPermission()]], and [[#deactivatePermission|deactivatePermission()]].
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]], [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]], [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]](), and [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#deactivatePermission|deactivatePermission]]().


=== <span id="checkPersistent"></span>QSharedPointer<CheckResult> FileShare::checkPersistent(const QList<PathPolicy> &''policies'') ===
=== <span id="checkPersistent"></span>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/CheckResult_Class|CheckResult]]> FileShare::checkPersistent(const [https://doc.qt.io/qt-5/qlist.html QList]<[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]]> &''policies'') ===


Checks if file or folder permissions from ''policies'' have persistent permissions. The result check for each file or folder can be determined from [[CheckResult_Class|CheckResult]]. CheckResult::PathPolicyCheckResult::result will be set to <code>true</code> for each file or folder only for succesufull check and persistent permission found, <code>false</code> otherwise.
Checks if file or folder permissions from ''policies'' have persistent permissions. The result check for each file or folder can be determined from [[Qt_for_HarmonyOS/qtohosextras_doc/CheckResult_Class|CheckResult]]. CheckResult::PathPolicyCheckResult::result will be set to <code>true</code> for each file or folder only for succesufull check and persistent permission found, <code>false</code> otherwise.


This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_checkpersistentpermission OH_FileShare_CheckPersistentPermission].
This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_checkpersistentpermission OH_FileShare_CheckPersistentPermission].


To persist permission, use [[#persistPermission|persistPermission()]].
To persist permission, use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]]().


'''See also:''' [[CheckResult_Class|CheckResult]], [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]], and [[#persistPermission|persistPermission()]].
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/CheckResult_Class|CheckResult]], [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]], and [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]]().


=== <span id="deactivatePermission"></span>QSharedPointer<ActionResult> FileShare::deactivatePermission(const QList<PathPolicy> &''policies'') ===
=== <span id="deactivatePermission"></span>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]]> FileShare::deactivatePermission(const [https://doc.qt.io/qt-5/qlist.html QList]<[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]]> &''policies'') ===


Deactivates file or folder permissions from ''policies''. The success of the action can be determined from [[ActionResult_Class|ActionResult]].
Deactivates file or folder permissions from ''policies''. The success of the action can be determined from [[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]].


This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_deactivatepermission OH_FileShare_DeactivatePermission].
This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_deactivatepermission OH_FileShare_DeactivatePermission].


To activate permission, use [[#activatePermission|activatePermission()]].
To activate permission, use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]]().
 
'''See also:''' [[ActionResult_Class|ActionResult]], [[PathPolicy_Struct|PathPolicy]], and [[#activatePermission|activatePermission()]].
 
=== <span id="persistPermission"></span>QSharedPointer<ActionResult> FileShare::persistPermission(const QList<PathPolicy> &''policies'') ===
 
Persists file or folder permissions from ''policies''. The success of the action can be determined from [[ActionResult_Class|ActionResult]].
 
This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_persistpermission OH_FileShare_PersistPermission]. persistPermission() stores persistence data in the system database. After persistPermission() call, permissions are not yet active. Use [[#activatePermission|activatePermission()]] to activate permissions. persistPermission() must be called at least once before [[#activatePermission|activatePermission()]].
 
To revoke a persistent permission, use [[#revokePermission|revokePermission()]].
 
'''See also:''' [[ActionResult_Class|ActionResult]], [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]], [[#revokePermission|revokePermission()]], and [[#activatePermission|activatePermission()]].


=== <span id="qt_getEnumMetaObject"></span>const QMetaObject *FileShare::qt_getEnumMetaObject(QtOhosExtras::FileShare::OperationMode) ===
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]], [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]], and [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]]().


=== <span id="persistPermission"></span>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]]> FileShare::persistPermission(const [https://doc.qt.io/qt-5/qlist.html QList]<[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]]> &''policies'') ===


Persists file or folder permissions from ''policies''. The success of the action can be determined from [[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]].


=== <span id="qt_getEnumName"></span>const char *FileShare::qt_getEnumName(QtOhosExtras::FileShare::OperationMode) ===
This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_persistpermission OH_FileShare_PersistPermission]. persistPermission() stores persistence data in the system database. After persistPermission() call, permissions are not yet active. Use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]]() to activate permissions. persistPermission() must be called at least once before [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]]().


To revoke a persistent permission, use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#revokePermission|revokePermission]]().


'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]], [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]], [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#revokePermission|revokePermission]](), and [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#activatePermission|activatePermission]]().


=== <span id="revokePermission"></span>QSharedPointer<ActionResult> FileShare::revokePermission(const QList<PathPolicy> &''policies'') ===
=== <span id="revokePermission"></span>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]]> FileShare::revokePermission(const [https://doc.qt.io/qt-5/qlist.html QList]<[[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]]> &''policies'') ===


Revokes file or folder permissions from ''policies''. The success of the action can be determined from [[ActionResult_Class|ActionResult]].
Revokes file or folder permissions from ''policies''. The success of the action can be determined from [[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]].


This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_revokepermission OH_FileShare_RevokePermission].
This function calls [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/file_share-V5#oh_fileshare_revokepermission OH_FileShare_RevokePermission].


To persist permission, use [[#persistPermission|persistPermission()]].
To persist permission, use [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]]().
 
'''See also:''' [[ActionResult_Class|ActionResult]], [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]], and [[#persistPermission|persistPermission()]].
 
=== <span id="operator-7c"></span>QFlags<OperationModes::enum_type> FileShare::operator|(OperationModes::enum_type ''f1'', OperationModes::enum_type ''f2'') ===
 
 
 
=== <span id="operator-7c-1"></span>QFlags<OperationModes::enum_type> FileShare::operator|(OperationModes::enum_type ''f1'', QFlags<OperationModes::enum_type> ''f2'') ===
 
 
 
=== <span id="operator-7c-2"></span>QIncompatibleFlag FileShare::operator|(OperationModes::enum_type ''f1'', int ''f2'') ===
 


'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/ActionResult_Class|ActionResult]], [[Qt_for_HarmonyOS/qtohosextras_doc/PathPolicy_Class|PathPolicy]], and [[Qt_for_HarmonyOS/qtohosextras_doc/FileShare_Namespace#persistPermission|persistPermission]]().


[[Category:Qt for HarmonyOS]]
[[Category:Qt for HarmonyOS]]

Latest revision as of 05:30, 17 September 2026

FileShare Namespace

QtOhosExtras::FileShare

The FileShare to expose file permission API. More...

Header: #include <FileShare>
qmake: QT += ohosextras
Since: Qt 5.12.12

This namespace was introduced in Qt 5.12.12.

Classes

class ActionResult
class CheckResult
struct PathPolicy
struct PathPolicyCheckResult
struct PathPolicyErrorInfo

Types

enum class OperationMode { Read, Write }
flags OperationModes
enum class PathPolicyError { Unknown, PersistenceForbidden, InvalidMode, InvalidPath, PermissionNotPersisted }

Functions

QSharedPointer<ActionResult> activatePermission(const QList<PathPolicy> &policies)
QSharedPointer<CheckResult> checkPersistent(const QList<PathPolicy> &policies)
QSharedPointer<ActionResult> deactivatePermission(const QList<PathPolicy> &policies)
QSharedPointer<ActionResult> persistPermission(const QList<PathPolicy> &policies)
QSharedPointer<ActionResult> revokePermission(const QList<PathPolicy> &policies)

Detailed Description

This API uses file system paths, which differ from the URIs used internally by HarmonyOS. For example, the path /data/storage/el1/bundle/entry/resources/resfile/test.txt will be converted to the URI file://com.your.example/data/storage/el1/bundle/entry/resources/resfile/test.txt , where com.your.example is app bundle name.

To learn more about file paths and URIs in HarmonyOS, see sandbox documentation.

Warning: This API relies on the underlying OHOS implementation. The following functions: persistPermission(), revokePermission(), activatePermission(), deactivatePermission(), and checkPersistent() may be unavailable on some devices. Additionally, there may be limitations on the maximum number of policies, and certain permissions may need to be explicitly granted to the application.

For more details and limitations, refer to the API documentation.

Classes

class ActionResult

The ActionResult class encapsulates the result of all file requested access permission actions. More...

class CheckResult

The CheckResult class encapsulates the result of all requested file access permission checks. More...

class PathPolicy

The PathPolicy struct encapsulates information required to request file access permissions for a specified path. More...

class PathPolicyCheckResult

The PathPolicyCheckResult struct contains the result of a file permission check request for a specified path, indicating whether access is granted or denied. More...

class PathPolicyErrorInfo

The PathPolicyErrorInfo struct contains the result of a file access permission request for a specified path. More...

Type Documentation

enum class FileShare::OperationMode
flags FileShare::OperationModes

Defines permissions on path. See FileShare_OperationMode. The flags can be combined using bitwise operations.

Constant Value Description
QtOhosExtras::FileShare::OperationMode::Read 1 << 0 Read on path
QtOhosExtras::FileShare::OperationMode::Write 1 << 1 Write on path

This enum was introduced or modified in Qt 5.12.12.

The OperationModes type is a typedef for QFlags<OperationMode>. It stores an OR combination of OperationMode values.

See also PathPolicy.

enum class FileShare::PathPolicyError

Defines permission policy error codes. See FileShare_PolicyErrorCode.

Constant Value Description
QtOhosExtras::FileShare::PathPolicyError::Unknown 0 Error type is unknown or not recognized
QtOhosExtras::FileShare::PathPolicyError::PersistenceForbidden 1 The permission on the path cannot be persisted
QtOhosExtras::FileShare::PathPolicyError::InvalidMode 2 Invalid operation mode
QtOhosExtras::FileShare::PathPolicyError::InvalidPath 3 Invalid path
QtOhosExtras::FileShare::PathPolicyError::PermissionNotPersisted 4 The permission is not persisted

This enum was introduced or modified in Qt 5.12.12.

See also PathPolicyErrorInfo.

Function Documentation

QSharedPointer<ActionResult> FileShare::activatePermission(const QList<PathPolicy> &policies)

Activates file or folder permissions from policies. The success of the action can be determined from ActionResult.

This function calls OH_FileShare_ActivatePermission. 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. If the activation fails because the permission has not been persisted, use persistPermission() first.

To deactivate an active permission, use deactivatePermission().

See also ActionResult, PathPolicy, persistPermission(), and deactivatePermission().

QSharedPointer<CheckResult> FileShare::checkPersistent(const QList<PathPolicy> &policies)

Checks if file or folder permissions from policies have persistent permissions. The result check for each file or folder can be determined from CheckResult. CheckResult::PathPolicyCheckResult::result will be set to true for each file or folder only for succesufull check and persistent permission found, false otherwise.

This function calls OH_FileShare_CheckPersistentPermission.

To persist permission, use persistPermission().

See also CheckResult, PathPolicy, and persistPermission().

QSharedPointer<ActionResult> FileShare::deactivatePermission(const QList<PathPolicy> &policies)

Deactivates file or folder permissions from policies. The success of the action can be determined from ActionResult.

This function calls OH_FileShare_DeactivatePermission.

To activate permission, use activatePermission().

See also ActionResult, PathPolicy, and activatePermission().

QSharedPointer<ActionResult> FileShare::persistPermission(const QList<PathPolicy> &policies)

Persists file or folder permissions from policies. The success of the action can be determined from ActionResult.

This function calls OH_FileShare_PersistPermission. persistPermission() stores persistence data in the system database. After persistPermission() call, permissions are not yet active. Use activatePermission() to activate permissions. persistPermission() must be called at least once before activatePermission().

To revoke a persistent permission, use revokePermission().

See also ActionResult, PathPolicy, revokePermission(), and activatePermission().

QSharedPointer<ActionResult> FileShare::revokePermission(const QList<PathPolicy> &policies)

Revokes file or folder permissions from policies. The success of the action can be determined from ActionResult.

This function calls OH_FileShare_RevokePermission.

To persist permission, use persistPermission().

See also ActionResult, PathPolicy, and persistPermission().