• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 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/**
17 * @file: Contact management
18 */
19import dataShare from '@ohos.data.dataShare';
20import dataSharePredicates from '@ohos.data.dataSharePredicates';
21import LogUtils from '../common/utils/LogUtils';
22import CallManager from '../model/CallManager';
23import GlobalThisHelper from '../common/utils/GlobalThisHelper';
24import Constants from '../common/utils/Constants';
25
26const TAG = "ContactManager";
27const DBbaseUri = 'datashare:///com.ohos.contactsdataability';
28const DBUri = DBbaseUri + '/contacts/contact_data';
29
30/**
31 * class ContactManager
32 */
33export default class ContactManager {
34  /**
35   * get contact info
36   *
37   * @param { Object } callData -Object
38   */
39  async getContactInfo(callData) {
40    if (callData.contactName) {
41      return;
42    }
43    try {
44      const columns = ['id', 'display_name', 'detail_info'];
45      const predicates = new dataSharePredicates.DataSharePredicates();
46      predicates.equalTo('detail_info', callData.accountNumber);
47      predicates.equalTo('is_deleted', 0);
48      const dataAbilityHelper = await dataShare.createDataShareHelper(GlobalThisHelper.get<any>(Constants.GLOBALTHIS_CONTEXT), DBbaseUri);
49      const resSet = await dataAbilityHelper.query(DBUri, predicates, columns);
50      LogUtils.i(TAG, "getContactInfo resSet : " + JSON.stringify(resSet.rowCount))
51      if (resSet.rowCount > 0) {
52        resSet.goToFirstRow();
53        callData.contactName = resSet.getString(resSet.getColumnIndex('display_name'));
54        CallManager.getInstance().update(callData);
55      }
56    } catch (err) {
57      LogUtils.i(TAG, "getContactInfo catch err : %s" + JSON.stringify(err))
58    }
59  }
60}