openharmony 鸿蒙 js-apis-freeInstall-sys

2025-06-12 浏览 (1)

@ohos.bundle.freeInstall (freeInstall) (System API)

The Bundle.freeInstall module provides APIs for setting and obtaining installation-free information and APIs for obtaining BundlePackInfo and DispatchInfo.

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.

The APIs provided by this module are system APIs.

Modules to Import

import freeInstall from '@ohos.bundle.freeInstall';

Required Permissions

PermissionAPLDescription
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basicPermission to query information about all applications.
ohos.permission.INSTALL_BUNDLEsystem_corePermission to install or uninstall other applications except enterprise applications, including enterprise InHouse, mobile device management (MDM), and Normal applications.

For details about the APL, see Basic Concepts in the Permission Mechanism.

UpgradeFlag

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

NameValueDescription
NOT_UPGRADE0No module needs an upgrade.
SINGLE_UPGRADE1A single module needs an upgrade.
RELATION_UPGRADE2The module that has a relationship with the current one needs an upgrade.

BundlePackFlag

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

NameValueDescription
GET_PACK_INFO_ALL0x00000000All information in the pack.info file.
GET_PACKAGES0x00000001Package information in the pack.info file.
GET_BUNDLE_SUMMARY0x00000002Bundle summary information in the pack.info file.
GET_MODULE_SUMMARY0x00000004Module summary information in the pack.info file.

freeInstall.setHapModuleUpgradeFlag

setHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag, callback: AsyncCallback<void>):void

Sets an upgrade flag for a module. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.INSTALL_BUNDLE

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
moduleNamestringYesModule name.
upgradeFlagUpgradeFlagYesUpgrade flag, which is for internal use only.
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is null; otherwise, err is an error object.

Error codes

For details about the error codes, see Universal Error Codes and Bundle Error Codes.

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700002The specified module name is not found.

Example

import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
try {
    freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag, err => {
        if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
        } else {
            console.info('Operation succeed');
        }
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

setHapModuleUpgradeFlag

setHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag): Promise<void>

Sets an upgrade flag for a module. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.INSTALL_BUNDLE

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
moduleNamestringYesModule name.
upgradeFlagUpgradeFlagYesUpgrade flag, which is for internal use only.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Bundle Error Codes.

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700002The specified module name is not found.

Example

import freeInstall from '@ohos.bundle.freeInstall';
import { BusinessError } from '@ohos.base';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
try {
    freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag).then(() => {
        console.info('Operation succeed')
    }).catch((err: BusinessError) => {
        console.error('Operation failed:' + JSON.stringify(err));
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

isHapModuleRemovable

isHapModuleRemovable(bundleName: string, moduleName: string, callback: AsyncCallback<boolean>): void

Checks whether a module can be removed. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
moduleNamestringYesModule name.
callbackAsyncCallback<boolean>YesCallback used to return the result. If the module can be removed, true is returned; otherwise, false is returned.

Error codes

For details about the error codes, see Universal Error Codes and Bundle Error Codes.

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700002The specified module name is not found.

Example

import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
try {
    freeInstall.isHapModuleRemovable(bundleName, moduleName, (err, data) => {
        if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
        } else {
            console.info('Operation succeed:' + JSON.stringify(data));
        }
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

isHapModuleRemovable

isHapModuleRemovable(bundleName: string, moduleName: string): Promise<boolean>

Checks whether a module can be removed. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
moduleNamestringYesModule name.

Return value

TypeDescription
Promise<boolean>Promise used to return the result. If the module can be removed, true is returned; otherwise, false is returned.

Error codes

For details about the error codes, see Universal Error Codes and Bundle Error Codes.

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.
17700002The specified module name is not found.

Example

import freeInstall from '@ohos.bundle.freeInstall';
import { BusinessError } from '@ohos.base';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
try {
    freeInstall.isHapModuleRemovable(bundleName, moduleName).then(data => {
        console.info('Operation succeed:' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
        console.error('Operation failed:' + JSON.stringify(err));
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

getBundlePackInfo

getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag, callback: AsyncCallback<BundlePackInfo>): void

Obtains bundlePackInfo based on bundleName and bundlePackFlag. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundlePackFlagBundlePackFlagYesFlag of the bundle package.
callbackAsyncCallback<BundlePackInfo>YesCallback used to return the result. If the operation is successful, err is null and data is the BundlePackInfo object obtained; otherwise, err is an error object.

Error codes

For details about the error codes, see Universal Error Codes and Bundle Error Codes.

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.

Example

import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
try {
    freeInstall.getBundlePackInfo(bundleName, bundlePackFlag, (err, data) => {
        if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
        } else {
            console.info('Operation succeed:' + JSON.stringify(data));
        }
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

getBundlePackInfo

getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag): Promise<BundlePackInfo>

Obtains bundlePackInfo based on bundleName and bundlePackFlag. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundlePackFlagBundlePackFlagYesFlag of the bundle package.

Return value

TypeDescription
Promise<BundlePackInfo>Promise used to return the BundlePackInfo object obtained.

Error codes

For details about the error codes, see Universal Error Codes and Bundle Error Codes.

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801Capability not supported.
17700001The specified bundle name is not found.

Example

import freeInstall from '@ohos.bundle.freeInstall';
import { BusinessError } from '@ohos.base';
let bundleName = 'com.example.myapplication';
let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
try {
    freeInstall.getBundlePackInfo(bundleName, bundlePackFlag).then(data => {
        console.info('Operation succeed:' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
        console.error('Operation failed:' + JSON.stringify(err));
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

getDispatchInfo

getDispatchInfo(callback: AsyncCallback<DispatchInfo>): void

Obtains the dispatch information. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<DispatchInfo>YesCallback used to return the result. If the operation is successful, err is null, and data is the DispatchInfo object obtained. otherwise, err is an error object.

Error codes

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

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
801Capability not supported.

Example

import freeInstall from '@ohos.bundle.freeInstall';
try {
    freeInstall.getDispatchInfo((err, data) => {
        if (err) {
            console.error('Operation failed:' + JSON.stringify(err));
        } else {
            console.info('Operation succeed:' + JSON.stringify(data));
        }
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

getDispatchInfo

getDispatchInfo(): Promise<DispatchInfo>

Obtains the dispatch information. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.FreeInstall

Return value

TypeDescription
Promise<DispatchInfo>Promise used to return the DispatchInfo object obtained.

Error codes

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

IDError Message
201Permission denied.
202Permission denied, non-system app called system api.
801Capability not supported.

Example

import freeInstall from '@ohos.bundle.freeInstall';
import { BusinessError } from '@ohos.base';
try {
    freeInstall.getDispatchInfo().then(data => {
        console.info('Operation succeed:' + JSON.stringify(data));
    }).catch((err: BusinessError) => {
        console.error('Operation failed:' + JSON.stringify(err));
    });
} catch (err) {
    console.error('Operation failed:' + JSON.stringify(err));
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

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