From f390095cc2c5200a0aabc1e66a08e643419d4fa2 Mon Sep 17 00:00:00 2001 From: jidong Date: Mon, 1 Apr 2024 22:05:24 +0800 Subject: [PATCH] add os account c api Signed-off-by: jidong Change-Id: Id87827c19eee5a05947bc7fad40b5dbaea68a104 --- account/os_account/BUILD.gn | 31 +++++++++ account/os_account/include/os_account.h | 60 +++++++++++++++++ .../os_account/include/os_account_common.h | 65 +++++++++++++++++++ account/os_account/libos_account.ndk.json | 5 ++ 4 files changed, 161 insertions(+) create mode 100644 account/os_account/BUILD.gn create mode 100644 account/os_account/include/os_account.h create mode 100644 account/os_account/include/os_account_common.h create mode 100644 account/os_account/libos_account.ndk.json diff --git a/account/os_account/BUILD.gn b/account/os_account/BUILD.gn new file mode 100644 index 000000000..c5dece9e9 --- /dev/null +++ b/account/os_account/BUILD.gn @@ -0,0 +1,31 @@ +# 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. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +ohos_ndk_headers("os_account_header") { + dest_dir = "$ndk_headers_out_dir/account/" + sources = [ + "./include/os_account.h", + "./include/os_account_common.h", + ] +} + +ohos_ndk_library("libos_account") { + output_name = "os_account" + output_extension = "so" + system_capability = "SystemCapability.Account.OsAccount" + ndk_description_file = "./libos_account.ndk.json" + min_compact_version = "12" + system_capability_headers = [ "account/os_account.h" ] +} diff --git a/account/os_account/include/os_account.h b/account/os_account/include/os_account.h new file mode 100644 index 000000000..de3bdf3fa --- /dev/null +++ b/account/os_account/include/os_account.h @@ -0,0 +1,60 @@ +/* + * 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 OS_ACCOUNT_H +#define OS_ACCOUNT_H + +/** + * @addtogroup OsAccount + * @{ + * + * @brief Provide the definition of the C interface for the native OsAccount. + * @since 12 + */ +/** + * @file os_account.h + * + * @brief Declares the APIs for accessing and managing the OS account information. + * @library libos_account.so + * @syscap SystemCapability.Account.OsAccount + * @since 12 + */ + +#include +#include "os_account_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Gets the name of the OS account to which the caller process belongs. + * + * @param buffer The name character array which should have space for the name and the terminating character ('\0'). + * @param buffer_size The size of the name character array. + * @return 0 - Indicates successful;
+ * 12300001 - Indicates the internal error.
+ * 12300002 - Indicates the buf is NULL pointer or the size of the name, including the terminating + * character ('\0'), is larger then buf_size; + * @syscap SystemCapability.Account.OsAccount + * @since 12 + */ +OsAccount_ErrCode OH_OsAccount_GetName(char *buffer, size_t buffer_size); + +#ifdef __cplusplus +}; +#endif + +#endif // OS_ACCOUNT_H diff --git a/account/os_account/include/os_account_common.h b/account/os_account/include/os_account_common.h new file mode 100644 index 000000000..a5f422577 --- /dev/null +++ b/account/os_account/include/os_account_common.h @@ -0,0 +1,65 @@ +/* + * 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 OS_ACCOUNT_COMMON_H +#define OS_ACCOUNT_COMMON_H + +/** + * @addtogroup OsAccount + * @{ + * + * @brief Provide the definition of the C interface for the native OsAccount. + * @since 12 + */ +/** + * @file os_account_common.h + * + * @brief Declare the common types for the native OsAccount. + * @library libos_account.so + * @syscap SystemCapability.Account.OsAccount + * @since 12 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the error codes. + * + * @since 12 + */ +typedef enum OsAccount_ErrCode { + /** + * Operation is successful. + */ + OS_ACCOUNT_ERR_OK = 0, + + /** + * Internal error. + */ + OS_ACCOUNT_ERR_INTERNAL_ERROR = 12300001, + + /** + * Invalid parameter. + */ + OS_ACCOUNT_ERR_INVALID_PARAMETER = 12300002 +} OsAccount_ErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // OS_ACCOUNT_COMMON_H diff --git a/account/os_account/libos_account.ndk.json b/account/os_account/libos_account.ndk.json new file mode 100644 index 000000000..e77db8847 --- /dev/null +++ b/account/os_account/libos_account.ndk.json @@ -0,0 +1,5 @@ +[ + { "first_introduced": "12", + "name":"OH_OsAccount_GetName" + } +] \ No newline at end of file -- Gitee