add os account c api

Signed-off-by: jidong <jidong4@huawei.com>
Change-Id: Ic25cbffb68956e8255246e187fae8ef6934bec24
This commit is contained in:
jidong 2024-04-01 22:10:34 +08:00
parent 2476571e32
commit 48a6e9a330
4 changed files with 165 additions and 0 deletions

31
BasicServicesKit/BUILD.gn Normal file
View File

@ -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_ndk_header") {
dest_dir = "$ndk_headers_out_dir/BasicServicesKit/"
sources = [
"./os_account.h",
"./os_account_common.h",
]
}
ohos_ndk_library("libos_account_ndk") {
output_name = "os_account_ndk"
output_extension = "so"
system_capability = "SystemCapability.Account.OsAccount"
ndk_description_file = "./libos_account.ndk.json"
min_compact_version = "12"
system_capability_headers = [ "BasicServicesKit/os_account.h" ]
}

View File

@ -0,0 +1,5 @@
[
{ "first_introduced": "12",
"name":"OH_OsAccount_GetName"
}
]

View File

@ -0,0 +1,62 @@
/*
* 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 <stddef.h>
#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 OS_ACCOUNT_ERR_OK - Indicates successful;<br>
* OS_ACCOUNT_ERR_INTERNAL_ERROR - Indicates the internal error.<br>
* OS_ACCOUNT_ERR_INVALID_PARAMETER - Indicates the <i>buf</i> is NULL pointer or the size of the name,
* including the terminating character ('\0'), is larger then <i>buffer_size</i>;
* @syscap SystemCapability.Account.OsAccount
* @since 12
*/
OsAccount_ErrCode OH_OsAccount_GetName(char *buffer, size_t buffer_size);
#ifdef __cplusplus
}
#endif
/** @} */
#endif // OS_ACCOUNT_H

View File

@ -0,0 +1,67 @@
/*
* 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