1 /* 2 * Copyright (c) 2021 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 BundleManager 18 * 19 * @brief Provides structures and functions for managing application bundles and obtaining application information. 20 * 21 * @since 1.0 22 * @version 1.0 23 */ 24 25 /** 26 * @file bundle_manager.h 27 * 28 * @brief Declares functions used for managing application bundles and obtaining bundle information. 29 * 30 * You can use functions provided in this file to install, update, or uninstall an application, obtain 31 * {@link AbilityInfo} and {@link BundleInfo} about an application, obtain the bundle name of an application based 32 * on the application's user ID (UID), and obtain {@link BundleInfo} objects of all applications or keep-alive 33 * applications in the system. 34 * 35 * @since 1.0 36 * @version 1.0 37 */ 38 #ifndef OHOS_BUNDLEMANAGER_INTERFACE_H 39 #define OHOS_BUNDLEMANAGER_INTERFACE_H 40 41 #include "ability_info.h" 42 #include "bundle_info.h" 43 #include "bundle_status_callback.h" 44 #include "install_param.h" 45 #include "stdint.h" 46 #include "want.h" 47 48 #ifdef __cplusplus 49 #if __cplusplus 50 extern "C" { 51 #endif 52 #endif /* __cplusplus */ 53 54 /** 55 * @brief Called when an application is installed, updated, or uninstalled. 56 * 57 * This function can be registered through {@link Install} and {@link Uninstall} to receive the installation, update, 58 * and uninstallation result. 59 * 60 * @param resultCode Indicates the status code returned for the application installation, update, or uninstallation 61 * result. For details, see {@link AppexecfwkErrors}. 62 * @param resultMessage Indicates the result message returned with the status code. 63 * 64 * @since 1.0 65 * @version 1.0 66 */ 67 typedef void (*InstallerCallback)(const uint8_t resultCode, const void *resultMessage); 68 69 /** 70 * @brief Installs or updates an application. 71 * 72 * 73 * @param hapPath Indicates the pointer to the path for storing the OpenHarmony Ability Package (HAP) of the application 74 * to install or update. 75 * @param installParam Indicates the pointer to the parameters used for application installation or update. 76 * @param installerCallback Indicates the callback to be invoked for notifying the installation or update result. 77 * @return Returns <b>true</b> if this function is successfully called; returns <b>false</b> otherwise. 78 * 79 * @since 1.0 80 * @version 1.0 81 */ 82 bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback); 83 84 /** 85 * @brief Uninstalls an application. 86 * 87 * @param bundleName Indicates the pointer to the bundle name of the application to uninstall. 88 * @param installParam Indicates the pointer to the parameters used for application uninstallation. 89 * @param installerCallback Indicates the callback to be invoked for notifying the uninstallation result. 90 * @return Returns <b>true</b> if this function is successfully called; returns <b>false</b> otherwise. 91 * 92 * @since 1.0 93 * @version 1.0 94 */ 95 bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback); 96 97 /** 98 * @brief Queries the {@link AbilityInfo} of an ability based on the information carried in the {@link Want} 99 * structure. 100 * @attention Before querying an {@link AbilityInfo} object, you should first call <b>memset</b> on the 101 * constructed {@link AbilityInfo} object so that each field in it can be properly initialized 102 * for carrying the obtained information. 103 * @param want Indicates the pointer to the {@link Want} structure used for querying the specified ability. 104 * @param abilityInfo Indicates the pointer to the obtained {@link AbilityInfo} object. 105 * 106 * @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in 107 * {@link AppexecfwkErrors} otherwise. 108 * 109 * @since 1.0 110 * @version 1.0 111 */ 112 uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); 113 114 /** 115 * @brief Obtains the {@link BundleInfo} of an application based on the specified bundle name. 116 * 117 * @attention Before querying a {@link BundleInfo} object, you should first call <b>memset</b> on the constructed 118 * {@link BundleInfo} object so that each field in it can be properly initialized for carrying the 119 * obtained information. 120 * @param bundleName Indicates the pointer to the name of the application bundle to query. 121 * @param flags Specifies whether the obtained {@link BundleInfo} object can contain {@link AbilityInfo}. The value 122 * <b>1</b> indicates that it can contain {@link AbilityInfo}, and <b>0</b> indicates that it cannot. 123 * @param bundleInfo Indicates the pointer to the obtained {@link BundleInfo} object. 124 * 125 * @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in 126 * {@link AppexecfwkErrors} otherwise. 127 * 128 * @since 1.0 129 * @version 1.0 130 */ 131 uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo); 132 133 /** 134 * @brief Obtains the {@link BundleInfo} of all bundles in the system. 135 * 136 * @param flags Specifies whether each of the obtained {@link BundleInfo} objects can contain {@link AbilityInfo}. 137 * The value <b>1</b> indicates that it can contain {@link AbilityInfo}, and <b>0</b> indicates that 138 * it cannot. 139 * @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects. 140 * @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained. 141 * @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in 142 * {@link AppexecfwkErrors} otherwise. 143 * 144 * @since 1.0 145 * @version 1.0 146 */ 147 uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); 148 #ifdef __cplusplus 149 #if __cplusplus 150 } 151 #endif 152 #endif /* __cplusplus */ 153 #endif /* OHOS_BUNDLEMANAGER_INTERFACE_H */ 154 /** @} */