From c42b9005671423d236e1eb9df5755bf31a0f5999 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Mon, 28 Jul 2025 12:32:32 +0800 Subject: [PATCH] Modify the problem about service dead Signed-off-by: wuzhihuitmac Change-Id: I0c1a2d7071f610d1d220df1da6f355976d26cefa --- frameworks/native/BUILD.gn | 1 - .../native/include/sensor_service_client.h | 3 + .../native/include/sensor_service_load.h | 41 ------ .../native/src/sensor_service_client.cpp | 97 ++++++++----- frameworks/native/src/sensor_service_load.cpp | 80 ----------- test/unittest/interfaces/inner_api/BUILD.gn | 35 +++-- .../inner_api/load_sensor_service_test.cpp | 104 -------------- .../inner_api/sensor_service_client_test.cpp | 128 ++++++++++++++++++ 8 files changed, 224 insertions(+), 265 deletions(-) delete mode 100644 frameworks/native/include/sensor_service_load.h delete mode 100644 frameworks/native/src/sensor_service_load.cpp delete mode 100644 test/unittest/interfaces/inner_api/load_sensor_service_test.cpp create mode 100644 test/unittest/interfaces/inner_api/sensor_service_client_test.cpp diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index 74f6b1bb..74a921a9 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -54,7 +54,6 @@ ohos_shared_library("libsensor_client") { "src/sensor_event_handler.cpp", "src/sensor_file_descriptor_listener.cpp", "src/sensor_service_client.cpp", - "src/sensor_service_load.cpp", ] sources += filter_include(output_values, [ "*_proxy.cpp" ]) diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index fcacdb83..8fa645e8 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -20,6 +20,7 @@ #include "iservice_registry.h" #include "singleton.h" +#include "system_ability_load_callback_stub.h" #include "sensor_basic_info.h" #include "sensor_client_stub.h" @@ -66,6 +67,8 @@ private: void ReenableSensor(); void WriteHiSysIPCEvent(ISensorServiceIpcCode code, int32_t ret); void WriteHiSysIPCEventSplit(ISensorServiceIpcCode code, int32_t ret); + int32_t DealAfterServiceAlive(); + bool LoadSensorService(); std::mutex clientMutex_; sptr serviceDeathObserver_ = nullptr; sptr sensorServer_ = nullptr; diff --git a/frameworks/native/include/sensor_service_load.h b/frameworks/native/include/sensor_service_load.h deleted file mode 100644 index 4d120444..00000000 --- a/frameworks/native/include/sensor_service_load.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 SENSOR_SERVICE_LOAD_H -#define SENSOR_SERVICE_LOAD_H - -#include "iremote_object.h" -#include "singleton.h" -#include "system_ability_load_callback_stub.h" - -namespace OHOS { -namespace Sensors { -class SensorLoadCallback : public SystemAbilityLoadCallbackStub { -public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; -}; - -class SensorServiceLoad : public Singleton { -public: - ~SensorServiceLoad() override; - int32_t LoadSensorService(void); - void SetLoadFinish(void); -private: - std::atomic isSensorServiceLoading_ = false; -}; -} // namespace Sensors -} // namespace OHOS -#endif // SENSOR_SERVICE_LOAD_H diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index ef54eb57..1da2452e 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -23,7 +23,6 @@ #include "hitrace_meter.h" #endif // HIVIEWDFX_HITRACE_ENABLE #include "sensor_agent_proxy.h" -#include "sensor_service_load.h" #include "system_ability_definition.h" #undef LOG_TAG @@ -46,10 +45,9 @@ extern "C" { } } #endif // OHOS_BUILD_ENABLE_RUST +constexpr int32_t LOADSA_TIMEOUT_MS = 10000; } // namespace -#define SEN_SERVICE_LOAD SensorServiceLoad::GetInstance() - SensorServiceClient::~SensorServiceClient() { if (sensorServer_ != nullptr && serviceDeathObserver_ != nullptr) { @@ -62,6 +60,27 @@ SensorServiceClient::~SensorServiceClient() Disconnect(); } +int32_t SensorServiceClient::DealAfterServiceAlive() +{ + CALL_LOG_ENTER; + serviceDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); + CHKPR(serviceDeathObserver_, SENSOR_NATIVE_GET_SERVICE_ERR); + sptr remoteObject = sensorServer_->AsObject(); + CHKPR(remoteObject, SENSOR_NATIVE_GET_SERVICE_ERR); + remoteObject->AddDeathRecipient(serviceDeathObserver_); + sensorList_.clear(); + int32_t ret = sensorServer_->GetSensorList(sensorList_); + WriteHiSysIPCEvent(ISensorServiceIpcCode::COMMAND_GET_SENSOR_LIST, ret); + if (sensorList_.empty()) { + SEN_HILOGW("sensorList_ is empty when connecting to the service for the first time"); + } + ret = TransferClientRemoteObject(); + if (ret != ERR_OK) { + SEN_HILOGE("TransferClientRemoteObject failed, ret:%{public}d", ret); + } + return ret; +} + int32_t SensorServiceClient::InitServiceClient() { CALL_LOG_ENTER; @@ -78,39 +97,55 @@ int32_t SensorServiceClient::InitServiceClient() if (sensorClientStub_ == nullptr) { sensorClientStub_ = new (std::nothrow) SensorClientStub(); } - auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); CHKPR(systemAbilityManager, SENSOR_NATIVE_SAM_ERR); - sensorServer_ = iface_cast(systemAbilityManager->GetSystemAbility(SENSOR_SERVICE_ABILITY_ID)); - if (sensorServer_ != nullptr) { - SEN_HILOGD("Get service success"); - serviceDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); - CHKPR(serviceDeathObserver_, SENSOR_NATIVE_GET_SERVICE_ERR); - auto remoteObject = sensorServer_->AsObject(); - CHKPR(remoteObject, SENSOR_NATIVE_GET_SERVICE_ERR); - remoteObject->AddDeathRecipient(serviceDeathObserver_); - sensorList_.clear(); - int32_t ret = sensorServer_->GetSensorList(sensorList_); - WriteHiSysIPCEvent(ISensorServiceIpcCode::COMMAND_GET_SENSOR_LIST, ret); - if (sensorList_.empty()) { - SEN_HILOGW("sensorList_ is empty when connecting to the service for the first time"); - } - ret = TransferClientRemoteObject(); - if (ret != ERR_OK) { - SEN_HILOGE("TransferClientRemoteObject failed, ret:%{public}d", ret); - return ret; + sensorServer_ = iface_cast(systemAbilityManager->CheckSystemAbility(SENSOR_SERVICE_ABILITY_ID)); + if (sensorServer_ == nullptr) { + if (!LoadSensorService()) { + SEN_HILOGE("LoadSensorService failed"); +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "SERVICE_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "InitServiceClient", "ERROR_CODE", + SENSOR_NATIVE_GET_SERVICE_ERR); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + return SENSOR_NATIVE_GET_SERVICE_ERR; } return ERR_OK; } - if (SEN_SERVICE_LOAD.LoadSensorService() != ERR_OK) { - SEN_HILOGE("LoadSensorService failed"); + SEN_HILOGD("Get service success"); + int32_t ret = DealAfterServiceAlive(); + if (ret != ERR_OK) { + SEN_HILOGE("DealAfterServiceAlive failed, ret:%{public}d", ret); } - SEN_HILOGW("Get service failed"); -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "SERVICE_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "InitServiceClient", "ERROR_CODE", SENSOR_NATIVE_GET_SERVICE_ERR); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - SEN_HILOGE("Get service failed"); - return SENSOR_NATIVE_GET_SERVICE_ERR; + return ret; +} + +bool SensorServiceClient::LoadSensorService() +{ + SEN_HILOGI("LoadSensorService in"); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + SEN_HILOGE("samgr is nullptr"); + return false; + } + auto sensorSa = samgr->LoadSystemAbility(SENSOR_SERVICE_ABILITY_ID, LOADSA_TIMEOUT_MS); + if (sensorSa == nullptr) { + SEN_HILOGE("Load sensor sa failed"); + return false; + } + sensorServer_ = iface_cast(sensorSa); + if (sensorServer_ == nullptr) { + SEN_HILOGI("LoadSensorService out"); + return false; + } + SEN_HILOGW("LoadSensorService success"); + int32_t ret = DealAfterServiceAlive(); + if (ret != ERR_OK) { + SEN_HILOGE("DealAfterServiceAlive failed, ret:%{public}d", ret); + return false; + } + return true; } bool SensorServiceClient::IsValid(const SensorDescription &sensorDesc) diff --git a/frameworks/native/src/sensor_service_load.cpp b/frameworks/native/src/sensor_service_load.cpp deleted file mode 100644 index 3bed68fc..00000000 --- a/frameworks/native/src/sensor_service_load.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 "sensor_service_load.h" - -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "sensor_errors.h" -#include "sensor_log.h" -#include "system_ability_definition.h" - -#undef LOG_TAG -#define LOG_TAG "SensorServiceLoad" - -namespace OHOS { -namespace Sensors { - -#define SEN_SERVICE_LOAD SensorServiceLoad::GetInstance() - -SensorServiceLoad::~SensorServiceLoad() {} - -int32_t SensorServiceLoad::LoadSensorService(void) -{ - if (isSensorServiceLoading_) { - SEN_HILOGI("Sensor service is loading."); - return ERR_OK; - } - SEN_HILOGI("start"); - isSensorServiceLoading_ = true; - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - isSensorServiceLoading_ = false; - SEN_HILOGE("Failed to get system ability mgr"); - return SENSOR_NATIVE_SAM_ERR; - } - sptr sensorLoadCallback(new SensorLoadCallback()); - int32_t ret = samgr->LoadSystemAbility(SENSOR_SERVICE_ABILITY_ID, sensorLoadCallback); - if (ret != ERR_OK) { - isSensorServiceLoading_ = false; - SEN_HILOGE("Failed to load sensor service, ret code:%{public}d", ret); - return ret; - } - return ERR_OK; -} - -void SensorServiceLoad::SetLoadFinish(void) -{ - isSensorServiceLoading_ = false; -} - -void SensorLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const sptr &remoteObject) -{ - SEN_HILOGI("Load sensor service success remoteObject result:%{public}s", - (remoteObject != nullptr) ? "true" : "false"); - SEN_SERVICE_LOAD.SetLoadFinish(); - if (remoteObject == nullptr) { - SEN_HILOGE("remoteObject is nullptr"); - } -} - -void SensorLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - SEN_HILOGE("Load sensor service failed."); - SEN_SERVICE_LOAD.SetLoadFinish(); -} -} // namespace Sensors -} // namespace OHOS diff --git a/test/unittest/interfaces/inner_api/BUILD.gn b/test/unittest/interfaces/inner_api/BUILD.gn index b326fc8f..7290465b 100644 --- a/test/unittest/interfaces/inner_api/BUILD.gn +++ b/test/unittest/interfaces/inner_api/BUILD.gn @@ -211,29 +211,48 @@ ohos_unittest("DropDetectionTest") { ] } -ohos_unittest("LoadSensorServiceTest") { +ohos_unittest("SensorServiceClientTest") { module_out_path = "sensor/sensor/interfaces/inner_api" - - sources = ["$SUBSYSTEM_DIR/test/unittest/interfaces/inner_api/load_sensor_service_test.cpp"] - + sources = ["$SUBSYSTEM_DIR/test/unittest/interfaces/inner_api/sensor_service_client_test.cpp"] include_dirs = [ - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", + "${target_gen_dir}", "$SUBSYSTEM_DIR/frameworks/native/include", + "$SUBSYSTEM_DIR/interfaces/inner_api", "$SUBSYSTEM_DIR/test/unittest/common/include", + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/utils/ipc/include", + ] + + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", ] deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_target", + "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", + "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", + "$SUBSYSTEM_DIR/frameworks/native:sensor_service_stub", + "$SUBSYSTEM_DIR/services:libsensor_service_static", "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken_shared", + "access_token:libtokensetproc_shared", "c_utils:utils", + "drivers_interface_sensor:libsensor_proxy_3.0", + "eventhandler:libeventhandler", "googletest:gmock", "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_single", + "safwk:system_ability_fwk", "samgr:samgr_proxy", ] } @@ -298,7 +317,7 @@ group("unittest") { ":Ambientlight1Test", ":DropDetectionTest", ":HeadPostureTest", - ":LoadSensorServiceTest", + ":SensorServiceClientTest", ":PostureTest", ":Proximity1Test", ":RPCSensorTest", diff --git a/test/unittest/interfaces/inner_api/load_sensor_service_test.cpp b/test/unittest/interfaces/inner_api/load_sensor_service_test.cpp deleted file mode 100644 index 7c24e0ad..00000000 --- a/test/unittest/interfaces/inner_api/load_sensor_service_test.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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 -#include - -#include -#include - -#include "sensor_agent.h" -#include "sensor_agent_type.h" -#include "sensor_errors.h" -#include "sensor_service_load.h" -#include "system_ability_definition.h" - -#undef LOG_TAG -#define LOG_TAG "LoadSensorServiceTest" - -namespace OHOS { -namespace Sensors { -using namespace testing; -using namespace testing::ext; -using namespace OHOS::HiviewDFX; - -class LoadSensorServiceTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - SensorServiceLoad *sensorServiceLoad; - SensorLoadCallback *callback; -}; - -void LoadSensorServiceTest::SetUpTestCase() -{ -} - -void LoadSensorServiceTest::TearDownTestCase() -{ -} - -void LoadSensorServiceTest::SetUp() -{ - sensorServiceLoad = new (std::nothrow) SensorServiceLoad(); - ASSERT_NE(sensorServiceLoad, nullptr); - callback = new (std::nothrow) SensorLoadCallback(); - ASSERT_NE(callback, nullptr); -} - -void LoadSensorServiceTest::TearDown() -{ - if (sensorServiceLoad != nullptr) { - delete sensorServiceLoad; - sensorServiceLoad = nullptr; - } - if (callback!= nullptr) { - delete callback; - callback = nullptr; - } -} - -HWTEST_F(LoadSensorServiceTest, SetLoadFinishTest_001, TestSize.Level1) -{ - SEN_HILOGI("SetLoadFinishTest_001 enter"); - ASSERT_NO_FATAL_FAILURE(sensorServiceLoad->SetLoadFinish()); -} - -HWTEST_F(LoadSensorServiceTest, OnLoadSystemAbilitySuccessTest_001, TestSize.Level1) -{ - SEN_HILOGI("OnLoadSystemAbilitySuccessTest_001 enter"); - int32_t systemAbilityId = 1; - sptr remoteObject = new (std::nothrow) IPCObjectStub(); - ASSERT_NO_FATAL_FAILURE(callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject)); -} - -HWTEST_F(LoadSensorServiceTest, OnLoadSystemAbilitySuccessTest_002, TestSize.Level1) -{ - SEN_HILOGI("OnLoadSystemAbilitySuccessTest_002 enter"); - int32_t systemAbilityId = 1; - sptr remoteObject = new (std::nothrow) IPCObjectStub(); - ASSERT_NO_FATAL_FAILURE(callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject)); -} - -HWTEST_F(LoadSensorServiceTest, OnLoadSystemAbilityFailTest_001, TestSize.Level1) -{ - SEN_HILOGI("OnLoadSystemAbilityFailTest_001 enter"); - int32_t systemAbilityId = 1; - ASSERT_NO_FATAL_FAILURE(callback->OnLoadSystemAbilityFail(systemAbilityId)); -} -} // namespace Sensors -} // namespace OHOS diff --git a/test/unittest/interfaces/inner_api/sensor_service_client_test.cpp b/test/unittest/interfaces/inner_api/sensor_service_client_test.cpp new file mode 100644 index 00000000..8d42a141 --- /dev/null +++ b/test/unittest/interfaces/inner_api/sensor_service_client_test.cpp @@ -0,0 +1,128 @@ +/* + * 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 +#include + +#include +#include + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include "sensor_errors.h" +#include "sensor_service_client.h" +#include "system_ability_definition.h" + +#undef LOG_TAG +#define LOG_TAG "SensorServiceClientTest" + +namespace OHOS { +namespace Sensors { +using namespace testing; +using namespace testing::ext; +using namespace OHOS::HiviewDFX; + +namespace { +static sptr g_remote = new (std::nothrow) IPCObjectStub(); +} // namespace + +class SensorServiceClientTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + SensorServiceClient *sensorServiceClient; +}; + +void SensorServiceClientTest::SetUpTestCase() +{ +} + +void SensorServiceClientTest::TearDownTestCase() +{ +} + +void SensorServiceClientTest::SetUp() +{ + sensorServiceClient = new (std::nothrow) SensorServiceClient(); + ASSERT_NE(sensorServiceClient, nullptr); +} + +void SensorServiceClientTest::TearDown() +{ + if (sensorServiceClient != nullptr) { + delete sensorServiceClient; + sensorServiceClient = nullptr; + } +} + +HWTEST_F(SensorServiceClientTest, InitServiceClientTest_001, TestSize.Level1) +{ + SEN_HILOGI("InitServiceClientTest_001 in"); + sensorServiceClient->sensorServer_ = iface_cast(g_remote); + sensorServiceClient->sensorList_.clear(); + int32_t ret = sensorServiceClient->InitServiceClient(); + EXPECT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorServiceClientTest, InitServiceClientTest_002, TestSize.Level1) +{ + SEN_HILOGI("InitServiceClientTest_002 in"); + sensorServiceClient->sensorServer_ = iface_cast(g_remote); + Sensor sensor; + sensorServiceClient->sensorList_.push_back(sensor); + int32_t ret = sensorServiceClient->InitServiceClient(); + EXPECT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorServiceClientTest, InitServiceClientTest_003, TestSize.Level1) +{ + SEN_HILOGI("InitServiceClientTest_003 in"); + sensorServiceClient->sensorServer_ = iface_cast(g_remote); + int32_t ret = sensorServiceClient->InitServiceClient(); + EXPECT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorServiceClientTest, InitServiceClientTest_004, TestSize.Level1) +{ + SEN_HILOGI("InitServiceClientTest_004 in"); + sensorServiceClient->sensorServer_ = nullptr; + int32_t ret = sensorServiceClient->InitServiceClient(); + EXPECT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorServiceClientTest, InitServiceClientTest_005, TestSize.Level1) +{ + SEN_HILOGI("InitServiceClientTest_005 in"); + auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_NE(systemAbilityManager, nullptr); + auto sa = systemAbilityManager->CheckSystemAbility(SENSOR_SERVICE_ABILITY_ID); + EXPECT_NE(sa, nullptr); + sensorServiceClient->sensorServer_ = iface_cast(sa); + EXPECT_NE(sensorServiceClient->sensorServer_, nullptr); + int32_t ret = sensorServiceClient->InitServiceClient(); + EXPECT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorServiceClientTest, LoadSensorServiceTest_001, TestSize.Level1) +{ + SEN_HILOGI("LoadSensorServiceTest_001 in"); + sensorServiceClient->sensorServer_ = nullptr; + int32_t ret = sensorServiceClient->LoadSensorService(); + EXPECT_EQ(ret, ERR_OK); +} +} // namespace Sensors +} // namespace OHOS -- Gitee