• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16import { AsyncCallback } from './@ohos.base';
17
18declare namespace cloudData {
19  /**
20   * Describes the clear action type.
21   *
22   * @enum { number }
23   * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
24   * @systemapi
25   * @since 10
26   */
27  enum ClearAction {
28    /**
29     * Indicates clearing cloud-related data only, which includes cloud meta data and cloud-related local data.
30     *
31     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
32     * @systemapi
33     * @since 10
34     */
35    CLEAR_CLOUD_INFO,
36
37    /**
38     * Indicates clearing all cloud-related file data,which synchronized with the cloud.
39     *
40     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
41     * @systemapi
42     * @since 10
43     */
44    CLEAR_CLOUD_DATA_AND_INFO
45  }
46
47  /**
48   * Provides methods to set CloudSync config.
49   *
50   * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
51   * @systemapi
52   * @since 10
53   */
54  class Config {
55    /**
56     * Enables the cloud function.
57     *
58     * @permission ohos.permission.CLOUDDATA_CONFIG
59     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
60     * @param { { [bundleName:string]:boolean } } switches - Indicates switches information of all applications.
61     * switches will overwrite the saved application switch information.If the specific application switch changes,
62     * the {@link changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean)} method will notify the data manager service.
63     * @param { AsyncCallback<void> } callback - the callback of enableCloud.
64     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
65     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
66     * @throws { BusinessError } 401 - Parameter error.
67     * @throws { BusinessError } 801 - Capability not supported.
68     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
69     * @systemapi
70     * @since 10
71     */
72    static enableCloud(
73      accountId: string,
74      switches: { [bundleName: string]: boolean },
75      callback: AsyncCallback<void>
76    ): void;
77
78    /**
79     * Enables the cloud function.
80     *
81     * @permission ohos.permission.CLOUDDATA_CONFIG
82     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
83     * @param { { [bundleName:string]:boolean } } switches - Indicates switches information of all applications.
84     * switches will overwrite the saved application switch information.If the specific application switch changes,
85     * the {@link changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean)} method will notify the data manager service.
86     * @returns { Promise<void> } the promise returned by the function.
87     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
88     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
89     * @throws { BusinessError } 401 - Parameter error.
90     * @throws { BusinessError } 801 - Capability not supported.
91     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
92     * @systemapi
93     * @since 10
94     */
95    static enableCloud(accountId: string, switches: { [bundleName: string]: boolean }): Promise<void>;
96
97    /**
98     * Disables the cloud function.
99     *
100     * @permission ohos.permission.CLOUDDATA_CONFIG
101     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
102     * @param { AsyncCallback<void> } callback - the callback of disableCloud.
103     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
104     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
105     * @throws { BusinessError } 401 - Parameter error.
106     * @throws { BusinessError } 801 - Capability not supported.
107     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
108     * @systemapi
109     * @since 10
110     */
111    static disableCloud(accountId: string, callback: AsyncCallback<void>): void;
112
113    /**
114     * Disables the cloud function.
115     *
116     * @permission ohos.permission.CLOUDDATA_CONFIG
117     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
118     * @returns { Promise<void> } the promise returned by the function.
119     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
120     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
121     * @throws { BusinessError } 401 - Parameter error.
122     * @throws { BusinessError } 801 - Capability not supported.
123     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
124     * @systemapi
125     * @since 10
126     */
127    static disableCloud(accountId: string): Promise<void>;
128
129    /**
130     * Changes the cloud switch of a single application.
131     *
132     * @permission ohos.permission.CLOUDDATA_CONFIG
133     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
134     * @param { string } bundleName -  Indicates the name of application.
135     * @param { boolean } status - Indicates the condition of cloud sync switch.true means the switch is on,false means switch is off.
136     * @param { AsyncCallback<void> } callback - the callback of changeAppCloudSwitch.
137     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
138     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
139     * @throws { BusinessError } 401 - Parameter error.
140     * @throws { BusinessError } 801 - Capability not supported.
141     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
142     * @systemapi
143     * @since 10
144     */
145    static changeAppCloudSwitch(
146      accountId: string,
147      bundleName: string,
148      status: boolean,
149      callback: AsyncCallback<void>
150    ): void;
151
152    /**
153     * Changes the cloud switch of a single application.
154     *
155     * @permission ohos.permission.CLOUDDATA_CONFIG
156     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
157     * @param { string } bundleName -  Indicates the name of application.
158     * @param { boolean } status - Indicates the condition of cloud sync switch.true means the switch is on,false means switch is off.
159     * @returns { Promise<void> } the promise returned by the function.
160     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
161     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
162     * @throws { BusinessError } 401 - Parameter error.
163     * @throws { BusinessError } 801 - Capability not supported.
164     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
165     * @systemapi
166     * @since 10
167     */
168    static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void>;
169
170    /**
171     * notifies changes of the cloud records
172     *
173     * @permission ohos.permission.CLOUDDATA_CONFIG
174     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
175     * @param { string } bundleName - Indicates the name of application.
176     * @param { AsyncCallback<void> } callback - the callback of notifyDataChange.
177     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
178     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
179     * @throws { BusinessError } 401 - Parameter error.
180     * @throws { BusinessError } 801 - Capability not supported.
181     * @syscap SystemCapability.DistributedDataManager.CloudSync.Server
182     * @systemapi
183     * @since 10
184     */
185    static notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void;
186
187    /**
188     * notifies changes of the cloud records
189     *
190     * @permission ohos.permission.CLOUDDATA_CONFIG
191     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
192     * @param { string } bundleName - Indicates the name of application.
193     * @returns { Promise<void> } the promise returned by the function.
194     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
195     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
196     * @throws { BusinessError } 401 - Parameter error.
197     * @throws { BusinessError } 801 - Capability not supported.
198     * @syscap SystemCapability.DistributedDataManager.CloudSync.Server
199     * @systemapi
200     * @since 10
201     */
202    static notifyDataChange(accountId: string, bundleName: string): Promise<void>;
203
204    /**
205     * deletes cloud information from local data.
206     *
207     * @permission ohos.permission.CLOUDDATA_CONFIG
208     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing cloud account.
209     * @param { { [bundleName: string]: ClearAction } } appActions - Indicates the way in which the application data is to be cleared.
210     * @param { AsyncCallback<void> } callback - the callback of clear.
211     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
212     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
213     * @throws { BusinessError } 401 - Parameter error.
214     * @throws { BusinessError } 801 - Capability not supported.
215     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
216     * @systemapi
217     * @since 10
218     */
219    static clear(
220      accountId: string,
221      appActions: { [bundleName: string]: ClearAction },
222      callback: AsyncCallback<void>
223    ): void;
224
225    /**
226     * deletes cloud information from local data.
227     *
228     * @permission ohos.permission.CLOUDDATA_CONFIG
229     * @param { string } accountId - Indicates the account ID. The account ID is required by hashing the information of specific opened cloud.
230     * @param { { [bundleName: string]: ClearAction } } appActions - Indicates the way in which the application data is to be cleared.
231     * @returns { Promise<void> } the promise returned by the function.
232     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
233     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
234     * @throws { BusinessError } 401 - Parameter error.
235     * @throws { BusinessError } 801 - Capability not supported.
236     * @syscap SystemCapability.DistributedDataManager.CloudSync.Config
237     * @systemapi
238     * @since 10
239     */
240    static clear(accountId: string, appActions: { [bundleName: string]: ClearAction }): Promise<void>;
241  }
242}
243
244export default cloudData;
245