1 /* 2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "spatial_location_callback_impl.h" 17 #include "dm_auth_state.h" 18 #include "multiple_user_connector.h" 19 #include "dm_auth_state_machine.h" 20 21 namespace OHOS { 22 namespace DistributedHardware { 23 constexpr int32_t pinCodeLength = 6; 24 SpatialLocationCallbackImpl(std::shared_ptr<DmAuthContext> context)25SpatialLocationCallbackImpl::SpatialLocationCallbackImpl(std::shared_ptr<DmAuthContext> context) 26 { 27 LOGI("SpatialLocationCallbackImpl Init."); 28 context_ = context; 29 } 30 ~SpatialLocationCallbackImpl()31SpatialLocationCallbackImpl::~SpatialLocationCallbackImpl() 32 { 33 LOGI("SpatialLocationCallbackImpl End."); 34 } 35 OnPinCodeChanged(const Msdp::PinCodeResponse & pinCodeResponse)36void SpatialLocationCallbackImpl::OnPinCodeChanged(const Msdp::PinCodeResponse &pinCodeResponse) 37 { 38 LOGI("Start."); 39 if (pinCodeResponse.pincode.length() != pinCodeLength) { 40 LOGE("OnPinCodeChanged pincode length error."); 41 return; 42 } 43 if (!IsValidPinCodeStr(pinCodeResponse.pincode)) { 44 LOGE("OnPinCodeChanged pincode is invalid"); 45 return; 46 } 47 if (context_ == nullptr) { 48 LOGE("OnPinCodeChanged context_ empty."); 49 return; 50 } 51 context_->pinCode = pinCodeResponse.pincode; 52 context_->authStateMachine->NotifyEventFinish(DmEventType::ON_ULTRASONIC_PIN_CHANGED); 53 } 54 IsValidPinCodeStr(const std::string & pinCodeStr)55bool SpatialLocationCallbackImpl::IsValidPinCodeStr(const std::string &pinCodeStr) 56 { 57 for (auto &digit : pinCodeStr) { 58 if (digit < '0' || digit > '9') { 59 return false; 60 } 61 } 62 return true; 63 } 64 } // namespace DistributedHardware 65 } // namespace OHOS