Qt for HarmonyOS/qtohosextras doc/FileShare Namespace: Difference between revisions
Created page with "<!-- Source: qtohosextras-fileshare.html --> <span id="fileshare-namespace"></span> = FileShare Namespace = <span class="small-subtitle">(QtOhosExtras::FileShare)<br /> </span> The FileShare to expose file permission API. More... <div class="table"> {| class="wikitable alignedsummary" |- | class="memItemLeft rightAlign topAlign"| Header: |..." |
No edit summary |
||
| (4 intermediate revisions 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 = | ||
The FileShare to expose file permission API. [[#details|More...]] | |||
The | |||
{| class="wikitable | {| class="wikitable" | ||
|- | |- | ||
! Header: | |||
| | | #include <FileShare> | ||
|- | |- | ||
! qmake: | |||
| QT += ohosextras | |||
|- | |- | ||
! Since: | |||
| Qt 5.12.12 | |||
|} | |} | ||
== Classes == | == Classes == | ||
{| class="wikitable" style="width:100%" | |||
|- | |- | ||
| class | | class || '''[[Qt for HarmonyOS/qtohosextras doc/ActionResult Class|ActionResult]]''' | ||
|- | |- | ||
| class | | class || '''[[Qt for HarmonyOS/qtohosextras doc/CheckResult Class|CheckResult]]''' | ||
|- | |- | ||
| class | | class || '''[[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]]''' | ||
|- | |- | ||
| class | | class || '''[[Qt for HarmonyOS/qtohosextras doc/PathPolicyCheckResult Class|PathPolicyCheckResult]]''' | ||
|- | |- | ||
| class | | class || '''[[Qt for HarmonyOS/qtohosextras doc/PathPolicyErrorInfo Class|PathPolicyErrorInfo]]''' | ||
|} | |} | ||
== Types == | == Types == | ||
{| class="wikitable" style="width:100%" | |||
|- | |- | ||
| enum || '''[[#OperationMode-enum|OperationMode]]''' { Read, Write } | |||
| | |||
|- | |- | ||
| flags || '''[[#OperationMode-enum|OperationModes]]''' | |||
| | |||
|- | |- | ||
| enum || '''[[#PathPolicyError-enum|PathPolicyError]]''' { Unknown, PersistenceForbidden, InvalidMode, InvalidPath, PermissionNotPersisted } | |||
| | |||
|} | |} | ||
== Functions == | == Functions == | ||
{| class="wikitable" style="width:100%" | |||
|- | |- | ||
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#activatePermission|activatePermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'') | |||
| | |||
|- | |- | ||
| QSharedPointer<QtOhosExtras::FileShare::CheckResult> || '''[[#checkPersistent|checkPersistent]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'') | |||
| | |||
|- | |- | ||
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#deactivatePermission|deactivatePermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'') | |||
| | |||
|- | |- | ||
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> || '''[[#persistPermission|persistPermission]]'''(const QList<QtOhosExtras::FileShare::PathPolicy> &''policies'') | |||
| | |||
|- | |- | ||
| const QMetaObject * || '''[[#qt_getEnumMetaObject|qt_getEnumMetaObject]]'''(QtOhosExtras::FileShare::OperationMode) | |||
| | |||
|- | |- | ||
| 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 == | |||
<span id="details"></span> | <span id="details"></span> | ||
The FileShare to expose file permission API. | |||
The | |||
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 129: | Line 77: | ||
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: [[ | '''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. | ||
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]. | ||
== Type Documentation == | == Type Documentation == | ||
=== <span id="OperationMode-enum"></span>enum FileShare::OperationMode === | |||
=== <span id="OperationMode-enum"></span>enum FileShare::<span | === <span id="OperationModes-flags"></span>flags FileShare::OperationModes === | ||
flags FileShare:: | |||
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" | |||
! Constant !! Value !! Description | |||
{| class="wikitable | |||
! | |||
! | |||
! | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::Read</code> || <code>1 << 0</code> || Read on path | |||
| | |||
| | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::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 | The OperationModes type is a typedef for QFlags<OperationMode>. It stores an OR combination of OperationMode values. | ||
'''See also''' [[ | '''See also:''' [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]]. | ||
=== <span id="PathPolicyError-enum"></span>enum FileShare::PathPolicyError === | |||
=== <span id="PathPolicyError-enum"></span>enum FileShare:: | |||
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" | |||
! Constant !! Value !! Description | |||
{| class="wikitable | |||
! | |||
! | |||
! | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::Unknown</code> || 0 || Error type is unknown or not recognized | |||
| | |||
| | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::PersistenceForbidden</code> || 1 || The permission on the path cannot be persisted | |||
| | |||
| | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::InvalidMode</code> || 2 || Invalid operation mode | |||
| | |||
| | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::InvalidPath</code> || 3 || Invalid path | |||
| | |||
| | |||
|- | |- | ||
| <code>QtOhosExtras::FileShare::PermissionNotPersisted</code> || 4 || 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''' [[ | '''See also:''' [[Qt for HarmonyOS/qtohosextras doc/PathPolicyErrorInfo Class|PathPolicyErrorInfo]]. | ||
== Function Documentation == | |||
</ | === <span id="activatePermission"></span>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_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. | |||
To deactivate an active permission, use [[#deactivatePermission|deactivatePermission()]]. | |||
'''See also:''' [[ActionResult_Class|ActionResult]], [[PathPolicy_Struct|PathPolicy]], [[#persistPermission|persistPermission()]], and [[#deactivatePermission|deactivatePermission()]]. | |||
=== <span id="checkPersistent"></span>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_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]. | |||
To persist permission, use [[#persistPermission|persistPermission()]]. | |||
'''See also:''' [[CheckResult_Class|CheckResult]], [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]], and [[#persistPermission|persistPermission()]]. | |||
=== <span id="deactivatePermission"></span>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_Class|ActionResult]]. | |||
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()]]. | |||
'''See also:''' [[ActionResult_Class|ActionResult]], [[PathPolicy_Struct|PathPolicy]], and [[#activatePermission|activatePermission()]]. | |||
< | === <span id="persistPermission"></span>QSharedPointer<ActionResult> FileShare::persistPermission(const QList<PathPolicy> &''policies'') === | ||
QSharedPointer< | |||
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# | 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 | To revoke a persistent permission, use [[#revokePermission|revokePermission()]]. | ||
'''See also''' [[ | '''See also:''' [[ActionResult_Class|ActionResult]], [[Qt for HarmonyOS/qtohosextras doc/PathPolicy Class|PathPolicy]], [[#revokePermission|revokePermission()]], and [[#activatePermission|activatePermission()]]. | ||
<span id=" | === <span id="qt_getEnumMetaObject"></span>const QMetaObject *FileShare::qt_getEnumMetaObject(QtOhosExtras::FileShare::OperationMode) === | ||
=== <span id="qt_getEnumName"></span>const char *FileShare::qt_getEnumName(QtOhosExtras::FileShare::OperationMode) === | |||
=== <span id="revokePermission"></span>QSharedPointer<ActionResult> FileShare::revokePermission(const QList<PathPolicy> &''policies'') === | |||
=== <span id=" | |||
Revokes 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_revokepermission OH_FileShare_RevokePermission]. | |||
To persist permission, use [[#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"></span> | === <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'') === | ||
[[Category:Qt for HarmonyOS]] | |||
Latest revision as of 08:12, 29 January 2026
The FileShare to expose file permission API. More...
| Header: | #include <FileShare> |
|---|---|
| qmake: | QT += ohosextras |
| Since: | Qt 5.12.12 |
Classes
| class | ActionResult |
| class | CheckResult |
| class | PathPolicy |
| class | PathPolicyCheckResult |
| class | PathPolicyErrorInfo |
Types
| enum | OperationMode { Read, Write } |
| flags | OperationModes |
| enum | PathPolicyError { Unknown, PersistenceForbidden, InvalidMode, InvalidPath, PermissionNotPersisted } |
Functions
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> | activatePermission(const QList<QtOhosExtras::FileShare::PathPolicy> &policies) |
| QSharedPointer<QtOhosExtras::FileShare::CheckResult> | checkPersistent(const QList<QtOhosExtras::FileShare::PathPolicy> &policies) |
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> | deactivatePermission(const QList<QtOhosExtras::FileShare::PathPolicy> &policies) |
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> | persistPermission(const QList<QtOhosExtras::FileShare::PathPolicy> &policies) |
| const QMetaObject * | qt_getEnumMetaObject(QtOhosExtras::FileShare::OperationMode) |
| const char * | qt_getEnumName(QtOhosExtras::FileShare::OperationMode) |
| QSharedPointer<QtOhosExtras::FileShare::ActionResult> | revokePermission(const QList<QtOhosExtras::FileShare::PathPolicy> &policies) |
| QFlags<OperationModes::enum_type> | operator\|(OperationModes::enum_type f1, OperationModes::enum_type f2) |
| QFlags<OperationModes::enum_type> | operator\|(OperationModes::enum_type f1, QFlags<OperationModes::enum_type> f2) |
| QIncompatibleFlag | operator\|(OperationModes::enum_type f1, int f2) |
Detailed Description
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
/data/storage/el1/bundle/entry/resources/resfile/test.txtwill be converted to the URI
file://com.your.example/data/storage/el1/bundle/entry/resources/resfile/test.txt, where
com.your.exampleis 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.
Type Documentation
Defines permissions on path. See FileShare_OperationMode. The flags can be combined using bitwise operations.
| Constant | Value | Description |
|---|---|---|
QtOhosExtras::FileShare::Read |
1 << 0 |
Read on path |
QtOhosExtras::FileShare::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.
Defines permission policy error codes. See FileShare_PolicyErrorCode.
| Constant | Value | Description |
|---|---|---|
QtOhosExtras::FileShare::Unknown |
0 | Error type is unknown or not recognized |
QtOhosExtras::FileShare::PersistenceForbidden |
1 | The permission on the path cannot be persisted |
QtOhosExtras::FileShare::InvalidMode |
2 | Invalid operation mode |
QtOhosExtras::FileShare::InvalidPath |
3 | Invalid path |
QtOhosExtras::FileShare::PermissionNotPersisted |
4 | The permission is not persisted |
This enum was introduced or modified in Qt 5.12.12.
See also: PathPolicyErrorInfo.
Function Documentation
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().
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,
falseotherwise.
This function calls OH_FileShare_CheckPersistentPermission.
To persist permission, use persistPermission().
See also: CheckResult, PathPolicy, and persistPermission().
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().
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().
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().