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 "opkey_version_ability.h"
17 
18 #include "core_service_client.h"
19 #include "data_storage_log_wrapper.h"
20 #include "new"
21 #include "opkey_version_result_set_bridge.h"
22 #include "rdb_errno.h"
23 #include "telephony_datashare_stub_impl.h"
24 #include "telephony_errors.h"
25 #include "uri.h"
26 #include "utility"
27 
28 namespace OHOS {
29 namespace Telephony {
OpkeyVersionAbility()30 OpkeyVersionAbility::OpkeyVersionAbility() : DataShareExtAbility() {}
31 
~OpkeyVersionAbility()32 OpkeyVersionAbility::~OpkeyVersionAbility() {}
33 
Create()34 OpkeyVersionAbility* OpkeyVersionAbility::Create()
35 {
36     auto self = new OpkeyVersionAbility();
37     return self;
38 }
39 
Query(const Uri & uri,const DataShare::DataSharePredicates & predicates,std::vector<std::string> & columns,DataShare::DatashareBusinessError & businessError)40 std::shared_ptr<DataShare::DataShareResultSet> OpkeyVersionAbility::Query(const Uri &uri,
41     const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns,
42     DataShare::DatashareBusinessError &businessError)
43 {
44     DATA_STORAGE_LOGD("start");
45     std::string versionInfo;
46     int32_t ret = DelayedRefSingleton<CoreServiceClient>::GetInstance().GetOpkeyVersion(versionInfo);
47     if (ret != TELEPHONY_ERR_SUCCESS) {
48         DATA_STORAGE_LOGE("get versionInfo failed!");
49         return nullptr;
50     }
51     std::shared_ptr<DataShare::ResultSetBridge> resultSet =
52              std::make_shared<OpkeyVersionResultSetBridge>(versionInfo);
53     std::shared_ptr<DataShare::DataShareResultSet> sharedPtrResult =
54         std::make_shared<DataShare::DataShareResultSet>(resultSet);
55     return sharedPtrResult;
56 }
57 } // Telephony
58 } // OHOS