From 801405602e99978cfad11d7135e5a52bc3d2845a Mon Sep 17 00:00:00 2001 From: "xiaocong.ran" Date: Thu, 17 Mar 2022 20:19:57 +0800 Subject: [PATCH 1/6] timer Signed-off-by: xiaocong.ran Change-Id: I0332a75fe7e834e53887ea8c69a87f938e904b39 --- common/include/dm_constants.h | 13 +++ .../dialog_ui/js/pages/index/index.js | 13 ++- .../dialog_ui/js/pages/index/index.js | 16 ++-- .../dialog_ui/js/pages/index/index.hml | 2 +- .../dialog_ui/js/pages/index/index.js | 14 +++- ext/pin_auth/src/pin_auth.cpp | 6 +- ext/pin_auth/src/pin_auth_ui.cpp | 8 +- .../include/dependency/timer/dm_timer.h | 2 + .../devicestate/dm_device_state_manager.h | 13 ++- .../src/authentication/dm_auth_manager.cpp | 72 +++++++++++----- .../src/dependency/timer/dm_timer.cpp | 83 ++++++++++++------- .../devicestate/dm_device_state_manager.cpp | 59 ++++++++----- .../src/discovery/dm_discovery_manager.cpp | 12 ++- 13 files changed, 211 insertions(+), 102 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 8883eeb3e..5e8b12431 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -84,6 +84,7 @@ enum { DM_AUTH_PEER_REJECT, DM_AUTH_NOT_AUTH, DM_AUTH_DONT_AUTH, + DM_AUTH_NOT_START, DM_SOFTBUS_FAILED = 3000, DM_SOFTBUS_CREATE_SESSION_SERVER_FAILED, DM_HICHAIN_FAILED = 4000, @@ -186,6 +187,18 @@ const int32_t ACE_X = 50; const int32_t ACE_Y = 300; const int32_t ACE_WIDTH = 600; const int32_t ACE_HEIGHT = 400; +const std::string EVENT_CONFIRM = "EVENT_CONFIRM"; +const std::string EVENT_CANCEL = "EVENT_CANCEL"; +const std::string EVENT_INIT = "EVENT_INIT"; +const std::string EVENT_CONFIRM_CODE = "0"; +const std::string EVENT_CANCEL_CODE = "1"; +const std::string EVENT_INIT_CODE = "2"; + +//timer +const std::string TIMER_PREFIX = "deviceManagerTimer:"; +const std::string STATE_TIMER_PREFIX = "stateTimer_"; +const int32_t TIMER_PREFIX_LENGTH = 19; +const int32_t TIMER_DEFAULT = 0; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js b/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js index 13a4384c5..536950498 100644 --- a/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js +++ b/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js @@ -4,9 +4,16 @@ var timel = null; export default { data: { seconds:60, + EVENT_CONFIRM:"EVENT_CONFIRM", + EVENT_CANCEL:"EVENT_CANCEL", + EVENT_INIT:"EVENT_INIT", + EVENT_CONFIRM_CODE:"0", + EVENT_CANCEL_CODE:"1", + EVENT_INIT_CODE:"2", }, onInit() { console.info('getParams: ' + router.getParams()); + callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); }, onShow() { timel = setInterval(this.run,1000) @@ -17,15 +24,15 @@ export default { clearInterval(timel); timel = null; console.info('click cancel'); - callNativeHandler("EVENT_CONFIRM", "1"); + callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); } }, onConfirm() { console.info('click confirm'); - callNativeHandler("EVENT_CONFIRM", "0"); + callNativeHandler(EVENT_CONFIRM, EVENT_CONFIRM_CODE); }, onCancel() { console.info('click cancel'); - callNativeHandler("EVENT_CANCEL", "1"); + callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); } } \ No newline at end of file diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js index 488972d50..8883ce5de 100644 --- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -8,10 +8,16 @@ export default { pincode: router.getParams().pinCode, isShow:false, isTimes:3, + EVENT_CONFIRM:"EVENT_CONFIRM", + EVENT_CANCEL:"EVENT_CANCEL", + EVENT_INIT:"EVENT_INIT", + EVENT_CONFIRM_CODE:"0", + EVENT_CANCEL_CODE:"1", + EVENT_INIT_CODE:"2", }, onInit() { code = router.getParams().pinCode; - callNativeHandler("EVENT_CONFIRM", "2"); + callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); }, onChange(e){ inputVal = e.value; @@ -22,11 +28,11 @@ export default { console.info('click confirm numbs < 3 '); if(code == inputVal){ console.info('click confirm code == inputVal'); - callNativeHandler("EVENT_INPUT", "0"); + callNativeHandler(EVENT_CONFIRM, EVENT_CONFIRM_CODE); }else{ if(numbs == 3){ console.info('click confirm code != inputVal and numbs == 3'); - callNativeHandler("EVENT_CONFIRM", "1"); + callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); } console.info('click confirm code != inputVal'); this.isShow = true; @@ -34,11 +40,11 @@ export default { } }else{ console.info('click confirm numbs > 3 '); - callNativeHandler("EVENT_CONFIRM", "1"); + callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); } }, onCancel() { console.info('click cancel'); - callNativeHandler("EVENT_CONFIRM", "1"); + callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); } } \ No newline at end of file diff --git a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.hml index 845c99e57..715ceda51 100644 --- a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.hml +++ b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.hml @@ -8,7 +8,7 @@ {{ pincode }} - \ No newline at end of file diff --git a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js index 598deca1f..d666417a3 100644 --- a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js @@ -3,12 +3,18 @@ import router from '@ohos.router' export default { data: { pincode: router.getParams().pinCode, + EVENT_CONFIRM:"EVENT_CONFIRM", + EVENT_CANCEL:"EVENT_CANCEL", + EVENT_INIT:"EVENT_INIT", + EVENT_CONFIRM_CODE:"0", + EVENT_CANCEL_CODE:"1", + EVENT_INIT_CODE:"2", }, onInit() { - callNativeHandler("EVENT_CONFIRM", "0"); + callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); }, - onConfirm() { - console.info('click confirm'); - callNativeHandler("EVENT_CONFIRM", "1"); + onCancel() { + console.info('click onCancel'); + callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); } } \ No newline at end of file diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 4c3e30409..1bc7838b4 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -67,7 +67,7 @@ int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string { times_ += 1; if (authParam.length() == 1) { - if (authParam == "0") { + if (authParam == EVENT_CONFIRM_CODE) { return DM_OK; } LOGE("Peer rejection"); @@ -89,9 +89,9 @@ int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string return DM_FAILED; } int32_t code = authTokenJson[PIN_CODE_KEY]; - int32_t pinToken = authTokenJson[PIN_TOKEN]; + std::string pinToken = authTokenJson[PIN_TOKEN]; int32_t inputPinCode = authParamJson[PIN_CODE_KEY]; - int32_t inputPinToken = authParamJson[PIN_TOKEN]; + std::string inputPinToken = authParamJson[PIN_TOKEN]; if (code == inputPinCode && pinToken == inputPinToken) { return DM_OK; } else if (code != inputPinCode && times_ < MAX_VERIFY_TIMES) { diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/pin_auth_ui.cpp index eb976a678..dcd283df7 100644 --- a/ext/pin_auth/src/pin_auth_ui.cpp +++ b/ext/pin_auth/src/pin_auth_ui.cpp @@ -42,10 +42,10 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authManager](int32_t id, const std::string& event, const std::string& params) { - if (strcmp(params.c_str(), "0") == 0) { + if (params == EVENT_INIT_CODE) { authManager->SetPageId(id); } - if (strcmp(params.c_str(), "1") == 0) { + if (params == EVENT_CANCEL_CODE) { LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); } @@ -68,10 +68,10 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authManager](int32_t id, const std::string& event, const std::string& params) { - if (strcmp(params.c_str(), "2") == 0) { + if (params == EVENT_INIT_CODE) { authManager->SetPageId(id); } - if (strcmp(params.c_str(), "0") == 0 || strcmp(params.c_str(), "1") == 0) { + if (params == EVENT_CANCEL_CODE || params == EVENT_CONFIRM_CODE) { Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); authManager->VerifyAuthentication(params.c_str()); diff --git a/services/devicemanagerservice/include/dependency/timer/dm_timer.h b/services/devicemanagerservice/include/dependency/timer/dm_timer.h index a4ffec0fd..b15a95770 100644 --- a/services/devicemanagerservice/include/dependency/timer/dm_timer.h +++ b/services/devicemanagerservice/include/dependency/timer/dm_timer.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -55,6 +56,7 @@ private: void Release(); private: + std::mutex mTimerLock_; DmTimerStatus mStatus_; uint32_t mTimeOutSec_; TimeoutHandle mHandle_; diff --git a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h index 7817313fc..32a7dacd7 100755 --- a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h +++ b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h @@ -29,6 +29,14 @@ namespace OHOS { namespace DistributedHardware { #define OFFLINE_TIMEOUT 300 +struct StateTimerInfo +{ + std::string timerName; + std::string netWorkId; + std::string deviceId; + std::shared_ptr timer; +}; + class DmDeviceStateManager final : public ISoftbusStateCallback, public std::enable_shared_from_this { public: @@ -48,7 +56,7 @@ public: int32_t RegisterSoftbusStateCallback(); void RegisterOffLineTimer(const DmDeviceInfo &deviceInfo); void StartOffLineTimer(const DmDeviceInfo &deviceInfo); - void DeleteTimeOutGroup(std::string deviceId); + void DeleteTimeOutGroup(std::string stateTimer); void RegisterDevStateCallback(const std::string &pkgName, const std::string &extra); void UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra); @@ -60,8 +68,7 @@ private: std::shared_ptr listener_; std::map remoteDeviceInfos_; std::map decisionInfos_; - std::map> timerMap_; - std::map deviceinfoMap_; + std::map stateTimerInfoMap_; std::shared_ptr hiChainConnector_; std::string decisionSoName_; }; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index bb075c5b9..bd7b9cf76 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -15,6 +15,8 @@ #include "dm_auth_manager.h" +#include + #include "auth_message_processor.h" #include "auth_ui.h" #include "dm_ability_manager.h" @@ -31,14 +33,14 @@ namespace OHOS { namespace DistributedHardware { -const std::string AUTHENTICATE_TIMEOUT_TASK = "authenticateTimeoutTask"; -const std::string NEGOTIATE_TIMEOUT_TASK = "negotiateTimeoutTask"; -const std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; -const std::string SHOW_TIMEOUT_TASK = "showTimeoutTask"; -const std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; -const std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; -const std::string WAIT_NEGOTIATE_TIMEOUT_TASK = "waitNegotiateTimeoutTask"; -const std::string WAIT_REQUEST_TIMEOUT_TASK = "waitRequestTimeoutTask"; +const std::string AUTHENTICATE_TIMEOUT_TASK = TIMER_PREFIX + "authenticate"; +const std::string NEGOTIATE_TIMEOUT_TASK = TIMER_PREFIX + "negotiate"; +const std::string CONFIRM_TIMEOUT_TASK = TIMER_PREFIX + "confirm"; +const std::string SHOW_TIMEOUT_TASK = TIMER_PREFIX + "show"; +const std::string INPUT_TIMEOUT_TASK = TIMER_PREFIX + "input"; +const std::string ADD_TIMEOUT_TASK = TIMER_PREFIX + "add"; +const std::string WAIT_NEGOTIATE_TIMEOUT_TASK = TIMER_PREFIX + "waitNegotiate"; +const std::string WAIT_REQUEST_TIMEOUT_TASK = TIMER_PREFIX + "waitRequest"; const int32_t SESSION_CANCEL_TIMEOUT = 0; const int32_t AUTHENTICATE_TIMEOUT = 120; @@ -53,12 +55,18 @@ const int32_t DEVICE_ID_HALF = 2; static void TimeOut(void *data, DmTimer& timer) { - LOGE("time out "); + LOGI("time out %s", timer.GetTimerName().c_str()); + if (data == nullptr || timer.GetTimerName().find(TIMER_PREFIX) == TIMER_DEFAULT) { + LOGE("time out is not our timer"); + return; + } + DmAuthManager *authMgr = (DmAuthManager *)data; if (authMgr == nullptr) { - LOGE("time out error"); + LOGE("authMgr is nullptr"); return; } + authMgr->HandleAuthenticateTimeout(); } @@ -145,7 +153,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au int32_t DmAuthManager::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) { if (pkgName.empty()) { - LOGI(" DmAuthManager::UnAuthenticateDevice failed pkgName is null"); + LOGE(" DmAuthManager::UnAuthenticateDevice failed pkgName is null"); return DM_FAILED; } std::string deviceUdid; @@ -175,7 +183,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) LOGI("DmAuthManager::VerifyAuthentication"); if (authResponseContext_ == nullptr) { LOGI("authResponseContext_ is not init"); - return DM_FAILED; + return DM_AUTH_NOT_START; } std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end() @@ -333,7 +341,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId { LOGI("DmAuthManager::OnGroupCreated start"); if (authResponseState_ == nullptr) { - LOGI("DmAuthManager::AuthenticateDevice end"); + LOGE("DmAuthManager::AuthenticateDevice end"); return; } if (groupId == "{}") { @@ -387,6 +395,8 @@ int32_t DmAuthManager::HandleAuthenticateTimeout() } if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { + authResponseContext_->state = authResponseState_->GetStateType(); + authResponseContext_->reply = DM_TIME_OUT; authResponseState_->TransitionTo(std::make_shared()); } LOGI("DmAuthManager::HandleAuthenticateTimeout start complete"); @@ -490,6 +500,11 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) int32_t DmAuthManager::StartAuthProcess(const int32_t &action) { LOGI("DmAuthManager:: StartAuthProcess"); + if (authResponseContext_ == nullptr) { + LOGE("Authenticate is not start"); + return DM_AUTH_NOT_START; + } + authResponseContext_->reply = action; if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { @@ -719,9 +734,14 @@ void DmAuthManager::ShowConfigDialog() OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authMgr_](int32_t id, const std::string& event, const std::string& params) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); - LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - authMgr_->StartAuthProcess(atoi(params.c_str())); + if (params == EVENT_INIT_CODE) { + LOGI("Dialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authMgr_->SetPageId(id); + } else { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authMgr_->StartAuthProcess(atoi(params.c_str())); + } }); LOGI("ShowConfigDialog end"); } @@ -754,13 +774,13 @@ void DmAuthManager::ShowStartAuthDialog() int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) { if (dmAbilityMgr_ == nullptr) { - LOGI("dmAbilityMgr_ is nullptr"); + LOGE("dmAbilityMgr_ is nullptr"); return DM_POINT_NULL; } if (authResponseContext_ == nullptr) { - LOGI("authResponseContext_ is not init"); - return DM_FAILED; + LOGE("authResponseContext_ is not init"); + return DM_AUTH_NOT_START; } dmAbilityMgr_->StartAbilityDone(); @@ -783,8 +803,8 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) int32_t DmAuthManager::OnUserOperation(int32_t action) { if (authResponseContext_ == nullptr) { - LOGI("authResponseContext_ is not init"); - return DM_FAILED; + LOGE("authResponseContext_ is not init"); + return DM_AUTH_NOT_START; } switch (action) { @@ -845,12 +865,22 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) int32_t DmAuthManager::SetPageId(int32_t pageId) { + if (authResponseContext_ == nullptr) { + LOGE("Authenticate is not start"); + return DM_AUTH_NOT_START; + } + authResponseContext_->pageId = pageId; return DM_OK; } int32_t DmAuthManager::SetReason(int32_t reason, int32_t state) { + if (authResponseContext_ == nullptr) { + LOGE("Authenticate is not start"); + return DM_AUTH_NOT_START; + } + if (state < AuthState::AUTH_REQUEST_FINISH) { authRequestContext_->reason = reason; } diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index 0dadbdf98..0835f9b5e 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -17,6 +17,7 @@ #include +#include "dm_constants.h" #include "securec.h" namespace OHOS { @@ -26,10 +27,11 @@ const int32_t MILL_SECONDS_PER_SECOND = 1000; } DmTimer::DmTimer(const std::string &name) { - if (name.empty()) { - LOGI("DmTimer name is null"); + if (name.empty() || name.find(TIMER_PREFIX) != TIMER_DEFAULT) { + LOGE("DmTimer name is null"); return; } + mStatus_ = DmTimerStatus::DM_STATUS_INIT; mTimeOutSec_ = 0; mHandle_ = nullptr; @@ -43,20 +45,23 @@ DmTimer::DmTimer(const std::string &name) DmTimer::~DmTimer() { - if (mTimerName_.empty()) { - LOGI("DmTimer is not init"); + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT) { + LOGE("DmTimer is not init"); return; } + LOGI("DmTimer %s Destroy in", mTimerName_.c_str()); Release(); } DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) { - if (mTimerName_.empty() || handle == nullptr || data == nullptr) { - LOGI("DmTimer is not init or param empty"); + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT + || handle == nullptr || data == nullptr) { + LOGE("DmTimer is not init or param empty"); return DmTimerStatus::DM_STATUS_FINISH; } + LOGI("DmTimer %s start timeout(%d)", mTimerName_.c_str(), timeOut); if (mStatus_ != DmTimerStatus::DM_STATUS_INIT) { return DmTimerStatus::DM_STATUS_BUSY; @@ -78,10 +83,12 @@ DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) void DmTimer::Stop(int32_t code) { - if (mTimerName_.empty()) { - LOGI("DmTimer is not init"); + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT + || mHandleData_ == nullptr) { + LOGE("DmTimer is not init"); return; } + if (mTimeFd_[1]) { char event = 'S'; if (write(mTimeFd_[1], &event, 1) < 0) { @@ -92,41 +99,47 @@ void DmTimer::Stop(int32_t code) void DmTimer::WaitForTimeout() { - if (mTimerName_.empty()) { - LOGI("DmTimer is not init"); + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT) { + LOGE("DmTimer is not init"); return; } LOGI("DmTimer %s start timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); - int32_t nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); - if (nfds < 0) { - LOGE("DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno); - } else if (nfds > 0) { - char event = 0; - if (mEvents_[0].events & EPOLLIN) { - int num = read(mTimeFd_[0], &event, 1); - if (num > 0) { - LOGI("DmTimer %s exit with event %d", mTimerName_.c_str(), event); - } else { - LOGE("DmTimer %s exit with errno %d", mTimerName_.c_str(), errno); + int32_t nfds = -1; + { + std::lock_guard lock(mTimerLock_); + nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); + LOGI("DmTimer is triggering"); + if (nfds > 0) { + char event = 0; + if (mEvents_[0].events & EPOLLIN) { + int num = read(mTimeFd_[0], &event, 1); + if (num > 0) { + LOGI("DmTimer %s exit with event %d", mTimerName_.c_str(), event); + } else { + LOGE("DmTimer %s exit with errno %d", mTimerName_.c_str(), errno); + } } - } - Release(); - } else { + } + } + + if (nfds == 0 && mHandleData_ != nullptr) { mHandle_(mHandleData_, *this); - Release(); - LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); + LOGI("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); + } else { + LOGE("DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno); } + Release(); } int32_t DmTimer::CreateTimeFd() { - if (mTimerName_.empty()) { - LOGI("DmTimer is not init"); + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT) { + LOGE("DmTimer is not init"); return DM_STATUS_FINISH; } - LOGI("DmTimer %s creatTimeFd", mTimerName_.c_str()); + LOGI("DmTimer %s creatTimeFd", mTimerName_.c_str()); int ret = pipe(mTimeFd_); if (ret < 0) { LOGE("DmTimer %s CreateTimeFd fail:(%d) errno(%d)", mTimerName_.c_str(), ret, errno); @@ -146,21 +159,27 @@ int32_t DmTimer::CreateTimeFd() void DmTimer::Release() { - if (mTimerName_.empty()) { - LOGI("DmTimer is not init"); + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT) { + LOGE("DmTimer is not init"); return; } + + std::lock_guard lock(mTimerLock_); LOGI("DmTimer %s Release in", mTimerName_.c_str()); if (mStatus_ == DmTimerStatus::DM_STATUS_INIT) { - LOGI("DmTimer %s already Release", mTimerName_.c_str()); + LOGE("DmTimer %s already Release", mTimerName_.c_str()); return; } + mStatus_ = DmTimerStatus::DM_STATUS_INIT; close(mTimeFd_[0]); close(mTimeFd_[1]); if (mEpFd_ >= 0) { close(mEpFd_); } + mTimeOutSec_ = 0; + mHandle_ = nullptr; + mHandleData_ = nullptr; mTimeFd_[0] = 0; mTimeFd_[1] = 0; mEpFd_ = 0; diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 1cef6db56..762f72d1a 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -26,12 +26,18 @@ const int32_t SESSION_CANCEL_TIMEOUT = 0; static void TimeOut(void *data, DmTimer& timer) { - LOGE("time out "); + LOGI("time out %s",timer.GetTimerName().c_str()); + if (data == nullptr || timer.GetTimerName().find(TIMER_PREFIX) == TIMER_DEFAULT) { + LOGE("time out is not our timer"); + return; + } + DmDeviceStateManager *deviceStateMgr = (DmDeviceStateManager*)data; if (deviceStateMgr == nullptr) { - LOGE("OnDeviceOfflineTimeOut deviceStateMgr = nullptr"); + LOGE("deviceStateMgr is nullptr"); return; } + deviceStateMgr->DeleteTimeOutGroup(timer.GetTimerName()); } @@ -244,41 +250,48 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) LOGI("Register OffLine Timer with device: %s", GetAnonyString(deviceId).c_str()); std::lock_guard mutexLock(timerMapMutex_); - deviceinfoMap_[deviceInfo.deviceId] = deviceId; - auto iter = timerMap_.find(deviceId); - if (iter != timerMap_.end()) { - iter->second->Stop(SESSION_CANCEL_TIMEOUT); - return; + for (auto &iter : stateTimerInfoMap_) { + if (iter.second.netWorkId == deviceInfo.deviceId) { + iter.second.timer->Stop(SESSION_CANCEL_TIMEOUT); + return; + } } - std::shared_ptr offLineTimer = std::make_shared(deviceId); + + std::string timerName = TIMER_PREFIX + STATE_TIMER_PREFIX + std::to_string(stateTimerInfoMap_.size()); + std::shared_ptr offLineTimer = std::make_shared(timerName); if (offLineTimer != nullptr) { - timerMap_[deviceId] = offLineTimer; + StateTimerInfo stateTimer = { + .timerName = timerName, + .netWorkId = deviceInfo.deviceId, + .deviceId = deviceId, + .timer = offLineTimer + }; + stateTimerInfoMap_[timerName] = stateTimer; } } void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo) { - if (deviceinfoMap_.find(deviceInfo.deviceId) == deviceinfoMap_.end()) { - LOGE("fail to get udid by networkId"); - return; - } - - LOGI("start offline timer with device: %s", GetAnonyString(deviceinfoMap_[deviceInfo.deviceId]).c_str()); - std::lock_guard mutexLock(timerMapMutex_); - for (auto &iter : timerMap_) { - if (iter.first == deviceinfoMap_[deviceInfo.deviceId]) { - iter.second->Start(OFFLINE_TIMEOUT, TimeOut, this); + LOGI("start offline timer"); + for (auto &iter : stateTimerInfoMap_) { + if (iter.second.netWorkId == deviceInfo.deviceId) { + iter.second.timer->Start(OFFLINE_TIMEOUT, TimeOut, this); } } - deviceinfoMap_.erase(deviceInfo.deviceId); } -void DmDeviceStateManager::DeleteTimeOutGroup(std::string deviceId) +void DmDeviceStateManager::DeleteTimeOutGroup(std::string stateTimer) { - LOGI("remove hichain group with device: %s", GetAnonyString(deviceId).c_str()); + std::lock_guard mutexLock(timerMapMutex_); if (hiChainConnector_ != nullptr) { - hiChainConnector_->DeleteTimeOutGroup(deviceId.c_str()); + auto iter = stateTimerInfoMap_.find(stateTimer); + if (iter != stateTimerInfoMap_.end()) { + LOGI("remove hichain group with device: %s", + GetAnonyString(stateTimerInfoMap_[stateTimer].deviceId).c_str()); + hiChainConnector_->DeleteTimeOutGroup(stateTimerInfoMap_[stateTimer].deviceId.c_str()); + } } + stateTimerInfoMap_.erase(stateTimer); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index 494214339..d653e2b18 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -21,18 +21,24 @@ namespace OHOS { namespace DistributedHardware { -const std::string DISCOVERY_TIMEOUT_TASK = "discoveryTimeout"; +const std::string DISCOVERY_TIMEOUT_TASK = TIMER_PREFIX + "discovery"; const int32_t DISCOVERY_TIMEOUT = 120; const int32_t SESSION_CANCEL_TIMEOUT = 0; static void TimeOut(void *data, DmTimer& timer) { - LOGE("time out"); + LOGI("time out %s",timer.GetTimerName().c_str()); + if (data == nullptr || timer.GetTimerName() != DISCOVERY_TIMEOUT_TASK) { + LOGE("time out is not our timer"); + return; + } + DmDiscoveryManager *discoveryMgr = (DmDiscoveryManager *)data; if (discoveryMgr == nullptr) { - LOGE("time out error"); + LOGE("discoveryMgr is nullptr"); return; } + discoveryMgr->HandleDiscoveryTimeout(); } -- Gitee From 7837cbe965bd4a55fbee32826ca23800a43ff099 Mon Sep 17 00:00:00 2001 From: fuchao Date: Thu, 17 Mar 2022 12:25:20 +0000 Subject: [PATCH 2/6] update services/devicemanagerservice/src/authentication/dm_auth_manager.cpp. --- .../devicemanagerservice/src/authentication/dm_auth_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index bd7b9cf76..38dcdab95 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -56,7 +56,7 @@ const int32_t DEVICE_ID_HALF = 2; static void TimeOut(void *data, DmTimer& timer) { LOGI("time out %s", timer.GetTimerName().c_str()); - if (data == nullptr || timer.GetTimerName().find(TIMER_PREFIX) == TIMER_DEFAULT) { + if (data == nullptr || timer.GetTimerName().find(TIMER_PREFIX) != TIMER_DEFAULT) { LOGE("time out is not our timer"); return; } -- Gitee From 216885dd67c2e55dad52e2139fe5fe4c131ec50c Mon Sep 17 00:00:00 2001 From: fuchao Date: Thu, 17 Mar 2022 12:26:45 +0000 Subject: [PATCH 3/6] update services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp. --- .../src/devicestate/dm_device_state_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 762f72d1a..ff935f6d6 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -27,7 +27,7 @@ const int32_t SESSION_CANCEL_TIMEOUT = 0; static void TimeOut(void *data, DmTimer& timer) { LOGI("time out %s",timer.GetTimerName().c_str()); - if (data == nullptr || timer.GetTimerName().find(TIMER_PREFIX) == TIMER_DEFAULT) { + if (data == nullptr || timer.GetTimerName().find(TIMER_PREFIX) != TIMER_DEFAULT) { LOGE("time out is not our timer"); return; } -- Gitee From 4ae491b87ee9901a5ba8881034e6847327a5414b Mon Sep 17 00:00:00 2001 From: fuchao Date: Fri, 18 Mar 2022 02:35:22 +0000 Subject: [PATCH 4/6] update common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js. --- .../dialog_ui/js/pages/index/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js b/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js index 536950498..1850093f0 100644 --- a/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js +++ b/common/include/show_confirm_dialog/dialog_ui/js/pages/index/index.js @@ -1,15 +1,15 @@ import router from '@ohos.router' var timel = null; +var EVENT_CONFIRM = "EVENT_CONFIRM"; +var EVENT_CANCEL = "EVENT_CANCEL"; +var EVENT_INIT = "EVENT_INIT"; +var EVENT_CONFIRM_CODE = "0"; +var EVENT_CANCEL_CODE = "1"; +var EVENT_INIT_CODE = "2"; export default { data: { seconds:60, - EVENT_CONFIRM:"EVENT_CONFIRM", - EVENT_CANCEL:"EVENT_CANCEL", - EVENT_INIT:"EVENT_INIT", - EVENT_CONFIRM_CODE:"0", - EVENT_CANCEL_CODE:"1", - EVENT_INIT_CODE:"2", }, onInit() { console.info('getParams: ' + router.getParams()); -- Gitee From 609fd14ac67611d29a3035cb4c8de6e7384ac850 Mon Sep 17 00:00:00 2001 From: fuchao Date: Fri, 18 Mar 2022 02:36:08 +0000 Subject: [PATCH 5/6] update ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js. --- .../dialog_ui/js/pages/index/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js index 8883ce5de..b0405866e 100644 --- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -3,17 +3,17 @@ import router from '@ohos.router'; var numbs = 0; var code = 0; var inputVal = 0; +var EVENT_CONFIRM = "EVENT_CONFIRM"; +var EVENT_CANCEL = "EVENT_CANCEL"; +var EVENT_INIT = "EVENT_INIT"; +var EVENT_CONFIRM_CODE = "0"; +var EVENT_CANCEL_CODE = "1"; +var EVENT_INIT_CODE = "2"; export default { data: { pincode: router.getParams().pinCode, isShow:false, isTimes:3, - EVENT_CONFIRM:"EVENT_CONFIRM", - EVENT_CANCEL:"EVENT_CANCEL", - EVENT_INIT:"EVENT_INIT", - EVENT_CONFIRM_CODE:"0", - EVENT_CANCEL_CODE:"1", - EVENT_INIT_CODE:"2", }, onInit() { code = router.getParams().pinCode; -- Gitee From 4466c69e818fa715cbb611c02e23d25ec36b388d Mon Sep 17 00:00:00 2001 From: fuchao Date: Fri, 18 Mar 2022 02:36:51 +0000 Subject: [PATCH 6/6] update ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js. --- .../dialog_ui/js/pages/index/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js index d666417a3..daef5ab44 100644 --- a/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/show_pin_dialog/dialog_ui/js/pages/index/index.js @@ -1,14 +1,14 @@ import router from '@ohos.router' +var EVENT_CONFIRM = "EVENT_CONFIRM"; +var EVENT_CANCEL = "EVENT_CANCEL"; +var EVENT_INIT = "EVENT_INIT"; +var EVENT_CONFIRM_CODE = "0"; +var EVENT_CANCEL_CODE = "1"; +var EVENT_INIT_CODE = "2"; export default { data: { pincode: router.getParams().pinCode, - EVENT_CONFIRM:"EVENT_CONFIRM", - EVENT_CANCEL:"EVENT_CANCEL", - EVENT_INIT:"EVENT_INIT", - EVENT_CONFIRM_CODE:"0", - EVENT_CANCEL_CODE:"1", - EVENT_INIT_CODE:"2", }, onInit() { callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); -- Gitee