From 733c7d0746581ad1f9544f093de25f47018600fb Mon Sep 17 00:00:00 2001 From: DXwangg Date: Sun, 13 Oct 2024 17:48:56 +0800 Subject: [PATCH] [cj] support cj api for osaccount Change-Id: Ic66b06dde2302ebfa0ec5d8a8a2343e07cb7fca5 Signed-off-by: DXwangg --- bundle.json | 1 + interfaces/kits/cj/BUILD.gn | 19 ++ interfaces/kits/cj/osaccount/BUILD.gn | 68 +++++++ .../cj/osaccount/include/cj_osaccount_ffi.h | 43 +++++ interfaces/kits/cj/osaccount/include/common.h | 38 ++++ .../include/osaccount_manager_impl.h | 43 +++++ .../cj/osaccount/src/cj_osaccount_ffi.cpp | 173 ++++++++++++++++++ .../osaccount/src/osaccount_manager_impl.cpp | 142 ++++++++++++++ os_account.gni | 1 + 9 files changed, 528 insertions(+) create mode 100644 interfaces/kits/cj/BUILD.gn create mode 100644 interfaces/kits/cj/osaccount/BUILD.gn create mode 100644 interfaces/kits/cj/osaccount/include/cj_osaccount_ffi.h create mode 100644 interfaces/kits/cj/osaccount/include/common.h create mode 100644 interfaces/kits/cj/osaccount/include/osaccount_manager_impl.h create mode 100644 interfaces/kits/cj/osaccount/src/cj_osaccount_ffi.cpp create mode 100644 interfaces/kits/cj/osaccount/src/osaccount_manager_impl.cpp diff --git a/bundle.json b/bundle.json index 3476680bb..5593a12d5 100644 --- a/bundle.json +++ b/bundle.json @@ -71,6 +71,7 @@ "base_group": [ "//base/account/os_account/interfaces/kits/capi:capi_packages", "//base/account/os_account/interfaces/kits/napi:napi_packages", + "//base/account/os_account/interfaces/kits/cj:cj_ffi_packages", "//base/account/os_account/sa_profile:account_sa_profile", "//base/account/os_account/tools:tools_acm" ], diff --git a/interfaces/kits/cj/BUILD.gn b/interfaces/kits/cj/BUILD.gn new file mode 100644 index 000000000..63a0db30b --- /dev/null +++ b/interfaces/kits/cj/BUILD.gn @@ -0,0 +1,19 @@ +# 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("../../../os_account.gni") + +group("cj_ffi_packages") { + deps = [ "osaccount:cj_osaccount_ffi" ] +} diff --git a/interfaces/kits/cj/osaccount/BUILD.gn b/interfaces/kits/cj/osaccount/BUILD.gn new file mode 100644 index 000000000..d6d70e404 --- /dev/null +++ b/interfaces/kits/cj/osaccount/BUILD.gn @@ -0,0 +1,68 @@ +# 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("../../../../os_account.gni") + +config("osaccount_ffi_kit_config") { + include_dirs = [ "include" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + cflags += [ "-pipe" ] + cflags_cc = [ + "-Wdate-time", + "-Wformat=2", + "-Wfloat-equal", + "-Wshadow", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"OsAccountJsKit\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +ohos_shared_library("cj_osaccount_ffi") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + configs = [ ":osaccount_ffi_kit_config" ] + sources = [ + "${os_account_ffi_kits_path}/src/cj_osaccount_ffi.cpp", + "${os_account_ffi_kits_path}/src/osaccount_manager_impl.cpp", + ] + + deps = [ + "${common_path}:libaccount_common", + "${innerkits_native_path}:libaccountkits", + "${os_account_innerkits_native_path}:os_account_innerkits", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "napi:cj_bind_ffi", + "napi:cj_bind_native", + ] + + innerapi_tags = [ "platformsdk" ] + part_name = "os_account" + subsystem_name = "account" +} diff --git a/interfaces/kits/cj/osaccount/include/cj_osaccount_ffi.h b/interfaces/kits/cj/osaccount/include/cj_osaccount_ffi.h new file mode 100644 index 000000000..a1214de99 --- /dev/null +++ b/interfaces/kits/cj/osaccount/include/cj_osaccount_ffi.h @@ -0,0 +1,43 @@ +/* + * 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 CJ_OSACCOUNT_FFI_H +#define CJ_OSACCOUNT_FFI_H + +#include +#include "cj_ffi/cj_common_ffi.h" +#include "ffi_remote_data.h" +#include "common.h" + +EXTERN_C_START +FFI_EXPORT bool FfiOHOSOsAccountIsOsAccountConstraintEnabled(char *constraint, int32_t *errCode); +FFI_EXPORT int32_t FfiOHOSOsAccountGetOsAccountType(int32_t *errCode); +FFI_EXPORT bool FfiOHOSOsAccountCheckOsAccountTestable(int32_t *errCode); +FFI_EXPORT bool FfiOHOSOsAccountCheckMultiOsAccountEnabled(int32_t *errCode); +FFI_EXPORT int32_t FfiOHOSOsAccountGetOsAccountLocalId(int32_t *errCode); +FFI_EXPORT RetDataCArrI32 FfiOHOSOsAccountGetActivatedOsAccountLocalIds(); +FFI_EXPORT uint32_t FfiOHOSOsAccountGetOsAccountCount(int32_t *errCode); +FFI_EXPORT char* FfiOHOSOsAccountQueryDistributedVirtualDeviceId(int32_t *errCode); +FFI_EXPORT int64_t FfiOHOSOsAccountGetSerialNumberForOsAccountLocalId(uint32_t localId, int32_t *errCode); +FFI_EXPORT int32_t FfiOHOSOsAccountGetOsAccountLocalIdForSerialNumber(int64_t serialNumber, int32_t *errCode); +FFI_EXPORT int32_t FfiOHOSOsAccountGetOsAccountLocalIdForDomain(CDomainAccountInfo cDoaminInfo, int32_t *errCode); +FFI_EXPORT int32_t FfiOHOSOsAccountGetOsAccountLocalIdForUid(int32_t uid, int32_t *errCode); +FFI_EXPORT char* FfiOHOSOsAccountGetOsAccountName(int32_t *errCode); +FFI_EXPORT bool FfiOHOSOsAccountIsOsAccountUnlocked(int32_t *errCode); +FFI_EXPORT RetDataI64 FfiOHOSOsAccountGetAccountManager(); + +EXTERN_C_END + +#endif \ No newline at end of file diff --git a/interfaces/kits/cj/osaccount/include/common.h b/interfaces/kits/cj/osaccount/include/common.h new file mode 100644 index 000000000..0e559ba05 --- /dev/null +++ b/interfaces/kits/cj/osaccount/include/common.h @@ -0,0 +1,38 @@ +/* + * 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 CJ_OSACCOUNT_COMMON_H +#define CJ_OSACCOUNT_COMMON_H + +#include + +#ifdef __cplusplus +#define EXTERN_C_START extern "C" { +#define EXTERN_C_END } +#else +#define EXTERN_C_START +#define EXTERN_C_END +#endif + +EXTERN_C_START + +struct CDomainAccountInfo { + char* domain; + char* accountName; +}; + +EXTERN_C_END + +#endif \ No newline at end of file diff --git a/interfaces/kits/cj/osaccount/include/osaccount_manager_impl.h b/interfaces/kits/cj/osaccount/include/osaccount_manager_impl.h new file mode 100644 index 000000000..7c533b18f --- /dev/null +++ b/interfaces/kits/cj/osaccount/include/osaccount_manager_impl.h @@ -0,0 +1,43 @@ +/* + * 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 OSACCOUNT_MANAGER_IMPL_H +#define OSACCOUNT_MANAGER_IMPL_H + +#include +#include + +namespace OHOS::AccountJsKit { + class OsAccountManagerImpl { + public: + static bool IsOsAccountConstraintEnabled(char *constraint, int32_t *errCode); + static int32_t GetOsAccountType(int32_t *errCode); + static bool CheckMultiOsAccountEnabled(int32_t *errCode); + static int32_t GetOsAccountLocalId(int32_t *errCode); + static int32_t GetActivatedOsAccountLocalIds(std::vector &osAccountIds); + static uint32_t GetOsAccountCount(int32_t *errCode); + static char *QueryDistributedVirtualDeviceId(int32_t *errCode); + static int64_t GetSerialNumberForOsAccountLocalId(uint32_t localId, int32_t *errCode); + static int32_t GetOsAccountLocalIdForSerialNumber(int64_t serialNumber, int32_t *errCode); + static int32_t GetOsAccountLocalIdForDomain(char *domain, char *accountName, int32_t *errCode); + static int32_t GetOsAccountLocalIdForUid(int32_t uid, int32_t *errCode); + static char *GetOsAccountName(int32_t *errCode); + static bool IsOsAccountUnlocked(int32_t *errCode); + + static char *MallocCString(const std::string &origin); + + private: + }; +} +#endif // OSACCOUNT_MANAGER_IMPL_H \ No newline at end of file diff --git a/interfaces/kits/cj/osaccount/src/cj_osaccount_ffi.cpp b/interfaces/kits/cj/osaccount/src/cj_osaccount_ffi.cpp new file mode 100644 index 000000000..85be5dbe3 --- /dev/null +++ b/interfaces/kits/cj/osaccount/src/cj_osaccount_ffi.cpp @@ -0,0 +1,173 @@ +/* + * 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. + */ + +#include "cj_osaccount_ffi.h" +#include "account_error_no.h" +#include "account_permission_manager.h" +#include "account_log_wrapper.h" +#include "osaccount_manager_impl.h" + +using namespace OHOS::AccountSA; + +namespace OHOS::AccountJsKit { + EXTERN_C_START + bool FfiOHOSOsAccountIsOsAccountConstraintEnabled(char *constraint, int32_t *errCode) + { + if (constraint == nullptr) { + *errCode = ERR_JS_PARAMETER_ERROR; + ACCOUNT_LOGE("[osAccount] IsOsAccountConstraintEnabled constraint is null! errCode %{public}d", + *errCode); + return false; + } + if (AccountPermissionManager::CheckSystemApp(false) != ERR_OK) { + *errCode = ERR_JS_IS_NOT_SYSTEM_APP; + ACCOUNT_LOGE("[osAccount] IsOsAccountConstraintEnabled CheckSystemApp failed! errCode %{public}d", + *errCode); + return false; + } + ACCOUNT_LOGE("[osAccount] IsOsAccountConstraintEnabled start"); + bool ret = OsAccountManagerImpl::IsOsAccountConstraintEnabled(constraint, errCode); + ACCOUNT_LOGE("[osAccount] IsOsAccountConstraintEnabled success. errCode %{public}d", *errCode); + return ret; + } + + int32_t FfiOHOSOsAccountGetOsAccountType(int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountType start"); + int32_t ret = OsAccountManagerImpl::GetOsAccountType(errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountType success. errCode %{public}d", *errCode); + return ret; + } + + bool FfiOHOSOsAccountCheckOsAccountTestable(int32_t *errCode) + { + *errCode = ERR_JS_SUCCESS; + return false; + } + + bool FfiOHOSOsAccountCheckMultiOsAccountEnabled(int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] CheckMultiOsAccountEnabled start"); + bool ret = OsAccountManagerImpl::CheckMultiOsAccountEnabled(errCode); + ACCOUNT_LOGE("[osAccount] CheckMultiOsAccountEnabled success. errCode %{public}d", *errCode); + return ret; + } + + int32_t FfiOHOSOsAccountGetOsAccountLocalId(int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalId start"); + int32_t ret = OsAccountManagerImpl::GetOsAccountLocalId(errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalId success. errCode %{public}d", *errCode); + return ret; + } + + RetDataCArrI32 FfiOHOSOsAccountGetActivatedOsAccountLocalIds() + { + std::vector osAccountIds; + ACCOUNT_LOGE("[osAccount] GetActivatedOsAccountLocalIds start"); + int32_t code = OsAccountManagerImpl::GetActivatedOsAccountLocalIds(osAccountIds); + ACCOUNT_LOGE("[osAccount] GetActivatedOsAccountLocalIds success. errCode %{public}d", code); + CArrI32 data = {.head = nullptr, .size = 0}; + RetDataCArrI32 ret = {.code = code, .data = data}; + if (code != ERR_JS_SUCCESS) { + return ret; + } + size_t listSize = osAccountIds.size(); + ret.data.size = static_cast(listSize); + if (listSize > 0) { + int32_t *retValue = static_cast(malloc(sizeof(int32_t) * listSize)); + if (retValue == nullptr) { + ret.code = ERR_JS_SYSTEM_SERVICE_EXCEPTION; + return ret; + } + for (int32_t i = 0; i < listSize; i++) { + retValue[i] = osAccountIds[i]; + } + ret.data.head = retValue; + } + return ret; + } + + uint32_t FfiOHOSOsAccountGetOsAccountCount(int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountCount start"); + int32_t ret = OsAccountManagerImpl::GetOsAccountCount(errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountCount success. errCode %{public}d", *errCode); + return ret; + } + + char *FfiOHOSOsAccountQueryDistributedVirtualDeviceId(int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] QueryDistributedVirtualDeviceId start"); + char *ret = OsAccountManagerImpl::QueryDistributedVirtualDeviceId(errCode); + ACCOUNT_LOGE("[osAccount] QueryDistributedVirtualDeviceId success. errCode %{public}d", *errCode); + return ret; + } + + int64_t FfiOHOSOsAccountGetSerialNumberForOsAccountLocalId(uint32_t localId, int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetSerialNumberForOsAccountLocalId start"); + int32_t ret = OsAccountManagerImpl::GetSerialNumberForOsAccountLocalId(localId, errCode); + ACCOUNT_LOGE("[osAccount] GetSerialNumberForOsAccountLocalId success. errCode %{public}d", *errCode); + return ret; + } + + int32_t FfiOHOSOsAccountGetOsAccountLocalIdForSerialNumber(int64_t serialNumber, int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalIdForSerialNumber start"); + int32_t ret = OsAccountManagerImpl::GetOsAccountLocalIdForSerialNumber(serialNumber, errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalIdForSerialNumber success. errCode %{public}d", *errCode); + return ret; + } + + int32_t FfiOHOSOsAccountGetOsAccountLocalIdForDomain(CDomainAccountInfo cDoaminInfo, int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalIdForDomain start"); + int32_t ret = OsAccountManagerImpl::GetOsAccountLocalIdForDomain( + cDoaminInfo.domain, cDoaminInfo.accountName, errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalIdForDomain success. errCode %{public}d", *errCode); + return ret; + } + + int32_t FfiOHOSOsAccountGetOsAccountLocalIdForUid(int32_t uid, int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalIdForUid start"); + int32_t ret = OsAccountManagerImpl::GetOsAccountLocalIdForUid(uid, errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountLocalIdForUid success. errCode %{public}d", *errCode); + return ret; + } + + char *FfiOHOSOsAccountGetOsAccountName(int32_t *errCode) + { + ACCOUNT_LOGE("[osAccount] GetOsAccountName start"); + char *ret = OsAccountManagerImpl::GetOsAccountName(errCode); + ACCOUNT_LOGE("[osAccount] GetOsAccountName success. errCode %{public}d", *errCode); + return ret; + } + + bool FfiOHOSOsAccountIsOsAccountUnlocked(int32_t *errCode) + { + if (AccountPermissionManager::CheckSystemApp(false) != ERR_OK) { + *errCode = ERR_JS_IS_NOT_SYSTEM_APP; + ACCOUNT_LOGE("[osAccount] IsOsAccountUnlocked CheckSystemApp failed! errCode %{public}d", *errCode); + return false; + } + ACCOUNT_LOGE("[osAccount] IsOsAccountUnlocked start"); + bool ret = OsAccountManagerImpl::IsOsAccountUnlocked(errCode); + ACCOUNT_LOGE("[osAccount] IsOsAccountUnlocked success. errCode %{public}d", *errCode); + return ret; + } + EXTERN_C_END +} // namespace OHOS::AccountJsKit diff --git a/interfaces/kits/cj/osaccount/src/osaccount_manager_impl.cpp b/interfaces/kits/cj/osaccount/src/osaccount_manager_impl.cpp new file mode 100644 index 000000000..c10c980c7 --- /dev/null +++ b/interfaces/kits/cj/osaccount/src/osaccount_manager_impl.cpp @@ -0,0 +1,142 @@ +/* + * 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. + */ + +#include "osaccount_manager_impl.h" +#include "os_account_manager.h" +#include "account_error_no.h" +#include "os_account_info.h" +#include "account_log_wrapper.h" + +namespace OHOS::AccountJsKit { + using namespace OHOS::AccountSA; + + bool OsAccountManagerImpl::IsOsAccountConstraintEnabled(char *constraint, int32_t *errCode) + { + int32_t id = 0; + bool isConsEnable = false; + std::vector ids; + *errCode = OsAccountManager::QueryActiveOsAccountIds(ids); + if (*errCode != ERR_OK) { + ACCOUNT_LOGE("isOsAccountConstraintEnabled Get id failed"); + return false; + } + if (ids.empty()) { + *errCode = ERR_ACCOUNT_COMMON_INVALID_PARAMETER; + ACCOUNT_LOGE("isOsAccountConstraintEnabled No Active OsAccount Ids"); + return false; + } + id = ids[0]; + *errCode = OsAccountManager::CheckOsAccountConstraintEnabled(id, constraint, isConsEnable); + return isConsEnable; + } + + int32_t OsAccountManagerImpl::GetOsAccountType(int32_t *errCode) + { + OsAccountType type; + *errCode = OsAccountManager::GetOsAccountTypeFromProcess(type); + return type; + } + + bool OsAccountManagerImpl::CheckMultiOsAccountEnabled(int32_t *errCode) + { + bool isMultiOAEnable = false; + *errCode = OsAccountManager::IsMultiOsAccountEnable(isMultiOAEnable); + return isMultiOAEnable; + } + + int32_t OsAccountManagerImpl::GetOsAccountLocalId(int32_t *errCode) + { + int32_t id = 0; + *errCode = OsAccountManager::GetOsAccountLocalIdFromProcess(id); + return id; + } + + int32_t OsAccountManagerImpl::GetActivatedOsAccountLocalIds(std::vector &osAccountIds) + { + return OsAccountManager::QueryActiveOsAccountIds(osAccountIds); + } + + uint32_t OsAccountManagerImpl::GetOsAccountCount(int32_t *errCode) + { + uint32_t osAccountCount = 0; + *errCode = OsAccountManager::GetCreatedOsAccountsCount(osAccountCount); + return osAccountCount; + } + + char *OsAccountManagerImpl::QueryDistributedVirtualDeviceId(int32_t *errCode) + { + std::string deviceId; + *errCode = OsAccountManager::GetDistributedVirtualDeviceId(deviceId); + return MallocCString(deviceId); + } + + int64_t OsAccountManagerImpl::GetSerialNumberForOsAccountLocalId(uint32_t localId, int32_t *errCode) + { + int64_t serialNum; + *errCode = OsAccountManager::GetSerialNumberByOsAccountLocalId(localId, serialNum); + return serialNum; + } + + int32_t OsAccountManagerImpl::GetOsAccountLocalIdForSerialNumber(int64_t serialNumber, int32_t *errCode) + { + int32_t id = 0; + *errCode = OsAccountManager::GetOsAccountLocalIdBySerialNumber(serialNumber, id); + return id; + } + + int32_t OsAccountManagerImpl::GetOsAccountLocalIdForDomain(char *domain, char *accountName, int32_t *errCode) + { + int32_t id = 0; + DomainAccountInfo domainInfo; + domainInfo.accountId_ = domain; + domainInfo.accountName_ = accountName; + *errCode = OsAccountManager::GetOsAccountLocalIdFromDomain(domainInfo, id); + return id; + } + + int32_t OsAccountManagerImpl::GetOsAccountLocalIdForUid(int32_t uid, int32_t *errCode) + { + int32_t id = 0; + *errCode = OsAccountManager::GetOsAccountLocalIdFromUid(uid, id); + return id; + } + + char *OsAccountManagerImpl::GetOsAccountName(int32_t *errCode) + { + std::string name; + *errCode = OsAccountManager::GetOsAccountName(name); + return MallocCString(name); + } + + bool OsAccountManagerImpl::IsOsAccountUnlocked(int32_t *errCode) + { + bool isVerified = false; + *errCode = OsAccountManager::IsCurrentOsAccountVerified(isVerified); + return isVerified; + } + + char *OsAccountManagerImpl::MallocCString(const std::string &origin) + { + if (origin.empty()) { + return nullptr; + } + auto len = origin.length() + 1; + char *res = static_cast(malloc(sizeof(char) * len)); + if (res == nullptr) { + return nullptr; + } + return std::char_traits::copy(res, origin.c_str(), len); + } +} \ No newline at end of file diff --git a/os_account.gni b/os_account.gni index cb6fa7a2e..7d3b7ea28 100644 --- a/os_account.gni +++ b/os_account.gni @@ -38,6 +38,7 @@ os_account_innerkits_native_path = "${os_account_path}/frameworks/osaccount/native" os_account_core_path = "${os_account_path}/frameworks/osaccount/core" os_account_kits_path = "${os_account_path}/interfaces/kits/napi/osaccount" +os_account_ffi_kits_path = "${os_account_path}/interfaces/kits/cj/osaccount" os_account_dfx_path = "${os_account_path}/dfx" account_iam_kits_path = "${os_account_path}/interfaces/kits/napi/account_iam"