1 /*
2 * Copyright (C) 2021 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 "call_data_base_helper.h"
17
18 #include "ability_context.h"
19 #include "call_manager_errors.h"
20 #include "call_number_utils.h"
21 #include "iservice_registry.h"
22 #include "phonenumbers/phonenumber.pb.h"
23 #include "phonenumberutil.h"
24 #include "telephony_log_wrapper.h"
25 #include "os_account_manager.h"
26 #include "system_ability_definition.h"
27
28 namespace OHOS {
29 namespace Telephony {
30 class AbsSharedResultSet;
31 static constexpr const char *CALLLOG_URI = "datashare:///com.ohos.calllogability";
32 static constexpr const char *CALL_SUBSECTION = "datashare:///com.ohos.calllogability/calls/calllog";
33 static const std::string CALL_SUBSECTION_SILENCE =
34 "datashareproxy://com.ohos.contactsdataability/calls/calllog?Proxy=true&user=";
35 static constexpr const char *CONTACT_URI = "datashare:///com.ohos.contactsdataability";
36 static constexpr const char *CALL_BLOCK = "datashare:///com.ohos.contactsdataability/contacts/contact_blocklist";
37 static constexpr const char *CONTACT_DATA = "datashare:///com.ohos.contactsdataability/contacts/contact_data";
38 static constexpr const char *ISO_COUNTRY_CODE = "CN";
39 static constexpr const char *SETTINGS_DATA_URI =
40 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
41 static constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility";
42 static constexpr const char *SETTINGS_AIRPLANE_MODE_URI =
43 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=airplane_mode";
44 static constexpr const char *SETTINGS_AIRPLANE_MODE = "settings.telephony.airplanemode";
45 static constexpr const int32_t MAX_WAITIME_TIME = 10;
46 constexpr int32_t E_OK = 0;
47
CallDataRdbObserver(std::vector<std::string> * phones)48 CallDataRdbObserver::CallDataRdbObserver(std::vector<std::string> *phones)
49 {
50 if (phones == nullptr) {
51 TELEPHONY_LOGE("phones is nullptr");
52 }
53 this->phones = phones;
54 }
55
~CallDataRdbObserver()56 CallDataRdbObserver::~CallDataRdbObserver() {}
57
OnChange()58 void CallDataRdbObserver::OnChange()
59 {
60 std::shared_ptr<CallDataBaseHelper> callDataPtr = DelayedSingleton<CallDataBaseHelper>::GetInstance();
61 if (callDataPtr == nullptr) {
62 TELEPHONY_LOGE("callDataPtr is nullptr!");
63 return;
64 }
65
66 DataShare::DataSharePredicates predicates;
67 predicates.NotEqualTo("phone_number", std::string(""));
68 this->phones->clear();
69 callDataPtr->Query(this->phones, predicates);
70 }
71
CallDataBaseHelper()72 CallDataBaseHelper::CallDataBaseHelper() {}
73
~CallDataBaseHelper()74 CallDataBaseHelper::~CallDataBaseHelper() {}
75
CreateDataShareHelper(std::string uri)76 std::shared_ptr<DataShare::DataShareHelper> CallDataBaseHelper::CreateDataShareHelper(std::string uri)
77 {
78 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
79 if (saManager == nullptr) {
80 TELEPHONY_LOGE("Get system ability mgr failed.");
81 return nullptr;
82 }
83 auto remoteObj = saManager->GetSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
84 if (remoteObj == nullptr) {
85 TELEPHONY_LOGE("GetSystemAbility Service Failed.");
86 return nullptr;
87 }
88 if (uri == SETTINGS_DATA_URI) {
89 return DataShare::DataShareHelper::Creator(remoteObj, uri, SETTINGS_DATA_EXT_URI);
90 }
91 return DataShare::DataShareHelper::Creator(remoteObj, uri, "", MAX_WAITIME_TIME);
92 }
93
RegisterObserver(std::vector<std::string> * phones)94 void CallDataBaseHelper::RegisterObserver(std::vector<std::string> *phones)
95 {
96 if (phones == nullptr) {
97 TELEPHONY_LOGE("phones is nullptr");
98 return;
99 }
100 callDataRdbObserverPtr_ = new (std::nothrow) CallDataRdbObserver(phones);
101 if (callDataRdbObserverPtr_ == nullptr) {
102 TELEPHONY_LOGE("callDataRdbObserverPtr_ is null");
103 return;
104 }
105 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CONTACT_URI);
106 if (helper == nullptr) {
107 TELEPHONY_LOGE("helper is null");
108 return;
109 }
110 Uri uri(CALL_BLOCK);
111 helper->RegisterObserver(uri, callDataRdbObserverPtr_);
112 helper->Release();
113 }
114
UnRegisterObserver()115 void CallDataBaseHelper::UnRegisterObserver()
116 {
117 if (callDataRdbObserverPtr_ == nullptr) {
118 TELEPHONY_LOGE("callDataRdbObserverPtr_ is null");
119 return;
120 }
121 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CONTACT_URI);
122 if (helper == nullptr) {
123 TELEPHONY_LOGE("helper_ is null");
124 return;
125 }
126 Uri uri(CALL_BLOCK);
127 helper->UnregisterObserver(uri, callDataRdbObserverPtr_);
128 helper->Release();
129 }
130
Insert(DataShare::DataShareValuesBucket & values)131 bool CallDataBaseHelper::Insert(DataShare::DataShareValuesBucket &values)
132 {
133 std::shared_ptr<DataShare::DataShareHelper> helper = nullptr;
134 std::string url;
135 bool result = GetHelperAndUrl(helper, url);
136 if (!result) {
137 TELEPHONY_LOGE("GetHelperAndUrl fail!");
138 return false;
139 }
140
141 Uri uri(url);
142 result = (helper->Insert(uri, values) > 0);
143 helper->Release();
144 return result;
145 }
146
Query(std::vector<std::string> * phones,DataShare::DataSharePredicates & predicates)147 bool CallDataBaseHelper::Query(std::vector<std::string> *phones, DataShare::DataSharePredicates &predicates)
148 {
149 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CONTACT_URI);
150 if (helper == nullptr) {
151 TELEPHONY_LOGE("helper is nullptr");
152 return false;
153 }
154 Uri uri(CALL_BLOCK);
155 std::vector<std::string> columns;
156 columns.push_back("phone_number");
157 auto resultSet = helper->Query(uri, predicates, columns);
158 if (resultSet == nullptr) {
159 helper->Release();
160 return false;
161 }
162 int32_t resultSetNum = resultSet->GoToFirstRow();
163 while (resultSetNum == 0) {
164 std::string phone;
165 int32_t columnIndex;
166 resultSet->GetColumnIndex("phone_number", columnIndex);
167 int32_t ret = resultSet->GetString(columnIndex, phone);
168 if (ret == 0 && (!phone.empty())) {
169 phones->push_back(phone);
170 }
171 resultSetNum = resultSet->GoToNextRow();
172 }
173 resultSet->Close();
174 helper->Release();
175 TELEPHONY_LOGI("Query end");
176 return true;
177 }
178
Query(ContactInfo & contactInfo,DataShare::DataSharePredicates & predicates)179 bool CallDataBaseHelper::Query(ContactInfo &contactInfo, DataShare::DataSharePredicates &predicates)
180 {
181 TELEPHONY_LOGI("QueryCallerInfo use normal query");
182 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CONTACT_URI);
183 if (helper == nullptr) {
184 TELEPHONY_LOGE("helper is nullptr");
185 return false;
186 }
187 Uri uri(CONTACT_DATA);
188 std::vector<std::string> columns;
189 auto resultSet = helper->Query(uri, predicates, columns);
190 helper->Release();
191 if (!CheckResultSet(resultSet)) {
192 TELEPHONY_LOGE("resultSet is null");
193 return false;
194 }
195 if (resultSet->GoToFirstRow() != E_OK) {
196 TELEPHONY_LOGE("GoToFirstRow failed");
197 resultSet->Close();
198 return false;
199 }
200 int32_t columnIndex;
201 std::string ringtonePath = "";
202 std::string personalNotificationRingtone = "";
203 resultSet->GetColumnIndex(CALL_DISPLAY_NAME, columnIndex);
204 resultSet->GetString(columnIndex, contactInfo.name);
205 resultSet->GetColumnIndex(PERSONAL_RINGTONE, columnIndex);
206 resultSet->GetString(columnIndex, ringtonePath);
207 uint32_t length = ringtonePath.length() > FILE_PATH_MAX_LEN ? FILE_PATH_MAX_LEN : ringtonePath.length();
208 if (memcpy_s(contactInfo.ringtonePath, FILE_PATH_MAX_LEN, ringtonePath.c_str(), length) != EOK) {
209 TELEPHONY_LOGE("memcpy_s ringtonePath fail!");
210 resultSet->Close();
211 return false;
212 }
213 TELEPHONY_LOGI("ringtonePath: %{public}s", contactInfo.ringtonePath);
214 resultSet->GetColumnIndex(PERSONAL_NOTIFICATION_RINGTONE, columnIndex);
215 resultSet->GetString(columnIndex, personalNotificationRingtone);
216 resultSet->Close();
217 length = personalNotificationRingtone.length() > FILE_PATH_MAX_LEN ?
218 FILE_PATH_MAX_LEN : personalNotificationRingtone.length();
219 if (memcpy_s(contactInfo.personalNotificationRingtone, FILE_PATH_MAX_LEN, personalNotificationRingtone.c_str(),
220 length) != EOK) {
221 TELEPHONY_LOGE("memcpy_s personalNotificationRingtone fail!");
222 return false;
223 }
224 TELEPHONY_LOGI("Query end, contactName length: %{public}zu", contactInfo.name.length());
225 return true;
226 }
227
GetHelperAndUrl(std::shared_ptr<DataShare::DataShareHelper> & helper,std::string & url)228 bool CallDataBaseHelper::GetHelperAndUrl(std::shared_ptr<DataShare::DataShareHelper> &helper, std::string &url)
229 {
230 int32_t userId = 0;
231 bool isUserUnlocked = false;
232 AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(userId);
233 AccountSA::OsAccountManager::IsOsAccountVerified(userId, isUserUnlocked);
234 TELEPHONY_LOGI("isUserUnlocked: %{public}d", isUserUnlocked);
235 if (!isUserUnlocked) {
236 helper = CreateDataShareHelper(CALL_SUBSECTION_SILENCE + std::to_string(userId));
237 url = CALL_SUBSECTION_SILENCE + std::to_string(userId);
238 } else {
239 helper = CreateDataShareHelper(CALLLOG_URI);
240 url = CALL_SUBSECTION;
241 }
242 if (helper == nullptr) {
243 TELEPHONY_LOGE("helper is nullptr!");
244 return false;
245 }
246 return true;
247 }
248
QueryCallLog(std::map<std::string,int32_t> & phoneNumAndUnreadCountMap,DataShare::DataSharePredicates & predicates)249 bool CallDataBaseHelper::QueryCallLog(
250 std::map<std::string, int32_t> &phoneNumAndUnreadCountMap, DataShare::DataSharePredicates &predicates)
251 {
252 std::shared_ptr<DataShare::DataShareHelper> helper = nullptr;
253 std::string url;
254 bool result = GetHelperAndUrl(helper, url);
255 if (!result) {
256 TELEPHONY_LOGE("GetHelperAndUrl fail!");
257 return false;
258 }
259
260 Uri uri(url);
261 std::vector<std::string> columns;
262 columns.push_back(CALL_PHONE_NUMBER);
263 auto resultSet = helper->Query(uri, predicates, columns);
264 if (resultSet == nullptr) {
265 TELEPHONY_LOGE("resultSet is nullptr!");
266 helper->Release();
267 return false;
268 }
269 int32_t operationResult = resultSet->GoToFirstRow();
270 while (operationResult == TELEPHONY_SUCCESS) {
271 std::string phoneNumber = "";
272 int32_t columnIndex = 0;
273 resultSet->GetColumnIndex(CALL_PHONE_NUMBER, columnIndex);
274 operationResult = resultSet->GetString(columnIndex, phoneNumber);
275 if (operationResult == TELEPHONY_SUCCESS && (!phoneNumber.empty())) {
276 auto iter = phoneNumAndUnreadCountMap.find(phoneNumber);
277 if (iter != phoneNumAndUnreadCountMap.end()) {
278 iter->second++;
279 } else {
280 phoneNumAndUnreadCountMap.insert(
281 std::map<std::string, int32_t>::value_type(phoneNumber, CALL_LOG_DEFAULT_COUNT));
282 }
283 }
284 operationResult = resultSet->GoToNextRow();
285 }
286 resultSet->Close();
287 helper->Release();
288 TELEPHONY_LOGI("QueryCallLog end");
289 return true;
290 }
291
QueryAndDeleteLimitedIds(DataShare::DataSharePredicates & predicates)292 bool CallDataBaseHelper::QueryAndDeleteLimitedIds(DataShare::DataSharePredicates &predicates)
293 {
294 std::shared_ptr<DataShare::DataShareHelper> helper = nullptr;
295 std::string url;
296 bool result = GetHelperAndUrl(helper, url);
297 if (!result) {
298 TELEPHONY_LOGE("GetHelperAndUrl fail!");
299 return false;
300 }
301
302 Uri uri(url);
303 std::vector<std::string> columns;
304 columns.push_back(CALL_ID);
305 auto resultSet = helper->Query(uri, predicates, columns);
306 if (resultSet == nullptr) {
307 TELEPHONY_LOGE("resultSet is nullptr!");
308 helper->Release();
309 return false;
310 }
311 int32_t operationResult = resultSet->GoToFirstRow();
312 while (operationResult == TELEPHONY_SUCCESS) {
313 int32_t id = 0;
314 int32_t columnIndex = 0;
315 resultSet->GetColumnIndex(CALL_ID, columnIndex);
316 operationResult = resultSet->GetInt(columnIndex, id);
317 if (operationResult == TELEPHONY_SUCCESS) {
318 TELEPHONY_LOGI("need delete call log id: %{public}d", id);
319 DataShare::DataSharePredicates deletePredicates;
320 deletePredicates.EqualTo(CALL_ID, id);
321 result = (helper->Delete(uri, deletePredicates) > 0);
322 TELEPHONY_LOGI("delete result: %{public}d", result);
323 }
324 operationResult = resultSet->GoToNextRow();
325 }
326 resultSet->Close();
327 helper->Release();
328 TELEPHONY_LOGI("QueryAndDeleteLimitedIds end");
329 return true;
330 }
331
Update(DataShare::DataSharePredicates & predicates,DataShare::DataShareValuesBucket & values)332 bool CallDataBaseHelper::Update(DataShare::DataSharePredicates &predicates, DataShare::DataShareValuesBucket &values)
333 {
334 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CALLLOG_URI);
335 if (helper == nullptr) {
336 TELEPHONY_LOGE("helper is nullptr");
337 return true;
338 }
339 Uri uri(CALL_SUBSECTION);
340 bool result = (helper->Update(uri, predicates, values) > 0);
341 helper->Release();
342 return result;
343 }
344
Delete(DataShare::DataSharePredicates & predicates)345 bool CallDataBaseHelper::Delete(DataShare::DataSharePredicates &predicates)
346 {
347 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CALLLOG_URI);
348 if (helper == nullptr) {
349 TELEPHONY_LOGE("helper is nullptr!");
350 return false;
351 }
352 Uri uri(CALL_SUBSECTION);
353 bool result = (helper->Delete(uri, predicates) > 0);
354 TELEPHONY_LOGI("delete result: %{public}d", result);
355 helper->Release();
356 return result;
357 }
358
QueryIsBlockPhoneNumber(const std::string & phoneNum,bool & result)359 int32_t CallDataBaseHelper::QueryIsBlockPhoneNumber(const std::string &phoneNum, bool &result)
360 {
361 result = false;
362 std::shared_ptr<DataShare::DataShareHelper> callDataHelper = CreateDataShareHelper(CALLLOG_URI);
363 if (callDataHelper == nullptr) {
364 TELEPHONY_LOGE("callDataHelper is nullptr!");
365 return TELEPHONY_ERR_LOCAL_PTR_NULL;
366 }
367 Uri uri(CALL_BLOCK);
368 DataShare::DataSharePredicates predicates;
369 std::vector<std::string> columns;
370 std::string internationalNumber;
371 std::string nationalNumber;
372 int32_t ret = DelayedSingleton<CallNumberUtils>::GetInstance()->FormatPhoneNumberToNational(
373 phoneNum, ISO_COUNTRY_CODE, nationalNumber);
374 if (ret != TELEPHONY_SUCCESS) {
375 TELEPHONY_LOGE("Format phone number failed.");
376 nationalNumber = phoneNum;
377 }
378 ret = DelayedSingleton<CallNumberUtils>::GetInstance()->FormatPhoneNumberToInternational(
379 phoneNum, ISO_COUNTRY_CODE, internationalNumber);
380 if (ret != TELEPHONY_SUCCESS) {
381 TELEPHONY_LOGE("Format phone number failed.");
382 internationalNumber = phoneNum;
383 }
384 predicates.EqualTo(CALL_PHONE_NUMBER, nationalNumber)->Or()->EqualTo(CALL_PHONE_NUMBER, internationalNumber);
385 auto resultSet = callDataHelper->Query(uri, predicates, columns);
386 if (resultSet == nullptr) {
387 TELEPHONY_LOGE("Query Result Set nullptr Failed.");
388 callDataHelper->Release();
389 return TELEPHONY_ERR_LOCAL_PTR_NULL;
390 }
391 int32_t count = 0;
392 if (resultSet->GetRowCount(count) == E_OK && count != 0) {
393 result = true;
394 }
395 TELEPHONY_LOGI("count: %{public}d", count);
396 resultSet->Close();
397 callDataHelper->Release();
398 return TELEPHONY_SUCCESS;
399 }
400
GetAirplaneMode(bool & isAirplaneModeOn)401 int32_t CallDataBaseHelper::GetAirplaneMode(bool &isAirplaneModeOn)
402 {
403 std::shared_ptr<DataShare::DataShareHelper> callDataHelper = CreateDataShareHelper(SETTINGS_DATA_URI);
404 if (callDataHelper == nullptr) {
405 TELEPHONY_LOGE("callDataHelper is null");
406 return TELEPHONY_ERR_LOCAL_PTR_NULL;
407 }
408 Uri uri(SETTINGS_AIRPLANE_MODE_URI);
409 std::vector<std::string> columns;
410 DataShare::DataSharePredicates predicates;
411 predicates.EqualTo(SETTING_KEY, SETTINGS_AIRPLANE_MODE);
412 auto result = callDataHelper->Query(uri, predicates, columns);
413 if (result == nullptr) {
414 TELEPHONY_LOGE("CallDataBaseHelper: query error, result is null");
415 callDataHelper->Release();
416 return TELEPHONY_ERR_LOCAL_PTR_NULL;
417 }
418 if (result->GoToFirstRow() != DataShare::E_OK) {
419 TELEPHONY_LOGE("CallDataBaseHelper: query error, go to first row error");
420 result->Close();
421 callDataHelper->Release();
422 return TELEPHONY_ERR_DATABASE_READ_FAIL;
423 }
424 int32_t columnindex = 0;
425 std::string value = "";
426 result->GetColumnIndex(SETTING_VALUE, columnindex);
427 result->GetString(columnindex, value);
428 result->Close();
429 callDataHelper->Release();
430 isAirplaneModeOn = value == "1";
431 TELEPHONY_LOGI("Get airplane mode:%{public}d", isAirplaneModeOn);
432 return TELEPHONY_SUCCESS;
433 }
434
CheckResultSet(std::shared_ptr<DataShare::DataShareResultSet> resultSet)435 bool CallDataBaseHelper::CheckResultSet(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
436 {
437 if (resultSet == nullptr) {
438 TELEPHONY_LOGE("resultSet is nullptr");
439 return false;
440 }
441 int rowCount = 0;
442 resultSet->GetRowCount(rowCount);
443 if (rowCount == 0) {
444 TELEPHONY_LOGE("query success, but rowCount is 0");
445 resultSet->Close();
446 return false;
447 }
448 return true;
449 }
450
451 #ifdef TELEPHONY_CUST_SUPPORT
QueryContactInfoEnhanced(ContactInfo & contactInfo,DataShare::DataSharePredicates & predicates)452 bool CallDataBaseHelper::QueryContactInfoEnhanced(ContactInfo &contactInfo, DataShare::DataSharePredicates &predicates)
453 {
454 TELEPHONY_LOGI("QueryCallerInfo use enhanced query.");
455 std::shared_ptr<DataShare::DataShareHelper> helper = CreateDataShareHelper(CONTACT_URI);
456 if (helper == nullptr) {
457 TELEPHONY_LOGE("helper is nullptr");
458 return false;
459 }
460 Uri uri(CONTACT_DATA);
461 std::vector<std::string> columns;
462 auto resultSet = helper->Query(uri, predicates, columns);
463 helper->Release();
464 if (!CheckResultSet(resultSet)) {
465 TELEPHONY_LOGE("resultSet is null!");
466 return false;
467 }
468 int resultId = GetCallerIndex(resultSet, contactInfo.number);
469 TELEPHONY_LOGI("index: %{public}d", resultId);
470 if (resultSet->GoToRow(resultId) != E_OK) {
471 TELEPHONY_LOGE("GoToRow failed");
472 resultSet->Close();
473 return false;
474 }
475 int32_t columnIndex;
476 std::string ringtonePath = "";
477 std::string personalNotificationRingtone = "";
478 resultSet->GetColumnIndex(CALL_DISPLAY_NAME, columnIndex);
479 resultSet->GetString(columnIndex, contactInfo.name);
480 resultSet->GetColumnIndex(PERSONAL_RINGTONE, columnIndex);
481 resultSet->GetString(columnIndex, ringtonePath);
482 uint32_t length = ringtonePath.length() > FILE_PATH_MAX_LEN ? FILE_PATH_MAX_LEN : ringtonePath.length();
483 if (memcpy_s(contactInfo.ringtonePath, FILE_PATH_MAX_LEN, ringtonePath.c_str(), length) != EOK) {
484 TELEPHONY_LOGE("memcpy_s ringtonePath fail!");
485 resultSet->Close();
486 return false;
487 }
488 TELEPHONY_LOGI("ringtonePath: %{public}s", contactInfo.ringtonePath);
489 resultSet->GetColumnIndex(PERSONAL_NOTIFICATION_RINGTONE, columnIndex);
490 resultSet->GetString(columnIndex, personalNotificationRingtone);
491 resultSet->Close();
492 length = personalNotificationRingtone.length() > FILE_PATH_MAX_LEN ?
493 FILE_PATH_MAX_LEN : personalNotificationRingtone.length();
494 if (memcpy_s(contactInfo.personalNotificationRingtone, FILE_PATH_MAX_LEN, personalNotificationRingtone.c_str(),
495 length) != EOK) {
496 TELEPHONY_LOGE("memcpy_s personalNotificationRingtone fail!");
497 return false;
498 }
499 TELEPHONY_LOGI("Query end, contactName length: %{public}zu", contactInfo.name.length());
500 return true;
501 }
502
GetCallerIndex(std::shared_ptr<DataShare::DataShareResultSet> resultSet,std::string phoneNumber)503 int CallDataBaseHelper::GetCallerIndex(std::shared_ptr<DataShare::DataShareResultSet> resultSet,
504 std::string phoneNumber)
505 {
506 void *telephonyHandle = dlopen(TELEPHONY_CUST_SO_PATH.c_str(), RTLD_LAZY);
507 if (telephonyHandle == nullptr) {
508 TELEPHONY_LOGE("telephonyHandle is nullptr");
509 return -1;
510 }
511 typedef int (*GetCallerIndex) (std::shared_ptr<DataShare::DataShareResultSet>, std::string);
512 GetCallerIndex getCallerIndex = reinterpret_cast<GetCallerIndex>(dlsym(telephonyHandle, "GetCallerNumIndex"));
513 if (getCallerIndex == nullptr) {
514 TELEPHONY_LOGE("getCallerIndex is nullptr");
515 dlclose(telephonyHandle);
516 return -1;
517 }
518 int resultId = getCallerIndex(resultSet, phoneNumber);
519 dlclose(telephonyHandle);
520 return resultId;
521 }
522 #endif
523 } // namespace Telephony
524 } // namespace OHOS
525