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 RINGTONE_SCANNER_UTILS_H
17 #define RINGTONE_SCANNER_UTILS_H
18 
19 #include <string>
20 #include <sys/stat.h>
21 
22 namespace OHOS {
23 namespace Media {
24 #define EXPORT __attribute__ ((visibility ("default")))
25 enum EXPORT ErrorCodes {
26     ERR_FAIL = -1,
27     ERR_SUCCESS,
28     ERR_EMPTY_ARGS,
29     ERR_NOT_ACCESSIBLE,
30     ERR_INCORRECT_PATH,
31     ERR_MEM_ALLOC_FAIL,
32     ERR_MIMETYPE_NOTSUPPORT,
33     ERR_SCAN_NOT_INIT
34 };
35 
36 const int32_t FILE_ID_DEFAULT = 0;
37 constexpr int32_t MAX_BATCH_SIZE = 5;
38 
39 constexpr int32_t UNKNOWN_ID = -1;
40 
41 const std::string DEFAULT_AUDIO_MIME_TYPE = "audio/*";
42 
43 static std::vector<std::string> EXTRACTOR_SUPPORTED_MIME = {
44     DEFAULT_AUDIO_MIME_TYPE,
45 };
46 
47 class RingtoneScannerUtils {
48 public:
49     EXPORT RingtoneScannerUtils();
50     EXPORT ~RingtoneScannerUtils();
51 
52     EXPORT static bool IsExists(const std::string &path);
53     EXPORT static std::string GetFileNameFromUri(const std::string &path);
54     EXPORT static std::string GetFileExtension(const std::string &path);
55     EXPORT static std::string GetParentPath(const std::string &path);
56     EXPORT static bool IsFileHidden(const std::string &path);
57 
58     EXPORT static bool IsDirectory(const std::string &path);
59     EXPORT static bool IsRegularFile(const std::string &path);
60 
61     EXPORT static std::string GetFileTitle(const std::string &displayName);
62     EXPORT static bool IsDirHiddenRecursive(const std::string &path);
63     EXPORT static bool IsDirHidden(const std::string &path);
64 };
65 } // namespace Media
66 } // namespace OHOS
67 
68 #endif // RINGTONE_SCANNER_UTILS_H
69