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

2022-12-05 浏览 (786)

@ohos.bundle.freeInstall (freeInstall)

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

PermissionPermission LevelDescription
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basicPermission to query information about all aplications.
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, see Permission Levels.

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 Bundle Error Codes.

IDError Message
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 Bundle Error Codes.

IDError Message
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 Bundle Error Codes.

IDError Message
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 Bundle Error Codes.

IDError Message
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 Bundle Error Codes.

IDError Message
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 Bundle Error Codes.

IDError Message
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.

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.

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 鸿蒙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/4d0b0a8b7a3e4324b5f1a9de62d2de90