diff --git a/api/@ohos.app.ability.UIExtensionContentSession.d.ts b/api/@ohos.app.ability.UIExtensionContentSession.d.ts index 480ee6558..c0721b0a6 100644 --- a/api/@ohos.app.ability.UIExtensionContentSession.d.ts +++ b/api/@ohos.app.ability.UIExtensionContentSession.d.ts @@ -14,6 +14,7 @@ */ import type { AbilityResult } from './ability/abilityResult'; +import type { AbilityStartCallback } from './application/AbilityStartCallback'; import type { AsyncCallback } from './@ohos.base'; import type { LocalStorage } from 'StateManagement'; import type Want from './@ohos.app.ability.Want'; @@ -357,4 +358,50 @@ export default class UIExtensionContentSession { * @since 10 */ setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback): void; + + /** + * Starts the UIAbility or UIExtensionAbility by type. + * If the target ability is visible, you can start the target ability; If the target ability is invisible, + * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. + * + * @param { string } type - The type of target ability. + * @param { Record } wantParam - Indicates the want parameter. + * @param { AbilityStartCallback } abilityStartCallback - Indicates the abilityStartCallback. + * @param { AsyncCallback } callback - The callback of startAbility. + * @throws { BusinessError } 201 - The application does not have permission to call the interface. + * @throws { BusinessError } 401 - If the input parameter is not valid parameter. + * @throws { BusinessError } 16000001 - The specified ability does not exist. + * @throws { BusinessError } 16000002 - Incorrect ability type. + * @throws { BusinessError } 16000004 - Can not start invisible component. + * @throws { BusinessError } 16000050 - Internal error. + * @throws { BusinessError } 16200001 - The caller has been released. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @StageModelOnly + * @since 11 + */ + startAbilityByType(type: string, wantParam: Record, + abilityStartCallback: AbilityStartCallback, callback: AsyncCallback): void; + + /** + * Starts the UIAbility or UIExtensionAbility by type. + * If the target ability is visible, you can start the target ability; If the target ability is invisible, + * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. + * + * @param { string } type - The type of target ability. + * @param { Record } wantParam - Indicates the want parameter. + * @param { AbilityStartCallback } abilityStartCallback - Indicates the abilityStartCallback. + * @returns { Promise } The promise returned by the function. + * @throws { BusinessError } 201 - The application does not have permission to call the interface. + * @throws { BusinessError } 401 - If the input parameter is not valid parameter. + * @throws { BusinessError } 16000001 - The specified ability does not exist. + * @throws { BusinessError } 16000002 - Incorrect ability type. + * @throws { BusinessError } 16000004 - Can not start invisible component. + * @throws { BusinessError } 16000050 - Internal error. + * @throws { BusinessError } 16200001 - The caller has been released. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @StageModelOnly + * @since 11 + */ + startAbilityByType(type: string, wantParam: Record, + abilityStartCallback: AbilityStartCallback): Promise; } diff --git a/api/@ohos.app.ability.common.d.ts b/api/@ohos.app.ability.common.d.ts index 3fc9c6348..f73fa25a9 100644 --- a/api/@ohos.app.ability.common.d.ts +++ b/api/@ohos.app.ability.common.d.ts @@ -25,6 +25,7 @@ import * as _ServiceExtensionContext from './application/ServiceExtensionContext import * as _EventHub from './application/EventHub'; import { PacMap as _PacMap } from './ability/dataAbilityHelper'; import { AbilityResult as _AbilityResult } from './ability/abilityResult'; +import type { AbilityStartCallback as _AbilityStartCallback } from './application/AbilityStartCallback'; import { ConnectOptions as _ConnectOptions } from './ability/connectOptions'; /** @@ -207,6 +208,15 @@ declare namespace common { * @since 10 */ export type UIExtensionContext = _UIExtensionContext.default; + + /** + * The function Called when some error occurred except disconnected from UIAbility or UIExtensionAbility + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @StageModelOnly + * @since 11 + */ + export type AbilityStartCallback = _AbilityStartCallback; } export default common; diff --git a/api/ability/uiExtensionCallback.d.ts b/api/ability/uiExtensionCallback.d.ts deleted file mode 100644 index f7a5390eb..000000000 --- a/api/ability/uiExtensionCallback.d.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Want from '../@ohos.app.ability.Want'; - -/** - * @interface UIExtensionCallback - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - * @since 11 - */ -export interface UIExtensionCallback { - /** - * Called when remote UIExtensionAbility object is ready for receive data. - * - * @param { UIExtensionProxy } proxy - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - * @since 11 - */ - onRemoteReady(proxy: UIExtensionProxy): void; - - /** - * Called when data received from UIExtensionAbility. - * - * @param { object } parameters - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - * @since 11 - */ - onReceive(parameters: { [key: string]: Object }): void; - - /** - * Called when the UIExtensionAbility is terminated with result data. - * - * @param { number } code - * @param { Want } want - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - * @since 11 - */ - onResult(code: number, want?: Want): void; - - /** - * Returned number if disconnected from UIExtensionAbility, 0 means the - * UIExtensionAbility is terminate by itself, otherwise the connect is broken abnormal. - * - * @param { number } code - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - * @since 11 - */ - onRelease(code: number): void; - - /** - * Called when some error occurred except disconnected from UIExtensionAbility. - * - * @param { number } code - * @param { string } name - * @param { string } message - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - * @since 11 - */ - onError(code: number, name: string, message: string): void; -} diff --git a/api/application/AbilityStartCallback.d.ts b/api/application/AbilityStartCallback.d.ts new file mode 100644 index 000000000..fa0b9a3bd --- /dev/null +++ b/api/application/AbilityStartCallback.d.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The callback of UIAbility or UIExtensionAbility. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @StageModelOnly + * @since 11 + */ +export default class AbilityStartCallback { + + /** + * Called when some error occurred except disconnected from UIAbility or UIExtensionAbility. + * + * @param { number } code - The code returned if the UIAbility or UIExtensionAbility failed to start. + * @param { string } name - The name returned if the UIAbility or UIExtensionAbility failed to start. + * @param { string } message - The message returned if the UIAbility or UIExtensionAbility failed to start. + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @StageModelOnly + * @since 11 + */ + onError(code: number, name: string, message: string): void; +} diff --git a/api/application/UIAbilityContext.d.ts b/api/application/UIAbilityContext.d.ts index e20ff6e06..b4f5bc81c 100644 --- a/api/application/UIAbilityContext.d.ts +++ b/api/application/UIAbilityContext.d.ts @@ -29,7 +29,7 @@ import { LocalStorage } from 'StateManagement'; import image from '../@ohos.multimedia.image'; import dialogRequest from '../@ohos.app.ability.dialogRequest'; import AbilityConstant from '../@ohos.app.ability.AbilityConstant'; -import { UIExtensionCallback } from '../ability/uiExtensionCallback'; +import type { AbilityStartCallback } from './AbilityStartCallback'; /** * The context of an ability. It allows access to ability-specific resources. @@ -2089,14 +2089,14 @@ export default class UIAbilityContext extends Context { reportDrawnCompleted(callback: AsyncCallback): void; /** - * Starts the uiExtensionability by type. + * Starts the UIAbility or UIExtensionAbility by type. * If the target ability is visible, you can start the target ability; If the target ability is invisible, * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. * - * @param { string } type - The type of UIExtensionAbilitys. - * @param { object } wantParam - Indicates the want parameter. - * @param { UIExtensionCallback } uiExtensioncallback - Indicates the uiExtensioncallback. - * @param { AsyncCallback } callback - The callback of startUIExtensionAbilityByType. + * @param { string } type - The type of target ability. + * @param { Record } wantParam - Indicates the want parameter. + * @param { AbilityStartCallback } abilityStartCallback - Indicates the abilityStartCallback. + * @param { AsyncCallback } callback - The callback of startAbility. * @throws { BusinessError } 201 - The application does not have permission to call the interface. * @throws { BusinessError } 401 - If the input parameter is not valid parameter. * @throws { BusinessError } 16000001 - The specified ability does not exist. @@ -2108,17 +2108,17 @@ export default class UIAbilityContext extends Context { * @StageModelOnly * @since 11 */ - startUIExtensionAbilityByType(type: string, wantParam: { [key: string]: Object }, - uiExtensioncallback: UIExtensionCallback, callback: AsyncCallback): void; + startAbilityByType(type: string, wantParam: Record, + abilityStartCallback: AbilityStartCallback, callback: AsyncCallback): void; /** - * Starts the uiExtensionability by type. + * Starts the UIAbility or UIExtensionAbility by type. * If the target ability is visible, you can start the target ability; If the target ability is invisible, * you need to apply for permission:ohos.permission.START_INVISIBLE_ABILITY to start target invisible ability. * - * @param { string } type - The type of UIExtensionAbilitys. - * @param { object } wantParam - Indicates the want parameter. - * @param { UIExtensionCallback } uiExtensioncallback - Indicates the uiExtensioncallback. + * @param { string } type - The type of target ability. + * @param { Record } wantParam - Indicates the want parameter. + * @param { AbilityStartCallback } abilityStartCallback - Indicates the abilityStartCallback. * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 201 - The application does not have permission to call the interface. * @throws { BusinessError } 401 - If the input parameter is not valid parameter. @@ -2131,6 +2131,6 @@ export default class UIAbilityContext extends Context { * @StageModelOnly * @since 11 */ - startUIExtensionAbilityByType(type: string, wantParam: { [key: string]: Object }, - uiExtensioncallback: UIExtensionCallback): Promise; + startAbilityByType(type: string, wantParam: Record, + abilityStartCallback: AbilityStartCallback): Promise; }