diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 8883eeb3e78dcceec849b895725ad8acc9854b8b..f09d3417c0bd9dc0a8d72ac4590877b6c6a79ad0 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,17 @@ 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 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 13a4384c54373870c4ca3b1e17d2daf7567c1239..53695049877a431ab43389aba77df0fa37b7e5ad 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/services/devicemanagerservice/include/dependency/timer/dm_timer.h b/services/devicemanagerservice/include/dependency/timer/dm_timer.h index a4ffec0fdddc84600365578547bde4c5f67e169c..d3504d2db27f1d33816058512654f45e15a80e6d 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 timerLock_; DmTimerStatus mStatus_; uint32_t mTimeOutSec_; TimeoutHandle mHandle_; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index bb075c5b98ab08045d520c72ccf794811e03fc19..d6e0bbc212006e7528d930398896a3486dd2ecfa 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 = "deviceManagerTimer:authenticate"; +const std::string NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:negotiate"; +const std::string CONFIRM_TIMEOUT_TASK = "deviceManagerTimer:confirm"; +const std::string SHOW_TIMEOUT_TASK = "deviceManagerTimer:show"; +const std::string INPUT_TIMEOUT_TASK = "deviceManagerTimer:input"; +const std::string ADD_TIMEOUT_TASK = "deviceManagerTimer:add"; +const std::string WAIT_NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:waitNegotiate"; +const std::string WAIT_REQUEST_TIMEOUT_TASK = "deviceManagerTimer:waitRequest"; const int32_t SESSION_CANCEL_TIMEOUT = 0; const int32_t AUTHENTICATE_TIMEOUT = 120; @@ -53,9 +55,9 @@ const int32_t DEVICE_ID_HALF = 2; static void TimeOut(void *data, DmTimer& timer) { - LOGE("time out "); + LOGE("time out %s", timer.GetTimerName().c_str()); DmAuthManager *authMgr = (DmAuthManager *)data; - if (authMgr == nullptr) { + if (authMgr == nullptr || timer.GetTimerName().substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { LOGE("time out error"); return; } @@ -175,7 +177,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() @@ -388,6 +390,8 @@ int32_t DmAuthManager::HandleAuthenticateTimeout() if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { authResponseState_->TransitionTo(std::make_shared()); + authResponseContext_->state = authResponseState_->GetStateType(); + authResponseContext_->reply = DM_TIME_OUT; } LOGI("DmAuthManager::HandleAuthenticateTimeout start complete"); return DM_OK; @@ -490,6 +494,11 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) int32_t DmAuthManager::StartAuthProcess(const int32_t &action) { LOGI("DmAuthManager:: StartAuthProcess"); + if (authResponseContext_ == nullptr) { + LOGI("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 +728,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"); } @@ -760,7 +774,7 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) if (authResponseContext_ == nullptr) { LOGI("authResponseContext_ is not init"); - return DM_FAILED; + return DM_AUTH_NOT_START; } dmAbilityMgr_->StartAbilityDone(); @@ -784,7 +798,7 @@ int32_t DmAuthManager::OnUserOperation(int32_t action) { if (authResponseContext_ == nullptr) { LOGI("authResponseContext_ is not init"); - return DM_FAILED; + return DM_AUTH_NOT_START; } switch (action) { @@ -845,12 +859,22 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) int32_t DmAuthManager::SetPageId(int32_t pageId) { + if (authResponseContext_ == nullptr) { + LOGI("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) { + LOGI("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 0dadbdf98216742db8862d53e9589e3fae6427cc..e507902751fbb25e9127a6fcc48ac380cb95b2e6 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,7 +27,7 @@ const int32_t MILL_SECONDS_PER_SECOND = 1000; } DmTimer::DmTimer(const std::string &name) { - if (name.empty()) { + if (name.empty() || name.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { LOGI("DmTimer name is null"); return; } @@ -43,17 +44,19 @@ DmTimer::DmTimer(const std::string &name) DmTimer::~DmTimer() { - if (mTimerName_.empty()) { + if (mTimerName_.empty() || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { LOGI("DmTimer is not init"); return; } LOGI("DmTimer %s Destroy in", mTimerName_.c_str()); + std::lock_guard lock(timerLock_); Release(); } DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) { - if (mTimerName_.empty() || handle == nullptr || data == nullptr) { + if (mTimerName_.empty() || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX + || handle == nullptr || data == nullptr) { LOGI("DmTimer is not init or param empty"); return DmTimerStatus::DM_STATUS_FINISH; } @@ -78,7 +81,8 @@ DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) void DmTimer::Stop(int32_t code) { - if (mTimerName_.empty()) { + if (mTimerName_.empty() || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX + || mHandleData_ == nullptr) { LOGI("DmTimer is not init"); return; } @@ -92,13 +96,19 @@ void DmTimer::Stop(int32_t code) void DmTimer::WaitForTimeout() { - if (mTimerName_.empty()) { + if (mTimerName_.empty() || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { LOGI("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); + int32_t nfds = -1; + { + std::lock_guard lock(timerLock_); + nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); + } + + LOGI("DmTimer is triggering"); if (nfds < 0) { LOGE("DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno); } else if (nfds > 0) { @@ -111,17 +121,20 @@ void DmTimer::WaitForTimeout() LOGE("DmTimer %s exit with errno %d", mTimerName_.c_str(), errno); } } - Release(); } else { + if (mHandleData_ == nullptr || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { + LOGI("DmTimer out pointer is nullptr"); + return; + } mHandle_(mHandleData_, *this); - Release(); LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); } + Release(); } int32_t DmTimer::CreateTimeFd() { - if (mTimerName_.empty()) { + if (mTimerName_.empty() || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { LOGI("DmTimer is not init"); return DM_STATUS_FINISH; } @@ -146,7 +159,7 @@ int32_t DmTimer::CreateTimeFd() void DmTimer::Release() { - if (mTimerName_.empty()) { + if (mTimerName_.empty() || mTimerName_.substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { LOGI("DmTimer is not init"); return; } @@ -161,6 +174,9 @@ void DmTimer::Release() 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 1cef6db5644e8e04a502580e21820ae27e4a98a5..6f1d74d7644e7f8e898bf70ed20b753e6bd9e8ff 100755 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -28,8 +28,9 @@ static void TimeOut(void *data, DmTimer& timer) { LOGE("time out "); DmDeviceStateManager *deviceStateMgr = (DmDeviceStateManager*)data; - if (deviceStateMgr == nullptr) { - LOGE("OnDeviceOfflineTimeOut deviceStateMgr = nullptr"); + if (deviceStateMgr == nullptr + || timer.GetTimerName().substr(TIMER_DEFAULT, TIMER_PREFIX_LENGTH) != TIMER_PREFIX) { + LOGE("time out error"); return; } deviceStateMgr->DeleteTimeOutGroup(timer.GetTimerName()); @@ -245,14 +246,15 @@ void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) std::lock_guard mutexLock(timerMapMutex_); deviceinfoMap_[deviceInfo.deviceId] = deviceId; - auto iter = timerMap_.find(deviceId); + std::string timerName = TIMER_PREFIX + deviceId; + auto iter = timerMap_.find(timerName); if (iter != timerMap_.end()) { iter->second->Stop(SESSION_CANCEL_TIMEOUT); return; } - std::shared_ptr offLineTimer = std::make_shared(deviceId); + std::shared_ptr offLineTimer = std::make_shared(timerName); if (offLineTimer != nullptr) { - timerMap_[deviceId] = offLineTimer; + timerMap_[timerName] = offLineTimer; } } @@ -277,7 +279,7 @@ void DmDeviceStateManager::DeleteTimeOutGroup(std::string deviceId) { LOGI("remove hichain group with device: %s", GetAnonyString(deviceId).c_str()); if (hiChainConnector_ != nullptr) { - hiChainConnector_->DeleteTimeOutGroup(deviceId.c_str()); + hiChainConnector_->DeleteTimeOutGroup(deviceId.substr(TIMER_PREFIX_LENGTH).c_str()); } } } // namespace DistributedHardware diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index 4942143390f1bdc5e34e76b397bdd4ad77ae5950..eff66a7da9bdebcb7ea0b2f664def7fd648b726d 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace DistributedHardware { -const std::string DISCOVERY_TIMEOUT_TASK = "discoveryTimeout"; +const std::string DISCOVERY_TIMEOUT_TASK = "deviceManagerTimer:discovery"; const int32_t DISCOVERY_TIMEOUT = 120; const int32_t SESSION_CANCEL_TIMEOUT = 0; @@ -29,7 +29,7 @@ static void TimeOut(void *data, DmTimer& timer) { LOGE("time out"); DmDiscoveryManager *discoveryMgr = (DmDiscoveryManager *)data; - if (discoveryMgr == nullptr) { + if (discoveryMgr == nullptr || timer.GetTimerName() != DISCOVERY_TIMEOUT_TASK) { LOGE("time out error"); return; }