mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
Revert "
Match-id-b804691ca6b89759dc40c5f7c5974aff090c5c14
This commit is contained in:
@@ -148,36 +148,6 @@ namespace DistributedInput {
|
||||
|
||||
const std::string SINK_WINDOW_SHOW_Y = "sinkWinShowY";
|
||||
|
||||
const std::string DEVICE_NAME = "name";
|
||||
|
||||
const std::string PHYSICAL_PATH = "physicalPath";
|
||||
|
||||
const std::string UNIQUE_ID = "uniqueId";
|
||||
|
||||
const std::string BUS = "bus";
|
||||
|
||||
const std::string VENDOR = "vendor";
|
||||
|
||||
const std::string PRODUCT = "product";
|
||||
|
||||
const std::string VERSION = "version";
|
||||
|
||||
const std::string DESCRIPTOR = "descriptor";
|
||||
|
||||
const std::string CLASSES = "classes";
|
||||
|
||||
const std::string EVENT_TYPES = "eventTypes";
|
||||
|
||||
const std::string EVENT_KEYS = "eventKeys";
|
||||
|
||||
const std::string ABS_TYPES = "absTypes";
|
||||
|
||||
const std::string ABS_INFOS = "absInfos";
|
||||
|
||||
const std::string REL_TYPES = "relTypes";
|
||||
|
||||
const std::string PROPERTIES = "properties";
|
||||
|
||||
constexpr uint32_t SCREEN_ID_DEFAULT = 0;
|
||||
|
||||
constexpr uint32_t DEFAULT_VALUE = 0;
|
||||
@@ -229,12 +199,6 @@ namespace DistributedInput {
|
||||
uint16_t version;
|
||||
std::string descriptor;
|
||||
uint32_t classes;
|
||||
std::vector<uint32_t> eventTypes;
|
||||
std::vector<uint32_t> eventKeys;
|
||||
std::vector<uint32_t> absTypes;
|
||||
std::map<uint32_t, std::vector<int32_t>> absInfos;
|
||||
std::vector<uint32_t> relTypes;
|
||||
std::vector<uint32_t> properties;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
+18
-145
@@ -17,16 +17,17 @@
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
#include <securec.h>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <utility>
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
@@ -101,7 +102,6 @@ int32_t InputHub::Release()
|
||||
::close(iNotifyFd_);
|
||||
StopCollectInputEvents();
|
||||
StopCollectInputHandler();
|
||||
sharedDHIds_.clear();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ size_t InputHub::StartCollectInputEvents(RawEvent* buffer, size_t bufferSize)
|
||||
needToScanDevices_ = false;
|
||||
ScanInputDevices(DEVICE_PATH);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
while (!openingDevices_.empty()) {
|
||||
@@ -185,11 +186,9 @@ size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize)
|
||||
if (!device) {
|
||||
continue;
|
||||
}
|
||||
if (!sharedDHIds_[device->identifier.descriptor]) {
|
||||
if (!device->isShare) {
|
||||
continue;
|
||||
}
|
||||
DHLOGD("shared device dhId: %s, name: %s", GetAnonyString(device->identifier.descriptor).c_str(),
|
||||
device->identifier.name.c_str());
|
||||
if (eventItem.events & EPOLLIN) {
|
||||
event += CollectEvent(event, capacity, device, readBuffer, count);
|
||||
|
||||
@@ -513,7 +512,7 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier)
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
identifier.name = buffer;
|
||||
}
|
||||
DHLOGD("QueryInputDeviceInfo deviceName: %s", buffer);
|
||||
|
||||
// If the device is already a virtual device, don't monitor it.
|
||||
if (identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) {
|
||||
return ERR_DH_INPUT_HUB_IS_VIRTUAL_DEVICE;
|
||||
@@ -551,127 +550,9 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier)
|
||||
identifier.uniqueId = buffer;
|
||||
}
|
||||
|
||||
QueryEventInfo(fd, identifier);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void InputHub::QueryEventInfo(int fd, InputDevice& identifier)
|
||||
{
|
||||
DHLOGI("QueryEventInfo: devName: %s, dhId: %s!", identifier.name.c_str(),
|
||||
GetAnonyString(identifier.descriptor).c_str());
|
||||
struct libevdev *dev = GetLibEvDev(fd);
|
||||
if (dev == nullptr) {
|
||||
DHLOGE("dev is nullptr");
|
||||
return;
|
||||
}
|
||||
GetEventTypes(dev, identifier);
|
||||
GetEventKeys(dev, identifier);
|
||||
GetABSInfo(dev, identifier);
|
||||
GetRELTypes(dev, identifier);
|
||||
GetProperties(dev, identifier);
|
||||
libevdev_free(dev);
|
||||
}
|
||||
|
||||
struct libevdev* InputHub::GetLibEvDev(int fd)
|
||||
{
|
||||
struct libevdev *dev = nullptr;
|
||||
int rc = 1;
|
||||
rc = libevdev_new_from_fd(fd, &dev);
|
||||
if (rc < 0) {
|
||||
DHLOGE("Failed to init libevdev (%s)", strerror(-rc));
|
||||
return nullptr;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
void InputHub::GetEventTypes(struct libevdev* dev, InputDevice& identifier)
|
||||
{
|
||||
for (uint32_t eventType = 0; eventType < EV_CNT; eventType++) {
|
||||
if (!libevdev_has_event_type(dev, eventType)) {
|
||||
DHLOGD("The device is not support eventType: %d", eventType);
|
||||
continue;
|
||||
}
|
||||
DHLOGI("QueryInputDeviceInfo eventType: %d", eventType);
|
||||
identifier.eventTypes.push_back(eventType);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputHub::GetEventKeys(struct libevdev* dev, InputDevice& identifier)
|
||||
{
|
||||
if (!libevdev_has_event_type(dev, EV_KEY)) {
|
||||
DHLOGE("The device doesn't has EV_KEY type!");
|
||||
return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL;
|
||||
}
|
||||
for (uint32_t eventKey = 0; eventKey < KEY_CNT; eventKey++) {
|
||||
if (!libevdev_has_event_code(dev, EV_KEY, eventKey)) {
|
||||
DHLOGD("The device is not support eventKey: %d", eventKey);
|
||||
continue;
|
||||
}
|
||||
DHLOGI("QueryInputDeviceInfo eventKey: %d", eventKey);
|
||||
identifier.eventKeys.push_back(eventKey);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t InputHub::GetABSInfo(struct libevdev* dev, InputDevice& identifier)
|
||||
{
|
||||
if (!libevdev_has_event_type(dev, EV_ABS)) {
|
||||
DHLOGE("The device doesn't has EV_ABS type!");
|
||||
return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL;
|
||||
}
|
||||
DHLOGI("The device has abs info, devName: %s, dhId: %s!", identifier.name.c_str(),
|
||||
GetAnonyString(identifier.descriptor).c_str());
|
||||
for (uint32_t absType = 0; absType < ABS_CNT; absType++) {
|
||||
if (!libevdev_has_event_code(dev, EV_ABS, absType)) {
|
||||
DHLOGD("The device is not support absType: %d", absType);
|
||||
continue;
|
||||
}
|
||||
DHLOGI("QueryInputDeviceInfo abs type: %d", absType);
|
||||
identifier.absTypes.push_back(absType);
|
||||
const struct input_absinfo *abs = libevdev_get_abs_info(dev, absType);
|
||||
if (abs == nullptr) {
|
||||
DHLOGE("absInfo is nullptr!");
|
||||
continue;
|
||||
}
|
||||
DHLOGI("QueryInputDeviceInfo abs info value: %d, min: %d, max: %d, fuzz: %d, flat: %d, res: %d", abs->value,
|
||||
abs->minimum, abs->maximum, abs->fuzz, abs->flat, abs->resolution);
|
||||
identifier.absInfos[absType].push_back(abs->value);
|
||||
identifier.absInfos[absType].push_back(abs->minimum);
|
||||
identifier.absInfos[absType].push_back(abs->maximum);
|
||||
identifier.absInfos[absType].push_back(abs->fuzz);
|
||||
identifier.absInfos[absType].push_back(abs->flat);
|
||||
identifier.absInfos[absType].push_back(abs->resolution);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t InputHub::GetRELTypes(struct libevdev* dev, InputDevice& identifier)
|
||||
{
|
||||
if (!libevdev_has_event_type(dev, EV_REL)) {
|
||||
DHLOGE("The device doesn't has EV_REL type!");
|
||||
return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL;
|
||||
}
|
||||
for (uint32_t code = 0; code < REL_CNT; code++) {
|
||||
if (!libevdev_has_event_code(dev, EV_REL, code)) {
|
||||
DHLOGD("The device is not support eventCode: %d", code);
|
||||
continue;
|
||||
}
|
||||
DHLOGI("QueryInputDeviceInfo rel types: %d", code);
|
||||
identifier.relTypes.push_back(code);
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void InputHub::GetProperties(struct libevdev* dev, InputDevice& identifier)
|
||||
{
|
||||
for (uint32_t prop = 0; prop < INPUT_PROP_CNT; prop++) {
|
||||
if (libevdev_has_property(dev, prop)) {
|
||||
DHLOGI("QueryInputDeviceInfo rel prop: %d", prop);
|
||||
identifier.properties.push_back(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
|
||||
{
|
||||
// Figure out the kinds of events the device reports.
|
||||
@@ -686,8 +567,8 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
|
||||
QueryLocalTouchScreenInfo(fd);
|
||||
device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
} else if (TestBit(BTN_TOUCH, device->keyBitmask) &&
|
||||
TestBit(ABS_X, device->absBitmask) &&
|
||||
TestBit(ABS_Y, device->absBitmask)) {
|
||||
TestBit(ABS_X, device->absBitmask) &&
|
||||
TestBit(ABS_Y, device->absBitmask)) {
|
||||
QueryLocalTouchScreenInfo(fd);
|
||||
device->classes |= INPUT_DEVICE_CLASS_TOUCH;
|
||||
}
|
||||
@@ -720,10 +601,12 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
|
||||
}
|
||||
|
||||
device->identifier.classes = device->classes;
|
||||
|
||||
if (device->classes & inputTypes_) {
|
||||
device->isShare = true;
|
||||
}
|
||||
DHLOGI("inputType=%d", inputTypes_.load());
|
||||
DHLOGI("New device: fd=%d, name='%s', classes=0x%x, isShare=%d", fd, device->identifier.name.c_str(),
|
||||
device->classes);
|
||||
DHLOGI("New device: fd=%d, name='%s', classes=0x%x, isShare=%d",
|
||||
fd, device->identifier.name.c_str(), device->classes, device->isShare);
|
||||
|
||||
AddDeviceLocked(std::move(device));
|
||||
return DH_SUCCESS;
|
||||
@@ -999,12 +882,9 @@ InputHub::Device* InputHub::GetDeviceByFdLocked(int fd)
|
||||
|
||||
InputHub::Device* InputHub::GetSupportDeviceByFd(int fd)
|
||||
{
|
||||
DHLOGI("GetSupportDeviceByFd fd: %d", fd);
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto& [id, device] : devices_) {
|
||||
DHLOGI("GetSupportDeviceByFd device: %d, fd: %d, path: %s, dhId: %s, classes=0x%x", id, device->fd,
|
||||
device->path.c_str(), GetAnonyString(device->identifier.descriptor).c_str(), device->classes);
|
||||
if (device != nullptr && device->fd == fd) {
|
||||
if (device->fd == fd) {
|
||||
return device.get();
|
||||
}
|
||||
}
|
||||
@@ -1072,14 +952,8 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector<std::string> d
|
||||
{
|
||||
AffectDhIds affDhIds;
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
DHLOGI("SetSharingDevices start");
|
||||
for (auto dhId : dhIds) {
|
||||
DHLOGI("SetSharingDevices dhId: %s, size: %d, enabled: %d", GetAnonyString(dhId).c_str(), devices_.size(),
|
||||
enabled);
|
||||
sharedDHIds_[dhId] = enabled;
|
||||
for (const auto &[id, device] : devices_) {
|
||||
DHLOGI("deviceName %s ,dhId: %s ", device->identifier.name.c_str(),
|
||||
GetAnonyString(device->identifier.descriptor).c_str());
|
||||
if (device->identifier.descriptor == dhId) {
|
||||
device->isShare = enabled;
|
||||
DHLOGW("dhid:%s, isshare:%d", GetAnonyString(device->identifier.descriptor).c_str(), enabled);
|
||||
@@ -1088,7 +962,7 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector<std::string> d
|
||||
}
|
||||
}
|
||||
}
|
||||
DHLOGI("SetSharingDevices end");
|
||||
|
||||
return affDhIds;
|
||||
}
|
||||
|
||||
@@ -1149,9 +1023,8 @@ void InputHub::GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<
|
||||
bool InputHub::IsAllDevicesStoped()
|
||||
{
|
||||
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
|
||||
for (const auto &[dhId, isShared] : sharedDHIds_) {
|
||||
DHLOGI("the dhId: %s, isShared: %d", GetAnonyString(dhId).c_str(), isShared);
|
||||
if (isShared) {
|
||||
for (const auto &[id, device] : devices_) {
|
||||
if (device->isShare) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <libevdev/libevdev.h>
|
||||
#include <linux/input.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/inotify.h>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "constants_dinput.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -95,14 +95,7 @@ private:
|
||||
int32_t RefreshEpollItem(bool isSleep);
|
||||
|
||||
int32_t OpenInputDeviceLocked(const std::string& devicePath);
|
||||
int32_t QueryInputDeviceInfo(int32_t fd, InputDevice& identifier);
|
||||
void QueryEventInfo(int32_t fd, InputDevice& identifier);
|
||||
struct libevdev* GetLibEvDev(int32_t fd);
|
||||
void GetEventTypes(struct libevdev* dev, InputDevice& identifier);
|
||||
int32_t GetEventKeys(struct libevdev* dev, InputDevice& identifier);
|
||||
int32_t GetABSInfo(struct libevdev* dev, InputDevice& identifier);
|
||||
int32_t GetRELTypes(struct libevdev* dev, InputDevice& identifier);
|
||||
void GetProperties(struct libevdev* dev, InputDevice& identifier);
|
||||
int32_t QueryInputDeviceInfo(int fd, InputDevice& identifier);
|
||||
int32_t MakeDevice(int fd, std::unique_ptr<Device> device);
|
||||
void GenerateDescriptor(InputDevice& identifier) const;
|
||||
std::string StringPrintf(const char* format, ...) const;
|
||||
@@ -171,7 +164,6 @@ private:
|
||||
std::atomic<uint32_t> inputTypes_;
|
||||
std::atomic<bool> isStartCollectEvent_;
|
||||
std::atomic<bool> isStartCollectHandler_;
|
||||
std::unordered_map<std::string, bool> sharedDHIds_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -34,7 +34,6 @@ ohos_shared_library("libdinput_handler") {
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -52,7 +51,6 @@ ohos_shared_library("libdinput_handler") {
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -57,21 +57,15 @@ void DistributedInputHandler::StructTransJson(const InputDevice& pBuf, std::stri
|
||||
DHLOGI("[%s] %d, %d, %d, %d, %s.\n", (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version,
|
||||
GetAnonyString(pBuf.descriptor).c_str());
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson[DEVICE_NAME] = pBuf.name;
|
||||
tmpJson[PHYSICAL_PATH] = pBuf.physicalPath;
|
||||
tmpJson[UNIQUE_ID] = pBuf.uniqueId;
|
||||
tmpJson[BUS] = pBuf.bus;
|
||||
tmpJson[VENDOR] = pBuf.vendor;
|
||||
tmpJson[PRODUCT] = pBuf.product;
|
||||
tmpJson[VERSION] = pBuf.version;
|
||||
tmpJson[DESCRIPTOR] = pBuf.descriptor;
|
||||
tmpJson[CLASSES] = pBuf.classes;
|
||||
tmpJson[EVENT_TYPES] = pBuf.eventTypes;
|
||||
tmpJson[EVENT_KEYS] = pBuf.eventKeys;
|
||||
tmpJson[ABS_TYPES] = pBuf.absTypes;
|
||||
tmpJson[ABS_INFOS] = pBuf.absInfos;
|
||||
tmpJson[REL_TYPES] = pBuf.relTypes;
|
||||
tmpJson[PROPERTIES] = pBuf.properties;
|
||||
tmpJson["name"] = pBuf.name;
|
||||
tmpJson["physicalPath"] = pBuf.physicalPath;
|
||||
tmpJson["uniqueId"] = pBuf.uniqueId;
|
||||
tmpJson["bus"] = pBuf.bus;
|
||||
tmpJson["vendor"] = pBuf.vendor;
|
||||
tmpJson["product"] = pBuf.product;
|
||||
tmpJson["version"] = pBuf.version;
|
||||
tmpJson["descriptor"] = pBuf.descriptor;
|
||||
tmpJson["classes"] = pBuf.classes;
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << tmpJson.dump();
|
||||
|
||||
@@ -36,7 +36,6 @@ config("input_sdk_public_config") {
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/common",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
}
|
||||
ohos_shared_library("libdinput_sdk") {
|
||||
@@ -86,7 +85,6 @@ ohos_shared_library("libdinput_sdk") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
defines = [
|
||||
|
||||
@@ -33,7 +33,6 @@ ohos_shared_library("libdinput_collector") {
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -52,7 +51,6 @@ ohos_shared_library("libdinput_collector") {
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -95,7 +95,6 @@ void *DistributedInputCollector::CollectEventsThread(void *param)
|
||||
|
||||
void DistributedInputCollector::StartCollectEventsThread()
|
||||
{
|
||||
DHLOGI("StartCollectEventsThread!");
|
||||
while (isCollectingEvents_) {
|
||||
memset_s(&mEventBuffer, sizeof(mEventBuffer), 0, sizeof(mEventBuffer));
|
||||
if (inputHub_ == nullptr) {
|
||||
|
||||
@@ -48,7 +48,6 @@ ohos_shared_library("libdinput_sink") {
|
||||
"//drivers/peripheral/display/interfaces/include",
|
||||
"//drivers/peripheral/base",
|
||||
"//foundation/graphic/graphic_2d/utils/buffer_handle/export",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -74,7 +73,6 @@ ohos_shared_library("libdinput_sink") {
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/transport:libdinput_sink_trans",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -848,32 +848,32 @@ int32_t DistributedInputSinkManager::ProjectWindowListener::ParseMessage(const s
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
srcDeviceId = jsonObj[SOURCE_DEVICE_ID].get<std::string>();
|
||||
if (!IsUInt64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
DHLOGE("sourceWinId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
srcWinId = jsonObj[SOURCE_WINDOW_ID].get<uint64_t>();
|
||||
if (!IsUInt64(jsonObj, SINK_SHOW_WINDOW_ID)) {
|
||||
if (!IsUint64(jsonObj, SINK_SHOW_WINDOW_ID)) {
|
||||
DHLOGE("sinkWinId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkScreenInfo.sinkShowWinId = jsonObj[SINK_SHOW_WINDOW_ID].get<uint64_t>();
|
||||
if (!IsUInt32(jsonObj, SINK_PROJECT_SHOW_WIDTH)) {
|
||||
if (!IsUint32(jsonObj, SINK_PROJECT_SHOW_WIDTH)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkScreenInfo.sinkProjShowWidth = jsonObj[SINK_PROJECT_SHOW_WIDTH].get<std::uint32_t>();
|
||||
if (!IsUInt32(jsonObj, SINK_PROJECT_SHOW_HEIGHT)) {
|
||||
if (!IsUint32(jsonObj, SINK_PROJECT_SHOW_HEIGHT)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkScreenInfo.sinkProjShowHeight = jsonObj[SINK_PROJECT_SHOW_HEIGHT].get<std::uint32_t>();
|
||||
if (!IsUInt32(jsonObj, SINK_WINDOW_SHOW_X)) {
|
||||
if (!IsUint32(jsonObj, SINK_WINDOW_SHOW_X)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkScreenInfo.sinkWinShowX = jsonObj[SINK_WINDOW_SHOW_X].get<std::uint32_t>();
|
||||
if (!IsUInt32(jsonObj, SINK_WINDOW_SHOW_Y)) {
|
||||
if (!IsUint32(jsonObj, SINK_WINDOW_SHOW_Y)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -59,7 +58,6 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -87,7 +87,6 @@ static void StreamReceived(int32_t sessionId, const StreamData *data, const Stre
|
||||
(void)param;
|
||||
DHLOGI("sessionId: %d", sessionId);
|
||||
}
|
||||
|
||||
DistributedInputSinkTransport &DistributedInputSinkTransport::GetInstance()
|
||||
{
|
||||
static DistributedInputSinkTransport instance;
|
||||
|
||||
@@ -36,7 +36,6 @@ ohos_shared_library("libdinput_inject") {
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -44,6 +43,10 @@ ohos_shared_library("libdinput_inject") {
|
||||
"src/distributed_input_inject.cpp",
|
||||
"src/distributed_input_node_manager.cpp",
|
||||
"src/virtual_device.cpp",
|
||||
"src/virtual_keyboard.cpp",
|
||||
"src/virtual_mouse.cpp",
|
||||
"src/virtual_touchpad.cpp",
|
||||
"src/virtual_touchscreen.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
@@ -57,7 +60,6 @@ ohos_shared_library("libdinput_inject") {
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "input_hub.h"
|
||||
#include "virtual_device.h"
|
||||
@@ -58,9 +56,8 @@ public:
|
||||
|
||||
private:
|
||||
void AddDeviceLocked(const std::string& dhId, std::unique_ptr<VirtualDevice> device);
|
||||
int32_t CreateHandle(const InputDevice& inputDevice, const std::string& devId, const std::string& dhId);
|
||||
void ParseInputDeviceJson(const std::string& str, InputDevice& pBuf);
|
||||
void VerifyInputDevice(const nlohmann::json& inputDeviceJson, InputDevice& pBuf);
|
||||
int32_t CreateHandle(InputDevice event, const std::string& devId, const std::string& dhId);
|
||||
void stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf);
|
||||
void InjectEvent();
|
||||
|
||||
/* the key is dhId, and the value is virtualDevice */
|
||||
@@ -74,7 +71,6 @@ private:
|
||||
std::queue<std::shared_ptr<RawEvent>> injectQueue_;
|
||||
std::unique_ptr<InputHub> inputHub_;
|
||||
int32_t virtualTouchScreenFd_;
|
||||
std::once_flag callOnceFlag_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -37,10 +37,9 @@ public:
|
||||
explicit VirtualDevice(const InputDevice& event);
|
||||
virtual ~VirtualDevice();
|
||||
bool DoIoctl(int32_t fd, int32_t request, const uint32_t value);
|
||||
bool CreateKey(const InputDevice& inputDevice);
|
||||
void SetABSInfo(struct uinput_user_dev& inputUserDev, const InputDevice& inputDevice);
|
||||
bool CreateKey();
|
||||
bool SetPhys(const std::string deviceName, std::string dhId);
|
||||
bool SetUp(const InputDevice& inputDevice, const std::string &devId, const std::string &dhId);
|
||||
bool SetUp(const std::string &devId, const std::string &dhId);
|
||||
bool InjectInputEvent(const input_event &event);
|
||||
void SetNetWorkId(const std::string netWorkId);
|
||||
std::string GetNetWorkId();
|
||||
@@ -48,7 +47,14 @@ public:
|
||||
int32_t GetDeviceFd();
|
||||
uint16_t GetDeviceType();
|
||||
|
||||
private:
|
||||
protected:
|
||||
VirtualDevice();
|
||||
virtual const std::vector<uint32_t>& GetEventTypes() const = 0;
|
||||
virtual const std::vector<uint32_t>& GetKeys() const = 0;
|
||||
virtual const std::vector<uint32_t>& GetProperties() const = 0;
|
||||
virtual const std::vector<uint32_t>& GetAbs() const = 0;
|
||||
virtual const std::vector<uint32_t>& GetRelBits() const = 0;
|
||||
|
||||
int32_t fd_ = -1;
|
||||
std::string deviceName_;
|
||||
std::string netWorkId_;
|
||||
@@ -58,6 +64,8 @@ private:
|
||||
const uint16_t version_;
|
||||
const uint16_t classes_;
|
||||
struct uinput_user_dev dev_ {};
|
||||
struct uinput_abs_setup absTemp_ = {};
|
||||
std::vector<uinput_abs_setup> absInit_;
|
||||
const std::string pid_ = std::to_string(getpid());
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 OHOS_VIRTUAL_KEYBOARD_H
|
||||
#define OHOS_VIRTUAL_KEYBOARD_H
|
||||
|
||||
#include "virtual_device.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class VirtualKeyboard : public VirtualDevice {
|
||||
public:
|
||||
explicit VirtualKeyboard(const InputDevice& event);
|
||||
~VirtualKeyboard() override;
|
||||
protected:
|
||||
const std::vector<uint32_t>& GetEventTypes() const override;
|
||||
const std::vector<uint32_t>& GetKeys() const override;
|
||||
const std::vector<uint32_t>& GetProperties() const override;
|
||||
const std::vector<uint32_t>& GetAbs() const override;
|
||||
const std::vector<uint32_t>& GetRelBits() const override;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_VIRTUAL_KEYBOARD_H
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 OHOS_VIRTUAL_MOUSE_H
|
||||
#define OHOS_VIRTUAL_MOUSE_H
|
||||
|
||||
#include "virtual_device.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class VirtualMouse : public VirtualDevice {
|
||||
public:
|
||||
explicit VirtualMouse(const InputDevice& event);
|
||||
~VirtualMouse() override;
|
||||
protected:
|
||||
const std::vector<uint32_t>& GetEventTypes() const override;
|
||||
const std::vector<uint32_t>& GetKeys() const override;
|
||||
const std::vector<uint32_t>& GetRelBits() const override;
|
||||
const std::vector<uint32_t>& GetProperties() const override;
|
||||
const std::vector<uint32_t>& GetAbs() const override;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // VIRTUALKEYBOARD_H
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 OHOS_VIRTUAL_TOUCHPAD_H
|
||||
#define OHOS_VIRTUAL_TOUCHPAD_H
|
||||
|
||||
#include "virtual_device.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class VirtualTouchpad : public VirtualDevice {
|
||||
public:
|
||||
explicit VirtualTouchpad(const InputDevice& event);
|
||||
~VirtualTouchpad() override;
|
||||
protected:
|
||||
const std::vector<uint32_t>& GetEventTypes() const override;
|
||||
const std::vector<uint32_t>& GetKeys() const override;
|
||||
const std::vector<uint32_t>& GetAbs() const override;
|
||||
const std::vector<uint32_t>& GetProperties() const override;
|
||||
const std::vector<uint32_t>& GetRelBits() const override;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_VIRTUAL_TOUCHPAD_H
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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_VIRTUAL_TOUCHSCREEN_H
|
||||
#define OHOS_VIRTUAL_TOUCHSCREEN_H
|
||||
|
||||
#include "dinput_context.h"
|
||||
#include "virtual_device.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class VirtualTouchScreen : public VirtualDevice {
|
||||
public:
|
||||
VirtualTouchScreen(const InputDevice& event, LocalAbsInfo& absInfo, uint32_t phyWidth, uint32_t phyHeight);
|
||||
~VirtualTouchScreen() override;
|
||||
protected:
|
||||
const std::vector<uint32_t>& GetEventTypes() const override;
|
||||
const std::vector<uint32_t>& GetKeys() const override;
|
||||
const std::vector<uint32_t>& GetAbs() const override;
|
||||
const std::vector<uint32_t>& GetProperties() const override;
|
||||
const std::vector<uint32_t>& GetRelBits() const override;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -131,21 +131,15 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st
|
||||
DHLOGI("[%s] %d, %d, %d, %d, %s.\n", (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version,
|
||||
GetAnonyString(pBuf.descriptor).c_str());
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson[DEVICE_NAME] = pBuf.name;
|
||||
tmpJson[PHYSICAL_PATH] = pBuf.physicalPath;
|
||||
tmpJson[UNIQUE_ID] = pBuf.uniqueId;
|
||||
tmpJson[BUS] = pBuf.bus;
|
||||
tmpJson[VENDOR] = pBuf.vendor;
|
||||
tmpJson[PRODUCT] = pBuf.product;
|
||||
tmpJson[VERSION] = pBuf.version;
|
||||
tmpJson[DESCRIPTOR] = pBuf.descriptor;
|
||||
tmpJson[CLASSES] = pBuf.classes;
|
||||
tmpJson[EVENT_TYPES] = pBuf.eventTypes;
|
||||
tmpJson[EVENT_KEYS] = pBuf.eventKeys;
|
||||
tmpJson[ABS_TYPES] = pBuf.absTypes;
|
||||
tmpJson[ABS_INFOS] = pBuf.absInfos;
|
||||
tmpJson[REL_TYPES] = pBuf.relTypes;
|
||||
tmpJson[PROPERTIES] = pBuf.properties;
|
||||
tmpJson["name"] = pBuf.name;
|
||||
tmpJson["physicalPath"] = pBuf.physicalPath;
|
||||
tmpJson["uniqueId"] = pBuf.uniqueId;
|
||||
tmpJson["bus"] = pBuf.bus;
|
||||
tmpJson["vendor"] = pBuf.vendor;
|
||||
tmpJson["product"] = pBuf.product;
|
||||
tmpJson["version"] = pBuf.version;
|
||||
tmpJson["descriptor"] = pBuf.descriptor;
|
||||
tmpJson["classes"] = pBuf.classes;
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << tmpJson.dump();
|
||||
|
||||
@@ -22,14 +22,18 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
#include "dinput_context.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "virtual_keyboard.h"
|
||||
#include "virtual_mouse.h"
|
||||
#include "virtual_touchpad.h"
|
||||
#include "virtual_touchscreen.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -57,7 +61,7 @@ int32_t DistributedInputNodeManager::openDevicesNode(const std::string& devId, c
|
||||
const std::string& parameters)
|
||||
{
|
||||
InputDevice event;
|
||||
ParseInputDeviceJson(parameters, event);
|
||||
stringTransJsonTransStruct(parameters, event);
|
||||
if (CreateHandle(event, devId, dhId) < 0) {
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL;
|
||||
}
|
||||
@@ -65,79 +69,55 @@ int32_t DistributedInputNodeManager::openDevicesNode(const std::string& devId, c
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::ParseInputDeviceJson(const std::string& str, InputDevice& pBuf)
|
||||
void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf)
|
||||
{
|
||||
nlohmann::json inputDeviceJson = nlohmann::json::parse(str, nullptr, false);
|
||||
if (inputDeviceJson.is_discarded()) {
|
||||
nlohmann::json recMsg = nlohmann::json::parse(str, nullptr, false);
|
||||
if (recMsg.is_discarded()) {
|
||||
DHLOGE("recMsg parse failed!");
|
||||
return;
|
||||
}
|
||||
VerifyInputDevice(inputDeviceJson, pBuf);
|
||||
recMsg.at("name").get_to(pBuf.name);
|
||||
recMsg.at("physicalPath").get_to(pBuf.physicalPath);
|
||||
recMsg.at("uniqueId").get_to(pBuf.uniqueId);
|
||||
recMsg.at("bus").get_to(pBuf.bus);
|
||||
recMsg.at("vendor").get_to(pBuf.vendor);
|
||||
recMsg.at("product").get_to(pBuf.product);
|
||||
recMsg.at("version").get_to(pBuf.version);
|
||||
recMsg.at("descriptor").get_to(pBuf.descriptor);
|
||||
recMsg.at("classes").get_to(pBuf.classes);
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::VerifyInputDevice(const nlohmann::json& inputDeviceJson, InputDevice& pBuf)
|
||||
{
|
||||
if (IsString(inputDeviceJson, DEVICE_NAME)) {
|
||||
pBuf.name = inputDeviceJson[DEVICE_NAME].get<std::string>();
|
||||
}
|
||||
if (IsString(inputDeviceJson, PHYSICAL_PATH)) {
|
||||
pBuf.physicalPath = inputDeviceJson[PHYSICAL_PATH].get<std::string>();
|
||||
}
|
||||
if (IsString(inputDeviceJson, UNIQUE_ID)) {
|
||||
pBuf.uniqueId = inputDeviceJson[UNIQUE_ID].get<std::string>();
|
||||
}
|
||||
if (IsUInt16(inputDeviceJson, BUS)) {
|
||||
pBuf.bus = inputDeviceJson[BUS].get<uint16_t>();
|
||||
}
|
||||
if (IsUInt16(inputDeviceJson, VENDOR)) {
|
||||
pBuf.vendor = inputDeviceJson[VENDOR].get<uint16_t>();
|
||||
}
|
||||
if (IsUInt16(inputDeviceJson, PRODUCT)) {
|
||||
pBuf.product = inputDeviceJson[PRODUCT].get<uint16_t>();
|
||||
}
|
||||
if (IsUInt16(inputDeviceJson, VERSION)) {
|
||||
pBuf.version = inputDeviceJson[VERSION].get<uint16_t>();
|
||||
}
|
||||
if (IsString(inputDeviceJson, DESCRIPTOR)) {
|
||||
pBuf.descriptor = inputDeviceJson[DESCRIPTOR].get<std::string>();
|
||||
}
|
||||
if (IsUInt32(inputDeviceJson, CLASSES)) {
|
||||
pBuf.classes = inputDeviceJson[CLASSES].get<uint32_t>();
|
||||
}
|
||||
if (IsArray(inputDeviceJson, EVENT_TYPES)) {
|
||||
pBuf.eventTypes = inputDeviceJson[EVENT_TYPES].get<std::vector<uint32_t>>();
|
||||
}
|
||||
if (IsArray(inputDeviceJson, EVENT_KEYS)) {
|
||||
pBuf.eventKeys = inputDeviceJson[EVENT_KEYS].get<std::vector<uint32_t>>();
|
||||
}
|
||||
if (IsArray(inputDeviceJson, ABS_TYPES)) {
|
||||
pBuf.absTypes = inputDeviceJson[ABS_TYPES].get<std::vector<uint32_t>>();
|
||||
}
|
||||
if (IsArray(inputDeviceJson, ABS_INFOS)) {
|
||||
pBuf.absInfos = inputDeviceJson[ABS_INFOS].get<std::map<uint32_t, std::vector<int32_t>>>();
|
||||
}
|
||||
if (IsArray(inputDeviceJson, REL_TYPES)) {
|
||||
pBuf.relTypes = inputDeviceJson[REL_TYPES].get<std::vector<uint32_t>>();
|
||||
}
|
||||
if (IsArray(inputDeviceJson, PROPERTIES)) {
|
||||
pBuf.properties = inputDeviceJson[PROPERTIES].get<std::vector<uint32_t>>();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputNodeManager::CreateHandle(const InputDevice& inputDevice, const std::string& devId,
|
||||
const std::string& dhId)
|
||||
int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std::string& devId, const std::string& dhId)
|
||||
{
|
||||
std::unique_lock<std::mutex> my_lock(operationMutex_);
|
||||
std::call_once(callOnceFlag_, [this]() { inputHub_->ScanInputDevices(DEVICE_PATH); });
|
||||
std::unique_ptr<VirtualDevice> virtualDevice = std::make_unique<VirtualDevice>(inputDevice);
|
||||
std::unique_ptr<VirtualDevice> device;
|
||||
if (event.classes & INPUT_DEVICE_CLASS_KEYBOARD) {
|
||||
device = std::make_unique<VirtualKeyboard>(event);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_CURSOR) {
|
||||
device = std::make_unique<VirtualMouse>(event);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_TOUCH_MT) {
|
||||
inputHub_->ScanInputDevices(DEVICE_PATH);
|
||||
LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo;
|
||||
device = std::make_unique<VirtualTouchScreen>(event, info, info.absMtPositionXMax, info.absMtPositionYMax);
|
||||
} else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) {
|
||||
device = std::make_unique<VirtualTouchpad>(event);
|
||||
} else {
|
||||
DHLOGW("could not find the deviceType\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
}
|
||||
|
||||
virtualDevice->SetNetWorkId(devId);
|
||||
if (device == nullptr) {
|
||||
DHLOGE("could not create new virtual device == null\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
}
|
||||
|
||||
if (!virtualDevice->SetUp(inputDevice, devId, dhId)) {
|
||||
device->SetNetWorkId(devId);
|
||||
|
||||
if (!device->SetUp(devId, dhId)) {
|
||||
DHLOGE("could not create new virtual device\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
}
|
||||
AddDeviceLocked(inputDevice.descriptor, std::move(virtualDevice));
|
||||
AddDeviceLocked(event.descriptor, std::move(device));
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -149,8 +129,8 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str
|
||||
LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo;
|
||||
DHLOGI("CreateVirtualTouchScreenNode start, dhId: %s, sourcePhyWidth: %d, sourcePhyHeight: %d",
|
||||
GetAnonyString(dhId).c_str(), sourcePhyWidth, sourcePhyHeight);
|
||||
device = std::make_unique<VirtualDevice>(info.deviceInfo);
|
||||
if (!device->SetUp(info.deviceInfo, devId, dhId)) {
|
||||
device = std::make_unique<VirtualTouchScreen>(info.deviceInfo, info, sourcePhyWidth - 1, sourcePhyHeight - 1);
|
||||
if (!device->SetUp(devId, dhId)) {
|
||||
DHLOGE("Virtual touch Screen setUp fail, devId: %s, dhId: %s", GetAnonyString(devId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
|
||||
@@ -26,16 +26,14 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
constexpr uint32_t ABS_MIN_POS = 1;
|
||||
constexpr uint32_t ABS_MAX_POS = 2;
|
||||
constexpr uint32_t ABS_FUZZ_POS = 3;
|
||||
constexpr uint32_t ABS_FLAT_POS = 4;
|
||||
VirtualDevice::VirtualDevice()
|
||||
: deviceName_(""), netWorkId_(""), busType_(0), vendorId_(0), productId_(0), version_(0), classes_(0)
|
||||
{
|
||||
}
|
||||
|
||||
VirtualDevice::VirtualDevice(const InputDevice& event) : deviceName_(event.name), busType_(event.bus),
|
||||
vendorId_(event.vendor), productId_(event.product), version_(event.version), classes_(event.classes)
|
||||
{
|
||||
DHLOGI("VirtualDevice ctor!");
|
||||
}
|
||||
|
||||
VirtualDevice::~VirtualDevice()
|
||||
@@ -57,7 +55,7 @@ bool VirtualDevice::DoIoctl(int32_t fd, int32_t request, const uint32_t value)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VirtualDevice::CreateKey(const InputDevice& inputDevice)
|
||||
bool VirtualDevice::CreateKey()
|
||||
{
|
||||
auto fun = [this](int32_t uiSet, const std::vector<uint32_t>& list) -> bool {
|
||||
for (uint32_t evt_type : list) {
|
||||
@@ -68,34 +66,20 @@ bool VirtualDevice::CreateKey(const InputDevice& inputDevice)
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
std::map<int32_t, std::vector<uint32_t>> evt_type;
|
||||
evt_type[UI_SET_EVBIT] = inputDevice.eventTypes;
|
||||
evt_type[UI_SET_KEYBIT] = inputDevice.eventKeys;
|
||||
evt_type[UI_SET_PROPBIT] = inputDevice.properties;
|
||||
evt_type[UI_SET_ABSBIT] = inputDevice.absTypes;
|
||||
evt_type[UI_SET_RELBIT] = inputDevice.relTypes;
|
||||
evt_type[UI_SET_EVBIT] = GetEventTypes();
|
||||
evt_type[UI_SET_KEYBIT] = GetKeys();
|
||||
evt_type[UI_SET_PROPBIT] = GetProperties();
|
||||
evt_type[UI_SET_ABSBIT] = GetAbs();
|
||||
evt_type[UI_SET_RELBIT] = GetRelBits();
|
||||
for (auto &it : evt_type) {
|
||||
if (!fun(it.first, it.second)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void VirtualDevice::SetABSInfo(struct uinput_user_dev& inputUserDev, const InputDevice& inputDevice)
|
||||
{
|
||||
DHLOGI("SetABSInfo!");
|
||||
for (const auto item : inputDevice.absInfos) {
|
||||
int absCode = item.first;
|
||||
std::vector<int32_t> absInfo = item.second;
|
||||
DHLOGI("SetABSInfo nodeName: %s, absCode: %d, absMin: %d, absMax: %d, absFuzz: %d, absFlat: %d",
|
||||
inputDevice.name.c_str(), absCode, absInfo[ABS_MIN_POS], absInfo[ABS_MAX_POS], absInfo[ABS_FUZZ_POS],
|
||||
absInfo[ABS_FLAT_POS]);
|
||||
inputUserDev.absmin[absCode] = absInfo[ABS_MIN_POS];
|
||||
inputUserDev.absmax[absCode] = absInfo[ABS_MAX_POS];
|
||||
inputUserDev.absfuzz[absCode] = absInfo[ABS_FUZZ_POS];
|
||||
inputUserDev.absflat[absCode] = absInfo[ABS_FLAT_POS];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId)
|
||||
@@ -110,7 +94,7 @@ bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VirtualDevice::SetUp(const InputDevice& inputDevice, const std::string& devId, const std::string& dhId)
|
||||
bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId)
|
||||
{
|
||||
fd_ = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
|
||||
if (fd_ < 0) {
|
||||
@@ -136,13 +120,11 @@ bool VirtualDevice::SetUp(const InputDevice& inputDevice, const std::string& dev
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CreateKey(inputDevice)) {
|
||||
if (!CreateKey()) {
|
||||
DHLOGE("Failed to create KeyValue");
|
||||
return false;
|
||||
}
|
||||
|
||||
SetABSInfo(dev_, inputDevice);
|
||||
|
||||
if (write(fd_, &dev_, sizeof(dev_)) < 0) {
|
||||
DHLOGE("Unable to set input device info");
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 "virtual_keyboard.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
const std::vector<uint32_t> EVT_TYPES {
|
||||
EV_KEY, EV_MSC, EV_LED, EV_REP, EV_SYN
|
||||
};
|
||||
const std::vector<uint32_t> KEYS {
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85,
|
||||
86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
|
||||
113, 114, 115, 116, 117, 119, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
|
||||
137, 138, 140, 142, 150, 152, 158, 159, 161, 163, 164, 165, 166, 173, 176, 177, 178, 179, 180, 183, 184, 185,
|
||||
186, 187, 188, 189, 190, 191, 192, 193, 194, 240, 211, 213, 214, 215, 218, 220, 221, 222, 223, 226, 227, 231,
|
||||
232, 233, 236, 237, 238, 239, 242, 243, 245, 246, 247, 248, 464, 522, 523, 141, 145, 146, 147, 148, 149, 151,
|
||||
153, 154, 157, 160, 162, 170, 175, 182, 200, 201, 202, 203, 204, 205, 101, 112, 118, 120
|
||||
};
|
||||
const std::vector<uint32_t> PROPERTIES {};
|
||||
const std::vector<uint32_t> ABS {};
|
||||
const std::vector<uint32_t> RELBITS {};
|
||||
}
|
||||
|
||||
VirtualKeyboard::VirtualKeyboard(const InputDevice& event) : VirtualDevice(event) {}
|
||||
|
||||
VirtualKeyboard::~VirtualKeyboard() {}
|
||||
|
||||
const std::vector<uint32_t>& VirtualKeyboard::GetEventTypes() const
|
||||
{
|
||||
return EVT_TYPES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualKeyboard::GetKeys() const
|
||||
{
|
||||
return KEYS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualKeyboard::GetProperties() const
|
||||
{
|
||||
return PROPERTIES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualKeyboard::GetAbs() const
|
||||
{
|
||||
return ABS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualKeyboard::GetRelBits() const
|
||||
{
|
||||
return RELBITS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 "virtual_mouse.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
const std::vector<uint32_t> EVT_TYPES {
|
||||
EV_KEY, EV_REL, EV_MSC, EV_SYN
|
||||
};
|
||||
const std::vector<uint32_t> KEYS {
|
||||
BTN_MOUSE, BTN_LEFT, BTN_RIGHT, BTN_MIDDLE, BTN_SIDE, BTN_EXTRA, BTN_FORWARD, BTN_BACK, BTN_TASK
|
||||
};
|
||||
const std::vector<uint32_t> PROPERTIES {};
|
||||
const std::vector<uint32_t> ABS {};
|
||||
const std::vector<uint32_t> RELBITS {
|
||||
REL_X, REL_Y, REL_WHEEL, REL_WHEEL_HI_RES
|
||||
};
|
||||
}
|
||||
|
||||
VirtualMouse::VirtualMouse(const InputDevice& event) : VirtualDevice(event) {}
|
||||
|
||||
VirtualMouse::~VirtualMouse() {}
|
||||
|
||||
const std::vector<uint32_t>& VirtualMouse::GetEventTypes() const
|
||||
{
|
||||
return EVT_TYPES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualMouse::GetKeys() const
|
||||
{
|
||||
return KEYS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualMouse::GetProperties() const
|
||||
{
|
||||
return PROPERTIES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualMouse::GetAbs() const
|
||||
{
|
||||
return ABS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualMouse::GetRelBits() const
|
||||
{
|
||||
return RELBITS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 "virtual_touchpad.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
const std::vector<uint32_t> EVT_TYPES {
|
||||
EV_KEY, EV_ABS
|
||||
};
|
||||
const std::vector<uint32_t> KEYS {
|
||||
BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_STYLUS, BTN_TOOL_PEN
|
||||
};
|
||||
const std::vector<uint32_t> PROPERTIES {};
|
||||
const std::vector<uint32_t> ABS {
|
||||
ABS_X, ABS_Y, ABS_WHEEL, ABS_MISC
|
||||
};
|
||||
const std::vector<uint32_t> RELBITS {};
|
||||
}
|
||||
|
||||
VirtualTouchpad::VirtualTouchpad(const InputDevice& event) : VirtualDevice(event)
|
||||
{
|
||||
const int absMaxWheel = 71;
|
||||
|
||||
dev_.absmin[ABS_X] = 0;
|
||||
dev_.absmax[ABS_X] = 1;
|
||||
dev_.absfuzz[ABS_X] = 0;
|
||||
dev_.absflat[ABS_X] = 0;
|
||||
|
||||
dev_.absmin[ABS_Y] = 0;
|
||||
dev_.absmax[ABS_Y] = 1;
|
||||
dev_.absfuzz[ABS_Y] = 0;
|
||||
dev_.absflat[ABS_Y] = 0;
|
||||
|
||||
dev_.absmin[ABS_WHEEL] = 0;
|
||||
dev_.absmax[ABS_WHEEL] = absMaxWheel;
|
||||
dev_.absfuzz[ABS_WHEEL] = 0;
|
||||
dev_.absflat[ABS_WHEEL] = 0;
|
||||
|
||||
dev_.absmin[ABS_MISC] = 0;
|
||||
dev_.absmax[ABS_MISC] = 0;
|
||||
dev_.absfuzz[ABS_MISC] = 0;
|
||||
dev_.absflat[ABS_MISC] = 0;
|
||||
}
|
||||
|
||||
VirtualTouchpad::~VirtualTouchpad() {}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchpad::GetEventTypes() const
|
||||
{
|
||||
return EVT_TYPES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchpad::GetKeys() const
|
||||
{
|
||||
return KEYS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchpad::GetProperties() const
|
||||
{
|
||||
return PROPERTIES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchpad::GetAbs() const
|
||||
{
|
||||
return ABS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchpad::GetRelBits() const
|
||||
{
|
||||
return RELBITS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 "virtual_touchscreen.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
const std::vector<uint32_t> EVT_TYPES {
|
||||
EV_KEY, EV_ABS
|
||||
};
|
||||
const std::vector<uint32_t> KEYS {
|
||||
KEY_F1, KEY_VOLUMEDOWN, KEY_VOLUMEUP, KEY_POWER, BTN_TOOL_FINGER, BTN_TOUCH, BTN_TRIGGER_HAPPY2,
|
||||
BTN_TRIGGER_HAPPY3
|
||||
};
|
||||
const std::vector<uint32_t> PROPERTIES {
|
||||
INPUT_PROP_DIRECT
|
||||
};
|
||||
const std::vector<uint32_t> ABS {
|
||||
ABS_X, ABS_Y, ABS_PRESSURE, ABS_MT_TOUCH_MAJOR, ABS_MT_TOUCH_MINOR, ABS_MT_ORIENTATION, ABS_MT_POSITION_X,
|
||||
ABS_MT_POSITION_Y, ABS_MT_BLOB_ID, ABS_MT_TRACKING_ID, ABS_MT_PRESSURE
|
||||
};
|
||||
const std::vector<uint32_t> RELBITS {};
|
||||
}
|
||||
|
||||
VirtualTouchScreen::VirtualTouchScreen(const InputDevice& event, LocalAbsInfo& absInfo, uint32_t phyWidth,
|
||||
uint32_t phyHeight) : VirtualDevice(event)
|
||||
{
|
||||
dev_.absmin[ABS_X] = 0;
|
||||
dev_.absmax[ABS_X] = static_cast<int32_t>(phyWidth);
|
||||
dev_.absfuzz[ABS_X] = 0;
|
||||
dev_.absflat[ABS_X] = 0;
|
||||
|
||||
dev_.absmin[ABS_Y] = 0;
|
||||
dev_.absmax[ABS_Y] = static_cast<int32_t>(phyHeight);
|
||||
dev_.absfuzz[ABS_Y] = 0;
|
||||
dev_.absflat[ABS_Y] = 0;
|
||||
|
||||
dev_.absmin[ABS_PRESSURE] = absInfo.absPressureMin;
|
||||
dev_.absmax[ABS_PRESSURE] = absInfo.absPressureMax;
|
||||
dev_.absfuzz[ABS_PRESSURE] = 0;
|
||||
dev_.absflat[ABS_PRESSURE] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_TOUCH_MAJOR] = absInfo.absMtTouchMajorMin;
|
||||
dev_.absmax[ABS_MT_TOUCH_MAJOR] = absInfo.absMtTouchMajorMax;
|
||||
dev_.absfuzz[ABS_MT_TOUCH_MAJOR] = 0;
|
||||
dev_.absflat[ABS_MT_TOUCH_MAJOR] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_TOUCH_MINOR] = absInfo.absMtTouchMinorMin;
|
||||
dev_.absmax[ABS_MT_TOUCH_MINOR] = absInfo.absMtTouchMinorMax;
|
||||
dev_.absfuzz[ABS_MT_TOUCH_MINOR] = 0;
|
||||
dev_.absflat[ABS_MT_TOUCH_MINOR] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_ORIENTATION] = absInfo.absMtOrientationMin;
|
||||
dev_.absmax[ABS_MT_ORIENTATION] = absInfo.absMtOrientationMax;
|
||||
dev_.absfuzz[ABS_MT_ORIENTATION] = 0;
|
||||
dev_.absflat[ABS_MT_ORIENTATION] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_POSITION_X] = 0;
|
||||
dev_.absmax[ABS_MT_POSITION_X] = static_cast<int32_t>(phyWidth);
|
||||
dev_.absfuzz[ABS_MT_POSITION_X] = 0;
|
||||
dev_.absflat[ABS_MT_POSITION_X] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_POSITION_Y] = 0;
|
||||
dev_.absmax[ABS_MT_POSITION_Y] = static_cast<int32_t>(phyHeight);
|
||||
dev_.absfuzz[ABS_MT_POSITION_Y] = 0;
|
||||
dev_.absflat[ABS_MT_POSITION_Y] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_BLOB_ID] = absInfo.absMtBlobIdMin;
|
||||
dev_.absmax[ABS_MT_BLOB_ID] = absInfo.absMtBlobIdMax;
|
||||
dev_.absfuzz[ABS_MT_BLOB_ID] = 0;
|
||||
dev_.absflat[ABS_MT_BLOB_ID] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_TRACKING_ID] = absInfo.absMtTrackingIdMin;
|
||||
dev_.absmax[ABS_MT_TRACKING_ID] = absInfo.absMtTrackingIdMax;
|
||||
dev_.absfuzz[ABS_MT_TRACKING_ID] = 0;
|
||||
dev_.absflat[ABS_MT_TRACKING_ID] = 0;
|
||||
|
||||
dev_.absmin[ABS_MT_PRESSURE] = absInfo.absMtPressureMin;
|
||||
dev_.absmax[ABS_MT_PRESSURE] = absInfo.absMtPressureMax;
|
||||
dev_.absfuzz[ABS_MT_PRESSURE] = 0;
|
||||
dev_.absflat[ABS_MT_PRESSURE] = 0;
|
||||
}
|
||||
|
||||
VirtualTouchScreen::~VirtualTouchScreen() {}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchScreen::GetEventTypes() const
|
||||
{
|
||||
return EVT_TYPES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchScreen::GetKeys() const
|
||||
{
|
||||
return KEYS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchScreen::GetProperties() const
|
||||
{
|
||||
return PROPERTIES;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchScreen::GetAbs() const
|
||||
{
|
||||
return ABS;
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& VirtualTouchScreen::GetRelBits() const
|
||||
{
|
||||
return RELBITS;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -62,6 +62,10 @@ ohos_unittest("distributed_input_inner_sourceinject_test") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_inject.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_node_manager.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_device.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_keyboard.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_mouse.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchpad.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchscreen.cpp",
|
||||
"distributed_input_sourceinject_test.cpp",
|
||||
"${common_path}/test/mock/softbus_bus_center_mock.cpp",
|
||||
]
|
||||
|
||||
@@ -44,7 +44,6 @@ ohos_shared_library("libdinput_source") {
|
||||
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/common",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -102,7 +101,6 @@ ohos_shared_library("libdinput_source") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -2660,17 +2660,17 @@ int32_t DistributedInputSourceManager::StartDScreenListener::ParseMessage(const
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkDevId = jsonObj[SINK_DEVICE_ID].get<std::string>();
|
||||
if (!IsUInt64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
DHLOGE("sourceWinId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
srcScreenInfo.sourceWinId = jsonObj[SOURCE_WINDOW_ID].get<uint64_t>();
|
||||
if (!IsUInt32(jsonObj, SOURCE_WINDOW_WIDTH)) {
|
||||
if (!IsUint32(jsonObj, SOURCE_WINDOW_WIDTH)) {
|
||||
DHLOGE("sourceWinWidth key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
srcScreenInfo.sourceWinWidth = jsonObj[SOURCE_WINDOW_WIDTH].get<std::uint32_t>();
|
||||
if (!IsUInt32(jsonObj, SOURCE_WINDOW_HEIGHT)) {
|
||||
if (!IsUint32(jsonObj, SOURCE_WINDOW_HEIGHT)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
@@ -2770,7 +2770,7 @@ int32_t DistributedInputSourceManager::StopDScreenListener::ParseMessage(const s
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkDevId = jsonObj[SINK_DEVICE_ID].get<std::string>();
|
||||
if (!IsUInt64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
DHLOGE("sourceWinId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,10 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_inject.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_node_manager.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_device.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_keyboard.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_mouse.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchpad.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchscreen.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_manager.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp",
|
||||
|
||||
@@ -38,7 +38,6 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"${distributedinput_path}/inputdevicehandler/include",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [ "src/distributed_input_source_transport.cpp" ]
|
||||
@@ -57,7 +56,6 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -39,7 +39,6 @@ ohos_shared_library("libdinput_source_handler") {
|
||||
"${services_source_path}/inputinject/include",
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include",
|
||||
"//third_party/libevdev/libevdev/"
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -59,7 +58,6 @@ ohos_shared_library("libdinput_source_handler") {
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"//third_party/libevdev:libevdev",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "i_dinput_context.h"
|
||||
#include "input_hub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
|
||||
@@ -36,13 +36,11 @@ std::string GetLocalNetworkId();
|
||||
std::string GetUUIDBySoftBus(const std::string &networkId);
|
||||
uint64_t GetCurrentTime();
|
||||
std::string SetAnonyId(const std::string &message);
|
||||
/* IsString, IsUInt32 and IsUInt64 are used to valid json key */
|
||||
/* IsString, IsUint32 and IsUint64 are used to valid json key */
|
||||
bool IsString(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsInt32(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUInt16(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUInt32(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUInt64(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsArray(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUint32(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUint64(const nlohmann::json& jsonObj, const std::string& key);
|
||||
std::string GetNodeDesc(std::string parameters);
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
const char *const DESCRIPTOR = "descriptor";
|
||||
}
|
||||
|
||||
DevInfo GetLocalDeviceInfo()
|
||||
{
|
||||
DevInfo devInfo{"", "", 0};
|
||||
@@ -130,35 +134,20 @@ bool IsInt32(const nlohmann::json& jsonObj, const std::string& key)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool IsUInt16(const nlohmann::json& jsonObj, const std::string& key)
|
||||
{
|
||||
bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT16_MAX;
|
||||
DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid");
|
||||
return res;
|
||||
}
|
||||
|
||||
bool IsUInt32(const nlohmann::json& jsonObj, const std::string& key)
|
||||
bool IsUint32(const nlohmann::json& jsonObj, const std::string& key)
|
||||
{
|
||||
bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT32_MAX;
|
||||
DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid");
|
||||
return res;
|
||||
}
|
||||
|
||||
bool IsUInt64(const nlohmann::json& jsonObj, const std::string& key)
|
||||
bool IsUint64(const nlohmann::json& jsonObj, const std::string& key)
|
||||
{
|
||||
bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT64_MAX;
|
||||
DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid");
|
||||
return res;
|
||||
}
|
||||
|
||||
bool IsArray(const nlohmann::json& jsonObj, const std::string& key)
|
||||
{
|
||||
bool res = jsonObj.contains(key) && jsonObj[key].is_array();
|
||||
DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid");
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string GetNodeDesc(std::string parameters)
|
||||
{
|
||||
nlohmann::json parObj = nlohmann::json::parse(parameters, nullptr, false);
|
||||
@@ -170,11 +159,11 @@ std::string GetNodeDesc(std::string parameters)
|
||||
std::string physicalPath = "N/A";
|
||||
int32_t classes = -1;
|
||||
|
||||
if (parObj.find(DEVICE_NAME) != parObj.end() && parObj.find(PHYSICAL_PATH) != parObj.end() &&
|
||||
parObj.find(CLASSES) != parObj.end()) {
|
||||
nodeName = parObj.at(DEVICE_NAME).get<std::string>();
|
||||
physicalPath = parObj.at(PHYSICAL_PATH).get<std::string>();
|
||||
classes = parObj.at(CLASSES).get<int32_t>();
|
||||
if (parObj.find("name") != parObj.end() && parObj.find("physicalPath") != parObj.end() &&
|
||||
parObj.find("classes") != parObj.end()) {
|
||||
nodeName = parObj.at("name").get<std::string>();
|
||||
physicalPath = parObj.at("physicalPath").get<std::string>();
|
||||
classes = parObj.at("classes").get<int32_t>();
|
||||
}
|
||||
return "{ nodeName: " + nodeName + ", physicalPath: " + physicalPath + ", classes: " +
|
||||
std::to_string(classes) + " }";
|
||||
|
||||
Reference in New Issue
Block a user