• 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 "opkey_version_ability.h"
17 
18 #include "core_service_client.h"
19 #include "data_storage_errors.h"
20 #include "data_storage_log_wrapper.h"
21 #include "new"
22 #include "opkey_version_result_set_bridge.h"
23 #include "parser_util.h"
24 #include "telephony_datashare_stub_impl.h"
25 #include "uri.h"
26 #include "utility"
27 
28 namespace OHOS {
29 namespace Telephony {
OpkeyVersionAbility()30 OpkeyVersionAbility::OpkeyVersionAbility() : DataShareExtAbility()
31 {
32     ParserUtil util;
33     util.GetJsonItemStringVaule(PARAM_CONFIG_PATH, "CARRIER_CONFIG", "cfgInfoUri", custParam_);
34     util.GetJsonItemStringVaule(PARAM_CONFIG_PATH, "NCFG_DEF_CONFIG", "cfgInfoUri", chipParam_);
35 }
36 
~OpkeyVersionAbility()37 OpkeyVersionAbility::~OpkeyVersionAbility() {}
38 
Create()39 OpkeyVersionAbility* OpkeyVersionAbility::Create()
40 {
41     auto self = new OpkeyVersionAbility();
42     return self;
43 }
44 
Query(const Uri & uri,const DataShare::DataSharePredicates & predicates,std::vector<std::string> & columns,DataShare::DatashareBusinessError & businessError)45 std::shared_ptr<DataShare::DataShareResultSet> OpkeyVersionAbility::Query(const Uri &uri,
46     const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns,
47     DataShare::DatashareBusinessError &businessError)
48 {
49     DATA_STORAGE_LOGD("start uri=%{public}s", uri.ToString().c_str());
50     std::string versionInfo;
51     int32_t ret = DATA_STORAGE_ERROR;
52     if (uri.ToString() == custParam_) {
53         ret = DelayedRefSingleton<CoreServiceClient>::GetInstance().GetOpkeyVersion(versionInfo);
54     } else if (uri.ToString() == chipParam_) {
55         ret = DelayedRefSingleton<CoreServiceClient>::GetInstance().GetOpnameVersion(versionInfo);
56     } else {
57         DATA_STORAGE_LOGW("uri not match");
58     }
59     if (ret != DATA_STORAGE_SUCCESS) {
60         DATA_STORAGE_LOGE("get versionInfo failed!");
61         return nullptr;
62     }
63     std::shared_ptr<DataShare::ResultSetBridge> resultSet =
64              std::make_shared<OpkeyVersionResultSetBridge>(versionInfo);
65     std::shared_ptr<DataShare::DataShareResultSet> sharedPtrResult =
66         std::make_shared<DataShare::DataShareResultSet>(resultSet);
67     return sharedPtrResult;
68 }
69 } // Telephony
70 } // OHOS