• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_LIBRARY_EXTEND_MANAGER_H_
17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_LIBRARY_EXTEND_MANAGER_H_
18 #define USERID "100"
19 
20 #include "datashare_helper.h"
21 #include "unique_fd.h"
22 
23 namespace OHOS {
24 namespace Media {
25 using namespace std;
26 using namespace OHOS::DataShare;
27 #define EXPORT __attribute__ ((visibility ("default")))
28 /**
29  * @brief Interface for accessing all the File operation and AlbumAsset operation APIs
30  *
31  * @since 1.0
32  * @version 1.0
33  */
34 enum class PhotoPermissionType : int32_t {
35     TEMPORARY_READ_IMAGEVIDEO = 0,
36     PERSIST_READ_IMAGEVIDEO,
37     TEMPORARY_WRITE_IMAGEVIDEO,
38     TEMPORARY_READWRITE_IMAGEVIDEO,
39     PERSIST_READWRITE_IMAGEVIDEO, // Internal reserved value, not open to the public
40     PERSIST_WRITE_IMAGEVIDEO,
41     GRANT_PERSIST_READWRITE_IMAGEVIDEO,
42 };
43 
44 enum class HideSensitiveType : int32_t {
45     ALL_DESENSITIZE = 0,
46     GEOGRAPHIC_LOCATION_DESENSITIZE,
47     SHOOTING_PARAM_DESENSITIZE,
48     NO_DESENSITIZE
49 };
50 
51 enum class OperationMode : uint32_t {
52     READ_MODE = 0b01,
53     WRITE_MODE = 0b10,
54     READ_WRITE_MODE = 0b11,
55 };
56 
57 class MediaLibraryExtendManager {
58 public:
59     EXPORT MediaLibraryExtendManager() = default;
60     EXPORT virtual ~MediaLibraryExtendManager() = default;
61 
62     /**
63      * @brief Returns the Media Library Manager Extend Instance
64      *
65      * @return Returns the Media Library Manager Extend Instance
66      * @since 1.0
67      * @version 1.0
68      */
69     EXPORT static MediaLibraryExtendManager *GetMediaLibraryExtendManager();
70 
71     /**
72      * @brief Initializes the environment for Media Library Extend Manager
73      *
74      * @since 1.0
75      * @version 1.0
76      */
77     EXPORT void InitMediaLibraryExtendManager();
78 
79     /**
80      * @brief Check PhotoUri Permission
81      *
82      * @param tokenId a parameter for input, indicating the expected app's tokenId to check
83      * @param urisSource a parameter for input, indicating the source of URIs expected to check
84      * @param result a parameter for output, indicating the check result (permission granted or not)
85      * @param flags a parameter for input, indicating the expected type of permission check
86      * @return If the check is successful, return 0; otherwise, return -1 for failure.
87      */
88     EXPORT int32_t CheckPhotoUriPermission(uint32_t tokenId,
89         const std::vector<string> &urisSource, std::vector<bool> &result, const std::vector<uint32_t> &flags);
90 
91     /**
92      * @brief Grant PhotoUri Permission
93      *
94      * @param strTokenId a parameter for input, indicating the calling sourceTokenId
95      * @param targetTokenId a parameter for input, indicating the calling targetTokenId
96      * @param uris a parameter for input, indicating the uris expected to grant permission
97      * @param photoPermissionTypes a parameter for input, indicating the expected grant permission type for photos
98      * @param hideSensitiveType a parameter for input, indicating the expected grant hideSensitiveType
99      * @return If the grant is successful, return 0; otherwise, return -1 for failure.
100      */
101     EXPORT int32_t GrantPhotoUriPermission(uint32_t srcTokenId, uint32_t targetTokenId, const std::vector<string> &uris,
102         const std::vector<PhotoPermissionType> &photoPermissionTypes, HideSensitiveType hideSensitiveTpye);
103 
104     /**
105      * @brief Cancel PhotoUri Permission
106      *
107      * @param strTokenId a parameter for input, indicating the calling sourceTokenId
108      * @param targetTokenId a parameter for input, indicating the calling targetTokenId
109      * @param uris a parameter for input, indicating the uris expected to grant permission
110      * @param persistFlag a parameter for cancel persist_permission or temporary_permission
111      * @param OperationMode a parameter for cancel read_permission or write_permission
112      * @return If the cancel is successful, return 0; otherwise, return -1 for failure.
113      */
114     EXPORT int32_t CancelPhotoUriPermission(uint32_t srcTokenId, uint32_t targetTokenId,
115         const std::vector<string> &uris, const bool persistFlag = false,
116         const std::vector<OperationMode> &mode = {OperationMode::READ_WRITE_MODE});
117 
118     /**
119      * @brief open photo or video
120      *
121      * @param uri uri of the asset
122      * @param openMode openMode "rw", "w", "r"
123      * @param type force sensitive type
124      * @return fileDescriptor for success and <-1> for fail
125      * @since 1.0
126      * @version 1.0
127      */
128     EXPORT int32_t OpenAsset(string &uri, const string openMode, HideSensitiveType type);
129 
130     /**
131      * @brief Open private moving photo to read
132      *
133      * @param uri asset uri of the moving photo
134      * @param type force type
135      * @return read fd for success and <-1> for fail
136      */
137     EXPORT int32_t ReadPrivateMovingPhoto(string &uri, const HideSensitiveType type);
138 
139     /**
140      * @brief query photo by condition of input
141      *
142      * @param value asset uri
143      * @param columns result columns
144      * @return resultset of query
145      */
146     EXPORT std::shared_ptr<DataShare::DataShareResultSet> GetResultSetFromPhotos(const string &value,
147         vector<string> &columns);
148 
149     /**
150      * @brief query photo by condition of input
151      *
152      * @param columnName query columnName
153      * @param value query condition
154      * @param columns result columns
155      * @return resultset of query
156      */
157     EXPORT std::shared_ptr<DataShare::DataShareResultSet> GetResultSetFromDb(string columnName,
158         const string &value, vector<string> &columns);
159 
160     /**
161      * @brief check if the application has the corresponding permissions for uris
162      *
163      * @param targetTokenld token of the target application
164      * @param uris query the list of uris
165      * @param photoPermissionType permission type to be queried
166      * @param result boolean result with permission or not
167      * @return container for Boolean Results
168      */
169     EXPORT int32_t GetPhotoUrisPermission(uint32_t targetTokenld, const std::vector<string> &uris,
170         const std::vector<PhotoPermissionType> &photoPermissionTypes, std::vector<bool> &result);
171 
172     /**
173      * @brief convert path to URI
174      *
175      * @param paths path
176      * @param uris uri
177      * @return container converted to URI
178      */
179     EXPORT int32_t GetUrisFromFusePaths(const std::vector<std::string> paths, std::vector<std::string> &uris);
180 private:
181 
182     int32_t userId_;
183     shared_ptr<DataShare::DataShareHelper> dataShareHelper_;
184     int32_t GetPhotoUrisPermission(uint32_t targetTokenId, const std::vector<string> &uris,
185         PhotoPermissionType photoPermissionType, std::vector<bool> &result);
186     bool ForceReconnect();
187     int32_t QueryGrantedIndex(uint32_t targetTokenId, const std::string &uriType, const std::vector<string> &fileIds,
188         std::map<std::string, pair<bool, bool>> &permissionMap, uint32_t businessCode);
189 };
190 } // namespace Media
191 } // namespace OHOS
192 
193 #endif  // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_LIBRARY_EXTEND_MANAGER_H_