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 #include "ringtone_source.h"
17
18 #include "ringtone_db_const.h"
19
20 using namespace std;
21
22 namespace OHOS {
23 namespace Media {
24
25 const string RingtoneRestoreRdbOpenCb::CREATE_RINGTONE_TABLE = "CREATE TABLE IF NOT EXISTS " + RINGTONE_TABLE + "(" +
26 RINGTONE_COLUMN_TONE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
27 RINGTONE_COLUMN_DATA + " TEXT , " +
28 RINGTONE_COLUMN_SIZE + " BIGINT DEFAULT 0, " +
29 RINGTONE_COLUMN_DISPLAY_NAME + " TEXT , " +
30 RINGTONE_COLUMN_TITLE + " TEXT , " +
31 RINGTONE_COLUMN_MEDIA_TYPE + " INT DEFAULT 0, " +
32 RINGTONE_COLUMN_TONE_TYPE + " INT DEFAULT 0, " +
33 RINGTONE_COLUMN_MIME_TYPE + " TEXT , " +
34 RINGTONE_COLUMN_SOURCE_TYPE + " INT DEFAULT 0, " +
35 RINGTONE_COLUMN_DATE_ADDED + " BIGINT DEFAULT 0, " +
36 RINGTONE_COLUMN_DATE_MODIFIED + " BIGINT DEFAULT 0, " +
37 RINGTONE_COLUMN_DATE_TAKEN + " BIGINT DEFAULT 0, " +
38 RINGTONE_COLUMN_DURATION + " INT DEFAULT 0, " +
39 RINGTONE_COLUMN_SHOT_TONE_TYPE + " INT DEFAULT 0, " +
40 RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
41 RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE + " INT DEFAULT 0, " +
42 RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
43 RINGTONE_COLUMN_RING_TONE_TYPE + " INT DEFAULT 0, " +
44 RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
45 RINGTONE_COLUMN_ALARM_TONE_TYPE + " INT DEFAULT 0, " +
46 RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
47 RINGTONE_COLUMN_SCANNER_FLAG + " INT DEFAULT 0 " + ")";
48
OnCreate(NativeRdb::RdbStore & store)49 int RingtoneRestoreRdbOpenCb::OnCreate(NativeRdb::RdbStore &store)
50 {
51 return store.ExecuteSql(CREATE_RINGTONE_TABLE);
52 }
53
OnUpgrade(NativeRdb::RdbStore & store,int oldVersion,int newVersion)54 int RingtoneRestoreRdbOpenCb::OnUpgrade(NativeRdb::RdbStore &store, int oldVersion, int newVersion)
55 {
56 return 0;
57 }
58
OnCreate(NativeRdb::RdbStore & store)59 int RingtoneLocalRdbOpenCb::OnCreate(NativeRdb::RdbStore &store)
60 {
61 return 0;
62 }
63
OnUpgrade(NativeRdb::RdbStore & store,int oldVersion,int newVersion)64 int RingtoneLocalRdbOpenCb::OnUpgrade(NativeRdb::RdbStore &store, int oldVersion, int newVersion)
65 {
66 return 0;
67 }
68
Init(const std::string & restoreDbPath,const std::string & localDbPath)69 void RingtoneSource::Init(const std::string &restoreDbPath, const std::string &localDbPath)
70 {
71 int errCode = 0;
72 NativeRdb::RdbStoreConfig localRdbConfig(localDbPath);
73 RingtoneLocalRdbOpenCb localDbHelper;
74 localRdbPtr_ = NativeRdb::RdbHelper::GetRdbStore(localRdbConfig, 1, localDbHelper, errCode);
75 NativeRdb::RdbStoreConfig restoreRdbConfig(restoreDbPath);
76 RingtoneRestoreRdbOpenCb restoreDbHelper;
77 restoreRdbPtr_ = NativeRdb::RdbHelper::GetRdbStore(restoreRdbConfig, 1, restoreDbHelper, errCode);
78 InitRingtoneDb();
79 }
80
InitRingtoneDb()81 void RingtoneSource::InitRingtoneDb()
82 {
83 restoreRdbPtr_->ExecuteSql("INSERT INTO " + RINGTONE_TABLE +
84 " VALUES (last_insert_rowid()+1, '/data/storage/el2/base/files/Ringtone/alarms/Adara.ogg'," +
85 " 10414, 'Adara.ogg', 'Adara', 2, 0, 'audio/ogg', 2, 1505707241000, 1505707241846, 1505707241," +
86 " 600, 0, -1, 0, -1, 0, -1, 1, 2, 0)");
87 restoreRdbPtr_->ExecuteSql("INSERT INTO " + RINGTONE_TABLE +
88 " VALUES (last_insert_rowid()+1, '/data/storage/el2/base/files/Ringtone/ringtones/Carme.ogg'," +
89 " 26177, 'Carme.ogg', 'Carme', 2, 1, 'audio/ogg', 2, 1505707241000, 1505707241846, 1505707241," +
90 " 1242, 0, -1, 0, -1, 3, 2, 0, -1, 0)");
91 restoreRdbPtr_->ExecuteSql("INSERT INTO " + RINGTONE_TABLE +
92 " VALUES (last_insert_rowid()+1, '/data/storage/el2/base/files/Ringtone/notifications/Radon.ogg'," +
93 " 25356, 'Radon.ogg', 'Radon', 2, 2, 'audio/ogg', 2, 1505707241000, 1505707241846, 1505707241," +
94 " 1800, 0, -1, 1, 2, 0, -1, 0, -1, 0)");
95 restoreRdbPtr_->ExecuteSql("INSERT INTO " + RINGTONE_TABLE +
96 " VALUES (last_insert_rowid()+1, '/data/storage/el2/base/files/Ringtone/notifications/Titan.ogg'," +
97 " 30984, 'Titan.ogg', 'Titan', 2, 2, 'audio/ogg', 2, 1505707241000, 1505707241846, 1505707241," +
98 " 1947, 3, 2, 0, -1, 0, -1, 0, -1, 0)");
99 }
100 } // namespace Media
101 } // namespace OHOS