diff --git a/zh-cn/application-dev/reference/apis-ability-kit/errorcode-ability.md b/zh-cn/application-dev/reference/apis-ability-kit/errorcode-ability.md index cd6bd2cb8a67bfbe15ca549876c1b154809dbafc..7a285802c4b62b1a44a890bf82f08561dc88b85b 100644 --- a/zh-cn/application-dev/reference/apis-ability-kit/errorcode-ability.md +++ b/zh-cn/application-dev/reference/apis-ability-kit/errorcode-ability.md @@ -1707,4 +1707,58 @@ The target bundle is not in u1. **处理步骤** 将指定的应用安装在userId为1的用户下。 - \ No newline at end of file + + +## 16000115 当前进程未运行配置了"isolationProcess"的组件,无法设为备选主控进程。 + +**错误信息** + +Current process is not running a component configured with "isolationProcess", and cannot be set as a candidate master process. + +**错误描述** + +当前进程未运行配置了"isolationProcess"的组件,方法将返回该错误码。 + +**可能原因** + +当前进程未运行配置了"isolationProcess"的组件。 + +**处理步骤** + +根据需要使用其他运行配置了"isolationProcess"的组件的进程。 + +## 16000116 当前进程已是主控进程,不支持撤销操作。 + +**错误信息** + +Current process is already a master process, revocation is not supported. + +**错误描述** + +当前进程已是主控进程,方法将返回该错误码。 + +**可能原因** + +当前进程已是主控进程。 + +**处理步骤** + +检查当前进程是否是主控进程。 + +## 16000117 当前进程非备选主控进程,不支持撤销操作。 + +**错误信息** + +Current process is not a candidate master process, no need to revocation. + +**错误描述** + +当前进程非备选主控进程,方法将返回该错误码。 + +**可能原因** + +当前进程非备选主控进程。 + +**处理步骤** + +检查当前进程是否被设置为了备选主控进程。 diff --git a/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-application.md b/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-application.md index 26b4e251d13d3bc4b6c4b1f89e3daa739dfa9c21..d7658dc539fbb92640c9d49e843b8a3305b01c3a 100644 --- a/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-application.md +++ b/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-application.md @@ -166,4 +166,118 @@ export default class EntryAbility extends UIAbility { } } } +``` + +## application.promoteCurrentToCandidateMasterProcess20+ + +promoteCurrentToCandidateMasterProcess(insertToHead: boolean): Promise\ + +将当前进程放入备选主控进程链表,根据参数insertToHead的值控制是放到表头还是表尾。使用Promise异步回调。 + +> **说明:** +> +> 当前仅支持2in1、tablet设备。当应用内的UIAbility或UIExtension组件的isolationProcess字段取true时,启动这类组件实例将触发主控进程的[onNewProcessRequest](js-apis-app-ability-abilityStage.md#abilitystageonnewprocessrequest11)回调。当主控进程退出,那么再次启动isolationProcess字段取true的UIAbility或UIExtension组件实例时,如果备选主控进程链表不为空,那么会使用备选主控进程链表中的表头作为主控进程。 +> + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ---------------------------------------- | ---- | -------------- | +| insertToHead | boolean | 是 | 取值为true时将当前进程插入到备选主控进程链表表头,取值为false时将当前进程插入到备选主控进程链表表尾。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------ | ------------------- | +|Promise\ | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +以下错误码详细介绍请参考[通用错误码说明文档](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| -------- | --------------- | +| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | +| 16000115 | Current process is not running a component configured with \"isolationProcess\", and cannot be set as a candidate master process. | + + +**示例:** + +```ts +import { AbilityConstant, UIAbility, application, common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try{ + application.promoteCurrentToCandidateMasterProcess(true) + .then(() => { + console.info('promote succeed'); + }) + .catch((err: BusinessError) => { + console.error(`promote failed, code is ${err.code}, message is ${err.message}`) + }); + } catch (error) { + let code: number = (error as BusinessError).code; + let message: string = (error as BusinessError).message; + console.error(`promoteCurrentToCandidateMasterProcess failed, error.code: ${code}, error.message: ${message}`); + } + } +} +``` + +## application.demoteCurrentFromCandidateMasterProcess20+ + +demoteCurrentFromCandidateMasterProcess(): Promise\ + +撤销当前进程的备选主控进程资格。使用Promise异步回调。 + +> **说明:** +> +> 当前仅支持2in1、tablet设备。 +> + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**返回值:** + +| 类型 | 说明 | +| ------------------ | ------------------- | +|Promise\ | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +以下错误码详细介绍请参考[通用错误码说明文档](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| -------- | --------------- | +| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | +| 16000116 | Current process is already a master process, revocation is not supported. | +| 16000117 | Current process is not a candidate master process, no need to revocation. | + +**示例:** + +```ts +import { AbilityConstant, UIAbility, application, common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try{ + application.demoteCurrentFromCandidateMasterProcess() + .then(() => { + console.info('demote succeed'); + }) + .catch((err: BusinessError) => { + console.error(`demote failed, code is ${err.code}, message is ${err.message}`) + }); + } catch (error) { + let code: number = (error as BusinessError).code; + let message: string = (error as BusinessError).message; + console.error(`demoteCurrentFromCandidateMasterProcess failed, error.code: ${code}, error.message: ${message}`); + } + } +} ``` \ No newline at end of file