Description:Security check

Match-id-e53066c1703557b07cb7c9b48a9114e61ccb2e8f
This commit is contained in:
xxxx
2022-09-27 14:09:35 +08:00
parent 04d3a38a2c
commit df66979502
14 changed files with 455 additions and 304 deletions
+3
View File
@@ -41,6 +41,9 @@ namespace DistributedInput {
const uint32_t READ_SLEEP_TIME_MS = 50;
const uint32_t READ_RETRY_MAX = 5;
const uint32_t DHID_LENGTH_MAX = 256;
const uint32_t DEVID_LENGTH_MAX = 256;
const uint32_t SCREEN_MSG_MAX = 40 * 1024 * 1024;
/*
* Device Type definitions
*/
+1
View File
@@ -106,6 +106,7 @@ namespace DistributedInput {
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REG_CALLBACK_ERR = -65036;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR = -65039;
// handler error code
constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000;
+198
View File
@@ -0,0 +1,198 @@
/*
* Copyright (c) 2021-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 "constants_dinput.h"
#include "distributed_hardware_log.h"
#include "input_check_param.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
DinputCheckParam &DinputCheckParam::GetInstance(void)
{
static DinputCheckParam instance;
return instance;
}
bool DinputCheckParam::CheckParam(const std::string &deviceId, sptr<IRemoteBroker> callback)
{
if (deviceId.empty() || deviceId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam deviceId is empty or deviceId size too long.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckParam(const std::string& deviceId, const uint32_t& inputTypes,
sptr<IRemoteBroker> callback)
{
if (deviceId.empty() || deviceId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam deviceId is empty or deviceId size too long.");
return false;
}
if (inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
DHLOGE("CheckParam, inputTypes is invalids.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckParam(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
sptr<IRemoteBroker> callback)
{
if (srcId.empty() || srcId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam srcId is empty or srcId size too long.");
return false;
}
if (sinkId.empty() || sinkId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam sinkId is empty or sinkId size too long.");
return false;
}
if (inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
DHLOGE("CheckParam, inputTypes is invalids.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckParam(const std::string &srcId, const std::string &sinkId,
sptr<IRemoteBroker> callback)
{
if (srcId.empty() || srcId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam srcId is empty or srcId size too long.");
return false;
}
if (sinkId.empty() || sinkId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam sinkId is empty or sinkId size too long.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckParam(const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IRemoteBroker> callback)
{
if (sinkId.empty() || sinkId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam sinkId is empty or sinkId size too long.");
return false;
}
if (dhIds.empty()) {
DHLOGE("CheckParam dhIds is empty.");
return false;
}
for (auto iter : dhIds) {
if (iter.size() > DHID_LENGTH_MAX) {
DHLOGE("CheckParam dhId size is too long.");
return false;
}
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckParam(const std::string &srcId, const std::string &sinkId,
const std::vector<std::string> &dhIds, sptr<IRemoteBroker> callback)
{
if (srcId.empty() || srcId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam srcId is empty or srcId size too long.");
return false;
}
if (sinkId.empty() || sinkId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam sinkId is empty or sinkId size too long.");
return false;
}
if (dhIds.empty()) {
DHLOGE("CheckParam dhIds is empty.");
return false;
}
for (auto iter : dhIds) {
if (iter.size() > DHID_LENGTH_MAX) {
DHLOGE("CheckParam dhId size is too long.");
return false;
}
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckRegisterParam(const std::string &devId, const std::string &dhId,
const std::string &parameters, const std::shared_ptr<RegisterCallback> &callback)
{
if (devId.empty() || devId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam devId is empty or devId size too long.");
return false;
}
if (dhId.empty() || dhId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam dhId is empty or dhId size too long.");
return false;
}
if (parameters.empty()) {
DHLOGE("CheckParam parameters is empty.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
bool DinputCheckParam::CheckUnregisterParam(const std::string &devId, const std::string &dhId,
const std::shared_ptr<UnregisterCallback> &callback)
{
if (devId.empty() || devId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam devId is empty or devId size too long.");
return false;
}
if (dhId.empty() || dhId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam dhId is empty or dhId size too long.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2021-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 INPUT_CHECK_PARAM_H
#define INPUT_CHECK_PARAM_H
#include <iremote_broker.h>
#include "idistributed_hardware_source.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DinputCheckParam {
public:
static DinputCheckParam &GetInstance(void);
bool CheckParam(const std::string &deviceId, sptr<IRemoteBroker> callback);
bool CheckParam(const std::string &deviceId, const uint32_t &inputTypes, sptr<IRemoteBroker> callback);
bool CheckParam(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
sptr<IRemoteBroker> callback);
bool CheckParam(const std::string &srcId, const std::string &sinkId, sptr<IRemoteBroker> callback);
bool CheckParam(const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IRemoteBroker> callback);
bool CheckParam(const std::string &srcId, const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IRemoteBroker> callback);
bool CheckRegisterParam(const std::string &devId, const std::string &dhId,
const std::string &parameters, const std::shared_ptr<RegisterCallback> &callback);
bool CheckUnregisterParam(const std::string &devId, const std::string &dhId,
const std::shared_ptr<UnregisterCallback> &callback);
private:
DinputCheckParam() = default;
~DinputCheckParam() = default;
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // INPUT_CHECK_PARAM_H
+2 -2
View File
@@ -1102,11 +1102,11 @@ void InputHub::HandleTouchScreenEvent(struct input_event readBuffer[], const siz
for (size_t j = iter.first; j <= iter.second; j++) {
struct input_event &iev = readBuffer[j];
if (iev.code == ABS_X || iev.code == ABS_MT_POSITION_X) {
absInfo.absX = iev.value;
absInfo.absX = (uint32_t)iev.value;
absInfo.absXIndex = (int32_t)j;
}
if (iev.code == ABS_Y || iev.code == ABS_MT_POSITION_Y) {
absInfo.absY = iev.value;
absInfo.absY = (uint32_t)iev.value;
absInfo.absYIndex = (int32_t)j;
}
}
+2 -2
View File
@@ -80,8 +80,8 @@ private:
};
struct AbsInfo {
int32_t absX;
int32_t absY;
uint32_t absX;
uint32_t absY;
int32_t absXIndex;
int32_t absYIndex;
};
+46 -10
View File
@@ -15,6 +15,7 @@
#include "white_list_util.h"
#include <algorithm>
#include <cstring>
#include <fstream>
#include <sstream>
@@ -34,6 +35,11 @@ namespace {
const int32_t COMB_KEY_VEC_MIN_LEN = 2;
const int32_t LAST_KEY_ACTION_LEN = 1;
const int32_t LAST_KEY_LEN = 1;
const int32_t MAX_LINE_NUM = 100;
const int32_t MAX_CHAR_PER_LINE_NUM = 100;
const int32_t MAX_SPLIT_COMMA_NUM = 4;
const int32_t MAX_SPLIT_LINE_NUM = 12;
const int32_t MAX_KEY_CODE_NUM = 4;
}
WhiteListUtil::WhiteListUtil()
@@ -65,9 +71,13 @@ int32_t WhiteListUtil::Init()
TYPE_KEY_CODE_VEC vecKeyCode;
TYPE_COMBINATION_KEY_VEC vecCombinationKey;
TYPE_WHITE_LIST_VEC vecWhiteList;
std::string line;
std::size_t lineNum = 0;
while (getline(inFile, line)) {
if ((++lineNum > MAX_LINE_NUM) || CheckLine(line)) {
DHLOGE("whitelist cfg file has too many lines or too complicated. lineNum is %d", lineNum);
break;
}
DHLOGI("read whitelist cfg, line=%s", line.c_str());
vecKeyCode.clear();
vecCombinationKey.clear();
@@ -81,12 +91,11 @@ int32_t WhiteListUtil::Init()
ReadLineDataStepOne(column, vecKeyCode, vecCombinationKey);
}
if (!line.empty()) {
if (CheckIsNumber(line)) {
int32_t keyCode = std::stoi(line);
if (keyCode != 0) {
vecKeyCode.push_back(keyCode);
}
if (!vecKeyCode.empty()) {
vecCombinationKey.push_back(vecKeyCode);
vecKeyCode.clear();
@@ -98,20 +107,47 @@ int32_t WhiteListUtil::Init()
vecCombinationKey.clear();
}
}
inFile.close();
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;
}
bool WhiteListUtil::CheckLine(const std::string &line) const
{
if (line.size() > MAX_CHAR_PER_LINE_NUM) {
DHLOGE("This line is too long, size is %d", line.size());
return false;
}
if (std::count(line.begin(), line.end(), SPLIT_COMMA[0]) > MAX_SPLIT_COMMA_NUM) {
DHLOGE("This line %s has too many SPLIT_COMMA", line.c_str());
return false;
}
if (std::count(line.begin(), line.end(), SPLIT_LINE[0]) > MAX_SPLIT_LINE_NUM) {
DHLOGE("This line %s has too many SPLIT_LINE", line.c_str());
return false;
}
return true;
}
bool WhiteListUtil::CheckIsNumber(const std::string &str) const
{
if (str.empty() || str.size() > MAX_KEY_CODE_NUM) {
DHLOGE("KeyCode size %d, is zero or too long.", str.size());
return false;
}
for (char const &c : str) {
if (std::isdigit(c) == 0) {
DHLOGE("Check KeyCode format fail, %s.", str.c_str());
return false;
}
}
return true;
}
void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &vecKeyCode,
TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const
{
@@ -121,7 +157,7 @@ void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &
column = column.substr(pos2 + 1, column.size());
pos2 = column.find(SPLIT_LINE);
if (!single.empty()) {
if (CheckIsNumber(single)) {
int32_t keyCode = std::stoi(single);
if (keyCode != 0) {
vecKeyCode.push_back(keyCode);
@@ -129,7 +165,7 @@ void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &
}
}
if (!column.empty()) {
if (CheckIsNumber(column)) {
int32_t keyCode = std::stoi(column);
if (keyCode != 0) {
vecKeyCode.push_back(keyCode);
+2
View File
@@ -68,6 +68,8 @@ private:
void GetAllComb(TYPE_COMBINATION_KEY_VEC vecs, WhiteListItemHash hash,
int32_t targetLen, std::unordered_set<std::string> &hashSets);
std::string GetBusinessEventHash(const BusinessEvent &event);
bool CheckLine(const std::string &line) const;
bool CheckIsNumber(const std::string &str) const;
private:
TYPE_DEVICE_WHITE_LIST_MAP mapDeviceWhiteList_;
std::map<std::string, std::unordered_set<std::string>> combKeysHashMap_;
+1
View File
@@ -43,6 +43,7 @@ ohos_shared_library("libdinput_sdk") {
sources = [
"${common_path}/include/white_list_util.cpp",
"${common_path}/include/input_check_param.cpp",
"${innerkits_path}/src/distributed_input_kit.cpp",
"${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp",
"${ipc_path}/src/add_white_list_infos_call_back_stub.cpp",
+58 -119
View File
@@ -26,6 +26,7 @@
#include "dinput_errcode.h"
#include "dinput_utils_tool.h"
#include "distributed_input_source_proxy.h"
#include "input_check_param.h"
#include "softbus_bus_center.h"
#include "white_list_util.h"
@@ -324,18 +325,15 @@ int32_t DistributedInputClient::ReleaseSink()
int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
const std::string& parameters, const std::shared_ptr<RegisterCallback>& callback)
{
DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s",
DHLOGI("DinputRegister called, deviceId: %s, dhId: %s, parameters: %s.",
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("RegisterDistributedHardware client fail");
DHLOGE("DinputRegister client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (devId.empty() || dhId.empty() || parameters.empty() || !IsJsonData(parameters) || callback == nullptr) {
if (!DinputCheckParam::GetInstance().CheckRegisterParam(devId, dhId, parameters, callback)) {
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
}
{
std::lock_guard<std::mutex> lock(DistributedInputClient::GetInstance().operationMutex_);
for (auto iter : dHardWareFwkRstInfos) {
@@ -343,11 +341,7 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d
return ERR_DH_INPUT_CLIENT_REGISTER_FAIL;
}
}
DHardWareFwkRegistInfo info;
info.devId = devId;
info.dhId = dhId;
info.callback = callback;
DHardWareFwkRegistInfo info {devId, dhId, callback};
dHardWareFwkRstInfos.push_back(info);
}
@@ -358,18 +352,15 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d
int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
const std::shared_ptr<UnregisterCallback>& callback)
{
DHLOGI("UnregisterDistributedHardware called, deviceId: %s, dhId: %s",
DHLOGI("DinputUnregister called, deviceId: %s, dhId: %s.",
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("UnregisterDistributedHardware client fail");
DHLOGE("DinputUnregister client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (devId.empty() || dhId.empty() || callback == nullptr) {
if (!DinputCheckParam::GetInstance().CheckUnregisterParam(devId, dhId, callback)) {
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;
}
{
std::lock_guard<std::mutex> lock(DistributedInputClient::GetInstance().operationMutex_);
for (auto iter : dHardWareFwkUnRstInfos) {
@@ -377,11 +368,7 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string&
return ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL;
}
}
DHardWareFwkUnRegistInfo info;
info.devId = devId;
info.dhId = dhId;
info.callback = callback;
DHardWareFwkUnRegistInfo info {devId, dhId, callback};
dHardWareFwkUnRstInfos.push_back(info);
}
@@ -389,56 +376,42 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string&
new(std::nothrow) UnregisterDInputCb());
}
int32_t DistributedInputClient::PrepareRemoteInput(
const std::string& deviceId, sptr<IPrepareDInputCallback> callback)
int32_t DistributedInputClient::PrepareRemoteInput(const std::string& deviceId, sptr<IPrepareDInputCallback> callback)
{
DHLOGI("PrepareRemoteInput called, deviceId: %s", GetAnonyString(deviceId).c_str());
DHLOGI("DinputPrepare called, deviceId: %s.", GetAnonyString(deviceId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("PrepareRemoteInput client fail");
DHLOGE("DinputPrepare client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr) {
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, callback)) {
return ERR_DH_INPUT_CLIENT_PREPARE_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(deviceId, callback);
}
int32_t DistributedInputClient::UnprepareRemoteInput(const std::string& deviceId,
sptr<IUnprepareDInputCallback> callback)
{
DHLOGI("UnprepareRemoteInput called, deviceId: %s", GetAnonyString(deviceId).c_str());
DHLOGI("DinputUnprepare called, deviceId: %s.", GetAnonyString(deviceId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("PrepareRemoteInput client fail");
DHLOGE("DinputUnprepare client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr) {
DHLOGE("UnprepareRemoteInput param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, callback)) {
return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(deviceId, callback);
}
int32_t DistributedInputClient::StartRemoteInput(
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
{
DHLOGI("StartRemoteInput called, deviceId: %s, inputTypes: %d",
GetAnonyString(deviceId).c_str(), inputTypes);
DHLOGI("DinputStart called, deviceId: %s, inputTypes: %d.", GetAnonyString(deviceId).c_str(), inputTypes);
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StartRemoteInput client fail");
DHLOGE("DinputStart client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr ||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
DHLOGE("StartRemoteInput param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) {
return ERR_DH_INPUT_CLIENT_START_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(deviceId, inputTypes, callback);
@@ -447,79 +420,58 @@ int32_t DistributedInputClient::StartRemoteInput(
int32_t DistributedInputClient::StopRemoteInput(const std::string& deviceId, const uint32_t& inputTypes,
sptr<IStopDInputCallback> callback)
{
DHLOGI("StopRemoteInput called, deviceId: %s, inputTypes: %d",
GetAnonyString(deviceId).c_str(), inputTypes);
DHLOGI("DinputStop called, deviceId: %s, inputTypes: %d.", GetAnonyString(deviceId).c_str(), inputTypes);
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StopRemoteInput client fail");
DHLOGE("DinputStop client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (deviceId.empty() || callback == nullptr ||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
DHLOGE("StopRemoteInput param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) {
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(deviceId, inputTypes, callback);
}
int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
{
DHLOGI("StartRemoteInput relay by type called, srcId: %s, sinkId: %s, inputTypes: %d",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), inputTypes);
DHLOGI("DinputStart called, srcId: %s, sinkId: %s, inputTypes: %d.", GetAnonyString(srcId).c_str(),
GetAnonyString(sinkId).c_str(), inputTypes);
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StartRemoteInput relay type client fail");
DHLOGE("DinputStart relay type client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (srcId.empty() || sinkId.empty() || callback == nullptr ||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
DHLOGE("StartRemoteInput relay type param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, callback)) {
return ERR_DH_INPUT_CLIENT_START_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(srcId, sinkId, inputTypes, callback);
}
int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
const uint32_t &inputTypes, sptr<IStopDInputCallback> callback)
{
DHLOGI("StopRemoteInput relay by type called, srcId: %s, sinkId: %s, inputTypes: %d",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), inputTypes);
DHLOGI("DinputStop called, srcId: %s, sinkId: %s, inputTypes: %d.", GetAnonyString(srcId).c_str(),
GetAnonyString(sinkId).c_str(), inputTypes);
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StopRemoteInput relay type client fail");
DHLOGE("DinputStop relay type client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (srcId.empty() || sinkId.empty() || callback == nullptr ||
inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL) ||
inputTypes == static_cast<uint32_t>(DInputDeviceType::NONE) ||
!(inputTypes & static_cast<uint32_t>(DInputDeviceType::ALL))) {
DHLOGE("StopRemoteInput relay type param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, callback)) {
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(srcId, sinkId, inputTypes, callback);
}
int32_t DistributedInputClient::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
sptr<IPrepareDInputCallback> callback)
{
DHLOGI("PrepareRemoteInput relay called, srcId: %s, sinkId: %s",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
DHLOGI("DinputPrepare called, srcId: %s, sinkId: %s.", GetAnonyString(srcId).c_str(),
GetAnonyString(sinkId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("PrepareRemoteInput relay proxy error, client fail");
DHLOGE("DinputPrepare relay proxy error, client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (srcId.empty() || sinkId.empty() || callback == nullptr) {
DHLOGE("PrepareRemoteInput relay param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, callback)) {
return ERR_DH_INPUT_CLIENT_PREPARE_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->PrepareRemoteInput(srcId, sinkId, callback);
@@ -528,16 +480,13 @@ int32_t DistributedInputClient::PrepareRemoteInput(const std::string &srcId, con
int32_t DistributedInputClient::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
sptr<IUnprepareDInputCallback> callback)
{
DHLOGI("UnprepareRemoteInput relay called, srcId: %s, sinkId: %s",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
DHLOGI("DinputUnprepare called, srcId: %s, sinkId: %s.", GetAnonyString(srcId).c_str(),
GetAnonyString(sinkId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("UnprepareRemoteInput relay proxy error, client fail");
DHLOGE("DinputUnprepare relay proxy error, client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (srcId.empty() || sinkId.empty() || callback == nullptr) {
DHLOGE("UnprepareRemoteInput relay param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, callback)) {
return ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->UnprepareRemoteInput(srcId, sinkId, callback);
@@ -546,80 +495,66 @@ int32_t DistributedInputClient::UnprepareRemoteInput(const std::string &srcId, c
int32_t DistributedInputClient::StartRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IStartStopDInputsCallback> callback)
{
DHLOGI("StartRemoteInput relay by dhid called, sinkId: %s", GetAnonyString(sinkId).c_str());
DHLOGI("DinputStart called, sinkId: %s.", GetAnonyString(sinkId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StartRemoteInput dhid proxy error, client fail");
DHLOGE("DinputStart dhid proxy error, client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
DHLOGE("StartRemoteInput dhid param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(sinkId, dhIds, callback)) {
return ERR_DH_INPUT_CLIENT_START_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(sinkId, dhIds, callback);
}
int32_t DistributedInputClient::StopRemoteInput(const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IStartStopDInputsCallback> callback)
{
DHLOGI("StopRemoteInput relay by dhid called, sinkId: %s", GetAnonyString(sinkId).c_str());
DHLOGI("DinputStop called, sinkId: %s.", GetAnonyString(sinkId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StopRemoteInput dhid proxy error, client fail");
DHLOGE("DinputStop dhid proxy error, client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
DHLOGE("StopRemoteInput dhid param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(sinkId, dhIds, callback)) {
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(sinkId, dhIds, callback);
}
int32_t DistributedInputClient::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
{
DHLOGI("StartRemoteInput relay by dhid called, srcId: %s, sinkId: %s",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
DHLOGI("DinputStart called, srcId: %s, sinkId: %s.", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StartRemoteInput proxy error, client fail");
DHLOGE("DinputStart proxy error, client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (srcId.empty() || sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
DHLOGE("StartRemoteInput param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, dhIds, callback)) {
return ERR_DH_INPUT_CLIENT_START_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StartRemoteInput(srcId, sinkId, dhIds, callback);
}
int32_t DistributedInputClient::StopRemoteInput(const std::string &srcId, const std::string &sinkId,
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
{
DHLOGI("StopRemoteInput relay by dhid called, srcId: %s, sinkId: %s",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
DHLOGI("DinputStop called, srcId: %s, sinkId: %s.", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("StopRemoteInput proxy error, client fail");
DHLOGE("DinputStop proxy error, client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
if (srcId.empty() || sinkId.empty() || callback == nullptr || (dhIds.size() <= 0)) {
DHLOGE("StopRemoteInput param error, client fail");
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, dhIds, callback)) {
return ERR_DH_INPUT_CLIENT_STOP_FAIL;
}
return DInputSAManager::GetInstance().dInputSourceProxy_->StopRemoteInput(srcId, sinkId, dhIds, callback);
}
bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event)
{
DHLOGI("IsNeedFilterOut called, deviceId: %s", GetAnonyString(deviceId).c_str());
if (deviceId.empty() || (deviceId.size() > DEVID_LENGTH_MAX)) {
DHLOGE("IsNeedFilterOut param deviceId is empty.");
return false;
}
return WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event);
}
@@ -639,6 +574,10 @@ bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &e
bool DistributedInputClient::IsStartDistributedInput(const std::string& dhId)
{
std::lock_guard<std::mutex> lock(sharingDhIdsMtx_);
if (dhId.empty() || (dhId.size() > DHID_LENGTH_MAX)) {
DHLOGE("IsStartDistributedInput param dhid is error.");
return false;
}
return sharingDhIds_.find(dhId) != sharingDhIds_.end();
}
+1
View File
@@ -49,6 +49,7 @@ ohos_shared_library("libdinput_source") {
sources = [
"${common_path}/include/white_list_util.cpp",
"${common_path}/include/input_check_param.cpp",
"${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp",
"${ipc_path}/src/add_white_list_infos_call_back_stub.cpp",
"${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp",
@@ -164,15 +164,10 @@ public:
const std::string &nodeDesc) override;
virtual int32_t RegisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
virtual int32_t UnregisterSimulationEventListener(sptr<ISimulationEventListener> listener) override;
bool CheckParameters(const std::string &deviceId, sptr<IRemoteBroker> callback);
bool CheckParameters(const std::string& deviceId, const uint32_t& inputTypes, sptr<IRemoteBroker> callback);
bool CheckParameters(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
sptr<IRemoteBroker> callback);
bool CheckParameters(const std::string &srcId, const std::string &sinkId, sptr<IRemoteBroker> callback);
bool CheckParameters(const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IRemoteBroker> callback);
bool CheckParameters(const std::string &srcId, const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IRemoteBroker> callback);
bool CheckRegisterParam(const std::string &devId, const std::string &dhId,
const std::string &parameters, sptr<IRegisterDInputCallback> callback);
bool CheckUnregisterParam(const std::string &devId, const std::string &dhId,
sptr<IUnregisterDInputCallback> callback);
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
class DInputSourceListener : public DInputSourceTransCallback {
@@ -44,6 +44,7 @@
#include "distributed_input_source_transport.h"
#include "hisysevent_util.h"
#include "hidumper.h"
#include "input_check_param.h"
#include "white_list_util.h"
namespace OHOS {
@@ -730,22 +731,40 @@ int32_t DistributedInputSourceManager::Release()
return DH_SUCCESS;
}
bool DistributedInputSourceManager::CheckRegisterParam(const std::string &devId, const std::string &dhId,
const std::string &parameters, sptr<IRegisterDInputCallback> callback)
{
if (devId.empty() || devId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam devId is empty or devId size too long.");
return false;
}
if (dhId.empty() || dhId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam dhId is empty or dhId size too long.");
return false;
}
if (parameters.empty()) {
DHLOGE("CheckParam parameters is empty.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
const std::string& parameters, sptr<IRegisterDInputCallback> callback)
{
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_REGISTER, devId, dhId, "dinput register call.");
DHLOGI("RegisterDistributedHardware called, deviceId: %s, dhId: %s, parameters: %s",
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
if (callback == nullptr) {
DHLOGE("RegisterDistributedHardware called, deviceId: %s callback is null.", GetAnonyString(devId).c_str());
if (!CheckRegisterParam(devId, dhId, parameters, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_REGISTER_FAIL, devId, dhId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL,
"dinput register distributed hardware failed callback is nullptr.");
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL, "Dinputregister failed callback is nullptr.");
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL;
}
std::lock_guard<std::mutex> lock(operationMutex_);
DInputClientRegistInfo info {devId, dhId, callback};
regCallbacks_.push_back(info);
InputDeviceId inputDeviceId {devId, dhId, GetNodeDesc(parameters)};
@@ -844,6 +863,24 @@ int32_t DistributedInputSourceManager::UnregCallbackNotify(const std::string &de
return DH_SUCCESS;
}
bool DistributedInputSourceManager::CheckUnregisterParam(const std::string &devId, const std::string &dhId,
sptr<IUnregisterDInputCallback> callback)
{
if (devId.empty() || devId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam devId is empty or devId size too long.");
return false;
}
if (dhId.empty() || dhId.size() > DEVID_LENGTH_MAX) {
DHLOGE("CheckParam dhId is empty or dhId size too long.");
return false;
}
if (callback == nullptr) {
DHLOGE("CheckParam callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::CheckDeviceIsExists(const std::string &devId, const std::string &dhId,
const InputDeviceId &inputDeviceId, std::vector<InputDeviceId>::iterator &it)
{
@@ -877,7 +914,6 @@ int32_t DistributedInputSourceManager::DeleteInputDeviceNodeInfo(const std::stri
}
inputDevice_.erase(it);
std::shared_ptr<nlohmann::json> jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = devId;
@@ -903,16 +939,13 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::
{
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_UNREGISTER, devId, dhId, "dinput unregister call");
DHLOGI("Unregister called, deviceId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
if (callback == nullptr) {
DHLOGE("Unregister called, deviceId: %s callback is null.", GetAnonyString(devId).c_str());
if (!CheckUnregisterParam(devId, dhId, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, "dinput unregister failed in callback is nullptr");
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL;
}
std::lock_guard<std::mutex> lock(operationMutex_);
DInputClientUnregistInfo info {devId, dhId, callback};
unregCallbacks_.push_back(info);
@@ -941,30 +974,18 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::
return DH_SUCCESS;
}
bool DistributedInputSourceManager::CheckParameters(const std::string &deviceId, sptr<IRemoteBroker> callback)
{
if (deviceId.empty()) {
DHLOGE("DeviceId is empty.");
return false;
}
if (callback == nullptr) {
DHLOGE("Callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::PrepareRemoteInput(
const std::string &deviceId, sptr<IPrepareDInputCallback> callback)
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_PREPARE, deviceId, "Dinput prepare call.");
if (!CheckParameters(deviceId, callback)) {
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, "Dinput prepare param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
DHLOGI("Prepare called, deviceId: %s", GetAnonyString(deviceId).c_str());
for (auto iter : preCallbacks_) {
if (iter.devId == deviceId) {
@@ -1011,7 +1032,7 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_UNPREPARE, deviceId, "Dinput unprepare call.");
if (!CheckParameters(deviceId, callback)) {
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, "Dinput unprepare param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK);
@@ -1049,35 +1070,18 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(
return DH_SUCCESS;
}
bool DistributedInputSourceManager::CheckParameters(const std::string &deviceId, const uint32_t& inputTypes,
sptr<IRemoteBroker> callback)
{
if (deviceId.empty()) {
DHLOGE("DeviceId is empty.");
return false;
}
if (inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL)) {
DHLOGE("Inputtype is invalids.");
return false;
}
if (callback == nullptr) {
DHLOGE("Callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::StartRemoteInput(
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, deviceId, "Dinput start use call.");
if (!CheckParameters(deviceId, inputTypes, callback)) {
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("Start called, deviceId: %s, inputTypes: %d", GetAnonyString(deviceId).c_str(), inputTypes);
for (auto iter : staCallbacks_) {
if (iter.devId == deviceId && iter.inputTypes == inputTypes) {
@@ -1116,12 +1120,13 @@ int32_t DistributedInputSourceManager::StopRemoteInput(
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, deviceId, "Dinput stop use call");
if (!CheckParameters(deviceId, inputTypes, callback)) {
if (!DinputCheckParam::GetInstance().CheckParam(deviceId, inputTypes, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
DHLOGI("Stop called, deviceId: %s, inputTypes: %d", GetAnonyString(deviceId).c_str(), inputTypes);
for (auto iter : stpCallbacks_) {
if (iter.devId == deviceId && iter.inputTypes == inputTypes) {
@@ -1154,45 +1159,27 @@ int32_t DistributedInputSourceManager::StopRemoteInput(
return DH_SUCCESS;
}
bool DistributedInputSourceManager::CheckParameters(const std::string &srcId, const std::string &sinkId,
const uint32_t &inputTypes, sptr<IRemoteBroker> callback)
{
if (srcId.empty() || sinkId.empty()) {
DHLOGE("SrcId=%d or sinkId=%d is empty.", srcId.empty(), sinkId.empty());
return false;
}
if (inputTypes > static_cast<uint32_t>(DInputDeviceType::ALL)) {
DHLOGE("Inputtype is invalids.");
return false;
}
if (callback == nullptr) {
DHLOGE("Callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
const uint32_t &inputTypes, sptr<IStartDInputCallback> callback)
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "Dinput start use call.");
if (!CheckParameters(srcId, sinkId, inputTypes, callback)) {
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput stop param is faild.");
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("StartRemoteInput called, srcId: %s, sinkId: %s, inputTypes: %d", GetAnonyString(srcId).c_str(),
GetAnonyString(sinkId).c_str(), inputTypes);
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("StartRemoteInput called, Could not get local device id.");
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in get local networkId error.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("StartRemoteInput called, device local networkId is %s", GetAnonyString(localNetworkId).c_str());
if (srcId != localNetworkId) {
return RelayStartRemoteInputByType(srcId, sinkId, inputTypes, callback);
}
@@ -1231,7 +1218,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId,
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "Dinput stop use call.");
if (!CheckParameters(srcId, sinkId, inputTypes, callback)) {
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, inputTypes, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
@@ -1241,13 +1228,11 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId,
GetAnonyString(sinkId).c_str(), inputTypes);
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("StopRemoteInput called, Could not get local device id.");
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in get networkId.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
DHLOGI("StopRemoteInput called, device local networkId is %s", GetAnonyString(localNetworkId).c_str());
if (srcId != localNetworkId) {
return RelayStopRemoteInputByType(srcId, sinkId, inputTypes, callback);
}
@@ -1332,36 +1317,20 @@ int32_t DistributedInputSourceManager::RelayStopRemoteInputByType(
return dInputSourceProxy->StopRemoteInput(srcId, sinkId, inputTypes, callback);
}
bool DistributedInputSourceManager::CheckParameters(const std::string &srcId, const std::string &sinkId,
sptr<IRemoteBroker> callback)
{
if (srcId.empty() || sinkId.empty()) {
DHLOGE("SrcId=%d or sinkId=%d is empty.", srcId.empty(), sinkId.empty());
return false;
}
if (callback == nullptr) {
DHLOGE("Callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId,
sptr<IPrepareDInputCallback> callback)
{
if (!CheckParameters(srcId, sinkId, callback)) {
DHLOGI("Dinput prepare, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, "Dinput prepare param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
DHLOGI("srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL;
}
DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str());
if (srcId != localNetworkId) {
return RelayPrepareRemoteInput(srcId, sinkId, callback);
}
@@ -1397,19 +1366,17 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &src
int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId,
sptr<IUnprepareDInputCallback> callback)
{
if (!CheckParameters(srcId, sinkId, callback)) {
DHLOGI("Dinput unprepare, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, "Dinput unprepare param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
}
DHLOGI("srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL;
}
DHLOGI("device local localNetworkId is %s", GetAnonyString(localNetworkId).c_str());
if (srcId != localNetworkId) {
return RelayUnprepareRemoteInput(srcId, sinkId, callback);
}
@@ -1456,51 +1423,25 @@ bool DistributedInputSourceManager::IsStringDataSame(const std::vector<std::stri
return isSame;
}
bool DistributedInputSourceManager::CheckParameters(const std::string &sinkId, const std::vector<std::string> &dhIds,
sptr<IRemoteBroker> callback)
{
if (sinkId.empty()) {
DHLOGE("SinkId is empty.");
return false;
}
if (dhIds.empty()) {
DHLOGE("DhIds is empty.");
return false;
}
for (auto iter : dhIds) {
if (iter.size() > DHID_LENGTH_MAX) {
DHLOGE("DhId length is too long.");
return false;
}
}
if (callback == nullptr) {
DHLOGE("Callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &sinkId,
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "dinput start use call");
if (!CheckParameters(sinkId, dhIds, callback)) {
DHLOGI("Dinput start, sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size());
if (!DinputCheckParam::GetInstance().CheckParam(sinkId, dhIds, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in get networkId");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str());
// current device is source device
for (auto iter : staStringCallbacks_) {
@@ -1538,22 +1479,20 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &sinkId
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "dinput stop use call");
if (!CheckParameters(sinkId, dhIds, callback)) {
DHLOGI("Dinput stop, sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size());
if (!DinputCheckParam::GetInstance().CheckParam(sinkId, dhIds, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
DHLOGI("sinkId: %s, vector.string.size: %d", GetAnonyString(sinkId).c_str(), dhIds.size());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in get networkId");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str());
for (auto iter : stpStringCallbacks_) {
if (iter.sinkId == sinkId && IsStringDataSame(iter.dhIds, dhIds)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
@@ -1583,51 +1522,25 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &sinkId
return DH_SUCCESS;
}
bool DistributedInputSourceManager::CheckParameters(const std::string &srcId, const std::string &sinkId,
const std::vector<std::string> &dhIds, sptr<IRemoteBroker> callback)
{
if (srcId.empty() || sinkId.empty()) {
DHLOGE("SrcId=%d or sinkId=%d is empty.", srcId.empty(), sinkId.empty());
return false;
}
if (dhIds.empty()) {
DHLOGE("DhIds is empty.");
return false;
}
for (auto iter : dhIds) {
if (iter.size() > DHID_LENGTH_MAX) {
DHLOGE("DhId length is too long.");
return false;
}
}
if (callback == nullptr) {
DHLOGE("Callback is null.");
return false;
}
return true;
}
int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId, const std::string &sinkId,
const std::vector<std::string> &dhIds, sptr<IStartStopDInputsCallback> callback)
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_START_USE, sinkId, "Dinput start use call.");
if (!CheckParameters(srcId, sinkId, dhIds, callback)) {
DHLOGI("Dinput start, srcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, dhIds, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("SrcId: %s, sinkId: %s", GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "Dinput start use failed in get networkId.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL;
}
DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str());
if (srcId != localNetworkId) {
return RelayStartRemoteInputByDhid(srcId, sinkId, dhIds, callback);
}
@@ -1666,23 +1579,21 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId,
{
StartAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_STOP_USE, sinkId, "Dinput stop use call.");
if (!CheckParameters(srcId, sinkId, dhIds, callback)) {
DHLOGI("Dinput stop, srcId: %s, sinkId: %s, vector.string.size: %d",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), dhIds.size());
if (!DinputCheckParam::GetInstance().CheckParam(srcId, sinkId, dhIds, callback)) {
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop param is faild.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
DHLOGI("srcId: %s, sinkId: %s, vector.string.size: %d",
GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str(), dhIds.size());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "Dinput stop use failed in get networkId.");
FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK);
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL;
}
DHLOGI("device local networkId is %s", GetAnonyString(localNetworkId).c_str());
if (srcId != localNetworkId) {
return RelayStopRemoteInputByDhid(srcId, sinkId, dhIds, callback);
}
@@ -1742,6 +1653,10 @@ int32_t DistributedInputSourceManager::RegisterDelWhiteListCallback(sptr<IDelWhi
int32_t DistributedInputSourceManager::RegisterInputNodeListener(sptr<InputNodeListener> listener)
{
DHLOGI("RegisterInputNodeListener, addr: %p", &listener);
if (listener == nullptr) {
DHLOGE("RegisterInputNodeListener callback is null.");
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR;
}
DistributedInputInject::GetInstance().RegisterInputNodeListener(listener);
SendExistVirNodeInfos(listener);
return DH_SUCCESS;
@@ -1750,6 +1665,10 @@ int32_t DistributedInputSourceManager::RegisterInputNodeListener(sptr<InputNodeL
int32_t DistributedInputSourceManager::UnregisterInputNodeListener(sptr<InputNodeListener> listener)
{
DHLOGI("UnregisterInputNodeListener, addr: %p", &listener);
if (listener == nullptr) {
DHLOGE("UnregisterInputNodeListener callback is null.");
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR;
}
DistributedInputInject::GetInstance().UnregisterInputNodeListener(listener);
return DH_SUCCESS;
}
@@ -2023,7 +1942,6 @@ void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sink
dhidsVec.size());
std::string localNetWorkId = GetLocalNetworkId();
if (localNetWorkId.empty()) {
DHLOGE("Could not get local device id.");
return;
}
@@ -2044,7 +1962,6 @@ void DistributedInputSourceManager::RunStopDhidCallback(const std::string &sinkI
StringSplitToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec);
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
DHLOGE("Could not get local device id.");
return;
}
@@ -2242,6 +2159,10 @@ void DistributedInputSourceManager::StartDScreenListener::OnMessage(const DHTopi
DHLOGE("this topic is wrong, %d", static_cast<uint32_t>(topic));
return;
}
if (message.size() > SCREEN_MSG_MAX) {
DHLOGE("StartDScreenListener message size too long.");
return;
}
std::string sinkDevId = "";
SrcScreenInfo srcScreenInfo = {};
int32_t parseRes = ParseMessage(message, sinkDevId, srcScreenInfo);
+4 -2
View File
@@ -55,10 +55,12 @@ DevInfo GetLocalDeviceInfo()
std::string GetLocalNetworkId()
{
if (GetLocalDeviceInfo().networkId.empty()) {
std::string localNetworkId = GetLocalDeviceInfo().networkId;
if (localNetworkId.empty()) {
DHLOGE("local networkId is empty!");
}
return GetLocalDeviceInfo().networkId;
DHLOGI("GetLocalNetworkId, device local networkId is %s", GetAnonyString(localNetworkId).c_str());
return localNetworkId;
}
std::string GetUUIDBySoftBus(const std::string &networkId)