• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_data_command.h"
17 
18 #include "rdb_utils.h"
19 #include "ringtone_errno.h"
20 #include "ringtone_log.h"
21 #include "ringtone_utils.h"
22 
23 namespace OHOS {
24 namespace Media {
25 using namespace std;
26 using namespace OHOS::NativeRdb;
27 using namespace OHOS::DataShare;
28 
RingtoneDataCommand(const Uri & uri,const string & table,const RingtoneOperationType type)29 RingtoneDataCommand::RingtoneDataCommand(const Uri &uri, const string &table, const RingtoneOperationType type)
30     : uri_(uri), tableName_(table), oprnType_(type)
31 {
32     toneId_ = -1;
33 }
34 
~RingtoneDataCommand()35 RingtoneDataCommand::~RingtoneDataCommand() {}
36 
37 // set functions
SetDataSharePred(const DataShare::DataSharePredicates & pred)38 void RingtoneDataCommand::SetDataSharePred(const DataShare::DataSharePredicates &pred)
39 {
40     datasharePred_ = make_unique<const DataSharePredicates>(pred);
41 }
42 
SetValueBucket(const NativeRdb::ValuesBucket & value)43 void RingtoneDataCommand::SetValueBucket(const NativeRdb::ValuesBucket &value)
44 {
45     insertValue_ = value;
46 }
47 
SetBundleName(const string & bundleName)48 void RingtoneDataCommand::SetBundleName(const string &bundleName)
49 {
50     bundleName_ = bundleName;
51 }
52 
SetResult(const string & result)53 void RingtoneDataCommand::SetResult(const string &result)
54 {
55     result_ = result;
56 }
57 
58 // get functions
GetValueBucket()59 ValuesBucket &RingtoneDataCommand::GetValueBucket()
60 {
61     return insertValue_;
62 }
63 
GetAbsRdbPredicates()64 AbsRdbPredicates *RingtoneDataCommand::GetAbsRdbPredicates()
65 {
66     if (absRdbPredicates_ == nullptr) {
67         absRdbPredicates_ = make_unique<RdbPredicates>(tableName_);
68     }
69     return absRdbPredicates_.get();
70 }
71 
GetTableName()72 const string &RingtoneDataCommand::GetTableName()
73 {
74     return tableName_;
75 }
76 
GetUri() const77 const Uri &RingtoneDataCommand::GetUri() const
78 {
79     return uri_;
80 }
81 
GetBundleName()82 const string &RingtoneDataCommand::GetBundleName()
83 {
84     return bundleName_;
85 }
86 
GetResult()87 const string &RingtoneDataCommand::GetResult()
88 {
89     return result_;
90 }
91 
GetToneIdFromUri(Uri & uri)92 int32_t RingtoneDataCommand::GetToneIdFromUri(Uri &uri)
93 {
94     string uriStr = uri.ToString();
95     if (uriStr.empty()) {
96         return E_INVALID_URI;
97     }
98 
99     auto toneId = uriStr.substr(RINGTONE_PATH_URI.size(), uriStr.size());
100     if (RingtoneUtils::IsNumber(toneId)) {
101         RINGTONE_INFO_LOG("Get toneId=%{public}s from Uri", toneId.c_str());
102         return stoi(toneId);
103     }
104 
105     return E_INVALID_URI;
106 }
107 
GetOprnType() const108 RingtoneOperationType RingtoneDataCommand::GetOprnType() const
109 {
110     return oprnType_;
111 }
112 } // namespace Media
113 } // namespace OHOS
114