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_DB_H
17 #define RINGTONE_SCANNER_DB_H
18 
19 #include "result_set.h"
20 #include "ringtone_data_command.h"
21 #include "ringtone_metadata.h"
22 #include "vibrate_metadata.h"
23 
24 namespace OHOS {
25 namespace Media {
26 #define EXPORT __attribute__ ((visibility ("default")))
27 class RingtoneScannerDb {
28 public:
29     EXPORT RingtoneScannerDb() = default;
30     EXPORT RingtoneScannerDb(RingtoneScannerDb &other) = delete;
31     EXPORT void operator=(const RingtoneScannerDb &) = delete;
32     EXPORT ~RingtoneScannerDb() = default;
33 
34     EXPORT static int32_t InsertMetadata(const RingtoneMetadata &metadata, std::string &tableName);
35     EXPORT static int32_t InsertVibrateMetadata(const VibrateMetadata &metadata, std::string &tableName);
36     EXPORT static int32_t UpdateMetadata(const RingtoneMetadata &metadata, std::string &tableName);
37     EXPORT static int32_t UpdateVibrateMetadata(const VibrateMetadata &metadata, std::string &tableName);
38     EXPORT static int32_t GetFileBasicInfo(const std::string &path, std::unique_ptr<RingtoneMetadata> &ptr);
39     EXPORT static int32_t GetVibrateFileBasicInfo(const std::string &path, std::unique_ptr<VibrateMetadata> &ptr);
40     EXPORT static int32_t UpdateRingtoneRdb(NativeRdb::ValuesBucket &values, const std::string &whereClause,
41          std::vector<std::string> &whereArgs, const std::string &tableName = RINGTONE_TABLE);
42     EXPORT static int32_t QueryRingtoneRdb(const std::string &whereClause, std::vector<std::string> &whereArgs,
43         const std::vector<std::string> &columns, std::shared_ptr<NativeRdb::ResultSet> &resultSet,
44         const std::string &tableName = RINGTONE_TABLE);
45     EXPORT static int32_t FillMetadata(const std::shared_ptr<NativeRdb::ResultSet> &resultSet,
46         std::unique_ptr<RingtoneMetadata> &ptr);
47     EXPORT static int32_t FillVibrateMetadata(const std::shared_ptr<NativeRdb::ResultSet> &resultSet,
48         std::unique_ptr<VibrateMetadata> &ptr);
49 private:
50     static bool InsertData(const NativeRdb::ValuesBucket values, const std::string &tableName, int32_t &rowNum);
51     static int32_t GetFileSet(RingtoneDataCommand &cmd, const std::vector<std::string> &columns,
52         std::shared_ptr<NativeRdb::ResultSet> &resultSet);
53     static void ExtractMetaFromColumn(const std::shared_ptr<NativeRdb::ResultSet> &resultSet,
54         std::unique_ptr<RingtoneMetadata> &metadata, const std::string &col);
55     static void ExtractVibrateMetaFromColumn(const std::shared_ptr<NativeRdb::ResultSet> &resultSet,
56         std::unique_ptr<VibrateMetadata> &metadata, const std::string &col);
57     static int32_t BuildToneSettingTypeQuery(ToneSettingType type, RingtoneDataCommand &cmd);
58     static int32_t GetToneSettingType(ToneSettingType type, std::vector<std::shared_ptr<RingtoneMetadata>> &metas);
59 };
60 } // namespace Media
61 } // namespace OHOS
62 #endif // RINGTONE_SCANNER_DB_H
63