From 3adfd3deadc4ec4d0639b77a79009f6733cfe327 Mon Sep 17 00:00:00 2001 From: fundavid Date: Tue, 18 Mar 2025 18:46:49 +0800 Subject: [PATCH] el5 idlize Signed-off-by: fundavid --- bundle.json | 8 +- .../include/el5_filekey_manager_interface.h | 50 --- .../include/el5_filekey_manager_proxy.h | 49 --- .../el5_filekey_service_ext_interface.h | 9 +- .../src/el5_filekey_manager_napi.cpp | 18 +- .../inner_api/el5filekeymanager/BUILD.gn | 52 ++- .../El5FilekeyCallbackInterface.idl | 20 + .../El5FilekeyManagerInterface.idl | 34 ++ .../data_lock_type.h => data_lock_type.idl} | 15 +- ...llback_interface.h => app_key_load_info.h} | 24 +- .../include/data_lock_type_ext.h | 21 + .../include/el5_filekey_callback_stub.h | 18 +- .../include/user_app_key_info.h | 29 +- .../src/app_key_load_info.cpp | 44 +- .../src/el5_filekey_callback_stub.cpp | 62 --- .../src/el5_filekey_manager_client.cpp | 22 +- .../src/el5_filekey_manager_proxy.cpp | 402 ------------------ .../src/user_app_key_info.cpp | 42 ++ .../inner_api/el5filekeymanager/test/BUILD.gn | 3 +- .../src/el5_filekey_manager_kit_unittest.cpp | 21 +- .../src/screen_lock_file_manager_ffi.cpp | 6 +- services/el5filekeymanager/BUILD.gn | 10 +- .../include/el5_filekey_manager_service.h | 11 +- .../include/el5_filekey_manager_stub.h | 57 --- .../src/el5_filekey_callback_proxy.cpp | 65 --- .../src/el5_filekey_manager_service.cpp | 8 +- .../src/el5_filekey_manager_stub.cpp | 196 --------- services/el5filekeymanager/test/BUILD.gn | 8 +- .../el5_filekey_manager_stub_unittest.h | 6 +- ..._filekey_manager_service_mock_unittest.cpp | 47 +- .../el5_filekey_manager_service_unittest.cpp | 36 +- .../src/el5_filekey_manager_stub_unittest.cpp | 72 ++-- 32 files changed, 382 insertions(+), 1083 deletions(-) delete mode 100644 frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface.h delete mode 100644 frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_proxy.h create mode 100644 interfaces/inner_api/el5filekeymanager/El5FilekeyCallbackInterface.idl create mode 100644 interfaces/inner_api/el5filekeymanager/El5FilekeyManagerInterface.idl rename interfaces/inner_api/el5filekeymanager/{include/data_lock_type.h => data_lock_type.idl} (67%) rename interfaces/inner_api/el5filekeymanager/include/{el5_filekey_callback_interface.h => app_key_load_info.h} (57%) create mode 100644 interfaces/inner_api/el5filekeymanager/include/data_lock_type_ext.h rename services/el5filekeymanager/include/el5_filekey_callback_proxy.h => interfaces/inner_api/el5filekeymanager/include/user_app_key_info.h (53%) rename frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface_code.h => interfaces/inner_api/el5filekeymanager/src/app_key_load_info.cpp (47%) delete mode 100644 interfaces/inner_api/el5filekeymanager/src/el5_filekey_callback_stub.cpp delete mode 100644 interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_proxy.cpp create mode 100644 interfaces/inner_api/el5filekeymanager/src/user_app_key_info.cpp delete mode 100644 services/el5filekeymanager/include/el5_filekey_manager_stub.h delete mode 100644 services/el5filekeymanager/src/el5_filekey_callback_proxy.cpp delete mode 100644 services/el5filekeymanager/src/el5_filekey_manager_stub.cpp diff --git a/bundle.json b/bundle.json index b4f8cb096..9a569db58 100644 --- a/bundle.json +++ b/bundle.json @@ -210,13 +210,13 @@ "name": "//base/security/access_token/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_sdk", "header": { "header_files": [ - "el5_filekey_manager_kit.h", "app_key_info.h", - "data_lock_type.h", - "el5_filekey_callback_interface.h", + "app_key_load_info.h", + "data_lock_type_ext.h", "el5_filekey_callback_stub.h", "el5_filekey_manager_error.h", - "el5_filekey_manager_kit.h" + "el5_filekey_manager_kit.h", + "user_app_key_info.h" ], "header_base": "//base/security/access_token/interfaces/inner_api/el5filekeymanager/include" } diff --git a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface.h b/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface.h deleted file mode 100644 index dd3e1086f..000000000 --- a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 EL5_FILEKEY_MANAGER_INTERFACE_H -#define EL5_FILEKEY_MANAGER_INTERFACE_H - -#include - -#include "data_lock_type.h" -#include "el5_filekey_callback_interface.h" -#include "el5_filekey_manager_error.h" -#include "el5_filekey_manager_interface_code.h" -#include "iremote_broker.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -class El5FilekeyManagerInterface : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.accesstoken.El5FilekeyManagerInterface"); - - virtual int32_t AcquireAccess(DataLockType type) = 0; - virtual int32_t ReleaseAccess(DataLockType type) = 0; - virtual int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId) = 0; - virtual int32_t DeleteAppKey(const std::string& bundleName, int32_t userId) = 0; - virtual int32_t GetUserAppKey(int32_t userId, bool getAllFlag, - std::vector> &keyInfos) = 0; - virtual int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector> &loadInfos) = 0; - virtual int32_t SetFilePathPolicy() = 0; - virtual int32_t RegisterCallback(const sptr &callback) = 0; - virtual int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId) = 0; - virtual int32_t DeleteGroupIDKey(uint32_t uid, const std::string &groupID) = 0; - virtual int32_t QueryAppKeyState(DataLockType type) = 0; -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS -#endif // EL5_FILEKEY_MANAGER_INTERFACE_H diff --git a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_proxy.h b/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_proxy.h deleted file mode 100644 index f572cc282..000000000 --- a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_proxy.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 EL5_FILEKEY_MANAGER_PROXY_H -#define EL5_FILEKEY_MANAGER_PROXY_H - -#include "el5_filekey_manager_interface.h" -#include "el5_filekey_manager_interface_code.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -class El5FilekeyManagerProxy : public IRemoteProxy { -public: - explicit El5FilekeyManagerProxy(const sptr &impl); - virtual ~El5FilekeyManagerProxy(); - - int32_t AcquireAccess(DataLockType type) override; - int32_t ReleaseAccess(DataLockType type) override; - int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId) override; - int32_t DeleteAppKey(const std::string& bundleName, int32_t userId) override; - int32_t GetUserAppKey(int32_t userId, bool getAllFlag, - std::vector> &keyInfos) override; - int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector> &loadInfos) override; - int32_t SetFilePathPolicy() override; - int32_t RegisterCallback(const sptr &callback) override; - int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId) override; - int32_t DeleteGroupIDKey(uint32_t uid, const std::string &groupID) override; - int32_t QueryAppKeyState(DataLockType type) override; -private: - static inline BrokerDelegator delegator_; -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS -#endif // EL5_FILEKEY_MANAGER_PROXY_H diff --git a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_service_ext_interface.h b/frameworks/inner_api/el5filekeymanager/include/el5_filekey_service_ext_interface.h index 13f2448ff..211eaddc2 100644 --- a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_service_ext_interface.h +++ b/frameworks/inner_api/el5filekeymanager/include/el5_filekey_service_ext_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -18,7 +18,9 @@ #include +#include "app_key_load_info.h" #include "data_lock_type.h" +#include "user_app_key_info.h" namespace OHOS { namespace Security { @@ -29,9 +31,8 @@ public: virtual int32_t ReleaseAccess(DataLockType type, bool isApp) = 0; virtual int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId) = 0; virtual int32_t DeleteAppKey(const std::string& bundleName, int32_t userId) = 0; - virtual int32_t GetUserAppKey(int32_t userId, bool getAllFlag, - std::vector> &keyInfos) = 0; - virtual int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector> &loadInfos) = 0; + virtual int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector &keyInfos) = 0; + virtual int32_t ChangeUserAppkeysLoadInfo(int32_t userId, const std::vector &loadInfos) = 0; virtual int32_t SetFilePathPolicy(int32_t userId) = 0; virtual int32_t HandleUserCommonEvent(const std::string &eventName, int32_t userId) = 0; virtual int32_t SetPolicyScreenLocked() = 0; diff --git a/frameworks/js/napi/el5filekeymanager/src/el5_filekey_manager_napi.cpp b/frameworks/js/napi/el5filekeymanager/src/el5_filekey_manager_napi.cpp index 9b1053a56..2244a7718 100644 --- a/frameworks/js/napi/el5filekeymanager/src/el5_filekey_manager_napi.cpp +++ b/frameworks/js/napi/el5filekeymanager/src/el5_filekey_manager_napi.cpp @@ -79,10 +79,10 @@ bool ParseDataType(const napi_env &env, napi_value args, int32_t &dataLockType) bool CheckDataType(napi_env env, int32_t dataLockType) { - if ((static_cast(dataLockType) != DEFAULT_DATA) && - (static_cast(dataLockType) != MEDIA_DATA) && - (static_cast(dataLockType) != GROUP_ID_DATA) && - (static_cast(dataLockType) != ALL_DATA)) { + if ((static_cast(dataLockType) != DataLockType::DEFAULT_DATA) && + (static_cast(dataLockType) != DataLockType::MEDIA_DATA) && + (static_cast(dataLockType) != DataLockType::GROUP_ID_DATA) && + (static_cast(dataLockType) != DataLockType::ALL_DATA)) { ThrowError(env, EFM_ERR_INVALID_DATATYPE); return false; } @@ -99,7 +99,7 @@ napi_value AcquireAccess(napi_env env, napi_callback_info info) return nullptr; } - int32_t dataLockType = DEFAULT_DATA; + int32_t dataLockType = static_cast(DataLockType::DEFAULT_DATA); if ((argc == MAX_PARAM_SIZE) && !ParseDataType(env, argv[0], dataLockType)) { return nullptr; } @@ -130,7 +130,7 @@ napi_value ReleaseAccess(napi_env env, napi_callback_info info) return nullptr; } - int32_t dataLockType = DEFAULT_DATA; + int32_t dataLockType = static_cast(DataLockType::DEFAULT_DATA); if ((argc == MAX_PARAM_SIZE) && !ParseDataType(env, argv[0], dataLockType)) { return nullptr; } @@ -161,7 +161,7 @@ napi_value QueryAppKeyState(napi_env env, napi_callback_info info) return nullptr; } - int32_t dataLockType = DEFAULT_DATA; + int32_t dataLockType = static_cast(DataLockType::DEFAULT_DATA); if ((argc == MAX_PARAM_SIZE) && !ParseDataType(env, argv[0], dataLockType)) { return nullptr; } @@ -216,8 +216,8 @@ static napi_value Init(napi_env env, napi_value exports) napi_value dataType = nullptr; napi_create_object(env, &dataType); - SetNamedProperty(env, dataType, MEDIA_DATA, "MEDIA_DATA"); - SetNamedProperty(env, dataType, ALL_DATA, "ALL_DATA"); + SetNamedProperty(env, dataType, static_cast(DataLockType::MEDIA_DATA), "MEDIA_DATA"); + SetNamedProperty(env, dataType, static_cast(DataLockType::ALL_DATA), "ALL_DATA"); napi_value accessStatus = nullptr; napi_create_object(env, &accessStatus); diff --git a/interfaces/inner_api/el5filekeymanager/BUILD.gn b/interfaces/inner_api/el5filekeymanager/BUILD.gn index d4c36ca0d..5e4034620 100644 --- a/interfaces/inner_api/el5filekeymanager/BUILD.gn +++ b/interfaces/inner_api/el5filekeymanager/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 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 @@ -11,17 +11,61 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("../../../access_token.gni") +idl_gen_interface("el5_filekey_manager_interface") { + sources = [ "El5FilekeyManagerInterface.idl" ] + sources_callback = [ "El5FilekeyCallbackInterface.idl" ] + sources_common = [ "data_lock_type.idl" ] + subsystem_name = "security" + part_name = "access_token" +} + config("efm_innerkits") { visibility = [ ":*" ] include_dirs = [ "include", "${access_token_path}/frameworks/inner_api/el5filekeymanager/include/", + "${target_gen_dir}", ] } +ohos_source_set("el5_filekey_manager_proxy") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":el5_filekey_manager_interface") + sources = [] + sources += filter_include(output_values, [ "*callback_interface_stub.cpp" ]) + sources += filter_include(output_values, [ "*manager_interface_proxy.cpp" ]) + public_configs = [ ":efm_innerkits" ] + deps = [ ":el5_filekey_manager_interface" ] + external_deps = [ "ipc:ipc_core" ] + subsystem_name = "security" + part_name = "access_token" +} + +ohos_source_set("el5_filekey_manager_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":el5_filekey_manager_interface") + sources = [] + sources += filter_include(output_values, [ "*callback_interface_proxy.cpp" ]) + sources += filter_include(output_values, [ "*manager_interface_stub.cpp" ]) + public_configs = [ ":efm_innerkits" ] + deps = [ ":el5_filekey_manager_interface" ] + external_deps = [ "ipc:ipc_core" ] + subsystem_name = "security" + part_name = "access_token" +} + ohos_shared_library("el5_filekey_manager_sdk") { sanitize = { cfi = true @@ -47,12 +91,14 @@ ohos_shared_library("el5_filekey_manager_sdk") { sources = [ "src/app_key_info.cpp", - "src/el5_filekey_callback_stub.cpp", + "src/app_key_load_info.cpp", "src/el5_filekey_manager_client.cpp", "src/el5_filekey_manager_kit.cpp", - "src/el5_filekey_manager_proxy.cpp", + "src/user_app_key_info.cpp", ] + deps = [ ":el5_filekey_manager_proxy" ] + external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/interfaces/inner_api/el5filekeymanager/El5FilekeyCallbackInterface.idl b/interfaces/inner_api/el5filekeymanager/El5FilekeyCallbackInterface.idl new file mode 100644 index 000000000..a1063b22b --- /dev/null +++ b/interfaces/inner_api/el5filekeymanager/El5FilekeyCallbackInterface.idl @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +sequenceable OHOS.Security.AccessToken.AppKeyInfo; + +[callback] interface OHOS.Security.AccessToken.El5FilekeyCallbackInterface{ + void OnRegenerateAppKey([inout] List infos); +} \ No newline at end of file diff --git a/interfaces/inner_api/el5filekeymanager/El5FilekeyManagerInterface.idl b/interfaces/inner_api/el5filekeymanager/El5FilekeyManagerInterface.idl new file mode 100644 index 000000000..27070333b --- /dev/null +++ b/interfaces/inner_api/el5filekeymanager/El5FilekeyManagerInterface.idl @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.Security.AccessToken; +import data_lock_type; +import El5FilekeyCallbackInterface; +sequenceable OHOS.Security.AccessToken.UserAppKeyInfo; +sequenceable OHOS.Security.AccessToken.AppKeyLoadInfo; + +interface OHOS.Security.AccessToken.El5FilekeyManagerInterface{ + void AcquireAccess([in] DataLockType type); + void ReleaseAccess([in] DataLockType type); + void GenerateAppKey([in] unsigned int uid, [in] String bundleName, [inout] String keyId); + void DeleteAppKey([in] String bundleName, [in] int userId); + void GetUserAppKey([in] int userId, [in] boolean getAllFlag, [inout] List keyInfos); + void ChangeUserAppkeysLoadInfo([in] int userId, [in] List loadInfos); + void SetFilePathPolicy(); + void RegisterCallback([in] El5FilekeyCallbackInterface cb); + void GenerateGroupIDKey([in] unsigned int uid, [in] String groupID, [inout] String keyId); + void DeleteGroupIDKey([in] unsigned int uid, [in] String groupID); + void QueryAppKeyState([in] DataLockType type); +} \ No newline at end of file diff --git a/interfaces/inner_api/el5filekeymanager/include/data_lock_type.h b/interfaces/inner_api/el5filekeymanager/data_lock_type.idl similarity index 67% rename from interfaces/inner_api/el5filekeymanager/include/data_lock_type.h rename to interfaces/inner_api/el5filekeymanager/data_lock_type.idl index b5f1f4c74..6daba4235 100644 --- a/interfaces/inner_api/el5filekeymanager/include/data_lock_type.h +++ b/interfaces/inner_api/el5filekeymanager/data_lock_type.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,19 +13,10 @@ * limitations under the License. */ -#ifndef EL5_FILEKEY_MANAGER_DATA_LOCK_TYPE_H -#define EL5_FILEKEY_MANAGER_DATA_LOCK_TYPE_H - -namespace OHOS { -namespace Security { -namespace AccessToken { +package OHOS.Security.AccessToken; enum DataLockType { DEFAULT_DATA = 0x0, MEDIA_DATA = 0x01, GROUP_ID_DATA = 0x02, ALL_DATA = 0xFFFFFFFF -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS -#endif // EL5_FILEKEY_MANAGER_DATA_LOCK_TYPE_H +}; \ No newline at end of file diff --git a/interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_interface.h b/interfaces/inner_api/el5filekeymanager/include/app_key_load_info.h similarity index 57% rename from interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_interface.h rename to interfaces/inner_api/el5filekeymanager/include/app_key_load_info.h index 80110d730..7e7d3856c 100644 --- a/interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_interface.h +++ b/interfaces/inner_api/el5filekeymanager/include/app_key_load_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,28 +13,28 @@ * limitations under the License. */ -#ifndef EL5_FILEKEY_CALLBACK_INTERFACE_H -#define EL5_FILEKEY_CALLBACK_INTERFACE_H +#ifndef EL5FILEKEYMANAGER_INCLUDE_APP_KEY_LOAD_INFO_H +#define EL5FILEKEYMANAGER_INCLUDE_APP_KEY_LOAD_INFO_H #include -#include "app_key_info.h" +#include "message_parcel.h" #include "iremote_broker.h" namespace OHOS { namespace Security { namespace AccessToken { -class El5FilekeyCallbackInterface : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.accesstoken.El5FilekeyCallback"); +struct AppKeyLoadInfo : public Parcelable { + std::string first; + bool second = false; - virtual void OnRegenerateAppKey(std::vector &infos) = 0; + AppKeyLoadInfo() {} + AppKeyLoadInfo(std::string &first, bool second) : first(first), second(second) {} - enum Code { - ON_REGENERATE_APP_KEY = 0, - }; + bool Marshalling(Parcel &parcel) const override; + static AppKeyLoadInfo *Unmarshalling(Parcel &parcel); }; } // namespace AccessToken } // namespace Security } // namespace OHOS -#endif // EL5_FILEKEY_CALLBACK_INTERFACE_H +#endif // EL5FILEKEYMANAGER_INCLUDE_APP_KEY_LOAD_INFO_H diff --git a/interfaces/inner_api/el5filekeymanager/include/data_lock_type_ext.h b/interfaces/inner_api/el5filekeymanager/include/data_lock_type_ext.h new file mode 100644 index 000000000..edfa56442 --- /dev/null +++ b/interfaces/inner_api/el5filekeymanager/include/data_lock_type_ext.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 EL5FILEKEYMANAGER_INCLUDE_DATA_LOCK_TYPE_EXT_H +#define EL5FILEKEYMANAGER_INCLUDE_DATA_LOCK_TYPE_EXT_H + +#include "data_lock_type.h" + +#endif // EL5FILEKEYMANAGER_INCLUDE_DATA_LOCK_TYPE_EXT_H diff --git a/interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_stub.h b/interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_stub.h index 94b03ddb5..c5a083f0f 100644 --- a/interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_stub.h +++ b/interfaces/inner_api/el5filekeymanager/include/el5_filekey_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -16,20 +16,6 @@ #ifndef EL5_FILEKEY_CALLBACK_STUB_H #define EL5_FILEKEY_CALLBACK_STUB_H -#include "el5_filekey_callback_interface.h" -#include "iremote_stub.h" +#include "el5_filekey_callback_interface_stub.h" -namespace OHOS { -namespace Security { -namespace AccessToken { -class El5FilekeyCallbackStub : public IRemoteStub { -public: - El5FilekeyCallbackStub(); - virtual ~El5FilekeyCallbackStub(); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS #endif // EL5_FILEKEY_CALLBACK_STUB_H diff --git a/services/el5filekeymanager/include/el5_filekey_callback_proxy.h b/interfaces/inner_api/el5filekeymanager/include/user_app_key_info.h similarity index 53% rename from services/el5filekeymanager/include/el5_filekey_callback_proxy.h rename to interfaces/inner_api/el5filekeymanager/include/user_app_key_info.h index 6617f0e5e..3dbbd5cfc 100644 --- a/services/el5filekeymanager/include/el5_filekey_callback_proxy.h +++ b/interfaces/inner_api/el5filekeymanager/include/user_app_key_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,25 +13,28 @@ * limitations under the License. */ -#ifndef EL5_FILEKEY_CALLBACK_PROXY_H -#define EL5_FILEKEY_CALLBACK_PROXY_H +#ifndef EL5FILEKEYMANAGER_INCLUDE_USER_APP_KEY_INFO_H +#define EL5FILEKEYMANAGER_INCLUDE_USER_APP_KEY_INFO_H -#include "el5_filekey_callback_interface.h" -#include "iremote_proxy.h" +#include + +#include "message_parcel.h" +#include "iremote_broker.h" namespace OHOS { namespace Security { namespace AccessToken { -class El5FilekeyCallbackProxy : public IRemoteProxy { -public: - explicit El5FilekeyCallbackProxy(const sptr& impl); - virtual ~El5FilekeyCallbackProxy(); +struct UserAppKeyInfo : public Parcelable { + int32_t first = -1; + std::string second; + + UserAppKeyInfo() {} + UserAppKeyInfo(int32_t first, std::string &second) : first(first), second(second) {} - void OnRegenerateAppKey(std::vector &infos) override; -private: - static inline BrokerDelegator delegator_; + bool Marshalling(Parcel &parcel) const override; + static UserAppKeyInfo *Unmarshalling(Parcel &parcel); }; } // namespace AccessToken } // namespace Security } // namespace OHOS -#endif // EL5_FILEKEY_CALLBACK_PROXY_H +#endif // EL5FILEKEYMANAGER_INCLUDE_USER_APP_KEY_INFO_H diff --git a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface_code.h b/interfaces/inner_api/el5filekeymanager/src/app_key_load_info.cpp similarity index 47% rename from frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface_code.h rename to interfaces/inner_api/el5filekeymanager/src/app_key_load_info.cpp index 688659dec..a88269e00 100644 --- a/frameworks/inner_api/el5filekeymanager/include/el5_filekey_manager_interface_code.h +++ b/interfaces/inner_api/el5filekeymanager/src/app_key_load_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,28 +13,30 @@ * limitations under the License. */ -#ifndef EL5_FILEKEY_MANAGER_INTERFACE_CODE_H -#define EL5_FILEKEY_MANAGER_INTERFACE_CODE_H +#include "app_key_load_info.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -/* SAID:3503 */ -enum class EFMInterfaceCode { - GENERATE_APP_KEY = 0x0000, - DELETE_APP_KEY, - ACQUIRE_ACCESS, - RELEASE_ACCESS, - GET_USER_APP_KEY, - CHANGE_USER_APP_KEYS_LOAD_INFO, - SET_FILE_PATH_POLICY, - REGISTER_CALLBACK, - GENERATE_GROUPID_KEY, - DELETE_GROUPID_KEY, - QUERY_APP_KEY_STATE, -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS +bool AppKeyLoadInfo::Marshalling(Parcel &parcel) const +{ + RETURN_IF_FALSE(parcel.WriteString(this->first)); + RETURN_IF_FALSE(parcel.WriteBool(this->second)); + return true; +} -#endif // EL5_FILEKEY_MANAGER_INTERFACE_CODE_H +AppKeyLoadInfo *AppKeyLoadInfo::Unmarshalling(Parcel &parcel) +{ + AppKeyLoadInfo *info = new (std::nothrow) AppKeyLoadInfo(); + if (info == nullptr) { + return nullptr; + } + + RELEASE_IF_FALSE(parcel.ReadString(info->first), info); + RELEASE_IF_FALSE(parcel.ReadBool(info->second), info); + return info; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_callback_stub.cpp b/interfaces/inner_api/el5filekeymanager/src/el5_filekey_callback_stub.cpp deleted file mode 100644 index 7ead6d8b4..000000000 --- a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_callback_stub.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 "el5_filekey_callback_stub.h" -#include "el5_filekey_manager_error.h" -#include "el5_filekey_manager_log.h" -#include "parcel_utils.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -El5FilekeyCallbackStub::El5FilekeyCallbackStub() -{ -} - -El5FilekeyCallbackStub::~El5FilekeyCallbackStub() -{ -} - -int32_t El5FilekeyCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) -{ - if (data.ReadInterfaceToken() != El5FilekeyCallbackInterface::GetDescriptor()) { - LOG_ERROR("Get unexpected descriptor"); - return EFM_ERR_IPC_TOKEN_INVALID; - } - if (code == static_cast(El5FilekeyCallbackInterface::Code::ON_REGENERATE_APP_KEY)) { - std::vector infos; - uint32_t infosSize = data.ReadUint32(); - if (infosSize > MAX_RECORD_SIZE) { - LOG_ERROR("Parse infos failed, results oversize %{public}d.", infosSize); - return EFM_ERR_IPC_READ_DATA; - } - for (uint32_t i = 0; i < infosSize; ++i) { - sptr info = data.ReadParcelable(); - if (info == nullptr) { - LOG_ERROR("Parse AppKetInfo failed."); - return EFM_ERR_IPC_READ_DATA; - } - infos.emplace_back(*info); - } - OnRegenerateAppKey(infos); - return NO_ERROR; - } else { - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp b/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp index 0faf46438..5840da228 100644 --- a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp +++ b/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -16,7 +16,10 @@ #include "el5_filekey_manager_client.h" #include "el5_filekey_manager_log.h" -#include "el5_filekey_manager_proxy.h" +#include "el5_filekey_manager_interface_proxy.h" +#include "el5_filekey_manager_error.h" +#include "app_key_load_info.h" +#include "user_app_key_info.h" #include "iservice_registry.h" #include "refbase.h" #include "system_ability_definition.h" @@ -77,17 +80,26 @@ int32_t El5FilekeyManagerClient::DeleteAppKey(const std::string &bundleName, int int32_t El5FilekeyManagerClient::GetUserAppKey(int32_t userId, bool getAllFlag, std::vector> &keyInfos) { + std::vector userAppKeyInfos; std::function &)> func = [&](sptr &proxy) { - return proxy->GetUserAppKey(userId, getAllFlag, keyInfos); + return proxy->GetUserAppKey(userId, getAllFlag, userAppKeyInfos); }; - return CallProxyWithRetry(func, __FUNCTION__, SA_REQUEST_RETRY_TIMES); + int32_t ret = CallProxyWithRetry(func, __FUNCTION__, SA_REQUEST_RETRY_TIMES); + for (auto const &it : userAppKeyInfos) { + keyInfos.emplace_back(std::make_pair(it.first, it.second)); + } + return ret; } int32_t El5FilekeyManagerClient::ChangeUserAppkeysLoadInfo(int32_t userId, std::vector> &loadInfos) { + std::vector appKeyLoadInfos; + for (auto &it : loadInfos) { + appKeyLoadInfos.emplace_back(AppKeyLoadInfo(it.first, it.second)); + } std::function &)> func = [&](sptr &proxy) { - return proxy->ChangeUserAppkeysLoadInfo(userId, loadInfos); + return proxy->ChangeUserAppkeysLoadInfo(userId, appKeyLoadInfos); }; return CallProxyWithRetry(func, __FUNCTION__); } diff --git a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_proxy.cpp b/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_proxy.cpp deleted file mode 100644 index 08fc150a0..000000000 --- a/interfaces/inner_api/el5filekeymanager/src/el5_filekey_manager_proxy.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/* - * 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 "el5_filekey_manager_proxy.h" - -#include "el5_filekey_manager_error.h" -#include "el5_filekey_manager_log.h" -#include "parcel_utils.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -El5FilekeyManagerProxy::El5FilekeyManagerProxy(const sptr& impl) - : IRemoteProxy(impl) -{ -} - -El5FilekeyManagerProxy::~El5FilekeyManagerProxy() -{ -} - -int32_t El5FilekeyManagerProxy::AcquireAccess(DataLockType type) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteInt32(static_cast(type))) { - LOG_ERROR("Failed to WriteInt32(%{public}d).", type); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest(static_cast(EFMInterfaceCode::ACQUIRE_ACCESS), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::ReleaseAccess(DataLockType type) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteInt32(static_cast(type))) { - LOG_ERROR("Failed to WriteInt32(%{public}d).", type); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest(static_cast(EFMInterfaceCode::RELEASE_ACCESS), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(uid)) { - LOG_ERROR("Failed to WriteUint32(%{public}d).", uid); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteString(bundleName)) { - LOG_ERROR("Failed to WriteString(%{public}s).", bundleName.c_str()); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::GENERATE_APP_KEY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - keyId = reply.ReadString(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::DeleteAppKey(const std::string& bundleName, int32_t userId) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteString(bundleName)) { - LOG_ERROR("Failed to WriteString(%{public}s).", bundleName.c_str()); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(userId)) { - LOG_ERROR("Failed to WriteUint32(%{public}d).", userId); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest(static_cast(EFMInterfaceCode::DELETE_APP_KEY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::GetUserAppKey(int32_t userId, bool getAllFlag, - std::vector> &keyInfos) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(userId)) { - LOG_ERROR("Failed to WriteUint32(%{public}d).", userId); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteBool(getAllFlag)) { - LOG_ERROR("Failed to WriteBool"); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::GET_USER_APP_KEY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - return result; - } - - result = reply.ReadInt32(); - if (result == EFM_SUCCESS) { - uint32_t keyInfoSize = reply.ReadUint32(); - if (keyInfoSize > MAX_RECORD_SIZE) { - LOG_ERROR("Parse keyInfos failed, results oversize %{public}d.", keyInfoSize); - return EFM_ERR_IPC_READ_DATA; - } - for (uint32_t i = 0; i < keyInfoSize; ++i) { - int32_t uid = reply.ReadInt32(); - std::string keyId = reply.ReadString(); - keyInfos.emplace_back(std::make_pair(uid, keyId)); - } - } - return result; -} - -int32_t El5FilekeyManagerProxy::ChangeUserAppkeysLoadInfo(int32_t userId, - std::vector> &loadInfos) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(userId)) { - LOG_ERROR("Failed to WriteUint32(%{public}d).", userId); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(loadInfos.size())) { - LOG_ERROR("Failed to WriteUint32(%{public}d).", static_cast(loadInfos.size())); - return EFM_ERR_IPC_WRITE_DATA; - } - for (std::pair &loadInfo : loadInfos) { - if (!data.WriteString(loadInfo.first)) { - LOG_ERROR("Failed to write keyId."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteBool(loadInfo.second)) { - LOG_ERROR("Failed to write load status."); - return EFM_ERR_IPC_WRITE_DATA; - } - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::CHANGE_USER_APP_KEYS_LOAD_INFO), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::SetFilePathPolicy() -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::SET_FILE_PATH_POLICY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::RegisterCallback(const sptr &callback) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - LOG_ERROR("Failed to write callback."); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::REGISTER_CALLBACK), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(uid)) { - LOG_ERROR("Failed to WriteInt32(%{public}d).", uid); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteString(groupID)) { - LOG_ERROR("Failed to WriteString(%{public}s).", groupID.c_str()); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::GENERATE_GROUPID_KEY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - keyId = reply.ReadString(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::DeleteGroupIDKey(uint32_t uid, const std::string &groupID) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteUint32(uid)) { - LOG_ERROR("Failed to WriteInt32(%{public}d).", uid); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteString(groupID)) { - LOG_ERROR("Failed to WriteString(%{public}s).", groupID.c_str()); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::DELETE_GROUPID_KEY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} - -int32_t El5FilekeyManagerProxy::QueryAppKeyState(DataLockType type) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return EFM_ERR_IPC_WRITE_DATA; - } - if (!data.WriteInt32(static_cast(type))) { - LOG_ERROR("Failed to WriteInt32(%{public}d).", type); - return EFM_ERR_IPC_WRITE_DATA; - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return EFM_ERR_REMOTE_CONNECTION; - } - int32_t result = remote->SendRequest( - static_cast(EFMInterfaceCode::QUERY_APP_KEY_STATE), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } else { - result = reply.ReadInt32(); - } - return result; -} -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/interfaces/inner_api/el5filekeymanager/src/user_app_key_info.cpp b/interfaces/inner_api/el5filekeymanager/src/user_app_key_info.cpp new file mode 100644 index 000000000..86465b3ca --- /dev/null +++ b/interfaces/inner_api/el5filekeymanager/src/user_app_key_info.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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 "user_app_key_info.h" +#include "parcel_utils.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool UserAppKeyInfo::Marshalling(Parcel &parcel) const +{ + RETURN_IF_FALSE(parcel.WriteInt32(this->first)); + RETURN_IF_FALSE(parcel.WriteString(this->second)); + return true; +} + +UserAppKeyInfo *UserAppKeyInfo::Unmarshalling(Parcel &parcel) +{ + UserAppKeyInfo *info = new (std::nothrow) UserAppKeyInfo(); + if (info == nullptr) { + return nullptr; + } + + RELEASE_IF_FALSE(parcel.ReadInt32(info->first), info); + RELEASE_IF_FALSE(parcel.ReadString(info->second), info); + return info; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/inner_api/el5filekeymanager/test/BUILD.gn b/interfaces/inner_api/el5filekeymanager/test/BUILD.gn index a334f3e6c..a596b8355 100644 --- a/interfaces/inner_api/el5filekeymanager/test/BUILD.gn +++ b/interfaces/inner_api/el5filekeymanager/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 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 @@ -36,6 +36,7 @@ ohos_unittest("el5_filekey_manager_kit_unittest") { configs = [ "${access_token_path}/config:coverage_flags" ] deps = [ + "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_proxy", "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_sdk", "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "${access_token_path}/interfaces/innerkits/token_setproc:libtoken_setproc", diff --git a/interfaces/inner_api/el5filekeymanager/test/unittest/src/el5_filekey_manager_kit_unittest.cpp b/interfaces/inner_api/el5filekeymanager/test/unittest/src/el5_filekey_manager_kit_unittest.cpp index d5f0d2cae..07337f276 100644 --- a/interfaces/inner_api/el5filekeymanager/test/unittest/src/el5_filekey_manager_kit_unittest.cpp +++ b/interfaces/inner_api/el5filekeymanager/test/unittest/src/el5_filekey_manager_kit_unittest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -16,7 +16,7 @@ #include "el5_filekey_manager_kit_unittest.h" #include "accesstoken_kit.h" -#include "el5_filekey_callback_stub.h" +#include "el5_filekey_callback_interface_stub.h" #include "el5_filekey_manager_error.h" #include "el5_filekey_manager_kit.h" #include "token_setproc.h" @@ -40,11 +40,12 @@ void El5FilekeyManagerKitTest::TearDown() { } -class TestEl5FilekeyCallback : public El5FilekeyCallbackStub { +class TestEl5FilekeyCallback : public El5FilekeyCallbackInterfaceStub { public: - void OnRegenerateAppKey(std::vector &infos) + OHOS::ErrCode OnRegenerateAppKey(std::vector &infos) { GTEST_LOG_(INFO) << "OnRegenerateAppKey."; + return OHOS::ERR_OK; } }; @@ -56,7 +57,7 @@ public: */ HWTEST_F(El5FilekeyManagerKitTest, AcquireAccess001, TestSize.Level1) { - DataLockType type = MEDIA_DATA; + DataLockType type = DataLockType::MEDIA_DATA; ASSERT_EQ(El5FilekeyManagerKit::AcquireAccess(static_cast(type)), EFM_ERR_NO_PERMISSION); } @@ -68,7 +69,7 @@ HWTEST_F(El5FilekeyManagerKitTest, AcquireAccess001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerKitTest, AcquireAccess002, TestSize.Level1) { - DataLockType type = ALL_DATA; + DataLockType type = DataLockType::ALL_DATA; ASSERT_EQ(El5FilekeyManagerKit::AcquireAccess(static_cast(type)), EFM_ERR_NO_PERMISSION); } @@ -80,7 +81,7 @@ HWTEST_F(El5FilekeyManagerKitTest, AcquireAccess002, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerKitTest, ReleaseAccess001, TestSize.Level1) { - DataLockType type = MEDIA_DATA; + DataLockType type = DataLockType::MEDIA_DATA; ASSERT_EQ(El5FilekeyManagerKit::ReleaseAccess(static_cast(type)), EFM_ERR_NO_PERMISSION); } @@ -92,7 +93,7 @@ HWTEST_F(El5FilekeyManagerKitTest, ReleaseAccess001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerKitTest, ReleaseAccess002, TestSize.Level1) { - DataLockType type = ALL_DATA; + DataLockType type = DataLockType::ALL_DATA; ASSERT_EQ(El5FilekeyManagerKit::ReleaseAccess(static_cast(type)), EFM_ERR_NO_PERMISSION); } @@ -221,7 +222,7 @@ HWTEST_F(El5FilekeyManagerKitTest, DeleteGroupIDKey001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerKitTest, QueryAppKeyState001, TestSize.Level1) { - DataLockType type = MEDIA_DATA; + DataLockType type = DataLockType::MEDIA_DATA; ASSERT_EQ(El5FilekeyManagerKit::QueryAppKeyState(static_cast(type)), EFM_ERR_NO_PERMISSION); } @@ -233,6 +234,6 @@ HWTEST_F(El5FilekeyManagerKitTest, QueryAppKeyState001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerKitTest, QueryAppKeyState002, TestSize.Level1) { - DataLockType type = ALL_DATA; + DataLockType type = DataLockType::ALL_DATA; ASSERT_EQ(El5FilekeyManagerKit::QueryAppKeyState(static_cast(type)), EFM_ERR_NO_PERMISSION); } diff --git a/interfaces/kits/cj/screenlockfilemanager/src/screen_lock_file_manager_ffi.cpp b/interfaces/kits/cj/screenlockfilemanager/src/screen_lock_file_manager_ffi.cpp index 3d3867654..882b21ee7 100644 --- a/interfaces/kits/cj/screenlockfilemanager/src/screen_lock_file_manager_ffi.cpp +++ b/interfaces/kits/cj/screenlockfilemanager/src/screen_lock_file_manager_ffi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -26,12 +26,12 @@ namespace ScreenLockFileManager { extern "C" { int32_t FfiOHOSScreenLockFileManagerAcquireAccess() { - return El5FilekeyManagerKit::AcquireAccess(DEFAULT_DATA); + return El5FilekeyManagerKit::AcquireAccess(DataLockType::DEFAULT_DATA); } int32_t FfiOHOSScreenLockFileManagerReleaseAccess() { - return El5FilekeyManagerKit::ReleaseAccess(DEFAULT_DATA); + return El5FilekeyManagerKit::ReleaseAccess(DataLockType::DEFAULT_DATA); } } } // namespace ScreenLockFileManager diff --git a/services/el5filekeymanager/BUILD.gn b/services/el5filekeymanager/BUILD.gn index b2445cc32..92cafd73c 100644 --- a/services/el5filekeymanager/BUILD.gn +++ b/services/el5filekeymanager/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 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 @@ -53,10 +53,8 @@ if (is_standard_system && ability_base_enable == true) { ] defines = [] sources = [ - "src/el5_filekey_callback_proxy.cpp", "src/el5_filekey_manager_service.cpp", "src/el5_filekey_manager_service_ability.cpp", - "src/el5_filekey_manager_stub.cpp", ] configs = [] @@ -65,13 +63,11 @@ if (is_standard_system && ability_base_enable == true) { cflags += [ "-DBINDER_IPC_32BIT" ] } - include_dirs = [ - "${access_token_path}/services/el5filekeymanager/include", - "${access_token_path}/frameworks/inner_api/el5filekeymanager/include/", - ] + include_dirs = [ "${access_token_path}/services/el5filekeymanager/include" ] deps = [ "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_sdk", + "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_stub", "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "${access_token_path}/interfaces/innerkits/accesstoken:libtokenid_sdk", "${access_token_path}/services/el5filekeymanager:el5_filekey_manager_cfg", diff --git a/services/el5filekeymanager/include/el5_filekey_manager_service.h b/services/el5filekeymanager/include/el5_filekey_manager_service.h index 3571fecfe..2d660a112 100644 --- a/services/el5filekeymanager/include/el5_filekey_manager_service.h +++ b/services/el5filekeymanager/include/el5_filekey_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -23,7 +23,7 @@ #ifdef COMMON_EVENT_SERVICE_ENABLE #include "el5_filkey_manager_subscriber.h" #endif -#include "el5_filekey_manager_stub.h" +#include "el5_filekey_manager_interface_stub.h" #include "el5_filekey_service_ext_interface.h" #ifdef EVENTHANDLER_ENABLE #include "event_handler.h" @@ -34,7 +34,7 @@ namespace Security { namespace AccessToken { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; -class El5FilekeyManagerService : public El5FilekeyManagerStub { +class El5FilekeyManagerService : public El5FilekeyManagerInterfaceStub { public: El5FilekeyManagerService(); virtual ~El5FilekeyManagerService(); @@ -46,9 +46,8 @@ public: int32_t ReleaseAccess(DataLockType type) override; int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId) override; int32_t DeleteAppKey(const std::string& bundleName, int32_t userId) override; - int32_t GetUserAppKey(int32_t userId, bool getAllFlag, - std::vector> &keyInfos) override; - int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector> &loadInfos) override; + int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector &keyInfos) override; + int32_t ChangeUserAppkeysLoadInfo(int32_t userId, const std::vector &loadInfos) override; int32_t SetFilePathPolicy() override; int32_t RegisterCallback(const sptr &callback) override; int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId) override; diff --git a/services/el5filekeymanager/include/el5_filekey_manager_stub.h b/services/el5filekeymanager/include/el5_filekey_manager_stub.h deleted file mode 100644 index 790588406..000000000 --- a/services/el5filekeymanager/include/el5_filekey_manager_stub.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 EL5_FILEKEY_MANAGER_STUB_H -#define EL5_FILEKEY_MANAGER_STUB_H - -#include - -#include "el5_filekey_manager_interface.h" -#include "el5_filekey_manager_log.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -class El5FilekeyManagerStub : public IRemoteStub { -public: - El5FilekeyManagerStub(); - virtual ~El5FilekeyManagerStub(); - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - void SetFuncInMap(); - void AcquireAccessInner(MessageParcel &data, MessageParcel &reply); - void ReleaseAccessInner(MessageParcel &data, MessageParcel &reply); - void GenerateAppKeyInner(MessageParcel &data, MessageParcel &reply); - void DeleteAppKeyInner(MessageParcel &data, MessageParcel &reply); - void GetUserAppKeyInner(MessageParcel &data, MessageParcel &reply); - void ChangeUserAppkeysLoadInfoInner(MessageParcel &data, MessageParcel &reply); - void SetFilePathPolicyInner(MessageParcel &data, MessageParcel &reply); - void RegisterCallbackInner(MessageParcel &data, MessageParcel &reply); - void GenerateGroupIDKeyInner(MessageParcel &data, MessageParcel &reply); - void DeleteGroupIDKeyInner(MessageParcel &data, MessageParcel &reply); - void QueryAppKeyStateInner(MessageParcel &data, MessageParcel &reply); - - void MarshallingKeyInfos(MessageParcel &reply, std::vector>& keyInfos); - int32_t UnmarshallingLoadInfos(MessageParcel &data, std::vector> &loadInfos); - - using RequestType = void (El5FilekeyManagerStub::*)(MessageParcel &data, MessageParcel &reply); - std::map requestMap_; -}; -} // namespace AccessToken -} // namespace Security -} // namespace OHOS -#endif // EL5_FILEKEY_MANAGER_STUB_H diff --git a/services/el5filekeymanager/src/el5_filekey_callback_proxy.cpp b/services/el5filekeymanager/src/el5_filekey_callback_proxy.cpp deleted file mode 100644 index 7747904ec..000000000 --- a/services/el5filekeymanager/src/el5_filekey_callback_proxy.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 "el5_filekey_callback_proxy.h" -#include "el5_filekey_manager_error.h" -#include "el5_filekey_manager_log.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -El5FilekeyCallbackProxy::El5FilekeyCallbackProxy(const sptr& impl) - : IRemoteProxy(impl) { -} - -El5FilekeyCallbackProxy::~El5FilekeyCallbackProxy() -{ -} - -void El5FilekeyCallbackProxy::OnRegenerateAppKey(std::vector &infos) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(El5FilekeyCallbackInterface::GetDescriptor())) { - LOG_ERROR("Failed to write WriteInterfaceToken."); - return; - } - if (!data.WriteUint32(infos.size())) { - LOG_ERROR("Failed to WriteUint32(%{public}d).", static_cast(infos.size())); - return; - } - for (AppKeyInfo info : infos) { - if (!data.WriteParcelable(&info)) { - LOG_ERROR("Failed to write AppKeyInfo."); - return; - } - } - - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - if (remote == nullptr) { - LOG_ERROR("Remote service is null."); - return; - } - - int32_t result = remote->SendRequest( - static_cast(El5FilekeyCallbackInterface::Code::ON_REGENERATE_APP_KEY), data, reply, option); - if (result != NO_ERROR) { - LOG_ERROR("SendRequest failed, result: %{public}d.", result); - } -} -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/services/el5filekeymanager/src/el5_filekey_manager_service.cpp b/services/el5filekeymanager/src/el5_filekey_manager_service.cpp index 8b7f6f662..450855093 100644 --- a/services/el5filekeymanager/src/el5_filekey_manager_service.cpp +++ b/services/el5filekeymanager/src/el5_filekey_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -24,6 +24,7 @@ #include "el5_filekey_manager_error.h" #include "ipc_skeleton.h" #include "iservice_registry.h" +#include "el5_filekey_manager_log.h" #ifdef THEME_SCREENLOCK_MGR_ENABLE #include "screenlock_manager.h" #endif @@ -241,8 +242,7 @@ int32_t El5FilekeyManagerService::DeleteAppKey(const std::string& bundleName, in return service_->DeleteAppKey(bundleName, userId); } -int32_t El5FilekeyManagerService::GetUserAppKey(int32_t userId, bool getAllFlag, - std::vector> &keyInfos) +int32_t El5FilekeyManagerService::GetUserAppKey(int32_t userId, bool getAllFlag, std::vector &keyInfos) { LOG_INFO("Get user %{public}d app key.", userId); if (userId < 0) { @@ -264,7 +264,7 @@ int32_t El5FilekeyManagerService::GetUserAppKey(int32_t userId, bool getAllFlag, } int32_t El5FilekeyManagerService::ChangeUserAppkeysLoadInfo(int32_t userId, - std::vector> &loadInfos) + const std::vector &loadInfos) { LOG_INFO("Change user %{public}d load infos.", userId); if (userId < 0) { diff --git a/services/el5filekeymanager/src/el5_filekey_manager_stub.cpp b/services/el5filekeymanager/src/el5_filekey_manager_stub.cpp deleted file mode 100644 index 055ff7ed9..000000000 --- a/services/el5filekeymanager/src/el5_filekey_manager_stub.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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 "el5_filekey_manager_stub.h" - -#include "el5_filekey_manager_error.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -namespace { -constexpr uint32_t MAX_KEY_SIZE = 1000; -} - -El5FilekeyManagerStub::El5FilekeyManagerStub() -{ - SetFuncInMap(); -} - -El5FilekeyManagerStub::~El5FilekeyManagerStub() -{ - requestMap_.clear(); -} - -void El5FilekeyManagerStub::SetFuncInMap() -{ - requestMap_[static_cast(EFMInterfaceCode::GENERATE_APP_KEY)] = - &El5FilekeyManagerStub::GenerateAppKeyInner; - requestMap_[static_cast(EFMInterfaceCode::DELETE_APP_KEY)] = - &El5FilekeyManagerStub::DeleteAppKeyInner; - requestMap_[static_cast(EFMInterfaceCode::ACQUIRE_ACCESS)] = - &El5FilekeyManagerStub::AcquireAccessInner; - requestMap_[static_cast(EFMInterfaceCode::RELEASE_ACCESS)] = - &El5FilekeyManagerStub::ReleaseAccessInner; - requestMap_[static_cast(EFMInterfaceCode::GET_USER_APP_KEY)] = - &El5FilekeyManagerStub::GetUserAppKeyInner; - requestMap_[static_cast(EFMInterfaceCode::CHANGE_USER_APP_KEYS_LOAD_INFO)] = - &El5FilekeyManagerStub::ChangeUserAppkeysLoadInfoInner; - requestMap_[static_cast(EFMInterfaceCode::SET_FILE_PATH_POLICY)] = - &El5FilekeyManagerStub::SetFilePathPolicyInner; - requestMap_[static_cast(EFMInterfaceCode::REGISTER_CALLBACK)] = - &El5FilekeyManagerStub::RegisterCallbackInner; - requestMap_[static_cast(EFMInterfaceCode::GENERATE_GROUPID_KEY)] = - &El5FilekeyManagerStub::GenerateGroupIDKeyInner; - requestMap_[static_cast(EFMInterfaceCode::DELETE_GROUPID_KEY)] = - &El5FilekeyManagerStub::DeleteGroupIDKeyInner; - requestMap_[static_cast(EFMInterfaceCode::QUERY_APP_KEY_STATE)] = - &El5FilekeyManagerStub::QueryAppKeyStateInner; -} - -int32_t El5FilekeyManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - if (data.ReadInterfaceToken() != El5FilekeyManagerInterface::GetDescriptor()) { - LOG_ERROR("Get unexpected descriptor"); - return EFM_ERR_IPC_TOKEN_INVALID; - } - - auto itFunc = requestMap_.find(code); - if (itFunc != requestMap_.end()) { - auto requestFunc = itFunc->second; - if (requestFunc != nullptr) { - (this->*requestFunc)(data, reply); - return NO_ERROR; - } - } - - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -void El5FilekeyManagerStub::AcquireAccessInner(MessageParcel &data, MessageParcel &reply) -{ - DataLockType type = static_cast(data.ReadInt32()); - reply.WriteInt32(this->AcquireAccess(type)); -} - -void El5FilekeyManagerStub::ReleaseAccessInner(MessageParcel &data, MessageParcel &reply) -{ - DataLockType type = static_cast(data.ReadInt32()); - reply.WriteInt32(this->ReleaseAccess(type)); -} - -void El5FilekeyManagerStub::GenerateAppKeyInner(MessageParcel &data, MessageParcel &reply) -{ - uint32_t uid = data.ReadUint32(); - std::string bundleName = data.ReadString(); - std::string keyId; - reply.WriteInt32(this->GenerateAppKey(uid, bundleName, keyId)); - reply.WriteString(keyId); -} - -void El5FilekeyManagerStub::DeleteAppKeyInner(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - int32_t userId = data.ReadInt32(); - reply.WriteInt32(this->DeleteAppKey(bundleName, userId)); -} - -void El5FilekeyManagerStub::GetUserAppKeyInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = data.ReadInt32(); - bool getAllFlag = data.ReadBool(); - std::vector> keyInfos; - reply.WriteInt32(this->GetUserAppKey(userId, getAllFlag, keyInfos)); - MarshallingKeyInfos(reply, keyInfos); -} - -void El5FilekeyManagerStub::ChangeUserAppkeysLoadInfoInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t userId = data.ReadInt32(); - std::vector> loadInfos; - int32_t ret = UnmarshallingLoadInfos(data, loadInfos); - if (ret == EFM_SUCCESS) { - ret = this->ChangeUserAppkeysLoadInfo(userId, loadInfos); - } - reply.WriteInt32(ret); -} - -void El5FilekeyManagerStub::SetFilePathPolicyInner(MessageParcel &data, MessageParcel &reply) -{ - reply.WriteInt32(this->SetFilePathPolicy()); -} - -void El5FilekeyManagerStub::RegisterCallbackInner(MessageParcel &data, MessageParcel &reply) -{ - auto callback = iface_cast(data.ReadRemoteObject()); - if ((callback == nullptr) || (!callback->AsObject())) { - LOG_ERROR("Read callback failed."); - reply.WriteInt32(EFM_ERR_IPC_READ_DATA); - return; - } - reply.WriteInt32(this->RegisterCallback(callback)); -} - -void El5FilekeyManagerStub::GenerateGroupIDKeyInner(MessageParcel &data, MessageParcel &reply) -{ - uint32_t uid = data.ReadUint32(); - std::string groupID = data.ReadString(); - std::string keyId; - reply.WriteInt32(this->GenerateGroupIDKey(uid, groupID, keyId)); - reply.WriteString(keyId); -} - -void El5FilekeyManagerStub::DeleteGroupIDKeyInner(MessageParcel &data, MessageParcel &reply) -{ - uint32_t uid = data.ReadUint32(); - std::string groupID = data.ReadString(); - reply.WriteInt32(this->DeleteGroupIDKey(uid, groupID)); -} - -void El5FilekeyManagerStub::QueryAppKeyStateInner(MessageParcel &data, MessageParcel &reply) -{ - DataLockType type = static_cast(data.ReadInt32()); - reply.WriteInt32(this->QueryAppKeyState(type)); -} - -void El5FilekeyManagerStub::MarshallingKeyInfos(MessageParcel &reply, - std::vector>& keyInfos) -{ - reply.WriteUint32(keyInfos.size()); - for (std::pair &keyInfo : keyInfos) { - reply.WriteInt32(keyInfo.first); - reply.WriteString(keyInfo.second); - } -} - -int32_t El5FilekeyManagerStub::UnmarshallingLoadInfos(MessageParcel &data, - std::vector> &loadInfos) -{ - uint32_t loadInfosSize = data.ReadUint32(); - if (loadInfosSize > MAX_KEY_SIZE) { - LOG_ERROR("Parse loadInfos failed, results oversize %{public}d.", loadInfosSize); - return EFM_ERR_IPC_READ_DATA; - } - for (uint32_t i = 0; i < loadInfosSize; ++i) { - std::string keyId = data.ReadString(); - bool loadState = data.ReadBool(); - loadInfos.emplace_back(std::make_pair(keyId, loadState)); - } - return EFM_SUCCESS; -} -} // namespace AccessToken -} // namespace Security -} // namespace OHOS diff --git a/services/el5filekeymanager/test/BUILD.gn b/services/el5filekeymanager/test/BUILD.gn index 5dee1aa0b..3e1001151 100644 --- a/services/el5filekeymanager/test/BUILD.gn +++ b/services/el5filekeymanager/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 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 @@ -35,7 +35,6 @@ if (is_standard_system && ability_base_enable == true) { sources = [ "../src/el5_filekey_manager_service.cpp", - "../src/el5_filekey_manager_stub.cpp", "mock/src/mock_ipc.cpp", "src/el5_filekey_manager_service_mock_unittest.cpp", ] @@ -44,6 +43,7 @@ if (is_standard_system && ability_base_enable == true) { deps = [ "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_sdk", + "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_stub", "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "${access_token_path}/interfaces/innerkits/accesstoken:libtokenid_sdk", "${access_token_path}/interfaces/innerkits/token_setproc:libtoken_setproc", @@ -99,7 +99,6 @@ if (is_standard_system && ability_base_enable == true) { sources = [ "../src/el5_filekey_manager_service.cpp", - "../src/el5_filekey_manager_stub.cpp", "src/el5_filekey_manager_service_unittest.cpp", ] @@ -107,6 +106,7 @@ if (is_standard_system && ability_base_enable == true) { deps = [ "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_sdk", + "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_stub", "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "${access_token_path}/interfaces/innerkits/accesstoken:libtokenid_sdk", "${access_token_path}/interfaces/innerkits/token_setproc:libtoken_setproc", @@ -162,7 +162,6 @@ if (is_standard_system && ability_base_enable == true) { sources = [ "../src/el5_filekey_manager_service.cpp", - "../src/el5_filekey_manager_stub.cpp", "src/el5_filekey_manager_stub_unittest.cpp", ] @@ -170,6 +169,7 @@ if (is_standard_system && ability_base_enable == true) { deps = [ "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_sdk", + "${access_token_path}/interfaces/inner_api/el5filekeymanager:el5_filekey_manager_stub", "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", "${access_token_path}/interfaces/innerkits/accesstoken:libtokenid_sdk", "${access_token_path}/interfaces/innerkits/token_setproc:libtoken_setproc", diff --git a/services/el5filekeymanager/test/include/el5_filekey_manager_stub_unittest.h b/services/el5filekeymanager/test/include/el5_filekey_manager_stub_unittest.h index 8a91db9a2..4efd776ad 100644 --- a/services/el5filekeymanager/test/include/el5_filekey_manager_stub_unittest.h +++ b/services/el5filekeymanager/test/include/el5_filekey_manager_stub_unittest.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -19,7 +19,7 @@ #include #include -#include "el5_filekey_manager_stub.h" +#include "el5_filekey_manager_interface_stub.h" #include "el5_filekey_manager_service.h" namespace OHOS { @@ -35,7 +35,7 @@ public: void TearDown(); - std::shared_ptr el5FilekeyManagerStub_; + std::shared_ptr el5FilekeyManagerStub_; }; } // namespace AccessToken } // namespace Security diff --git a/services/el5filekeymanager/test/src/el5_filekey_manager_service_mock_unittest.cpp b/services/el5filekeymanager/test/src/el5_filekey_manager_service_mock_unittest.cpp index 2f1d17c03..aecbe199b 100644 --- a/services/el5filekeymanager/test/src/el5_filekey_manager_service_mock_unittest.cpp +++ b/services/el5filekeymanager/test/src/el5_filekey_manager_service_mock_unittest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -16,7 +16,8 @@ #include "el5_filekey_manager_service_mock_unittest.h" #include "accesstoken_kit.h" -#include "el5_filekey_callback_stub.h" +#include "el5_filekey_callback_interface_stub.h" +#include "el5_filekey_manager_error.h" #include "mock_ipc.h" #include "token_setproc.h" @@ -46,11 +47,12 @@ void El5FilekeyManagerServiceMockTest::TearDown() { } -class TestEl5FilekeyCallback : public El5FilekeyCallbackStub { +class TestEl5FilekeyCallback : public El5FilekeyCallbackInterfaceStub { public: - void OnRegenerateAppKey(std::vector &infos) + OHOS::ErrCode OnRegenerateAppKey(std::vector &infos) { GTEST_LOG_(INFO) << "OnRegenerateAppKey."; + return OHOS::ERR_OK; } }; @@ -76,15 +78,15 @@ public: return EFM_SUCCESS; } - int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector> &keyInfos) + int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector &keyInfos) { int32_t key = 111; std::string info = "test"; - keyInfos.emplace_back(std::make_pair(key, info)); + keyInfos.emplace_back(UserAppKeyInfo(key, info)); return EFM_SUCCESS; } - int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector> &loadInfos) + int32_t ChangeUserAppkeysLoadInfo(int32_t userId, const std::vector &loadInfos) { return EFM_SUCCESS; } @@ -154,7 +156,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, AcquireAccess001, TestSize.Level1) AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0); MockIpc::SetCallingTokenID(static_cast(tokenId)); - ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DEFAULT_DATA), EFM_SUCCESS); + ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DataLockType::DEFAULT_DATA), EFM_SUCCESS); } /** @@ -171,7 +173,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, AcquireAccess002, TestSize.Level1) AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0); MockIpc::SetCallingTokenID(static_cast(tokenId)); - ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DEFAULT_DATA), EFM_SUCCESS); + ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DataLockType::DEFAULT_DATA), EFM_SUCCESS); } /** @@ -188,7 +190,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, ReleaseAccess001, TestSize.Level1) AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0); MockIpc::SetCallingTokenID(static_cast(tokenId)); - ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DEFAULT_DATA), EFM_SUCCESS); + ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DataLockType::DEFAULT_DATA), EFM_SUCCESS); } /** @@ -205,7 +207,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, ReleaseAccess002, TestSize.Level1) AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0); MockIpc::SetCallingTokenID(static_cast(tokenId)); - ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DEFAULT_DATA), EFM_SUCCESS); + ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DataLockType::DEFAULT_DATA), EFM_SUCCESS); } /** @@ -293,7 +295,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, GetUserAppKey001, TestSize.Level1) el5FilekeyManagerService_->service_ = nullptr; int32_t userId = 100; - std::vector> keyInfos; + std::vector keyInfos; AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon"); MockIpc::SetCallingTokenID(static_cast(tokenId)); @@ -312,7 +314,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, GetUserAppKey002, TestSize.Level1) el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt(); int32_t userId = 100; - std::vector> keyInfos; + std::vector keyInfos; AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon"); MockIpc::SetCallingTokenID(static_cast(tokenId)); @@ -338,7 +340,8 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, GetUserAppKey003, TestSize.Level1) data.WriteBool(false); ASSERT_EQ(el5FilekeyManagerService_->OnRemoteRequest( - static_cast(EFMInterfaceCode::GET_USER_APP_KEY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_GET_USER_APP_KEY), data, reply, option), + OHOS::NO_ERROR); } /** @@ -352,8 +355,9 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, ChangeUserAppkeysLoadInfo001, TestSiz el5FilekeyManagerService_->service_ = nullptr; int32_t userId = 100; - std::vector> loadInfos; - loadInfos.emplace_back(std::make_pair("", true)); + std::vector loadInfos; + std::string emptyStr(""); + loadInfos.emplace_back(AppKeyLoadInfo(emptyStr, true)); AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon"); MockIpc::SetCallingTokenID(static_cast(tokenId)); @@ -372,8 +376,9 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, ChangeUserAppkeysLoadInfo002, TestSiz el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt(); int32_t userId = 100; - std::vector> loadInfos; - loadInfos.emplace_back(std::make_pair("", true)); + std::vector loadInfos; + std::string emptyStr(""); + loadInfos.emplace_back(AppKeyLoadInfo(emptyStr, true)); AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon"); MockIpc::SetCallingTokenID(static_cast(tokenId)); @@ -535,7 +540,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, QueryAppKeyState001, TestSize.Level1) AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0); MockIpc::SetCallingTokenID(static_cast(tokenId)); - ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DEFAULT_DATA), EFM_SUCCESS); + ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DataLockType::DEFAULT_DATA), EFM_SUCCESS); } /** @@ -552,7 +557,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, QueryAppKeyState002, TestSize.Level1) AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0); MockIpc::SetCallingTokenID(static_cast(tokenId)); - ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DEFAULT_DATA), EFM_SUCCESS); + ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DataLockType::DEFAULT_DATA), EFM_SUCCESS); } /** @@ -651,7 +656,7 @@ HWTEST_F(El5FilekeyManagerServiceMockTest, OnRemoteRequest001, TestSize.Level1) OHOS::MessageParcel data; OHOS::MessageParcel reply; OHOS::MessageOption option; - uint32_t code = static_cast(El5FilekeyCallbackInterface::Code::ON_REGENERATE_APP_KEY); + uint32_t code = static_cast(El5FilekeyCallbackInterfaceIpcCode::COMMAND_ON_REGENERATE_APP_KEY); ASSERT_EQ(data.WriteInterfaceToken(El5FilekeyCallbackInterface::GetDescriptor()), true); data.WriteUint32(1); // infosSize diff --git a/services/el5filekeymanager/test/src/el5_filekey_manager_service_unittest.cpp b/services/el5filekeymanager/test/src/el5_filekey_manager_service_unittest.cpp index 3c2ae6353..717bac1a1 100644 --- a/services/el5filekeymanager/test/src/el5_filekey_manager_service_unittest.cpp +++ b/services/el5filekeymanager/test/src/el5_filekey_manager_service_unittest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -16,7 +16,8 @@ #include "el5_filekey_manager_service_unittest.h" #include "accesstoken_kit.h" -#include "el5_filekey_callback_stub.h" +#include "el5_filekey_callback_interface_stub.h" +#include "el5_filekey_manager_error.h" #include "token_setproc.h" using namespace testing::ext; @@ -44,11 +45,12 @@ void El5FilekeyManagerServiceTest::TearDown() { } -class TestEl5FilekeyCallback : public El5FilekeyCallbackStub { +class TestEl5FilekeyCallback : public El5FilekeyCallbackInterfaceStub { public: - void OnRegenerateAppKey(std::vector &infos) + OHOS::ErrCode OnRegenerateAppKey(std::vector &infos) { GTEST_LOG_(INFO) << "OnRegenerateAppKey."; + return OHOS::ERR_OK; } }; @@ -60,7 +62,7 @@ public: */ HWTEST_F(El5FilekeyManagerServiceTest, AcquireAccess001, TestSize.Level1) { - ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(MEDIA_DATA), EFM_ERR_NO_PERMISSION); + ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DataLockType::MEDIA_DATA), EFM_ERR_NO_PERMISSION); } /** @@ -71,7 +73,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, AcquireAccess001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerServiceTest, AcquireAccess002, TestSize.Level1) { - ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(ALL_DATA), EFM_ERR_NO_PERMISSION); + ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DataLockType::ALL_DATA), EFM_ERR_NO_PERMISSION); } /** @@ -94,7 +96,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, AcquireAccess003, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerServiceTest, ReleaseAccess001, TestSize.Level1) { - ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(MEDIA_DATA), EFM_ERR_NO_PERMISSION); + ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DataLockType::MEDIA_DATA), EFM_ERR_NO_PERMISSION); } /** @@ -105,7 +107,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, ReleaseAccess001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerServiceTest, ReleaseAccess002, TestSize.Level1) { - ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(ALL_DATA), EFM_ERR_NO_PERMISSION); + ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DataLockType::ALL_DATA), EFM_ERR_NO_PERMISSION); } /** @@ -144,7 +146,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, DeleteAppKey001, TestSize.Level1) HWTEST_F(El5FilekeyManagerServiceTest, GetUserAppKey001, TestSize.Level1) { int32_t userId = 100; - std::vector> keyInfos; + std::vector keyInfos; ASSERT_EQ(el5FilekeyManagerService_->GetUserAppKey(userId, false, keyInfos), EFM_ERR_NO_PERMISSION); } @@ -157,7 +159,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, GetUserAppKey001, TestSize.Level1) HWTEST_F(El5FilekeyManagerServiceTest, GetUserAppKey002, TestSize.Level1) { int32_t userId = -100; - std::vector> keyInfos; + std::vector keyInfos; ASSERT_EQ(el5FilekeyManagerService_->GetUserAppKey(userId, false, keyInfos), EFM_ERR_INVALID_PARAMETER); } @@ -170,8 +172,9 @@ HWTEST_F(El5FilekeyManagerServiceTest, GetUserAppKey002, TestSize.Level1) HWTEST_F(El5FilekeyManagerServiceTest, ChangeUserAppkeysLoadInfo001, TestSize.Level1) { int32_t userId = 100; - std::vector> loadInfos; - loadInfos.emplace_back(std::make_pair("", true)); + std::vector loadInfos; + std::string emptyStr(""); + loadInfos.emplace_back(AppKeyLoadInfo(emptyStr, true)); ASSERT_EQ(el5FilekeyManagerService_->ChangeUserAppkeysLoadInfo(userId, loadInfos), EFM_ERR_NO_PERMISSION); } @@ -184,8 +187,9 @@ HWTEST_F(El5FilekeyManagerServiceTest, ChangeUserAppkeysLoadInfo001, TestSize.Le HWTEST_F(El5FilekeyManagerServiceTest, ChangeUserAppkeysLoadInfo002, TestSize.Level1) { int32_t userId = -100; - std::vector> loadInfos; - loadInfos.emplace_back(std::make_pair("", true)); + std::vector loadInfos; + std::string emptyStr(""); + loadInfos.emplace_back(AppKeyLoadInfo(emptyStr, true)); ASSERT_EQ(el5FilekeyManagerService_->ChangeUserAppkeysLoadInfo(userId, loadInfos), EFM_ERR_INVALID_PARAMETER); } @@ -246,7 +250,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, DeleteGroupIDKey001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerServiceTest, QueryAppKeyState001, TestSize.Level1) { - ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(MEDIA_DATA), EFM_ERR_NO_PERMISSION); + ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DataLockType::MEDIA_DATA), EFM_ERR_NO_PERMISSION); } /** @@ -257,7 +261,7 @@ HWTEST_F(El5FilekeyManagerServiceTest, QueryAppKeyState001, TestSize.Level1) */ HWTEST_F(El5FilekeyManagerServiceTest, QueryAppKeyState002, TestSize.Level1) { - ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(ALL_DATA), EFM_ERR_NO_PERMISSION); + ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DataLockType::ALL_DATA), EFM_ERR_NO_PERMISSION); } /** diff --git a/services/el5filekeymanager/test/src/el5_filekey_manager_stub_unittest.cpp b/services/el5filekeymanager/test/src/el5_filekey_manager_stub_unittest.cpp index d0fae46b9..90da39a02 100644 --- a/services/el5filekeymanager/test/src/el5_filekey_manager_stub_unittest.cpp +++ b/services/el5filekeymanager/test/src/el5_filekey_manager_stub_unittest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -17,7 +17,8 @@ #include "singleton.h" #include "accesstoken_kit.h" -#include "el5_filekey_callback_stub.h" +#include "el5_filekey_callback_interface_stub.h" +#include "el5_filekey_manager_error.h" #include "token_setproc.h" using namespace testing::ext; @@ -42,7 +43,7 @@ void El5FilekeyManagerStubTest::TearDown() /** * @tc.name: OnRemoteRequest001 - * @tc.desc: EFMInterfaceCode::GENERATE_APP_KEY. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_GENERATE_APP_KEY. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -55,12 +56,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest001, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::GENERATE_APP_KEY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_GENERATE_APP_KEY), data, reply, option), + OHOS::NO_ERROR); } /** * @tc.name: OnRemoteRequest002 - * @tc.desc: EFMInterfaceCode::DELETE_APP_KEY. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_DELETE_APP_KEY. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -73,12 +75,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest002, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::DELETE_APP_KEY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_DELETE_APP_KEY), data, reply, option), + OHOS::NO_ERROR); } /** * @tc.name: OnRemoteRequest003 - * @tc.desc: EFMInterfaceCode::ACQUIRE_ACCESS. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_ACQUIRE_ACCESS. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -91,12 +94,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest003, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::ACQUIRE_ACCESS), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_ACQUIRE_ACCESS), data, reply, option), + OHOS::ERR_INVALID_DATA); } /** * @tc.name: OnRemoteRequest004 - * @tc.desc: EFMInterfaceCode::RELEASE_ACCESS. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_RELEASE_ACCESS. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -109,12 +113,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest004, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::RELEASE_ACCESS), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_RELEASE_ACCESS), data, reply, option), + OHOS::ERR_INVALID_DATA); } /** * @tc.name: OnRemoteRequest005 - * @tc.desc: EFMInterfaceCode::GET_USER_APP_KEY. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_GET_USER_APP_KEY. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -127,12 +132,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest005, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::GET_USER_APP_KEY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_GET_USER_APP_KEY), data, reply, option), + OHOS::NO_ERROR); } /** * @tc.name: OnRemoteRequest006 - * @tc.desc: EFMInterfaceCode::CHANGE_USER_APP_KEYS_LOAD_INFO. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_CHANGE_USER_APPKEYS_LOAD_INFO. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -149,12 +155,14 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest006, TestSize.Level1) data.WriteBool(false); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::CHANGE_USER_APP_KEYS_LOAD_INFO), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_CHANGE_USER_APPKEYS_LOAD_INFO), + data, reply, option), + OHOS::ERR_INVALID_DATA); } /** * @tc.name: OnRemoteRequest007 - * @tc.desc: EFMInterfaceCode::CHANGE_USER_APP_KEYS_LOAD_INFO. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_CHANGE_USER_APPKEYS_LOAD_INFO. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -171,12 +179,14 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest007, TestSize.Level1) data.WriteBool(false); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::CHANGE_USER_APP_KEYS_LOAD_INFO), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_CHANGE_USER_APPKEYS_LOAD_INFO), + data, reply, option), + OHOS::ERR_INVALID_DATA); } /** * @tc.name: OnRemoteRequest008 - * @tc.desc: EFMInterfaceCode::SET_FILE_PATH_POLICY. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_SET_FILE_PATH_POLICY. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -189,12 +199,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest008, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::SET_FILE_PATH_POLICY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_SET_FILE_PATH_POLICY), data, reply, option), + OHOS::NO_ERROR); } /** * @tc.name: OnRemoteRequest009 - * @tc.desc: EFMInterfaceCode::REGISTER_CALLBACK. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_REGISTER_CALLBACK. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -207,7 +218,8 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest009, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::REGISTER_CALLBACK), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_REGISTER_CALLBACK), data, reply, option), + OHOS::ERR_INVALID_DATA); } /** @@ -226,7 +238,8 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest010, TestSize.Level1) data.WriteInterfaceToken(OHOS::Str8ToStr16(des)); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::GENERATE_APP_KEY), data, reply, option), EFM_ERR_IPC_TOKEN_INVALID); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_GENERATE_APP_KEY), data, reply, option), + OHOS::ERR_TRANSACTION_FAILED); } /** @@ -245,12 +258,12 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest011, TestSize.Level1) data.WriteInterfaceToken(OHOS::Str8ToStr16(des)); int32_t code = -1; - ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest(code, data, reply, option), EFM_ERR_IPC_TOKEN_INVALID); + ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest(code, data, reply, option), OHOS::ERR_TRANSACTION_FAILED); } /** * @tc.name: OnRemoteRequest0012 - * @tc.desc: EFMInterfaceCode::GENERATE_GROUPID_KEY. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_GENERATE_GROUP_I_D_KEY. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -263,12 +276,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest0012, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::GENERATE_GROUPID_KEY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_GENERATE_GROUP_I_D_KEY), data, reply, option), + OHOS::NO_ERROR); } /** * @tc.name: OnRemoteRequest0013 - * @tc.desc: EFMInterfaceCode::DELETE_GROUPID_KEY. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_DELETE_GROUP_I_D_KEY. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -281,12 +295,13 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest0013, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::DELETE_GROUPID_KEY), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_DELETE_GROUP_I_D_KEY), data, reply, option), + OHOS::NO_ERROR); } /** * @tc.name: OnRemoteRequest0014 - * @tc.desc: EFMInterfaceCode::QUERY_APP_KEY_STATE. + * @tc.desc: El5FilekeyManagerInterfaceIpcCode::COMMAND_QUERY_APP_KEY_STATE. * @tc.type: FUNC * @tc.require: issueI9JGMV */ @@ -299,5 +314,6 @@ HWTEST_F(El5FilekeyManagerStubTest, OnRemoteRequest0014, TestSize.Level1) ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor())); ASSERT_EQ(el5FilekeyManagerStub_->OnRemoteRequest( - static_cast(EFMInterfaceCode::QUERY_APP_KEY_STATE), data, reply, option), OHOS::NO_ERROR); + static_cast(El5FilekeyManagerInterfaceIpcCode::COMMAND_QUERY_APP_KEY_STATE), data, reply, option), + OHOS::ERR_INVALID_DATA); } -- Gitee