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/**
17 * @file
18 * @kit TelephonyKit
19 */
20
21import type { AsyncCallback } from './@ohos.base';
22import type dataSharePredicates from './@ohos.data.dataSharePredicates';
23
24import type Context from './application/BaseContext';
25
26/**
27 * Provides applications with APIs for obtaining vcard.
28 *
29 * @namespace vcard
30 * @syscap SystemCapability.Telephony.CoreService
31 * @since 11
32 */
33declare namespace vcard {
34  /**
35   * Import contacts from the specified vcf file.
36   *
37   * @permission ohos.permission.WRITE_CONTACTS and
38   * ohos.permission.READ_CONTACTS
39   * @param { Context } context - Indicates the context of application or
40   *     capability.
41   * @param { string } filePath - Vcf file path.
42   * @param { number } accountId - Contact account ID. When the app chooses to
43   *     import the vcf file into a contact account,
44   * it needs to pass in the accountId. If the accountId is not passed, a new
45   * contact account will be added by default.
46   * @param { AsyncCallback<void> } callback - The callback of the function.
47   * @throws { BusinessError } 201 - Permission denied.
48   * @throws { BusinessError } 202 - Non-system applications use system APIs.
49   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
50   * 2. Incorrect parameter types.
51   * @throws { BusinessError } 8300001 - Invalid parameter value.
52   * @throws { BusinessError } 8300003 - System internal error.
53   * @throws { BusinessError } 8300999 - Unknown error code.
54   * @syscap SystemCapability.Telephony.CoreService
55   * @systemapi Hide this for inner system use.
56   * @since 11
57   */
58  function importVCard(context: Context, filePath: string, accountId: number, callback: AsyncCallback<void>): void;
59
60  /**
61   * Import contacts from the specified vcf file.
62   *
63   * @permission ohos.permission.WRITE_CONTACTS and
64   * ohos.permission.READ_CONTACTS
65   * @param { Context } context - Indicates the context of application or
66   *     capability.
67   * @param { string } filePath - Vcf file path.
68   * @param { number } accountId - Contact account ID.When the app chooses to
69   *     import the vcf file into a contact account,
70   * it needs to pass in the accountId. If the accountId is not passed, a new
71   * contact account will be added by default.
72   * @returns { Promise<void> } the promise returned by the function.
73   * @throws { BusinessError } 201 - Permission denied.
74   * @throws { BusinessError } 202 - Non-system applications use system APIs.
75   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
76   * 2. Incorrect parameter types.
77   * @throws { BusinessError } 8300001 - Invalid parameter value.
78   * @throws { BusinessError } 8300003 - System internal error.
79   * @throws { BusinessError } 8300999 - Unknown error code.
80   * @syscap SystemCapability.Telephony.CoreService
81   * @systemapi Hide this for inner system use.
82   * @since 11
83   */
84  function importVCard(context: Context, filePath: string, accountId?: number): Promise<void>;
85
86  /**
87   * Import contacts from the specified vcf file.
88   *
89   * @permission ohos.permission.WRITE_CONTACTS and
90   * ohos.permission.READ_CONTACTS
91   * @param { Context } context - Indicates the context of application or
92   *     capability.
93   * @param { string } filePath - Vcf file path.
94   * @param { AsyncCallback<void> } callback - The callback of the function.
95   * @throws { BusinessError } 201 - Permission denied.
96   * @throws { BusinessError } 202 - Non-system applications use system APIs.
97   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
98   * 2. Incorrect parameter types.
99   * @throws { BusinessError } 8300001 - Invalid parameter value.
100   * @throws { BusinessError } 8300003 - System internal error.
101   * @throws { BusinessError } 8300999 - Unknown error code.
102   * @syscap SystemCapability.Telephony.CoreService
103   * @systemapi Hide this for inner system use.
104   * @since 11
105   */
106  function importVCard(context: Context, filePath: string, callback: AsyncCallback<void>): void;
107
108  /**
109   * Export contact data to a vcf file.
110   *
111   * @permission ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
112   * @param { Context } context - Indicates the context of application or capability.
113   * @param { dataSharePredicates.DataSharePredicates } predicates - Execute statement.
114   * @param { VCardBuilderOptions } options - Encoding and version.
115   * @param { AsyncCallback<string> } callback - Represents the address of the generated vcf file.
116   * @throws { BusinessError } 201 - Permission denied.
117   * @throws { BusinessError } 202 - Non-system applications use system APIs.
118   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
119   * 2. Incorrect parameter types.
120   * @throws { BusinessError } 8300001 - Invalid parameter value.
121   * @throws { BusinessError } 8300003 - System internal error.
122   * @throws { BusinessError } 8300999 - Unknown error code.
123   * @syscap SystemCapability.Telephony.CoreService
124   * @systemapi Hide this for inner system use.
125   * @since 11
126   */
127  function exportVCard(context: Context, predicates: dataSharePredicates.DataSharePredicates,
128    options: VCardBuilderOptions, callback: AsyncCallback<string>): void;
129
130  /**
131   * Export contact data to a vcf file.
132   *
133   * @permission ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
134   * @param { Context } context - Indicates the context of application or capability.
135   * @param { dataSharePredicates.DataSharePredicates } predicates - Execute statement.
136   * @param { VCardBuilderOptions } options - Encoding and version.
137   * @returns { Promise<string> } the promise represents the address of the generated vcf file..
138   * @throws { BusinessError } 201 - Permission denied.
139   * @throws { BusinessError } 202 - Non-system applications use system APIs.
140   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
141   * 2. Incorrect parameter types.
142   * @throws { BusinessError } 8300001 - Invalid parameter value.
143   * @throws { BusinessError } 8300003 - System internal error.
144   * @throws { BusinessError } 8300999 - Unknown error code.
145   * @syscap SystemCapability.Telephony.CoreService
146   * @systemapi Hide this for inner system use.
147   * @since 11
148   */
149  function exportVCard(context: Context, predicates: dataSharePredicates.DataSharePredicates,
150    options?: VCardBuilderOptions): Promise<string>;
151
152  /**
153   * Export contact data to a vcf file.
154   *
155   * @permission ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
156   * @param { Context } context - Indicates the context of application or capability.
157   * @param { dataSharePredicates.DataSharePredicates } predicates - Execute statement.
158   * @param { AsyncCallback<string> } callback - Represents the address of the generated vcf file.
159   * @throws { BusinessError } 201 - Permission denied.
160   * @throws { BusinessError } 202 - Non-system applications use system APIs.
161   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
162   * 2. Incorrect parameter types.
163   * @throws { BusinessError } 8300001 - Invalid parameter value.
164   * @throws { BusinessError } 8300003 - System internal error.
165   * @throws { BusinessError } 8300999 - Unknown error code.
166   * @syscap SystemCapability.Telephony.CoreService
167   * @systemapi Hide this for inner system use.
168   * @since 11
169   */
170  function exportVCard(context: Context, predicates: dataSharePredicates.DataSharePredicates,
171    callback: AsyncCallback<string>): void;
172
173  /**
174   * Indicates the VCard types.
175   *
176   * @enum { string }
177   * @syscap SystemCapability.Telephony.CoreService
178   * @systemapi Hide this for inner system use.
179   * @since 11
180   */
181  export enum VCardType {
182    /**
183     * Indicates the VCard version 2.1.
184     *
185     * @syscap SystemCapability.Telephony.CoreService
186     * @systemapi Hide this for inner system use.
187     * @since 11
188     */
189    VERSION_21 = 0,
190
191    /**
192     * Indicates the VCard version 3.0.
193     *
194     * @syscap SystemCapability.Telephony.CoreService
195     * @systemapi Hide this for inner system use.
196     * @since 11
197     */
198    VERSION_30 = 1,
199
200    /**
201     * Indicates the VCard version 4.0.
202     *
203     * @syscap SystemCapability.Telephony.CoreService
204     * @systemapi Hide this for inner system use.
205     * @since 11
206     */
207    VERSION_40 = 2,
208  }
209
210  /**
211   * Indicates the options for VCard export.
212   *
213   * @interface VCardBuilderOptions
214   * @syscap SystemCapability.Telephony.CoreService
215   * @systemapi Hide this for inner system use.
216   * @since 11
217   */
218  export interface VCardBuilderOptions {
219    /**
220     * Indicates the VCard types.
221     *
222     * @type { ?VCardType }
223     * @syscap SystemCapability.Telephony.CoreService
224     * @systemapi Hide this for inner system use.
225     * @since 11
226     */
227    cardType?: VCardType;
228    /**
229     * Indicates the Encoding format.
230     *
231     * @type { ?string }
232     * @syscap SystemCapability.Telephony.CoreService
233     * @systemapi Hide this for inner system use.
234     * @since 11
235     */
236    charset?: string;
237  }
238
239}
240
241export default vcard;
242