• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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_FILE_URI_H_
17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_FILE_URI_H_
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include "medialibrary_db_const.h"
23 #include "uri.h"
24 #include "userfile_manager_types.h"
25 
26 namespace OHOS {
27 namespace Media {
28 #define EXPORT __attribute__ ((visibility ("default")))
29 enum {
30     API10_PHOTO_URI,
31     API10_PHOTOALBUM_URI,
32     API10_AUDIO_URI,
33     API9_URI,
34 };
35 
36 const std::string MEDIA_FILE_URI_EMPTY = "empty";
37 class MediaFileUri : public OHOS::Uri {
38     std::string networkId_ { MEDIA_FILE_URI_EMPTY };
39     std::string fileId_ { MEDIA_FILE_URI_EMPTY };
40     std::unordered_map<std::string, std::string> queryMap_;
41     std::string MediaFileUriConstruct(MediaType mediaType, const std::string &networkId, const std::string &fileId,
42                                       const int32_t &apiVersion, const std::string &extrUri);
43     int uriType_;
44     void ParseUri(const std::string& uri);
45 public:
MediaFileUri(const std::string & uriStr)46     EXPORT explicit MediaFileUri(const std::string &uriStr) : Uri(uriStr) {ParseUri(uriStr);}
47     EXPORT explicit MediaFileUri(MediaType mediaType,
48                           const std::string &fileId,
49                           const std::string &networkId = "",
50                           const int32_t &apiVersion = MEDIA_API_VERSION_V9,
Uri(MediaFileUriConstruct (mediaType,fileId,networkId,apiVersion,extrUri))51                           const std::string &extrUri = "") : Uri(
52                           MediaFileUriConstruct(mediaType, fileId, networkId, apiVersion, extrUri)) {}
53     EXPORT ~MediaFileUri() = default;
54 
55     EXPORT std::string GetNetworkId();
56     EXPORT std::string GetFileId();
57     EXPORT std::string GetFilePath();
58     EXPORT std::unordered_map<std::string, std::string> &GetQueryKeys();
59     EXPORT std::string GetTableName();
60     EXPORT bool IsValid();
61     EXPORT bool IsApi10();
62     EXPORT int GetUriType();
63     EXPORT static MediaType GetMediaTypeFromUri(const std::string &uri);
64     EXPORT static std::string GetPathFirstDentry(Uri &uri);
65     EXPORT static std::string GetPathSecondDentry(Uri &uri);
66     EXPORT static void RemoveAllFragment(std::string &uri);
67     EXPORT static std::string GetMediaTypeUri(MediaType mediaType, const int32_t &apiVersion);
68     EXPORT static std::string GetPhotoId(const std::string &uri);
69     EXPORT static void GetTimeIdFromUri(
70         const std::vector<std::string> &uriBatch, std::vector<std::string> &timeIdBatch);
71 };
72 } // namespace Media
73 } // namespace OHOS
74 
75 #endif  // INTERFACES_INNERKITS_NATIVE_INCLUDE_MEDIA_FILE_URI_H_
76