From be99335e9dff49782e013377782ac8365881e04d Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Tue, 12 Nov 2024 12:48:06 +0800 Subject: [PATCH] Remove retry fun Signed-off-by: wuzhihuitmac Change-Id: I082df8899c397c5fa2c704f7e6b7052566b9b7de --- frameworks/native/light/src/light_client.cpp | 29 +++++------- .../vibrator/src/vibrator_service_client.cpp | 45 ++++++++----------- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/frameworks/native/light/src/light_client.cpp b/frameworks/native/light/src/light_client.cpp index 4eb7e5e..32e5624 100644 --- a/frameworks/native/light/src/light_client.cpp +++ b/frameworks/native/light/src/light_client.cpp @@ -33,9 +33,7 @@ namespace OHOS { namespace Sensors { namespace { -constexpr int32_t GET_SERVICE_MAX_COUNT = 30; constexpr uint32_t MAX_LIGHT_LIST_SIZE = 0X00ff; -constexpr uint32_t WAIT_MS = 200; } // namespace LightClient::~LightClient() @@ -59,23 +57,16 @@ int32_t LightClient::InitLightClient() } auto systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); CHKPR(systemManager, MISC_NATIVE_SAM_ERR); - int32_t retry = 0; - while (retry < GET_SERVICE_MAX_COUNT) { - miscdeviceProxy_ = iface_cast(systemManager->GetSystemAbility( - MISCDEVICE_SERVICE_ABILITY_ID)); - if (miscdeviceProxy_ != nullptr) { - MISC_HILOGD("miscdeviceProxy_ get service success, retry:%{public}d", retry); - serviceDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); - CHKPR(serviceDeathObserver_, MISC_NATIVE_GET_SERVICE_ERR); - auto remoteObject = miscdeviceProxy_->AsObject(); - CHKPR(remoteObject, MISC_NATIVE_GET_SERVICE_ERR); - remoteObject->AddDeathRecipient(serviceDeathObserver_); - lightInfoList_ = miscdeviceProxy_->GetLightList(); - return ERR_OK; - } - MISC_HILOGW("Get service failed, retry:%{public}d", retry); - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_MS)); - retry++; + miscdeviceProxy_ = iface_cast(systemManager->GetSystemAbility( + MISCDEVICE_SERVICE_ABILITY_ID)); + if (miscdeviceProxy_ != nullptr) { + serviceDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); + CHKPR(serviceDeathObserver_, MISC_NATIVE_GET_SERVICE_ERR); + auto remoteObject = miscdeviceProxy_->AsObject(); + CHKPR(remoteObject, MISC_NATIVE_GET_SERVICE_ERR); + remoteObject->AddDeathRecipient(serviceDeathObserver_); + lightInfoList_ = miscdeviceProxy_->GetLightList(); + return ERR_OK; } #ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_EXCEPTION", diff --git a/frameworks/native/vibrator/src/vibrator_service_client.cpp b/frameworks/native/vibrator/src/vibrator_service_client.cpp index 8a841e8..c78070f 100644 --- a/frameworks/native/vibrator/src/vibrator_service_client.cpp +++ b/frameworks/native/vibrator/src/vibrator_service_client.cpp @@ -39,8 +39,6 @@ namespace Sensors { using namespace OHOS::HiviewDFX; namespace { -constexpr int32_t GET_SERVICE_MAX_COUNT = 3; -constexpr uint32_t WAIT_MS = 200; #ifdef __aarch64__ static const std::string DECODER_LIBRARY_PATH = "/system/lib64/platformsdk/libvibrator_decoder.z.so"; #else @@ -80,32 +78,25 @@ int32_t VibratorServiceClient::InitServiceClient() MISC_HILOGE("sm cannot be null"); return MISC_NATIVE_SAM_ERR; } - int32_t retry = 0; - while (retry < GET_SERVICE_MAX_COUNT) { - miscdeviceProxy_ = iface_cast(sm->GetSystemAbility(MISCDEVICE_SERVICE_ABILITY_ID)); - if (miscdeviceProxy_ != nullptr) { - MISC_HILOGD("Get service success, retry:%{public}d", retry); - serviceDeathObserver_ = - new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); - CHKPR(serviceDeathObserver_, MISC_NATIVE_GET_SERVICE_ERR); - auto remoteObject = miscdeviceProxy_->AsObject(); - CHKPR(remoteObject, MISC_NATIVE_GET_SERVICE_ERR); - remoteObject->AddDeathRecipient(serviceDeathObserver_); - int32_t ret = TransferClientRemoteObject(); - if (ret != ERR_OK) { - MISC_HILOGE("TransferClientRemoteObject failed, ret:%{public}d", ret); - return ERROR; - } - ret = GetVibratorCapacity(); - if (ret != ERR_OK) { - MISC_HILOGE("GetVibratorCapacity failed, ret:%{public}d", ret); - return ERROR; - } - return ERR_OK; + miscdeviceProxy_ = iface_cast(sm->GetSystemAbility(MISCDEVICE_SERVICE_ABILITY_ID)); + if (miscdeviceProxy_ != nullptr) { + serviceDeathObserver_ = + new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); + CHKPR(serviceDeathObserver_, MISC_NATIVE_GET_SERVICE_ERR); + auto remoteObject = miscdeviceProxy_->AsObject(); + CHKPR(remoteObject, MISC_NATIVE_GET_SERVICE_ERR); + remoteObject->AddDeathRecipient(serviceDeathObserver_); + int32_t ret = TransferClientRemoteObject(); + if (ret != ERR_OK) { + MISC_HILOGE("TransferClientRemoteObject failed, ret:%{public}d", ret); + return ERROR; } - MISC_HILOGW("Get service failed, retry:%{public}d", retry); - std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_MS)); - retry++; + ret = GetVibratorCapacity(); + if (ret != ERR_OK) { + MISC_HILOGE("GetVibratorCapacity failed, ret:%{public}d", ret); + return ERROR; + } + return ERR_OK; } #ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_EXCEPTION", -- Gitee