diff --git a/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md b/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md index c75df316c32598a2727713583e72aa5541f3b563..b881c5739a4e626fb795b3dbc5cc8b0201545f65 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md @@ -1590,6 +1590,52 @@ try { } ``` +### bundleManager.getBundleNameByUidSync10+ + +getBundleNameByUidSync(uid: number): string; + +以同步方法根据给定的uid获取对应的bundleName。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ------------------ | +| uid | number | 是 | 表示应用程序的UID。 | + +**返回值:** + +| 类型 | 说明 | +| ---------------- | --------------------------- | +| string | 返回获取到的bundleName。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------| +| 17700021 | The uid is not found. | + +**示例:** + +```ts +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; +let uid = 20010005; +try { + let data = bundleManager.getBundleNameByUidSync(uid); + hilog.info(0x0000, 'testTag', 'getBundleNameByUidSync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getBundleNameByUidSync failed. Cause: %{public}s', err.message); +} +``` + ### bundleManager.getBundleArchiveInfo getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void; @@ -1691,6 +1737,55 @@ try { } ``` +### bundleManager.getBundleArchiveInfoSync10+ + +getBundleArchiveInfoSync(hapFilePath: string, bundleFlags: number): BundleInfo; + +以同步方法根据给定的hapFilePath和bundleFlags获取BundleInfo对象。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----------- | ------ | ---- | ------------------------------------------------------------ | +| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | +| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------------------------- | --------------------------- | +| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------- | +| 17700022 | The hapFilePath is invalid. | + +**示例:** + +```ts +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; +let hapFilePath = "/data/xxx/test.hap"; +let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; + +try { + let data = bundleManager.getBundleArchiveInfoSync(hapFilePath, bundleFlags) + hilog.info(0x0000, 'testTag', 'getBundleArchiveInfoSync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getBundleArchiveInfoSync failed. Cause: %{public}s', err.message); +} +``` + ### bundleManager.cleanBundleCacheFiles cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\): void; @@ -2780,6 +2875,70 @@ try { } ``` +### bundleManager.getProfileByAbilitySync10+ + +getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array\; + +以同步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,返回对象为string数组。 + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------ | ---- | -------------------------- | +| moduleName | string | 是 | 表示应用程序的moduleName。 | +| abilityName | string | 是 | 表示应用程序的abilityName。 | +| metadataName | string | 否 | 表示应用程序的metadataName,默认值为空。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------- | ------------------------------- | +| Array\ | 数组对象,返回Array\。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700002 | The specified moduleName is not existed. | +| 17700003 | The specified abilityName is not existed. | +| 17700024 | Failed to get the profile because there is no profile in the HAP. | +| 17700026 | The specified bundle is disabled. | +| 17700029 | The specified ability is disabled. | + +**示例:** + +```ts +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; +let moduleName = 'entry'; +let abilityName = 'EntryAbility'; + +try { + let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName); + hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', err.message); +} +``` + +```ts +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; +let moduleName: string = 'entry'; +let abilityName: string = 'EntryAbility'; +let metadataName: string = 'com.example.myapplication.metadata'; +try { + let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName, metadataName); + hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', err.message); +} +``` + ### bundleManager.getProfileByExtensionAbility getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\\>): void; @@ -2893,6 +3052,63 @@ try { } ``` +### bundleManager.getProfileByExtensionAbilitySync10+ + +getProfileByExtensionAbilitySync(moduleName: string, extensionAbilityName: string, metadataName?: string): Array\; + +以同步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,返回对象为string数组。 + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | ------ | ---- | ---------------------------------- | +| moduleName | string | 是 | 表示应用程序的moduleName。 | +| extensionAbilityName | string | 是 | 表示应用程序的extensionAbilityName。 | +| metadataName | string | 否 | 表示应用程序的metadataName,默认值为空。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------- | ----------------------------------- | +| Array\ | 返回Array\对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700002 | The specified moduleName is not existed. | +| 17700003 | The specified extensionAbilityName not existed. | +| 17700024 | Failed to get the profile because there is no profile in the HAP. | +| 17700026 | The specified bundle is disabled. | + +**示例:** + +```ts +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; +let moduleName = 'entry'; +let extensionAbilityName = 'com.example.myapplication.extension'; +let metadataName = 'com.example.myapplication.metadata'; + +try { + let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName); + hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', err.message); +} + +try { + let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName, metadataName); + hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', err.message); +} +``` + ### bundleManager.getPermissionDef getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void; @@ -3744,6 +3960,64 @@ try { } ``` +### bundleManager.getAppProvisionInfoSync10+ + +getAppProvisionInfoSync(bundleName: string, userId?: number): AppProvisionInfo; + +以同步方法根据bundleName和userId获取应用的provision配置文件信息并返回结果。 + +**系统接口:** 此接口为系统接口 + +**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| bundleName | string | 是 | 指定的bundleName。 | +| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口[getOsAccountLocalId](js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | + + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------------------------------ | ----------------------------------- | +| [AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md) | AppProvisionInfo对象,返回应用的provision配置文件信息。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | -------------------------------------- | +| 17700001 | The specified bundleName is not found. | +| 17700004 | The specified user ID is not found. | + +**示例:** + +```ts +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; +let bundleName = "com.ohos.myapplication"; +let userId = 100; + +try { + let data = bundleManager.getAppProvisionInfoSync(bundleName); + hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', err.message); +} + +try { + let data = bundleManager.getAppProvisionInfoSync(bundleName, userId); + hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); +} catch (err) { + hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', err.message); +} +``` + ### bundleManager.getSpecifiedDistributionType10+ getSpecifiedDistributionType(bundleName: string): string;