• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.cloudSyncManager (端云同步管理能力)(系统接口)
2<!--Kit: Core File Kit-->
3<!--Subsystem: FileManagement-->
4<!--Owner: @zsyztt; @Hermits; @reminder2352-->
5<!--Designer: @yunlanying-->
6<!--Tester: @liuhonggang123-->
7<!--Adviser: @foryourself-->
8
9该模块向云空间应用提供端云同步管理能力:包括使能/去使能端云协同能力、修改应用同步开关,云端数据变化通知以及账号退出清理/保留云相关文件等。
10
11> **说明:**
12>
13> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.cloudSyncManager (端云同步管理能力)](js-apis-file-cloudsyncmanager.md)。
15
16## 导入模块
17
18```ts
19import { cloudSyncManager } from '@kit.CoreFileKit';
20```
21
22## cloudSyncManager.changeAppCloudSwitch
23
24changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise&lt;void&gt;
25
26异步方法修改应用的端云文件同步开关,以Promise形式返回结果。
27
28**系统接口**:该接口为系统接口。
29
30**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
31
32**参数:**
33
34| 参数名     | 类型   | 必填 | 说明 |
35| ---------- | ------ | ---- | ---- |
36| accountId | string | 是   | 账号Id。 |
37| bundleName | string | 是   | 应用包名。|
38| status | boolean | 是   | 修改的应用云同步开关状态。true为打开;false为关闭。|
39
40**返回值:**
41
42| 类型                  | 说明             |
43| --------------------- | ---------------- |
44| Promise&lt;void&gt; | 使用Promise形式返回修改应用的端云文件同步开关的结果。 |
45
46**错误码:**
47
48以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
49
50| 错误码ID                     | 错误信息        |
51| ---------------------------- | ---------- |
52| 201 | Permission verification failed. |
53| 202 | The caller is not a system application. |
54| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
55
56**示例:**
57
58  ```ts
59  import { BusinessError } from '@kit.BasicServicesKit';
60  let accountId: string = "testAccount";
61  let bundleName: string = "com.example.bundle";
62  cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true).then(() => {
63    console.info("changeAppCloudSwitch successfully");
64  }).catch((err: BusinessError) => {
65    console.error("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code);
66  });
67  ```
68
69## cloudSyncManager.changeAppCloudSwitch
70
71changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback&lt;void&gt;): void
72
73异步方法修改应用的端云文件同步开关,以callback形式返回结果。
74
75**系统接口**:该接口为系统接口。
76
77**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
78
79**参数:**
80
81| 参数名     | 类型   | 必填 | 说明 |
82| ---------- | ------ | ---- | ---- |
83| accountId | string | 是   | 账号Id。|
84| bundleName | string | 是   | 应用包名|
85| status | boolean | 是   | 修改的应用云同步开关状态。true为打开;false为关闭。|
86| callback | AsyncCallback&lt;void&gt; | 是   | 异步修改应用的端云文件同步开关之后的回调。 |
87
88**错误码:**
89
90以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
91
92| 错误码ID                     | 错误信息        |
93| ---------------------------- | ---------- |
94| 201 | Permission verification failed. |
95| 202 | The caller is not a system application. |
96| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
97
98**示例:**
99
100  ```ts
101  import { BusinessError } from '@kit.BasicServicesKit';
102  let accountId: string = "testAccount";
103  let bundleName: string = "com.example.bundle";
104  cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true, (err: BusinessError) => {
105    if (err) {
106      console.error("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code);
107    } else {
108      console.info("changeAppCloudSwitch successfully");
109    }
110  });
111  ```
112
113## cloudSyncManager.notifyDataChange
114
115notifyDataChange(accountId: string, bundleName: string): Promise&lt;void&gt;
116
117异步方法通知端云服务应用的云数据变更,以Promise形式返回结果。
118
119**系统接口**:该接口为系统接口。
120
121**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
122
123**参数:**
124
125| 参数名     | 类型   | 必填 | 说明 |
126| ---------- | ------ | ---- | ---- |
127| accountId | string | 是   | 账号Id。|
128| bundleName | string | 是   | 应用包名。|
129
130**返回值:**
131
132| 类型                  | 说明             |
133| --------------------- | ---------------- |
134| Promise&lt;void&gt; | 使用Promise形式返回通知端云服务应用的云数据变更的结果。 |
135
136**错误码:**
137
138以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
139
140| 错误码ID                     | 错误信息        |
141| ---------------------------- | ---------- |
142| 201 | Permission verification failed. |
143| 202 | The caller is not a system application. |
144| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
145
146**示例:**
147
148  ```ts
149  import { BusinessError } from '@kit.BasicServicesKit';
150  let accountId: string = "testAccount";
151  let bundleName: string = "com.example.bundle";
152  cloudSyncManager.notifyDataChange(accountId, bundleName).then(() => {
153    console.info("notifyDataChange successfully");
154  }).catch((err: BusinessError) => {
155    console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
156  });
157  ```
158
159## cloudSyncManager.notifyDataChange
160
161notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
162
163异步方法通知端云服务应用的云数据变更,以callback形式返回结果。
164
165**系统接口**:该接口为系统接口。
166
167**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
168
169**参数:**
170
171| 参数名     | 类型   | 必填 | 说明 |
172| ---------- | ------ | ---- | ---- |
173| accountId | string | 是   | 账号Id。|
174| bundleName | string | 是   | 应用包名。|
175| callback | AsyncCallback&lt;void&gt; | 是   | 异步通知端云服务应用的云数据变更之后的回调。 |
176
177**错误码:**
178
179以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
180
181| 错误码ID                     | 错误信息        |
182| ---------------------------- | ---------- |
183| 201 | Permission verification failed. |
184| 202 | The caller is not a system application. |
185| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
186
187**示例:**
188
189  ```ts
190  import { BusinessError } from '@kit.BasicServicesKit';
191  let accountId: string = "testAccount";
192  let bundleName: string = "com.example.bundle";
193  cloudSyncManager.notifyDataChange(accountId, bundleName, (err: BusinessError) => {
194    if (err) {
195      console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
196    } else {
197      console.info("notifyDataChange successfully");
198    }
199  });
200  ```
201
202## ExtraData<sup>11+</sup>
203
204云端数据变更信息。
205
206**系统接口**:该接口为系统接口。
207
208**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
209
210| 名称     | 类型   | 必填 | 说明 |
211| ---------- | ------ | ---- | ---- |
212| eventId | string | 是   | 变更事件id。|
213| extraData | ExtraData | 是   | 云端数据变更信息。|
214
215## cloudSyncManager.notifyDataChange<sup>11+</sup>
216
217notifyDataChange(userId: number, extraData: ExtraData): Promise&lt;void&gt;
218
219异步方法通知端云服务应用的云数据变更,以Promise形式返回结果。
220
221**系统接口**:该接口为系统接口。
222
223**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
224
225**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
226
227**参数:**
228
229| 参数名     | 类型   | 必填 | 说明 |
230| ---------- | ------ | ---- | ---- |
231| userId | number | 是   | 用户Id。|
232| extraData | ExtraData | 是   | 云端数据变更信息。|
233
234**返回值:**
235
236| 类型                  | 说明             |
237| --------------------- | ---------------- |
238| Promise&lt;void&gt; | 使用Promise形式返回通知端云服务应用的云数据变更的结果。 |
239
240**错误码:**
241
242以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
243
244| 错误码ID                     | 错误信息        |
245| ---------------------------- | ---------- |
246| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
247| 202 | Permission verification failed, application which is not a system application uses system API. |
248| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
249| 13600001  | IPC error. |
250
251**示例:**
252
253  ```ts
254  import { BusinessError } from '@kit.BasicServicesKit';
255  let userId: number = 100;
256  let extraData: cloudSyncManager.ExtraData = {eventId: "eventId", extraData: "data"};
257  cloudSyncManager.notifyDataChange(userId, extraData).then(() => {
258    console.info("notifyDataChange successfully");
259  }).catch((err: BusinessError) => {
260    console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
261  });
262  ```
263
264## cloudSyncManager.notifyDataChange<sup>11+</sup>
265
266notifyDataChange(userId: number, extraData: ExtraData, callback: AsyncCallback&lt;void&gt;): void
267
268异步方法通知端云服务应用的云数据变更,以callback形式返回结果。
269
270**系统接口**:该接口为系统接口。
271
272**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
273
274**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
275
276**参数:**
277
278| 参数名     | 类型   | 必填 | 说明 |
279| ---------- | ------ | ---- | ---- |
280| userId | number | 是   | 用户Id。|
281| extraData | ExtraData | 是   | 云端数据变更信息。|
282| callback | AsyncCallback&lt;void&gt; | 是   | 异步通知端云服务应用的云数据变更之后的回调。 |
283
284**错误码:**
285
286以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
287
288| 错误码ID                     | 错误信息        |
289| ---------------------------- | ---------- |
290| 201 | Permission verification failed. |
291| 202 | The caller is not a system application. |
292| 401 | The input parameter is invalid. |
293| 13600001  | IPC error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
294
295**示例:**
296
297  ```ts
298  import { BusinessError } from '@kit.BasicServicesKit';
299  let userId: number = 100;
300  let extraData: cloudSyncManager.ExtraData = {eventId: "eventId", extraData: "data"};
301  cloudSyncManager.notifyDataChange(userId, extraData, (err: BusinessError) => {
302    if (err) {
303      console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code);
304    } else {
305      console.info("notifyDataChange successfully");
306    }
307  });
308  ```
309
310## cloudSyncManager.enableCloud
311
312enableCloud(accountId: string, switches: Record<string, boolean>): Promise&lt;void&gt;
313
314异步方法使能端云协同能力,以Promise形式返回结果。
315
316**系统接口**:该接口为系统接口。
317
318**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
319
320**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
321
322**参数:**
323
324| 参数名     | 类型   | 必填 | 说明 |
325| ---------- | ------ | ---- | ---- |
326| accountId | string | 是   | 账号Id。|
327| switches | Record<string, boolean> | 是   | 应用的端云协同特性使能开关,string类型为应用包名,boolean类型为开关状态。true为打开;false为关闭。|
328
329**返回值:**
330
331| 类型                  | 说明             |
332| --------------------- | ---------------- |
333| Promise&lt;void&gt; | 使用Promise形式返回使能端云协同能力的结果。 |
334
335**错误码:**
336
337以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
338
339| 错误码ID                     | 错误信息        |
340| ---------------------------- | ---------- |
341| 201 | Permission verification failed. |
342| 202 | The caller is not a system application. |
343| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
344
345**示例:**
346
347  ```ts
348  import { BusinessError } from '@kit.BasicServicesKit';
349  let accountId: string = "testAccount";
350  let switches: Record<string, boolean> = {
351    'com.example.bundleName1': true,
352    'com.example.bundleName2': false
353  }
354  cloudSyncManager.enableCloud(accountId, switches).then(() => {
355    console.error("enableCloud successfully");
356  }).catch((err: BusinessError) => {
357    console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code);
358  });
359  ```
360
361## cloudSyncManager.enableCloud
362
363enableCloud(accountId: string, switches: Record<string, boolean>, callback: AsyncCallback&lt;void&gt;): void
364
365异步方法使能端云协同能力,以callback形式返回结果。
366
367**系统接口**:该接口为系统接口。
368
369**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
370
371**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
372
373**参数:**
374
375| 参数名     | 类型   | 必填 | 说明 |
376| ---------- | ------ | ---- | ---- |
377| accountId | string | 是   | 账号Id。|
378| switches | Record<string, boolean> | 是   | 应用的端云协同特性使能开关,string类型为应用包名,boolean类型为开关状态。true为打开;false为关闭。|
379| callback | AsyncCallback&lt;void&gt; | 是   | 异步使能端云协同能力之后的回调。 |
380
381**错误码:**
382
383以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
384
385| 错误码ID                     | 错误信息        |
386| ---------------------------- | ---------- |
387| 201 | Permission verification failed. |
388| 202 | The caller is not a system application. |
389| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
390
391**示例:**
392
393  ```ts
394  import { BusinessError } from '@kit.BasicServicesKit';
395  let accountId: string = "testAccount";
396  let switches: Record<string, boolean> = {
397    'com.example.bundleName1': true,
398    'com.example.bundleName2': false
399  }
400  cloudSyncManager.enableCloud(accountId, switches, (err: BusinessError) => {
401    if (err) {
402      console.error("enableCloud failed with error message: " + err.message + ", error code: " + err.code);
403    } else {
404      console.info("enableCloud successfully");
405    }
406  });
407  ```
408
409## cloudSyncManager.disableCloud
410
411disableCloud(accountId: string): Promise&lt;void&gt;
412
413异步方法去使能端云协同能力,以Promise形式返回结果。
414
415**系统接口**:该接口为系统接口。
416
417**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
418
419**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
420
421**参数:**
422
423| 参数名     | 类型   | 必填 | 说明 |
424| ---------- | ------ | ---- | ---- |
425| accountId | string | 是   | 账号Id。|
426
427**返回值:**
428
429| 类型                  | 说明             |
430| --------------------- | ---------------- |
431| Promise&lt;void&gt; | 使用Promise形式返回去使能端云协同能力的结果。 |
432
433**错误码:**
434
435以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
436
437| 错误码ID                     | 错误信息        |
438| ---------------------------- | ---------- |
439| 201 | Permission verification failed. |
440| 202 | The caller is not a system application. |
441| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
442
443**示例:**
444
445  ```ts
446  import { BusinessError } from '@kit.BasicServicesKit';
447  let accountId: string = "testAccount";
448  cloudSyncManager.disableCloud(accountId).then(() => {
449    console.info("disableCloud successfully");
450  }).catch((err: BusinessError) => {
451    console.error("disableCloud failed with error message: " + err.message + ", error code: " + err.code);
452  });
453  ```
454
455## cloudSyncManager.disableCloud
456
457disableCloud(accountId: string, callback: AsyncCallback&lt;void&gt;): void
458
459异步方法去使能端云协同能力,以callback形式返回结果。
460
461**系统接口**:该接口为系统接口。
462
463**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
464
465**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
466
467**参数:**
468
469| 参数名     | 类型   | 必填 | 说明 |
470| ---------- | ------ | ---- | ---- |
471| accountId | string | 是   | 账号Id。|
472| callback | AsyncCallback&lt;void&gt; | 是   | 异步去使能端云协同能力之后的回调。|
473
474**错误码:**
475
476以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
477
478| 错误码ID                     | 错误信息        |
479| ---------------------------- | ---------- |
480| 201 | Permission verification failed. |
481| 202 | The caller is not a system application. |
482| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
483
484**示例:**
485
486  ```ts
487  import { BusinessError } from '@kit.BasicServicesKit';
488  let accountId: string = "testAccount";
489  cloudSyncManager.disableCloud(accountId, (err: BusinessError) => {
490    if (err) {
491      console.error("disableCloud failed with error message: " + err.message + ", error code: " + err.code);
492    } else {
493      console.info("disableCloud successfully");
494    }
495  });
496  ```
497
498## Action
499
500清理本地云相关数据时的Action,为枚举类型。
501
502**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
503
504**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
505
506| 名称 |  值|  说明 |
507| ----- |  ---- |  ---- |
508| RETAIN_DATA |  0 |  仅清除云端标识,保留本地缓存文件。|
509| CLEAR_DATA |  1 |  清除云端标识信息,若存在本地缓存文件,一并删除。|
510
511## cloudSyncManager.clean
512
513clean(accountId: string, appActions: Record<string, Action>): Promise&lt;void&gt;
514
515异步方法清理本地云相关数据,以Promise形式返回结果。
516
517**系统接口**:该接口为系统接口。
518
519**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
520
521**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
522
523**参数:**
524
525| 参数名     | 类型   | 必填 | 说明 |
526| ---------- | ------ | ---- | ---- |
527| accountId | string | 是   | 账号Id。|
528| appActions | Record<string, Action> | 是   | 清理动作类型,string类型为待清理应用包名, [Action](#action)为清理动作类型。|
529
530**返回值:**
531
532| 类型                  | 说明             |
533| --------------------- | ---------------- |
534| Promise&lt;void&gt; | 使用Promise形式返回清理本地云相关数据的结果。 |
535
536**错误码:**
537
538以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
539
540| 错误码ID                     | 错误信息        |
541| ---------------------------- | ---------- |
542| 201 | Permission verification failed. |
543| 202 | The caller is not a system application. |
544| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
545
546**示例:**
547
548  ```ts
549  import { BusinessError } from '@kit.BasicServicesKit';
550  let accountId: string = "testAccount";
551  let appActions: Record<string, cloudSyncManager.Action> = {
552    'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA,
553    'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA
554  };
555  cloudSyncManager.clean(accountId, appActions).then(() => {
556    console.info("clean successfully");
557  }).catch((err: BusinessError) => {
558    console.error("clean failed with error message: " + err.message + ", error code: " + err.code);
559  });
560  ```
561
562## cloudSyncManager.clean
563
564clean(accountId: string, appActions: Record<string, Action>, callback: AsyncCallback&lt;void&gt;): void
565
566异步方法清理本地云相关数据,以callback形式返回结果。
567
568**系统接口**:该接口为系统接口。
569
570**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
571
572**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
573
574**参数:**
575
576| 参数名     | 类型   | 必填 | 说明 |
577| ---------- | ------ | ---- | ---- |
578| accountId | string | 是   | 账号Id。|
579| appActions | Record<string, Action> | 是   | 清理动作类型,string类型为待清理应用包名, [Action](#action)为清理动作类型。|
580| callback | AsyncCallback&lt;void&gt; | 是   | 异步方法清理本地云相关数据。 |
581
582**错误码:**
583
584以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
585
586| 错误码ID                     | 错误信息        |
587| ---------------------------- | ---------- |
588| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
589| 202 | Permission verification failed, application which is not a system application uses system API. |
590| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
591
592**示例:**
593
594  ```ts
595  import { BusinessError } from '@kit.BasicServicesKit';
596  let accountId: string = "testAccount";
597    let appActions: Record<string, cloudSyncManager.Action> = {
598    'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA,
599    'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA
600  };
601  cloudSyncManager.clean(accountId, appActions, (err: BusinessError) => {
602    if (err) {
603      console.error("clean failed with error message: " + err.message + ", error code: " + err.code);
604    } else {
605      console.info("clean successfully");
606    }
607  });
608  ```
609
610## DowngradeDownload<sup>20+</sup>
611
612降级下载:云空间会员服务到期,为避免用户云上数据丢失,提供的集中下载云端数据的能力。
613
614云盘降级下载对象,用于支撑云空间应用完成云盘文件的降级下载流程。
615
616**系统接口**:该接口为系统接口。
617
618**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
619
620### constructor<sup>20+</sup>
621
622constructor(bundleName: string)
623
624降级下载对象的构造函数,用于获取指定包名的DowngradeDownload类的实例。
625
626**系统接口**:该接口为系统接口。
627
628**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
629
630**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
631
632**参数:**
633
634| 参数名     | 类型   | 必填 | 说明       |
635| ---------- | ------ | ---- | ---------- |
636| bundleName | string | 是   | 应用包名。 |
637
638**错误码:**
639
640以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)以及[通用错误码](../errorcode-universal.md)。
641
642| 错误码ID | 错误信息                                                                                                                                                                          |
643| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
644| 201      | Permission verification failed, usually the result returned by VerifyAccessToken.                                                                                                 |
645| 202      | Permission verification failed, application which is not a system application uses system API.                                                                                    |
646| 13900020 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.                                                                     |
647| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
648
649**示例:**
650
651  ```ts
652  let bundleName = 'com.demo.a';
653  try {
654    let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
655  } catch (e) {
656    let error = e as BusinessError;
657    console.error(`Failed to create downgrade manager object, error code: ${error.code}, message: ${error.message}`);
658  }
659  ```
660
661### getCloudFileInfo<sup>20+</sup>
662
663getCloudFileInfo(): Promise&lt;CloudFileInfo&gt;
664
665获取需要降级下载的应用仅位于本地、仅位于云端或者本地和云端均有的文件大小和个数信息。使用Promise异步回调。
666
667**系统接口**:该接口为系统接口。
668
669**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
670
671**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
672
673**返回值:**
674
675  | 类型                              | 说明                     |
676  | --------------------------------- | ------------------------ |
677  | Promise&lt;[CloudFileInfo](js-apis-file-cloudsyncmanager.md#cloudfileinfo20)&gt; | Promise对象,返回携带本地与云端文件信息的对象。 |
678
679**错误码:**
680
681以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)以及[通用错误码](../errorcode-universal.md)。
682
683| 错误码ID | 错误信息                                                                                                                                                                          |
684| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
685| 201      | Permission verification failed, usually the result returned by VerifyAccessToken.                                                                                                 |
686| 202      | Permission verification failed, application which is not a system application uses system API.                                                                                    |
687| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service.                                                                                              |
688| 13900010 | Try again.                                                                                                                                                                        |
689| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
690
691**示例:**
692
693  ```ts
694  import { BusinessError } from '@kit.BasicServicesKit';
695
696  let bundleName: string = "com.demo.a";
697  let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
698  downgradeMgr.getCloudFileInfo().then((fileInfo: cloudSyncManager.CloudFileInfo) => {
699    console.info("cloud file info: " + JSON.stringify(fileInfo));
700  }).catch((err: BusinessError) => {
701    console.error(`Failed to get downgrade info, error message: ${err.message}, error code: ${err.code}`);
702  });
703  ```
704
705### startDownload<sup>20+</sup>
706
707startDownload(callback: Callback&lt;DownloadProgress&gt;): Promise&lt;void&gt;
708
709异步方法启动指定应用的云文件的降级下载,使用Promise异步回调。
710
711同一应用存在正在执行的降级下载任务的情况下,重复触发会返回错误信息(22400006)。
712
713**系统接口**:该接口为系统接口。
714
715**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
716
717**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
718
719**参数:**
720
721| 参数名   | 类型                             | 必填 | 说明                                                                                |
722| -------- | -------------------------------- | ---- | ----------------------------------------------------------------------------------- |
723| callback | Callback&lt;[DownloadProgress](js-apis-file-cloudsyncmanager.md#downloadprogress20)&gt; | 是   | 降级下载进度回调,回调参数为DownloadProgress,返回值为void。 |
724
725**返回值:**
726
727  | 类型                | 说明                      |
728  | ------------------- | ------------------------- |
729  | Promise&lt;void&gt; | Promise对象,无返回结果。 |
730
731**错误码:**
732
733以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)以及[通用错误码](../errorcode-universal.md)。
734
735| 错误码ID | 错误信息                                                                                                                                                                          |
736| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
737| 201      | Permission verification failed, usually the result returned by VerifyAccessToken.                                                                                                 |
738| 202      | Permission verification failed, application which is not a system application uses system API.                                                                                    |
739| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service.                                                                                              |
740| 13900010 | Try again.                                                                                                                                                                        |
741| 13900020 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.                                                                     |
742| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
743| 22400006 | The same task is already in progress.                                                                                                                                             |
744
745**示例:**
746
747  ```ts
748  import { BusinessError } from '@kit.BasicServicesKit';
749
750  let bundleName: string = "com.demo.a";
751  let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
752  let callback = (data: cloudSyncManager.DownloadProgress) => {
753    console.info(`Dwongrade progress: downloadedSize: ${data.downloadedSize}, totalSize: ${data.totalSize}`);
754    if (data.state == cloudSyncManager.DownloadState.COMPLETED) {
755      console.info('Dwongrade finished.');
756    } else if (data.state == cloudSyncManager.DownloadState.STOPPED) {
757      console.info(`Dwongrade stopped, reason: ${data.stopReason}.`);
758    }
759  };
760  downgradeMgr.startDownload(callback).then(() => {
761    console.info("Downgrade started successfully.");
762  }).catch((err: BusinessError) => {
763    console.error(`Failed to start downgrade, error message: ${err.message}, error code: ${err.code}`);
764  });
765  ```
766
767### stopDownload<sup>20+</sup>
768
769stopDownload(): Promise&lt;void&gt;
770
771停止由[startDownload](#startdownload20)触发的降级下载任务,使用Promise异步回调。
772
773**系统接口**:该接口为系统接口。
774
775**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER
776
777**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSyncManager
778
779**返回值:**
780
781  | 类型                | 说明                      |
782  | ------------------- | ------------------------- |
783  | Promise&lt;void&gt; | Promise对象,无返回结果。 |
784
785**错误码:**
786
787以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)以及[通用错误码](../errorcode-universal.md)。
788
789| 错误码ID | 错误信息                                                                                                                                                                          |
790| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
791| 201      | Permission verification failed, usually the result returned by VerifyAccessToken.                                                                                                 |
792| 202      | Permission verification failed, application which is not a system application uses system API.                                                                                    |
793| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service.                                                                                              |
794| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. |
795
796**示例:**
797
798  ```ts
799  import { BusinessError } from '@kit.BasicServicesKit';
800
801  let bundleName: string = "com.demo.a";
802  let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName);
803  downgradeMgr.startDownload((data: cloudSyncManager.DownloadProgress) => {
804    console.info(`Dwongrade progress: downloadedSize: ${data.downloadedSize}, totalSize: ${data.totalSize}`);
805  }).then(() => {
806    console.info("Downgrade started successfully.");
807  }).catch((err: BusinessError) => {
808    console.error(`Failed to start downgrade, error message: ${err.message}, error code: ${err.code}`);
809  });
810
811  let needStop = true;
812  if (needStop) {
813    downgradeMgr.stopDownload().then(() => {
814      console.info("Downgrade stopped successfully.");
815    }).catch((err: BusinessError) => {
816      console.error(`Failed to stop downgrade, error message: ${err.message}, error code: ${err.code}`);
817    });
818  }
819  ```
820