diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 09583962c0f958dbb42cc1ced77cd3acf5e125d4..858f0272caecebd92b4aa69425bf91c0905a438c 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -88,6 +88,7 @@ enum { DM_AUTH_NOT_AUTH, DM_AUTH_DONT_AUTH, DM_AUTH_NOT_START, + DM_AUTH_INPUT_PARAMETER_FAILED, DM_SOFTBUS_FAILED = 3000, DM_SOFTBUS_CREATE_SESSION_SERVER_FAILED, DM_HICHAIN_FAILED = 4000, @@ -159,7 +160,7 @@ const int32_t AUTH_TYPE_SCAN = 2; const int32_t AUTH_TYPE_TOUCH = 3; const int32_t DEFAULT_PIN_CODE = 0; const int32_t DEFAULT_PIN_TOKEN = 0; - +const int32_t DEFAULT_PIN_CODE_LENGTH = 6; // Softbus const int32_t SOFTBUS_CHECK_INTERVAL = 100000; // 100ms const uint32_t SOFTBUS_SUBSCRIBE_ID_PREFIX_LEN = 16; diff --git a/common/include/ipc/model/ipc_set_useroperation_req.h b/common/include/ipc/model/ipc_set_useroperation_req.h index f3465df4aabfb48cb04e396e889005361ef97f58..fd5494df5810252954e06faccb2f987564e6ef20 100644 --- a/common/include/ipc/model/ipc_set_useroperation_req.h +++ b/common/include/ipc/model/ipc_set_useroperation_req.h @@ -35,8 +35,29 @@ public: action_ = action; } + /** + * @tc.name: IpcGetOperationReq::GetParams + * @tc.desc: Ipc Get Params Request Get Params + * @tc.type: FUNC + */ + const std::string &GetParams() const + { + return params_; + } + + /** + * @tc.name: IpcGetOperationReq::SetParams + * @tc.desc: Ipc Set Params Request Set Params + * @tc.type: FUNC + */ + void SetParams(const std::string ¶ms) + { + params_ = params; + } + private: int32_t action_ { 0 }; + std::string params_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/display/@ohos.distributedHardware.deviceManager.d.ts b/display/@ohos.distributedHardware.deviceManager.d.ts index d00376306a92181187afa2623d4f18fff21648cd..65d8f3e5983c86d9011e876cbbe160adaa9219fe 100644 --- a/display/@ohos.distributedHardware.deviceManager.d.ts +++ b/display/@ohos.distributedHardware.deviceManager.d.ts @@ -410,6 +410,44 @@ declare namespace deviceManager { */ verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void; + /** + * Set user Operation from devicemanager ui, this interface can only be used by devicemanager ui. + * + * @since 9 + * @param operateAction User Operation Actions. + * operateAction = 0 - allow authentication + * operateAction = 1 - cancel authentication + * operateAction = 2 - user operation timeout for authentication confirm + * operateAction = 3 - cancel pincode display + * operateAction = 4 - cancel pincode input + * operateAction = 5 - confirm pincode input + * @param params Indicates the input param of the user. + * @throws {BusinessError} 401 - Input parameter error. + * @systemapi this method can be used only by system applications. + */ + setUserOperation(operateAction: number, params: string): void; + + /** + * Register a callback from deviceManager service so that the devicemanager ui can be notified when ui statue + * changes. + * + * @since 9 + * @param callback Indicates the devicemanager ui state to register. + * @throws {BusinessError} 401 - Input parameter error. + * @systemapi this method can be used only by system applications. + */ + on(type: 'uiStateChange', callback: Callback<{ param: string}>): void; + + /** + * Unregister uiStatueChange, this interface can only be used by devicemanager ui. + * + * @since 9 + * @param callback Indicates the devicemanager ui state to unregister. + * @throws {BusinessError} 401 - Input parameter error. + * @systemapi this method can be used only by system applications. + */ + off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void; + /** * Register a device state callback so that the application can be notified upon device state changes based on * the application bundle name. diff --git a/ext/pin_auth/include/ability/dm_ability_manager.h b/ext/pin_auth/include/ability/dm_ability_manager.h index 225fefc6218fcd9c761be7cc5fd260fce4155e1d..c836b50a30c7c00940cb2c18e70054c882cd97cd 100644 --- a/ext/pin_auth/include/ability/dm_ability_manager.h +++ b/ext/pin_auth/include/ability/dm_ability_manager.h @@ -16,11 +16,9 @@ #ifndef OHOS_DM_ABILITY_MANAGER_H #define OHOS_DM_ABILITY_MANAGER_H -#include - -#include #include #include +#include "want.h" namespace OHOS { namespace DistributedHardware { @@ -28,27 +26,18 @@ enum AbilityRole { ABILITY_ROLE_PASSIVE = 0, ABILITY_ROLE_INITIATIVE = 1, ABILIT enum AbilityStatus { ABILITY_STATUS_FAILED = 0, ABILITY_STATUS_SUCCESS = 1, ABILITY_STATUS_START = 2 }; -enum FaAction { +enum UiAction { USER_OPERATION_TYPE_ALLOW_AUTH = 0, USER_OPERATION_TYPE_CANCEL_AUTH = 1, USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT = 2, USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY = 3, - USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT = 4 + USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT = 4, + USER_OPERATION_TYPE_DONE_PINCODE_INPUT = 5 }; class DmAbilityManager { public: - AbilityRole GetAbilityRole(); - AbilityStatus StartAbility(AbilityRole role); - void StartAbilityDone(); - -private: - void waitForTimeout(uint32_t timeout_s); - -private: - sem_t mSem_; - AbilityStatus mStatus_; - AbilityRole mAbilityStatus_; + AbilityStatus StartAbility(AAFwk::Want &want); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/pin_auth/include/lite/pin_auth_ui.h b/ext/pin_auth/include/lite/pin_auth_ui.h index 87920dd31e495d6af541028dbdf72e359b3a4693..c971fb666970ddd262fcd7a110b7b2f91ee0d106 100644 --- a/ext/pin_auth/include/lite/pin_auth_ui.h +++ b/ext/pin_auth/include/lite/pin_auth_ui.h @@ -27,7 +27,7 @@ class PinAuthUi { public: PinAuthUi(); int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager); - int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); + int32_t InputPinDialog(std::shared_ptr authManager); int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager); private: diff --git a/ext/pin_auth/include/standard/pin_auth_ui.h b/ext/pin_auth/include/standard/pin_auth_ui.h index 87920dd31e495d6af541028dbdf72e359b3a4693..e44c4e2250785ec836385b48d9838424239af574 100644 --- a/ext/pin_auth/include/standard/pin_auth_ui.h +++ b/ext/pin_auth/include/standard/pin_auth_ui.h @@ -20,6 +20,7 @@ #include "dm_auth_manager.h" #include "dm_ability_manager.h" +#include "want.h" namespace OHOS { namespace DistributedHardware { @@ -27,11 +28,9 @@ class PinAuthUi { public: PinAuthUi(); int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager); - int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); + int32_t InputPinDialog(std::shared_ptr authManager); int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager); - -private: - int32_t StartFaUiService(std::shared_ptr dmAbilityManager); + int32_t UpdatePinDialog(int32_t pageId); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml index 53558da904c5d13768c9a31383aed65dbd133aa8..98852be5d41f57420390df5d24aec88cb1ca144b 100644 --- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml +++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml @@ -5,7 +5,7 @@ 请输入另一个设备显示的PIN码进行验证 - + PIN码输入错误,请重新输入(3次:还有{{isTimes}}次机会) 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 48a242f2dc32917aa39b17556c37cfa62439a60f..95c13d2dea83aba26d48846ae98f4b5744b7ce49 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 @@ -15,51 +15,36 @@ import router from '@ohos.router'; -var numbs = 0; -var code = 0; -var inputVal = 0; +var inputValue; 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, + inputValue: "", + isShow: false, + isTimes: 3, }, onInit() { - code = router.getParams().pinCode; callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); }, - onChange(e){ - inputVal = e.value; - }, + onChange(e){ + inputValue = e.value; + }, onConfirm() { - numbs = numbs + 1; - if(numbs <= 3){ - console.info('click confirm numbs < 3 '); - if(code == inputVal){ - console.info('click confirm code == inputVal'); - callNativeHandler(EVENT_CONFIRM, EVENT_CONFIRM_CODE); - }else{ - if(numbs == 3){ - console.info('click confirm code != inputVal and numbs == 3'); - callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); - } - console.info('click confirm code != inputVal'); - this.isShow = true; - this.isTimes = 3 - numbs; - } - }else{ - console.info('click confirm numbs > 3 '); - callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); - } + if ((inputValue == null) || (inputValue == "")) { + return; + } + this.isTimes--; + callNativeHandler(EVENT_CONFIRM, inputValue); }, onCancel() { console.info('click cancel'); callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); + }, + onDialogUpdated(param) { + this.isShow = param.verifyFailed; } } \ No newline at end of file diff --git a/ext/pin_auth/src/ability/lite/dm_ability_manager.cpp b/ext/pin_auth/src/ability/lite/dm_ability_manager.cpp index d58403aeeb0b4c73e1f99d91bc78ad6cc719e796..643cbaa48a0e8e0412f0ba40e2881bf0b8c2dcc3 100644 --- a/ext/pin_auth/src/ability/lite/dm_ability_manager.cpp +++ b/ext/pin_auth/src/ability/lite/dm_ability_manager.cpp @@ -17,31 +17,10 @@ namespace OHOS { namespace DistributedHardware { -AbilityRole DmAbilityManager::GetAbilityRole() -{ - return mAbilityStatus_; -} - -AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) +AbilityStatus DmAbilityManager::StartAbility(AAFwk::Want &want) { // not support for L1 yet, do nothing. just save status and role - mAbilityStatus_ = role; - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - return mStatus_; -} - -void DmAbilityManager::waitForTimeout(uint32_t timeout_s) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += (int32_t)timeout_s; - sem_timedwait(&mSem_, &ts); -} - -void DmAbilityManager::StartAbilityDone() -{ - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - sem_post(&mSem_); + return AbilityStatus::ABILITY_STATUS_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp b/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp index 09d7203142859847f2881085371a51fc338a02d8..7e7c1778ef6443afff300bb4ff95885ee0ac6cab 100644 --- a/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp +++ b/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp @@ -20,55 +20,18 @@ #include "ability_record.h" #include "dm_constants.h" #include "dm_log.h" -#include "parameter.h" -#include "semaphore.h" namespace OHOS { namespace DistributedHardware { -namespace { -const int32_t ABILITY_START_TIMEOUT = 3; // 3 second -const std::string bundleUiName = "com.ohos.devicemanagerui"; -const std::string abilityUiName = "com.ohos.devicemanagerui.MainAbility"; -} // namespace - -AbilityRole DmAbilityManager::GetAbilityRole() +AbilityStatus DmAbilityManager::StartAbility(AAFwk::Want &want) { - return mAbilityStatus_; -} - -AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) -{ - mAbilityStatus_ = role; - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - std::string deviceId = localDeviceId; - mStatus_ = ABILITY_STATUS_START; - AAFwk::Want want; - AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); - want.SetElement(element); AAFwk::AbilityManagerClient::GetInstance()->Connect(); ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); - if (result != OHOS::ERR_OK) { + if (result != 0) { LOGE("Start Ability failed"); - mStatus_ = ABILITY_STATUS_FAILED; - return mStatus_; + return AbilityStatus::ABILITY_STATUS_FAILED; } - waitForTimeout(ABILITY_START_TIMEOUT); - return mStatus_; -} - -void DmAbilityManager::waitForTimeout(uint32_t timeout_s) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += (int32_t)timeout_s; - sem_timedwait(&mSem_, &ts); -} - -void DmAbilityManager::StartAbilityDone() -{ - mStatus_ = ABILITY_STATUS_SUCCESS; - sem_post(&mSem_); + return AbilityStatus::ABILITY_STATUS_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/pin_auth/src/lite/pin_auth_ui.cpp b/ext/pin_auth/src/lite/pin_auth_ui.cpp index 09fe32d272efab533750a80cd3c115d80f888815..581cd75e7d56aa45fbc8dad19c5f596af5cac145 100644 --- a/ext/pin_auth/src/lite/pin_auth_ui.cpp +++ b/ext/pin_auth/src/lite/pin_auth_ui.cpp @@ -33,7 +33,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au return DM_OK; } -int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) +int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) { LOGI("InputPinDialog start"); std::shared_ptr dmAbilityManager_ = std::make_shared(); diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 5b0d61c132d78ca5d60741f39c7587eb99eae9c4..9e9a0a4c97cc577f212c1724899af1b75495b542 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -51,16 +51,7 @@ int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) { - nlohmann::json jsonObject = nlohmann::json::parse(authToken, nullptr, false); - if (jsonObject.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return DM_FAILED; - } - if (!jsonObject.contains(PIN_CODE_KEY)) { - LOGE("err json string, first time"); - return DM_FAILED; - } - return pinAuthUi_->InputPinDialog(jsonObject[PIN_CODE_KEY], authManager); + return pinAuthUi_->InputPinDialog(authManager); } int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) diff --git a/ext/pin_auth/src/standard/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp index ce71a973535b9cdded41733cef1d183d6eebf9ea..e7e6c4df21e7639e91ec938f8203418917669098 100644 --- a/ext/pin_auth/src/standard/pin_auth_ui.cpp +++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp @@ -19,10 +19,13 @@ #include "dm_constants.h" #include "dm_log.h" #include "nlohmann/json.hpp" +#include "parameter.h" #include "ui_service_mgr_client.h" namespace OHOS { namespace DistributedHardware { +constexpr const char* VERIFY_FAILED = "verifyFailed"; + PinAuthUi::PinAuthUi() { LOGI("AuthUi constructor"); @@ -32,60 +35,59 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au { LOGI("ShowPinDialog start"); if (authManager == nullptr) { - LOGE("ShowPinDialog authManager is null"); + LOGE("authManager is null"); return DM_FAILED; } - nlohmann::json jsonObj; - jsonObj[PIN_CODE_KEY] = code; - jsonObj.dump(); - const std::string params = jsonObj.dump(); - - Ace::UIServiceMgrClient::GetInstance()->ShowDialog( - "show_pin_service", - params, - 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 (params == EVENT_INIT_CODE) { - authManager->SetPageId(id); - } - 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); - } - }); - LOGI("ShowConfigDialog end"); + std::shared_ptr dmAbilityMgr = std::make_shared(); + if (dmAbilityMgr == nullptr) { + LOGE("PinAuthUi::dmAbilityManager is null"); + return DM_FAILED; + } + AAFwk::Want want; + want.SetParam("PinCode", std::to_string(code)); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + const std::string deviceId = localDeviceId; + const std::string bundleUiName = "com.ohos.devicemanagerui"; + const std::string abilityUiName = "com.ohos.devicemanagerui.PinDialogAbility"; + AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); + want.SetElement(element); + AbilityStatus status = dmAbilityMgr->StartAbility(want); + if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { + LOGE("ShowConfirm::start ui service success"); + return DM_FAILED; + } + LOGI("ShowPinDialog end"); return DM_OK; } -int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) +int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) { LOGI("InputPinDialog start"); if (authManager == nullptr) { - LOGE("ShowPinDialog InputPinDialog is null"); + LOGE("authManager is null"); return DM_FAILED; } - nlohmann::json jsonObj; - jsonObj[PIN_CODE_KEY] = code; - jsonObj.dump(); - const std::string params = jsonObj.dump(); - - Ace::UIServiceMgrClient::GetInstance()->ShowDialog( - "input_pin_service", - params, - 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 (params == EVENT_INIT_CODE) { - authManager->SetPageId(id); - } - 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()); - } - }); - LOGI("ShowConfigDialog end"); + std::shared_ptr dmAbilityMgr = std::make_shared(); + if (dmAbilityMgr == nullptr) { + LOGE("PinAuthUi::dmAbilityManager is null"); + return DM_FAILED; + } + AAFwk::Want want; + want.SetParam(VERIFY_FAILED, false); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + const std::string deviceId = localDeviceId; + const std::string bundleUiName = "com.ohos.devicemanagerui"; + const std::string abilityUiName = "com.ohos.devicemanagerui.InputPinDialogAbility"; + AppExecFwk::ElementName element(deviceId, bundleUiName, abilityUiName); + want.SetElement(element); + AbilityStatus status = dmAbilityMgr->StartAbility(want); + if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { + LOGE("ShowConfirm::start ui service success"); + return DM_FAILED; + } + LOGI("InputPinDialog end"); return DM_OK; } @@ -97,14 +99,5 @@ int32_t PinAuthUi::ClosePage(const int32_t &pageId, std::shared_ptr dmAbilityManager) -{ - AbilityStatus status = dmAbilityManager->StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE); - if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - LOGE("PinAuthUi::StartFaService timeout"); - return DM_FAILED; - } - return DM_OK; -} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 0dab46069fff25fee10cc407690aa43acdaea853..f69ae44944c3e4f5ffbbb877d606542c3bfd3748 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -48,10 +48,20 @@ public: virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara, std::shared_ptr callback) = 0; virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName, - std::shared_ptr callback) = 0; + std::shared_ptr callback) = 0; + /** + * @tc.name: DeviceManagerImpl::UnRegisterDeviceManagerFaCallback + * @tc.desc: Unregister Fa callback for device manager + * @tc.type: FUNC + */ virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) = 0; virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) = 0; - virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action) = 0; + /** + * @tc.name: DeviceManagerImpl::SetUserOperation + * @tc.desc: Set User Actions + * @tc.type: FUNC + */ + virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) = 0; virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) = 0; virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid) = 0; virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra) = 0; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index f175f2344d7e95d5829510acb3b98fd9be1bb8b7..a35bace6b5b7219dec103d77a77ed7dbd12d5d1d 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -68,9 +68,9 @@ public: } virtual void OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) = 0; }; -class DeviceManagerFaCallback { +class DeviceManagerUiCallback { public: - virtual ~DeviceManagerFaCallback() + virtual ~DeviceManagerUiCallback() { } virtual void OnCall(const std::string ¶mJson) = 0; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 791aab440ac2fc339ee459d123b3ef211ae9a335..651c8412239694730c39787c214bad08bc4f87d2 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -48,11 +48,21 @@ public: virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) override; virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara, std::shared_ptr callback) override; + /** + * @tc.name: DeviceManagerImpl::RegisterDeviceManagerFaCallback + * @tc.desc: Register Fa callback for device manager + * @tc.type: FUNC + */ virtual int32_t RegisterDeviceManagerFaCallback(const std::string &packageName, - std::shared_ptr callback) override; + std::shared_ptr callback) override; virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) override; virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) override; - virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action) override; + /** + * @tc.name: DeviceManagerImpl::SetUserOperation + * @tc.desc: Set User Actions + * @tc.type: FUNC + */ + virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) override; virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) override; virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index 6aef7a4d8d9b7743a74f58165548941bfb224ebe..8dcfb6d63626df3436c66039a4dc02ebcd4f0e03 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -47,7 +47,7 @@ public: void RegisterVerifyAuthenticationCallback(const std::string &pkgName, const std::string &authPara, std::shared_ptr callback); void UnRegisterVerifyAuthenticationCallback(const std::string &pkgName); - void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr callback); + void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr callback); void UnRegisterDeviceManagerFaCallback(const std::string &pkgName); public: @@ -62,7 +62,7 @@ public: void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, uint32_t status, uint32_t reason); void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, int32_t flag); - void OnFaCall(std::string &pkgName, std::string ¶mJson); + void OnUiCall(std::string &pkgName, std::string ¶mJson); private: #if !defined(__LITEOS_M__) @@ -73,7 +73,7 @@ private: std::map>> authenticateCallback_; std::map> verifyAuthCallback_; std::map> dmInitCallback_; - std::map> dmFaCallback_; + std::map> dmUiCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 09dcb1780aef14b891af55e7aa9fb0468b962bfd..9f3aedd98d2fef1491fcebba2101aa11083565f5 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -304,7 +304,7 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons } int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(const std::string &pkgName, - std::shared_ptr callback) + std::shared_ptr callback) { LOGI("DeviceManager::RegisterDeviceManagerFaCallback start, pkgName: %s", pkgName.c_str()); if (pkgName.empty() || callback == nullptr) { @@ -380,18 +380,19 @@ int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &d return DM_OK; } -int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action) +int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) { - LOGI("DeviceManager::SetUserOperation start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - LOGE("VerifyAuthentication failed, pkgName is empty"); - return DM_INVALID_VALUE; + if (pkgName.empty() || params.empty()) { + LOGE("DeviceManager::SetUserOperation start, pkgName: %s, params: %s", pkgName.c_str(), params.c_str()); + return DM_INVALID_VALUE;; } + LOGI("SetUserOperation start, pkgName: %s", pkgName.c_str()); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetOperation(action); + req->SetParams(params); if (ipcClientProxy_->SendRequest(SERVER_USER_AUTH_OPERATION, req, rsp) != DM_OK) { return DM_IPC_SEND_REQUEST_FAILED; diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index cf73c6a7e2b49b8c6999feb1c3e812cc2a5ce9e6..9888d2f4c30ed73a0d6d920be6cff1fb70985a4e 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -320,7 +320,7 @@ ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, IpcIo &reply) std::string packagename = (const char *)IpcIoPopString(&reply, &len); size_t jsonLen = 0; std::string paramJson = (const char *)IpcIoPopString(&reply, &jsonLen); - DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson); + DeviceManagerNotify::GetInstance().OnUiCall(packagename, paramJson); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 1c57337828b967ab8f640036b04775e505bdb9a0..25a0cbcaa8fe2f70b2817e4c8f602df8952b8ab3 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -330,6 +330,7 @@ ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr pBaseReq, std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t action = pReq->GetOperation(); + std::string params = pReq->GetParams(); if (!data.WriteString(pkgName)) { LOGE("write pkgName failed"); @@ -339,6 +340,10 @@ ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr pBaseReq, LOGE("write action failed"); return DM_WRITE_FAILED; } + if (!data.WriteString(params)) { + LOGE("write params failed"); + return DM_WRITE_FAILED; + } return DM_OK; } @@ -489,7 +494,7 @@ ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply) { std::string packagename = data.ReadString(); std::string paramJson = data.ReadString(); - DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson); + DeviceManagerNotify::GetInstance().OnUiCall(packagename, paramJson); if (!reply.WriteInt32(DM_OK)) { LOGE("write return failed"); return DM_WRITE_FAILED; diff --git a/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp index 38d460f69123a32511708d6fea4a6c4659e2e3ff..55eee2cbbcbcf3bdc903c354b75456bee1fc04ca 100644 --- a/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/mini/device_manager_impl.cpp @@ -268,7 +268,7 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons } int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(const std::string &packageName, - std::shared_ptr callback) + std::shared_ptr callback) { LOGI("DeviceManager::RegisterDeviceManagerFaCallback start, pkgName: %s", packageName.c_str()); if (packageName.empty() || callback == nullptr) { @@ -344,15 +344,13 @@ int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &d return DM_OK; } -int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action) +int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) { - LOGI("DeviceManager::SetUserOperation start, pkgName: %s", pkgName.c_str()); - - if (pkgName.empty()) { - LOGE("VerifyAuthentication failed, pkgName is empty"); + if (pkgName.empty() || params.empty()) { + LOGE("SetUserOperation failed, pkgName or params is empty"); return DM_INVALID_VALUE; } - + LOGI("DeviceManager::SetUserOperation start, pkgName: %s", pkgName.c_str()); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); diff --git a/interfaces/inner_kits/native_cpp/src/mini/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/mini/device_manager_notify.cpp index 02eeb2392dc599c120fea041653941c612832049..4072a800abe31300b1da25e1767f6b7d3c3e3fa2 100644 --- a/interfaces/inner_kits/native_cpp/src/mini/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/mini/device_manager_notify.cpp @@ -103,18 +103,18 @@ void DeviceManagerNotify::UnRegisterVerifyAuthenticationCallback(const std::stri } void DeviceManagerNotify::RegisterDeviceManagerFaCallback(const std::string &pkgName, - std::shared_ptr callback) + std::shared_ptr callback) { - dmFaCallback_[pkgName] = callback; + dmUiCallback_[pkgName] = callback; } void DeviceManagerNotify::UnRegisterDeviceManagerFaCallback(const std::string &pkgName) { - if (dmFaCallback_.count(pkgName) == 0) { + if (dmUiCallback_.count(pkgName) == 0) { LOGE("DeviceManager UnRegisterDeviceManagerFaCallback not register"); return; } - dmFaCallback_.erase(pkgName); + dmUiCallback_.erase(pkgName); } @@ -246,15 +246,15 @@ void DeviceManagerNotify::OnVerifyAuthResult(const std::string &pkgName, const s verifyAuthCallback_.erase(pkgName); } -void DeviceManagerNotify::OnFaCall(std::string &pkgName, std::string ¶mJson) +void DeviceManagerNotify::OnUiCall(std::string &pkgName, std::string ¶mJson) { - LOGI("DeviceManager OnFaCallback pkgName:%s", pkgName.c_str()); + LOGI("DeviceManager OnUiCallback pkgName:%s", pkgName.c_str()); - if (dmFaCallback_.count(pkgName) == 0) { - LOGE("DeviceManager DmFaCallback not register"); + if (dmUiCallback_.count(pkgName) == 0) { + LOGE("DeviceManager dmUiCallback_ not register"); return; } - dmFaCallback_[pkgName]->OnCall(paramJson); + dmUiCallback_[pkgName]->OnCall(paramJson); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 89c945640ee3ad38c14ed9f238d1f71f4cbac253..cceb67aa69f1d16bc043afa1a15d800a10d09e90 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -114,20 +114,20 @@ void DeviceManagerNotify::UnRegisterVerifyAuthenticationCallback(const std::stri } void DeviceManagerNotify::RegisterDeviceManagerFaCallback(const std::string &pkgName, - std::shared_ptr callback) + std::shared_ptr callback) { std::lock_guard autoLock(lock_); - dmFaCallback_[pkgName] = callback; + dmUiCallback_[pkgName] = callback; } void DeviceManagerNotify::UnRegisterDeviceManagerFaCallback(const std::string &pkgName) { std::lock_guard autoLock(lock_); - if (dmFaCallback_.count(pkgName) == 0) { + if (dmUiCallback_.count(pkgName) == 0) { LOGE("DeviceManager UnRegisterDeviceManagerFaCallback not register"); return; } - dmFaCallback_.erase(pkgName); + dmUiCallback_.erase(pkgName); } void DeviceManagerNotify::OnRemoteDied() @@ -271,15 +271,27 @@ void DeviceManagerNotify::OnVerifyAuthResult(const std::string &pkgName, const s verifyAuthCallback_.erase(pkgName); } -void DeviceManagerNotify::OnFaCall(std::string &pkgName, std::string ¶mJson) +void DeviceManagerNotify::OnUiCall(std::string &pkgName, std::string ¶mJson) { - LOGI("DeviceManager OnFaCallback pkgName:%s", pkgName.c_str()); - std::lock_guard autoLock(lock_); - if (dmFaCallback_.count(pkgName) == 0) { - LOGE("DeviceManager DmFaCallback not register"); + if (pkgName.empty()) { + LOGE("DeviceManagerNotify::OnUiCall error: Invalid parameter, pkgName: %s", pkgName.c_str()); + return; + } + LOGI("DeviceManagerNotify::OnUiCall in, pkgName:%s", pkgName.c_str()); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(lock_); + if (dmUiCallback_.count(pkgName) == 0) { + LOGE("OnUiCall error, dm Ui callback not register for pkgName %d.", pkgName.c_str()); + return; + } + tempCbk = dmUiCallback_[pkgName]; + } + if (tempCbk == nullptr) { + LOGE("OnUiCall error, registered dm Ui callback is nullptr."); return; } - dmFaCallback_[pkgName]->OnCall(paramJson); + tempCbk->OnCall(paramJson); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index b88a4f807257afed497186b89a9eecf7c2b95655..eff2ea5ade83a72d46b7afd0fe6805fb0c634046 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -170,12 +170,12 @@ private: std::unique_ptr jsCallback_; }; -class DmNapiDeviceManagerFaCallback : public OHOS::DistributedHardware::DeviceManagerFaCallback { +class DmNapiDeviceManagerUiCallback : public OHOS::DistributedHardware::DeviceManagerUiCallback { public: - explicit DmNapiDeviceManagerFaCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) + explicit DmNapiDeviceManagerUiCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) { } - virtual ~DmNapiDeviceManagerFaCallback() {}; + virtual ~DmNapiDeviceManagerUiCallback() {}; void OnCall(const std::string ¶mJson) override; private: @@ -284,7 +284,7 @@ public: void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason); void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason); void OnVerifyResult(const std::string &deviceId, int32_t resultCode, int32_t flag); - void OnDmfaCall(const std::string ¶mJson); + void OnDmUiCall(const std::string ¶mJson); private: static napi_value JsOffFrench(napi_env env, int32_t num, napi_value thisVar, napi_value argv[]); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index e3d51f8364b3370c9f0636ca2ed0b3853b003ecc..7c86730b7027ce77644a04e00d5acd33d942c4ca 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -39,7 +39,7 @@ const std::string DM_NAPI_EVENT_DEVICE_FOUND = "deviceFound"; const std::string DM_NAPI_EVENT_DEVICE_DISCOVERY_FAIL = "discoveryFail"; const std::string DM_NAPI_EVENT_DEVICE_SERVICE_DIE = "serviceDie"; const std::string DEVICE_MANAGER_NAPI_CLASS_NAME = "DeviceManager"; -const std::string DM_NAPI_EVENT_DMFA_CALLBACK = "dmFaCallback"; +const std::string DM_NAPI_EVENT_UI_STATE_CHANGE = "uiStateChange"; const int32_t DM_NAPI_ARGS_ONE = 1; const int32_t DM_NAPI_ARGS_TWO = 2; @@ -60,7 +60,7 @@ std::map> g_deviceStateC std::map> g_DiscoveryCallbackMap; std::map> g_authCallbackMap; std::map> g_verifyAuthCallbackMap; -std::map> g_dmfaCallbackMap; +std::map> g_dmUiCallbackMap; } // namespace thread_local napi_ref DeviceManagerNapi::sConstructor_ = nullptr; @@ -966,15 +966,15 @@ void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, return; } - if (eventType == DM_NAPI_EVENT_DMFA_CALLBACK) { - auto callback = std::make_shared(env, bundleName); + if (eventType == DM_NAPI_EVENT_UI_STATE_CHANGE) { + auto callback = std::make_shared(env, bundleName); int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback); if (ret != 0) { - LOGE("RegisterDeviceManagerFaCallback failed for bunderName %s", bundleName.c_str()); + LOGE("RegisterDeviceManagerFaCallback failed for bundleName %s", bundleName.c_str()); return; } - g_dmfaCallbackMap.erase(bundleName); - g_dmfaCallbackMap[bundleName] = callback; + g_dmUiCallbackMap.erase(bundleName); + g_dmUiCallbackMap[bundleName] = callback; } } @@ -1027,18 +1027,18 @@ void DeviceManagerNapi::ReleaseDmCallback(std::string &bundleName, std::string & return; } - if (eventType == DM_NAPI_EVENT_DMFA_CALLBACK) { - auto iter = g_dmfaCallbackMap.find(bundleName); - if (iter == g_dmfaCallbackMap.end()) { - LOGE("cannot find dmFaCallback for bunderName %s", bundleName.c_str()); + if (eventType == DM_NAPI_EVENT_UI_STATE_CHANGE) { + auto iter = g_dmUiCallbackMap.find(bundleName); + if (iter == g_dmUiCallbackMap.end()) { + LOGE("cannot find dmFaCallback for bundleName %s", bundleName.c_str()); return; } int32_t ret = DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(bundleName); if (ret != 0) { - LOGE("RegisterDevStateCallback failed for bunderName %s", bundleName.c_str()); + LOGE("RegisterDevStateCallback failed for bundleName %s", bundleName.c_str()); return; } - g_dmfaCallbackMap.erase(bundleName); + g_dmUiCallbackMap.erase(bundleName); return; } } @@ -1069,18 +1069,30 @@ napi_value DeviceManagerNapi::GetAuthenticationParamSync(napi_env env, napi_call napi_value DeviceManagerNapi::SetUserOperationSync(napi_env env, napi_callback_info info) { LOGI("SetUserOperationSync in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); + GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); napi_valuetype valueType; napi_typeof(env, argv[0], &valueType); NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Object expected."); + napi_valuetype strType; + napi_typeof(env, argv[1], &strType); + NAPI_ASSERT(env, strType == napi_string, "Wrong argument type, string expected."); int32_t action = 0; napi_get_value_int32(env, argv[0], &action); + + size_t typeLen = 0; + napi_get_value_string_utf8(env, argv[1], nullptr, 0, &typeLen); + NAPI_ASSERT(env, typeLen > 0, "typeLen == 0"); + NAPI_ASSERT(env, typeLen < DM_NAPI_BUF_LENGTH, "typeLen >= MAXLEN"); + char type[DM_NAPI_BUF_LENGTH] = {0}; + napi_get_value_string_utf8(env, argv[1], type, typeLen + 1, &typeLen); + + std::string params = type; DeviceManagerNapi *deviceManagerWrapper = nullptr; napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - int32_t ret = DeviceManager::GetInstance().SetUserOperation(deviceManagerWrapper->bundleName_, action); + int32_t ret = DeviceManager::GetInstance().SetUserOperation(deviceManagerWrapper->bundleName_, action, params); if (ret != 0) { - LOGE("SetUserOperation for bunderName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret); + LOGE("SetUserOperation for bundleName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret); } napi_value result = nullptr; napi_get_undefined(env, &result); @@ -1121,7 +1133,7 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatusSync(napi_env env, napi_st } } -void DmNapiDeviceManagerFaCallback::OnCall(const std::string ¶mJson) +void DmNapiDeviceManagerUiCallback::OnCall(const std::string ¶mJson) { uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); @@ -1130,7 +1142,7 @@ void DmNapiDeviceManagerFaCallback::OnCall(const std::string ¶mJson) } uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { - LOGE("DmNapiDeviceManagerFaCallback: OnCall, No memory"); + LOGE("DmNapiDeviceManagerUiCallback: OnCall, No memory"); return; } @@ -1141,29 +1153,27 @@ void DmNapiDeviceManagerFaCallback::OnCall(const std::string ¶mJson) DmNapiAuthJsCallback *callback = reinterpret_cast(work->data); DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); if (deviceManagerNapi == nullptr) { - LOGE("OnCall, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnCall, deviceManagerNapi not find for bundleName %s", callback->bundleName_.c_str()); return; } - deviceManagerNapi->OnDmfaCall(callback->token_); - if (work != nullptr) { - delete work; - } + deviceManagerNapi->OnDmUiCall(callback->token_); + delete work; + work = nullptr; }); if (ret != 0) { LOGE("Failed to execute OnCall work queue"); - if (work != nullptr) { - delete work; - } + delete work; + work = nullptr; } } -void DeviceManagerNapi::OnDmfaCall(const std::string ¶mJson) +void DeviceManagerNapi::OnDmUiCall(const std::string ¶mJson) { LOGI("OnCall for paramJson"); napi_value result; napi_create_object(env_, &result); SetValueUtf8String(env_, "param", paramJson, result); - OnEvent("dmFaCallback", DM_NAPI_ARGS_ONE, &result); + OnEvent(DM_NAPI_EVENT_UI_STATE_CHANGE, DM_NAPI_ARGS_ONE, &result); } void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status &status, diff --git a/interfaces/kits/js_mini/include/native_devicemanager_js.h b/interfaces/kits/js_mini/include/native_devicemanager_js.h index 752f681027c369548ea25b680ad206f9eb02b78f..1371e4e0c76e01c494446bbfb6c7c5d58a1ed77e 100644 --- a/interfaces/kits/js_mini/include/native_devicemanager_js.h +++ b/interfaces/kits/js_mini/include/native_devicemanager_js.h @@ -116,7 +116,7 @@ private: std::string bundleName_; }; -class DmJSIDeviceManagerFaCallback : public OHOS::DistributedHardware::DeviceManagerFaCallback { +class DmJSIDeviceManagerFaCallback : public OHOS::DistributedHardware::DeviceManagerUiCallback { public: explicit DmJSIDeviceManagerFaCallback(std::string &bundleName) : bundleName_(bundleName) {} virtual ~DmJSIDeviceManagerFaCallback() {}; diff --git a/services/devicemanagerservice/include/ability/dm_ability_manager.h b/services/devicemanagerservice/include/ability/dm_ability_manager.h index 64c27a5e5bffaf97a5f0db3099c61e611c2404bd..5094809df4763c91fb8da863d6ee51af6acd0b01 100644 --- a/services/devicemanagerservice/include/ability/dm_ability_manager.h +++ b/services/devicemanagerservice/include/ability/dm_ability_manager.h @@ -26,31 +26,20 @@ namespace OHOS { namespace DistributedHardware { -enum AbilityRole { ABILITY_ROLE_PASSIVE = 0, ABILITY_ROLE_INITIATIVE = 1, ABILITY_ROLE_UNKNOWN = 2 }; - enum AbilityStatus { ABILITY_STATUS_FAILED = 0, ABILITY_STATUS_SUCCESS = 1, ABILITY_STATUS_START = 2 }; -enum FaAction { +enum UiAction { USER_OPERATION_TYPE_ALLOW_AUTH = 0, USER_OPERATION_TYPE_CANCEL_AUTH = 1, USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT = 2, USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY = 3, - USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT = 4 + USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT = 4, + USER_OPERATION_TYPE_DONE_PINCODE_INPUT = 5 }; class DmAbilityManager { public: - AbilityRole GetAbilityRole(); - AbilityStatus StartAbility(AbilityRole role); - void StartAbilityDone(); - -private: - void waitForTimeout(uint32_t timeout_s); - -private: - sem_t mSem_; - AbilityStatus mStatus_; - AbilityRole mAbilityStatus_; + AbilityStatus StartAbility(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/authentication/auth_request_state.h b/services/devicemanagerservice/include/authentication/auth_request_state.h index 81c98308dd7468d624625fd953db14230c5fb136..b2e27df38549b07360cf8df65846baa78adbfb1d 100644 --- a/services/devicemanagerservice/include/authentication/auth_request_state.h +++ b/services/devicemanagerservice/include/authentication/auth_request_state.h @@ -66,12 +66,6 @@ public: int32_t Enter() override; }; -class AuthRequestInputState : public AuthRequestState { -public: - int32_t GetStateType() override; - int32_t Enter() override; -}; - class AuthRequestJoinState : public AuthRequestState { public: int32_t GetStateType() override; diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 3ca7ff45d1116c348b08da2d55f9a4affde35545..c194cc23f706ff3b3266b7aab8795e4272251ed4 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -144,7 +144,7 @@ public: int32_t StartAuthProcess(const int32_t &authType); void StartRespAuthProcess(); int32_t CreateGroup(); - int32_t AddMember(const std::string &deviceId); + int32_t AddMember(int32_t pinCode); std::string GetConnectAddr(std::string deviceId); int32_t JoinNetwork(); void AuthenticateFinish(); @@ -155,15 +155,33 @@ public: std::string GenerateGroupName(); void HandleAuthenticateTimeout(std::string name); void CancelDisplay(); + + /** + * @tc.name: DmAuthManager::UpdateInputDialogDisplay + * @tc.desc: Update InputDialog Display of the DeviceManager Authenticate Manager + * @tc.type: FUNC + */ + void UpdateInputDialogDisplay(bool isShow); + + /** + * @tc.name: DmAuthManager::GeneratePincode + * @tc.desc: Generate Pincode of the DeviceManager Authenticate Manager + * @tc.type: FUNC + */ int32_t GeneratePincode(); void ShowConfigDialog(); void ShowAuthInfoDialog(); void ShowStartAuthDialog(); int32_t GetAuthenticationParam(DmAuthParam &authParam); - int32_t OnUserOperation(int32_t action); + /** + * @tc.name: DmAuthManager::OnUserOperation + * @tc.desc: User Operation of the DeviceManager Authenticate Manager + * @tc.type: FUNC + */ + int32_t OnUserOperation(int32_t action, const std::string ¶ms); void UserSwitchEventCallback(int32_t userId); int32_t SetPageId(int32_t pageId); - int32_t SetReason(int32_t reason, int32_t state); + int32_t SetReasonAndFinish(int32_t reason, int32_t state); private: std::shared_ptr softbusConnector_; @@ -180,6 +198,8 @@ private: std::shared_ptr dmAbilityMgr_; bool isCryptoSupport_ = false; bool isFinishOfLocal_ = true; + int32_t authTimes_ = 0; + std::shared_ptr authPtr_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h index 0254a3fa1dbfd9b4666153a99376183580270cdc..a99e032a356e0df729ff3113549773ec5e3b735a 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/device_manager_service.h @@ -48,7 +48,7 @@ public: int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId); int32_t VerifyAuthentication(const std::string &authParam); int32_t GetFaParam(std::string &pkgName, DmAuthParam &authParam); - int32_t SetUserOperation(std::string &pkgName, int32_t action); + int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra); int32_t UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra); bool IsServiceInitialized(); diff --git a/services/devicemanagerservice/include/device_manager_service_listener.h b/services/devicemanagerservice/include/device_manager_service_listener.h index 15bfa27475eb7eb7f92510e9388d5128573fed29..c366166b602023fe2329636f00061d02d8cd4aac 100644 --- a/services/devicemanagerservice/include/device_manager_service_listener.h +++ b/services/devicemanagerservice/include/device_manager_service_listener.h @@ -36,7 +36,8 @@ public: int32_t reason); void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, const std::string &flag); - void OnFaCall(std::string &pkgName, std::string ¶mJson); + + void OnUiCall(std::string &pkgName, std::string ¶mJson); private: #if !defined(__LITEOS_M__) diff --git a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h index 62a535c83b8b8803a0f961ac5f45f93320355ef8..3d0e6c1c56a81045d9e42b57c51dff194dee83f7 100644 --- a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h +++ b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h @@ -49,6 +49,7 @@ private: std::queue discoveryQueue_; std::map discoveryContextMap_; std::shared_ptr timer_; + std::mutex locks_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp index fed65776c76e2d993accfce7eb5dc0668c6b6cc7..b0782d221d737014c5185904d89e6237723798d0 100644 --- a/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp +++ b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp @@ -19,31 +19,10 @@ namespace OHOS { namespace DistributedHardware { -AbilityRole DmAbilityManager::GetAbilityRole() +AbilityStatus DmAbilityManager::StartAbility() { - return mAbilityStatus_; -} - -AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) -{ - // not support for L1 yet, do nothing. jsut save status and role - mAbilityStatus_ = role; - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - return mStatus_; -} - -void DmAbilityManager::waitForTimeout(uint32_t timeout_s) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += (int32_t)timeout_s; - sem_timedwait(&mSem_, &ts); -} - -void DmAbilityManager::StartAbilityDone() -{ - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - sem_post(&mSem_); + // not support for L1 yet, do nothing. just save status and role + return AbilityStatus::ABILITY_STATUS_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp index a4916043b0223eedfc13f0fa6f83c45f7e7db8e9..3e5a58072106446538f0728eb897254072dfb6aa 100644 --- a/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp +++ b/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp @@ -21,55 +21,30 @@ #include "dm_constants.h" #include "dm_log.h" #include "parameter.h" -#include "semaphore.h" #include "single_instance.h" namespace OHOS { namespace DistributedHardware { namespace { -const int32_t ABILITY_START_TIMEOUT = 3; // 3 second const std::string bundleName = "com.ohos.devicemanagerui"; -const std::string abilityName = "com.ohos.devicemanagerui.MainAbility"; +const std::string abilityName = "com.ohos.devicemanagerui.ConfirmDialogAbility"; } // namespace -AbilityRole DmAbilityManager::GetAbilityRole() +AbilityStatus DmAbilityManager::StartAbility() { - return mAbilityStatus_; -} - -AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) -{ - mAbilityStatus_ = role; char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string deviceId = localDeviceId; - mStatus_ = AbilityStatus::ABILITY_STATUS_START; AAFwk::Want want; AppExecFwk::ElementName element(deviceId, bundleName, abilityName); want.SetElement(element); AAFwk::AbilityManagerClient::GetInstance()->Connect(); ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); - if (result != OHOS::ERR_OK) { - LOGE("Start Ability faild"); - mStatus_ = AbilityStatus::ABILITY_STATUS_FAILED; - return mStatus_; + if (result != 0) { + LOGE("Start Ability failed"); + return AbilityStatus::ABILITY_STATUS_FAILED; } - waitForTimeout(ABILITY_START_TIMEOUT); - return mStatus_; -} - -void DmAbilityManager::waitForTimeout(uint32_t timeout_s) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += (int32_t)timeout_s; - sem_timedwait(&mSem_, &ts); -} - -void DmAbilityManager::StartAbilityDone() -{ - mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; - sem_post(&mSem_); + return AbilityStatus::ABILITY_STATUS_SUCCESS; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/authentication/auth_request_state.cpp b/services/devicemanagerservice/src/authentication/auth_request_state.cpp index 7b6797cbcea17fa4fb345e12b66255ec1f454ba3..52a0ed4524de8df789b2331dfc0243ee2101aef2 100644 --- a/services/devicemanagerservice/src/authentication/auth_request_state.cpp +++ b/services/devicemanagerservice/src/authentication/auth_request_state.cpp @@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter() return DM_OK; } -int32_t AuthRequestInputState::GetStateType() -{ - return AuthState::AUTH_REQUEST_INPUT; -} - -int32_t AuthRequestInputState::Enter() -{ - LOGE("DmAuthManager::AuthRequestInputState"); - std::shared_ptr stateAuthManager = authManager_.lock(); - if (stateAuthManager == nullptr) { - LOGE("AuthRequestState::authManager_ null"); - return DM_FAILED; - } - stateAuthManager->ShowStartAuthDialog(); - return DM_OK; -} - int32_t AuthRequestJoinState::GetStateType() { return AuthState::AUTH_REQUEST_JOIN; @@ -152,7 +135,7 @@ int32_t AuthRequestJoinState::Enter() LOGE("AuthRequestState::authManager_ null"); return DM_FAILED; } - stateAuthManager->AddMember(context_->deviceId); + stateAuthManager->ShowStartAuthDialog(); return DM_OK; } diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 3bad99b534da2110664bda6850673dd0d33be72a..b758041c3f5b6b808524e882fbb3e42300aa0518 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -39,7 +39,9 @@ const int32_t WAIT_NEGOTIATE_TIMEOUT = 10; const int32_t WAIT_REQUEST_TIMEOUT = 10; const int32_t CANCEL_PIN_CODE_DISPLAY = 1; const int32_t DEVICE_ID_HALF = 2; +const int32_t MAX_AUTH_TIMES = 3; +constexpr const char* VERIFY_FAILED = "verifyFailed"; DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, std::shared_ptr listener, std::shared_ptr hiChainConnector) @@ -96,6 +98,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au return DM_INPUT_PARA_EMPTY; } + authPtr_ = authenticationMap_[authType]; if (timer_ == nullptr) { timer_ = std::make_shared(); } @@ -172,14 +175,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) LOGI("authResponseContext_ is not init"); return DM_AUTH_NOT_START; } - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return DM_FAILED; - } timer_->DeleteTimer(INPUT_TIMEOUT_TASK); - ptr = authenticationMap_[authResponseContext_->authType]; - int32_t ret = ptr->VerifyAuthentication(authResponseContext_->authToken, authParam); + int32_t ret = authPtr_->VerifyAuthentication(authResponseContext_->authToken, authParam); switch (ret) { case DM_OK: authRequestState_->TransitionTo(std::make_shared()); @@ -345,12 +342,11 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId int32_t pinCode = GeneratePincode(); nlohmann::json jsonObj; - jsonObj[PIN_CODE_KEY] = pinCode; jsonObj[PIN_TOKEN] = authResponseContext_->token; jsonObj[QR_CODE_KEY] = GenerateGroupName(); jsonObj[NFC_CODE_KEY] = GenerateGroupName(); authResponseContext_->authToken = jsonObj.dump(); - LOGI("DmAuthManager::AddMember start %s", authResponseContext_->authToken.c_str()); + LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str()); authResponseContext_->groupId = groupId; authResponseContext_->code = pinCode; authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -365,18 +361,25 @@ void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) LOGE("failed to OnMemberJoin because authResponseContext_ is nullptr"); return; } - LOGI("DmAuthManager OnMemberJoin start"); + LOGI("DmAuthManager OnMemberJoin start authTimes %d", authTimes_); if (authRequestState_ != nullptr) { - timer_->DeleteTimer(ADD_TIMEOUT_TASK); + authTimes_++; + timer_->DeleteTimer(std::string(ADD_TIMEOUT_TASK)); if (status != DM_OK || authResponseContext_->requestId != requestId) { - if (authRequestState_ != nullptr) { + if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = DM_AUTH_INPUT_FAILED; authRequestState_->TransitionTo(std::make_shared()); - return; + } else { + timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), INPUT_TIMEOUT, + [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + UpdateInputDialogDisplay(true); } + } else { + authRequestState_->TransitionTo(std::make_shared()); } - authRequestState_->TransitionTo(std::make_shared()); } } @@ -456,6 +459,8 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType); authResponseContext_->reply = DM_AUTH_NOT_SUPPORT; + } else { + authPtr_ = authenticationMap_[authResponseContext_->authType]; } std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); @@ -538,7 +543,7 @@ void DmAuthManager::StartRespAuthProcess() [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); - authRequestState_->TransitionTo(std::make_shared()); + authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("do not accept"); authResponseContext_->state = AuthState::AUTH_REQUEST_REPLY; @@ -560,23 +565,18 @@ int32_t DmAuthManager::CreateGroup() return DM_OK; } -int32_t DmAuthManager::AddMember(const std::string &deviceId) +int32_t DmAuthManager::AddMember(int32_t pinCode) { if (authResponseContext_ == nullptr) { LOGE("failed to AddMember because authResponseContext_ is nullptr"); return DM_FAILED; } - LOGI("DmAuthManager::AddMember start"); - nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false); - if (jsonObj.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return DM_FAILED; - } - LOGI("DmAuthManager::AddMember start %s", authResponseContext_->authToken.c_str()); + LOGI("DmAuthManager::AddMember start group id %s", authResponseContext_->groupId.c_str()); + timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); nlohmann::json jsonObject; jsonObject[TAG_GROUP_ID] = authResponseContext_->groupId; jsonObject[TAG_GROUP_NAME] = authResponseContext_->groupName; - jsonObject[PIN_CODE_KEY] = jsonObj[PIN_CODE_KEY]; + jsonObject[PIN_CODE_KEY] = pinCode; jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId; jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId; std::string connectInfo = jsonObject.dump(); @@ -584,18 +584,11 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); - int32_t ret = hiChainConnector_->AddMember(deviceId, connectInfo); + int32_t ret = hiChainConnector_->AddMember(authRequestContext_->deviceId, connectInfo); if (ret != 0) { + LOGE("DmAuthManager::AddMember failed, ret: %d", ret); return DM_FAILED; } - LOGI("DmAuthManager::authRequestContext CancelDisplay start"); - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return DM_FAILED; - } - ptr = authenticationMap_[authResponseContext_->authType]; - ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); return DM_OK; } @@ -629,14 +622,8 @@ void DmAuthManager::AuthenticateFinish() } LOGI("DmAuthManager::AuthenticateFinish start"); if (authResponseState_ != nullptr) { - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return ; - } - ptr = authenticationMap_[authResponseContext_->authType]; - ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH && authPtr_ != nullptr) { + UpdateInputDialogDisplay(false); } if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -648,6 +635,7 @@ void DmAuthManager::AuthenticateFinish() authResponseContext_ = nullptr; authResponseState_ = nullptr; authMessageProcessor_ = nullptr; + authPtr_ = nullptr; } else if (authRequestState_ != nullptr) { if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -656,14 +644,9 @@ void DmAuthManager::AuthenticateFinish() } else { authRequestContext_->reason = authResponseContext_->reply; } - if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return ; - } - ptr = authenticationMap_[authResponseContext_->authType]; - ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); + if ((authResponseContext_->state == AuthState::AUTH_REQUEST_JOIN || + authResponseContext_->state == AuthState::AUTH_REQUEST_FINISH) && authPtr_ != nullptr) { + UpdateInputDialogDisplay(false); } listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason); @@ -674,6 +657,8 @@ void DmAuthManager::AuthenticateFinish() authResponseContext_ = nullptr; authRequestState_ = nullptr; authMessageProcessor_ = nullptr; + authPtr_ = nullptr; + authTimes_ = 0; } LOGI("DmAuthManager::AuthenticateFinish complete"); } @@ -685,7 +670,18 @@ void DmAuthManager::CancelDisplay() jsonObj[CANCEL_DISPLAY_KEY] = CANCEL_PIN_CODE_DISPLAY; std::string paramJson = jsonObj.dump(); std::string pkgName = "com.ohos.devicemanagerui"; - listener_->OnFaCall(pkgName, paramJson); + listener_->OnUiCall(pkgName, paramJson); +} + +void DmAuthManager::UpdateInputDialogDisplay(bool isShow) +{ + LOGI("DmAuthManager::UpdateInputDialogDisplay start"); + nlohmann::json jsonObj; + jsonObj[VERIFY_FAILED] = isShow; + jsonObj.dump(); + std::string paramJson = jsonObj.dump(); + std::string pkgName = "com.ohos.devicemanagerui"; + listener_->OnUiCall(pkgName, paramJson); } int32_t DmAuthManager::GeneratePincode() @@ -746,12 +742,7 @@ int32_t DmAuthManager::GetPinCode() return DM_AUTH_NOT_START; } LOGI("ShowConfigDialog start add member pin code."); - nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false); - if (jsonObj.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return DM_FAILED; - } - return jsonObj[PIN_CODE_KEY]; + return authResponseContext_->code; } void DmAuthManager::ShowConfigDialog() @@ -779,15 +770,11 @@ void DmAuthManager::ShowAuthInfoDialog() LOGE("failed to ShowAuthInfoDialog because authResponseContext_ is nullptr"); return; } - LOGI("DmAuthManager::ShowAuthInfoDialog start"); - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return; - } - ptr = authenticationMap_[authResponseContext_->authType]; - LOGI("ShowAuthInfoDialog authToken:%s", authResponseContext_->authToken.c_str()); - ptr->ShowAuthInfo(authResponseContext_->authToken, shared_from_this()); + LOGI("DmAuthManager::ShowAuthInfoDialog start %d", authResponseContext_->code); + nlohmann::json jsonObj; + jsonObj[PIN_CODE_KEY] = authResponseContext_->code; + std::string authParam = jsonObj.dump(); + authPtr_->ShowAuthInfo(authParam, shared_from_this()); } void DmAuthManager::ShowStartAuthDialog() @@ -797,47 +784,18 @@ void DmAuthManager::ShowStartAuthDialog() return; } LOGI("DmAuthManager::ShowStartAuthDialog start"); - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return; - } - ptr = authenticationMap_[authResponseContext_->authType]; - ptr->StartAuth(authResponseContext_->authToken, shared_from_this()); + authPtr_->StartAuth(authResponseContext_->authToken, shared_from_this()); } int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) { - if (dmAbilityMgr_ == nullptr) { - LOGE("dmAbilityMgr_ is nullptr"); - return DM_POINT_NULL; - } - - if (authResponseContext_ == nullptr) { - LOGE("authResponseContext_ is not init"); - return DM_AUTH_NOT_START; - } - - dmAbilityMgr_->StartAbilityDone(); - AbilityRole role = dmAbilityMgr_->GetAbilityRole(); - authParam.direction = (int32_t)role; - authParam.authType = AUTH_TYPE_PIN; - authParam.authToken = authResponseContext_->token; - - if (role == AbilityRole::ABILITY_ROLE_PASSIVE) { - authParam.packageName = authResponseContext_->targetPkgName; - authParam.appName = authResponseContext_->appName; - authParam.appDescription = authResponseContext_->appDesc; - authParam.business = BUSINESS_FA_MIRGRATION; - authParam.pincode = authResponseContext_->code; - } return DM_OK; } -int32_t DmAuthManager::OnUserOperation(int32_t action) +int32_t DmAuthManager::OnUserOperation(int32_t action, const std::string ¶ms) { if (authResponseContext_ == nullptr) { - LOGE("authResponseContext_ is not init"); + LOGE("Authenticate is not start"); return DM_AUTH_NOT_START; } @@ -850,12 +808,12 @@ int32_t DmAuthManager::OnUserOperation(int32_t action) AuthenticateFinish(); break; case USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY: - CancelDisplay(); break; case USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT: - authRequestContext_->reason = DM_AUTH_DONT_AUTH; - authResponseContext_->state = authRequestState_->GetStateType(); - AuthenticateFinish(); + SetReasonAndFinish(ERR_DM_INPUT_PARA_INVALID, AuthState::AUTH_REQUEST_JOIN); + break; + case USER_OPERATION_TYPE_DONE_PINCODE_INPUT: + AddMember(std::stoi(params)); break; default: LOGE("this action id not support"); @@ -908,18 +866,20 @@ int32_t DmAuthManager::SetPageId(int32_t pageId) return DM_OK; } -int32_t DmAuthManager::SetReason(int32_t reason, int32_t state) +int32_t DmAuthManager::SetReasonAndFinish(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; - } authResponseContext_->state = state; authResponseContext_->reply = reason; + if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { + authRequestContext_->reason = reason; + authRequestState_->TransitionTo(std::make_shared()); + } else if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { + authResponseState_->TransitionTo(std::make_shared()); + } return DM_OK; } } // namespace DistributedHardware diff --git a/services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp b/services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp index fc0cb7f6f33c053ed7fb029b2eee521abd4d0d93..9d282459aa2e1de32882aa72532ad39387a2a1de 100644 --- a/services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp +++ b/services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp @@ -38,9 +38,9 @@ void ShowConfirm::ShowConfirmDialog(const std::string ¶ms, std::shared_ptrStartAbility(AbilityRole::ABILITY_ROLE_PASSIVE); + AbilityStatus status = dmAbilityMgr->StartAbility(); if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - LOGE("ShowConfirm::startFaservice timeout"); + LOGE("ShowConfirm::start ui service failed"); return; } LOGI("ShowConfirm hap end"); diff --git a/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp b/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp index c0d13c07d4477cfa8e915d6bcf190a2d109367a7..1a01e5a89e80ceb8d3f5358cf02519add9d78e93 100644 --- a/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp +++ b/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp @@ -34,27 +34,17 @@ ShowConfirm::~ShowConfirm() void ShowConfirm::ShowConfirmDialog(const std::string ¶ms, std::shared_ptr authManager, std::shared_ptr dmAbilityMgr) { - LOGI("ShowConfirm ace start"); - if (authManager == nullptr) { + LOGI("ShowConfirm hap start"); + if (dmAbilityMgr == nullptr) { LOGE("ShowConfirm::dmAbilityManager is null"); return; } - Ace::UIServiceMgrClient::GetInstance()->ShowDialog( - "config_dialog_service", - params, - 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) { - authManager->SetPageId(id); - } - if (strcmp(params.c_str(), "0") == 0 || strcmp(params.c_str(), "1") == 0) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); - LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - authManager->StartAuthProcess(atoi(params.c_str())); - } - }); - LOGI("ShowConfirm ace end"); + AbilityStatus status = dmAbilityMgr->StartAbility(); + if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { + LOGE("ShowConfirm::start ui service failed"); + return; + } + LOGI("ShowConfirm hap end"); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index d02ba51bcd3d92c63668216655d7849119bb144c..a71bcb012ca14f0a946827bfa8912b7ddc8e8adf 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -292,13 +292,17 @@ int32_t DeviceManagerService::GetFaParam(std::string &pkgName, DmAuthParam &auth return DM_OK; } -int32_t DeviceManagerService::SetUserOperation(std::string &pkgName, int32_t action) +int32_t DeviceManagerService::SetUserOperation(std::string &pkgName, int32_t action, + const std::string ¶ms) { - if (pkgName.empty()) { - LOGE("SetUserOperation failed, pkgName is empty"); + if (pkgName.empty() || params.empty()) { + LOGE("DeviceManagerService::SetUserOperation error: Invalid parameter, pkgName: %s", pkgName.c_str(), + params.c_str()); return DM_INPUT_PARA_EMPTY; } - authMgr_->OnUserOperation(action); + if (authMgr_ != nullptr) { + authMgr_->OnUserOperation(action, params); + } return DM_OK; } diff --git a/services/devicemanagerservice/src/device_manager_service_listener.cpp b/services/devicemanagerservice/src/device_manager_service_listener.cpp index c7f53eee4f9c6b9d2b47ed5ce55d383c8457d46c..e0976a099dc61d706c23fc47321ef3b2144670f3 100644 --- a/services/devicemanagerservice/src/device_manager_service_listener.cpp +++ b/services/devicemanagerservice/src/device_manager_service_listener.cpp @@ -108,9 +108,9 @@ void DeviceManagerServiceListener::OnVerifyAuthResult(const std::string &pkgName ipcServerListener_.SendAll(SERVER_VERIFY_AUTH_RESULT, pReq, pRsp); } -void DeviceManagerServiceListener::OnFaCall(std::string &pkgName, std::string ¶mJson) +void DeviceManagerServiceListener::OnUiCall(std::string &pkgName, std::string ¶mJson) { - LOGI("OnFaCall in"); + LOGI("OnUiCall in"); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index abdcfe044ba4b3f2a4810a67730762c55f82098b..c4793d311c2a287ef06558b60bb9998903d04e90 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -49,6 +49,7 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con StopDeviceDiscovery(discoveryQueue_.front(), discoveryContextMap_[discoveryQueue_.front()].subscribeId); } } + std::lock_guard autoLock(locks_); discoveryQueue_.push(pkgName); DmDiscoveryContext context = {pkgName, extra, subscribeInfo.subscribeId}; discoveryContextMap_.emplace(pkgName, context); @@ -66,6 +67,7 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { + std::lock_guard autoLock(locks_); if (!discoveryQueue_.empty()) { discoveryQueue_.pop(); } diff --git a/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp b/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp index c7bbd9b3029a7de3e4fa07e87c31fa21ea33eb2b..5b667c7395cb0bd362fb29e44e2000ee357b43ca 100644 --- a/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp +++ b/services/devicemanagerservice/src/dispatch/device_manager_service_listener_mini.cpp @@ -91,10 +91,10 @@ void DeviceManagerServiceListener::OnVerifyAuthResult(const std::string &pkgName } } -void DeviceManagerServiceListener::OnFaCall(std::string &pkgName, std::string ¶mJson) +void DeviceManagerServiceListener::OnUiCall(std::string &pkgName, std::string ¶mJson) { - LOGI("call OnFaCall in"); - DeviceManagerNotify::GetInstance().OnFaCall(pkgName, paramJson); + LOGI("call OnUiCall in"); + DeviceManagerNotify::GetInstance().OnUiCall(pkgName, paramJson); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp index 3feaaadf8b3db4775df3409972bdb386876f1385..d1b4f6df8f5296cc752ec9af6826f445095ed19f 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -428,8 +428,9 @@ ON_IPC_CMD(SERVER_USER_AUTH_OPERATION, MessageParcel &data, MessageParcel &reply { std::string packageName = data.ReadString(); int32_t action = data.ReadInt32(); - int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action); - if (!reply.WriteInt32(action)) { + std::string params = data.ReadString(); + int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action, params); + if (!reply.WriteInt32(result)) { LOGE("write result failed"); return DM_WRITE_FAILED; } diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index 49cda8a7cebdec52fa935d409e196700986d89ae..b942e2a75d22a6fa49c9b888d0948d4570aee92e 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -339,6 +339,7 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->sessionId = 1; + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->SetAuthRequestState(authRequestState); @@ -350,57 +351,6 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } -/** - * @tc.name: AuthRequestInputState::GetStateType_005 - * @tc.desc: 1 call AuthRequestInputState::GetStateType - * 2 check ret is AuthState::AUTH_REQUEST_INPUT - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) -{ - std::shared_ptr authRequestState = std::make_shared(); - int32_t ret = authRequestState->GetStateType(); - ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT); -} - -/** - * @tc.name: AuthRequestInputState::Enter_009 - * @tc.desc: 1 set authManager to null - * 2 call AuthRequestInputState::Enter with authManager = null - * 3 check ret is DM_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) -{ - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); - std::shared_ptr authRequestState = std::make_shared(); - authRequestState->SetAuthManager(nullptr); - int32_t ret = authRequestState->Enter(); - ASSERT_EQ(ret, DM_FAILED); -} - -/** - * @tc.name: AuthRequestInputState::Enter_010 - * @tc.desc: 1 set authManager not null - * 2 call AuthRequestInputState::Enter with authManager != null - * 3 check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) -{ - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); - authManager->authResponseContext_ = std::make_shared(); - std::shared_ptr authRequestState = std::make_shared(); - authRequestState->SetAuthManager(authManager); - int32_t ret = authRequestState->Enter(); - ASSERT_EQ(ret, DM_OK); -} - /** * @tc.name: AuthRequestJoinState::GetStateType_006 * @tc.desc: 1 call AuthRequestJoinState::GetStateType @@ -449,12 +399,14 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authResponseContext_->groupId = "111"; authManager->authResponseContext_->groupName = "222"; authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; authRequestState->SetAuthManager(authManager); + authManager->timer_ = std::make_shared(); authManager->SetAuthRequestState(authRequestState); authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); @@ -516,6 +468,7 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authRequestState_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); @@ -571,6 +524,7 @@ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authManager->timer_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index ae10ad41e9d784a3bda9cccf2f46695c275e7c89..0b9d1808aec59150ae4448c53a464ccf488e486c 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -198,6 +198,7 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->deviceId = "111"; authManager->authResponseContext_->localDeviceId = "222"; + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); @@ -360,6 +361,8 @@ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0) std::make_shared(softbusConnector, listener, hiChainConnector); authManager->authResponseContext_ = std::make_shared(); std::shared_ptr authResponseState = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; + authManager->authResponseContext_->code = 123456; authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); @@ -416,6 +419,7 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->listener_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authResponseContext_->sessionId = 1; authManager->authRequestContext_->deviceId = "2"; authManager->authRequestContext_->hostPkgName = "3"; @@ -423,6 +427,7 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) authManager->authResponseContext_->reply = 5; authManager->authRequestContext_->reason = 6; authManager->SetAuthResponseState(authResponseState); + authManager->timer_ = std::make_shared(); authResponseState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); authResponseState->SetAuthContext(context); diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index fd869ef0ddcbb73c13df5c8bcfe1e5d482c01069..e6759921eee431feaa0fadf4c6ce5b3e1de73109 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -208,11 +208,12 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; - std::string deviceId = "44444"; + int32_t pinCode = 444444; + authManager->timer_ = std::make_shared(); authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->SetAuthResponseState(authResponseState); - int32_t ret = authManager->AddMember(deviceId); - ASSERT_EQ(ret, DM_FAILED); + int32_t ret = authManager->AddMember(pinCode); + ASSERT_NE(ret, -1); } /** @@ -264,8 +265,9 @@ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) std::shared_ptr authManager = std::make_shared(softbusConnector, listener, hiChainConnector_); authManager->authResponseContext_ = std::make_shared(); + authManager->authResponseContext_->code = 123456; int32_t ret = authManager->GetPinCode(); - ASSERT_EQ(ret, DM_FAILED); + ASSERT_EQ(ret, 123456); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp index 8e029a42d1d3d8bb326b9863a40e59c878c29df4..e3ff7b91e541b4b654b30d6391ff0d084a7e8183 100644 --- a/test/unittest/UTTest_dm_discovery_manager.cpp +++ b/test/unittest/UTTest_dm_discovery_manager.cpp @@ -88,6 +88,7 @@ HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_001, testing::ext::TestSiz discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); EXPECT_EQ(ret, DM_DISCOVERY_REPEATED); + discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); } /** @@ -106,6 +107,7 @@ HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSiz pkgName = "com.ohos.helloworld.new"; int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); ASSERT_EQ(ret, DM_DISCOVERY_FAILED); + discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); } /** diff --git a/test/unittest/auth_request_state.cpp b/test/unittest/auth_request_state.cpp index 7b6797cbcea17fa4fb345e12b66255ec1f454ba3..55a21bc33bef2953bb61d204e58372286a436ee7 100644 --- a/test/unittest/auth_request_state.cpp +++ b/test/unittest/auth_request_state.cpp @@ -58,22 +58,6 @@ int32_t AuthRequestState::TransitionTo(std::shared_ptr state) return DM_OK; } -int32_t AuthRequestInitState::GetStateType() -{ - return AuthState::AUTH_REQUEST_INIT; -} - -int32_t AuthRequestInitState::Enter() -{ - std::shared_ptr stateAuthManager = authManager_.lock(); - if (stateAuthManager == nullptr) { - LOGE("AuthRequestState::authManager_ null"); - return DM_FAILED; - } - stateAuthManager->EstablishAuthChannel(context_->deviceId); - return DM_OK; -} - int32_t AuthRequestNegotiateState::GetStateType() { return AuthState::AUTH_REQUEST_NEGOTIATE;