* Copyright (c) 2026 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.
*/
* @addtogroup AbilityRuntime
* @{
*
* @brief Provides the definition of the C interface for the modular object extension context.
*
* @since 26.0.0
*/
* @file modular_object_extension_context.h
*
* @brief Declares the modular object extension context.
*
* @library libability_runtime.so
* @kit AbilityKit
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @since 26.0.0
*/
#ifndef ABILITY_RUNTIME_MODULAR_OBJECT_EXTENSION_CONTEXT_H
#define ABILITY_RUNTIME_MODULAR_OBJECT_EXTENSION_CONTEXT_H
#include "AbilityKit/ability_base/want.h"
#include "ability_runtime_common.h"
#include "context.h"
#include "IPCKit/ipc_cremote_object.h"
#include "start_options.h"
#ifdef __cplusplus
extern "C" {
#endif
* @brief Defines a pointer type to OH_AbilityRuntime_ModObjExtensionContextHandle.
*
* @since 26.0.0
*/
typedef struct OH_AbilityRuntime_ModularObjectExtensionContext* OH_AbilityRuntime_ModObjExtensionContextHandle;
* @brief Gets the base context from the modular object extension context.
*
* @param modObjExtensionContext Represents a pointer to a modular object extension ability context.
* @param baseContext Represents a pointer to a {@link AbilityRuntime_ContextHandle} base extension ability context.
* @return Returns a specific error code.
* {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} success.
* {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} parameter check failed.
* @since 26.0.0
*/
AbilityRuntime_ErrorCode OH_AbilityRuntime_ModObjExtensionContext_GetBaseContext(
OH_AbilityRuntime_ModObjExtensionContextHandle modObjExtensionContext, AbilityRuntime_ContextHandle* baseContext);
* @brief Starts the self UIAbility.
*
* @permission ohos.permission.NDK_START_SELF_UI_ABILITY
* @param context Represents a pointer to a modular object extension ability context.
* @param want The arguments passed to start the self UIAbility.
* For details, see {@link AbilityBase_Want}.
* @return Returns a specific error code.
* {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the call is successful.
* {@link ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED} if the caller has no correct permission.
* {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the arguments provided is invalid.
* {@link ABILITY_RUNTIME_ERROR_CODE_NOT_SUPPORTED} if the device does not support starting self UIAbility.
* {@link ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY} if the target ability does not exist.
* {@link ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE} if the ability type is incorrect.
* {@link ABILITY_RUNTIME_ERROR_CODE_CROWDTEST_EXPIRED} if the crowdtesting application expires.
* {@link ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE} if the ability cannot be started in Wukong mode.
* {@link ABILITY_RUNTIME_ERROR_CODE_CONTROLLED} if the app is controlled.
* {@link ABILITY_RUNTIME_ERROR_CODE_EDM_CONTROLLED} if the app is controlled by EDM.
* {@link ABILITY_RUNTIME_ERROR_CODE_CROSS_APP} if the caller tries to start a different application.
* {@link ABILITY_RUNTIME_ERROR_CODE_INTERNAL} if an internal error occurs.
* {@link ABILITY_RUNTIME_ERROR_CODE_NOT_TOP_ABILITY} if the caller is not top ability.
* {@link ABILITY_RUNTIME_ERROR_CODE_MULTI_APP_NOT_SUPPORTED} if the app clone or multi-instance is
not supported.
* {@link ABILITY_RUNTIME_ERROR_CODE_INVALID_APP_INSTANCE_KEY} if the app instance key is invalid.
* {@link ABILITY_RUNTIME_ERROR_CODE_UPPER_LIMIT_REACHED} if the number of app instances has reached
the limit.
* {@link ABILITY_RUNTIME_ERROR_MULTI_INSTANCE_NOT_SUPPORTED} if multi-instance is not supported.
* {@link ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED} if the APP_INSTANCE_KEY cannot
be specified.
* @since 26.0.0
*/
AbilityRuntime_ErrorCode OH_AbilityRuntime_ModObjExtensionContext_StartSelfUIAbility(
OH_AbilityRuntime_ModObjExtensionContextHandle context, const AbilityBase_Want *want);
* @brief Starts the self UIAbility with start options.
*
* @permission ohos.permission.NDK_START_SELF_UI_ABILITY
* @param context Represents a pointer to a modular object extension ability context.
* @param want The arguments passed to start the self UIAbility.
* For details, see {@link AbilityBase_Want}.
* @param options The start options passed to start the self UIAbility.
* For details, see {@link AbilityRuntime_StartOptions}.
* @return Returns a specific error code.
* {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the call is successful.
* {@link ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED} if the caller has no correct permission.
* {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the arguments provided are invalid.
* {@link ABILITY_RUNTIME_ERROR_CODE_NOT_SUPPORTED} if the device does not support starting self UIAbility.
* {@link ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY} if the target ability does not exist.
* {@link ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE} if the ability type is incorrect.
* {@link ABILITY_RUNTIME_ERROR_CODE_CROWDTEST_EXPIRED} if the crowdtesting application expires.
* {@link ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE} if the ability cannot be started in Wukong mode.
* {@link ABILITY_RUNTIME_ERROR_CODE_CONTROLLED} if the app is controlled.
* {@link ABILITY_RUNTIME_ERROR_CODE_EDM_CONTROLLED} if the app is controlled by EDM.
* {@link ABILITY_RUNTIME_ERROR_CODE_CROSS_APP} if the caller tries to start a different application.
* {@link ABILITY_RUNTIME_ERROR_CODE_INTERNAL} if an internal error occurs.
* {@link ABILITY_RUNTIME_ERROR_CODE_NOT_TOP_ABILITY} if the caller is not a foreground process.
* {@link ABILITY_RUNTIME_ERROR_VISIBILITY_SETTING_DISABLED} if setting visibility is disabled.
* {@link ABILITY_RUNTIME_ERROR_CODE_MULTI_APP_NOT_SUPPORTED} if the app clone or multi-instance is
not supported.
* {@link ABILITY_RUNTIME_ERROR_CODE_INVALID_APP_INSTANCE_KEY} if the app instance key is invalid.
* {@link ABILITY_RUNTIME_ERROR_CODE_UPPER_LIMIT_REACHED} if the number of app instances has reached
the limit.
* {@link ABILITY_RUNTIME_ERROR_MULTI_INSTANCE_NOT_SUPPORTED} if multi-instance is not supported.
* {@link ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED} if the APP_INSTANCE_KEY cannot
be specified.
* @since 26.0.0
*/
AbilityRuntime_ErrorCode OH_AbilityRuntime_ModObjExtensionContext_StartSelfUIAbilityWithStartOptions(
OH_AbilityRuntime_ModObjExtensionContextHandle context, const AbilityBase_Want *want,
const AbilityRuntime_StartOptions *options);
* @brief Destroys the modular object extension.
*
* @param context Represents a pointer to a modular object extension ability context.
* @return <ul>
* <li>{@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the call is successful.</li>
* <li>{@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the arguments provided are invalid.</li>
* <li>{@link ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE} if the ability cannot be terminated in Wukong mode.</li>
* <li>{@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the context does not exist.</li>
* <li>{@link ABILITY_RUNTIME_ERROR_CODE_INTERNAL} if an internal error occurs.</li>
* </ul>
* @since 26.0.0
*/
AbilityRuntime_ErrorCode OH_AbilityRuntime_ModObjExtensionContext_TerminateSelf(
OH_AbilityRuntime_ModObjExtensionContextHandle context);
* @brief Creates an <b>OHIPCRemoteStub</b> object with callbacks running on the extension's designated thread.
* The requestCallback and destroyCallback are invoked serially on the thread determined by the
* extension's {@link OH_AbilityRuntime_ThreadMode}. After calling
* {@link OH_AbilityRuntime_ModObjExtensionContext_DestroyIPCRemoteStub}, no new requestCallback
* invocations will occur, and any in-flight requestCallback will complete before destroyCallback is invoked.
*
* The caller is responsible for destroying the returned object by calling
* {@link OH_AbilityRuntime_ModObjExtensionContext_DestroyIPCRemoteStub} to avoid memory leaks.
*
* @param context Represents a pointer to a modular object extension ability context.
* @param descriptor Pointer to the descriptor of the <b>OHIPCRemoteStub</b> object to create. It cannot be NULL.
* The string is copied internally during creation, so the caller may release the descriptor
* after this function returns.
* @param requestCallback Callback used to process the data request. It cannot be NULL.
* @param destroyCallback Callback to be invoked when the object is destroyed. It can be NULL.
* @param userData Pointer to the user data. It can be NULL. Must remain valid before the object is destroyed.
* @return Returns the pointer to the <b>OHIPCRemoteStub</b> object created if the operation is successful;
* returns NULL otherwise.
* @since 26.0.0
*/
OHIPCRemoteStub* OH_AbilityRuntime_ModObjExtensionContext_CreateIPCRemoteStub(
OH_AbilityRuntime_ModObjExtensionContextHandle context, const char *descriptor,
OH_OnRemoteRequestCallback requestCallback, OH_OnRemoteDestroyCallback destroyCallback, void *userData);
* @brief Destroys an <b>OHIPCRemoteStub</b> object.
*
* @param context Represents a pointer to a modular object extension ability context.
* @param stub Pointer to the <b>OHIPCRemoteStub</b> object to destroy.
* @since 26.0.0
*/
void OH_AbilityRuntime_ModObjExtensionContext_DestroyIPCRemoteStub(
OH_AbilityRuntime_ModObjExtensionContextHandle context, OHIPCRemoteStub *stub);
#ifdef __cplusplus
}
#endif
#endif