• 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 of fromTokenId to targetTokenId.
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 fromTokenId The owner of uri.
35      * @param targetTokenId The user of uri.
36      */
37     virtual bool GrantUriPermission(const Uri &uri, unsigned int flag,
38         const Security::AccessToken::AccessTokenID fromTokenId,
39         const Security::AccessToken::AccessTokenID targetTokenId) = 0;
40 
41     /**
42      * @brief Check whether the tokenId has URI permissions.
43      *
44      * @param uri The file uri.
45      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
46      * @param tokenId The user of uri.
47      * @return Returns true if the verification is successful, otherwise returns false.
48      */
49     virtual bool VerifyUriPermission(const Uri &uri, unsigned int flag,
50         const Security::AccessToken::AccessTokenID tokenId) = 0;
51 
52     /**
53      * @brief Clear user's uri authorization record.
54      *
55      * @param tokenId A tokenId of an application.
56      */
57     virtual void RemoveUriPermission(const Security::AccessToken::AccessTokenID tokenId) = 0;
58 
59     enum UriPermMgrCmd {
60         // ipc id for GrantUriPermission
61         ON_GRANT_URI_PERMISSION = 0,
62 
63         // ipc id for VerifyUriPermission
64         ON_VERIFY_URI_PERMISSION,
65 
66         // ipc id for RemoveUriPermission
67         ON_REMOVE_URI_PERMISSION,
68     };
69 };
70 }  // namespace AAFwk
71 }  // namespace OHOS
72 #endif  // OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_INTERFACE_H
73