From 6354036a20026b83575b2de50cc53371a51575ef Mon Sep 17 00:00:00 2001 From: tangjunyuan Date: Sat, 28 Jun 2025 18:30:07 +0800 Subject: [PATCH] min system Signed-off-by: tangjunyuan --- bundle.json | 4 +- frameworks/inc/deviceauth_sa.h | 17 +- frameworks/inc/ipc_sdk_defines.h | 44 +- frameworks/inc/standard/ipc_dev_auth_proxy.h | 1 + frameworks/sdk/sa_listener/inc/sa_listener.h | 37 ++ .../sdk/sa_listener/src/sa_listener.cpp | 39 ++ .../sa_load_on_demand/inc/sa_load_on_demand.h | 51 +++ .../src/mock/sa_load_on_demand_mock.cpp | 68 +++ .../src/sa_load_on_demand.cpp | 394 ++++++++++++++++++ frameworks/src/deviceauth_sa.cpp | 157 +++++-- frameworks/src/identity_service_ipc_sdk.c | 46 +- frameworks/src/ipc_sdk.c | 100 ++++- frameworks/src/ipc_service_common.c | 2 +- .../src/standard/ipc_dev_auth_proxy.cpp | 19 + interfaces/inner_api/device_auth_defines.h | 5 + services/BUILD.gn | 15 + services/device_auth.c | 2 + services/deviceauth.gni | 14 + services/deviceauth_service.cfg | 4 +- .../os_account_adapter/os_account_adapter.h | 2 + .../os_account_adapter/os_account_adapter.cpp | 4 +- .../account_lifecycle_plugin_proxy.c | 8 + .../src/group_operation/group_operation.c | 10 + .../cache_common_event_handler.h | 28 ++ .../inc/critical_handler/critical_handler.h | 36 ++ services/sa/sa_profile/4701.json | 17 +- .../cache_common_event_handler.cpp | 93 +++++ .../mock/cache_common_event_handler_mock.cpp | 18 + .../src/critical_handler/critical_handler.cpp | 62 +++ .../mock/critical_handler_mock.cpp | 32 ++ .../session_manager/inc/dev_session_mgr.h | 1 + .../session_manager/src/dev_session_mgr.c | 11 +- .../auth/isoauthtask_fuzzer/BUILD.gn | 1 + .../pake/standardexchangetask_fuzzer/BUILD.gn | 1 + .../credsmanager_fuzzer/BUILD.gn | 1 + test/fuzztest/devauth_fuzzer/BUILD.gn | 1 + test/fuzztest/devauthcb_fuzzer/BUILD.gn | 1 + test/fuzztest/devauthfunc_fuzzer/BUILD.gn | 1 + .../fuzztest/devauthinterface_fuzzer/BUILD.gn | 4 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../devauthservauthdevice_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../devauthservcreategroup_fuzzer/BUILD.gn | 1 + .../devauthservdeletegroup_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../devauthservgetgroupinfo_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../devauthservgetpkinfolist_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../devauthservregcallback_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../devauthservunregcallback_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../accountrelatedgroupauth_fuzzer/BUILD.gn | 1 + .../groupoperationcommon_fuzzer/BUILD.gn | 1 + test/fuzztest/identityservice_fuzzer/BUILD.gn | 1 + .../fuzztest/protocol/dlspeke_fuzzer/BUILD.gn | 1 + .../fuzztest/protocol/ecspeke_fuzzer/BUILD.gn | 1 + test/fuzztest/protocol/iso_fuzzer/BUILD.gn | 1 + test/unittest/deviceauth/BUILD.gn | 9 + .../source/device_auth_ipc_test.cpp | 8 + .../source/deviceauth_interface_test.cpp | 9 +- .../source/os_account_adapter_mock.c | 10 + .../unit_test/services/creds_manager/BUILD.gn | 1 + .../frameworks/os_account_adapter/BUILD.gn | 2 + 76 files changed, 1367 insertions(+), 54 deletions(-) create mode 100644 frameworks/sdk/sa_listener/inc/sa_listener.h create mode 100644 frameworks/sdk/sa_listener/src/sa_listener.cpp create mode 100644 frameworks/sdk/sa_load_on_demand/inc/sa_load_on_demand.h create mode 100644 frameworks/sdk/sa_load_on_demand/src/mock/sa_load_on_demand_mock.cpp create mode 100644 frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp create mode 100644 services/sa/inc/cache_common_event_handler/cache_common_event_handler.h create mode 100644 services/sa/inc/critical_handler/critical_handler.h create mode 100644 services/sa/src/cache_common_event_handler/cache_common_event_handler.cpp create mode 100644 services/sa/src/cache_common_event_handler/mock/cache_common_event_handler_mock.cpp create mode 100644 services/sa/src/critical_handler/critical_handler.cpp create mode 100644 services/sa/src/critical_handler/mock/critical_handler_mock.cpp diff --git a/bundle.json b/bundle.json index 3a7de2fc..46e5df65 100644 --- a/bundle.json +++ b/bundle.json @@ -67,7 +67,9 @@ "samgr", "safwk", "ipc", - "netmanager_base" + "netmanager_base", + "memmgr", + "eventhandler" ], "third_party": [], "hisysevent_config": [ diff --git a/frameworks/inc/deviceauth_sa.h b/frameworks/inc/deviceauth_sa.h index 2890f069..5621fb19 100644 --- a/frameworks/inc/deviceauth_sa.h +++ b/frameworks/inc/deviceauth_sa.h @@ -21,6 +21,7 @@ #include "iremote_broker.h" #include "iremote_stub.h" #include "nocopyable.h" +#include "event_handler.h" #include "ipc_dev_auth_stub.h" @@ -46,12 +47,22 @@ public: protected: void OnStart() override; void OnStop() override; + void OnActive(const SystemAbilityOnDemandReason &activeReason) override; + int32_t OnIdle(const SystemAbilityOnDemandReason &idleReason) override; + void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; private: - static std::mutex g_instanceLock; - static sptr g_instance; - + bool CreateUnloadHandler(); + void DestroyUnloadHandler(); + void DelayUnload(); DeviceAuthAbility(); + bool CheckDevAuthStatus(); + bool CheckUnloadStatus(); + + std::shared_ptr unloadHandler_; + std::mutex instanceMutex_; + bool isUnloading_{false}; }; } // namespace OHOS diff --git a/frameworks/inc/ipc_sdk_defines.h b/frameworks/inc/ipc_sdk_defines.h index 8e56706e..69ae0c01 100644 --- a/frameworks/inc/ipc_sdk_defines.h +++ b/frameworks/inc/ipc_sdk_defines.h @@ -17,17 +17,39 @@ #define IPC_SDK_DEFINES_H #include - +#include "device_auth.h" #ifdef __cplusplus extern "C" { #endif +typedef struct { + char *appId; + uint8_t callbackType; // 1 DevAuthCallback, 2 groupListener, 3 credListener + union { + DeviceAuthCallback *deviceAuthCallback; + DataChangeListener *dataChangeListener; + CredChangeListener *credChangeListener; + } callback; +} DevAuthCallbackInfo; + +typedef void (*SaStatusChangeCallbackFunc)(void); +typedef struct { + SaStatusChangeCallbackFunc onReceivedSaAdd; + SaStatusChangeCallbackFunc onReceivedSaRemoved; +} SaStatusChangeCallback; + #define IPC_CALL_BACK_STUB_AUTH_ID 0 #define IPC_CALL_BACK_STUB_BIND_ID 1 #define IPC_CALL_BACK_STUB_DIRECT_AUTH_ID 2 +#define DEVICE_AUTH_SA_LOAD_TIME (4 * 1000) + #define IPC_CALL_CONTEXT_INIT 0x0 +#define DEVAUTH_CALLBACK 1 +#define GROUP_CHANGE_LISTENER 2 +#define CRED_CHANGE_LISTENER 3 + /* params type for ipc call */ #define PARAM_TYPE_APPID 1 #define PARAM_TYPE_DEV_AUTH_CB 2 @@ -175,7 +197,7 @@ if (ret != HC_SUCCESS) { \ #define BREAK_IF_DO_IPC_CALL_FAILED(callCtx, callFunc, isSync) \ ret = DoBinderCall((callCtx), (callFunc), (isSync)); \ if (ret != HC_SUCCESS) { \ - LOGE("ipc call failed."); \ + LOGE("ipc call failed, ret: %" LOG_PUB "d", ret); \ break; \ } @@ -209,6 +231,24 @@ if ((resultNum < (ipcResultNum)) || (inOutLen != sizeof(int32_t))) { \ #define DESTROY_IPC_CTX(callCtx) DestroyCallCtx(&(callCtx)) +#define RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED() \ +if (LoadDeviceAuthSaIfNotLoad() != HC_SUCCESS) { \ + LOGW("sa not load."); \ + return HC_ERR_IPC_SA_NOT_LOAD; \ +} + +#define RETURN_VOID_IF_LOAD_DEVAUTH_FAILED() \ +if (LoadDeviceAuthSaIfNotLoad() != HC_SUCCESS) { \ + LOGW("sa not load."); \ + return; \ +} + +#define RETURN_NULL_IF_LOAD_DEVAUTH_FAILED() \ +if (LoadDeviceAuthSaIfNotLoad() != HC_SUCCESS) { \ + LOGW("sa not load."); \ + return NULL; \ +} + #ifdef __cplusplus } #endif diff --git a/frameworks/inc/standard/ipc_dev_auth_proxy.h b/frameworks/inc/standard/ipc_dev_auth_proxy.h index 7439ee65..97fbe837 100755 --- a/frameworks/inc/standard/ipc_dev_auth_proxy.h +++ b/frameworks/inc/standard/ipc_dev_auth_proxy.h @@ -27,6 +27,7 @@ public: ~ProxyDevAuth(); int32_t DoCallRequest(MessageParcel &dataParcel, MessageParcel &replyParcel, bool withSync); static bool ServiceRunning(void); + void RetryLoadDeviceAuthSa(void); private: static inline BrokerDelegator delegator_; diff --git a/frameworks/sdk/sa_listener/inc/sa_listener.h b/frameworks/sdk/sa_listener/inc/sa_listener.h new file mode 100644 index 00000000..bdd7a448 --- /dev/null +++ b/frameworks/sdk/sa_listener/inc/sa_listener.h @@ -0,0 +1,37 @@ +/* + * 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 SA_LISTENER_H +#define SA_LISTENER_H + +#include "system_ability_status_change_stub.h" +#include "ipc_sdk_defines.h" + +namespace OHOS { +namespace DevAuth { + +class SaListener : public SystemAbilityStatusChangeStub { +public: + SaListener(SaStatusChangeCallback act); + ~SaListener() = default; + void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; + +private: + SaStatusChangeCallback act_; +}; + +} // namespace DevAuth +} // namespace OHOS +#endif // SA_LISTENER_H \ No newline at end of file diff --git a/frameworks/sdk/sa_listener/src/sa_listener.cpp b/frameworks/sdk/sa_listener/src/sa_listener.cpp new file mode 100644 index 00000000..dc0c412e --- /dev/null +++ b/frameworks/sdk/sa_listener/src/sa_listener.cpp @@ -0,0 +1,39 @@ +/* + * 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 "sa_listener.h" + +#include "hc_log.h" + +namespace OHOS { +namespace DevAuth { +SaListener::SaListener(SaStatusChangeCallback act) : act_(act) +{} + +void SaListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{ + (void)deviceId; + LOGI("[SystemAbilityStatusChangeListener]: OnAddSystemAbility systemAbilityId: %" LOG_PUB "d.", systemAbilityId); + act_.onReceivedSaAdd(); +} + +void SaListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{ + (void)deviceId; + LOGI("[SystemAbilityStatusChangeListener]: OnRemoveSystemAbility systemAbilityId: %" LOG_PUB "d.", systemAbilityId); + act_.onReceivedSaRemoved(); +} +} // namespace DevAuth +} // namespace OHOS diff --git a/frameworks/sdk/sa_load_on_demand/inc/sa_load_on_demand.h b/frameworks/sdk/sa_load_on_demand/inc/sa_load_on_demand.h new file mode 100644 index 00000000..1f77edf7 --- /dev/null +++ b/frameworks/sdk/sa_load_on_demand/inc/sa_load_on_demand.h @@ -0,0 +1,51 @@ +/* + * 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 SA_LOAD_ON_DEMAND_H +#define SA_LOAD_ON_DEMAND_H + +#include +#include "device_auth.h" +#include "ipc_sdk_defines.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int32_t (*RegCallbackFunc)(const char *appId, const DeviceAuthCallback *callback, bool needCache); +typedef int32_t (*RegDataChangeListenerFunc)(const char *appId, const DataChangeListener *listener, bool needCache); +typedef int32_t (*RegCredChangeListenerFunc)(const char *appId, CredChangeListener *listener, bool needCache); + +int32_t AddCallbackInfoToList(const char *appId, const DeviceAuthCallback *callback, + const DataChangeListener *dataChangeListener, CredChangeListener *listener, int32_t callbackType); +int32_t RemoveCallbackInfoFromList(const char *appId, int32_t callbackType); + +void SetRegCallbackFunc(RegCallbackFunc regCallbackFunc); +void SetRegDataChangeListenerFunc(RegDataChangeListenerFunc regDataChangeListenerFunc); +void SetRegCredChangeListenerFunc(RegCredChangeListenerFunc regCredChangeListenerFunc); +void RegisterDevAuthCallbackIfNeed(void); + +int32_t LoadDeviceAuthSaIfNotLoad(void); +void SubscribeDeviceAuthSa(void); +void UnSubscribeDeviceAuthSa(void); + +int32_t InitLoadOnDemand(void); +void DeInitLoadOnDemand(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/frameworks/sdk/sa_load_on_demand/src/mock/sa_load_on_demand_mock.cpp b/frameworks/sdk/sa_load_on_demand/src/mock/sa_load_on_demand_mock.cpp new file mode 100644 index 00000000..4c4403df --- /dev/null +++ b/frameworks/sdk/sa_load_on_demand/src/mock/sa_load_on_demand_mock.cpp @@ -0,0 +1,68 @@ +/* + * 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 "sa_load_on_demand.h" +#include "common_defs.h" + +int32_t AddCallbackInfoToList(const char *appId, const DeviceAuthCallback *callback, + const DataChangeListener *dataChangeListener, CredChangeListener *credChangeListener, int32_t callbackType) +{ + (void)appId; + (void)callback; + (void)dataChangeListener; + (void)credChangeListener; + (void)callbackType; + return HC_ERR_NOT_SUPPORT; +} + +int32_t RemoveCallbackInfoFromList(const char *appId, int32_t callbackType) +{ + (void)appId; + (void)callbackType; + return HC_ERR_NOT_SUPPORT; +} + +void SetRegCallbackFunc(RegCallbackFunc regCallbackFunc) +{ + (void)regCallbackFunc; +} + +void SetRegDataChangeListenerFunc(RegDataChangeListenerFunc regDataChangeListenerFunc) +{ + (void)regDataChangeListenerFunc; +} + +void SetRegCredChangeListenerFunc(RegCredChangeListenerFunc regCredChangeListenerFunc) +{ + (void)regCredChangeListenerFunc; +} + +void RegisterDevAuthCallbackIfNeed(void) {} + +int32_t LoadDeviceAuthSaIfNotLoad(void) +{ + return HC_ERR_NOT_SUPPORT; +} + +void SubscribeDeviceAuthSa(void) {} + +void UnSubscribeDeviceAuthSa(void) {} + +int32_t InitLoadOnDemand(void) +{ + return HC_ERR_NOT_SUPPORT; +} + +void DeInitLoadOnDemand(void) {} diff --git a/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp b/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp new file mode 100644 index 00000000..9f670638 --- /dev/null +++ b/frameworks/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp @@ -0,0 +1,394 @@ +/* + * 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 "sa_load_on_demand.h" +#include "common_defs.h" +#include "hc_log.h" +#include "hc_types.h" +#include "iservice_registry.h" +#include "hc_vector.h" +#include "securec.h" +#include "system_ability_definition.h" +#include "parameter.h" +#include "sa_listener.h" +#include "hc_mutex.h" + +using namespace std; +using namespace OHOS; + +static sptr g_saListener = nullptr; +static HcMutex g_devAuthCallbackMutex; + +DECLARE_HC_VECTOR(DevAuthCallbackInfoVec, DevAuthCallbackInfo) +IMPLEMENT_HC_VECTOR(DevAuthCallbackInfoVec, DevAuthCallbackInfo, 1) +static DevAuthCallbackInfoVec g_devAuthCallbackList; +static bool g_devAuthSaIsActive = false; + +static RegCallbackFunc g_regCallback; +static RegDataChangeListenerFunc g_regDataChangeListener; +static RegCredChangeListenerFunc g_regCredChangeListener; + +static int32_t DoBuildDevAuthCallback(DevAuthCallbackInfo *callbackInfo, const DeviceAuthCallback *callback) +{ + DeviceAuthCallback *copyCallback = (DeviceAuthCallback *)HcMalloc(sizeof(DeviceAuthCallback), 0); + if (copyCallback == nullptr) { + LOGE("[SDK]: Failed to malloc callback memory."); + return HC_ERR_ALLOC_MEMORY; + } + if (memcpy_s(copyCallback, sizeof(DeviceAuthCallback), callback, sizeof(DeviceAuthCallback)) != HC_SUCCESS) { + LOGE("[SDK]: Failed to copy callback."); + HcFree(copyCallback); + return HC_ERR_MEMORY_COPY; + } + callbackInfo->callback.deviceAuthCallback = copyCallback; + return HC_SUCCESS; +} + +static int32_t DoBuildGroupChangeListener(DevAuthCallbackInfo *callbackInfo, + const DataChangeListener *dataChangeListener) +{ + DataChangeListener *copyListener = (DataChangeListener *)HcMalloc(sizeof(DataChangeListener), 0); + if (copyListener == nullptr) { + LOGE("[SDK]: Failed to malloc copyListener memory."); + return HC_ERR_ALLOC_MEMORY; + } + if (memcpy_s(copyListener, sizeof(DataChangeListener), dataChangeListener, sizeof(DataChangeListener)) + != HC_SUCCESS) { + LOGE("[SDK]: Failed to copy dataChangeListener."); + HcFree(copyListener); + return HC_ERR_MEMORY_COPY; + } + callbackInfo->callback.dataChangeListener = copyListener; + return HC_SUCCESS; +} + +static int32_t DoBuildCredChangeListener(DevAuthCallbackInfo *callbackInfo, + const CredChangeListener *credChangeListener) +{ + CredChangeListener *copyListener = (CredChangeListener *)HcMalloc(sizeof(CredChangeListener), 0); + if (copyListener == nullptr) { + LOGE("[SDK]: Failed to malloc credChangeListener memory."); + return HC_ERR_ALLOC_MEMORY; + } + if (memcpy_s(copyListener, sizeof(CredChangeListener), credChangeListener, sizeof(CredChangeListener)) + != HC_SUCCESS) { + LOGE("[SDK]: Failed to copy copyListener."); + HcFree(copyListener); + return HC_ERR_MEMORY_COPY; + } + callbackInfo->callback.credChangeListener = copyListener; + return HC_SUCCESS; +} + +static void FreeCallbackByType(DevAuthCallbackInfo *entry) +{ + switch (entry->callbackType) { + case DEVAUTH_CALLBACK: + HcFree(entry->callback.deviceAuthCallback); + entry->callback.deviceAuthCallback = nullptr; + break; + case GROUP_CHANGE_LISTENER: + HcFree(entry->callback.dataChangeListener); + entry->callback.dataChangeListener = nullptr; + break; + case CRED_CHANGE_LISTENER: + HcFree(entry->callback.credChangeListener); + entry->callback.credChangeListener = nullptr; + break; + default: + LOGE("invalid callback type."); + break; + } +} + +static int32_t CreateCallbackByType(DevAuthCallbackInfo *entry, const DeviceAuthCallback *callback, + const DataChangeListener *dataChangeListener, CredChangeListener *listener) +{ + int32_t ret = HC_ERR_IPC_CALLBACK_TYPE; + switch (entry->callbackType) { + case DEVAUTH_CALLBACK: + ret = DoBuildDevAuthCallback(entry, callback); + break; + case GROUP_CHANGE_LISTENER: + ret = DoBuildGroupChangeListener(entry, dataChangeListener); + break; + case CRED_CHANGE_LISTENER: + ret = DoBuildCredChangeListener(entry, listener); + break; + default: + LOGE("invalid callback type."); + break; + } + return ret; +} + +static int32_t BuildCallbackInfo(DevAuthCallbackInfo *callbackInfo, const char *appId, + const DeviceAuthCallback *callback, const DataChangeListener *dataChangeListener, CredChangeListener *listener) +{ + uint32_t appIdLen = HcStrlen(appId) + 1; + char *copyAppId = (char *)HcMalloc(appIdLen, 0); + if (copyAppId == nullptr) { + LOGE("[SDK]: Failed to malloc appId."); + return HC_ERR_ALLOC_MEMORY; + } + if (strcpy_s(copyAppId, appIdLen, appId) != HC_SUCCESS) { + LOGE("[SDK]: Failed to copy appId."); + HcFree(copyAppId); + return HC_ERR_ALLOC_MEMORY; + } + callbackInfo->appId = copyAppId; + int32_t ret = CreateCallbackByType(callbackInfo, callback, dataChangeListener, listener); + if (ret != HC_SUCCESS) { + LOGE("[SDK]: Do build callback failed."); + HcFree(copyAppId); + } + return ret; +} + +static void ClearCallbackInfo(DevAuthCallbackInfo *callbackInfo) +{ + HcFree(callbackInfo->appId); + FreeCallbackByType(callbackInfo); +} + +static bool UpdateCallback(DevAuthCallbackInfo *callbackInfo, const DeviceAuthCallback *callback, + const DataChangeListener *dataChangeListener, CredChangeListener *listener, uint32_t index) +{ + FreeCallbackByType(callbackInfo); + if (CreateCallbackByType(callbackInfo, callback, dataChangeListener, listener) != HC_SUCCESS) { + LOGE("[SDK]: Update callback failed, start to pop callback info."); + DevAuthCallbackInfo entry; + HC_VECTOR_POPELEMENT(&g_devAuthCallbackList, &entry, index); + HcFree(entry.appId); + return false; + } + return true; +} + +static bool UpdateCallbackInfoIfExist(const char *appId, const DeviceAuthCallback *callback, + const DataChangeListener *dataChangeListener, CredChangeListener *listener, int32_t callbackType) +{ + uint32_t index; + DevAuthCallbackInfo *entry = nullptr; + (void)LockHcMutex(&g_devAuthCallbackMutex); + FOR_EACH_HC_VECTOR(g_devAuthCallbackList, index, entry) { + if (entry == nullptr || entry->appId == nullptr) { + continue; + } + if (strcmp(entry->appId, appId) == 0 && entry->callbackType == callbackType) { + LOGI("[SDK]:start to update callback, appId: %" LOG_PUB "s, callbackType: %" LOG_PUB "d", + appId, callbackType); + bool ret = UpdateCallback(entry, callback, dataChangeListener, listener, index); + UnlockHcMutex(&g_devAuthCallbackMutex); + return ret; + } + } + UnlockHcMutex(&g_devAuthCallbackMutex); + return false; +} + +int32_t AddCallbackInfoToList(const char *appId, const DeviceAuthCallback *callback, + const DataChangeListener *dataChangeListener, CredChangeListener *listener, int32_t callbackType) +{ + if (UpdateCallbackInfoIfExist(appId, callback, dataChangeListener, listener, callbackType)) { + LOGI("[SDK]:Callback info exist, update successfully."); + return HC_SUCCESS; + } + DevAuthCallbackInfo callbackInfo; + callbackInfo.callbackType = callbackType; + int32_t ret = BuildCallbackInfo(&callbackInfo, appId, callback, dataChangeListener, listener); + if (ret != HC_SUCCESS) { + return ret; + } + (void)LockHcMutex(&g_devAuthCallbackMutex); + if (g_devAuthCallbackList.pushBack(&g_devAuthCallbackList, &callbackInfo) == nullptr) { + LOGE("[SDK]: Failed to add callbackInfo."); + ClearCallbackInfo(&callbackInfo); + UnlockHcMutex(&g_devAuthCallbackMutex); + return HC_ERR_ALLOC_MEMORY; + } + LOGI("[SDK]: Add callback info successfully, cache list size: %" LOG_PUB "d.", + g_devAuthCallbackList.size(&g_devAuthCallbackList)); + UnlockHcMutex(&g_devAuthCallbackMutex); + return HC_SUCCESS; +} + +int32_t RemoveCallbackInfoFromList(const char *appId, int32_t callbackType) +{ + uint32_t index; + DevAuthCallbackInfo *entry = nullptr; + int32_t ret = HC_SUCCESS; + (void)LockHcMutex(&g_devAuthCallbackMutex); + FOR_EACH_HC_VECTOR(g_devAuthCallbackList, index, entry) { + if (entry == nullptr || entry->appId == nullptr) { + continue; + } + if (strcmp(entry->appId, appId) == 0 && entry->callbackType == callbackType) { + LOGW("[SDK]: start to remove callbackInfo."); + DevAuthCallbackInfo deleteCallbackInfo; + HC_VECTOR_POPELEMENT(&g_devAuthCallbackList, &deleteCallbackInfo, index); + ClearCallbackInfo(&deleteCallbackInfo); + UnlockHcMutex(&g_devAuthCallbackMutex); + return ret; + } + } + UnlockHcMutex(&g_devAuthCallbackMutex); + return ret; +} + +static void RegisterDevAuthCallback() +{ + uint32_t index; + DevAuthCallbackInfo *callbackInfo = nullptr; + int32_t ret = HC_SUCCESS; + (void)LockHcMutex(&g_devAuthCallbackMutex); + LOGI("[SDK]: cache list size: %" LOG_PUB "d", g_devAuthCallbackList.size(&g_devAuthCallbackList)); + FOR_EACH_HC_VECTOR(g_devAuthCallbackList, index, callbackInfo) { + if (callbackInfo == nullptr || callbackInfo->appId == nullptr) { + continue; + } + switch (callbackInfo->callbackType) { + case DEVAUTH_CALLBACK: + LOGI("regCallback."); + ret = g_regCallback(callbackInfo->appId, callbackInfo->callback.deviceAuthCallback, false); + break; + case GROUP_CHANGE_LISTENER: + LOGI("regDataChangeListener."); + ret = g_regDataChangeListener(callbackInfo->appId, callbackInfo->callback.dataChangeListener, false); + break; + case CRED_CHANGE_LISTENER: + LOGI("regCredChangeListener."); + ret = g_regCredChangeListener(callbackInfo->appId, callbackInfo->callback.credChangeListener, false); + break; + default: + LOGE("invalid callback type: %" LOG_PUB "d.", callbackInfo->callbackType); + break; + } + LOGI("register result: %" LOG_PUB "d.", ret); + } + UnlockHcMutex(&g_devAuthCallbackMutex); +} + +static void OnReceivedDevAuthAdded() +{ + LOGI("SA load, need to register cache callback."); + RegisterDevAuthCallback(); + (void)LockHcMutex(&g_devAuthCallbackMutex); + g_devAuthSaIsActive = true; + UnlockHcMutex(&g_devAuthCallbackMutex); +} + +static void OnReceivedDevAuthRemoved() +{ + LOGI("SA unload."); + (void)LockHcMutex(&g_devAuthCallbackMutex); + g_devAuthSaIsActive = false; + UnlockHcMutex(&g_devAuthCallbackMutex); +} + +void SetRegCallbackFunc(RegCallbackFunc regCallbackFunc) +{ + g_regCallback = regCallbackFunc; +} + +void SetRegDataChangeListenerFunc(RegDataChangeListenerFunc regDataChangeListenerFunc) +{ + g_regDataChangeListener = regDataChangeListenerFunc; +} + +void SetRegCredChangeListenerFunc(RegCredChangeListenerFunc regCredChangeListenerFunc) +{ + g_regCredChangeListener = regCredChangeListenerFunc; +} + +void RegisterDevAuthCallbackIfNeed(void) +{ + (void)LockHcMutex(&g_devAuthCallbackMutex); + if (!g_devAuthSaIsActive) { + LOGE("[SDK]: need to register callback."); + RegisterDevAuthCallback(); + } + UnlockHcMutex(&g_devAuthCallbackMutex); +} + +int32_t LoadDeviceAuthSaIfNotLoad(void) +{ + auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saMgr == nullptr) { + LOGE("[SDK]: Get systemabilitymanager instance failed."); + return HC_ERR_IPC_GET_SAMGR_FAILED; + } + auto deviceAuthSa = saMgr->CheckSystemAbility(DEVICE_AUTH_SERVICE_ID); + if (deviceAuthSa != nullptr) { + return HC_SUCCESS; + } + deviceAuthSa = saMgr->LoadSystemAbility(DEVICE_AUTH_SERVICE_ID, DEVICE_AUTH_SA_LOAD_TIME); + if (deviceAuthSa == nullptr) { + LOGE("[SDK]: SaMgr load device auth sa failed, reason is loading timeout probably."); + return HC_ERR_IPC_LOAD_SA_FAILED; + } + return HC_SUCCESS; +} + +void SubscribeDeviceAuthSa(void) +{ + auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saMgr == nullptr) { + LOGE("[SDK]: Get systemabilitymanager instance failed."); + return; + } + + SaStatusChangeCallback statusChangeCallback; + statusChangeCallback.onReceivedSaAdd = OnReceivedDevAuthAdded; + statusChangeCallback.onReceivedSaRemoved = OnReceivedDevAuthRemoved; + if (g_saListener == nullptr) { + g_saListener = new DevAuth::SaListener(statusChangeCallback); + } + if (saMgr->SubscribeSystemAbility(DEVICE_AUTH_SERVICE_ID, g_saListener) == OHOS::ERR_OK) { + LOGI("[SDK]: Subscribe device auth sa successfully."); + } else { + LOGE("[SDK]: Subscribe device auth sa failed."); + } +} + +void UnSubscribeDeviceAuthSa(void) +{ + auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saMgr == nullptr) { + LOGE("[SDK]: Get systemabilitymanager instance failed."); + return; + } + if (saMgr->UnSubscribeSystemAbility(DEVICE_AUTH_SERVICE_ID, g_saListener) == OHOS::ERR_OK) { + LOGI("[SDK]: UnSubscribe device auth sa successfully."); + } else { + LOGE("[SDK]: UnSubscribe device auth sa failed."); + } +} + +int32_t InitLoadOnDemand(void) +{ + int32_t ret = InitHcMutex(&g_devAuthCallbackMutex, false); + if (ret != HC_SUCCESS) { + return ret; + } + g_devAuthCallbackList = CREATE_HC_VECTOR(DevAuthCallbackInfoVec); + return HC_SUCCESS; +} + +void DeInitLoadOnDemand(void) +{ + DESTROY_HC_VECTOR(DevAuthCallbackInfoVec, &g_devAuthCallbackList); + DestroyHcMutex(&g_devAuthCallbackMutex); +} \ No newline at end of file diff --git a/frameworks/src/deviceauth_sa.cpp b/frameworks/src/deviceauth_sa.cpp index d30e1ee6..cc4bf688 100644 --- a/frameworks/src/deviceauth_sa.cpp +++ b/frameworks/src/deviceauth_sa.cpp @@ -28,16 +28,25 @@ #include "hidump_adapter.h" #include "string_ex.h" #include "ipc_service_common.h" +#include "event_runner.h" #include "deviceauth_sa.h" +#include "iservice_registry.h" +#include "dev_session_mgr.h" +#include "critical_handler.h" #ifdef DEV_AUTH_USE_JEMALLOC #include "malloc.h" #endif namespace OHOS { - -static const uint32_t RESTORE_CODE = 14701; +namespace { + const uint32_t RESTORE_CODE = 14701; + const std::string DEVAUTH_UNLOAD_SA_HANDLER = "devauth_unload_sa_handler"; + const std::string DEVAUTH_UNLOAD_TASK_ID = "devauth_unload_task"; + const int32_t DEVAUTH_LIFE_TIME = 90000; // 90 * 1000 + const int32_t SA_REFUSE_TO_UNLOAD = -1; +} using IpcCallMap = struct { int32_t (*func)(const IpcDataInfo*, int32_t, uintptr_t); uint32_t id; @@ -94,10 +103,7 @@ static IpcCallMap g_ipcCallMaps[] = { REGISTER_SYSTEM_ABILITY_BY_ID(DeviceAuthAbility, SA_ID_DEVAUTH_SERVICE, true); -std::mutex DeviceAuthAbility::g_instanceLock; -sptr DeviceAuthAbility::g_instance; - -DeviceAuthAbility::DeviceAuthAbility(int saId, bool runOnCreate = true) : SystemAbility(saId, runOnCreate) +DeviceAuthAbility::DeviceAuthAbility(int saId, bool runOnCreate) : SystemAbility(saId, runOnCreate) { LOGI("DeviceAuthAbility"); } @@ -127,23 +133,58 @@ static int32_t SaAddMethodMap(uintptr_t ipcInstance) return ret; } -sptr DeviceAuthAbility::GetInstance() +bool DeviceAuthAbility::CreateUnloadHandler() { - std::lock_guard autoLock(g_instanceLock); - if (g_instance == nullptr) { - g_instance = new (std::nothrow) DeviceAuthAbility(SA_ID_DEVAUTH_SERVICE, true); + std::lock_guard lock(instanceMutex_); + if (unloadHandler_ != nullptr) { + return true; } - return g_instance; + auto unloadRunner = AppExecFwk::EventRunner::Create(DEVAUTH_UNLOAD_SA_HANDLER); + if (unloadRunner == nullptr) { + LOGE("Create unloadRunner failed."); + return false; + } + unloadHandler_ = std::make_shared(unloadRunner); + if (unloadHandler_ == nullptr) { + LOGE("Create unloadHandler failed."); + return false; + } + return true; } -void DeviceAuthAbility::DestroyInstance() +void DeviceAuthAbility::DestroyUnloadHandler() { - std::lock_guard autoLock(g_instanceLock); - if (g_instance != nullptr) { - delete g_instance; - g_instance = nullptr; + std::lock_guard lock(instanceMutex_); + if (unloadHandler_ == nullptr) { + LOGE("unloadHandler is nullptr."); + return; } - LOGI("DeviceAuthAbility DestroyInstance done"); + unloadHandler_->RemoveTask(DEVAUTH_UNLOAD_TASK_ID); + unloadHandler_ = nullptr; +} + +void DeviceAuthAbility::DelayUnload() +{ + if (!CreateUnloadHandler()) { + LOGE("UnloadHandler is nullptr."); + return; + } + auto utask = []() { + LOGI("The Service starts unloading."); + auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saMgr == nullptr) { + LOGE("Get systemabilitymanager instance failed."); + return; + } + int32_t ret = saMgr->UnloadSystemAbility(DEVICE_AUTH_SERVICE_ID); + if (ret != ERR_OK) { + LOGE("Unload system ability failed."); + return; + } + LOGI("Service unloaded successfully."); + }; + unloadHandler_->RemoveTask(DEVAUTH_UNLOAD_TASK_ID); + unloadHandler_->PostTask(utask, DEVAUTH_UNLOAD_TASK_ID, DEVAUTH_LIFE_TIME); } int32_t DeviceAuthAbility::Dump(int32_t fd, const std::vector &args) @@ -187,27 +228,19 @@ void DeviceAuthAbility::OnStart() return; } - sptr serviceInstance = DeviceAuthAbility::GetInstance(); - if (serviceInstance == nullptr) { - LOGE("DeviceAuthAbility GetInstance Failed"); - DeMainRescInit(); - DestroyDeviceAuthService(); - return; - } - - uintptr_t serviceInstanceAddress = reinterpret_cast(serviceInstance.GetRefPtr()); + uintptr_t serviceInstanceAddress = reinterpret_cast(this); ret = SaAddMethodMap(serviceInstanceAddress); if (ret != HC_SUCCESS) { LOGW("DeviceAuthAbility SaAddMethodMap failed at least once."); } - - if (!Publish(serviceInstance)) { + if (!Publish(this)) { LOGE("DeviceAuthAbility Publish failed"); - DeviceAuthAbility::DestroyInstance(); DeMainRescInit(); DestroyDeviceAuthService(); return; } + AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); + DelayUnload(); LOGI("DeviceAuthAbility start success."); } @@ -219,9 +252,31 @@ static void DevAuthInitMemoryPolicy(void) #endif } +bool DeviceAuthAbility::CheckUnloadStatus() +{ + if (GetCriticalCnt() > 0) { + return false; + } + return true; +} + +bool DeviceAuthAbility::CheckDevAuthStatus() +{ + std::lock_guard lock(instanceMutex_); + if (isUnloading_) { + LOGW("sa is unloading, need to retry."); + return true; + } + return false; +} + int32_t DeviceAuthAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + DelayUnload(); + if (CheckDevAuthStatus()) { + return HC_ERR_IPC_SA_IS_UNLOADING; + } DevAuthInitMemoryPolicy(); std::u16string readToken = data.ReadInterfaceToken(); @@ -230,19 +285,57 @@ int32_t DeviceAuthAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, M LOGE("DeviceAuthAbility [IPC][C->S]: The proxy interface token is invalid!"); return -1; } + int32_t ret; + IncreaseCriticalCnt(ADD_ONE); if (isRestoreCall) { - return HandleRestoreCall(data, reply); + ret = HandleRestoreCall(data, reply); } else { - return HandleDeviceAuthCall(code, data, reply, option); + ret = HandleDeviceAuthCall(code, data, reply, option); } + DecreaseCriticalCnt(); + return ret; +} + +void DeviceAuthAbility::OnActive(const SystemAbilityOnDemandReason &activeReason) +{ + std::lock_guard lock(instanceMutex_); + LOGI("OnActive, activeReason name is %" LOG_PUB "s, isUnloading is %" LOG_PUB "d.", + activeReason.GetName().c_str(), isUnloading_); + isUnloading_ = false; +} + +int32_t DeviceAuthAbility::OnIdle(const SystemAbilityOnDemandReason &idleReason) +{ + std::lock_guard lock(instanceMutex_); + isUnloading_ = CheckUnloadStatus(); + LOGI("OnIdle, idleReason name is %" LOG_PUB "s, isUnloading is %" LOG_PUB "d.", + idleReason.GetName().c_str(), isUnloading_); + if (isUnloading_) { + return HC_SUCCESS; + } + return SA_REFUSE_TO_UNLOAD; } void DeviceAuthAbility::OnStop() { LOGI("DeviceAuthAbility OnStop"); - DeviceAuthAbility::DestroyInstance(); + RemoveTimeoutSession(); DeMainRescInit(); DestroyDeviceAuthService(); + NotifyProcessIsStop(); +} + +void DeviceAuthAbility::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{ + LOGI("OnAddSystemAbility systemAbilityId: %" LOG_PUB "d add.", systemAbilityId); + if (systemAbilityId == MEMORY_MANAGER_SA_ID) { + NotifyProcessIsActive(); + } +} + +void DeviceAuthAbility::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{ + LOGI("OnRemoveSystemAbility systemAbilityId: %" LOG_PUB "d add.", systemAbilityId); } } // namespace OHOS \ No newline at end of file diff --git a/frameworks/src/identity_service_ipc_sdk.c b/frameworks/src/identity_service_ipc_sdk.c index 7fb393e0..6f5931f1 100644 --- a/frameworks/src/identity_service_ipc_sdk.c +++ b/frameworks/src/identity_service_ipc_sdk.c @@ -20,6 +20,7 @@ #include "device_auth.h" #include "hc_log.h" #include "hc_mutex.h" +#include "sa_load_on_demand.h" #include "ipc_sdk_defines.h" #include "ipc_adapt.h" @@ -121,6 +122,8 @@ static void GetIpcReplyByType(const IpcDataInfo *ipcData, static int32_t IpcCmAddCredential(int32_t osAccountId, const char *requestParams, char **returnData) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -148,7 +151,7 @@ static int32_t IpcCmAddCredential(int32_t osAccountId, const char *requestParams return ret; } -static int32_t IpcCmRegChangeListener(const char *appId, CredChangeListener *listener) +static int32_t IpcCmRegChangeListenerInner(const char *appId, CredChangeListener *listener, bool needCache) { LOGI("starting ..."); uintptr_t callCtx = 0x0; @@ -166,14 +169,24 @@ static int32_t IpcCmRegChangeListener(const char *appId, CredChangeListener *lis DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); BREAK_IF_CHECK_IPC_RESULT_FAILED(replyCache, ret); AddIpcCliCallbackCtx(appId, 0, &g_ipcCredListenerCbList); + if (needCache) { + ret = AddCallbackInfoToList(appId, NULL, NULL, listener, CRED_CHANGE_LISTENER); + } } while (0); DESTROY_IPC_CTX(callCtx); LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } +static int32_t IpcCmRegChangeListener(const char *appId, CredChangeListener *listener) +{ + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + return IpcCmRegChangeListenerInner(appId, listener, true); +} + static int32_t IpcCmUnRegChangeListener(const char *appId) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -188,6 +201,7 @@ static int32_t IpcCmUnRegChangeListener(const char *appId) DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); BREAK_IF_CHECK_IPC_RESULT_FAILED(replyCache, ret); DelIpcCliCallbackCtx(appId, &g_ipcCredListenerCbList); + ret = RemoveCallbackInfoFromList(appId, CRED_CHANGE_LISTENER); } while (0); DESTROY_IPC_CTX(callCtx); @@ -197,6 +211,8 @@ static int32_t IpcCmUnRegChangeListener(const char *appId) static int32_t IpcCmExportCredential(int32_t osAccountId, const char *credId, char **returnData) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -227,6 +243,8 @@ static int32_t IpcCmExportCredential(int32_t osAccountId, const char *credId, ch static int32_t IpcCmQueryCredByParams(int32_t osAccountId, const char *requestParams, char **returnCredList) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; @@ -257,6 +275,8 @@ static int32_t IpcCmQueryCredByParams(int32_t osAccountId, const char *requestPa static int32_t IpcCmQueryCredInfoByCredId(int32_t osAccountId, const char *credId, char **returnCredInfo) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; @@ -288,6 +308,8 @@ static int32_t IpcCmQueryCredInfoByCredId(int32_t osAccountId, const char *credI static int32_t IpcCmDeleteCredential(int32_t osAccountId, const char *credId) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -311,6 +333,8 @@ static int32_t IpcCmDeleteCredential(int32_t osAccountId, const char *credId) static int32_t IpcCmUpdateCredInfo(int32_t osAccountId, const char *credId, const char *requestParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -336,6 +360,8 @@ static int32_t IpcCmUpdateCredInfo(int32_t osAccountId, const char *credId, cons static int32_t IpcCmAgreeCredential(int32_t osAccountId, const char *selfCredId, const char *requestParams, char **returnData) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -369,6 +395,8 @@ static int32_t IpcCmAgreeCredential(int32_t osAccountId, const char *selfCredId, static int32_t IpcCmDelCredByParams(int32_t osAccountId, const char *requestParams, char **returnData) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -400,6 +428,8 @@ static int32_t IpcCmDelCredByParams(int32_t osAccountId, const char *requestPara static int32_t IpcCmBatchUpdateCredentials(int32_t osAccountId, const char *requestParams, char **returnData) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -442,6 +472,7 @@ static bool IsJsonString(const char *str) static void IpcCmDestroyInfo(char **returnData) { + RETURN_VOID_IF_LOAD_DEVAUTH_FAILED(); if (returnData == NULL || *returnData == NULL) { return; } @@ -473,6 +504,8 @@ static void InitIpcCmMethods(CredManager *cmMethodObj) static int32_t IpcCmAuthCredential(int32_t osAccountId, int64_t authReqId, const char *authParams, const DeviceAuthCallback *caCallback) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -499,6 +532,8 @@ static int32_t IpcCmAuthCredential(int32_t osAccountId, int64_t authReqId, const static int32_t IpcCmProcessCredData(int64_t authReqId, const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -529,7 +564,12 @@ static void InitIpcCaMethods(CredAuthManager *caMethodObj) int32_t InitISIpc(void) { - return InitHcMutex(&g_ipcMutex, false); + int32_t ret = InitHcMutex(&g_ipcMutex, false); + if (ret != IS_SUCCESS) { + return ret; + } + SetRegCredChangeListenerFunc(IpcCmRegChangeListenerInner); + return IS_SUCCESS; } void DeInitISIpc(void) @@ -539,6 +579,7 @@ void DeInitISIpc(void) DEVICE_AUTH_API_PUBLIC const CredManager *GetCredMgrInstance(void) { + RETURN_NULL_IF_LOAD_DEVAUTH_FAILED(); static CredManager cmInstCtx; static CredManager *cmInstPtr = NULL; @@ -551,6 +592,7 @@ DEVICE_AUTH_API_PUBLIC const CredManager *GetCredMgrInstance(void) DEVICE_AUTH_API_PUBLIC const CredAuthManager *GetCredAuthInstance(void) { + RETURN_NULL_IF_LOAD_DEVAUTH_FAILED(); static CredAuthManager caInstCtx; static CredAuthManager *caInstPtr = NULL; diff --git a/frameworks/src/ipc_sdk.c b/frameworks/src/ipc_sdk.c index 7c4b4b04..563bffcc 100644 --- a/frameworks/src/ipc_sdk.c +++ b/frameworks/src/ipc_sdk.c @@ -26,6 +26,7 @@ #include "ipc_adapt.h" #include "securec.h" +#include "sa_load_on_demand.h" #ifdef __cplusplus extern "C" { @@ -133,9 +134,8 @@ static void GetIpcReplyByType(const IpcDataInfo *ipcData, return; } -static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *callback) +static int32_t IpcGmRegCallbackInner(const char *appId, const DeviceAuthCallback *callback, bool needCache) { - LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; @@ -151,6 +151,9 @@ static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *cal DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); BREAK_IF_CHECK_IPC_RESULT_FAILED(replyCache, ret); AddIpcCliCallbackCtx(appId, 0, &g_ipcProxyCbList); + if (needCache) { + ret = AddCallbackInfoToList(appId, callback, NULL, NULL, DEVAUTH_CALLBACK); + } } while (0); DESTROY_IPC_CTX(callCtx); @@ -158,8 +161,16 @@ static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *cal return ret; } +static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *callback) +{ + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + LOGI("starting ..."); + return IpcGmRegCallbackInner(appId, callback, true); +} + static int32_t IpcGmUnRegCallback(const char *appId) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); uintptr_t callCtx = 0x0; IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; int32_t inOutLen; @@ -174,6 +185,7 @@ static int32_t IpcGmUnRegCallback(const char *appId) DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); BREAK_IF_CHECK_IPC_RESULT_FAILED(replyCache, ret); DelIpcCliCallbackCtx(appId, &g_ipcProxyCbList); + ret = RemoveCallbackInfoFromList(appId, DEVAUTH_CALLBACK); } while (0); DESTROY_IPC_CTX(callCtx); @@ -181,9 +193,8 @@ static int32_t IpcGmUnRegCallback(const char *appId) return ret; } -static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeListener *listener) +static int32_t IpcGmRegDataChangeListenerInner(const char *appId, const DataChangeListener *listener, bool needCache) { - LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; @@ -199,6 +210,9 @@ static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeLis DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); BREAK_IF_CHECK_IPC_RESULT_FAILED(replyCache, ret); AddIpcCliCallbackCtx(appId, 0, &g_ipcListenerCbList); + if (needCache) { + ret = AddCallbackInfoToList(appId, NULL, listener, NULL, GROUP_CHANGE_LISTENER); + } } while (0); DESTROY_IPC_CTX(callCtx); @@ -206,8 +220,16 @@ static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeLis return ret; } +static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeListener *listener) +{ + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + LOGI("starting ..."); + return IpcGmRegDataChangeListenerInner(appId, listener, true); +} + static int32_t IpcGmUnRegDataChangeListener(const char *appId) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -222,6 +244,7 @@ static int32_t IpcGmUnRegDataChangeListener(const char *appId) DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); BREAK_IF_CHECK_IPC_RESULT_FAILED(replyCache, ret); DelIpcCliCallbackCtx(appId, &g_ipcListenerCbList); + ret = RemoveCallbackInfoFromList(appId, GROUP_CHANGE_LISTENER); } while (0); DESTROY_IPC_CTX(callCtx); @@ -231,6 +254,8 @@ static int32_t IpcGmUnRegDataChangeListener(const char *appId) static int32_t IpcGmCreateGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -256,6 +281,8 @@ static int32_t IpcGmCreateGroup(int32_t osAccountId, int64_t requestId, const ch static int32_t IpcGmDeleteGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; @@ -281,6 +308,8 @@ static int32_t IpcGmDeleteGroup(int32_t osAccountId, int64_t requestId, const ch static int32_t IpcGmAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -306,6 +335,8 @@ static int32_t IpcGmAddMemberToGroup(int32_t osAccountId, int64_t requestId, con static int32_t IpcGmDelMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -331,6 +362,8 @@ static int32_t IpcGmDelMemberFromGroup(int32_t osAccountId, int64_t requestId, c static int32_t IpcGmAddMultiMembersToGroup(int32_t osAccountId, const char *appId, const char *addParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); int32_t ret; uintptr_t callCtx = 0x0; @@ -355,6 +388,8 @@ static int32_t IpcGmAddMultiMembersToGroup(int32_t osAccountId, const char *appI static int32_t IpcGmDelMultiMembersFromGroup(int32_t osAccountId, const char *appId, const char *delParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); int32_t ret; uintptr_t callCtx = 0x0; @@ -379,6 +414,8 @@ static int32_t IpcGmDelMultiMembersFromGroup(int32_t osAccountId, const char *ap static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t dataLen) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -402,6 +439,7 @@ static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t static int32_t IpcGmGetRegisterInfo(const char *reqJsonStr, char **registerInfo) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); LOGI("starting ..."); int32_t ret; uintptr_t callCtx = 0x0; @@ -431,6 +469,8 @@ static int32_t IpcGmGetRegisterInfo(const char *reqJsonStr, char **registerInfo) static int32_t IpcGmCheckAccessToGroup(int32_t osAccountId, const char *appId, const char *groupId) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); uintptr_t callCtx = 0x0; int32_t ret; int32_t inOutLen; @@ -454,6 +494,8 @@ static int32_t IpcGmCheckAccessToGroup(int32_t osAccountId, const char *appId, c static int32_t IpcGmGetPkInfoList(int32_t osAccountId, const char *appId, const char *queryParams, char **returnInfoList, uint32_t *returnInfoNum) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); uintptr_t callCtx = 0x0; int32_t ret; int32_t inOutLen; @@ -486,6 +528,8 @@ static int32_t IpcGmGetPkInfoList(int32_t osAccountId, const char *appId, const static int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId, char **outGroupInfo) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; @@ -516,6 +560,8 @@ static int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, con static int32_t IpcGmGetGroupInfo(int32_t osAccountId, const char *appId, const char *queryParams, char **outGroupVec, uint32_t *groupNum) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; @@ -549,6 +595,7 @@ static int32_t IpcGmGetGroupInfo(int32_t osAccountId, const char *appId, const c static int32_t IpcGmGetJoinedGroups(int32_t osAccountId, const char *appId, int32_t groupType, char **outGroupVec, uint32_t *groupNum) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; @@ -581,6 +628,7 @@ static int32_t IpcGmGetJoinedGroups(int32_t osAccountId, const char *appId, int3 static int32_t IpcGmGetRelatedGroups(int32_t osAccountId, const char *appId, const char *peerUdid, char **outGroupVec, uint32_t *groupNum) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); uintptr_t callCtx = 0x0; int32_t ret; int32_t inOutLen; @@ -614,6 +662,7 @@ static int32_t IpcGmGetRelatedGroups(int32_t osAccountId, const char *appId, con static int32_t IpcGmGetDeviceInfoById(int32_t osAccountId, const char *appId, const char *peerUdid, const char *groupId, char **outDevInfo) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); uintptr_t callCtx = 0x0; int32_t ret; int32_t inOutLen; @@ -646,6 +695,7 @@ static int32_t IpcGmGetDeviceInfoById(int32_t osAccountId, const char *appId, co static int32_t IpcGmGetTrustedDevices(int32_t osAccountId, const char *appId, const char *groupId, char **outDevInfoVec, uint32_t *deviceNum) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; @@ -678,6 +728,7 @@ static int32_t IpcGmGetTrustedDevices(int32_t osAccountId, const char *appId, static bool IpcGmIsDeviceInGroup(int32_t osAccountId, const char *appId, const char *groupId, const char *udid) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; @@ -701,6 +752,7 @@ static bool IpcGmIsDeviceInGroup(int32_t osAccountId, const char *appId, const c static void IpcGmDestroyInfo(char **returnInfo) { + RETURN_VOID_IF_LOAD_DEVAUTH_FAILED(); if ((returnInfo == NULL) || (*returnInfo == NULL)) { return; } @@ -710,6 +762,8 @@ static void IpcGmDestroyInfo(char **returnInfo) static void IpcGmCancelRequest(int64_t requestId, const char *appId) { + RETURN_VOID_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -757,6 +811,7 @@ static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj) static int32_t IpcGaProcessData(int64_t authReqId, const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -783,6 +838,7 @@ static int32_t IpcGaProcessData(int64_t authReqId, static int32_t IpcGaAuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); LOGI("starting ..."); int32_t ret; int32_t inOutLen; @@ -809,6 +865,8 @@ static int32_t IpcGaAuthDevice(int32_t osAccountId, int64_t authReqId, const cha static void IpcGaCancelRequest(int64_t requestId, const char *appId) { + RETURN_VOID_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -827,6 +885,8 @@ static void IpcGaCancelRequest(int64_t requestId, const char *appId) static int32_t IpcGaGetRealInfo(int32_t osAccountId, const char *pseudonymId, char **realInfo) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); uintptr_t callCtx = 0x0; int32_t ret; int32_t inOutLen; @@ -854,6 +914,8 @@ static int32_t IpcGaGetRealInfo(int32_t osAccountId, const char *pseudonymId, ch static int32_t IpcGaGetPseudonymId(int32_t osAccountId, const char *indexKey, char **pseudonymId) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; @@ -925,6 +987,7 @@ static int32_t SetReturnRandom(const uint8_t *randomVal, uint32_t randomLen, Dat static void IpcAvDestroyDataBuff(DataBuff *dataBuff) { + RETURN_VOID_IF_LOAD_DEVAUTH_FAILED(); if (dataBuff == NULL || dataBuff->data == NULL) { return; } @@ -980,6 +1043,8 @@ static int32_t GetSharedKeyAndRandom(const IpcDataInfo *replies, int32_t cacheNu static int32_t IpcAvGetClientSharedKey(const char *peerPkWithSig, const char *serviceId, DataBuff *returnSharedKey, DataBuff *returnRandom) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); if ((peerPkWithSig == NULL) || (serviceId == NULL) || (returnSharedKey == NULL) || (returnRandom == NULL)) { LOGE("Error occurs, params invalid."); return HC_ERR_INVALID_PARAMS; @@ -1050,6 +1115,7 @@ static int32_t GetSharedKey(const IpcDataInfo *replies, int32_t cacheNum, DataBu static int32_t IpcAvGetServerSharedKey(const char *peerPkWithSig, const char *serviceId, const DataBuff *random, DataBuff *returnSharedKey) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); if ((peerPkWithSig == NULL) || (serviceId == NULL) || (random == NULL) || (random->data == NULL) || (returnSharedKey == NULL)) { LOGE("Invalid params."); @@ -1108,6 +1174,8 @@ static void InitIpcAccountVerifierMethods(AccountVerifier *accountVerifier) DEVICE_AUTH_API_PUBLIC int32_t ProcessCredential(int32_t operationCode, const char *reqJsonStr, char **returnData) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); uintptr_t callCtx = 0x0; int32_t ret; @@ -1138,6 +1206,8 @@ DEVICE_AUTH_API_PUBLIC int32_t ProcessCredential(int32_t operationCode, const ch DEVICE_AUTH_API_PUBLIC int32_t ProcessAuthDevice( int64_t requestId, const char *authParams, const DeviceAuthCallback *callback) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); int32_t ret; uintptr_t callCtx = 0x0; @@ -1164,6 +1234,8 @@ DEVICE_AUTH_API_PUBLIC int32_t ProcessAuthDevice( DEVICE_AUTH_API_PUBLIC int32_t StartAuthDevice( int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); int32_t ret; uintptr_t callCtx = 0x0; @@ -1189,6 +1261,8 @@ DEVICE_AUTH_API_PUBLIC int32_t StartAuthDevice( DEVICE_AUTH_API_PUBLIC int32_t CancelAuthRequest(int64_t requestId, const char *authParams) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); + RegisterDevAuthCallbackIfNeed(); LOGI("starting ..."); int32_t ret; uintptr_t callCtx = 0x0; @@ -1212,39 +1286,53 @@ DEVICE_AUTH_API_PUBLIC int32_t CancelAuthRequest(int64_t requestId, const char * DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) { + RETURN_ERROR_CODE_IF_LOAD_DEVAUTH_FAILED(); if (g_devAuthServiceStatus == true) { - LOGI("device auth service already init"); + LOGI("device auth sdk already init"); return HC_SUCCESS; } int32_t ret = InitHcMutex(&g_ipcMutex, false); if (ret != HC_SUCCESS) { return ret; } + ret = InitLoadOnDemand(); + if (ret != HC_SUCCESS) { + DestroyHcMutex(&g_ipcMutex); + return ret; + } ret = InitISIpc(); if (ret != HC_SUCCESS) { + DeInitLoadOnDemand(); DestroyHcMutex(&g_ipcMutex); return ret; } ret = InitProxyAdapt(); if (ret != HC_SUCCESS) { DeInitISIpc(); + DeInitLoadOnDemand(); DestroyHcMutex(&g_ipcMutex); return ret; } g_devAuthServiceStatus = true; + SetRegCallbackFunc(IpcGmRegCallbackInner); + SetRegDataChangeListenerFunc(IpcGmRegDataChangeListenerInner); + SubscribeDeviceAuthSa(); return HC_SUCCESS; } DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void) { + UnSubscribeDeviceAuthSa(); UnInitProxyAdapt(); DeInitISIpc(); + DeInitLoadOnDemand(); DestroyHcMutex(&g_ipcMutex); g_devAuthServiceStatus = false; } DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void) { + RETURN_NULL_IF_LOAD_DEVAUTH_FAILED(); static GroupAuthManager gaInstCtx; static GroupAuthManager *gaInstPtr = NULL; @@ -1257,6 +1345,7 @@ DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void) DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void) { + RETURN_NULL_IF_LOAD_DEVAUTH_FAILED(); static DeviceGroupManager gmInstCtx; static DeviceGroupManager *gmInstPtr = NULL; @@ -1269,6 +1358,7 @@ DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void) DEVICE_AUTH_API_PUBLIC const AccountVerifier *GetAccountVerifierInstance(void) { + RETURN_NULL_IF_LOAD_DEVAUTH_FAILED(); static AccountVerifier avInstCtx; static AccountVerifier *avInstPtr = NULL; InitIpcAccountVerifierMethods(&avInstCtx); diff --git a/frameworks/src/ipc_service_common.c b/frameworks/src/ipc_service_common.c index 1edb6323..fe6c7a82 100644 --- a/frameworks/src/ipc_service_common.c +++ b/frameworks/src/ipc_service_common.c @@ -183,7 +183,7 @@ int32_t IpcServiceGmRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t static int32_t registered = 0; int32_t cbObjIdx = -1; int32_t inOutLen; - + LOGI("starting ..."); ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL); if (ret != HC_SUCCESS) { LOGE("IpcServiceGmRegDataChangeListener failed, get app id error."); diff --git a/frameworks/src/standard/ipc_dev_auth_proxy.cpp b/frameworks/src/standard/ipc_dev_auth_proxy.cpp index bcac62aa..9589a4a0 100644 --- a/frameworks/src/standard/ipc_dev_auth_proxy.cpp +++ b/frameworks/src/standard/ipc_dev_auth_proxy.cpp @@ -29,6 +29,19 @@ ProxyDevAuth::ProxyDevAuth(const sptr &impl) : IRemoteProxyLoadSystemAbility(DEVICE_AUTH_SERVICE_ID, DEVICE_AUTH_SA_LOAD_TIME); + if (deviceAuthSa == nullptr) { + LOGE("Retry load device auth sa failed."); + } +} + int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &replyParcel, bool withSync) { int32_t ret; @@ -46,6 +59,12 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re } ret = remote->SendRequest(static_cast(DevAuthInterfaceCode::DEV_AUTH_CALL_REQUEST), dataParcel, replyParcel, option); + if (ret == HC_ERR_IPC_SA_IS_UNLOADING) { + LOGI("Try to retry load device auth sa, and send request again, %" LOG_PUB "d.", ret); + RetryLoadDeviceAuthSa(); + ret = remote->SendRequest(static_cast(DevAuthInterfaceCode::DEV_AUTH_CALL_REQUEST), + dataParcel, replyParcel, option); + } if (ret != ERR_NONE) { LOGE("ProxyDevAuth::DoCallRequest SendRequest fail. ret = %" LOG_PUB "d", ret); ret = HC_ERR_IPC_INTERNAL_FAILED; diff --git a/interfaces/inner_api/device_auth_defines.h b/interfaces/inner_api/device_auth_defines.h index 27755064..c9bbc134 100644 --- a/interfaces/inner_api/device_auth_defines.h +++ b/interfaces/inner_api/device_auth_defines.h @@ -76,6 +76,11 @@ enum { HC_ERR_IPC_BAD_PARAM = 0x00003011, // 12305 HC_ERR_IPC_SERVICE_DIED = 0x00003012, // 12306 HC_ERR_IPC_PERMISSION_DENIED = 0x00003013, // 12307 + HC_ERR_IPC_CALLBACK_TYPE = 0x00003014, // 12308 + HC_ERR_IPC_SA_NOT_LOAD = 0x00003015, // 12309 + HC_ERR_IPC_GET_SAMGR_FAILED = 0x00003016, // 12310 + HC_ERR_IPC_LOAD_SA_FAILED = 0x00003017, // 12311 + HC_ERR_IPC_SA_IS_UNLOADING = 0x00003018, // 12312 /* error code for module , 0x00004000 ~ 0x00004FFF */ HC_ERR_MODULE_NOT_FOUNT = 0x00004001, // 16385 diff --git a/services/BUILD.gn b/services/BUILD.gn index ec80585f..b92edf99 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -30,8 +30,12 @@ if (os_level == "mini" || os_level == "small") { "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "${dev_frameworks_path}/inc/hiview_adapter", + "${services_path}/sa/inc/critical_handler", + "${services_path}/sa/inc/cache_common_event_handler", ] sources = deviceauth_files + sources += critical_handler_mock_files + sources += cache_common_event_handler_mock_files sources += identity_service_mock_files defines = [ "HILOG_ENABLE" ] defines += deviceauth_defines @@ -142,12 +146,14 @@ if (os_level == "mini" || os_level == "small") { "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr", "${dev_frameworks_path}/inc/hiview_adapter", + "${frameworks_path}/sdk/sa_load_on_demand/inc", ] sources = deviceauth_ipc_files sources += [ "${frameworks_path}/src/ipc_sdk.c" ] sources += [ "${frameworks_path}/src/mock/identity_service_ipc_sdk_mock.c" ] + sources += [ "${frameworks_path}/sdk/sa_load_on_demand/src/mock/sa_load_on_demand_mock.cpp" ] defines = [ "HILOG_ENABLE" ] if (ohos_kernel_type == "linux") { @@ -173,6 +179,8 @@ if (os_level == "mini" || os_level == "small") { include_dirs += [ "${frameworks_path}/inc/standard", "${dev_frameworks_path}/inc/hiview_adapter", + "${services_path}/sa/inc/cache_common_event_handler", + "${services_path}/sa/inc/critical_handler", "${dev_frameworks_path}/inc/permission_adapter", ] @@ -188,6 +196,7 @@ if (os_level == "mini" || os_level == "small") { sources += sa_subscriber_files sources += net_observer_files } + sources += sa_load_on_demand_files sources += permission_adapter_files sources += identity_service_files sources += hiview_adapter_files @@ -236,6 +245,7 @@ if (os_level == "mini" || os_level == "small") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "memmgr:memmgrclient", ] if (support_os_account) { external_deps += [ @@ -266,6 +276,8 @@ if (os_level == "mini" || os_level == "small") { include_dirs += [ "${frameworks_path}/inc/standard", + "${frameworks_path}/sdk/sa_listener/inc", + "${frameworks_path}/sdk/sa_load_on_demand/inc", "${dev_frameworks_path}/inc/permission_adapter", "${dev_frameworks_path}/inc/hiview_adapter", ] @@ -274,6 +286,8 @@ if (os_level == "mini" || os_level == "small") { sources += permission_adapter_files sources += [ "${frameworks_path}/src/ipc_sdk.c" ] sources += [ "${frameworks_path}/src/identity_service_ipc_sdk.c" ] + sources += [ "${frameworks_path}/sdk/sa_listener/src/sa_listener.cpp" ] + sources += [ "${frameworks_path}/sdk/sa_load_on_demand/src/sa_load_on_demand.cpp" ] defines = [ "__LINUX__", @@ -372,6 +386,7 @@ if (os_level == "mini" || os_level == "small") { "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "eventhandler:libeventhandler", ] } } diff --git a/services/device_auth.c b/services/device_auth.c index 0543433f..bd37c3f6 100644 --- a/services/device_auth.c +++ b/services/device_auth.c @@ -47,6 +47,7 @@ #include "cred_session_util.h" #include "credential_data_manager.h" #include "identity_service_defines.h" +#include "cache_common_event_handler.h" static GroupAuthManager *g_groupAuthManager = NULL; static DeviceGroupManager *g_groupManagerInstance = NULL; @@ -1005,6 +1006,7 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) InitPseudonymModule(); InitAccountTaskManager(); SetInitStatus(); + HandleCacheCommonEvent(); LOGI("[End]: [Service]: Init device auth service successfully!"); return HC_SUCCESS; } diff --git a/services/deviceauth.gni b/services/deviceauth.gni index d0874fa3..af7bb902 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -60,6 +60,8 @@ identity_service_mock_files = [ inc_path = [ "${inner_api_path}", "${device_auth_common}/inc", + "${services_path}/sa/inc/cache_common_event_handler", + "${services_path}/sa/inc/critical_handler", "${frameworks_path}/inc", "${ext_plugin_manager_path}/inc", "${ext_plugin_manager_path}/inc/account_related", @@ -151,6 +153,18 @@ security_label_adapter_mock_files = [ "${dev_frameworks_path}/src/security_label permission_adapter_files = [ "${dev_frameworks_path}/src/permission_adapter/permission_adapter.cpp" ] +cache_common_event_handler_files = + [ "${services_path}/sa/src/cache_common_event_handler/cache_common_event_handler.cpp" ] +cache_common_event_handler_mock_files = + [ "${services_path}/sa/src/cache_common_event_handler/mock/cache_common_event_handler_mock.cpp" ] +critical_handler_files = + [ "${services_path}/sa/src/critical_handler/critical_handler.cpp" ] +critical_handler_mock_files = + [ "${services_path}/sa/src/critical_handler/mock/critical_handler_mock.cpp" ] + +sa_load_on_demand_files = cache_common_event_handler_files + critical_handler_files +sa_load_on_demand_mock_files = cache_common_event_handler_mock_files + critical_handler_mock_files + hiview_adapter_files = [ "${dev_frameworks_path}/src/hiview_adapter/hidump_adapter.c", "${dev_frameworks_path}/src/hiview_adapter/hisysevent_adapter.cpp", diff --git a/services/deviceauth_service.cfg b/services/deviceauth_service.cfg index 64691eb2..c7f573c5 100644 --- a/services/deviceauth_service.cfg +++ b/services/deviceauth_service.cfg @@ -4,8 +4,7 @@ "cmds" : [ "mkdir /data/service/el1/public/deviceauth 0711 deviceauth deviceauth", "mkdir /data/service/el1/public/deviceauth/account 0711 deviceauth deviceauth", - "mkdir /data/service/el1/public/deviceauth/pseudonym 0711 deviceauth deviceauth", - "start deviceauth_service" + "mkdir /data/service/el1/public/deviceauth/pseudonym 0711 deviceauth deviceauth" ] } ], @@ -14,6 +13,7 @@ "path" : ["/system/bin/sa_main", "/system/profile/deviceauth_service.json"], "uid" : "deviceauth", "gid" : ["deviceauth", "shell", "netsys_socket"], + "ondemand" : true, "secon" : "u:r:deviceauth_service:s0", "permission" : [ "ohos.permission.DISTRIBUTED_DATASYNC", diff --git a/services/frameworks/inc/os_account_adapter/os_account_adapter.h b/services/frameworks/inc/os_account_adapter/os_account_adapter.h index 9241f1fb..24b0d106 100644 --- a/services/frameworks/inc/os_account_adapter/os_account_adapter.h +++ b/services/frameworks/inc/os_account_adapter/os_account_adapter.h @@ -33,6 +33,8 @@ typedef enum { typedef void (*OsAccountCallbackFunc)(int32_t osAccountId); +void NotifyOsAccountUnlocked(int32_t osAccountId); +void NotifyOsAccountRemoved(int32_t osAccountId); void AddOsAccountEventCallback(EventCallbackId callbackId, OsAccountCallbackFunc unlockFunc, OsAccountCallbackFunc removeFunc); void RemoveOsAccountEventCallback(EventCallbackId callbackId); diff --git a/services/frameworks/src/os_account_adapter/os_account_adapter.cpp b/services/frameworks/src/os_account_adapter/os_account_adapter.cpp index 3e739ac3..6370dfe5 100644 --- a/services/frameworks/src/os_account_adapter/os_account_adapter.cpp +++ b/services/frameworks/src/os_account_adapter/os_account_adapter.cpp @@ -52,7 +52,7 @@ static OHOS::DevAuth::OsAccountEventNotifier g_accountEventNotifier; static OHOS::DevAuth::SaEventNotifier g_saEventNotifier; static OHOS::sptr g_observer = nullptr; -static void NotifyOsAccountUnlocked(int32_t osAccountId) +void NotifyOsAccountUnlocked(int32_t osAccountId) { if (!g_isInitialized) { return; @@ -64,7 +64,7 @@ static void NotifyOsAccountUnlocked(int32_t osAccountId) } } -static void NotifyOsAccountRemoved(int32_t osAccountId) +void NotifyOsAccountRemoved(int32_t osAccountId) { if (!g_isInitialized) { return; diff --git a/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin/account_lifecycle_plugin_proxy.c b/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin/account_lifecycle_plugin_proxy.c index 7490d5ab..2a753a45 100644 --- a/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin/account_lifecycle_plugin_proxy.c +++ b/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin/account_lifecycle_plugin_proxy.c @@ -21,6 +21,7 @@ #include "account_task_manager.h" #include "alg_loader.h" #include "identity_service.h" +#include "critical_handler.h" static AccountLifecyleExtPlug *g_accountLifeCyclePlugin = NULL; static AccountLifecyleExtPlugCtx *g_accountPluginCtx = NULL; @@ -36,18 +37,22 @@ static void DoWorkerTask(HcTaskBase *task) LOGD("[ACCOUNT_LIFE_PLUGIN]: Do worker task begin."); if (task == NULL) { LOGE("[ACCOUNT_LIFE_PLUGIN]: The input task is NULL, cannot do task!"); + DecreaseCriticalCnt(); return; } WorkerTask *workerTask = (WorkerTask *)task; if (workerTask->extTask == NULL) { LOGE("[ACCOUNT_LIFE_PLUGIN]: The inner task is NULL, cannot do task!"); + DecreaseCriticalCnt(); return; } if (workerTask->extTask->execute == NULL) { LOGE("[ACCOUNT_LIFE_PLUGIN]: The ext func is NULL, cannot do task!"); + DecreaseCriticalCnt(); return; } workerTask->extTask->execute(workerTask->extTask); + DecreaseCriticalCnt(); LOGD("[ACCOUNT_LIFE_PLUGIN]: Do worker task end."); } @@ -65,10 +70,12 @@ static void DestroyWorkerTask(HcTaskBase *workerTask) LOGD("[ACCOUNT_LIFE_PLUGIN]: Destroy worker task begin."); if (workerTask == NULL) { LOGE("[ACCOUNT_LIFE_PLUGIN]: The inner task is NULL, cannot do task!"); + DecreaseCriticalCnt(); return; } DestroyExtWorkerTask(((WorkerTask *)workerTask)->extTask); RemoveAccountTaskRecordAndUnload(((WorkerTask *)workerTask)->taskId); + DecreaseCriticalCnt(); LOGD("[ACCOUNT_LIFE_PLUGIN]: Destroy worker task end."); } @@ -109,6 +116,7 @@ static int32_t ExecuteWorkerTask(struct ExtWorkerTask *extTask) HcFree(baseTask); return HC_ERR_INIT_TASK_FAIL; } + IncreaseCriticalCnt(ADD_TWO); return HC_SUCCESS; } diff --git a/services/legacy/group_manager/src/group_operation/group_operation.c b/services/legacy/group_manager/src/group_operation/group_operation.c index 1a924f2c..7dcd7b14 100644 --- a/services/legacy/group_manager/src/group_operation/group_operation.c +++ b/services/legacy/group_manager/src/group_operation/group_operation.c @@ -38,6 +38,7 @@ #include "device_auth_common.h" #include "performance_dumper.h" #include "channel_manager.h" +#include "critical_handler.h" #define EXT_PART_APP_ID "ext_part" @@ -460,6 +461,7 @@ static void DoCreateGroup(HcTaskBase *baseTask) ProcessFinishCallback(task->reqId, GROUP_CREATE, returnJsonStr, task->cb); FreeJsonString(returnJsonStr); } + DecreaseCriticalCnt(); } static void DoDeleteGroup(HcTaskBase *baseTask) @@ -476,6 +478,7 @@ static void DoDeleteGroup(HcTaskBase *baseTask) ProcessFinishCallback(task->reqId, GROUP_DISBAND, returnJsonStr, task->cb); FreeJsonString(returnJsonStr); } + DecreaseCriticalCnt(); } static void DoDeleteMember(HcTaskBase *baseTask) @@ -485,6 +488,7 @@ static void DoDeleteMember(HcTaskBase *baseTask) SET_TRACE_ID(task->reqId); LOGI("[Start]: DoDeleteMember! [ReqId]: %" LOG_PUB PRId64, task->reqId); (void)DeleteMemberFromPeerToPeerGroup(task->osAccountId, task->reqId, task->params, task->cb); + DecreaseCriticalCnt(); } static int32_t CreateGroupInner(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams) @@ -1212,6 +1216,7 @@ static void DoOnChannelOpened(HcTaskBase *baseTask) { if (baseTask == NULL) { LOGE("The input task is NULL!"); + DecreaseCriticalCnt(); return; } SoftBusTask *task = (SoftBusTask *)baseTask; @@ -1223,6 +1228,7 @@ static void DoOnChannelOpened(HcTaskBase *baseTask) LOGE("start session fail.[Res]: %" LOG_PUB "d", res); CloseDevSession(task->requestId); } + DecreaseCriticalCnt(); } static void InitSoftBusTask(SoftBusTask *task, int64_t requestId) @@ -1252,6 +1258,7 @@ static int OnChannelOpenedCb(int64_t requestId, int result) CloseDevSession(requestId); return HC_ERR_INIT_TASK_FAIL; } + IncreaseCriticalCnt(ADD_ONE); LOGI("[End]: OnChannelOpened!"); return HC_SUCCESS; } @@ -1777,11 +1784,13 @@ void DestroyGroupManagerTask(HcTaskBase *task) { if (task == NULL) { LOGE("The input task is NULL!"); + DecreaseCriticalCnt(); return; } RemoveAccountTaskIfNeeded(((GroupManagerTask *)task)->opCode, ((GroupManagerTask *)task)->reqId, ((GroupManagerTask *)task)->params); FreeJson(((GroupManagerTask *)task)->params); + DecreaseCriticalCnt(); } int32_t AddReqInfoToJson(int64_t requestId, const char *appId, CJson *jsonParams) @@ -1847,6 +1856,7 @@ int32_t InitAndPushGMTask(int32_t osAccountId, int32_t opCode, int64_t reqId, CJ HcFree(task); return HC_ERR_INIT_TASK_FAIL; } + IncreaseCriticalCnt(ADD_TWO); return HC_SUCCESS; } diff --git a/services/sa/inc/cache_common_event_handler/cache_common_event_handler.h b/services/sa/inc/cache_common_event_handler/cache_common_event_handler.h new file mode 100644 index 00000000..e525fe8c --- /dev/null +++ b/services/sa/inc/cache_common_event_handler/cache_common_event_handler.h @@ -0,0 +1,28 @@ +/* + * 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 CACHE_COMMON_EVENT_HANDLER_H +#define CACHE_COMMON_EVENT_HANDLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +void HandleCacheCommonEvent(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/services/sa/inc/critical_handler/critical_handler.h b/services/sa/inc/critical_handler/critical_handler.h new file mode 100644 index 00000000..5518f648 --- /dev/null +++ b/services/sa/inc/critical_handler/critical_handler.h @@ -0,0 +1,36 @@ +/* + * 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 CRITICAL_HANDLER_H +#define CRITICAL_HANDLER_H +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define ADD_ONE 1 +#define ADD_TWO 2 + +void NotifyProcessIsActive(void); +void NotifyProcessIsStop(void); +void IncreaseCriticalCnt(int addCnt); +void DecreaseCriticalCnt(void); +int32_t GetCriticalCnt(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/services/sa/sa_profile/4701.json b/services/sa/sa_profile/4701.json index 6cf2ac46..3fb7f9c3 100644 --- a/services/sa/sa_profile/4701.json +++ b/services/sa/sa_profile/4701.json @@ -4,9 +4,22 @@ { "name": 4701, "libpath": "libdeviceauth_service.z.so", - "run-on-create": true, + "run-on-create": false, "distributed": false, - "dump_level": 1 + "dump_level": 1, + "cache-common-event": true, + "start-on-demand": { + "allow-update": false, + "commonevent": [ + { "name": "usual.event.USER_REMOVED" }, + { "name": "usual.event.USER_UNLOCKED" }, + { "name": "common.event.DISTRIBUTED_ACCOUNT_LOGIN" }, + { "name": "common.event.DISTRIBUTED_ACCOUNT_LOGOUT" }, + { "name": "usual.event.bluetooth.host.STATE_UPDATE" }, + { "name": "usual.event.USER_SWITCHED" }, + { "name": "usual.event.CONNECTIVITY_CHANGE" } + ] + } } ] } \ No newline at end of file diff --git a/services/sa/src/cache_common_event_handler/cache_common_event_handler.cpp b/services/sa/src/cache_common_event_handler/cache_common_event_handler.cpp new file mode 100644 index 00000000..a59b07ff --- /dev/null +++ b/services/sa/src/cache_common_event_handler/cache_common_event_handler.cpp @@ -0,0 +1,93 @@ +/* + * 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 "cache_common_event_handler.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "matching_skills.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "hc_log.h" +#include +#include "system_ability_ondemand_reason.h" +#include "os_account_adapter.h" +#include "account_task_manager.h" +#include "json_utils.h" +#include "common_defs.h" + +static const std::string COMMON_EVENT_ACTION_NAME = "common_event_action_name"; + +static void HandleCacheCommonEventInner(const char *eventName, int32_t eventCode) +{ + CJson *cmdParamJson = CreateJson(); + if (cmdParamJson == nullptr) { + LOGE("[CacheCommonEvent]: Failed to create cmd params json."); + return; + } + if (AddStringToJson(cmdParamJson, FIELD_COMMON_EVENT_NAME, eventName) + != HC_SUCCESS) { + LOGE("[CacheCommonEvent]: Failed to add common event name to json."); + FreeJson(cmdParamJson); + return; + } + if (AddIntToJson(cmdParamJson, FIELD_COMMON_EVENT_CODE, eventCode) != HC_SUCCESS) { + LOGE("[CacheCommonEvent]: Failed to add common event code to json."); + FreeJson(cmdParamJson); + return; + } + LOGI("[CacheCommonEvent]: start handle common event."); + int32_t res = ExecuteAccountAuthCmd(DEFAULT_OS_ACCOUNT, HANDLE_COMMON_EVENT, cmdParamJson, nullptr); + FreeJson(cmdParamJson); + LOGI("[CacheCommonEvent]: handle common event res: %" LOG_PUB "d.", res); +} + +void HandleCacheCommonEvent(void) +{ + auto saMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + std::vector extraDataIdList; + int32_t ret = saMgr->GetCommonEventExtraDataIdlist(OHOS::DEVICE_AUTH_SERVICE_ID, extraDataIdList); + if (ret != OHOS::ERR_OK) { + LOGE("GetCommonEventExtraDataIdlist failed ret is %" LOG_PUB "d.", ret); + return; + } + LOGI("extra id size: %" LOG_PUB "ld", extraDataIdList.size()); + for (auto &item : extraDataIdList) { + OHOS::MessageParcel extraDataParcel; + ret = saMgr->GetOnDemandReasonExtraData(item, extraDataParcel); + if (ret != OHOS::ERR_OK) { + LOGE("get extra data failed."); + continue; + } + auto extraData = extraDataParcel.ReadParcelable(); + if (extraData == nullptr) { + LOGE("get extra data read parcel failed."); + continue; + } + LOGI("code: %" LOG_PUB "d, data: %" LOG_PUB "s", extraData->GetCode(), extraData->GetData().c_str()); + auto want = extraData->GetWant(); + LOGI("want[COMMON_EVENT_ACTION_NAME]: %" LOG_PUB "s.", want[COMMON_EVENT_ACTION_NAME].c_str()); + if (want[COMMON_EVENT_ACTION_NAME] == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED) { + LOGI("[CacheCommonEvent]: user unlocked, userId %" LOG_PUB "d.", extraData->GetCode()); + NotifyOsAccountUnlocked(extraData->GetCode()); + } else if (want[COMMON_EVENT_ACTION_NAME] == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { + LOGI("[CacheCommonEvent]: user removed, userId %" LOG_PUB "d.", extraData->GetCode()); + NotifyOsAccountRemoved(extraData->GetCode()); + } else { + LOGI("[CacheCommonEvent]: receive other event."); + } + HandleCacheCommonEventInner(want[COMMON_EVENT_ACTION_NAME].c_str(), extraData->GetCode()); + } + return; +} \ No newline at end of file diff --git a/services/sa/src/cache_common_event_handler/mock/cache_common_event_handler_mock.cpp b/services/sa/src/cache_common_event_handler/mock/cache_common_event_handler_mock.cpp new file mode 100644 index 00000000..9d6f4959 --- /dev/null +++ b/services/sa/src/cache_common_event_handler/mock/cache_common_event_handler_mock.cpp @@ -0,0 +1,18 @@ +/* + * 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 "cache_common_event_handler.h" + +void HandleCacheCommonEvent(void) {} \ No newline at end of file diff --git a/services/sa/src/critical_handler/critical_handler.cpp b/services/sa/src/critical_handler/critical_handler.cpp new file mode 100644 index 00000000..1a3e0dcb --- /dev/null +++ b/services/sa/src/critical_handler/critical_handler.cpp @@ -0,0 +1,62 @@ +/* + * 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 "critical_handler.h" +#include "mem_mgr_client.h" +#include "mem_mgr_proxy.h" +#include "hc_log.h" +#include + +static int32_t g_count = 0; +static std::mutex g_criticalLock; + +void NotifyProcessIsActive(void) +{ + LOGI("start to notify memmgr sa active."); + OHOS::Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 1, OHOS::DEVICE_AUTH_SERVICE_ID); +} + +void NotifyProcessIsStop(void) +{ + LOGI("start to notify memmgr sa stop."); + OHOS::Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 0, OHOS::DEVICE_AUTH_SERVICE_ID); +} + +void IncreaseCriticalCnt(int addCnt) +{ + std::lock_guard autoLock(g_criticalLock); + if (g_count == 0) { + LOGI("Try to set critical to true."); + OHOS::Memory::MemMgrClient::GetInstance().SetCritical(getpid(), true, OHOS::DEVICE_AUTH_SERVICE_ID); + } + g_count = g_count + addCnt; +} + +void DecreaseCriticalCnt(void) +{ + std::lock_guard autoLock(g_criticalLock); + g_count = g_count - 1; + if (g_count == 0) { + LOGI("Try to set critical to false."); + OHOS::Memory::MemMgrClient::GetInstance().SetCritical(getpid(), false, OHOS::DEVICE_AUTH_SERVICE_ID); + } +} + +int32_t GetCriticalCnt(void) +{ + std::lock_guard autoLock(g_criticalLock); + return g_count; +} \ No newline at end of file diff --git a/services/sa/src/critical_handler/mock/critical_handler_mock.cpp b/services/sa/src/critical_handler/mock/critical_handler_mock.cpp new file mode 100644 index 00000000..c0810c60 --- /dev/null +++ b/services/sa/src/critical_handler/mock/critical_handler_mock.cpp @@ -0,0 +1,32 @@ +/* + * 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 "critical_handler.h" + +void NotifyProcessIsActive(void) {} + +void NotifyProcessIsStop(void) {} + +void IncreaseCriticalCnt(int addCnt) +{ + (void)addCnt; +} + +void DecreaseCriticalCnt(void) {} + +int32_t GetCriticalCnt(void) +{ + return 0; +} \ No newline at end of file diff --git a/services/session_manager/inc/dev_session_mgr.h b/services/session_manager/inc/dev_session_mgr.h index f31d0662..b21db6e8 100644 --- a/services/session_manager/inc/dev_session_mgr.h +++ b/services/session_manager/inc/dev_session_mgr.h @@ -36,6 +36,7 @@ void CancelDevSession(int64_t sessionId, const char *appId); int32_t PushStartSessionTask(int64_t sessionId); int32_t PushProcSessionTask(int64_t sessionId, CJson *receivedMsg); +void RemoveTimeoutSession(void); #ifdef __cplusplus } diff --git a/services/session_manager/src/dev_session_mgr.c b/services/session_manager/src/dev_session_mgr.c index 6939de61..51e65046 100644 --- a/services/session_manager/src/dev_session_mgr.c +++ b/services/session_manager/src/dev_session_mgr.c @@ -24,6 +24,7 @@ #include "hc_time.h" #include "hc_vector.h" #include "task_manager.h" +#include "critical_handler.h" typedef struct { DevSession *session; @@ -61,7 +62,7 @@ static int32_t GetSessionInfo(int64_t sessionId, SessionInfo **returnObj) return HC_ERR_SESSION_NOT_EXIST; } -static void RemoveTimeoutSession(void) +void RemoveTimeoutSession(void) { uint32_t index = 0; while (index < g_sessionInfoList.size(&(g_sessionInfoList))) { @@ -264,6 +265,7 @@ static void DoStartSession(HcTaskBase *task) LOGI("start session task begin."); if (task == NULL) { LOGE("The input task is NULL, can't start session!"); + DecreaseCriticalCnt(); return; } StartSessionTask *realTask = (StartSessionTask *)task; @@ -274,6 +276,7 @@ static void DoStartSession(HcTaskBase *task) LOGE("start session fail.[Res]: %" LOG_PUB "d", res); CloseDevSession(realTask->sessionId); } + DecreaseCriticalCnt(); } static void DoProcSession(HcTaskBase *task) @@ -281,6 +284,7 @@ static void DoProcSession(HcTaskBase *task) LOGI("proc session task begin."); if (task == NULL) { LOGE("The input task is NULL, can't start session!"); + DecreaseCriticalCnt(); return; } ProcSessionTask *realTask = (ProcSessionTask *)task; @@ -291,12 +295,14 @@ static void DoProcSession(HcTaskBase *task) if (res != HC_SUCCESS) { LOGE("ProcessDevSession fail. [Res]: %" LOG_PUB "d", res); CloseDevSession(realTask->sessionId); + DecreaseCriticalCnt(); return; } LOGI("ProcessDevSession success. [State]: %" LOG_PUB "s", isFinish ? "FINISH" : "CONTINUE"); if (isFinish) { CloseDevSession(realTask->sessionId); } + DecreaseCriticalCnt(); } static void InitStartSessionTask(StartSessionTask *task, int64_t sessionId) @@ -310,6 +316,7 @@ static void DestroyProcSessionTask(HcTaskBase *task) { ProcSessionTask *realTask = (ProcSessionTask *)task; FreeJson(realTask->receivedMsg); + DecreaseCriticalCnt(); } static void InitProcSessionTask(ProcSessionTask *task, int64_t sessionId, CJson *receivedMsg) @@ -333,6 +340,7 @@ int32_t PushStartSessionTask(int64_t sessionId) HcFree(task); return HC_ERR_INIT_TASK_FAIL; } + IncreaseCriticalCnt(ADD_ONE); LOGI("push start session task success."); return HC_SUCCESS; } @@ -350,6 +358,7 @@ int32_t PushProcSessionTask(int64_t sessionId, CJson *receivedMsg) HcFree(task); return HC_ERR_INIT_TASK_FAIL; } + IncreaseCriticalCnt(ADD_TWO); LOGI("push start session task success."); return HC_SUCCESS; } \ No newline at end of file diff --git a/test/fuzztest/authenticators/account_related/auth/isoauthtask_fuzzer/BUILD.gn b/test/fuzztest/authenticators/account_related/auth/isoauthtask_fuzzer/BUILD.gn index 846fc6dd..98a0a251 100644 --- a/test/fuzztest/authenticators/account_related/auth/isoauthtask_fuzzer/BUILD.gn +++ b/test/fuzztest/authenticators/account_related/auth/isoauthtask_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("IsoAuthTaskFuzzTest") { sources += hiview_adapter_files sources += identity_manager_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files defines = deviceauth_defines defines += [ "HILOG_ENABLE" ] defines += [ "DEV_AUTH_HIVIEW_ENABLE" ] diff --git a/test/fuzztest/authenticators/account_unrelated/pake/standardexchangetask_fuzzer/BUILD.gn b/test/fuzztest/authenticators/account_unrelated/pake/standardexchangetask_fuzzer/BUILD.gn index 3fef77e6..9f3434d2 100644 --- a/test/fuzztest/authenticators/account_unrelated/pake/standardexchangetask_fuzzer/BUILD.gn +++ b/test/fuzztest/authenticators/account_unrelated/pake/standardexchangetask_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("StandardExchangeTaskFuzzTest") { sources += deviceauth_files sources += identity_manager_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files if (support_os_account) { sources += account_subscriber_files diff --git a/test/fuzztest/creds_manager/credsmanager_fuzzer/BUILD.gn b/test/fuzztest/creds_manager/credsmanager_fuzzer/BUILD.gn index 1f184582..a6472ab4 100644 --- a/test/fuzztest/creds_manager/credsmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/creds_manager/credsmanager_fuzzer/BUILD.gn @@ -40,6 +40,7 @@ ohos_fuzztest("CredsManagerFuzzTest") { sources = [ "credsmanager_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hal_common_files sources += hiview_adapter_files if (support_os_account) { diff --git a/test/fuzztest/devauth_fuzzer/BUILD.gn b/test/fuzztest/devauth_fuzzer/BUILD.gn index c001b255..135c76e6 100644 --- a/test/fuzztest/devauth_fuzzer/BUILD.gn +++ b/test/fuzztest/devauth_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("DevAuthFuzzTest") { sources = [ "devauth_fuzzer.cpp" ] sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += [ "${frameworks_path}/src/ipc_service_common.c" ] sources += [ "${frameworks_path}/src/ipc_service_lite.c" ] sources += identity_service_mock_files diff --git a/test/fuzztest/devauthcb_fuzzer/BUILD.gn b/test/fuzztest/devauthcb_fuzzer/BUILD.gn index 0ef43d6a..114c4a72 100644 --- a/test/fuzztest/devauthcb_fuzzer/BUILD.gn +++ b/test/fuzztest/devauthcb_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("DevAuthCbFuzzTest") { sources = [ "devauthcb_fuzzer.cpp" ] sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files defines = [ "HILOG_ENABLE" ] defines += [ "DEV_AUTH_HIVIEW_ENABLE" ] defines += [ "DEV_AUTH_FUZZ_TEST" ] diff --git a/test/fuzztest/devauthfunc_fuzzer/BUILD.gn b/test/fuzztest/devauthfunc_fuzzer/BUILD.gn index dbdd9876..83245ed1 100644 --- a/test/fuzztest/devauthfunc_fuzzer/BUILD.gn +++ b/test/fuzztest/devauthfunc_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("DevAuthFuncFuzzTest") { sources += dev_frameworks_files sources += deviceauth_common_files + sources += sa_load_on_demand_mock_files sources += identity_service_mock_files sources += group_database_manager_files sources += ext_plugin_manager_files diff --git a/test/fuzztest/devauthinterface_fuzzer/BUILD.gn b/test/fuzztest/devauthinterface_fuzzer/BUILD.gn index a7834068..6ca8d120 100644 --- a/test/fuzztest/devauthinterface_fuzzer/BUILD.gn +++ b/test/fuzztest/devauthinterface_fuzzer/BUILD.gn @@ -70,6 +70,7 @@ ohos_fuzztest("DevAuthInterfaceFuzzTest") { sources += soft_bus_channel_files sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_files sources += group_auth_files sources += group_auth_account_unrelated_files @@ -147,6 +148,9 @@ ohos_fuzztest("DevAuthInterfaceFuzzTest") { "mbedtls:mbedtls_shared", "openssl:libcrypto_static", "samgr:samgr_proxy", + "memmgr:memmgrclient", + "common_event_service:cesfwk_innerkits", + "safwk:system_ability_fwk", ] } diff --git a/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn index c4edc3ef..042175f0 100644 --- a/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn @@ -32,6 +32,7 @@ ohos_fuzztest("DevAuthServAddMemberToGroupFuzzTest") { ] sources = [ "devauthservaddmembertogroup_fuzzer.cpp" ] sources += identity_service_mock_files + sources += sa_load_on_demand_mock_files sources += deviceauth_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { diff --git a/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn index f4e20b37..84ac5491 100644 --- a/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServAddMultiMembersToGroupFuzzTest") { sources = [ "devauthservaddmultimemberstogroup_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn index a1b0e11a..46a46db3 100644 --- a/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServAuthDeviceFuzzTest") { sources = [ "devauthservauthdevice_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn index b3d48db1..7c7a4f7d 100644 --- a/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServCancelAuthRequestFuzzTest") { sources = [ "devauthservcancelauthrequest_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn index 999e35f8..a261c5b8 100644 --- a/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServCancelBindRequestFuzzTest") { sources = [ "devauthservcancelbindrequest_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn index ba9ad6f6..cffa2799 100644 --- a/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServCheckAccessToGroupFuzzTest") { sources = [ "devauthservcheckaccesstogroup_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn index 80332d3b..8797b792 100644 --- a/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("DevAuthServCreateGroupFuzzTest") { sources += identity_service_mock_files sources += deviceauth_files sources += hiview_adapter_files + sources += sa_load_on_demand_mock_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files sources += soft_bus_channel_mock_files diff --git a/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn index ead73668..26a44da9 100644 --- a/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServDeleteGroupFuzzTest") { sources = [ "devauthservdeletegroup_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn index 24eaa674..6dc7d86c 100644 --- a/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServDeleteMemberFromGroupFuzzTest") { sources = [ "devauthservdeletememberfromgroup_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn index f35aa9fc..87bfd47b 100644 --- a/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServDeleteMultiMembersFromGroupFuzzTest") { sources = [ "devauthservdeletemultimembersfromgroup_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn index 80a3f412..808db633 100644 --- a/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetDeviceInfoByIdFuzzTest") { sources = [ "devauthservgetdeviceinfobyid_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn index ef6b68f7..9bb23bd3 100644 --- a/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetGroupInfoFuzzTest") { sources = [ "devauthservgetgroupinfo_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn index 80d036b3..442e0a30 100644 --- a/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetGroupInfoByIdFuzzTest") { sources = [ "devauthservgetgroupinfobyid_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn index 0d8908e7..2c1122ba 100644 --- a/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetJoinedGroupsFuzzTest") { sources = [ "devauthservgetjoinedgroups_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn index 41a870e2..5b5cebf1 100644 --- a/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetPkInfoListFuzzTest") { sources = [ "devauthservgetpkinfolist_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn index 5a399cbf..0710cc36 100644 --- a/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetRegisterInfoFuzzTest") { sources = [ "devauthservgetregisterinfo_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn index 81083fda..6a4735cd 100644 --- a/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetRelatedGroupsFuzzTest") { sources = [ "devauthservgetrelatedgroups_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn index fab1839e..ad7908b3 100644 --- a/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServGetTrustedDevicesFuzzTest") { sources = [ "devauthservgettrusteddevices_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn index dfecb3a0..764273f3 100644 --- a/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServIsDeviceInGroupFuzzTest") { sources = [ "devauthservisdeviceingroup_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn index d71f68b0..bccab43b 100644 --- a/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServProcessAuthDataFuzzTest") { sources = [ "devauthservprocessauthdata_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn index e6dac9a4..c8aaf8ed 100644 --- a/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServProcessBindDataFuzzTest") { sources = [ "devauthservprocessbinddata_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn index 786a4f4e..5dd805de 100644 --- a/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServRegCallbackFuzzTest") { sources = [ "devauthservregcallback_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn index 6c0e54c0..6591748a 100644 --- a/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("DevAuthServRegDataChangeListenerFuzzTest") { sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn index 3682f62d..1887f0d1 100644 --- a/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServUnregCallbackFuzzTest") { sources = [ "devauthservunregcallback_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn index 60495976..36a810c0 100644 --- a/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("DevAuthServUnregDataChangeListenerFuzzTest") { sources = [ "devauthservunregdatachangelistener_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files if (device_auth_enable_soft_bus_channel == true) { sources -= soft_bus_channel_files diff --git a/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn b/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn index 271e9a12..8ba1d439 100644 --- a/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn +++ b/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("AccountRelatedGroupAuthFuzzTest") { sources += dev_frameworks_files sources += identity_service_mock_files sources += deviceauth_common_files + sources += sa_load_on_demand_mock_files sources += group_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files diff --git a/test/fuzztest/group_manage/groupoperationcommon_fuzzer/BUILD.gn b/test/fuzztest/group_manage/groupoperationcommon_fuzzer/BUILD.gn index f6d57ba6..1481d41f 100644 --- a/test/fuzztest/group_manage/groupoperationcommon_fuzzer/BUILD.gn +++ b/test/fuzztest/group_manage/groupoperationcommon_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("GroupOperationCommonFuzzTest") { sources = [ "groupoperationcommon_fuzzer.cpp" ] sources += identity_service_mock_files sources += deviceauth_files + sources += sa_load_on_demand_mock_files sources += hal_common_files sources += hiview_adapter_files sources += identity_manager_files diff --git a/test/fuzztest/identityservice_fuzzer/BUILD.gn b/test/fuzztest/identityservice_fuzzer/BUILD.gn index 920b7c70..3b589e59 100644 --- a/test/fuzztest/identityservice_fuzzer/BUILD.gn +++ b/test/fuzztest/identityservice_fuzzer/BUILD.gn @@ -72,6 +72,7 @@ ohos_fuzztest("IdentityServiceFuzzTest") { sources += broadcast_manager_files sources += soft_bus_channel_mock_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += group_auth_files sources += group_auth_account_unrelated_files diff --git a/test/fuzztest/protocol/dlspeke_fuzzer/BUILD.gn b/test/fuzztest/protocol/dlspeke_fuzzer/BUILD.gn index 3aa6e246..f41e0681 100644 --- a/test/fuzztest/protocol/dlspeke_fuzzer/BUILD.gn +++ b/test/fuzztest/protocol/dlspeke_fuzzer/BUILD.gn @@ -37,6 +37,7 @@ ohos_fuzztest("DLSpekeFuzzTest") { sources = [ "dlspeke_fuzzer.cpp" ] sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files defines = [ "ENABLE_P2P_BIND_DL_SPEKE" ] diff --git a/test/fuzztest/protocol/ecspeke_fuzzer/BUILD.gn b/test/fuzztest/protocol/ecspeke_fuzzer/BUILD.gn index a6e957c1..52ac5e9a 100644 --- a/test/fuzztest/protocol/ecspeke_fuzzer/BUILD.gn +++ b/test/fuzztest/protocol/ecspeke_fuzzer/BUILD.gn @@ -37,6 +37,7 @@ ohos_fuzztest("ECSpekeFuzzTest") { sources = [ "ecspeke_fuzzer.cpp" ] sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files defines = [ "ENABLE_EC_SPEKE" ] diff --git a/test/fuzztest/protocol/iso_fuzzer/BUILD.gn b/test/fuzztest/protocol/iso_fuzzer/BUILD.gn index 2b1eeca7..74e67c1f 100644 --- a/test/fuzztest/protocol/iso_fuzzer/BUILD.gn +++ b/test/fuzztest/protocol/iso_fuzzer/BUILD.gn @@ -37,6 +37,7 @@ ohos_fuzztest("IsoFuzzTest") { sources = [ "iso_fuzzer.cpp" ] sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += hiview_adapter_files defines = [ "ENABLE_ISO" ] diff --git a/test/unittest/deviceauth/BUILD.gn b/test/unittest/deviceauth/BUILD.gn index ab5c600d..b3756d3d 100644 --- a/test/unittest/deviceauth/BUILD.gn +++ b/test/unittest/deviceauth/BUILD.gn @@ -54,6 +54,7 @@ ohos_unittest("deviceauth_llt") { sources += dev_frameworks_files sources += identity_service_mock_files sources += deviceauth_common_files + sources += sa_load_on_demand_mock_files sources += group_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files @@ -178,6 +179,7 @@ ohos_unittest("device_auth_func_test") { sources += dev_frameworks_files sources += identity_service_mock_files sources += deviceauth_common_files + sources += sa_load_on_demand_mock_files sources += group_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files @@ -324,6 +326,7 @@ ohos_unittest("device_auth_identity_service_test") { sources += broadcast_manager_files sources += soft_bus_channel_mock_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += group_auth_files sources += group_auth_account_unrelated_files @@ -458,6 +461,8 @@ ohos_unittest("device_auth_interface_test") { sources += soft_bus_channel_files sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_files + sources -= cache_common_event_handler_files sources += group_auth_files sources += group_auth_account_unrelated_files @@ -537,6 +542,9 @@ ohos_unittest("device_auth_interface_test") { "mbedtls:mbedtls_shared", "openssl:libcrypto_static", "samgr:samgr_proxy", + "memmgr:memmgrclient", + "common_event_service"cesfwk_innerkits", + "safwk:system_ability_fwk", ] } @@ -575,6 +583,7 @@ ohos_unittest("deviceauth_unit_test") { sources += identity_service_mock_files sources += dev_frameworks_files sources += deviceauth_common_files + sources += sa_load_on_demand_mock_files sources += group_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files diff --git a/test/unittest/deviceauth/source/device_auth_ipc_test.cpp b/test/unittest/deviceauth/source/device_auth_ipc_test.cpp index bc043433..5823e39c 100644 --- a/test/unittest/deviceauth/source/device_auth_ipc_test.cpp +++ b/test/unittest/deviceauth/source/device_auth_ipc_test.cpp @@ -448,6 +448,10 @@ HWTEST_F(GmRegCallbackTest, GmRegCallbackTest002, TestSize.Level0) DeviceAuthCallback callback2; ret = gm->regCallback(TEST_APP_ID, &callback2); ASSERT_EQ(ret, HC_SUCCESS); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); } HWTEST_F(GmRegCallbackTest, GmRegCallbackTest003, TestSize.Level0) @@ -2102,6 +2106,10 @@ HWTEST_F(GmUnRegDataChangeListenerTest, GmUnRegDataChangeListenerTest001, TestSi ASSERT_EQ(ret, HC_SUCCESS); ret = gm->unRegDataChangeListener(TEST_APP_ID); ASSERT_EQ(ret, HC_SUCCESS); + ret = gm->regDataChangeListener(TEST_APP_ID, &g_listener); + ASSERT_EQ(ret, HC_SUCCESS); + ret = gm->regDataChangeListener(TEST_APP_ID, &g_listener); + ASSERT_EQ(ret, HC_SUCCESS); } HWTEST_F(GmUnRegDataChangeListenerTest, GmUnRegDataChangeListenerTest002, TestSize.Level0) diff --git a/test/unittest/deviceauth/source/deviceauth_interface_test.cpp b/test/unittest/deviceauth/source/deviceauth_interface_test.cpp index 15d3784f..4aad85bd 100644 --- a/test/unittest/deviceauth/source/deviceauth_interface_test.cpp +++ b/test/unittest/deviceauth/source/deviceauth_interface_test.cpp @@ -58,7 +58,7 @@ #include "base/security/device_auth/services/legacy/authenticators/src/account_unrelated/pake_task/pake_v1_task/pake_v1_protocol_task/pake_v1_protocol_task_common.c" #include "base/security/device_auth/services/session_manager/src/session/v2/dev_session_util.c" #include "base/security/device_auth/services/legacy/group_manager/src/group_operation/identical_account_group/identical_account_group.c" - +#include "base/security/device_auth/services/sa/src/cache_common_event_handler/cache_common_event_handler.cpp" using namespace std; using namespace testing::ext; @@ -78,6 +78,7 @@ namespace { #define TEST_KEY_LEN_2 40 #define TEST_OS_ACCOUNT_ID 0 #define TEST_DEVICE_PK "testDevicePk" +#define TEST_EVENT_NAME "usual.event.USER_UNLOCKED" #define TEST_VERSION 0 #define TEST_RANDOM_LEN 16 static const char *EXT_INFO = @@ -1881,6 +1882,12 @@ HWTEST_F(DeviceAuthInterfaceTest, DeviceAuthInterfaceTest035, TestSize.Level0) ASSERT_NE(res, HC_SUCCESS); } +HWTEST_F(DeviceAuthInterfaceTest, DeviceAuthInterfaceTest036, TestSize.Level0) +{ + HandleCacheCommonEvent(); + HandleCacheCommonEventInner(TEST_EVENT_NAME, 0); +} + class AvInterfaceTest : public testing::Test { public: static void SetUpTestCase(); diff --git a/test/unittest/deviceauth/source/os_account_adapter_mock.c b/test/unittest/deviceauth/source/os_account_adapter_mock.c index 01e75a31..4811fc85 100644 --- a/test/unittest/deviceauth/source/os_account_adapter_mock.c +++ b/test/unittest/deviceauth/source/os_account_adapter_mock.c @@ -17,6 +17,16 @@ #include "device_auth.h" #include "device_auth_defines.h" +void NotifyOsAccountUnlocked(int32_t osAccountId) +{ + (void)osAccountId; +} + +void NotifyOsAccountRemoved(int32_t osAccountId) +{ + (void)osAccountId; +} + int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId) { return inputId; diff --git a/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn b/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn index e121a540..8ecc7f88 100644 --- a/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn +++ b/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("creds_manager_test") { ] sources = deviceauth_files + sources += sa_load_on_demand_mock_files sources += identity_service_mock_files sources += [ "creds_manager_test.cpp" ] sources += hal_common_files diff --git a/test/unittest/tdd_framework/unit_test/services/frameworks/os_account_adapter/BUILD.gn b/test/unittest/tdd_framework/unit_test/services/frameworks/os_account_adapter/BUILD.gn index 3edcf55f..4e6e4584 100644 --- a/test/unittest/tdd_framework/unit_test/services/frameworks/os_account_adapter/BUILD.gn +++ b/test/unittest/tdd_framework/unit_test/services/frameworks/os_account_adapter/BUILD.gn @@ -30,6 +30,8 @@ if (support_os_account) { include_dirs += [ "${dev_frameworks_path}/inc/net_observer" ] sources = deviceauth_files + sources += cache_common_event_handler_mock_files + sources += critical_handler_mock_files sources += identity_service_mock_files sources += hal_common_files sources += hiview_adapter_files -- Gitee