• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2023 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_MANAGER_H_
17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_LIBRARY_MANAGER_H_
18 #define USERID "100"
19 
20 #include "datashare_helper.h"
21 #include "media_volume.h"
22 #include "pixel_map.h"
23 
24 namespace OHOS {
25 namespace Media {
26 using namespace std;
27 using namespace OHOS::DataShare;
28 
29 /**
30  * @brief Structure for defining the condition for fetching of files and albums
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 struct MediaFetchOptions {
36     /**
37      * @brief The Query condition based on which to fetch the files/albums
38      */
39     string selections;
40 
41     /**
42      * @brief List of values for columns mentioned in the selections query condition
43      */
44     vector<string> selectionArgs;
45 
46     /**
47      * @brief The column based on which the output will be sorted in ascending order
48      */
49     string order;
50 };
51 
52 /**
53  * @brief Interface for accessing all the File operation and AlbumAsset operation APIs
54  *
55  * @since 1.0
56  * @version 1.0
57  */
58 class MediaLibraryManager {
59 public:
60     MediaLibraryManager() = default;
61     virtual ~MediaLibraryManager() = default;
62 
63     /**
64      * @brief Returns the Media Library Manager Instance
65      *
66      * @return Returns the Media Library Manager Instance
67      * @since 1.0
68      * @version 1.0
69      */
70     static MediaLibraryManager *GetMediaLibraryManager();
71 
72     /**
73      * @brief Initializes the environment for Media Library Manager
74      *
75      * @param context The Ability context required for calling Data Ability Helper APIs
76      * @since 1.0
77      * @version 1.0
78      */
79     void InitMediaLibraryManager(const sptr<IRemoteObject> &token);
80 
81     /**
82      * @brief Close an opened file
83      *
84      * @param uri source uri of a file which is to be closed
85      * @param fd file descriptor for the file which is to be closed
86      * @return close status. <0> for success and <-1> for fail
87      * @since 1.0
88      * @version 1.0
89      */
90     int32_t CloseAsset(const string &uri, const int32_t fd);
91 
92     /**
93      * @brief Obtain a mediaVolume object from MediaAssets can be obtained
94      *
95      * @param MediaVolume MediaVolume for outValue
96      * @return errorcode
97      * @since 1.0
98      * @version 1.0
99      */
100     int32_t QueryTotalSize(MediaVolume &outMediaVolume);
101 
102     /**
103      * @brief Make a query from database
104      *
105      * @param columnName a column name in datebase
106      * @param value a parameter for input which is a uri or path
107      * @param columns query conditions
108      * @return query result
109      * @since 1.0
110      * @version 1.0
111      */
112     static std::shared_ptr<DataShareResultSet> GetResultSetFromDb(string columnName, const string &value,
113         vector<string> &columns);
114 
115     /**
116      * @brief get file path from uri
117      *
118      * @param fileUri a parameter for input  which is uri
119      * @param filePath a parameter for output  which is path
120      * @param userId  a parameter for user id
121      * @return errorcode
122      * @since 1.0
123      * @version 1.0
124      */
125     int32_t GetFilePathFromUri(const Uri &fileUri, std::string &filePath, string userId = USERID);
126 
127     /**
128      * @brief Obtain a mediaVolume object from MediaAssets can be obtained
129      *
130      * @param fileUri a parameter for output  which is uri
131      * @param filePath a parameter for input  which is path
132      * @param userId  a parameter for user id
133      * @return errorcode
134      * @since 1.0
135      * @version 1.0
136      */
137     int32_t GetUriFromFilePath(const std::string &filePath, Uri &fileUri, string &userId);
138 
139     std::unique_ptr<PixelMap> GetThumbnail(const Uri &uri);
140     static int OpenThumbnail(std::string &uriStr, const std::string &path, const Size &size);
141 
142 private:
143     static shared_ptr<DataShare::DataShareHelper> sDataShareHelper_;
144 };
145 } // namespace Media
146 } // namespace OHOS
147 
148 #endif  // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_LIBRARY_MANAGER_H_
149