* Copyright (c) 2024 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.
*/
#ifndef HNP_API_H
#define HNP_API_H
#include "hilog/log.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef APPSPAWN_TEST
#ifndef APPSPAWN_STATIC
#define APPSPAWN_STATIC static
#endif
#else
#ifndef APPSPAWN_STATIC
#define APPSPAWN_STATIC
#endif
#endif
typedef enum {
OPTION_INDEX_FORCE = 0,
OPTION_INDEX_BUTT
} HnpInstallOptionIndex;
#define HNP_API_ERRNO_BASE 0x2000
#define FD_BUFFER_LEN (64)
#define HNP_INFO_RET_FD_ENV "HNP_INFO_RET_FD_ENV"
#define SESSIONID_BUFFER_LEN (32)
#define HNP_API_ERRNO_PARAM_INVALID (HNP_API_ERRNO_BASE + 0x1)
#define HNP_API_ERRNO_FORK_FAILED (HNP_API_ERRNO_BASE + 0x2)
#define HNP_API_WAIT_PID_FAILED (HNP_API_ERRNO_BASE + 0x3)
#define HNP_API_NOT_IN_DEVELOPER_MODE (HNP_API_ERRNO_BASE + 0x4)
#define HNP_API_ERRNO_PIPE_CREATED_FAILED (HNP_API_ERRNO_BASE + 0x5)
#define HNP_API_ERRNO_PIPE_READ_FAILED (HNP_API_ERRNO_BASE + 0x6)
#define HNP_API_ERRNO_RETURN_VALUE_GET_FAILED (HNP_API_ERRNO_BASE + 0x7)
#define HNP_API_ERRNO_MEMMOVE_FAILED (HNP_API_ERRNO_BASE + 0x8)
#define HNP_API_ERRNO_HNP_INSTALL_DISABLED (HNP_API_ERRNO_BASE + 0x9)
#define HNP_API_ERRNO_TOO_MANY_PARAM (HNP_API_ERRNO_BASE + 0x10)
#define PACK_NAME_LENTH 256
#define HAP_PATH_LENTH 512
#define ABI_LENTH 128
#define APP_IDENTIFIER_LEN 64
typedef struct HapInfo {
char packageName[PACK_NAME_LENTH];
char hapPath[HAP_PATH_LENTH];
char abi[ABI_LENTH];
char appIdentifier[APP_IDENTIFIER_LEN];
int count;
char **independentSignHnpPaths;
} HapInfo;
typedef struct HnpResult {
int result;
} HnpResult;
* Install native software package.
*
* @param userId Indicates id of user.
* @param hnpRootPath Indicates the root path of hnp packages
* @param hapInfo Indicates the information of HAP.
* @param installOptions Indicates install options.
*
* @return 0:success;other means failure.
*/
int NativeInstallHnp(const char *userId, const char *hnpRootPath, const HapInfo *hapInfo,
int installOptions, int32_t sessionId);
* Uninstall native software package.
*
* @param userId Indicates id of user.
* @param packageName Indicates the packageName of HAP.
*
* @return 0:success;other means failure.
*/
int NativeUnInstallHnp(const char *userId, const char *packageName);
#define HNPAPI_LOG(fmt, ...) \
HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d]" fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
#define HNPAPI_INFO_CHECK(ret, statement, format, ...) \
do { \
if (!(ret)) { \
HNPAPI_LOG(format, ##__VA_ARGS__); \
statement; \
} \
} while (0)
#define HNPAPI_LOG_ERR(fmt, ...) \
HILOG_ERROR(LOG_CORE, "[%{public}s:%{public}d]" fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
#define HNPAPI_ERROR_CHECK(ret, statement, format, ...) \
do { \
if (!(ret)) { \
HNPAPI_LOG_ERR(format, ##__VA_ARGS__); \
statement; \
} \
} while (0)
#ifdef __cplusplus
}
#endif
#endif