• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_INTERFACE_H
18 
19 #include "base/security/access_token/interfaces/innerkits/accesstoken/include/access_token.h"
20 #include "iremote_broker.h"
21 #include "uri.h"
22 
23 namespace OHOS {
24 namespace AAFwk {
25 class IUriPermissionManager : public IRemoteBroker {
26 public:
27     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.ability.UriPermissionManager");
28 
29     /**
30      * @brief Authorize the uri permission to targetBundleName.
31      *
32      * @param uri The file uri.
33      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
34      * @param targetBundleName The user of uri.
35      * @param autoremove the uri is temperarily or not
36      * @return Returns true if the authorization is successful, otherwise returns false.
37      */
38     virtual int GrantUriPermission(const Uri &uri, unsigned int flag,
39         const std::string targetBundleName, int autoremove, int32_t appIndex = 0) = 0;
40 
41     /**
42      * @brief Clear user's uri authorization record with autoremove flag.
43      *
44      * @param tokenId A tokenId of an application.
45      * @return Returns true if the remove is successful, otherwise returns false.
46      */
47     virtual void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) = 0;
48 
49     /**
50      * @brief Clear user's all uri authorization record with autoremove flag.
51      *
52      * @param tokenId A tokenId of an application.
53      * @return Returns true if the remove is successful, otherwise returns false.
54      */
55     virtual int RevokeAllUriPermissions(const Security::AccessToken::AccessTokenID tokenId) = 0;
56 
57     /**
58      * @brief Clear user's uri authorization record.
59      *
60      * @param uri The file uri.
61      * @param bundleName bundleName of an application.
62      * @return Returns true if the remove is successful, otherwise returns false.
63      */
64     virtual int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) = 0;
65 
66     /**
67      * @brief check if caller can grant persistable uri permission
68      *
69      * @param uri The file uri.
70      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
71      * @param tokenId A tokenId of an application.
72      */
73     virtual bool CheckPersistableUriPermissionProxy(const Uri& uri, uint32_t flag, uint32_t tokenId) = 0;
74 
75     /**
76      * @brief verify if tokenId have uri permission of flag, including temporary permission and persistable permission
77      *
78      * @param uri The file uri.
79      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
80      * @param tokenId A tokenId of an application.
81      */
82     virtual bool VerifyUriPermission(const Uri& uri, uint32_t flag, uint32_t tokenId) = 0;
83 
84     enum UriPermMgrCmd {
85         // ipc id for GrantUriPermission
86         ON_GRANT_URI_PERMISSION = 0,
87 
88         // ipc id for RevokeUriPermission
89         ON_REVOKE_URI_PERMISSION,
90 
91         // ipc id for RevokeAllUriPermission
92         ON_REVOKE_ALL_URI_PERMISSION,
93 
94         ON_REVOKE_URI_PERMISSION_MANUALLY,
95 
96         // ipc id for CheckPersistableUriPermissionProxy
97         ON_CHECK_PERSISTABLE_URIPERMISSION_PROXY,
98 
99         // ipc id for VerifyUriPermission
100         ON_VERIFY_URI_PERMISSION,
101     };
102 };
103 }  // namespace AAFwk
104 }  // namespace OHOS
105 #endif  // OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_INTERFACE_H
106