• 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 #ifndef FRAMEWORKS_SERVICES_MEDIA_LIBRARY_EXTENTION_UTILS_H_
16 #define FRAMEWORKS_SERVICES_MEDIA_LIBRARY_EXTENTION_UTILS_H_
17 
18 #include "abs_shared_result_set.h"
19 #include "file_access_extension_info.h"
20 #include "file_filter.h"
21 #include "uri.h"
22 
23 namespace OHOS {
24 namespace Media {
25 // parent id is root path
26 const int32_t ROOT_PARENT_ID = 0;
27 // device virtual root node
28 static const std::string MEDIALIBRARY_ROOT = "/root";
29 static const std::string MEDIALIBRARY_LOCAL_DEVICE_NAME = "LOCAL";
30 // mimetype prefix
31 const std::string DEFAULT_AUDIO_MIME_TYPE_PREFIX = "audio/";
32 const std::string DEFAULT_VIDEO_MIME_TYPE_PREFIX = "video/";
33 const std::string DEFAULT_IMAGE_MIME_TYPE_PREFIX = "image/";
34 const std::string DEFAULT_FILE_MIME_TYPE_PREFIX = "file/";
35 enum MediaFileUriType {
36     URI_ROOT,
37     URI_MEDIA_ROOT,
38     URI_FILE_ROOT,
39     URI_DIR,
40     URI_ALBUM,
41 };
42 class MediaFileExtentionUtils {
43 public:
44     static bool CheckUriValid(const std::string &uri);
45     static bool CheckDistributedUri(const std::string &uri);
46     static int32_t CheckUriSupport(const std::string &uri);
47     static int32_t ResolveUri(const FileAccessFwk::FileInfo &fileInfo, MediaFileUriType &uriType);
48     static bool CheckValidDirName(const std::string &displayName);
49     static int32_t CheckMkdirValid(MediaFileUriType uriType, const std::string &parentUriStr,
50         const std::string &displayName);
51     static bool GetAlbumRelativePathFromDB(const std::string &selectUri, const std::string &networkId,
52         std::string &relativePath);
53     static std::shared_ptr<NativeRdb::AbsSharedResultSet> GetFileFromDB(const std::string &selectUri,
54         const std::string &networkId);
55 
56     static int32_t OpenFile(const Uri &uri, const int flags, int &fd);
57     static int32_t CreateFile(const Uri &parentUri, const std::string &displayName,  Uri &newFileUri);
58     static int32_t Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri);
59     static int32_t Delete(const Uri &sourceFileUri);
60     static int32_t Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri);
61     static int32_t Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri);
62     static int32_t ListFile(const FileAccessFwk::FileInfo &parentInfo, const int64_t offset, const int64_t maxCount,
63         const DistributedFS::FileFilter &filter, std::vector<FileAccessFwk::FileInfo> &fileList);
64     static int32_t ScanFile(const FileAccessFwk::FileInfo &parentInfo, const int64_t offset, const int64_t maxCount,
65         const DistributedFS::FileFilter &filter, std::vector<FileAccessFwk::FileInfo> &fileList);
66     static int32_t GetRoots(std::vector<FileAccessFwk::RootInfo> &rootList);
67     static int Access(const Uri &uri, bool &isExist);
68 };
69 } // Media
70 } // OHOS
71 
72 #endif // FRAMEWORKS_SERVICES_MEDIA_LIBRARY_EXTENTION_UTILS_H_
73