1 /*
2 * Copyright (c) 2021-2022 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 "pdp_profile_ability.h"
17
18 #include "ability_context.h"
19 #include "ability_loader.h"
20 #include "abs_rdb_predicates.h"
21 #include "abs_shared_result_set.h"
22 #include "core_service_client.h"
23 #include "data_storage_errors.h"
24 #include "data_storage_log_wrapper.h"
25 #include "datashare_ext_ability.h"
26 #include "datashare_predicates.h"
27 #include "new"
28 #include "pdp_profile_data.h"
29 #include "permission_util.h"
30 #include "preferences_util.h"
31 #include "rdb_errno.h"
32 #include "rdb_utils.h"
33 #include "string_ex.h"
34 #include "telephony_datashare_stub_impl.h"
35 #include "uri.h"
36 #include "utility"
37
38 namespace OHOS {
39 using AppExecFwk::Ability;
40 using AppExecFwk::AbilityLoader;
41 namespace Telephony {
42 const int32_t CHANGED_ROWS = 0;
43 static const std::map<std::string, PdpProfileUriType> pdpProfileUriMap_ = {
44 { "/net/pdp_profile", PdpProfileUriType::PDP_PROFILE },
45 { "/net/pdp_profile/init", PdpProfileUriType::INIT},
46 { "/net/pdp_profile/reset", PdpProfileUriType::RESET },
47 { "/net/pdp_profile/preferapn", PdpProfileUriType::PREFER_APN },
48 };
49
PdpProfileAbility()50 PdpProfileAbility::PdpProfileAbility() : DataShareExtAbility() {}
51
~PdpProfileAbility()52 PdpProfileAbility::~PdpProfileAbility() {}
53
Create()54 PdpProfileAbility* PdpProfileAbility::Create()
55 {
56 DATA_STORAGE_LOGD("PdpProfileAbility::Create begin.");
57 auto self = new PdpProfileAbility();
58 self->DoInit();
59 return self;
60 }
61
DoInit()62 void PdpProfileAbility::DoInit()
63 {
64 if (initDatabaseDir && initRdbStore) {
65 DATA_STORAGE_LOGE("DoInit has done");
66 return;
67 }
68 auto abilityContext = AbilityRuntime::Context::GetApplicationContext();
69 if (abilityContext == nullptr) {
70 DATA_STORAGE_LOGE("DoInit GetAbilityContext is null");
71 return;
72 }
73 // switch database dir to el1 for init before unlock
74 abilityContext->SwitchArea(0);
75 std::string path = abilityContext->GetDatabaseDir();
76 if (!path.empty()) {
77 initDatabaseDir = true;
78 path.append("/");
79 helper_.UpdateDbPath(path);
80 int rdbInitCode = helper_.Init();
81 if (rdbInitCode == NativeRdb::E_OK) {
82 initRdbStore = true;
83 } else {
84 DATA_STORAGE_LOGE("DoInit rdb init fail!");
85 initRdbStore = false;
86 }
87 } else {
88 DATA_STORAGE_LOGE("DoInit##databaseDir is empty!");
89 initDatabaseDir = false;
90 }
91 }
92
OnConnect(const AAFwk::Want & want)93 sptr<IRemoteObject> PdpProfileAbility::OnConnect(const AAFwk::Want &want)
94 {
95 DATA_STORAGE_LOGI("PdpProfileAbility %{public}s begin.", __func__);
96 Extension::OnConnect(want);
97 sptr<DataShare::TelephonyDataShareStubImpl> remoteObject =
98 new (std::nothrow) DataShare::TelephonyDataShareStubImpl();
99 if (remoteObject == nullptr) {
100 DATA_STORAGE_LOGE("%{public}s No memory allocated for DataShareStubImpl", __func__);
101 return nullptr;
102 }
103 remoteObject->SetPdpProfileAbility(std::static_pointer_cast<PdpProfileAbility>(shared_from_this()));
104 DATA_STORAGE_LOGI("PdpProfileAbility %{public}s end.", __func__);
105 return remoteObject->AsObject();
106 }
107
OnStart(const AppExecFwk::Want & want)108 void PdpProfileAbility::OnStart(const AppExecFwk::Want &want)
109 {
110 DATA_STORAGE_LOGI("PdpProfileAbility::OnStart");
111 Extension::OnStart(want);
112 DoInit();
113 }
114
BatchInsert(const Uri & uri,const std::vector<DataShare::DataShareValuesBucket> & values)115 int PdpProfileAbility::BatchInsert(const Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values)
116 {
117 if (!PermissionUtil::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
118 DATA_STORAGE_LOGE("Permission denied!");
119 return DATA_STORAGE_ERR_PERMISSION_ERR;
120 }
121 if (!IsInitOk()) {
122 return DATA_STORAGE_ERROR;
123 }
124 Uri tempUri = uri;
125 PdpProfileUriType pdpProfileUriType = ParseUriType(tempUri);
126 int result = DATA_STORAGE_ERROR;
127 if (pdpProfileUriType == PdpProfileUriType::INIT && !values.empty()) {
128 for (const auto &item : values) {
129 OHOS::NativeRdb::ValuesBucket valuesBucket = RdbDataShareAdapter::RdbUtils::ToValuesBucket(item);
130 int slotId = 0;
131 if (GetIntFromValuesBucket(valuesBucket, "slotId", slotId) != NativeRdb::E_OK) {
132 continue;
133 }
134 std::string opkey;
135 GetTargetOpkey(slotId, opkey);
136 result = helper_.InitAPNDatabase(slotId, opkey, true);
137 DATA_STORAGE_LOGI(
138 "PdpProfileAbility::BatchInsert INIT, slotId = %{public}d, result = %{public}d", slotId, result);
139 }
140 }
141 return result;
142 }
143
Insert(const Uri & uri,const DataShare::DataShareValuesBucket & value)144 int PdpProfileAbility::Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value)
145 {
146 if (!PermissionUtil::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
147 DATA_STORAGE_LOGE("Permission denied!");
148 return DATA_STORAGE_ERR_PERMISSION_ERR;
149 }
150 if (!IsInitOk()) {
151 return DATA_STORAGE_ERROR;
152 }
153 std::lock_guard<std::mutex> guard(lock_);
154 Uri tempUri = uri;
155 PdpProfileUriType pdpProfileUriType = ParseUriType(tempUri);
156 int64_t id = DATA_STORAGE_ERROR;
157 if (pdpProfileUriType == PdpProfileUriType::PDP_PROFILE) {
158 OHOS::NativeRdb::ValuesBucket values = RdbDataShareAdapter::RdbUtils::ToValuesBucket(value);
159 helper_.Insert(id, values, TABLE_PDP_PROFILE);
160 } else {
161 DATA_STORAGE_LOGE("PdpProfileAbility::Insert##uri = %{public}s", uri.ToString().c_str());
162 }
163 return id;
164 }
165
GetQueryKey(const std::string & queryString,const std::string & key)166 std::string PdpProfileAbility::GetQueryKey(const std::string &queryString, const std::string &key)
167 {
168 size_t pos = queryString.find(key);
169 if (pos != std::string::npos) {
170 return queryString.substr(pos + key.length());
171 }
172 return "";
173 }
174
GetPreferApn(const std::string & queryString)175 int PdpProfileAbility::GetPreferApn(const std::string &queryString)
176 {
177 auto preferencesUtil = DelayedSingleton<PreferencesUtil>::GetInstance();
178 if (preferencesUtil == nullptr) {
179 DATA_STORAGE_LOGE("preferencesUtil is nullptr!");
180 return NativePreferences::E_ERROR;
181 }
182 int preferApnId = preferencesUtil->ObtainInt(PREFER_APN_ID + GetQueryKey(queryString, "simId="),
183 INVALID_PROFILE_ID);
184 DATA_STORAGE_LOGI("%{public}d.", preferApnId);
185 return preferApnId;
186 }
187
SetPreferApn(int simId,int profileId)188 int PdpProfileAbility::SetPreferApn(int simId, int profileId)
189 {
190 auto preferencesUtil = DelayedSingleton<PreferencesUtil>::GetInstance();
191 if (preferencesUtil == nullptr) {
192 DATA_STORAGE_LOGE("preferencesUtil is nullptr!");
193 return NativePreferences::E_ERROR;
194 }
195 DATA_STORAGE_LOGI("simId:%{public}d profileId:%{public}d", simId, profileId);
196 return preferencesUtil->SaveInt(PREFER_APN_ID + std::to_string(simId), profileId);
197 }
198
Query(const Uri & uri,const DataShare::DataSharePredicates & predicates,std::vector<std::string> & columns,DataShare::DatashareBusinessError & businessError)199 std::shared_ptr<DataShare::DataShareResultSet> PdpProfileAbility::Query(const Uri &uri,
200 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns,
201 DataShare::DatashareBusinessError &businessError)
202 {
203 if (!PermissionUtil::CheckPermission(Permission::GET_TELEPHONY_STATE)) {
204 DATA_STORAGE_LOGE("Permission denied!");
205 return nullptr;
206 }
207 std::shared_ptr<DataShare::DataShareResultSet> sharedPtrResult = nullptr;
208 if (!IsInitOk()) {
209 return nullptr;
210 }
211 Uri tempUri = uri;
212 PdpProfileUriType pdpProfileUriType = ParseUriType(tempUri);
213 if (pdpProfileUriType == PdpProfileUriType::PDP_PROFILE || pdpProfileUriType == PdpProfileUriType::PREFER_APN) {
214 NativeRdb::AbsRdbPredicates *absRdbPredicates = new NativeRdb::AbsRdbPredicates(TABLE_PDP_PROFILE);
215 if (absRdbPredicates == nullptr) {
216 DATA_STORAGE_LOGE("PdpProfileAbility::Query NativeRdb::AbsRdbPredicates is null!");
217 return sharedPtrResult;
218 }
219 std::shared_ptr<NativeRdb::ResultSet> result = nullptr;
220 if (pdpProfileUriType == PdpProfileUriType::PREFER_APN) {
221 DataShare::DataSharePredicates preferapnPredicates;
222 preferapnPredicates.EqualTo(PdpProfileData::PROFILE_ID, GetPreferApn(tempUri.GetQuery()));
223 result = helper_.Query(ConvertPredicates(absRdbPredicates->GetTableName(), preferapnPredicates), columns);
224 } else if (pdpProfileUriType == PdpProfileUriType::PDP_PROFILE) {
225 result = QueryPdpProfile(tempUri, absRdbPredicates->GetTableName(), predicates, columns);
226 }
227 if (result == nullptr) {
228 DATA_STORAGE_LOGE("PdpProfileAbility::Query NativeRdb::ResultSet is null!");
229 delete absRdbPredicates;
230 return nullptr;
231 }
232 auto queryResultSet = RdbDataShareAdapter::RdbUtils::ToResultSetBridge(result);
233 sharedPtrResult = std::make_shared<DataShare::DataShareResultSet>(queryResultSet);
234 delete absRdbPredicates;
235 return sharedPtrResult;
236 }
237 DATA_STORAGE_LOGE("PdpProfileAbility::Query##uri = %{public}s", uri.ToString().c_str());
238 return sharedPtrResult;
239 }
240
Update(const Uri & uri,const DataShare::DataSharePredicates & predicates,const DataShare::DataShareValuesBucket & value)241 int PdpProfileAbility::Update(
242 const Uri &uri, const DataShare::DataSharePredicates &predicates,
243 const DataShare::DataShareValuesBucket &value)
244 {
245 if (!PermissionUtil::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
246 DATA_STORAGE_LOGE("Permission denied!");
247 return DATA_STORAGE_ERR_PERMISSION_ERR;
248 }
249 int result = DATA_STORAGE_ERROR;
250 if (!IsInitOk()) {
251 return result;
252 }
253 std::lock_guard<std::mutex> guard(lock_);
254 Uri tempUri = uri;
255 PdpProfileUriType pdpProfileUriType = ParseUriType(tempUri);
256 NativeRdb::AbsRdbPredicates *absRdbPredicates = nullptr;
257 switch (pdpProfileUriType) {
258 case PdpProfileUriType::PDP_PROFILE: {
259 absRdbPredicates = new NativeRdb::AbsRdbPredicates(TABLE_PDP_PROFILE);
260 break;
261 }
262 case PdpProfileUriType::RESET: {
263 result = ResetApn(value);
264 if (result != NativeRdb::E_OK) {
265 DATA_STORAGE_LOGE("PdpProfileAbility::Update ResetApn fail!");
266 result = static_cast<int>(LoadProFileErrorType::RESET_APN_FAIL);
267 }
268 break;
269 }
270 case PdpProfileUriType::PREFER_APN: {
271 result = (UpdatePreferApn(value) == NativeRdb::E_OK)
272 ? NativeRdb::E_OK
273 : static_cast<int>(LoadProFileErrorType::PREFER_APN_FAIL);
274 break;
275 }
276 default:
277 DATA_STORAGE_LOGE("PdpProfileAbility::Update##uri = %{public}s", uri.ToString().c_str());
278 break;
279 }
280 if (absRdbPredicates != nullptr) {
281 int changedRows = CHANGED_ROWS;
282 NativeRdb::RdbPredicates rdbPredicates = ConvertPredicates(absRdbPredicates->GetTableName(), predicates);
283 OHOS::NativeRdb::ValuesBucket values = RdbDataShareAdapter::RdbUtils::ToValuesBucket(value);
284 result = helper_.Update(changedRows, values, rdbPredicates);
285 delete absRdbPredicates;
286 absRdbPredicates = nullptr;
287 } else if (result == DATA_STORAGE_ERROR) {
288 DATA_STORAGE_LOGE("PdpProfileAbility::Update NativeRdb::AbsRdbPredicates is null!");
289 }
290 return result;
291 }
292
UpdatePreferApn(const DataShare::DataShareValuesBucket & sharedValue)293 int PdpProfileAbility::UpdatePreferApn(const DataShare::DataShareValuesBucket &sharedValue)
294 {
295 OHOS::NativeRdb::ValuesBucket value = RdbDataShareAdapter::RdbUtils::ToValuesBucket(sharedValue);
296 int result = DATA_STORAGE_ERROR;
297 NativeRdb::ValueObject valueObject;
298 if (!HasColumnValue(value, PdpProfileData::PROFILE_ID, valueObject)) {
299 return result;
300 }
301 double temp = 0;
302 int profileId = INVALID_PROFILE_ID;
303 if (valueObject.GetDouble(temp) == NativeRdb::E_OK) {
304 profileId = ceil(temp);
305 }
306 if (!HasColumnValue(value, PdpProfileData::SIM_ID, valueObject)) {
307 return result;
308 }
309 int simId = DEFAULT_SIM_ID;
310 if (valueObject.GetDouble(temp) == NativeRdb::E_OK) {
311 simId = ceil(temp);
312 }
313 return SetPreferApn(simId, profileId);
314 }
315
HasColumnValue(const OHOS::NativeRdb::ValuesBucket & value,const char * columnName,NativeRdb::ValueObject & valueObject)316 bool PdpProfileAbility::HasColumnValue(
317 const OHOS::NativeRdb::ValuesBucket &value, const char *columnName, NativeRdb::ValueObject &valueObject)
318 {
319 if (!value.HasColumn(columnName)) {
320 DATA_STORAGE_LOGE("the column in valuesBucket does not exist!");
321 return false;
322 }
323 bool isExistValue = value.GetObject(columnName, valueObject);
324 if (!isExistValue) {
325 DATA_STORAGE_LOGE("failed to get value in valuesBucket!");
326 return false;
327 }
328 return true;
329 }
330
Delete(const Uri & uri,const DataShare::DataSharePredicates & predicates)331 int PdpProfileAbility::Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates)
332 {
333 if (!PermissionUtil::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
334 DATA_STORAGE_LOGE("Permission denied!");
335 return DATA_STORAGE_ERR_PERMISSION_ERR;
336 }
337 int result = DATA_STORAGE_ERROR;
338 if (!IsInitOk()) {
339 return result;
340 }
341 std::lock_guard<std::mutex> guard(lock_);
342 Uri tempUri = uri;
343 PdpProfileUriType pdpProfileUriType = ParseUriType(tempUri);
344 if (pdpProfileUriType == PdpProfileUriType::PDP_PROFILE) {
345 NativeRdb::AbsRdbPredicates *absRdbPredicates = new NativeRdb::AbsRdbPredicates(TABLE_PDP_PROFILE);
346 if (absRdbPredicates != nullptr) {
347 NativeRdb::RdbPredicates rdbPredicates = ConvertPredicates(absRdbPredicates->GetTableName(), predicates);
348 int deletedRows = CHANGED_ROWS;
349 result = helper_.Delete(deletedRows, rdbPredicates);
350 delete absRdbPredicates;
351 absRdbPredicates = nullptr;
352 } else {
353 DATA_STORAGE_LOGE("PdpProfileAbility::Delete NativeRdb::AbsRdbPredicates is null!");
354 }
355 } else {
356 DATA_STORAGE_LOGI("PdpProfileAbility::Delete##uri = %{public}s", uri.ToString().c_str());
357 }
358 return result;
359 }
360
IsInitOk()361 bool PdpProfileAbility::IsInitOk()
362 {
363 if (!initDatabaseDir) {
364 DATA_STORAGE_LOGE("PdpProfileAbility::IsInitOk initDatabaseDir failed!");
365 return false;
366 }
367 if (!initRdbStore) {
368 DATA_STORAGE_LOGE("PdpProfileAbility::IsInitOk initRdbStore failed!");
369 return false;
370 }
371 return true;
372 }
373
GetType(const Uri & uri)374 std::string PdpProfileAbility::GetType(const Uri &uri)
375 {
376 DATA_STORAGE_LOGI("PdpProfileAbility::GetType##uri = %{public}s", uri.ToString().c_str());
377 std::string retval(uri.ToString());
378 return retval;
379 }
380
OpenFile(const Uri & uri,const std::string & mode)381 int PdpProfileAbility::OpenFile(const Uri &uri, const std::string &mode)
382 {
383 DATA_STORAGE_LOGI("PdpProfileAbility::OpenFile##uri = %{public}s", uri.ToString().c_str());
384 Uri tempUri = uri;
385 PdpProfileUriType pdpProfileUriType = ParseUriType(tempUri);
386 return static_cast<int>(pdpProfileUriType);
387 }
388
ParseUriType(Uri & uri)389 PdpProfileUriType PdpProfileAbility::ParseUriType(Uri &uri)
390 {
391 DATA_STORAGE_LOGD("PdpProfileAbility::ParseUriType start");
392 PdpProfileUriType pdpProfileUriType = PdpProfileUriType::UNKNOW;
393 std::string uriPath = uri.ToString();
394 if (!uriPath.empty()) {
395 helper_.ReplaceAllStr(uriPath, ":///", "://");
396 Uri tempUri(uriPath);
397 std::string path = tempUri.GetPath();
398 if (!path.empty() && !pdpProfileUriMap_.empty()) {
399 auto it = pdpProfileUriMap_.find(path);
400 if (it != pdpProfileUriMap_.end()) {
401 pdpProfileUriType = it->second;
402 DATA_STORAGE_LOGD("PdpProfileAbility::ParseUriType##pdpProfileUriType = %{public}d",
403 pdpProfileUriType);
404 }
405 }
406 }
407 return pdpProfileUriType;
408 }
409
ConvertPredicates(const std::string & tableName,const DataShare::DataSharePredicates & predicates)410 OHOS::NativeRdb::RdbPredicates PdpProfileAbility::ConvertPredicates(
411 const std::string &tableName, const DataShare::DataSharePredicates &predicates)
412 {
413 OHOS::NativeRdb::RdbPredicates res = RdbDataShareAdapter::RdbUtils::ToPredicates(predicates, tableName);
414 return res;
415 }
416
QueryPdpProfile(Uri & uri,const std::string & tableName,const DataShare::DataSharePredicates & predicates,std::vector<std::string> & columns)417 std::shared_ptr<NativeRdb::ResultSet> PdpProfileAbility::QueryPdpProfile(Uri &uri, const std::string &tableName,
418 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns)
419 {
420 const std::string &simIdStr = GetQueryKey(uri.GetQuery(), "simId=");
421 std::string opkey;
422 int simId = DEFAULT_SIM_ID;
423 if (StrToInt(simIdStr, simId)) {
424 int32_t slotId = DelayedRefSingleton<CoreServiceClient>::GetInstance().GetSlotId(simId);
425 GetTargetOpkey(slotId, opkey);
426 }
427 if (opkey.empty() || strcmp(opkey.c_str(), INVALID_OPKEY) == 0) {
428 return helper_.Query(ConvertPredicates(tableName, predicates), columns);
429 }
430 constexpr int32_t FIELD_IDX = 0;
431 auto &operations = predicates.GetOperationList();
432 std::vector<DataShare::OperationItem> operationsRes;
433 bool isMccMnc = false;
434 for (const auto &oper : operations) {
435 if (oper.singleParams.empty()) {
436 operationsRes.push_back(oper);
437 continue;
438 }
439 std::string filed = static_cast<std::string>(oper.GetSingle(FIELD_IDX));
440 if (strcmp(filed.c_str(), PdpProfileData::MCCMNC) == 0 && oper.operation == DataShare::EQUAL_TO) {
441 isMccMnc = true;
442 operationsRes.push_back({DataShare::EQUAL_TO, {PdpProfileData::OPKEY, opkey}});
443 continue;
444 }
445 operationsRes.push_back(oper);
446 }
447 DATA_STORAGE_LOGI(
448 "PdpProfileAbility::QueryPdpProfile, simId= %{public}d, isMccMnc= %{public}d", simId, isMccMnc);
449 if (isMccMnc) {
450 const std::shared_ptr<NativeRdb::ResultSet> &result =
451 helper_.Query(ConvertPredicates(tableName, DataShare::DataSharePredicates(move(operationsRes))), columns);
452 if (result != nullptr) {
453 int count = 0;
454 result->GetRowCount(count);
455 DATA_STORAGE_LOGI("PdpProfileAbility::QueryPdpProfile, count= %{public}d", count);
456 if (count > 0) {
457 return result;
458 }
459 }
460 }
461 return helper_.Query(ConvertPredicates(tableName, predicates), columns);
462 }
463
ResetApn(const DataShare::DataShareValuesBucket & valuesBucket)464 int PdpProfileAbility::ResetApn(const DataShare::DataShareValuesBucket &valuesBucket)
465 {
466 OHOS::NativeRdb::ValuesBucket values = RdbDataShareAdapter::RdbUtils::ToValuesBucket(valuesBucket);
467 int simId = DEFAULT_SIM_ID;
468 if (GetIntFromValuesBucket(values, "simId", simId) != NativeRdb::E_OK) {
469 DATA_STORAGE_LOGE("PdpProfileAbility::ResetApn no simId!");
470 return helper_.ResetApn();
471 }
472 int32_t slotId = DelayedRefSingleton<CoreServiceClient>::GetInstance().GetSlotId(simId);
473 std::string opkey;
474 GetTargetOpkey(slotId, opkey);
475 if (opkey.empty() || strcmp(opkey.c_str(), INVALID_OPKEY) == 0) {
476 DATA_STORAGE_LOGW("PdpProfileAbility::ResetApn opkey empty!");
477 return helper_.ResetApn();
478 }
479 DATA_STORAGE_LOGI("PdpProfileAbility::ResetApn##simId = %{public}d", simId);
480 SetPreferApn(simId, -1);
481 NativeRdb::RdbPredicates rdbPredicates(TABLE_PDP_PROFILE);
482 rdbPredicates.EqualTo(PdpProfileData::OPKEY, opkey);
483 int deletedRows = CHANGED_ROWS;
484 helper_.Delete(deletedRows, rdbPredicates);
485 int result = helper_.InitAPNDatabase(slotId, opkey, false);
486 if (result != NativeRdb::E_OK) {
487 DATA_STORAGE_LOGE("PdpProfileAbility::ResetApn fail!");
488 result = static_cast<int>(LoadProFileErrorType::RESET_APN_FAIL);
489 }
490 return result;
491 }
492
GetIntFromValuesBucket(OHOS::NativeRdb::ValuesBucket & bucket,const char * key,int & value)493 int PdpProfileAbility::GetIntFromValuesBucket(OHOS::NativeRdb::ValuesBucket &bucket, const char *key, int &value)
494 {
495 NativeRdb::ValueObject valueObject;
496 if (!HasColumnValue(bucket, key, valueObject)) {
497 return OPERATION_ERROR;
498 }
499 if (valueObject.GetType() == NativeRdb::ValueObject::TYPE_INT) {
500 return valueObject.GetInt(value);
501 }
502 if (valueObject.GetType() == NativeRdb::ValueObject::TYPE_DOUBLE) {
503 double temp = 0;
504 if (valueObject.GetDouble(temp) == NativeRdb::E_OK) {
505 value = ceil(temp);
506 return NativeRdb::E_OK;
507 }
508 }
509 return OPERATION_ERROR;
510 }
511
GetTargetOpkey(int slotId,std::string & opkey)512 void PdpProfileAbility::GetTargetOpkey(int slotId, std::string &opkey)
513 {
514 std::u16string opkeyU16;
515 DelayedRefSingleton<CoreServiceClient>::GetInstance().GetTargetOpkey(slotId, opkeyU16);
516 opkey = Str16ToStr8(opkeyU16);
517 DATA_STORAGE_LOGI(
518 "PdpProfileAbility::GetTargetOpkey##slotId = %{public}d, opkey = %{public}s", slotId, opkey.c_str());
519 }
520 } // namespace Telephony
521 } // namespace OHOS
522