From e086833ac7ca294d1bf54bf0d9362c4e1e6d3540 Mon Sep 17 00:00:00 2001 From: liqinglin <996260657@qq.com> Date: Thu, 19 Sep 2024 11:49:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=BB=84=E8=93=9D=E5=B7=AE=E5=BC=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqinglin <996260657@qq.com> --- bundle.json | 2 +- .../src/deviceprofile_connector.cpp | 5 +- .../ets/UIExtAbility/InputUIExtAbility.ets | 3 + .../src/main/ets/pages/ConfirmDialog.ets | 24 +++-- .../src/main/ets/pages/InputPinDialog.ets | 25 ++++-- .../main/resources/base/element/plural.json | 4 +- .../main/resources/base/element/string.json | 4 + .../main/resources/bo_CN/element/string.json | 4 + .../src/main/resources/ug/element/string.json | 4 + .../main/resources/zh_CN/element/string.json | 4 + .../main/resources/zh_HK/element/string.json | 6 +- .../main/resources/zh_TW/element/string.json | 4 + .../main/resources/zz_ZX/element/plural.json | 12 +-- .../main/resources/zz_ZX/element/string.json | 4 + .../src/notify/device_manager_notify.cpp | 4 +- services/implementation/BUILD.gn | 2 +- .../src/authentication/dm_auth_manager.cpp | 16 +++- .../src/device_manager_service_impl.cpp | 2 +- .../include/ipc/standard/ipc_server_stub.h | 2 - .../service/src/device_manager_service.cpp | 88 +++++++++---------- services/service/src/pinholder/pin_holder.cpp | 3 +- .../softbuscache/src/dm_softbus_cache.cpp | 7 +- test/commonunittest/UTTest_dm_timer.cpp | 2 +- utils/include/crypto/dm_crypto.h | 1 - utils/src/crypto/dm_crypto.cpp | 12 --- 25 files changed, 140 insertions(+), 104 deletions(-) diff --git a/bundle.json b/bundle.json index 8e193b87c..788963479 100644 --- a/bundle.json +++ b/bundle.json @@ -40,8 +40,8 @@ "device_info_manager", "dsoftbus", "eventhandler", - "hicollie", "ffrt", + "hicollie", "hisysevent", "hitrace", "hilog", diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 60dde1581..3d4bda835 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -704,7 +704,7 @@ int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid) int32_t DeviceProfileConnector::CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("DeviceProfileConnector::CheckAccessControl pkgName %{public}s, srcUdid %{public}s, sinkUdid %{public}s", + LOGI("DeviceProfileConnector::CheckAccessControl pkgName %{public}s, srcUdid %{public}s, sinkUdid %{public}s.", caller.pkgName.c_str(), GetAnonyString(srcUdid).c_str(), GetAnonyString(sinkUdid).c_str()); std::vector profiles = GetAccessControlProfile(); for (auto &item : profiles) { @@ -756,8 +756,7 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A int32_t DeviceProfileConnector::CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { - LOGI("DeviceProfileConnector::CheckAccessControl pkgName %{public}s, srcUdid %{public}s, sinkUdid %{public}s", - caller.pkgName.c_str(), GetAnonyString(srcUdid).c_str(), GetAnonyString(sinkUdid).c_str()); + LOGI("DeviceProfileConnector::CheckIsSameAccount"); std::vector profiles = GetAccessControlProfile(); for (auto &item : profiles) { if (item.GetStatus() != ACTIVE || (item.GetTrustDeviceId() != sinkUdid && diff --git a/display/entry/src/main/ets/UIExtAbility/InputUIExtAbility.ets b/display/entry/src/main/ets/UIExtAbility/InputUIExtAbility.ets index 4c24158c3..15a8081dc 100644 --- a/display/entry/src/main/ets/UIExtAbility/InputUIExtAbility.ets +++ b/display/entry/src/main/ets/UIExtAbility/InputUIExtAbility.ets @@ -24,6 +24,9 @@ export default class InputUIExtAbility extends UIExtensionAbility { if (want.parameters && want.parameters.targetDeviceName) { AppStorage.setOrCreate('targetDeviceName', want.parameters.targetDeviceName); } + if (want.parameters && want.parameters.model) { + AppStorage.setOrCreate('model', want.parameters.model); + } let param: Record = { 'session': session diff --git a/display/entry/src/main/ets/pages/ConfirmDialog.ets b/display/entry/src/main/ets/pages/ConfirmDialog.ets index 2e320c6a2..598b966e3 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialog.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialog.ets @@ -139,14 +139,6 @@ struct ConfirmCustomDialog { } destruction() { - if (dmClass != null) { - try { - dmClass.release(); - dmClass = null; - } catch (error) { - console.log('dmClass release failed') - } - } let session = AppStorage.get('ConfirmSession'); if (session) { session.terminateSelf(); @@ -356,6 +348,7 @@ struct dialogPlusPage { let tmpStr: Record = JSON.parse(data.param) let msg: number = tmpStr.uiStateMsg as number if (msg === MSG_CANCEL_CONFIRM_SHOW) { + console.log('cancel confirm show.') this.destruction() return } @@ -369,17 +362,22 @@ struct dialogPlusPage { } destruction() { + let session = AppStorage.get('ConfirmSession'); + if (session) { + session.terminateSelf(); + } + } + + aboutToDisappear() { + console.log(TAG + 'aboutToDisappear aboutToDisappear') if (dmClass != null) { try { + dmClass.off('uiStateChange'); dmClass.release(); - dmClass = null; } catch (error) { console.log('dmClass release failed') } - } - let session = AppStorage.get('ConfirmSession'); - if (session) { - session.terminateSelf(); + dmClass = null } } diff --git a/display/entry/src/main/ets/pages/InputPinDialog.ets b/display/entry/src/main/ets/pages/InputPinDialog.ets index d261d732a..1e0dd1e7c 100644 --- a/display/entry/src/main/ets/pages/InputPinDialog.ets +++ b/display/entry/src/main/ets/pages/InputPinDialog.ets @@ -26,6 +26,8 @@ const ACTION_DONE_PINCODE_INPUT: number = 5 const MSG_PIN_CODE_ERROR: number = 0 const MSG_CANCEL_PIN_CODE_INPUT: number = 3 const MSG_DOING_AUTH: number = 4 +const MODEL_PIN: string = 'pin'; +const MODEL_PASSWORD: string = 'password'; @CustomDialog struct InputCustomDialog { @@ -36,6 +38,7 @@ struct InputCustomDialog { @State errorTipsVisible: Visibility = Visibility.None; @State heightNum: number = 600; @State targetDeviceName: string = ''; + @State model: string = MODEL_PIN; @State isPC: boolean = false; @State btnColor: ResourceColor = Color.Transparent; listener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync('(orientation: landscape)'); @@ -67,6 +70,10 @@ struct InputCustomDialog { this.targetDeviceName = AppStorage.get('targetDeviceName') as string; console.log('targetDeviceName is ' + this.targetDeviceName); } + if (AppStorage.get('model') != null) { + this.model = AppStorage.get('model') as string; + console.log('model is ' + this.model); + } deviceManager.createDeviceManager('com.ohos.devicemanagerui.input', (err: Error, dm: deviceManager.DeviceManager) => { if (err) { @@ -88,11 +95,7 @@ struct InputCustomDialog { return; } if (msg === MSG_PIN_CODE_ERROR) { - this.isTimes--; - this.errorTips = $r('app.plural.dm_incorrect_code', this.isTimes, this.isTimes); - this.password = ''; - this.errorTipsVisible = Visibility.Visible; - this.passwordCircle = ['', '', '', '', '', '']; + this.inputCodeError(); } }) }); @@ -101,6 +104,18 @@ struct InputCustomDialog { }); } + inputCodeError() { + if (this.model == MODEL_PASSWORD) { + this.errorTips = $r('app.string.dm_password_error'); + } else { + this.isTimes--; + this.errorTips = $r('app.plural.dm_incorrect_code', this.isTimes, this.isTimes); + } + this.password = ''; + this.errorTipsVisible = Visibility.Visible; + this.passwordCircle = ['', '', '', '', '', '']; + } + cancel() { console.log('cancle'); if (dmClass) { diff --git a/display/entry/src/main/resources/base/element/plural.json b/display/entry/src/main/resources/base/element/plural.json index e19eb94d6..f103d249c 100644 --- a/display/entry/src/main/resources/base/element/plural.json +++ b/display/entry/src/main/resources/base/element/plural.json @@ -18,11 +18,11 @@ "value":[ { "quantity":"one", - "value":"Incorrect connection code. %d attempt remaining." + "value":"Incorrect. %d attempt remaining." }, { "quantity":"other", - "value":"Incorrect connection code. %d attempts remaining." + "value":"Incorrect. %d attempts remaining." } ] } diff --git a/display/entry/src/main/resources/base/element/string.json b/display/entry/src/main/resources/base/element/string.json index fdcc8bdf1..2aaa625a4 100644 --- a/display/entry/src/main/resources/base/element/string.json +++ b/display/entry/src/main/resources/base/element/string.json @@ -79,6 +79,10 @@ { "name":"dm_enter_peer_connect_code", "value":"Enter the peer connection code" + }, + { + "name":"dm_password_error", + "value":"Incorrect password. Connection failed." } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/bo_CN/element/string.json b/display/entry/src/main/resources/bo_CN/element/string.json index 172322a68..56d4566e0 100644 --- a/display/entry/src/main/resources/bo_CN/element/string.json +++ b/display/entry/src/main/resources/bo_CN/element/string.json @@ -55,6 +55,10 @@ { "name":"dm_bluetooth_dialog_content", "value":"སྒྲིག་ཆས་སྦྲེལ་མཐུད་བྱ་བར་སོ་སྔོན་ཁ་འབྱེད་དགོས། ཁ་ཕྱེ་ནས་ཡང་བསྐྱར་ཚོད་ལྟ་གནང་རོགས།" + }, + { + "name":"dm_password_error", + "value":"གསང་གྲངས་ནོར་འཁྲུལ་བྱུང་། སྦྲེལ་མཐུད་བྱེད་མ་ཐུབ།" } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/ug/element/string.json b/display/entry/src/main/resources/ug/element/string.json index bef55b20e..9ad7fa3fa 100644 --- a/display/entry/src/main/resources/ug/element/string.json +++ b/display/entry/src/main/resources/ug/element/string.json @@ -55,6 +55,10 @@ { "name":"dm_bluetooth_dialog_content", "value":"ئۈسكۈنە ئۇلاش ئۈچۈن كۆكچىشنى ئېچىش كېرەك، ئېچىپ قايتا سىناڭ." + }, + { + "name":"dm_password_error", + "value":"مەخپىي نومۇر خاتا، ئۇلانمىدى." } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/zh_CN/element/string.json b/display/entry/src/main/resources/zh_CN/element/string.json index cde7f2102..e4e630fb1 100644 --- a/display/entry/src/main/resources/zh_CN/element/string.json +++ b/display/entry/src/main/resources/zh_CN/element/string.json @@ -79,6 +79,10 @@ { "name":"dm_enter_peer_connect_code", "value":"输入对端连接码" + }, + { + "name":"dm_password_error", + "value":"密码错误,连接失败。" } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/zh_HK/element/string.json b/display/entry/src/main/resources/zh_HK/element/string.json index 52c71bd58..68988b20c 100644 --- a/display/entry/src/main/resources/zh_HK/element/string.json +++ b/display/entry/src/main/resources/zh_HK/element/string.json @@ -34,7 +34,7 @@ }, { "name":"dm_is_trust_device", - "value":"%s 信任此裝置?" + "value":"%s信任此裝置?" }, { "name":"dm_confirm_title_hap", @@ -55,6 +55,10 @@ { "name":"dm_bluetooth_dialog_content", "value":"裝置連接需要啟用藍牙。請先啟用,然後重試。" + }, + { + "name":"dm_password_error", + "value":"密碼錯誤,連接失敗。" } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/zh_TW/element/string.json b/display/entry/src/main/resources/zh_TW/element/string.json index a5e5c5eca..f6935899d 100644 --- a/display/entry/src/main/resources/zh_TW/element/string.json +++ b/display/entry/src/main/resources/zh_TW/element/string.json @@ -55,6 +55,10 @@ { "name":"dm_bluetooth_dialog_content", "value":"裝置連線需要啟用藍牙,請啟用後重試。" + }, + { + "name":"dm_password_error", + "value":"密碼錯誤,連線失敗。" } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/zz_ZX/element/plural.json b/display/entry/src/main/resources/zz_ZX/element/plural.json index f015807ed..45ea14644 100644 --- a/display/entry/src/main/resources/zz_ZX/element/plural.json +++ b/display/entry/src/main/resources/zz_ZX/element/plural.json @@ -5,27 +5,27 @@ "value":[ { "quantity":"one", - "value":"[TS_922746]_Incorrect connection code. %d attempt remaining." + "value":"[TS_922746]_Incorrect. %d attempt remaining." }, { "quantity":"other", - "value":"[TS_922743]_Incorrect connection code. %d attempts remaining." + "value":"[TS_922743]_Incorrect. %d attempts remaining." }, { "quantity":"zero", - "value":"[TS_922738]_Incorrect connection code. %d attempts remaining." + "value":"[TS_922738]_Incorrect. %d attempts remaining." }, { "quantity":"few", - "value":"[TS_922740]_Incorrect connection code. %d attempts remaining." + "value":"[TS_922740]_Incorrect. %d attempts remaining." }, { "quantity":"many", - "value":"[TS_922747]_Incorrect connection code. %d attempts remaining." + "value":"[TS_922747]_Incorrect. %d attempts remaining." }, { "quantity":"two", - "value":"[TS_922736]_Incorrect connection code. %d attempts remaining." + "value":"[TS_922736]_Incorrect. %d attempts remaining." } ] }, diff --git a/display/entry/src/main/resources/zz_ZX/element/string.json b/display/entry/src/main/resources/zz_ZX/element/string.json index 7404e663b..0d75833f2 100644 --- a/display/entry/src/main/resources/zz_ZX/element/string.json +++ b/display/entry/src/main/resources/zz_ZX/element/string.json @@ -75,6 +75,10 @@ { "name":"dm_confirm_intention", "value":"[TS_931360]_This is required for cross-device data syncing and collaboration." + }, + { + "name":"dm_password_error", + "value":"[TS_958913]_Incorrect password. Connection failed." } ] } \ No newline at end of file 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 49359aea1..89218971a 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 @@ -28,8 +28,8 @@ DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) constexpr const char* DEVICE_STATE_INIT_QUEUE = "deviceStateInitQueue"; #else -constexpr const char* DEVICE_ONLINE = "deviceOnline"; -constexpr const char* DEVICE_OFFLINE = "deviceOffline"; +constexpr const char* DEVICE_ONLINE = "deviceOnLine"; +constexpr const char* DEVICE_OFFLINE = "deviceOffLine"; constexpr const char* DEVICEINFO_CHANGE = "deviceInfoChange"; constexpr const char* DEVICE_READY = "deviceReady"; #endif diff --git a/services/implementation/BUILD.gn b/services/implementation/BUILD.gn index 1cc59a5c7..312496170 100644 --- a/services/implementation/BUILD.gn +++ b/services/implementation/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index c3f1d02a4..c4e4cda5a 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -473,7 +473,9 @@ void DmAuthManager::ProcessSourceMsg() break; case MSG_TYPE_REQ_SYNC_DELETE_DONE: if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_SYNCDELETE) { - timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + } isFinishOfLocal_ = false; authRequestState_->TransitionTo(std::make_shared()); } @@ -492,13 +494,17 @@ void DmAuthManager::ProcessSinkMsg() switch (authResponseContext_->msgType) { case MSG_TYPE_NEGOTIATE: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT) { - timer_->DeleteTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK)); + } authResponseState_->TransitionTo(std::make_shared()); } break; case MSG_TYPE_REQ_AUTH: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE) { - timer_->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); + } authResponseState_->TransitionTo(std::make_shared()); } break; @@ -520,7 +526,9 @@ void DmAuthManager::ProcessSinkMsg() break; case MSG_TYPE_REQ_SYNC_DELETE_DONE: if (authResponseState_->GetStateType() == AuthState::AUTH_REQUEST_SYNCDELETE) { - timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + } isFinishOfLocal_ = false; authResponseState_->TransitionTo(std::make_shared()); } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 0c348850a..7884f5f3e 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -22,9 +22,9 @@ #include "dm_crypto.h" #include "dm_distributed_hardware_load.h" #include "dm_log.h" -#include "dm_radar_helper.h" #include "multiple_user_connector.h" #include "app_manager.h" +#include "dm_radar_helper.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "dm_common_event_manager.h" #include "parameter.h" diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index d5390706f..77a83b211 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -160,8 +160,6 @@ private: mutable std::mutex listenerLock_; std::map> appRecipient_; std::map> dmListener_; - std::mutex dependsSASetLock_; - std::unordered_set dependsSASet_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index c0e400f14..720a424d0 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -130,15 +130,9 @@ void DeviceManagerService::QueryDependsSwitchState() { LOGI("DeviceManagerService::QueryDependsSwitchState start."); std::shared_ptr publishSubScriber = publshCommonEventManager_->GetSubscriber(); - if (publishSubScriber == nullptr) { - LOGE("publishSubScriber is nullptr."); - return; - } + CHECK_NULL_VOID(publishSubScriber); auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - LOGE("Get SystemAbilityManager Failed"); - return; - } + CHECK_NULL_VOID(samgr); #ifdef SUPPORT_BLUETOOTH if (samgr->CheckSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID) == nullptr) { publishSubScriber->SetBluetoothState(static_cast(Bluetooth::BTStateID::STATE_TURN_OFF)); @@ -1668,45 +1662,6 @@ void DeviceManagerService::HandleDeviceNotTrust(const std::string &msg) return; } -int32_t DeviceManagerService::SetDnPolicy(const std::string &pkgName, std::map &policy) -{ - if (!PermissionManager::GetInstance().CheckNewPermission()) { - LOGE("The caller does not have permission to call"); - return ERR_DM_NO_PERMISSION; - } - LOGI("Start for pkgName = %{public}s", pkgName.c_str()); - if (pkgName.empty()) { - LOGE("Invalid parameter, pkgName is empty."); - return ERR_DM_INPUT_PARA_INVALID; - } - auto policyStrategyIter = policy.find(PARAM_KEY_POLICY_STRATEGY_FOR_BLE); - if (policyStrategyIter == policy.end()) { - LOGE("Invalid parameter, DM_POLICY_STRATEGY_FOR_BLE is empty."); - return ERR_DM_INPUT_PARA_INVALID; - } - auto timeOutIter = policy.find(PARAM_KEY_POLICY_TIME_OUT); - if (timeOutIter == policy.end()) { - LOGE("Invalid parameter, DM_POLICY_TIMEOUT is empty."); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!IsNumberString(policyStrategyIter->second)) { - LOGE("Invalid parameter, DM_POLICY_STRATEGY_FOR_BLE is not number."); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!IsNumberString(timeOutIter->second)) { - LOGE("Invalid parameter, DM_POLICY_TIMEOUT is not number."); - return ERR_DM_INPUT_PARA_INVALID; - } - int32_t policyStrategy = std::stoi(policyStrategyIter->second); - int32_t timeOut = std::stoi(timeOutIter->second); - LOGD("strategy: %{public}d, timeOut: %{public}d", policyStrategy, timeOut); - if (!IsDMServiceAdapterLoad()) { - LOGE("SetDnPolicy failed, instance not init or init failed."); - return ERR_DM_UNSUPPORTED_METHOD; - } - return dmServiceImplExt_->SetDnPolicy(policyStrategy, timeOut); -} - #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void DeviceManagerService::ConvertUdidHashToAnoyDeviceId(DmDeviceInfo &deviceInfo) { @@ -1750,6 +1705,45 @@ int32_t DeviceManagerService::GetUdidHashByAnoyDeviceId(const std::string &anoyD } #endif +int32_t DeviceManagerService::SetDnPolicy(const std::string &pkgName, std::map &policy) +{ + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller does not have permission to call"); + return ERR_DM_NO_PERMISSION; + } + LOGI("Start for pkgName = %{public}s", pkgName.c_str()); + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + auto policyStrategyIter = policy.find(PARAM_KEY_POLICY_STRATEGY_FOR_BLE); + if (policyStrategyIter == policy.end()) { + LOGE("Invalid parameter, DM_POLICY_STRATEGY_FOR_BLE is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + auto timeOutIter = policy.find(PARAM_KEY_POLICY_TIME_OUT); + if (timeOutIter == policy.end()) { + LOGE("Invalid parameter, DM_POLICY_TIMEOUT is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsNumberString(policyStrategyIter->second)) { + LOGE("Invalid parameter, DM_POLICY_STRATEGY_FOR_BLE is not number."); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsNumberString(timeOutIter->second)) { + LOGE("Invalid parameter, DM_POLICY_TIMEOUT is not number."); + return ERR_DM_INPUT_PARA_INVALID; + } + int32_t policyStrategy = std::stoi(policyStrategyIter->second); + int32_t timeOut = std::stoi(timeOutIter->second); + LOGD("strategy: %{public}d, timeOut: %{public}d", policyStrategy, timeOut); + if (!IsDMServiceAdapterLoad()) { + LOGE("SetDnPolicy failed, instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExt_->SetDnPolicy(policyStrategy, timeOut); +} + void DeviceManagerService::SubscribePackageCommonEvent() { LOGI("Start"); diff --git a/services/service/src/pinholder/pin_holder.cpp b/services/service/src/pinholder/pin_holder.cpp index 3674c0929..5a4cb7b34 100644 --- a/services/service/src/pinholder/pin_holder.cpp +++ b/services/service/src/pinholder/pin_holder.cpp @@ -173,7 +173,8 @@ int32_t PinHolder::DestroyPinHolder(const std::string &pkgName, const PeerTarget ret = session_->SendData(sessionId_, message); int32_t stageRes = ret == DM_OK ? static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL); - DmRadarHelper::GetInstance().ReportDestroyPinHolder(registerPkgName_, targetId.deviceId, ret, stageRes); + DmRadarHelper::GetInstance().ReportDestroyPinHolder(registerPkgName_, + targetId.deviceId, ret, stageRes); if (ret != DM_OK) { LOGE("[SOFTBUS]SendBytes failed, ret: %{public}d.", ret); listener_->OnDestroyResult(registerPkgName_, ERR_DM_FAILED); diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index a7c9a7e39..b0dd64e15 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -310,7 +310,12 @@ int32_t SoftbusCache::GetSecurityDeviceLevel(const char *networkId, int32_t &sec return DM_OK; } } - return GetDevLevelFromBus(networkId, securityLevel); + int32_t ret = GetDevLevelFromBus(networkId, securityLevel); + if (ret == DM_OK) { + LOGI("Get dev level from softbus success."); + return DM_OK; + } + return ret; } int32_t SoftbusCache::GetDevLevelFromBus(const char *networkId, int32_t &securityLevel) diff --git a/test/commonunittest/UTTest_dm_timer.cpp b/test/commonunittest/UTTest_dm_timer.cpp index bcb9066b5..f883a68af 100644 --- a/test/commonunittest/UTTest_dm_timer.cpp +++ b/test/commonunittest/UTTest_dm_timer.cpp @@ -101,7 +101,7 @@ HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0) EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); ret = timer->DeleteTimer(name); - EXPECT_EQ(ERR_DM_FAILED, ret); + EXPECT_EQ(DM_OK, ret); } /** diff --git a/utils/include/crypto/dm_crypto.h b/utils/include/crypto/dm_crypto.h index 52d6f2bad..6eb10cc40 100644 --- a/utils/include/crypto/dm_crypto.h +++ b/utils/include/crypto/dm_crypto.h @@ -33,7 +33,6 @@ public: static int32_t GetSecRandom(uint8_t *out, size_t outLen); static std::string GetSecSalt(); static std::string GetHashWithSalt(const std::string &text, const std::string &salt); - static int32_t GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue); diff --git a/utils/src/crypto/dm_crypto.cpp b/utils/src/crypto/dm_crypto.cpp index 59bf08e3c..f340f1f62 100644 --- a/utils/src/crypto/dm_crypto.cpp +++ b/utils/src/crypto/dm_crypto.cpp @@ -210,18 +210,6 @@ std::string Crypto::GetHashWithSalt(const std::string &text, const std::string & return Crypto::Sha256(rawText); } -int32_t Crypto::GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash) -{ - unsigned char hash[SHA256_DIGEST_LENGTH] = ""; - DmGenerateStrHash(accountId.data(), accountId.size(), hash, SHA256_DIGEST_LENGTH, 0); - if (ConvertBytesToHexString(reinterpret_cast(accountIdHash), SHORT_ACCOUNTID_ID_HASH_LENGTH + 1, - reinterpret_cast(hash), SHORT_ACCOUNTID_ID_HASH_LENGTH / HEX_TO_UINT8) != DM_OK) { - LOGE("ConvertBytesToHexString failed."); - return ERR_DM_FAILED; - } - return DM_OK; -} - #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t Crypto::ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue) -- Gitee From 6c9beb80662806930941bb2d4246bda4c6401f00 Mon Sep 17 00:00:00 2001 From: liqinglin <996260657@qq.com> Date: Thu, 19 Sep 2024 14:05:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=BB=84=E8=93=9D=E5=B7=AE=E5=BC=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqinglin <996260657@qq.com> --- services/service/include/ipc/standard/ipc_server_stub.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index 77a83b211..d5390706f 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -160,6 +160,8 @@ private: mutable std::mutex listenerLock_; std::map> appRecipient_; std::map> dmListener_; + std::mutex dependsSASetLock_; + std::unordered_set dependsSASet_; }; } // namespace DistributedHardware } // namespace OHOS -- Gitee From acfde3d6f3308b4fcee24b953193261d8c9113ec Mon Sep 17 00:00:00 2001 From: liqinglin <996260657@qq.com> Date: Thu, 19 Sep 2024 17:44:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=93=9D=E9=BB=84=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqinglin <996260657@qq.com> --- .../native_cpp/src/device_manager_impl.cpp | 2 +- .../include/ipc/standard/ipc_server_stub.h | 2 - .../service/src/device_manager_service.cpp | 10 +++-- .../src/ipc/standard/ipc_server_stub.cpp | 40 +++++-------------- .../UTTest_dm_deviceprofile_connector.cpp | 4 +- test/commonunittest/UTTest_dm_timer.cpp | 2 +- .../UTTest_softbus_listener.cpp | 8 ++-- utils/src/crypto/dm_crypto.cpp | 1 - 8 files changed, 25 insertions(+), 44 deletions(-) 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 5b3cdd8d8..613c22806 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -125,7 +125,7 @@ int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::sh int32_t retryNum = 0; while (retryNum < SERVICE_INIT_TRY_MAX_NUM) { ret = ipcClientProxy_->Init(pkgName); - if (ret != ERR_DM_NOT_INIT) { + if (ret == DM_OK) { break; } usleep(USLEEP_TIME_MS); diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index d5390706f..77a83b211 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -160,8 +160,6 @@ private: mutable std::mutex listenerLock_; std::map> appRecipient_; std::map> dmListener_; - std::mutex dependsSASetLock_; - std::unordered_set dependsSASet_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 720a424d0..a30356ba5 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -162,10 +162,14 @@ void DeviceManagerService::QueryDependsSwitchState() #endif // SUPPORT_WIFI #ifdef SUPPORT_POWER_MANAGER - if (OHOS::PowerMgr::PowerMgrClient::GetInstance().IsScreenOn()) { - publishSubScriber->SetScreenState(DM_SCREEN_ON); - } else { + if (samgr->CheckSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr) { publishSubScriber->SetScreenState(DM_SCREEN_OFF); + } else { + if (OHOS::PowerMgr::PowerMgrClient::GetInstance().IsScreenOn()) { + publishSubScriber->SetScreenState(DM_SCREEN_ON); + } else { + publishSubScriber->SetScreenState(DM_SCREEN_OFF); + } } #else publishSubScriber->SetScreenState(DM_SCREEN_ON); diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index 670d25f48..44c59cdcd 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -60,46 +60,26 @@ void IpcServerStub::OnStart() AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN); AddSystemAbilityListener(SCREENLOCK_SERVICE_ID); - - { - std::lock_guard lock(dependsSASetLock_); - dependsSASet_.emplace(SOFTBUS_SERVER_SA_ID); -#ifdef SUPPORT_POWER_MANAGER - dependsSASet_.emplace(POWER_MANAGER_SERVICE_ID); // power -#endif // SUPPORT_POWER_MANAGER - } - AddSystemAbilityListener(SOFTBUS_SERVER_SA_ID); -#ifdef SUPPORT_POWER_MANAGER - AddSystemAbilityListener(POWER_MANAGER_SERVICE_ID); // power -#endif // SUPPORT_POWER_MANAGER + LOGI("called:AddAbilityListener end!"); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); #endif - DeviceManagerService::GetInstance().SubscribePackageCommonEvent(); - LOGI("called:AddAbilityListener end!"); + DeviceManagerService::GetInstance.SubscribePackageCommonEvent(); } void IpcServerStub::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { LOGI("OnAddSystemAbility systemAbilityId:%{public}d added!", systemAbilityId); - { - std::lock_guard lock(dependsSASetLock_); - if (dependsSASet_.find(systemAbilityId) != dependsSASet_.end()) { - dependsSASet_.erase(systemAbilityId); - if (dependsSASet_.empty()) { - DeviceManagerService::GetInstance().InitSoftbusListener(); - if (!Init()) { - LOGE("failed to init IpcServerStub"); - state_ = ServiceRunningState::STATE_NOT_START; - return; - } - state_ = ServiceRunningState::STATE_RUNNING; - } + if (systemAbilityId == SOFTBUS_SERVER_SA_ID) { + DeviceManagerService::GetInstance().InitSoftbusListener(); + if (!Init()) { + LOGE("failed to init IpcServerStub"); + state_ = ServiceRunningState::STATE_NOT_START; + return; } - } - - if (systemAbilityId == MEMORY_MANAGER_SA_ID) { + state_ = ServiceRunningState::STATE_RUNNING; + } else if (systemAbilityId == MEMORY_MANAGER_SA_ID) { int pid = getpid(); Memory::MemMgrClient::GetInstance().NotifyProcessStatus(pid, 1, 1, DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); } else if (systemAbilityId == SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN) { diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 5d6308a28..ecf3f49c2 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -719,11 +719,11 @@ HWTEST_F(DeviceProfileConnectorTest, CheckPkgnameInAcl_003, testing::ext::TestSi HWTEST_F(DeviceProfileConnectorTest, CheckPkgnameInAcl_004, testing::ext::TestSize.Level0) { - std::string pkgName = "bundleName2"; + std::string pkgName = "bundleName"; std::string localDeviceId = "deviceId"; std::string remoteDeviceId = "deviceId"; bool ret = DeviceProfileConnector::GetInstance().CheckPkgnameInAcl(pkgName, localDeviceId, remoteDeviceId); - EXPECT_EQ(ret, false); + EXPECT_EQ(ret, true); } HWTEST_F(DeviceProfileConnectorTest, IsSameAccount_001, testing::ext::TestSize.Level0) diff --git a/test/commonunittest/UTTest_dm_timer.cpp b/test/commonunittest/UTTest_dm_timer.cpp index f883a68af..bcb9066b5 100644 --- a/test/commonunittest/UTTest_dm_timer.cpp +++ b/test/commonunittest/UTTest_dm_timer.cpp @@ -101,7 +101,7 @@ HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0) EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret); ret = timer->DeleteTimer(name); - EXPECT_EQ(DM_OK, ret); + EXPECT_EQ(ERR_DM_FAILED, ret); } /** diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index f9892bc37..5e4de4522 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -495,7 +495,7 @@ HWTEST_F(SoftbusListenerTest, GetDmRadarHelperObj_001, testing::ext::TestSize.Le softbusListener = std::make_shared(); } auto ret = softbusListener->GetDmRadarHelperObj(); - EXPECT_NE(ret, nullptr); + EXPECT_EQ(ret, nullptr); } HWTEST_F(SoftbusListenerTest, SetHostPkgName_001, testing::ext::TestSize.Level0) @@ -525,7 +525,7 @@ HWTEST_F(SoftbusListenerTest, CacheDeviceInfo_001, testing::ext::TestSize.Level0 softbusListener = std::make_shared(); } softbusListener->CacheDeviceInfo(deviceId, infoPtr); - EXPECT_EQ(softbusListener->isRadarSoLoad_, true); + EXPECT_EQ(softbusListener->isRadarSoLoad_, false); } HWTEST_F(SoftbusListenerTest, CacheDeviceInfo_002, testing::ext::TestSize.Level0) @@ -537,7 +537,7 @@ HWTEST_F(SoftbusListenerTest, CacheDeviceInfo_002, testing::ext::TestSize.Level0 softbusListener = std::make_shared(); } softbusListener->CacheDeviceInfo(deviceId, infoPtr); - EXPECT_EQ(softbusListener->isRadarSoLoad_, true); + EXPECT_EQ(softbusListener->isRadarSoLoad_, false); } HWTEST_F(SoftbusListenerTest, CacheDeviceInfo_003, testing::ext::TestSize.Level0) @@ -549,7 +549,7 @@ HWTEST_F(SoftbusListenerTest, CacheDeviceInfo_003, testing::ext::TestSize.Level0 softbusListener = std::make_shared(); } softbusListener->CacheDeviceInfo(deviceId, infoPtr); - EXPECT_EQ(softbusListener->isRadarSoLoad_, true); + EXPECT_EQ(softbusListener->isRadarSoLoad_, false); } HWTEST_F(SoftbusListenerTest, GetIPAddrTypeFromCache_001, testing::ext::TestSize.Level0) diff --git a/utils/src/crypto/dm_crypto.cpp b/utils/src/crypto/dm_crypto.cpp index f340f1f62..21af4e112 100644 --- a/utils/src/crypto/dm_crypto.cpp +++ b/utils/src/crypto/dm_crypto.cpp @@ -40,7 +40,6 @@ constexpr int HEX_DIGIT_MAX_NUM = 16; constexpr int SHORT_DEVICE_ID_HASH_LENGTH = 16; constexpr int32_t SALT_LENGTH = 8; const std::string SALT_DEFAULT = "salt_defsalt_def"; -constexpr int SHORT_ACCOUNTID_ID_HASH_LENGTH = 6; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #define DM_MAX_DEVICE_ID_LEN (97) #endif -- Gitee