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_DUALFWK_RESTORE_H
17 #define RINGTONE_DUALFWK_RESTORE_H
18 
19 #include "datashare_helper.h"
20 #include "dualfwk_sound_setting.h"
21 #include "rdb_helper.h"
22 #include "result_set.h"
23 #include "ringtone_metadata.h"
24 #include "ringtone_restore_base.h"
25 #include "ringtone_restore_type.h"
26 #include "medialibrary_db_const.h"
27 
28 namespace OHOS {
29 namespace Media {
30 class RingtoneDualFwkRestore : public RingtoneRestoreBase {
31 public:
32     RingtoneDualFwkRestore() = default;
33     virtual ~RingtoneDualFwkRestore() = default;
34     int32_t Init(const std::string &backupPath) override;
35     int32_t StartRestore() override;
36 protected:
37     std::unique_ptr<DualFwkSoundSetting> dualFwkSetting_ = nullptr;
38 private:
39     virtual bool OnPrepare(FileInfo &info, const std::string &destPath) override;
40     virtual void OnFinished(std::vector<FileInfo> &infos) override;
41     virtual int32_t LoadDualFwkConf(const std::string &backupPath) override;
42     int32_t ParseDualFwkConf(const std::string &xml);
43     int32_t DupToneFile(FileInfo &info);
44     void UpdateRestoreFileInfo(FileInfo &info);
45     std::vector<FileInfo> BuildFileInfo();
46     int32_t QueryMediaLibForFileInfo(const std::vector<std::string> &names,
47         std::map<std::string, std::shared_ptr<FileInfo>> &infoMap,
48         const std::string &queryFileUriBase = UFM_QUERY_AUDIO,
49         const std::string &predicateColumn = MEDIA_DATA_DB_NAME);
50     int32_t QueryRingToneDbForFileInfo(std::shared_ptr<NativeRdb::RdbStore> rdbStore,
51         const std::vector<std::string> &names, std::map<std::string, std::shared_ptr<FileInfo>> &infoMap,
52         const std::string &predicateColumn = MEDIA_DATA_DB_NAME);
53 
54 private:
55     std::shared_ptr<DataShare::DataShareHelper> mediaDataShare_ = nullptr;
56     std::string dualFwkConf_ = {};
57 };
58 
59 class RingtoneDualFwkRestoreClone : public RingtoneDualFwkRestore {
60 private:
61     virtual int32_t LoadDualFwkConf(const std::string &backupPath) override;
62 };
63 } // namespace Media
64 } // namespace OHOS
65 #endif  // RINGTONE_DUALFWK_RESTORE_H
66