1 /*
2 * Copyright (C) 2023 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 "cellular_call_rdb_helper.h"
17
18 #include "telephony_errors.h"
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
23 static constexpr const char *GLOBAL_ECC_URI_SELECTION =
24 "datashare:///com.ohos.globalparamsability/globalparams/ecc_data";
25
CellularCallRdbHelper()26 CellularCallRdbHelper::CellularCallRdbHelper() : globalEccUri_(GLOBAL_ECC_URI_SELECTION) {}
27
28 CellularCallRdbHelper::~CellularCallRdbHelper() = default;
29
CreateDataAbilityHelper()30 std::shared_ptr<DataShare::DataShareHelper> CellularCallRdbHelper::CreateDataAbilityHelper()
31 {
32 TELEPHONY_LOGD("Create data ability helper");
33 sptr<ISystemAbilityManager> saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
34 if (saManager == nullptr) {
35 TELEPHONY_LOGE("CellularCallRdbHelper GetSystemAbilityManager failed.");
36 return nullptr;
37 }
38 sptr<IRemoteObject> remoteObj = saManager->GetSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
39 if (remoteObj == nullptr) {
40 TELEPHONY_LOGE("CellularCallRdbHelper GetSystemAbility Service Failed.");
41 return nullptr;
42 }
43 return DataShare::DataShareHelper::Creator(remoteObj, GLOBAL_PARAMS_URI);
44 }
45
QueryEccList(const std::string & numeric,std::vector<EccNum> & eccVec)46 int32_t CellularCallRdbHelper::QueryEccList(const std::string &numeric, std::vector<EccNum> &eccVec)
47 {
48 std::shared_ptr<DataShare::DataShareHelper> dataShareHelper = CreateDataAbilityHelper();
49 if (dataShareHelper == nullptr) {
50 TELEPHONY_LOGE("dataShareHelper is null");
51 return TELEPHONY_ERR_LOCAL_PTR_NULL;
52 }
53 std::vector<std::string> columns;
54 DataShare::DataSharePredicates predicates;
55 predicates.EqualTo(EccData::NUMERIC, numeric);
56 std::shared_ptr<DataShare::DataShareResultSet> result =
57 dataShareHelper->Query(globalEccUri_, predicates, columns);
58 if (result == nullptr) {
59 TELEPHONY_LOGE("CellularCallRdbHelper: query apns error");
60 dataShareHelper->Release();
61 return TELEPHONY_ERR_LOCAL_PTR_NULL;
62 }
63 int rowCnt = 0;
64 result->GetRowCount(rowCnt);
65 TELEPHONY_LOGD("CellularCallRdbHelper::query ecc_data rowCnt = %{public}d", rowCnt);
66 for (int32_t index = 0; index < rowCnt; index++) {
67 EccNum bean;
68 result->GoToRow(index);
69 result->GetColumnIndex(EccData::ID, index);
70 result->GetInt(index, bean.id);
71 result->GetColumnIndex(EccData::NAME, index);
72 result->GetString(index, bean.name);
73 result->GetColumnIndex(EccData::MCC, index);
74 result->GetString(index, bean.mcc);
75 result->GetColumnIndex(EccData::MNC, index);
76 result->GetString(index, bean.mnc);
77 result->GetColumnIndex(EccData::NUMERIC, index);
78 result->GetString(index, bean.numeric);
79 result->GetColumnIndex(EccData::ECC_WITH_CARD, index);
80 result->GetString(index, bean.ecc_withcard);
81 result->GetColumnIndex(EccData::ECC_NO_CARD, index);
82 result->GetString(index, bean.ecc_nocard);
83 result->GetColumnIndex(EccData::ECC_FAKE, index);
84 result->GetString(index, bean.ecc_fake);
85 eccVec.push_back(bean);
86 }
87 result->Close();
88 dataShareHelper->Release();
89 dataShareHelper = nullptr;
90 return TELEPHONY_SUCCESS;
91 }
92 } // namespace Telephony
93 } // namespace OHOS
94