harmony 鸿蒙@ohos.app.ability.quickFixManager (quickFixManager)

2022-12-22 浏览 (737)

@ohos.app.ability.quickFixManager (quickFixManager)

The 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.

NOTE

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.

Modules to Import

import quickFixManager from '@ohos.app.ability.quickFixManager';

HapModuleQuickFixInfo

Defines the quick fix information at the HAP file level.

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

NameTypeMandatoryDescription
moduleNamestringYesName of the HAP file.
originHapHashstringYesHash value of the HAP file.
quickFixFilePathstringYesInstallation path of the quick fix patch file.

ApplicationQuickFixInfo

Defines the quick fix information at the application level.

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleVersionCodenumberYesInternal version number of the application.
bundleVersionNamestringYesVersion number of the application that is shown to users.
quickFixVersionCodenumberYesVersion code of the quick fix patch package.
quickFixVersionNamestringYesText description of the version number of the quick fix patch package.
hapModuleQuickFixInfoArray<HapModuleQuickFixInfo>YesQuick fix information at the HAP file level.

quickFixManager.applyQuickFix

applyQuickFix(hapModuleQuickFixFiles: Array<string>, callback: AsyncCallback<void>): void;

Applies a quick fix patch. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.INSTALL_BUNDLE

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

Parameters

ParameterTypeMandatoryDescription
hapModuleQuickFixFilesArray<string>YesQuick fix patch files, each of which must contain a valid file path.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

If an error occurs during patch installation, the error code and message are returned through the common event COMMON_EVENT_QUICK_FIX_APPLY_RESULT.

IDError Message
18500002The specified quick fix is invalid. It may not exist or inaccessible.
18500008Internal error.

For details about the error codes, see Ability Error Codes.

NOTE

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. The path mapped to the device is /proc/<applicationProcessId>/root/sandboxPath.

Example

import quickFixManager from '@ohos.app.ability.quickFixManager';

  try {
    let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
    quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
      if (error) {
          console.error( `applyQuickFix failed with error: ${error}`);
      } else {
          console.info( 'applyQuickFix success');
      }
    });
  } catch (paramError) {
    console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
  }

quickFixManager.applyQuickFix

applyQuickFix(hapModuleQuickFixFiles: Array<string>): Promise<void>;

Applies a quick fix patch. This API uses a promise to return the result.

Required permissions: ohos.permission.INSTALL_BUNDLE

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

Parameters

ParameterTypeMandatoryDescription
hapModuleQuickFixFilesArray<string>YesQuick fix patch files, each of which must contain a valid file path.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

If an error occurs during patch installation, the error code and message are returned through the common event COMMON_EVENT_QUICK_FIX_APPLY_RESULT.

IDError Message
18500002The specified quick fix is invalid. It may not exist or inaccessible.
18500008Internal error.

For details about the error codes, see Ability Error Codes.

Example

import quickFixManager from '@ohos.app.ability.quickFixManager';
import { BusinessError } from '@ohos.base';

  let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
  try {
    quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
      console.info('applyQuickFix success');
    }).catch((error: BusinessError) => {
      console.error(`applyQuickFix err: ${error}`);
    });
  } catch (paramError) {
    console.error(`error: ${paramError.code}, ${paramError.message}`);
  }

quickFixManager.getApplicationQuickFixInfo

getApplicationQuickFixInfo(bundleName: string, callback: AsyncCallback<ApplicationQuickFixInfo>): void;

Obtains the quick fix information of the application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

Parameters

ParameterTypeMandatoryDescription
bundleNamestringYesBundle name.
callbackAsyncCallback<ApplicationQuickFixInfo>YesCallback used to return the quick fix information.

Error codes

IDError Message
18500001The specified bundleName is invalid.
18500008Internal error.

For details about the error codes, see Ability Error Codes.

Example

import quickFixManager from '@ohos.app.ability.quickFixManager';

  try {
    let bundleName = 'bundleName';
    quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
      if (error) {
        console.error(`getApplicationQuickFixInfo error: ${error}`);
      } else {
        console.info(`getApplicationQuickFixInfo success: ${data}`);
      }
    });
  } catch (paramError) {
    console.error(`error: ${paramError.code}, ${paramError.message}`);
  }

quickFixManager.getApplicationQuickFixInfo

getApplicationQuickFixInfo(bundleName: string): Promise<ApplicationQuickFixInfo>;

Obtains the quick fix information of the application. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

Parameters

ParameterTypeMandatoryDescription
bundleNamestringYesBundle name.

Return value

TypeDescription
Promise<ApplicationQuickFixInfo>Promise used to return the quick fix information.

Error codes

IDError Message
18500001The specified bundleName is invalid.
18500008Internal error.

For details about the error codes, see Ability Error Codes.

Example

import quickFixManager from '@ohos.app.ability.quickFixManager';
import { BusinessError } from '@ohos.base';

try {
  let bundleName = 'bundleName';
  quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
    console.info(`getApplicationQuickFixInfo success: ${data}`);
  }).catch((error: BusinessError) => {
    console.error(`getApplicationQuickFixInfo err: ${error}`);
  });
} catch (paramError) {
  console.error(`error: ${paramError.code}, ${paramError.message}`);
}

quickFixManager.revokeQuickFix10+

revokeQuickFix(bundleName: string, callback: AsyncCallback<void>): void;

Revokes quick fix. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INSTALL_BUNDLE

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

Parameters

ParameterTypeMandatoryDescription
bundleNamestringYesName of the bundle for which the patch needs to be revoked.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Ability Error Codes.

IDError Message
18500001The bundle is not exist or no patch has applied.
18500009The application has a apply quick fix task that is being processed.

If an error occurs during patch installation, the error code and message are returned through the common event COMMON_EVENT_QUICK_FIX_REVOKE_RESULT.

Example

import quickFixManager from '@ohos.app.ability.quickFixManager';

  let bundleName = "com.example.myapplication";
  quickFixManager.revokeQuickFix(bundleName, (err) => {
    console.info("revokeQuickFix " + bundleName + " " + JSON.stringify(err));
  });

quickFixManager.revokeQuickFix10+

revokeQuickFix(bundleName: string): Promise<void>;

Revokes quick fix. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INSTALL_BUNDLE

System capability: SystemCapability.Ability.AbilityRuntime.QuickFix

System API: This is a system API and cannot be called by third-party applications.

Parameters

ParameterTypeMandatoryDescription
bundleNamestringYesName of the bundle for which the patch needs to be revoked.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Ability Error Codes.

IDError Message
18500001The bundle is not exist or no patch has applied.
18500009The application has a apply quick fix task that is being processed.

If an error occurs during patch installation, the error code and message are returned through the common event COMMON_EVENT_QUICK_FIX_REVOKE_RESULT. The table below lists the possible error codes and messages.

Example

import quickFixManager from '@ohos.app.ability.quickFixManager';
import { BusinessError } from '@ohos.base';

  let bundleName = "com.example.myapplication";
  quickFixManager.revokeQuickFix(bundleName).then(() => {
    console.info("revokeQuickFix " + bundleName +" ok");
  }).catch((err: BusinessError) => {
    console.info("revokeQuickFix " + bundleName +" failed, error code is ", JSON.stringify((err)));
  });

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/7be93ea828df4d57ab76379f8ca6ca86