diff --git a/bundle.json b/bundle.json index 67f9fa2..66239a1 100644 --- a/bundle.json +++ b/bundle.json @@ -59,7 +59,8 @@ "//foundation/distributedhardware/distributed_input/sourcehandler:libdinput_source_handler", "//foundation/distributedhardware/distributed_input/sinkhandler:libdinput_sink_handler", "//foundation/distributedhardware/distributed_input/inputdevicehandler:libdinput_handler", - "//foundation/distributedhardware/distributed_input/dfx_utils:libdinput_dfx_utils" + "//foundation/distributedhardware/distributed_input/dfx_utils:libdinput_dfx_utils", + "//foundation/distributedhardware/distributed_input/utils:libdinput_utils" ], "inner_kits":[ { diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 02e52eb..48dc40c 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -133,8 +133,6 @@ namespace DistributedInput { /* The input device is external (not built-in). */ constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000; - const std::string LOCAL_DEV_ID = "localNodeDevice"; - enum class EHandlerMsgType { DINPUT_SINK_EVENT_HANDLER_MSG = 1, DINPUT_SOURCE_EVENT_HANDLER_MSG = 2 diff --git a/common/include/test/whitelistunittest/BUILD.gn b/common/include/test/whitelistunittest/BUILD.gn index 247d7ca..7b4087f 100644 --- a/common/include/test/whitelistunittest/BUILD.gn +++ b/common/include/test/whitelistunittest/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("distributed_input_white_list_test") { "${service_common}/include", "//third_party/json/include", "//foundation/communication/dsoftbus/interfaces/kits/transport", + "${utils_path}/include", ] sources = [ @@ -68,6 +69,7 @@ ohos_unittest("distributed_input_white_list_test") { "//utils/native/base:utils", "${fwk_utils_path}:distributedhardwareutils", "//foundation/communication/dsoftbus/sdk:softbus_client", + "${utils_path}:libdinput_utils", ] external_deps = [ diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index 8cfc33c..f7418bc 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -23,6 +23,7 @@ #include "distributed_hardware_log.h" #include "dinput_errcode.h" +#include "dinput_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -101,7 +102,13 @@ int32_t WhiteListUtil::Init() } inFile.close(); - SyncWhiteList(LOCAL_DEV_ID, vecWhiteList); + + std::string localNetworkId = GetLocalDeviceInfo().networkId; + if (!localNetworkId.empty()) { + SyncWhiteList(localNetworkId, vecWhiteList); + } else { + DHLOGE("query local network id from softbus failed"); + } DHLOGI("Local WhiteListUtil init success"); return DH_SUCCESS; diff --git a/frameworks/include/i_distributed_sink_input.h b/frameworks/include/i_distributed_sink_input.h index 189aef5..cddb558 100644 --- a/frameworks/include/i_distributed_sink_input.h +++ b/frameworks/include/i_distributed_sink_input.h @@ -29,8 +29,6 @@ namespace DistributedHardware { namespace DistributedInput { class IDistributedSinkInput : public IRemoteBroker { public: - static const int32_t SA_ID_DISTRIBUTED_INPUT_SINK_SERVICE = 4810; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IDistributedSinkInput"); virtual int32_t Init() = 0; diff --git a/frameworks/include/i_distributed_source_input.h b/frameworks/include/i_distributed_source_input.h index d603454..5194fce 100644 --- a/frameworks/include/i_distributed_source_input.h +++ b/frameworks/include/i_distributed_source_input.h @@ -37,8 +37,6 @@ namespace DistributedHardware { namespace DistributedInput { class IDistributedSourceInput : public IRemoteBroker { public: - static const int32_t SA_ID_DISTRIBUTED_INPUT_SOURCE_SERVICE = 4809; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IDistributedSourceInput"); virtual int32_t Init() = 0; diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index 230d60c..1581104 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -28,6 +28,7 @@ ohos_shared_library("libdinput_sdk") { "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", + "${utils_path}/include", "//third_party/json/include", ] sources = [ @@ -62,6 +63,7 @@ ohos_shared_library("libdinput_sdk") { deps = [ "//utils/native/base:utils", "${fwk_utils_path}:distributedhardwareutils", + "${utils_path}:libdinput_utils" ] defines = [ diff --git a/interfaces/inner_kits/test/unittest/BUILD.gn b/interfaces/inner_kits/test/unittest/BUILD.gn index 9e7c1b5..fba5d62 100644 --- a/interfaces/inner_kits/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/BUILD.gn @@ -41,6 +41,7 @@ ohos_unittest("distributed_input_inner_test") { "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", "//third_party/json/include", + "${utils_path}/include", ] sources = [ @@ -63,9 +64,7 @@ ohos_unittest("distributed_input_inner_test") { "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/distributed_input_source_proxy.cpp", - "//foundation/distributedhardware/distributed_input/interfaces/inner_kits/test/unittest/mock/mock_distributed_input_client.cpp", - "distributed_input_inner_test.cpp", ] @@ -87,6 +86,7 @@ ohos_unittest("distributed_input_inner_test") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//utils/native/base:utils", "${fwk_utils_path}:distributedhardwareutils", + "${utils_path}:libdinput_utils", ] external_deps = [ diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp index 4510965..2b32555 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -15,6 +15,8 @@ #include "distributed_input_inner_test.h" +#include "system_ability_definition.h" + using namespace testing::ext; using namespace OHOS::DistributedHardware::DistributedInput; using namespace std; @@ -82,7 +84,7 @@ int DistributedInputInnerTest::CheckSourceProxy() const } OHOS::sptr remoteObject = systemAbilityManager->GetSystemAbility( - IDistributedSourceInput::SA_ID_DISTRIBUTED_INPUT_SOURCE_SERVICE); + DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID); if (!remoteObject) { return SUCCESS; } @@ -106,7 +108,7 @@ int DistributedInputInnerTest::CheckSinkProxy() const } OHOS::sptr remoteObject = systemAbilityManager->GetSystemAbility( - IDistributedSinkInput::SA_ID_DISTRIBUTED_INPUT_SINK_SERVICE); + DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID); if (!remoteObject) { return SUCCESS; } diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index b1fae0e..21fb242 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -140,7 +140,7 @@ int32_t DistributedInputClient::ReleaseSink() serverType = DInputServerType::NULL_SERVER_TYPE; inputTypes_ = DInputDeviceType::NONE; sinkTypeCallback = nullptr; - WhiteListUtil::GetInstance().ClearWhiteList(LOCAL_DEV_ID); + WhiteListUtil::GetInstance().ClearWhiteList(); return DinputSAManager::GetInstance().dInputSinkProxy_->Release(); } diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn index 16ee48e..d88a719 100644 --- a/services/sink/sinkmanager/BUILD.gn +++ b/services/sink/sinkmanager/BUILD.gn @@ -34,6 +34,7 @@ ohos_shared_library("libdinput_sink") { "${services_sink_path}/inputcollector/include", "//third_party/json/include", "${dfx_utils_path}/include", + "${utils_path}/include", ] sources = [ @@ -59,6 +60,7 @@ ohos_shared_library("libdinput_sink") { "//foundation/distributedhardware/distributed_input/services/sink/transport:libdinput_sink_trans", "//foundation/distributedhardware/distributed_input/services/sink/inputcollector:libdinput_collector", "${dfx_utils_path}:libdinput_dfx_utils", + "${utils_path}:libdinput_utils", ] external_deps = [ diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 5b3cafc..5cad6da 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -28,6 +28,7 @@ #include "distributed_input_sink_transport.h" #include "dinput_errcode.h" +#include "dinput_utils_tool.h" #include "hidumper.h" #include "white_list_util.h" @@ -80,7 +81,12 @@ void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput( // send prepare result and if result ok, send white list TYPE_WHITE_LIST_VEC vecFilter; - WhiteListUtil::GetInstance().GetWhiteList(LOCAL_DEV_ID, vecFilter); + std::string localNetworkId = GetLocalDeviceInfo().networkId; + if (!localNetworkId.empty()) { + WhiteListUtil::GetInstance().GetWhiteList(localNetworkId, vecFilter); + } else { + DHLOGE("query local network id from softbus failed"); + } if (vecFilter.empty() || vecFilter[0].empty() || vecFilter[0][0].empty()) { DHLOGE("onPrepareRemoteInput called, white list is null."); jsonStr[DINPUT_SOFTBUS_KEY_RESP_VALUE] = true; diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn index a2c4ad7..d94db35 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("distributed_input_sinkmanager_test") { "//foundation/communication/dsoftbus/interfaces/kits/transport", "${services_sink_path}/inputcollector/include", "${dfx_utils_path}/include", + "${utils_path}/include", ] sources = [ @@ -82,6 +83,7 @@ ohos_unittest("distributed_input_sinkmanager_test") { "//foundation/communication/dsoftbus/sdk:softbus_client", "//third_party/openssl:libcrypto_static", "${dfx_utils_path}:libdinput_dfx_utils", + "${utils_path}:libdinput_utils", ] external_deps = [ diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index 6da902d..dff027e 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("libdinput_source") { "${services_source_path}/inputinject/include", "${services_source_path}/transport/include", "${dfx_utils_path}/include", + "${utils_path}/include", "//third_party/json/include", "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter", ] @@ -79,6 +80,7 @@ ohos_shared_library("libdinput_source") { "//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans", "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", "${dfx_utils_path}:libdinput_dfx_utils", + "${utils_path}:libdinput_utils", ] external_deps = [ diff --git a/utils/BUILD.gn b/utils/BUILD.gn new file mode 100644 index 0000000..2197e33 --- /dev/null +++ b/utils/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2022 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import( + "//foundation/distributedhardware/distributed_input/distributedinput.gni") + +ohos_shared_library("libdinput_utils") { + include_dirs = [ + "${fwk_common_path}/log/include", + "${fwk_utils_path}/include", + "${fwk_utils_path}/include/log", + "${utils_path}/include", + ] + + sources = [ + "src/dinput_utils_tool.cpp", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"dinpututils\"", + "LOG_DOMAIN=0xD004100", + ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + ] + + external_deps = [ + "dsoftbus:softbus_client", + "hiviewdfx_hilog_native:libhilog", + ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_input" +} diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h new file mode 100644 index 0000000..070906e --- /dev/null +++ b/utils/include/dinput_utils_tool.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H +#define OHOS_DISTRIBUTED_INPUT_UTILS_TOOL_H + +#include +#include + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +struct DevInfo { + std::string networkId; + std::string deviceName; + uint16_t deviceType; +}; + +DevInfo GetLocalDeviceInfo(); +} +} +} +#endif \ No newline at end of file diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp new file mode 100644 index 0000000..13dc5b3 --- /dev/null +++ b/utils/src/dinput_utils_tool.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dinput_utils_tool.h" + +#include "softbus_bus_center.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +namespace { + const std::string DINPUT_PKG_NAME = "ohos.dhardware.dinput"; +} + +DevInfo GetLocalDeviceInfo() +{ + DevInfo devInfo { "", "", 0 }; + auto info = std::make_unique(); + auto ret = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), info.get()); + if (ret != 0) { + DHLOGE("GetLocalNodeDeviceInfo failed, errCode = %d", ret); + return devInfo; + } + + devInfo.networkId = info->networkId; + devInfo.deviceName = info->deviceName; + devInfo.deviceType = info->deviceTypeId; + + return devInfo; +} +} +} +} \ No newline at end of file