diff --git a/bundle.json b/bundle.json index 3a7de2fc2d71d1598ca6e72ea57cc535e46dadb5..46e5df6587d6be19715f4f8d74c208587059ed49 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 2890f069f59e311e04da76e9b5724b9982be5933..9230555ac19acabd3f4230417a47d4359019f6b9 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::recursive_mutex instanceMutex_; + bool isUnloading_{false}; }; } // namespace OHOS diff --git a/frameworks/inc/ipc_sdk_defines.h b/frameworks/inc/ipc_sdk_defines.h index 8e56706ee238cca17261675ecd74d7b1e7a8da43..69ae0c01756ac0654f9891a7d84379de076f560d 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 7439ee65216b1286b1d4740086f1c74f85546fd1..97fbe8378e8caf470445ac40d694c601136b87ed 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 0000000000000000000000000000000000000000..bdd7a448cfe0d3dbae57a77662b2ac5fb288247a --- /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 0000000000000000000000000000000000000000..dc0c412e888c5f80bc2e03cba0951e578efede4f --- /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 0000000000000000000000000000000000000000..1f77edf753bd3e40d8be8bd88d8eef4d24b34184 --- /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 0000000000000000000000000000000000000000..4c4403df0dbab61fdae3bea388daa97be7787ce1 --- /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 0000000000000000000000000000000000000000..24604e3a44557f883191a3cb406bcbe9ab1eaa44 --- /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; +} + +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); +} + +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; +} + +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 d30e1ee6478790cb7d1faf6a7ed3f9b457f598b0..be7811c8bb1e406f15ce4dd7dbc5f5be4460eed1 100644 --- a/frameworks/src/deviceauth_sa.cpp +++ b/frameworks/src/deviceauth_sa.cpp @@ -28,16 +28,26 @@ #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 { +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; +} -static const uint32_t RESTORE_CODE = 14701; using IpcCallMap = struct { int32_t (*func)(const IpcDataInfo*, int32_t, uintptr_t); uint32_t id; @@ -94,10 +104,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 +134,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; + } + auto unloadRunner = AppExecFwk::EventRunner::Create(DEVAUTH_UNLOAD_SA_HANDLER); + if (unloadRunner == nullptr) { + LOGE("Create unloadRunner failed."); + return false; } - return g_instance; + 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 +229,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."); } @@ -222,6 +256,8 @@ static void DevAuthInitMemoryPolicy(void) int32_t DeviceAuthAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + std::lock_guard lock(instanceMutex_); + DelayUnload(); DevAuthInitMemoryPolicy(); std::u16string readToken = data.ReadInterfaceToken(); @@ -230,19 +266,63 @@ int32_t DeviceAuthAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, M LOGE("DeviceAuthAbility [IPC][C->S]: The proxy interface token is invalid!"); return -1; } + if (isUnloading_) { + LOGW("sa is unloading, need to retry."); + return HC_ERR_IPC_SA_IS_UNLOADING; + } + 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 "s.", + activeReason.GetName().c_str(), isUnloading_ ? "YES" : "NO"); + isUnloading_ = false; +} + +int32_t DeviceAuthAbility::OnIdle(const SystemAbilityOnDemandReason &idleReason) +{ + std::lock_guard lock(instanceMutex_); + isUnloading_ = GetCriticalCnt() > 0 ? false : true; + LOGI("OnIdle, idleReason name is %" LOG_PUB "s, isUnloading is %" LOG_PUB "s.", + idleReason.GetName().c_str(), isUnloading_ ? "YES" : "NO"); + if (isUnloading_) { + return HC_SUCCESS; } + return SA_REFUSE_TO_UNLOAD; } void DeviceAuthAbility::OnStop() { + std::lock_guard lock(instanceMutex_); LOGI("DeviceAuthAbility OnStop"); - DeviceAuthAbility::DestroyInstance(); + DestroyUnloadHandler(); + 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 7fb393e06090ffc469d3501cc544de56257c5bb7..6f5931f165ae1d5900b35a739a88217ccb7cf2b1 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 7c4b4b045761b7b9effdfaf5524131a16a5afa31..563bffcca4e571cd377a2c8fdf2d240753d4f631 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 1edb6323389df1ea06ecba2460b3a2ebad909ff1..fe6c7a82c72f139882e53a883b7660fe8bb6715e 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 bcac62aa66685be9834c0680ea546cc66f417830..9589a4a0710534a142cf65caa600ec5719552abe 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 2775506498fd87ccba5ccd9fba47189631e0faec..c9bbc1345e9e331fb56ff165732c76d0b930c966 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 ec80585f9b98755df159d9a8face597dc9e6041d..aeb7c4c1c6422c274ecf44ed86b6f1e7b20594cc 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,11 @@ if (os_level == "mini" || os_level == "small") { sources += sa_subscriber_files sources += net_observer_files } + if (timeline_memmgr_enable) { + sources += sa_load_on_demand_files + } else { + sources += sa_load_on_demand_mock_files + } sources += permission_adapter_files sources += identity_service_files sources += hiview_adapter_files @@ -246,8 +259,12 @@ if (os_level == "mini" || os_level == "small") { "netmanager_base:net_conn_manager_if", "os_account:os_account_innerkits", "samgr:samgr_proxy", + "safwk:system_ability_fwk", ] } + if (timeline_memmgr_enable) { + external_deps += [ "memmgr:memmgrclient" ] + } } ohos_prebuilt_etc("pre_deviceauth_service") { @@ -266,6 +283,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 +293,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 +393,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 0543433f2d813040675dd2f9ac6f6eaa899e1494..bd37c3f621b5cec357a7d38fc8327b654cd76399 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 d0874fa36ed82ab372cd3e15abcb66ceeb364f5d..14c3e19e3ab16c798fec9d3f17bd4071daae45b7 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", @@ -470,6 +484,13 @@ if (defined(global_parts_info) && common_event_enabled = false } +if (defined(global_parts_info) && + defined(global_parts_info.resourceschedule_memmgr_override)) { + timeline_memmgr_enable = true +} else { + timeline_memmgr_enable = false +} + if (defined(ohos_lite)) { deviceauth_files += security_label_adapter_mock_files } else { diff --git a/services/deviceauth_service.cfg b/services/deviceauth_service.cfg index 64691eb24485bc3b693d8046715b9cf7dad4c66f..c7f573c56c333100bf4011e7fddafef43b97fab0 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 9241f1fb1a5b183041972d8d3542080a7ebccd93..24b0d10643d8241c43038bcd366cdcd34df0d2f0 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 3e739ac3a1eefabc469d4af9530e4567303bbc88..6370dfe55e1a7f6dccdbefa507209cb73d882885 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 7490d5ab0a000eda59914d4a5c36278308c5f3f1..2a753a45754884b05425a9a7c70085ae99cf0241 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 1a924f2cede0fe2980d53b365bfafb0727e02d12..7dcd7b146f707a046b949b8db491c6ab5ae1f01b 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 0000000000000000000000000000000000000000..e525fe8c9efe53533fa936eff9b65b62985d3f95 --- /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 0000000000000000000000000000000000000000..5518f648a9e42cbb32ea0484267dd3c216b616c7 --- /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 6cf2ac463290a20a9bf5ca4fe5eef9b9f04dc6f5..3fb7f9c3f8a310aad80de0d2c1bb10f5c72c9b06 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 0000000000000000000000000000000000000000..8d93c65fc0d4e46c8e53bf33b6e36d3623e68f4d --- /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 "u", 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 0000000000000000000000000000000000000000..9d6f4959b4300ebfa3c13f9d7ef333530ce7fa32 --- /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 0000000000000000000000000000000000000000..1a3e0dcb4314fe9a24b3f25f1d8f3ce476921bc8 --- /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 0000000000000000000000000000000000000000..c0810c60740947372ced28c1761cb8f06b085928 --- /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 f31d0662912e96b06767821a4239a76b5b15ad88..b21db6e8ee914a0e2fe7a2eba078dd0adf4f4069 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 6939de61432032ee07c6983a1f25a18994f952c5..51e650465bf2b9579c655afb01b78adb82ce5b48 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 846fc6ddb3be7a93a90488607a742fbadb3dad38..98a0a251011f603223849d4689b5ef146d2d9b47 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 3fef77e631080736b77de52d186aae380e63f962..9f3434d202cd75d1c388f833e117a6a94e3845e3 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 1f184582608e5ddade113933526830600079871c..a6472ab4e8f9c8c1381ea9f05ded1fb49dfb08e9 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 c001b255924e8d3a560f6e7c76031016beed5e3a..135c76e6528423ebf7c2fd8c3e82875c617e1df9 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 0ef43d6aa9ee09ccd541fac4a60c2d85b7430ac2..114c4a72f00c3688d4d06c5c588fff52d1baa05b 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 dbdd9876342a79ddc3b08bd7f88e47be3d6136f6..83245ed13c30750beba2b2c912f1398e13a45261 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 a783406820ba78451866155a41d284cda13884dc..70a55ce52f4c503fb6224e158af723bac1bff5e0 100644 --- a/test/fuzztest/devauthinterface_fuzzer/BUILD.gn +++ b/test/fuzztest/devauthinterface_fuzzer/BUILD.gn @@ -28,6 +28,7 @@ ohos_fuzztest("DevAuthInterfaceFuzzTest") { include_dirs += hals_inc_path include_dirs += [ + ".", "../../unittest/deviceauth/include", "${dev_frameworks_path}/inc/hiview_adapter", "${frameworks_path}/inc/standard", @@ -70,6 +71,7 @@ ohos_fuzztest("DevAuthInterfaceFuzzTest") { sources += soft_bus_channel_files sources += deviceauth_ipc_files sources += permission_adapter_files + sources += sa_load_on_demand_mock_files sources += group_auth_files sources += group_auth_account_unrelated_files @@ -147,6 +149,8 @@ ohos_fuzztest("DevAuthInterfaceFuzzTest") { "mbedtls:mbedtls_shared", "openssl:libcrypto_static", "samgr:samgr_proxy", + "common_event_service:cesfwk_innerkits", + "safwk:system_ability_fwk", ] } diff --git a/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn index f4e20b371c07fdca788392b0cc9077a1d92ab455..84ac5491812866c94d4c4cea52ff44c91293890f 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 a1b0e11ae2f171d1c62c2fbf39aa0f9a36014a05..46a46db3179cdae2a17dc2aaa00d8d9a8c29d4a6 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 b3d48db1a49edf03e2bb8ce89ad23e4bc320eb42..7c7a4f7d43e67ae7bf55bc82d774d5db767a4d4e 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 999e35f8612027e3787d81611c15225e5cdc02d6..a261c5b8e7b3742791f1abafb9c8f66e2f045363 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 ba9ad6f63a8ff59aacd8020582446b82de6f9b2f..cffa2799031c53abf5c677a34a112cac7bcf761d 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 80332d3b0a438db8698b18da291b85ddfb73aaf8..8797b792ab008736c8adfd3b861d6a30204feb90 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 ead7366807867c0a87ea456b9a9b8421e1dc56cd..26a44da9437a9427ff0830ca7e8c65e9f1045db6 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 24eaa6747e682847d65bce128954017bfad3fccc..6dc7d86ccd3b6543330478bdca37ccc71a02d1c7 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 f35aa9fc7f525df5f5d036af9c46c85629283860..87bfd47b9842f6dc642f1d22915f68f613339611 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 80a3f4129dff726959dea839d1f4a04a383f3e19..808db63358357dca3c9df358a781de41473fbeb6 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 ef6b68f7a9e4316622aa39671e22a768c6ecaa0e..9bb23bd3c7c87511172b14b9c15224c0d19c0c10 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 80d036b3f802c11c60c9439391f1ae460caa39c9..442e0a30d32d9bf4ef04a171dc194ac6a689c595 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 0d8908e756a7d7dd4b1902f1e018fabeb52ffecf..2c1122ba81b81b0611090ea4295496aa1992ae36 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 41a870e21a2e0839ddf2d72af337f2f2eb4f2133..5b5cebf144ca18c62777a8d01bfbfae3c7c7d730 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 5a399cbf170d29eb16c0ad9c5988446b21f23909..0710cc3695e1108021a560288b4cd71a605c47a4 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 81083fda26a013ed6f2fa6bd24735d289c0c0c30..6a4735cd8aa17926cc478a3026ec50888a93f28b 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 fab1839eea4612841214dc8654cd32af3aa5bb45..ad7908b3035f07f44382c6430f3f771b8b6d33ae 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 dfecb3a053f3a8154a4d6c356ee8691ff8be98fb..764273f3e690e23148574f1c827c2898345b85b1 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 d71f68b0de632c1d2d460bcd8ee4529f7551143a..bccab43bcec3be8a243def32734596575fbddf3f 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 e6dac9a4f13984b3de83e2e6fa9db0f1f9268ea5..c8aaf8ed8e63865eb2a7e8b959c92809074648b7 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 786a4f4e6bbbeaff0012917d44c29f2fd359f868..5dd805deeaa15783ef6a150aea29fb6208dd5247 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 6c0e54c036eb4bb0c58b4b41ca9a7e225c747595..6591748a74b4c91f64940da94e10b4ba2f4f87ff 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 3682f62d11ce746bd34ee3c55607fb77d03ac930..1887f0d14c90e53848fb3446c984cd1468ad029e 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 6049597665a3bedfffe76e0e7cb099c1f45b69d8..36a810c0e2d6ad0c1720d3c3d4e9770e6043b784 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 271e9a1270b008503cd2caf57af70c9c93bdfce2..8ba1d439401df87f1fadb3f23039e1bf2c8bb37f 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 f6d57ba6b25fe054ce561a17d6fc1c1e16ac739a..1481d41fb2c87ac5e79401ae8016194e68ad9d1b 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 920b7c7081372bbded039e1bea39688389799bb0..3b589e592df85f03776aeada28b148b2d9ae8a4c 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 3aa6e246e5ae6de232d9530d207a91adc8e9ac4a..f41e068104300a5e880d91ed8e071f39db194f8f 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 a6e957c172e69b4cdb08416eaad65118a2a5a714..52ac5e9abc8bf511cfc157f474be69323c3e9f6a 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 2b1eeca7b96249da0495af92b0732b2046b7c4da..74e67c1f6f32e9596c0ed40ca64380177089723b 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 ab5c600d2b7a49a27be9f4c6e45a45e828dbf22b..b91ea366126acf309c06373659f090c447d1fbc6 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,7 @@ ohos_unittest("device_auth_interface_test") { sources += soft_bus_channel_files sources += deviceauth_ipc_files sources += permission_adapter_files + sources += critical_handler_mock_files sources += group_auth_files sources += group_auth_account_unrelated_files @@ -507,7 +511,6 @@ ohos_unittest("device_auth_interface_test") { "ENABLE_PSEUDONYM", "DEV_AUTH_HIVIEW_ENABLE", ] - sources += identity_manager_files include_dirs += identity_manager_inc sources += [ "source/deviceauth_interface_test.cpp" ] @@ -537,6 +540,8 @@ ohos_unittest("device_auth_interface_test") { "mbedtls:mbedtls_shared", "openssl:libcrypto_static", "samgr:samgr_proxy", + "common_event_service:cesfwk_innerkits", + "safwk:system_ability_fwk", ] } @@ -575,6 +580,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 bc043433f45ba8a02ec500aca11b1a1ef9621b0f..5823e39c07ec222d051e6c9fc65559ca128c427c 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 15d3784f5f0f20a404f0e61f5bde80fcf1c0b99a..4aad85bd74a87ef583b198f849275cd897609f86 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 01e75a31e0495a5ef30d11c9421958b4a4078452..4811fc85f9b0e8c3557720e2b85baf3d5e0fc673 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 e121a5402761cf5737e7de3aeff5eb9ac28670e8..8ecc7f88bb9399c47035f888e11b0812801e6f8b 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 3edcf55f46e6e4e8364625602d7729287116e4ed..0e9db739dcaab03b4833504499737c8ab6debc0f 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,7 @@ if (support_os_account) { include_dirs += [ "${dev_frameworks_path}/inc/net_observer" ] sources = deviceauth_files + sources += sa_load_on_demand_mock_files sources += identity_service_mock_files sources += hal_common_files sources += hiview_adapter_files