1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup AbilityRuntime 18 * @{ 19 * 20 * @brief Describe the functions provided by the application context. 21 * 22 * @syscap SystemCapability.Ability.AbilityRuntime.Core 23 * @since 13 24 */ 25 26 /** 27 * @file application_context.h 28 * 29 * @brief Defines the application context APIs. 30 * 31 * @library libability_runtime.so 32 * @kit AbilityKit 33 * @syscap SystemCapability.Ability.AbilityRuntime.Core 34 * @since 13 35 */ 36 37 #ifndef ABILITY_RUNTIME_APPLICATION_CONTEXT_H 38 #define ABILITY_RUNTIME_APPLICATION_CONTEXT_H 39 40 #include <stdint.h> 41 #include <stddef.h> 42 #include <AbilityKit/ability_base/want.h> 43 #include "ability_runtime_common.h" 44 #include "context_constant.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Obtain the cache directory of the application. 52 * 53 * @param buffer A pointer to a buffer that receives the cache directory of the application. 54 * @param bufferSize The length of the buffer. 55 * @param writeLength The string length actually written to the buffer, 56 * when returning {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR}. 57 * @return The error code. 58 * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. 59 * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the buffer or writeLength is null, 60 * or the buffer size is less than the minimum buffer size. 61 * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. 62 * @since 13 63 */ 64 AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir( 65 char* buffer, int32_t bufferSize, int32_t* writeLength); 66 67 /** 68 * @brief Obtain the area mode of the application. 69 * 70 * @param areaMode A pointer to the area mode. 71 * @return The error code. 72 * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. 73 * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the areaMode is null. 74 * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. 75 * @since 13 76 */ 77 AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetAreaMode(AbilityRuntime_AreaMode* areaMode); 78 79 /** 80 * @brief Obtain the bundle name. 81 * 82 * @param buffer A pointer to a buffer that receives the bundle name. 83 * @param bufferSize The length of the buffer. 84 * @param writeLength The string length actually written to the buffer, 85 * when returning {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR}. 86 * @return The error code. 87 * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. 88 * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the buffer or writeLength is null, 89 * or the buffer size is less than the minimum buffer size. 90 * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. 91 * @since 13 92 */ 93 AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetBundleName( 94 char* buffer, int32_t bufferSize, int32_t* writeLength); 95 96 /** 97 * @brief Starts self UIAbility. 98 * 99 * @permission {@code ohos.permission.NDK_START_SELF_UI_ABILITY} 100 * @param want The arguments passed to start self UIAbility. 101 * For details, see {@link AbilityBase_Want}. 102 * @return Returns {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the call is successful. 103 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED} if the caller has no correct permission. 104 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the arguments provided is invalid. 105 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_NOT_SUPPORTED} if the device does not support starting self uiability. 106 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY} if the target ability does not exist. 107 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE} if the ability type is incorrect. 108 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_CROWDTEST_EXPIRED} if the crowdtesting application expires. 109 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE} if the ability cannot be started in Wukong mode. 110 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_CONTROLLED} if the app is controlled. 111 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_EDM_CONTROLLED} if the app is controlled by EDM. 112 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_CROSS_APP} if the caller tries to start a different application. 113 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_INTERNAL} if internal error occurs. 114 * Returns {@link ABILITY_RUNTIME_ERROR_CODE_NOT_TOP_ABILITY} if the caller is not top ability. 115 * For details, see {@link AbilityRuntime_ErrorCode}. 116 * @since 15 117 */ 118 AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbility(AbilityBase_Want *want); 119 120 #ifdef __cplusplus 121 } // extern "C" 122 #endif 123 124 /** @} */ 125 #endif // ABILITY_RUNTIME_APPLICATION_CONTEXT_H 126