• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.quickFixManager (quickFixManager)
2
3The **quickFixManager** module provides APIs for quick fix. With quick fix, you can fix bugs in your application by applying patches, which is more efficient than by updating the entire application.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import quickFixManager from '@ohos.app.ability.quickFixManager';
13```
14
15## HapModuleQuickFixInfo
16
17Defines the quick fix information at the HAP file level.
18
19**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
20
21**System API**: This is a system API and cannot be called by third-party applications.
22
23| Name       | Type                | Mandatory| Description                                                        |
24| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
25| moduleName    | string               | Yes  | Name of the HAP file.                              |
26| originHapHash    | string               | Yes  | Hash value of the HAP file.                              |
27| quickFixFilePath    | string               | Yes  | Installation path of the quick fix patch file.                              |
28
29## ApplicationQuickFixInfo
30
31Defines the quick fix information at the application level.
32
33**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
34
35**System API**: This is a system API and cannot be called by third-party applications.
36
37| Name       | Type                | Mandatory| Description                                                        |
38| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
39| bundleName    | string               | Yes  | Bundle name.                      |
40| bundleVersionCode    | number               | Yes  | Internal version number of the application.                              |
41| bundleVersionName    | string               | Yes  | Version number of the application that is shown to users.                              |
42| quickFixVersionCode    | number               | Yes  | Version code of the quick fix patch package.                              |
43| quickFixVersionName    | string               | Yes  | Text description of the version number of the quick fix patch package.                              |
44| hapModuleQuickFixInfo    | Array\<[HapModuleQuickFixInfo](#hapmodulequickfixinfo)>      | Yes  | Quick fix information at the HAP file level.    |
45
46## quickFixManager.applyQuickFix
47
48applyQuickFix(hapModuleQuickFixFiles: Array\<string>, callback: AsyncCallback\<void>): void;
49
50Applies a quick fix patch. This API uses an asynchronous callback to return the result.
51
52**Required permissions**: ohos.permission.INSTALL_BUNDLE
53
54**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
55
56**System API**: This is a system API and cannot be called by third-party applications.
57
58**Parameters**
59
60  | Parameter| Type| Mandatory| Description|
61  | -------- | -------- | -------- | -------- |
62  | hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix patch files, each of which must contain a valid file path.|
63  | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
64
65**Error codes**
66
67If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9).
68
69| ID| Error Message|
70| ------- | -------- |
71| 18500002 | The specified quick fix is invalid. It may not exist or inaccessible. |
72| 18500008 | Internal error. |
73
74For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
75
76> **NOTE**
77>
78> The file path passed in the API must be an application sandbox path. For details about how to obtain the sandbox path, see [Obtaining the Sandbox Path](js-apis-bundle-BundleInstaller.md#obtaining-the-sandbox-path). The path mapped to the device is **/proc/<*applicationProcessId*>/root/*sandboxPath***.
79
80**Example**
81
82```ts
83import quickFixManager from '@ohos.app.ability.quickFixManager';
84
85  try {
86    let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
87    quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
88      if (error) {
89          console.error( `applyQuickFix failed with error: ${error}`);
90      } else {
91          console.info( 'applyQuickFix success');
92      }
93    });
94  } catch (paramError) {
95    console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
96  }
97```
98
99## quickFixManager.applyQuickFix
100
101applyQuickFix(hapModuleQuickFixFiles: Array\<string>): Promise\<void>;
102
103Applies a quick fix patch. This API uses a promise to return the result.
104
105**Required permissions**: ohos.permission.INSTALL_BUNDLE
106
107**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
108
109**System API**: This is a system API and cannot be called by third-party applications.
110
111**Parameters**
112
113  | Parameter| Type| Mandatory| Description|
114  | -------- | -------- | -------- | -------- |
115  | hapModuleQuickFixFiles | Array\<string> | Yes| Quick fix patch files, each of which must contain a valid file path.|
116
117**Return value**
118
119  | Type| Description|
120  | -------- | -------- |
121  | Promise\<void> | Promise used to return the result.|
122
123**Error codes**
124
125If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9).
126
127| ID| Error Message|
128| ------- | -------- |
129| 18500002 | The specified quick fix is invalid. It may not exist or inaccessible. |
130| 18500008 | Internal error. |
131
132For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
133
134**Example**
135
136```ts
137import quickFixManager from '@ohos.app.ability.quickFixManager';
138import { BusinessError } from '@ohos.base';
139
140  let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
141  try {
142    quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
143      console.info('applyQuickFix success');
144    }).catch((error: BusinessError) => {
145      console.error(`applyQuickFix err: ${error}`);
146    });
147  } catch (paramError) {
148    console.error(`error: ${paramError.code}, ${paramError.message}`);
149  }
150```
151
152## quickFixManager.getApplicationQuickFixInfo
153
154getApplicationQuickFixInfo(bundleName: string, callback: AsyncCallback\<ApplicationQuickFixInfo>): void;
155
156Obtains the quick fix information of the application. This API uses an asynchronous callback to return the result.
157
158**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
159
160**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
161
162**System API**: This is a system API and cannot be called by third-party applications.
163
164**Parameters**
165
166| Parameter| Type| Mandatory| Description|
167| -------- | -------- | -------- | -------- |
168| bundleName | string | Yes|Bundle name. |
169| callback | AsyncCallback\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Yes| Callback used to return the quick fix information.|
170
171**Error codes**
172
173| ID| Error Message|
174| ------- | -------- |
175| 18500001 | The specified bundleName is invalid. |
176| 18500008 | Internal error. |
177
178For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
179
180**Example**
181
182```ts
183import quickFixManager from '@ohos.app.ability.quickFixManager';
184
185  try {
186    let bundleName = 'bundleName';
187    quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
188      if (error) {
189        console.error(`getApplicationQuickFixInfo error: ${error}`);
190      } else {
191        console.info(`getApplicationQuickFixInfo success: ${data}`);
192      }
193    });
194  } catch (paramError) {
195    console.error(`error: ${paramError.code}, ${paramError.message}`);
196  }
197```
198
199## quickFixManager.getApplicationQuickFixInfo
200
201getApplicationQuickFixInfo(bundleName: string): Promise\<ApplicationQuickFixInfo>;
202
203Obtains the quick fix information of the application. This API uses a promise to return the result.
204
205**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
206
207**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
208
209**System API**: This is a system API and cannot be called by third-party applications.
210
211**Parameters**
212
213| Parameter| Type| Mandatory| Description|
214| -------- | -------- | -------- | -------- |
215| bundleName | string | Yes| Bundle name.|
216
217**Return value**
218
219  | Type| Description|
220  | -------- | -------- |
221  | Promise\<[ApplicationQuickFixInfo](#applicationquickfixinfo)> | Promise used to return the quick fix information.|
222
223**Error codes**
224
225| ID| Error Message|
226| ------- | -------- |
227| 18500001 | The specified bundleName is invalid. |
228| 18500008 | Internal error. |
229
230For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
231
232**Example**
233
234  ```ts
235import quickFixManager from '@ohos.app.ability.quickFixManager';
236import { BusinessError } from '@ohos.base';
237
238  try {
239    let bundleName = 'bundleName';
240    quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
241      console.info(`getApplicationQuickFixInfo success: ${data}`);
242    }).catch((error: BusinessError) => {
243      console.error(`getApplicationQuickFixInfo err: ${error}`);
244    });
245  } catch (paramError) {
246    console.error(`error: ${paramError.code}, ${paramError.message}`);
247  }
248  ```
249
250## quickFixManager.revokeQuickFix<sup>10+<sup>
251
252revokeQuickFix(bundleName: string, callback: AsyncCallback\<void>): void;
253
254Revokes quick fix. This API uses an asynchronous callback to return the result.
255
256**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INSTALL_BUNDLE
257
258**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
259
260**System API**: This is a system API and cannot be called by third-party applications.
261
262**Parameters**
263
264  | Parameter| Type| Mandatory| Description|
265  | -------- | -------- | -------- | -------- |
266  | bundleName | string | Yes| Name of the bundle for which the patch needs to be revoked.|
267  | callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
268
269**Error codes**
270
271For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
272
273| ID| Error Message|
274| ------- | -------- |
275| 18500001 | The bundle is not exist or no patch has applied. |
276| 18500009 | The application has a apply quick fix task that is being processed. |
277
278If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_REVOKE_RESULT](./common_event/commonEvent-ability.md#common_event_quick_fix_revoke_result10).
279
280**Example**
281
282```ts
283import quickFixManager from '@ohos.app.ability.quickFixManager';
284
285  let bundleName = "com.example.myapplication";
286  quickFixManager.revokeQuickFix(bundleName, (err) => {
287    console.info("revokeQuickFix " + bundleName + " " + JSON.stringify(err));
288  });
289```
290
291## quickFixManager.revokeQuickFix<sup>10+<sup>
292
293revokeQuickFix(bundleName: string): Promise\<void>;
294
295Revokes quick fix. This API uses a promise to return the result.
296
297**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INSTALL_BUNDLE
298
299**System capability**: SystemCapability.Ability.AbilityRuntime.QuickFix
300
301**System API**: This is a system API and cannot be called by third-party applications.
302
303**Parameters**
304
305  | Parameter| Type| Mandatory| Description|
306  | -------- | -------- | -------- | -------- |
307  | bundleName | string | Yes| Name of the bundle for which the patch needs to be revoked.|
308
309**Return value**
310
311  | Type| Description|
312  | -------- | -------- |
313  | Promise\<void> | Promise used to return the result.|
314
315**Error codes**
316
317For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
318
319| ID| Error Message|
320| ------- | -------- |
321| 18500001 | The bundle is not exist or no patch has applied. |
322| 18500009 | The application has a apply quick fix task that is being processed. |
323
324If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_REVOKE_RESULT](./common_event/commonEvent-ability.md#common_event_quick_fix_revoke_result10). The table below lists the possible error codes and messages.
325
326**Example**
327
328```ts
329import quickFixManager from '@ohos.app.ability.quickFixManager';
330import { BusinessError } from '@ohos.base';
331
332  let bundleName = "com.example.myapplication";
333  quickFixManager.revokeQuickFix(bundleName).then(() => {
334    console.info("revokeQuickFix " + bundleName +" ok");
335  }).catch((err: BusinessError) => {
336    console.info("revokeQuickFix " + bundleName +" failed, error code is ", JSON.stringify((err)));
337  });
338```
339