mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-18 16:04:40 -04:00
Description:add startScreen Feature
Match-id-ac751a4511a3e385320912de43c9860f0c22a529
This commit is contained in:
@@ -113,6 +113,32 @@ namespace DistributedInput {
|
||||
|
||||
const std::string DINPUT_SPLIT_COMMA = ", ";
|
||||
|
||||
const std::string SOURCE_DEVICE_ID = "sourceDevId";
|
||||
|
||||
const std::string SINK_DEVICE_ID = "sinkDevId";
|
||||
|
||||
const std::string SOURCE_WINDOW_ID = "sourceWinId";
|
||||
|
||||
const std::string SINK_SHOW_WINDOW_ID = "sinkShowWinId";
|
||||
|
||||
const std::string SOURCE_WINDOW_WIDTH = "sourceWinWidth";
|
||||
|
||||
const std::string SOURCE_WINDOW_HEIGHT = "sourceWinHeight";
|
||||
|
||||
const std::string SINK_PROJECT_SHOW_WIDTH = "sinkProjShowWidth";
|
||||
|
||||
const std::string SINK_PROJECT_SHOW_HEIGHT = "sinkProjShowHeight";
|
||||
|
||||
const std::string SINK_WINDOW_SHOW_X = "sinkWinShowX";
|
||||
|
||||
const std::string SINK_WINDOW_SHOW_Y = "sinkWinShowY";
|
||||
|
||||
constexpr uint32_t SCREEN_ID_DEFAULT = 0;
|
||||
|
||||
constexpr uint32_t DEFAULT_VALUE = 0;
|
||||
|
||||
constexpr int32_t UNINIT_FD_VALUE = -1;
|
||||
|
||||
enum class EHandlerMsgType {
|
||||
DINPUT_SINK_EVENT_HANDLER_MSG = 1,
|
||||
DINPUT_SOURCE_EVENT_HANDLER_MSG = 2
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace DistributedInput {
|
||||
constexpr int32_t ERR_DH_INPUT_LOW_LATENCY_LIB_NULL = -60011;
|
||||
constexpr int32_t ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST = -60012;
|
||||
constexpr int32_t ERR_DH_INPUT_CONTEXT_CALCULATE_FAIL = -60013;
|
||||
constexpr int32_t ERR_DH_INPUT_JSON_PARSE_FAIL = -60014;
|
||||
|
||||
// whilte list error code
|
||||
constexpr int32_t ERR_DH_INPUT_WHILTELIST_INIT_FAIL = -61001;
|
||||
@@ -57,6 +58,7 @@ namespace DistributedInput {
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESPSTOP_FAIL = -64008;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_SENDMESSAGE_FAIL = -64009;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_TRANSPORT_RESP_LATENCY_FAIL = -64010;
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SINK_SCREEN_INFO_IS_EMPTY = -64011;
|
||||
|
||||
// service source error code
|
||||
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_INJECT_REGISTER_FAIL = -65000;
|
||||
@@ -131,6 +133,11 @@ namespace DistributedInput {
|
||||
constexpr int32_t ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL = -67028;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL = -67029;
|
||||
constexpr int32_t ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL = -67030;
|
||||
constexpr int32_t ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL = -67035;
|
||||
constexpr int32_t ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL = -67036;
|
||||
constexpr int32_t ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL = -67037;
|
||||
constexpr int32_t ERR_DH_INPUT_RPC_REPLY_FAIL = -67038;
|
||||
constexpr int32_t ERR_DH_INPUT_SA_REQUEST_CODE_INVALID = -67039;
|
||||
|
||||
// Hidump Helper error code
|
||||
constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <securec.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@@ -35,6 +34,7 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_context.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dh_utils_tool.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -209,7 +209,7 @@ size_t InputHub::CollectEvent(RawEvent* buffer, size_t& capacity, size_t bufferS
|
||||
|
||||
std::vector<bool> needFilted(bufferSize, false);
|
||||
if (device->classes == INPUT_DEVICE_CLASS_TOUCH_MT) {
|
||||
HandleTouchScreenEvent(readBuffer, count, needFilted);
|
||||
HandleTouchScreenEvent(readBuffer, count, needFilted, device);
|
||||
}
|
||||
|
||||
RawEvent* event = buffer;
|
||||
@@ -670,21 +670,6 @@ std::string InputHub::StringPrintf(const char* format, ...) const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string InputHub::Sha256(const std::string& in) const
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, reinterpret_cast<const u_char*>(in.c_str()), in.size());
|
||||
u_char digest[SHA_DIGEST_LENGTH];
|
||||
SHA256_Final(digest, &ctx);
|
||||
|
||||
std::string out;
|
||||
for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) {
|
||||
out += StringPrintf("%02x", digest[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void InputHub::GenerateDescriptor(InputDevice& identifier) const
|
||||
{
|
||||
std::string rawDescriptor;
|
||||
@@ -964,7 +949,6 @@ void InputHub::RecordEventLog(const RawEvent* event)
|
||||
case EV_ABS:
|
||||
eventType = "EV_ABS";
|
||||
break;
|
||||
break;
|
||||
case EV_SYN:
|
||||
eventType = "EV_SYN";
|
||||
break;
|
||||
@@ -972,60 +956,59 @@ void InputHub::RecordEventLog(const RawEvent* event)
|
||||
eventType = "other type " + std::to_string(event->type);
|
||||
break;
|
||||
}
|
||||
DHLOGD("1.E2E-Test Sink collect event, EventType: %s, Code: %d, Value: %d, Path: %s, When:%" PRId64 "",
|
||||
eventType.c_str(), event->code, event->value, event->path.c_str(), event->when);
|
||||
DHLOGD("1.E2E-Test Sink collect event, EventType: %s, Code: %d, Value: %d, Path: %s, descriptor: %s,"
|
||||
"When:%" PRId64 "", eventType.c_str(), event->code, event->value, event->path.c_str(),
|
||||
GetAnonyString(event->descriptor).c_str(), event->when);
|
||||
}
|
||||
|
||||
void InputHub::HandleTouchScreenEvent(struct input_event readBuffer[], const size_t count,
|
||||
std::vector<bool>& needFilted)
|
||||
std::vector<bool>& needFilted, Device* device)
|
||||
{
|
||||
std::vector<std::pair<size_t, size_t>> absIndexs;
|
||||
uint32_t typePre = 0;
|
||||
uint32_t typeCurr = 0;
|
||||
size_t firstIndex = 0;
|
||||
size_t lastIndex = 0;
|
||||
int32_t firstIndex = -1;
|
||||
int32_t lastIndex = -1;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
struct input_event& iev = readBuffer[i];
|
||||
typePre = typeCurr;
|
||||
typeCurr = iev.type;
|
||||
if ((typePre != EV_ABS) && (typeCurr == EV_ABS)) {
|
||||
firstIndex = i;
|
||||
if ((iev.type == EV_ABS) && (iev.code == ABS_MT_POSITION_X || iev.code == ABS_X)) {
|
||||
firstIndex = (int32_t)i;
|
||||
} else if (iev.type == EV_SYN) {
|
||||
lastIndex = (int32_t)i;
|
||||
}
|
||||
if (typeCurr == EV_SYN) {
|
||||
lastIndex = i;
|
||||
absIndexs.emplace_back(std::make_pair(firstIndex, lastIndex));
|
||||
if ((firstIndex >= 0) && (lastIndex > 0)) {
|
||||
absIndexs.emplace_back(std::make_pair((size_t)firstIndex, (size_t)lastIndex));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t absXIndex = -1;
|
||||
int32_t absYIndex = -1;
|
||||
uint32_t absX = 0;
|
||||
uint32_t absY = 0;
|
||||
AbsInfo absInfo = {
|
||||
.absX = 0,
|
||||
.absY = 0,
|
||||
.absXIndex = -1,
|
||||
.absYIndex = -1,
|
||||
};
|
||||
for (auto iter : absIndexs) {
|
||||
absXIndex = -1;
|
||||
absYIndex = -1;
|
||||
absInfo.absXIndex = -1;
|
||||
absInfo.absYIndex = -1;
|
||||
|
||||
for (size_t j = iter.first; j <= iter.second; j++) {
|
||||
struct input_event &iev = readBuffer[j];
|
||||
if (iev.code == ABS_MT_POSITION_X) {
|
||||
absX = (uint32_t)iev.value;
|
||||
absXIndex = (int32_t)j;
|
||||
if (iev.code == ABS_MT_POSITION_X || iev.code == ABS_X) {
|
||||
absInfo.absX = iev.value;
|
||||
absInfo.absXIndex = j;
|
||||
}
|
||||
if (iev.code == ABS_MT_POSITION_Y) {
|
||||
absY = (uint32_t)iev.value;
|
||||
absYIndex = (int32_t)j;
|
||||
if (iev.code == ABS_MT_POSITION_Y || iev.code == ABS_Y) {
|
||||
absInfo.absY = iev.value;
|
||||
absInfo.absYIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
if ((absXIndex < 0) || (absYIndex < 0)) {
|
||||
if ((absInfo.absXIndex < 0) || (absInfo.absYIndex < 0)) {
|
||||
for (size_t j = iter.first; j <= iter.second; j++) {
|
||||
needFilted[j] = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!CheckTouchPointRegion(readBuffer, absX, absY, absXIndex, absYIndex)) {
|
||||
if (!CheckTouchPointRegion(readBuffer, absInfo, device)) {
|
||||
for (size_t j = iter.first; j <= iter.second; j++) {
|
||||
needFilted[j] = true;
|
||||
}
|
||||
@@ -1033,17 +1016,17 @@ void InputHub::HandleTouchScreenEvent(struct input_event readBuffer[], const siz
|
||||
}
|
||||
}
|
||||
|
||||
bool InputHub::CheckTouchPointRegion(struct input_event readBuffer[], uint32_t absX, uint32_t absY,
|
||||
int32_t absXIndex, int32_t absYIndex)
|
||||
bool InputHub::CheckTouchPointRegion(struct input_event readBuffer[], const AbsInfo& absInfo, Device* device)
|
||||
{
|
||||
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
|
||||
|
||||
for (const auto& [id, sinkInfo] : sinkInfos) {
|
||||
auto info = sinkInfo.transformInfo;
|
||||
if ((absX >= info.sinkWinPhyX) && (absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth))
|
||||
&& (absY >= info.sinkWinPhyY) && (absY <= (info.sinkWinPhyY + info.sinkProjPhyHeight))) {
|
||||
readBuffer[absXIndex].value = (absX - info.sinkWinPhyX) * info.coeffWidth;
|
||||
readBuffer[absYIndex].value = (absY - info.sinkWinPhyY) * info.coeffHeight;
|
||||
if ((absInfo.absX >= info.sinkWinPhyX) && (absInfo.absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth))
|
||||
&& (absInfo.absY >= info.sinkWinPhyY) && (absInfo.absY <= (info.sinkWinPhyY + info.sinkProjPhyHeight))) {
|
||||
device->identifier.descriptor = sinkInfo.srcScreenInfo.sourcePhyId;
|
||||
readBuffer[absInfo.absXIndex].value = (absInfo.absX - info.sinkWinPhyX) * info.coeffWidth;
|
||||
readBuffer[absInfo.absYIndex].value = (absInfo.absY - info.sinkWinPhyY) * info.coeffHeight;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,13 @@ private:
|
||||
const bool isVirtual; // set if fd < 0 is passed to constructor
|
||||
};
|
||||
|
||||
struct AbsInfo {
|
||||
uint32_t absX;
|
||||
uint32_t absY;
|
||||
int32_t absXIndex;
|
||||
int32_t absYIndex;
|
||||
};
|
||||
|
||||
int32_t Initialize();
|
||||
int32_t Release();
|
||||
|
||||
@@ -78,7 +85,6 @@ private:
|
||||
int32_t MakeDevice(int fd, std::unique_ptr<Device> device);
|
||||
void GenerateDescriptor(InputDevice& identifier) const;
|
||||
std::string StringPrintf(const char* format, ...) const;
|
||||
std::string Sha256(const std::string& in) const;
|
||||
|
||||
int32_t RegisterFdForEpoll(int fd);
|
||||
int32_t RegisterDeviceForEpollLocked(const Device& device);
|
||||
@@ -108,10 +114,10 @@ private:
|
||||
uint32_t SizeofBitArray(uint32_t bit);
|
||||
bool IsSupportInputTypes(uint32_t classes);
|
||||
void RecordEventLog(const RawEvent* event);
|
||||
void HandleTouchScreenEvent(struct input_event readBuffer[], const size_t count, std::vector<bool>& needFilted);
|
||||
void HandleTouchScreenEvent(struct input_event readBuffer[], const size_t count, std::vector<bool>& needFilted,
|
||||
Device* device);
|
||||
int32_t QueryLocalTouchScreenInfo(int fd);
|
||||
bool CheckTouchPointRegion(struct input_event readBuffer[], uint32_t absX, uint32_t absY,
|
||||
int32_t absXIndex, int32_t absYIndex);
|
||||
bool CheckTouchPointRegion(struct input_event readBuffer[], const AbsInfo& absInfo, Device* device);
|
||||
size_t CollectEvent(RawEvent* buffer, size_t& capacity, size_t bufferSize, Device* device);
|
||||
|
||||
int epollFd_;
|
||||
|
||||
@@ -39,6 +39,8 @@ fwk_common_path = "${distributedhardwarefwk_path}/common"
|
||||
|
||||
fwk_utils_path = "${distributedhardwarefwk_path}/utils"
|
||||
|
||||
fwk_interfaces_path = "${distributedhardwarefwk_path}/interfaces/inner_kits"
|
||||
|
||||
distributedinput_ldflags = [ "-lpthread" ]
|
||||
|
||||
declare_args() {
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
#include "i_start_d_input_server_call_back.h"
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_context.h"
|
||||
#include "i_start_d_input_server_call_back.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -31,6 +32,10 @@ class IDistributedSinkInput : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.DistributedHardware.DistributedInput.IDistributedSinkInput");
|
||||
|
||||
/*
|
||||
* Init, Release and IsStartDistributedInput are IPC interface,
|
||||
* which are used for interacting by dhareware and dinput
|
||||
*/
|
||||
virtual int32_t Init() = 0;
|
||||
|
||||
virtual int32_t Release() = 0;
|
||||
@@ -38,10 +43,20 @@ public:
|
||||
virtual int32_t IsStartDistributedInput(
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback) = 0;
|
||||
|
||||
enum class MessageCode {
|
||||
INIT = 0xf011,
|
||||
RELEASE = 0xf012,
|
||||
ISSTART_REMOTE_INPUT = 0xf013,
|
||||
/*
|
||||
* NotifyStartDScreen and NotifyStopDScreen are RPC interface,
|
||||
* which are used for interacting by dinput source and dinput sink
|
||||
*/
|
||||
virtual int32_t NotifyStartDScreen(const SrcScreenInfo& remoteCtrlInfo) = 0;
|
||||
|
||||
virtual int32_t NotifyStopDScreen(const std::string &srcScreenInfoKey) = 0;
|
||||
|
||||
enum {
|
||||
INIT = 0xf011U,
|
||||
RELEASE = 0xf012U,
|
||||
IS_START_REMOTE_INPUT = 0xf013U,
|
||||
NOTIFY_START_DSCREEN = 0xf014U,
|
||||
NOTIFY_STOP_DSCREEN = 0xf015U,
|
||||
};
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef I_DISTRIBUTED_INPUT_H
|
||||
#define I_DISTRIBUTED_INPUT_H
|
||||
#ifndef I_DISTRIBUTED_SOURCE_INPUT_H
|
||||
#define I_DISTRIBUTED_SOURCE_INPUT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -84,4 +84,4 @@ public:
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISTRIBUTED_INPUT_INNERKITS_INCLUDE_I_DISTRIBUTED_INPUT_H
|
||||
#endif // I_DISTRIBUTED_SOURCE_INPUT_H
|
||||
|
||||
@@ -28,6 +28,8 @@ ohos_shared_library("libdinput_handler") {
|
||||
"${frameworks_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -46,6 +48,7 @@ ohos_shared_library("libdinput_handler") {
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+3
@@ -31,6 +31,8 @@ ohos_shared_library("libdinput_sdk") {
|
||||
"${fwk_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
sources = [
|
||||
"${common_path}/include/white_list_util.cpp",
|
||||
@@ -64,6 +66,7 @@ ohos_shared_library("libdinput_sdk") {
|
||||
deps = [
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
defines = [
|
||||
|
||||
Executable → Regular
+3
@@ -43,6 +43,8 @@ ohos_unittest("distributed_input_inner_test") {
|
||||
"${fwk_utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -87,6 +89,7 @@ ohos_unittest("distributed_input_inner_test") {
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -70,6 +70,10 @@ public:
|
||||
|
||||
DInputServerType IsStartDistributedInput(const uint32_t& inputType);
|
||||
|
||||
int32_t NotifyStartDScreen(const std::string &networkId, const std::string& srcDevId, const uint64_t srcWinId);
|
||||
|
||||
int32_t NotifyStopDScreen(const std::string &networkId, const std::string& srcScreenInfoKey);
|
||||
|
||||
public:
|
||||
class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub {
|
||||
public:
|
||||
@@ -111,6 +115,7 @@ private:
|
||||
bool IsJsonData(std::string strData) const;
|
||||
void AddWhiteListInfos(const std::string &deviceId, const std::string &strJson) const;
|
||||
void DelWhiteListInfos(const std::string &deviceId) const;
|
||||
sptr<IDistributedSinkInput> GetRemoteDInput(const std::string &networkId) const;
|
||||
|
||||
private:
|
||||
static std::shared_ptr<DistributedInputClient> instance;
|
||||
|
||||
@@ -39,8 +39,12 @@ public:
|
||||
virtual int32_t IsStartDistributedInput(
|
||||
const uint32_t& inputType, sptr<IStartDInputServerCallback> callback) override;
|
||||
|
||||
virtual int32_t NotifyStartDScreen(const SrcScreenInfo& srcScreenRemoteCtrlInfo) override;
|
||||
|
||||
virtual int32_t NotifyStopDScreen(const std::string& srcScreenInfoKey) override;
|
||||
|
||||
private:
|
||||
bool SendRequest(IDistributedSinkInput::MessageCode code, MessageParcel &data, MessageParcel &reply);
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
static inline BrokerDelegator<DistributedInputSinkProxy> delegator_;
|
||||
};
|
||||
|
||||
@@ -33,8 +33,21 @@ public:
|
||||
virtual int32_t OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
int32_t InitInner(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
int32_t ReleaseInner(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
int32_t IsStartDistributedInputInner(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
int32_t NotifyStartDScreenInner(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
int32_t NotifyStopDScreenInner(MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(DistributedInputSinkStub);
|
||||
using DistributedInputSinkFunc = int32_t (DistributedInputSinkStub::*)(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
std::map<int32_t, DistributedInputSinkFunc> memberFuncMap_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -363,6 +363,64 @@ void DistributedInputClient::DelWhiteListInfos(const std::string &deviceId) cons
|
||||
{
|
||||
WhiteListUtil::GetInstance().ClearWhiteList(deviceId);
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::NotifyStartDScreen(const std::string &sinkDevId, const std::string& srcDevId,
|
||||
const uint64_t srcWinId)
|
||||
{
|
||||
sptr<IDistributedSinkInput> remoteDInput = GetRemoteDInput(sinkDevId);
|
||||
if (remoteDInput == nullptr || !remoteDInput->AsObject()) {
|
||||
DHLOGE("GetRemoteDInput failed, networkId = %s", GetAnonyString(sinkDevId).c_str());
|
||||
return ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL;
|
||||
}
|
||||
std::string srcScreenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(srcDevId, srcWinId);
|
||||
SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(srcScreenInfoKey);
|
||||
DHLOGI("DistributedInputSinkProxy the data: devId: %s, sourceWinId: %d, sourceWinWidth: %d, sourceWinHeight: %d,"
|
||||
"sourcePhyId: %s, sourcePhyFd: %d, sourcePhyWidth: %d, sourcePhyHeight: %d",
|
||||
GetAnonyString(srcScreenInfo.devId).c_str(), srcScreenInfo.sourceWinId, srcScreenInfo.sourceWinWidth,
|
||||
srcScreenInfo.sourceWinHeight, GetAnonyString(srcScreenInfo.sourcePhyId).c_str(), srcScreenInfo.sourcePhyFd,
|
||||
srcScreenInfo.sourcePhyWidth, srcScreenInfo.sourcePhyHeight);
|
||||
auto ret = remoteDInput->NotifyStartDScreen(srcScreenInfo);
|
||||
DHLOGI("NotifyStartDScreen, retCode = %d", ret);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("NotifyStartDScreen failed, errCode = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputClient::NotifyStopDScreen(const std::string &networkId, const std::string& srcScreenInfoKey)
|
||||
{
|
||||
sptr<IDistributedSinkInput> remoteDInput = GetRemoteDInput(networkId);
|
||||
if (remoteDInput == nullptr || !remoteDInput->AsObject()) {
|
||||
DHLOGE("GetRemoteDInput failed, networkId = %s", GetAnonyString(networkId).c_str());
|
||||
return ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL;
|
||||
}
|
||||
auto ret = remoteDInput->NotifyStopDScreen(srcScreenInfoKey);
|
||||
DHLOGI("NotifyStopDScreen, retCode = %d", ret);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("NotifyStopDScreen failed, errCode = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
sptr<IDistributedSinkInput> DistributedInputClient::GetRemoteDInput(const std::string &networkId) const
|
||||
{
|
||||
DHLOGI("start, networkId = %s", GetAnonyString(networkId).c_str());
|
||||
if (networkId.empty()) {
|
||||
DHLOGE("networkId is empty");
|
||||
return nullptr;
|
||||
}
|
||||
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr == nullptr) {
|
||||
DHLOGE("GetSystemAbilityManager failed");
|
||||
return nullptr;
|
||||
}
|
||||
auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, networkId);
|
||||
if (object == nullptr) {
|
||||
DHLOGE("CheckSystemAbility failed");
|
||||
return nullptr;
|
||||
}
|
||||
return iface_cast<IDistributedSinkInput>(object);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "distributed_input_sink_proxy.h"
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
@@ -38,10 +39,12 @@ int32_t DistributedInputSinkProxy::Init()
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
int32_t result = ERR_DH_INPUT_SINK_PROXY_INIT_FAIL;
|
||||
bool ret = SendRequest(IDistributedSinkInput::MessageCode::INIT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
bool ret = SendRequest(INIT, data, reply);
|
||||
if (!ret) {
|
||||
DHLOGE("SendRequest fail!");
|
||||
return ERR_DH_INPUT_SINK_PROXY_INIT_FAIL;
|
||||
}
|
||||
result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -54,10 +57,12 @@ int32_t DistributedInputSinkProxy::Release()
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
int32_t result = ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL;
|
||||
bool ret = SendRequest(IDistributedSinkInput::MessageCode::RELEASE, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
bool ret = SendRequest(RELEASE, data, reply);
|
||||
if (!ret) {
|
||||
DHLOGE("SendRequest fail!");
|
||||
return ERR_DH_INPUT_SINK_PROXY_RELEASE_FAIL;
|
||||
}
|
||||
result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -79,22 +84,75 @@ int32_t DistributedInputSinkProxy::IsStartDistributedInput(
|
||||
}
|
||||
MessageParcel reply;
|
||||
int32_t result = ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL;
|
||||
bool ret = SendRequest(IDistributedSinkInput::MessageCode::ISSTART_REMOTE_INPUT, data, reply);
|
||||
if (ret) {
|
||||
result = reply.ReadInt32();
|
||||
bool ret = SendRequest(IS_START_REMOTE_INPUT, data, reply);
|
||||
if (!ret) {
|
||||
DHLOGE("SendRequest fail!");
|
||||
return ERR_DH_INPUT_SINK_PROXY_IS_START_INPUT_FAIL;
|
||||
}
|
||||
result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DistributedInputSinkProxy::SendRequest(
|
||||
IDistributedSinkInput::MessageCode code, MessageParcel &data, MessageParcel &reply)
|
||||
int32_t DistributedInputSinkProxy::NotifyStartDScreen(const SrcScreenInfo &remoteCtrlInfo)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken fail!");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
DHLOGI("DistributedInputSinkProxy the data: devId: %s, sourceWinId: %d, sourceWinWidth: %d, sourceWinHeight: %d, "
|
||||
"sourcePhyId: %s, sourcePhyFd: %d, sourcePhyWidth: %d, sourcePhyHeight: %d",
|
||||
GetAnonyString(remoteCtrlInfo.devId).c_str(), remoteCtrlInfo.sourceWinId, remoteCtrlInfo.sourceWinWidth,
|
||||
remoteCtrlInfo.sourceWinHeight, GetAnonyString(remoteCtrlInfo.sourcePhyId).c_str(),
|
||||
remoteCtrlInfo.sourcePhyFd, remoteCtrlInfo.sourcePhyWidth, remoteCtrlInfo.sourcePhyHeight);
|
||||
if (!data.WriteString(remoteCtrlInfo.devId) || !data.WriteUint64(remoteCtrlInfo.sourceWinId) ||
|
||||
!data.WriteUint32(remoteCtrlInfo.sourceWinWidth) || !data.WriteUint32(remoteCtrlInfo.sourceWinHeight) ||
|
||||
!data.WriteString(remoteCtrlInfo.sourcePhyId) || !data.WriteUint32(remoteCtrlInfo.sourcePhyFd) ||
|
||||
!data.WriteUint32(remoteCtrlInfo.sourcePhyWidth) || !data.WriteUint32(remoteCtrlInfo.sourcePhyHeight)) {
|
||||
DHLOGE("DistributedInputSinkProxy write params failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
int32_t result = ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL;
|
||||
bool ret = SendRequest(NOTIFY_START_DSCREEN, data, reply);
|
||||
if (!ret) {
|
||||
DHLOGE("SendRequest fail!");
|
||||
return ERR_DH_INPUT_NOTIFY_START_DSCREEN_FAIL;
|
||||
}
|
||||
result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkProxy::NotifyStopDScreen(const std::string &srcScreenInfoKey)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken fail!");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
if (!data.WriteString(srcScreenInfoKey)) {
|
||||
DHLOGE("DistributedInputSinkProxy write params failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
int32_t result = ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL;
|
||||
bool ret = SendRequest(NOTIFY_STOP_DSCREEN, data, reply);
|
||||
if (!ret) {
|
||||
DHLOGE("SendRequest fail!");
|
||||
return ERR_DH_INPUT_NOTIFY_STOP_DSCREEN_FAIL;
|
||||
}
|
||||
result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DistributedInputSinkProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != DH_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "distributed_input_sink_stub.h"
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
@@ -24,10 +25,20 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
DistributedInputSinkStub::DistributedInputSinkStub()
|
||||
{}
|
||||
{
|
||||
DHLOGI("DistributedInputSinkStub ctor!");
|
||||
memberFuncMap_[INIT] = &DistributedInputSinkStub::InitInner;
|
||||
memberFuncMap_[RELEASE] = &DistributedInputSinkStub::ReleaseInner;
|
||||
memberFuncMap_[IS_START_REMOTE_INPUT] = &DistributedInputSinkStub::IsStartDistributedInputInner;
|
||||
memberFuncMap_[NOTIFY_START_DSCREEN] = &DistributedInputSinkStub::NotifyStartDScreenInner;
|
||||
memberFuncMap_[NOTIFY_STOP_DSCREEN] = &DistributedInputSinkStub::NotifyStopDScreenInner;
|
||||
}
|
||||
|
||||
DistributedInputSinkStub::~DistributedInputSinkStub()
|
||||
{}
|
||||
{
|
||||
DHLOGI("DistributedInputSinkStub dtor!");
|
||||
memberFuncMap_.clear();
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
@@ -36,40 +47,94 @@ int32_t DistributedInputSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &
|
||||
DHLOGE("DistributedInputSinkStub read token valid failed");
|
||||
return ERR_DH_INPUT_IPC_READ_TOKEN_VALID_FAIL;
|
||||
}
|
||||
switch (code) {
|
||||
case static_cast<uint32_t>(IDistributedSinkInput::MessageCode::INIT): {
|
||||
int32_t ret = Init();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case static_cast<uint32_t>(IDistributedSinkInput::MessageCode::RELEASE): {
|
||||
int32_t ret = Release();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case static_cast<uint32_t>(IDistributedSinkInput::MessageCode::ISSTART_REMOTE_INPUT): {
|
||||
uint32_t inputType = data.ReadUint32();
|
||||
sptr<IStartDInputServerCallback> callback =
|
||||
iface_cast<IStartDInputServerCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = IsStartDistributedInput(inputType, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
auto iter = memberFuncMap_.find(code);
|
||||
if (iter == memberFuncMap_.end()) {
|
||||
DHLOGE("invalid request code is %d.", code);
|
||||
return ERR_DH_INPUT_SA_REQUEST_CODE_INVALID;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
DistributedInputSinkFunc &func = iter->second;
|
||||
return (this->*func)(data, reply, option);
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkStub::InitInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
DHLOGI("start");
|
||||
int32_t ret = Init();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkStub::ReleaseInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
int32_t ret = Release();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkStub::IsStartDistributedInputInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
uint32_t inputType = data.ReadUint32();
|
||||
sptr<IStartDInputServerCallback> callback =
|
||||
iface_cast<IStartDInputServerCallback>(data.ReadRemoteObject());
|
||||
int32_t ret = IsStartDistributedInput(inputType, callback);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("DistributedInputSinkStub write ret failed");
|
||||
return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkStub::NotifyStartDScreenInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
std::string devId = data.ReadString();
|
||||
uint64_t sourceWinId = data.ReadUint64();
|
||||
uint32_t sourceWinWidth = data.ReadUint32();
|
||||
uint32_t sourceWinHeight = data.ReadUint32();
|
||||
std::string sourcePhyId = data.ReadString();
|
||||
uint32_t sourcePhyFd = data.ReadUint32();
|
||||
uint32_t sourcePhyWidth = data.ReadUint32();
|
||||
uint32_t sourcePhyHeight = data.ReadUint32();
|
||||
DHLOGI("OnRemoteRequest the data: devId: %s, sourceWinId: %d, sourceWinWidth: %d, sourceWinHeight: %d,"
|
||||
"sourcePhyId: %s, sourcePhyFd: %d, sourcePhyWidth: %d, sourcePhyHeight: %d", GetAnonyString(devId).c_str(),
|
||||
sourceWinId, sourceWinWidth, sourceWinHeight, GetAnonyString(sourcePhyId).c_str(), sourcePhyFd, sourcePhyWidth,
|
||||
sourcePhyHeight);
|
||||
SrcScreenInfo srcScreenInfo = {
|
||||
.devId = devId,
|
||||
.sourceWinId = sourceWinId,
|
||||
.sourceWinWidth = sourceWinWidth,
|
||||
.sourceWinHeight = sourceWinHeight,
|
||||
.sourcePhyId = sourcePhyId,
|
||||
.sourcePhyFd = sourcePhyFd,
|
||||
.sourcePhyWidth = sourcePhyWidth,
|
||||
.sourcePhyHeight = sourcePhyHeight,
|
||||
};
|
||||
int32_t ret = NotifyStartDScreen(srcScreenInfo);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("write reply failed");
|
||||
return ERR_DH_INPUT_RPC_REPLY_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkStub::NotifyStopDScreenInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
std::string srcScreenInfoKey = data.ReadString();
|
||||
DHLOGI("OnRemoteRequest srcScreenInfoKey: %s", GetAnonyString(srcScreenInfoKey).c_str());
|
||||
int ret = NotifyStopDScreen(srcScreenInfoKey);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
DHLOGE("write version failed");
|
||||
return ERR_DH_INPUT_RPC_REPLY_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -27,6 +27,8 @@ ohos_shared_library("libdinput_collector") {
|
||||
"${fwk_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -45,6 +47,7 @@ ohos_shared_library("libdinput_collector") {
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+7
@@ -37,6 +37,10 @@ ohos_shared_library("libdinput_sink") {
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"//foundation/window/window_manager/interfaces/innerkits/dm",
|
||||
"//foundation/window/window_manager/utils/include/",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -68,6 +72,9 @@ ohos_shared_library("libdinput_sink") {
|
||||
"//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk",
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/inputcollector:libdinput_collector",
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/transport:libdinput_sink_trans",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DISRIBUTED_INPUT_SINK_MANAGER_SERVICE_H
|
||||
#define DISRIBUTED_INPUT_SINK_MANAGER_SERVICE_H
|
||||
#ifndef DISTRIBUTED_INPUT_SINK_MANAGER_SERVICE_H
|
||||
#define DISTRIBUTED_INPUT_SINK_MANAGER_SERVICE_H
|
||||
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
@@ -23,6 +23,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "event_handler.h"
|
||||
#include "ipublisher_listener.h"
|
||||
#include "publisher_listener_stub.h"
|
||||
#include "screen.h"
|
||||
#include "singleton.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
@@ -41,7 +44,7 @@ class DistributedInputSinkManager : public SystemAbility, public DistributedInpu
|
||||
|
||||
public:
|
||||
DistributedInputSinkManager(int32_t saId, bool runOnCreate);
|
||||
~DistributedInputSinkManager() = default;
|
||||
~DistributedInputSinkManager();
|
||||
|
||||
class DInputSinkListener : public DInputSinkTransCallback {
|
||||
public:
|
||||
@@ -55,6 +58,25 @@ public:
|
||||
DistributedInputSinkManager *sinkManagerObj_;
|
||||
};
|
||||
|
||||
class ProjectWindowListener : public PublisherListenerStub {
|
||||
public:
|
||||
ProjectWindowListener();
|
||||
~ProjectWindowListener();
|
||||
void OnMessage(const DHTopic topic, const std::string& message) override;
|
||||
|
||||
private:
|
||||
int32_t ParseMessage(const std::string& message, std::string& srcDeviceId, uint64_t& srcWinId,
|
||||
SinkScreenInfo& sinkScreenInfo);
|
||||
int32_t UpdateSinkScreenInfoCache(const std::string& srcDevId, const uint64_t srcWinId,
|
||||
const SinkScreenInfo& sinkScreenInfoTmp);
|
||||
uint32_t GetScreenWidth();
|
||||
uint32_t GetScreenHeight();
|
||||
|
||||
private:
|
||||
sptr<Rosen::Screen> screen_;
|
||||
std::mutex handleScreenMutex_;
|
||||
};
|
||||
|
||||
public:
|
||||
void OnStart() override;
|
||||
|
||||
@@ -84,7 +106,12 @@ public:
|
||||
*/
|
||||
std::shared_ptr<DistributedInputSinkEventHandler> GetEventHandler();
|
||||
|
||||
int32_t NotifyStartDScreen(const SrcScreenInfo& srcScreenInfo) override;
|
||||
|
||||
int32_t NotifyStopDScreen(const std::string& srcScreenInfoKey) override;
|
||||
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
private:
|
||||
ServiceSinkRunningState serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START;
|
||||
DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE;
|
||||
@@ -95,9 +122,10 @@ private:
|
||||
std::shared_ptr<DistributedInputSinkEventHandler> handler_;
|
||||
bool InitAuto();
|
||||
DInputDeviceType inputTypes_;
|
||||
sptr<ProjectWindowListener> projectWindowListener_ = nullptr;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISRIBUTED_INPUT_SINK_MANAGER_SERVICE_H
|
||||
#endif // DISTRIBUTED_INPUT_SINK_MANAGER_SERVICE_H
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
#include "distributed_input_sink_manager.h"
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_fwk_kit.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "system_ability_definition.h"
|
||||
#include "screen_manager.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "distributed_input_collector.h"
|
||||
#include "distributed_input_sink_switch.h"
|
||||
@@ -41,9 +43,16 @@ REGISTER_SYSTEM_ABILITY_BY_ID(DistributedInputSinkManager, DISTRIBUTED_HARDWARE_
|
||||
DistributedInputSinkManager::DistributedInputSinkManager(int32_t saId, bool runOnCreate)
|
||||
: SystemAbility(saId, runOnCreate)
|
||||
{
|
||||
DHLOGI("DistributedInputSinkManager ctor!");
|
||||
inputTypes_ = DInputDeviceType::NONE;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::~DistributedInputSinkManager()
|
||||
{
|
||||
DHLOGI("DistributedInputSinkManager dtor!");
|
||||
projectWindowListener_ = nullptr;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::DInputSinkListener::DInputSinkListener(DistributedInputSinkManager *manager)
|
||||
{
|
||||
sinkManagerObj_ = manager;
|
||||
@@ -276,6 +285,13 @@ int32_t DistributedInputSinkManager::Init()
|
||||
|
||||
serviceRunningState_ = ServiceSinkRunningState::STATE_RUNNING;
|
||||
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
|
||||
if (dhFwkKit == nullptr) {
|
||||
DHLOGE("dhFwkKit obtain fail!");
|
||||
return ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL;
|
||||
}
|
||||
projectWindowListener_ = new ProjectWindowListener;
|
||||
dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, projectWindowListener_);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -301,6 +317,11 @@ int32_t DistributedInputSinkManager::Release()
|
||||
DistributedInputCollector::GetInstance().Release();
|
||||
|
||||
serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START;
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
|
||||
if (dhFwkKit != nullptr && projectWindowListener_ != nullptr) {
|
||||
DHLOGI("UnPublish ProjectWindowListener");
|
||||
dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, projectWindowListener_);
|
||||
}
|
||||
DHLOGI("exit dinput sink sa.");
|
||||
SetSinkProcessExit();
|
||||
|
||||
@@ -349,6 +370,154 @@ void DistributedInputSinkManager::SetInputTypes(const uint32_t& inputTypes)
|
||||
inputTypes_ = static_cast<DInputDeviceType>(inputTypes);
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::ProjectWindowListener::ProjectWindowListener()
|
||||
{
|
||||
DHLOGI("ProjectWindowListener ctor!");
|
||||
std::lock_guard<std::mutex> lock(handleScreenMutex_);
|
||||
if (screen_ == nullptr) {
|
||||
std::vector<sptr<Rosen::Screen>> screens = Rosen::ScreenManager::GetInstance().GetAllScreens();
|
||||
screen_ = screens[SCREEN_ID_DEFAULT];
|
||||
}
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::ProjectWindowListener::~ProjectWindowListener()
|
||||
{
|
||||
DHLOGI("ProjectWindowListener dtor!");
|
||||
std::lock_guard<std::mutex> lock(handleScreenMutex_);
|
||||
screen_ = nullptr;
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::ProjectWindowListener::OnMessage(const DHTopic topic, const std::string& message)
|
||||
{
|
||||
std::string srcDeviceId = "";
|
||||
uint64_t srcWinId = 0;
|
||||
SinkScreenInfo sinkScreenInfo = {};
|
||||
int32_t parseRes = ParseMessage(message, srcDeviceId, srcWinId, sinkScreenInfo);
|
||||
if (parseRes != DH_SUCCESS) {
|
||||
DHLOGE("message parse failed!");
|
||||
return;
|
||||
}
|
||||
int32_t saveRes = UpdateSinkScreenInfoCache(srcDeviceId, srcWinId, sinkScreenInfo);
|
||||
if (saveRes != DH_SUCCESS) {
|
||||
DHLOGE("Save sink screen info failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkManager::ProjectWindowListener::ParseMessage(const std::string& message,
|
||||
std::string& srcDeviceId, uint64_t& srcWinId, SinkScreenInfo& sinkScreenInfo)
|
||||
{
|
||||
nlohmann::json jsonObj = nlohmann::json::parse(message, nullptr, false);
|
||||
if (jsonObj.is_discarded()) {
|
||||
DHLOGE("jsonObj parse failed!");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
if (!IsString(jsonObj, SOURCE_DEVICE_ID)) {
|
||||
DHLOGE("sourceDevId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
srcDeviceId = jsonObj[SOURCE_DEVICE_ID].get<std::string>();
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkScreenInfo.sinkWinShowY = jsonObj[SINK_WINDOW_SHOW_Y].get<std::uint32_t>();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkManager::ProjectWindowListener::UpdateSinkScreenInfoCache(const std::string& srcDevId,
|
||||
const uint64_t srcWinId, const SinkScreenInfo& sinkScreenInfoTmp)
|
||||
{
|
||||
std::string srcScreenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(srcDevId, srcWinId);
|
||||
SinkScreenInfo sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(srcScreenInfoKey);
|
||||
sinkScreenInfo.sinkShowWinId = sinkScreenInfoTmp.sinkShowWinId;
|
||||
sinkScreenInfo.sinkProjShowWidth = sinkScreenInfoTmp.sinkProjShowWidth;
|
||||
sinkScreenInfo.sinkProjShowHeight = sinkScreenInfoTmp.sinkProjShowHeight;
|
||||
sinkScreenInfo.sinkWinShowX = sinkScreenInfoTmp.sinkWinShowX;
|
||||
sinkScreenInfo.sinkWinShowY = sinkScreenInfoTmp.sinkWinShowY;
|
||||
sinkScreenInfo.sinkShowWidth = GetScreenWidth();
|
||||
sinkScreenInfo.sinkShowHeight = GetScreenHeight();
|
||||
LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo;
|
||||
sinkScreenInfo.sinkPhyWidth = info.absMtPositionXMax + 1;
|
||||
sinkScreenInfo.sinkPhyHeight = info.absMtPositionYMax + 1;
|
||||
DHLOGI("sinkShowWinId: %d, sinkProjShowWidth: %d, sinkProjShowHeight: %d, sinkWinShowX: %d, sinkWinShowY: %d,"
|
||||
"sinkShowWidth: %d, sinkShowHeight: %d, sinkPhyWidth: %d, sinkPhyHeight: %d", sinkScreenInfo.sinkShowWinId,
|
||||
sinkScreenInfo.sinkProjShowWidth, sinkScreenInfo.sinkProjShowHeight, sinkScreenInfo.sinkWinShowX,
|
||||
sinkScreenInfo.sinkWinShowY, sinkScreenInfo.sinkShowWidth, sinkScreenInfo.sinkShowHeight,
|
||||
sinkScreenInfo.sinkPhyWidth, sinkScreenInfo.sinkPhyHeight);
|
||||
return DInputContext::GetInstance().UpdateSinkScreenInfo(srcScreenInfoKey, sinkScreenInfo);
|
||||
}
|
||||
|
||||
uint32_t DistributedInputSinkManager::ProjectWindowListener::GetScreenWidth()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(handleScreenMutex_);
|
||||
if (screen_ == nullptr) {
|
||||
DHLOGE("screen is nullptr!");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
return screen_->GetWidth();
|
||||
}
|
||||
|
||||
uint32_t DistributedInputSinkManager::ProjectWindowListener::GetScreenHeight()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(handleScreenMutex_);
|
||||
if (screen_ == nullptr) {
|
||||
DHLOGE("screen is nullptr!");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
return screen_->GetHeight();
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkManager::NotifyStartDScreen(const SrcScreenInfo& srcScreenInfo)
|
||||
{
|
||||
DHLOGI("NotifyStartDScreen start!");
|
||||
std::string screenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(srcScreenInfo.devId,
|
||||
srcScreenInfo.sourceWinId);
|
||||
SinkScreenInfo sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(screenInfoKey);
|
||||
sinkScreenInfo.srcScreenInfo = srcScreenInfo;
|
||||
DHLOGI("OnRemoteRequest the data: devId: %s, sourceWinId: %d, sourceWinWidth: %d, sourceWinHeight: %d,"
|
||||
"sourcePhyId: %s, sourcePhyFd: %d, sourcePhyWidth: %d, sourcePhyHeight: %d",
|
||||
GetAnonyString(srcScreenInfo.devId).c_str(), srcScreenInfo.sourceWinId, srcScreenInfo.sourceWinWidth,
|
||||
srcScreenInfo.sourceWinHeight, GetAnonyString(srcScreenInfo.sourcePhyId).c_str(), srcScreenInfo.sourcePhyFd,
|
||||
srcScreenInfo.sourcePhyWidth, srcScreenInfo.sourcePhyHeight);
|
||||
return DInputContext::GetInstance().UpdateSinkScreenInfo(screenInfoKey, sinkScreenInfo);
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkManager::NotifyStopDScreen(const std::string& srcScreenInfoKey)
|
||||
{
|
||||
DHLOGI("NotifyStopDScreen start, srcScreenInfoKey: %s", GetAnonyString(srcScreenInfoKey).c_str());
|
||||
if (srcScreenInfoKey.empty()) {
|
||||
DHLOGE("srcScreenInfoKey is empty, srcScreenInfoKey: %s", GetAnonyString(srcScreenInfoKey).c_str());
|
||||
return ERR_DH_INPUT_SERVER_SINK_SCREEN_INFO_IS_EMPTY;
|
||||
}
|
||||
return DInputContext::GetInstance().RemoveSinkScreenInfo(srcScreenInfoKey);
|
||||
}
|
||||
|
||||
int32_t DistributedInputSinkManager::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DistributedInputSinkManager Dump.");
|
||||
|
||||
@@ -48,6 +48,10 @@ ohos_unittest("distributed_input_sinkmanager_test") {
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"//foundation/window/window_manager/interfaces/innerkits/dm",
|
||||
"//foundation/window/window_manager/utils/include/",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -91,6 +95,9 @@ ohos_unittest("distributed_input_sinkmanager_test") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+3
@@ -31,6 +31,8 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -56,6 +58,7 @@ 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",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+3
@@ -28,6 +28,8 @@ ohos_shared_library("libdinput_inject") {
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -53,6 +55,7 @@ ohos_shared_library("libdinput_inject") {
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -36,12 +36,19 @@ public:
|
||||
int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor);
|
||||
void StartInjectThread();
|
||||
void StopInjectThread();
|
||||
std::string GenerateVirtualTouchScreenDHId(const uint64_t sourceWinId, const uint32_t sourceWinWidth,
|
||||
const uint32_t sourceWinHeight);
|
||||
int32_t CreateVirtualTouchScreenNode(const std::string& devId, const std::string& dhId, const uint64_t srcWinId,
|
||||
const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight);
|
||||
int32_t RemoveVirtualTouchScreenNode(const std::string& dhId);
|
||||
int32_t GetVirtualTouchScreenFd();
|
||||
|
||||
private:
|
||||
DistributedInputInject();
|
||||
~DistributedInputInject();
|
||||
|
||||
std::unique_ptr<DistributedInputNodeManager> inputNodeManager_;
|
||||
std::mutex inputNodeManagerMutex_;
|
||||
|
||||
// The event queue.
|
||||
static const int EVENT_BUFFER_SIZE = 16;
|
||||
|
||||
@@ -44,6 +44,10 @@ public:
|
||||
int32_t CloseDeviceLocked(const std::string& dhId);
|
||||
void StartInjectThread();
|
||||
void StopInjectThread();
|
||||
int32_t CreateVirtualTouchScreenNode(const std::string& devId, const std::string& dhId, const uint64_t srcWinId,
|
||||
const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight);
|
||||
int32_t RemoveVirtualTouchScreenNode(const std::string& dhId);
|
||||
int32_t GetVirtualTouchScreenFd();
|
||||
|
||||
private:
|
||||
void AddDeviceLocked(const std::string& dhId, std::unique_ptr<VirtualDevice> device);
|
||||
@@ -62,6 +66,7 @@ private:
|
||||
std::condition_variable conditionVariable_;
|
||||
std::queue<std::shared_ptr<RawEvent>> injectQueue_;
|
||||
std::unique_ptr<InputHub> inputHub_;
|
||||
int32_t virtualTouchScreenFd_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
bool SetUp(const std::string& devId, const std::string& dhId);
|
||||
bool InjectInputEvent(const input_event& event);
|
||||
void SetNetWorkId(const std::string netWorkId);
|
||||
int32_t GetFd();
|
||||
|
||||
protected:
|
||||
VirtualDevice();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "dh_utils_tool.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
@@ -29,12 +30,16 @@ namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
DistributedInputInject::DistributedInputInject()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
inputNodeManager_ = std::make_unique<DistributedInputNodeManager>();
|
||||
}
|
||||
|
||||
DistributedInputInject::~DistributedInputInject()
|
||||
{
|
||||
DHLOGI("~DistributedInputInject");
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
inputNodeManager_.reset();
|
||||
inputNodeManager_ = nullptr;
|
||||
}
|
||||
|
||||
DistributedInputInject &DistributedInputInject::GetInstance()
|
||||
@@ -48,7 +53,7 @@ int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& d
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s",
|
||||
__func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
|
||||
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the DistributedInputNodeManager is null\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
|
||||
@@ -64,6 +69,7 @@ int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string&
|
||||
{
|
||||
DHLOGI("%s called, deviceId: %s, dhId: %s",
|
||||
__func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the DistributedInputNodeManager is null\n");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
|
||||
@@ -98,8 +104,9 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::st
|
||||
|
||||
int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("the DistributedInputNodeManager is null\n");
|
||||
DHLOGE("the DistributedInputNodeManager is null");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
|
||||
}
|
||||
DHLOGI("RegisterDistributedEvent start %zu\n", bufferSize);
|
||||
@@ -111,6 +118,7 @@ int32_t DistributedInputInject::RegisterDistributedEvent(RawEvent* buffer, size_
|
||||
|
||||
void DistributedInputInject::StartInjectThread()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ != nullptr) {
|
||||
inputNodeManager_->StartInjectThread();
|
||||
}
|
||||
@@ -118,10 +126,50 @@ void DistributedInputInject::StartInjectThread()
|
||||
|
||||
void DistributedInputInject::StopInjectThread()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ != nullptr) {
|
||||
inputNodeManager_->StopInjectThread();
|
||||
}
|
||||
}
|
||||
|
||||
std::string DistributedInputInject::GenerateVirtualTouchScreenDHId(const uint64_t sourceWinId,
|
||||
const uint32_t sourceWinWidth, const uint32_t sourceWinHeight)
|
||||
{
|
||||
std::string uniqueInfo = GetLocalNetworkId() + std::to_string(sourceWinId) +
|
||||
std::to_string(sourceWinWidth) + std::to_string(sourceWinHeight);
|
||||
return DH_ID_PREFIX + Sha256(uniqueInfo);
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::CreateVirtualTouchScreenNode(const std::string& devId, const std::string& dhId,
|
||||
const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("inputNodeManager is nullptr");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
|
||||
}
|
||||
return inputNodeManager_->CreateVirtualTouchScreenNode(devId, dhId, srcWinId, sourcePhyWidth, sourcePhyHeight);
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::RemoveVirtualTouchScreenNode(const std::string& dhId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("inputNodeManager is nullptr");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL;
|
||||
}
|
||||
return inputNodeManager_->RemoveVirtualTouchScreenNode(dhId);
|
||||
}
|
||||
|
||||
int32_t DistributedInputInject::GetVirtualTouchScreenFd()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
|
||||
if (inputNodeManager_ == nullptr) {
|
||||
DHLOGE("inputNodeManager is nullptr");
|
||||
return UNINIT_FD_VALUE;
|
||||
}
|
||||
return inputNodeManager_->GetVirtualTouchScreenFd();
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -114,8 +114,43 @@ int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std::
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::string& devId, const std::string& dhId,
|
||||
const uint64_t srcWinId, const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight)
|
||||
{
|
||||
std::unique_lock<std::mutex> my_lock(operationMutex_);
|
||||
std::unique_ptr<VirtualDevice> device;
|
||||
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<VirtualTouchScreen>(info.deviceInfo, info, sourcePhyWidth - 1, sourcePhyHeight - 1);
|
||||
if (device == nullptr) {
|
||||
DHLOGE("could not create new virtual touch Screen");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
virtualTouchScreenFd_ = device->GetFd();
|
||||
AddDeviceLocked(dhId, std::move(device));
|
||||
DHLOGI("CreateVirtualTouchScreenNode end, dhId: %s", GetAnonyString(dhId).c_str());
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputNodeManager::RemoveVirtualTouchScreenNode(const std::string& dhId)
|
||||
{
|
||||
return CloseDeviceLocked(dhId);
|
||||
}
|
||||
|
||||
int32_t DistributedInputNodeManager::GetVirtualTouchScreenFd()
|
||||
{
|
||||
return virtualTouchScreenFd_;
|
||||
}
|
||||
|
||||
void DistributedInputNodeManager::AddDeviceLocked(const std::string& dhId, std::unique_ptr<VirtualDevice> device)
|
||||
{
|
||||
DHLOGI("dhId=%s", GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
|
||||
auto [dev_it, inserted] = virtualDeviceMap_.insert_or_assign(dhId, std::move(device));
|
||||
if (!inserted) {
|
||||
@@ -129,6 +164,7 @@ int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId)
|
||||
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
|
||||
std::map<std::string, std::unique_ptr<VirtualDevice>>::iterator iter = virtualDeviceMap_.find(dhId);
|
||||
if (iter != virtualDeviceMap_.end()) {
|
||||
DHLOGI("%s called success, dhId=%s", __func__, GetAnonyString(dhId).c_str());
|
||||
virtualDeviceMap_.erase(iter);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ bool VirtualDevice::SetPhys(const std::string deviceName)
|
||||
bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId)
|
||||
{
|
||||
fd_ = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
|
||||
DHLOGI("open fd %d", fd_);
|
||||
if (fd_ < 0) {
|
||||
DHLOGE("Failed to open uinput %s", __func__);
|
||||
return false;
|
||||
@@ -133,12 +134,13 @@ bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId)
|
||||
DHLOGE("Unable to create input device : %s", __func__);
|
||||
return false;
|
||||
}
|
||||
DHLOGI("create fd %d", fd_);
|
||||
|
||||
char sysfs_device_name[16];
|
||||
if (ioctl(fd_, UI_GET_SYSNAME(sizeof(sysfs_device_name)), sysfs_device_name) < 0) {
|
||||
DHLOGE("Unable to get input device name: %s", __func__);
|
||||
}
|
||||
DHLOGI("get input device name: %s", GetAnonyString(sysfs_device_name).c_str());
|
||||
DHLOGI("get input device name: %s, fd: %d", GetAnonyString(sysfs_device_name).c_str(), fd_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -162,6 +164,11 @@ void VirtualDevice::SetNetWorkId(const std::string netWorkId)
|
||||
netWorkId_.append(netWorkId);
|
||||
}
|
||||
|
||||
int32_t VirtualDevice::GetFd()
|
||||
{
|
||||
return fd_;
|
||||
}
|
||||
|
||||
void VirtualDevice::RecordEventLog(const input_event& event)
|
||||
{
|
||||
std::string eventType = "";
|
||||
|
||||
@@ -45,6 +45,8 @@ ohos_unittest("distributed_input_inner_sourceinject_test") {
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -80,6 +82,7 @@ ohos_unittest("distributed_input_inner_sourceinject_test") {
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+4
@@ -20,6 +20,7 @@ ohos_shared_library("libdinput_source") {
|
||||
"include",
|
||||
"${frameworks_path}/include",
|
||||
"${innerkits_path}/include",
|
||||
"${innerkits_path}/include/ipc",
|
||||
"${innerkits_path}/src",
|
||||
"${ipc_path}/include",
|
||||
"${ipc_path}/src",
|
||||
@@ -38,6 +39,8 @@ ohos_shared_library("libdinput_source") {
|
||||
"//third_party/json/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -88,6 +91,7 @@ ohos_shared_library("libdinput_source") {
|
||||
"//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DISRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H
|
||||
#define DISRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H
|
||||
#ifndef DISTRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H
|
||||
#define DISTRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H
|
||||
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
@@ -23,12 +23,16 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "dinput_context.h"
|
||||
#include "event_handler.h"
|
||||
#include "ipublisher_listener.h"
|
||||
#include "publisher_listener_stub.h"
|
||||
#include "singleton.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_source_trans_callback.h"
|
||||
#include "distributed_input_node_manager.h"
|
||||
#include "distributed_input_source_stub.h"
|
||||
#include "distributed_input_source_event_handler.h"
|
||||
|
||||
@@ -69,7 +73,7 @@ typedef struct InputDeviceId {
|
||||
|
||||
public:
|
||||
DistributedInputSourceManager(int32_t saId, bool runOnCreate);
|
||||
~DistributedInputSourceManager() = default;
|
||||
~DistributedInputSourceManager();
|
||||
|
||||
void OnStart() override;
|
||||
|
||||
@@ -137,6 +141,27 @@ public:
|
||||
DistributedInputSourceManager *sourceManagerObj_;
|
||||
};
|
||||
|
||||
class StartDScreenListener : public PublisherListenerStub {
|
||||
public:
|
||||
StartDScreenListener();
|
||||
~StartDScreenListener();
|
||||
void OnMessage(const DHTopic topic, const std::string& message) override;
|
||||
|
||||
private:
|
||||
int32_t ParseMessage(const std::string& message, std::string& sinkDevId, SrcScreenInfo& srcScreenInfo);
|
||||
int32_t UpdateSrcScreenInfoCache(const SrcScreenInfo& TmpInfo);
|
||||
};
|
||||
|
||||
class StopDScreenListener : public PublisherListenerStub {
|
||||
public:
|
||||
StopDScreenListener();
|
||||
~StopDScreenListener();
|
||||
void OnMessage(const DHTopic topic, const std::string& message) override;
|
||||
|
||||
private:
|
||||
int32_t ParseMessage(const std::string& message, std::string& sinkDevId, uint64_t& sourceWinId);
|
||||
};
|
||||
|
||||
std::shared_ptr<DInputSourceManagerEventHandler> GetCallbackEventHandler()
|
||||
{
|
||||
return callBackHandler_;
|
||||
@@ -237,9 +262,11 @@ private:
|
||||
bool InitAuto();
|
||||
void handleStartServerCallback(const std::string& devId);
|
||||
std::mutex operationMutex_;
|
||||
sptr<StartDScreenListener> startDScreenListener_ = nullptr;
|
||||
sptr<StopDScreenListener> stopDScreenListener_ = nullptr;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H
|
||||
#endif // DISTRIBUTED_INPUT_SOURCE_MANAGER_SERVICE_H
|
||||
|
||||
@@ -29,11 +29,15 @@
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_hitrace.h"
|
||||
#include "dinput_sa_process_state.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "distributed_hardware_fwk_kit.h"
|
||||
#include "distributed_input_client.h"
|
||||
#include "distributed_input_inject.h"
|
||||
#include "distributed_input_source_transport.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "hisysevent_util.h"
|
||||
#include "hidumper.h"
|
||||
#include "ipublisher_listener.h"
|
||||
#include "white_list_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -44,6 +48,14 @@ REGISTER_SYSTEM_ABILITY_BY_ID(DistributedInputSourceManager, DISTRIBUTED_HARDWAR
|
||||
DistributedInputSourceManager::DistributedInputSourceManager(int32_t saId, bool runOnCreate)
|
||||
: SystemAbility(saId, runOnCreate)
|
||||
{
|
||||
DHLOGI("DistributedInputSourceManager ctor!");
|
||||
}
|
||||
|
||||
DistributedInputSourceManager::~DistributedInputSourceManager()
|
||||
{
|
||||
DHLOGI("DistributedInputSourceManager dtor!");
|
||||
startDScreenListener_ = nullptr;
|
||||
stopDScreenListener_ = nullptr;
|
||||
}
|
||||
|
||||
DistributedInputSourceManager::DInputSourceListener::DInputSourceListener(DistributedInputSourceManager *manager)
|
||||
@@ -495,6 +507,16 @@ int32_t DistributedInputSourceManager::Init()
|
||||
DistributedInputSourceTransport::GetInstance().RegisterSourceRespCallback(statuslistener_);
|
||||
|
||||
serviceRunningState_ = ServiceSourceRunningState::STATE_RUNNING;
|
||||
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
|
||||
if (dhFwkKit == nullptr) {
|
||||
DHLOGE("dhFwkKit obtain fail!");
|
||||
return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL;
|
||||
}
|
||||
startDScreenListener_ = new StartDScreenListener;
|
||||
stopDScreenListener_ = new StopDScreenListener;
|
||||
dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_START_DSCREEN, startDScreenListener_);
|
||||
dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_STOP_DSCREEN, stopDScreenListener_);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -538,6 +560,12 @@ int32_t DistributedInputSourceManager::Release()
|
||||
callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
|
||||
|
||||
serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START;
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
|
||||
if (dhFwkKit != nullptr && startDScreenListener_ != nullptr && stopDScreenListener_ != nullptr) {
|
||||
DHLOGI("UnPublish StartDScreenListener and StopDScreenListener");
|
||||
dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_START_DSCREEN, startDScreenListener_);
|
||||
dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_STOP_DSCREEN, stopDScreenListener_);
|
||||
}
|
||||
DHLOGI("exit dinput source sa.");
|
||||
SetSourceProcessExit();
|
||||
return DH_SUCCESS;
|
||||
@@ -1179,6 +1207,172 @@ void DistributedInputSourceManager::DInputSourceListener::RecordEventLog(int64_t
|
||||
eventType.c_str(), code, value, path.c_str(), when);
|
||||
}
|
||||
|
||||
DistributedInputSourceManager::StartDScreenListener::StartDScreenListener()
|
||||
{
|
||||
DHLOGI("StartDScreenListener ctor!");
|
||||
}
|
||||
|
||||
DistributedInputSourceManager::StartDScreenListener::~StartDScreenListener()
|
||||
{
|
||||
DHLOGI("StartDScreenListener dtor!");
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::StartDScreenListener::OnMessage(const DHTopic topic, const std::string& message)
|
||||
{
|
||||
DHLOGI("StartDScreenListener OnMessage!");
|
||||
std::string sinkDevId = "";
|
||||
SrcScreenInfo srcScreenInfo = {};
|
||||
int32_t parseRes = ParseMessage(message, sinkDevId, srcScreenInfo);
|
||||
if (parseRes != DH_SUCCESS) {
|
||||
DHLOGE("Parse message failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string srcDevId = GetLocalNetworkId();
|
||||
std::string virtualTouchScreenDHId = DistributedInputInject::GetInstance().GenerateVirtualTouchScreenDHId(
|
||||
srcScreenInfo.sourceWinId, srcScreenInfo.sourceWinWidth, srcScreenInfo.sourceWinHeight);
|
||||
int32_t createNodeRes = DistributedInputInject::GetInstance().CreateVirtualTouchScreenNode(srcDevId,
|
||||
virtualTouchScreenDHId, srcScreenInfo.sourceWinId, srcScreenInfo.sourceWinWidth,
|
||||
srcScreenInfo.sourceWinHeight);
|
||||
if (createNodeRes != DH_SUCCESS) {
|
||||
DHLOGE("Create virtual touch screen Node failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t cacheRes = UpdateSrcScreenInfoCache(srcScreenInfo);
|
||||
if (cacheRes != DH_SUCCESS) {
|
||||
DHLOGE("Update SrcScreenInfo cache failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t rpcRes = DistributedInputClient::GetInstance().NotifyStartDScreen(sinkDevId, srcDevId,
|
||||
srcScreenInfo.sourceWinId);
|
||||
if (rpcRes != DH_SUCCESS) {
|
||||
DHLOGE("Rpc invoke failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceManager::StartDScreenListener::ParseMessage(const std::string& message,
|
||||
std::string& sinkDevId, SrcScreenInfo& srcScreenInfo)
|
||||
{
|
||||
nlohmann::json jsonObj = nlohmann::json::parse(message, nullptr, false);
|
||||
if (jsonObj.is_discarded()) {
|
||||
DHLOGE("jsonObj parse failed!");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
if (!IsString(jsonObj, SINK_DEVICE_ID)) {
|
||||
DHLOGE("devId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkDevId = jsonObj[SINK_DEVICE_ID].get<std::string>();
|
||||
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)) {
|
||||
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)) {
|
||||
DHLOGE("sourceWinHeight key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
srcScreenInfo.sourceWinHeight = jsonObj[SOURCE_WINDOW_HEIGHT].get<std::uint32_t>();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceManager::StartDScreenListener::UpdateSrcScreenInfoCache(const SrcScreenInfo& TmpInfo)
|
||||
{
|
||||
std::string srcDevId = GetLocalNetworkId();
|
||||
std::string srcScreenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(srcDevId, TmpInfo.sourceWinId);
|
||||
SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(srcScreenInfoKey);
|
||||
srcScreenInfo.devId = srcDevId;
|
||||
srcScreenInfo.sourceWinId = TmpInfo.sourceWinId;
|
||||
srcScreenInfo.sourceWinWidth = TmpInfo.sourceWinWidth;
|
||||
srcScreenInfo.sourceWinHeight = TmpInfo.sourceWinHeight;
|
||||
srcScreenInfo.sourcePhyId = DistributedInputInject::GetInstance().GenerateVirtualTouchScreenDHId(
|
||||
srcScreenInfo.sourceWinId, srcScreenInfo.sourceWinWidth, srcScreenInfo.sourceWinHeight);
|
||||
srcScreenInfo.sourcePhyFd = DistributedInputInject::GetInstance().GetVirtualTouchScreenFd();
|
||||
srcScreenInfo.sourcePhyWidth = TmpInfo.sourceWinWidth;
|
||||
srcScreenInfo.sourcePhyHeight = TmpInfo.sourceWinHeight;
|
||||
DHLOGI("StartDScreenListener UpdateSrcScreenInfo the data: devId: %s, sourceWinId: %d, sourceWinWidth: %d,"
|
||||
"sourceWinHeight: %d, sourcePhyId: %s, sourcePhyFd: %d, sourcePhyWidth: %d, sourcePhyHeight: %d",
|
||||
GetAnonyString(srcScreenInfo.devId).c_str(), srcScreenInfo.sourceWinId, srcScreenInfo.sourceWinWidth,
|
||||
srcScreenInfo.sourceWinHeight, GetAnonyString(srcScreenInfo.sourcePhyId).c_str(), srcScreenInfo.sourcePhyFd,
|
||||
srcScreenInfo.sourcePhyWidth, srcScreenInfo.sourcePhyHeight);
|
||||
return DInputContext::GetInstance().UpdateSrcScreenInfo(srcScreenInfoKey, srcScreenInfo);
|
||||
}
|
||||
|
||||
DistributedInputSourceManager::StopDScreenListener::StopDScreenListener()
|
||||
{
|
||||
DHLOGI("StopDScreenListener ctor!");
|
||||
}
|
||||
|
||||
DistributedInputSourceManager::StopDScreenListener::~StopDScreenListener()
|
||||
{
|
||||
DHLOGI("StopDScreenListener dtor!");
|
||||
}
|
||||
|
||||
void DistributedInputSourceManager::StopDScreenListener::OnMessage(const DHTopic topic, const std::string& message)
|
||||
{
|
||||
DHLOGI("StopDScreenListener OnMessage!");
|
||||
std::string sinkDevId = "";
|
||||
uint64_t sourceWinId = 0;
|
||||
int32_t parseRes = ParseMessage(message, sinkDevId, sourceWinId);
|
||||
if (parseRes != DH_SUCCESS) {
|
||||
DHLOGE("Message parse failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string sourceDevId = GetLocalNetworkId();
|
||||
std::string screenInfoKey = DInputContext::GetInstance().GetScreenInfoKey(sourceDevId, sourceWinId);
|
||||
DHLOGI("screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
SrcScreenInfo srcScreenInfo = DInputContext::GetInstance().GetSrcScreenInfo(screenInfoKey);
|
||||
|
||||
int32_t removeNodeRes = DistributedInputInject::GetInstance().RemoveVirtualTouchScreenNode(
|
||||
srcScreenInfo.sourcePhyId);
|
||||
if (removeNodeRes != DH_SUCCESS) {
|
||||
DHLOGE("Remove virtual touch screen node failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t removeCacheRes = DInputContext::GetInstance().RemoveSrcScreenInfo(screenInfoKey);
|
||||
if (removeCacheRes != DH_SUCCESS) {
|
||||
DHLOGE("Remove src cache failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t rpcRes = DistributedInputClient::GetInstance().NotifyStopDScreen(sinkDevId, screenInfoKey);
|
||||
if (rpcRes != DH_SUCCESS) {
|
||||
DHLOGE("Rpc invoke failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceManager::StopDScreenListener::ParseMessage(const std::string& message,
|
||||
std::string& sinkDevId, uint64_t& sourceWinId)
|
||||
{
|
||||
nlohmann::json jsonObj = nlohmann::json::parse(message, nullptr, false);
|
||||
if (jsonObj.is_discarded()) {
|
||||
DHLOGE("jsonObj parse failed!");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
if (!IsString(jsonObj, SINK_DEVICE_ID)) {
|
||||
DHLOGE("sourceWinId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sinkDevId = jsonObj[SINK_DEVICE_ID].get<std::string>();
|
||||
if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) {
|
||||
DHLOGE("sourceWinId key is invalid");
|
||||
return ERR_DH_INPUT_JSON_PARSE_FAIL;
|
||||
}
|
||||
sourceWinId = jsonObj[SOURCE_WINDOW_ID].get<uint64_t>();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DistributedInputSourceManager::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
DHLOGI("DistributedInputSourceManager Dump.");
|
||||
|
||||
@@ -28,6 +28,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
|
||||
include_dirs = [
|
||||
"${innerkits_path}/include",
|
||||
"${innerkits_path}/ipc/include",
|
||||
"${innerkits_path}/src",
|
||||
"${ipc_path}/include",
|
||||
"${ipc_path}/src",
|
||||
@@ -50,6 +51,8 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -117,6 +120,8 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+6
@@ -33,6 +33,9 @@ ohos_shared_library("libdinput_sink_handler") {
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -52,6 +55,9 @@ ohos_shared_library("libdinput_sink_handler") {
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
"${services_sink_path}/sinkmanager:libdinput_sink",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -44,6 +44,10 @@ ohos_unittest("distributed_input_sink_handler_test") {
|
||||
"${fwk_utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${services_source_path}/inputinject/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -73,6 +77,8 @@ ohos_unittest("distributed_input_sink_handler_test") {
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
"${services_source_path}/sourcemanager:libdinput_source",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
Executable → Regular
+8
@@ -33,6 +33,10 @@ ohos_shared_library("libdinput_source_handler") {
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${utils_path}/include",
|
||||
"${services_source_path}/inputinject/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -52,6 +56,10 @@ ohos_shared_library("libdinput_source_handler") {
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
"${services_source_path}/sourcemanager:libdinput_source",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${distributedinput_path}/services/source/inputinject:libdinput_inject",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -44,6 +44,10 @@ ohos_unittest("distributed_input_source_handler_test") {
|
||||
"${fwk_utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${services_source_path}/inputinject/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -73,6 +77,8 @@ ohos_unittest("distributed_input_source_handler_test") {
|
||||
"${innerkits_path}:libdinput_sdk",
|
||||
"${services_source_path}/sourcemanager:libdinput_source",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -43,6 +43,10 @@ ohos_fuzztest("DistributedInputClientFuzzTest") {
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/common/utils/include",
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/utils/include/log",
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/utils/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${services_source_path}/inputinject/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
@@ -66,6 +70,8 @@ ohos_fuzztest("DistributedInputClientFuzzTest") {
|
||||
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
|
||||
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -43,6 +43,10 @@ ohos_fuzztest("DistributedInputKitFuzzTest") {
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/common/utils/include",
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/utils/include/log",
|
||||
"//foundation/distributedhardware/distributed_hardware_fwk/utils/include",
|
||||
"${utils_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"${services_source_path}/inputinject/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
@@ -66,6 +70,8 @@ ohos_fuzztest("DistributedInputKitFuzzTest") {
|
||||
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
|
||||
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
+5
@@ -20,6 +20,7 @@
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <refbase.h>
|
||||
|
||||
@@ -28,6 +29,9 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace {
|
||||
const uint32_t SLEEP_TIME_US = 100 * 1000;
|
||||
}
|
||||
void OpenInputSoftbusFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size <= 0)) {
|
||||
@@ -36,6 +40,7 @@ void OpenInputSoftbusFuzzTest(const uint8_t* data, size_t size)
|
||||
|
||||
std::string remoteDevId(reinterpret_cast<const char*>(data), size);
|
||||
|
||||
usleep(SLEEP_TIME_US);
|
||||
DistributedInput::DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(remoteDevId);
|
||||
DistributedInput::DistributedInputSourceTransport::GetInstance().CloseInputSoftbus(remoteDevId);
|
||||
}
|
||||
|
||||
+9
-1
@@ -25,6 +25,9 @@ ohos_shared_library("libdinput_utils") {
|
||||
"${utils_path}/include",
|
||||
"${common_path}/include",
|
||||
"${service_common}/include",
|
||||
"//third_party/json/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -38,11 +41,16 @@ ohos_shared_library("libdinput_utils") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
deps = [ "${fwk_utils_path}:distributedhardwareutils" ]
|
||||
deps = [
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"dsoftbus:softbus_client",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
@@ -18,12 +18,14 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "single_instance.h"
|
||||
|
||||
#include "distributed_hardware_fwk_kit.h"
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "input_hub.h"
|
||||
@@ -67,7 +69,7 @@ struct LocalTouchScreenInfo {
|
||||
|
||||
struct SrcScreenInfo {
|
||||
std::string devId = ""; // source device id
|
||||
std::string sourceWinId = ""; // source projection window id
|
||||
uint64_t sourceWinId = 0; // source projection window id
|
||||
uint32_t sourceWinWidth = 0; // source projection window width
|
||||
uint32_t sourceWinHeight = 0; // source projection window height
|
||||
std::string sourcePhyId = ""; // source virtual screen driver id
|
||||
@@ -90,7 +92,7 @@ struct SinkScreenInfo {
|
||||
uint32_t sinkShowHeight = 0; // sink show height
|
||||
uint32_t sinkPhyWidth = 0; // sink touch screen width
|
||||
uint32_t sinkPhyHeight = 0; // sink touch screen height
|
||||
std::string sinkShowWinId = ""; // sink show window id
|
||||
uint64_t sinkShowWinId = 0; // sink show window id
|
||||
uint32_t sinkWinShowX = 0; // sink show window x coordinate
|
||||
uint32_t sinkWinShowY = 0; // sink show window y coordinate
|
||||
uint32_t sinkProjShowWidth = 0; // sink show window width
|
||||
@@ -102,18 +104,20 @@ struct SinkScreenInfo {
|
||||
class DInputContext {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DInputContext);
|
||||
public:
|
||||
std::string GetScreenInfoKey(const std::string &devId, const std::string &sourceWinId);
|
||||
int32_t RemoveSinkScreenInfo(const std::string &sourceWinId);
|
||||
int32_t UpdateSinkScreenInfo(const std::string &sourceWinId, const SinkScreenInfo &sinkScreenInfo);
|
||||
SinkScreenInfo GetSinkScreenInfo(const std::string &sourceWinId);
|
||||
std::string GetScreenInfoKey(const std::string &devId, const uint64_t sourceWinId);
|
||||
int32_t RemoveSinkScreenInfo(const std::string &screenInfoKey);
|
||||
int32_t UpdateSinkScreenInfo(const std::string &screenInfoKey, const SinkScreenInfo &sinkScreenInfo);
|
||||
SinkScreenInfo GetSinkScreenInfo(const std::string &screenInfoKey);
|
||||
const std::unordered_map<std::string, SinkScreenInfo>& GetAllSinkScreenInfo();
|
||||
|
||||
int32_t RemoveSrcScreenInfo(const std::string &sourceWinId);
|
||||
int32_t UpdateSrcScreenInfo(const std::string &sourceWinId, const SrcScreenInfo &srcScreenInfo);
|
||||
SrcScreenInfo GetSrcScreenInfo(const std::string &sourceWinId);
|
||||
int32_t RemoveSrcScreenInfo(const std::string &screenInfoKey);
|
||||
int32_t UpdateSrcScreenInfo(const std::string &screenInfoKey, const SrcScreenInfo &srcScreenInfo);
|
||||
SrcScreenInfo GetSrcScreenInfo(const std::string &screenInfoKey);
|
||||
|
||||
void SetLocalTouchScreenInfo(const LocalTouchScreenInfo &localTouchScreenInfo);
|
||||
LocalTouchScreenInfo GetLocalTouchScreenInfo();
|
||||
std::shared_ptr<DistributedHardwareFwkKit> GetDHFwkKit();
|
||||
|
||||
private:
|
||||
int32_t CalculateTransformInfo(SinkScreenInfo &sinkScreenInfo);
|
||||
|
||||
@@ -121,12 +125,17 @@ private:
|
||||
DInputContext() = default;
|
||||
~DInputContext();
|
||||
|
||||
/* the key is Combination of sink's localDeviceId and windowId, the value is sinkScreenInfo */
|
||||
std::unordered_map<std::string, SinkScreenInfo> sinkScreenInfoMap_;
|
||||
|
||||
/* the key is Combination of source's localDeviceId and windowId, the value is sourceScreenInfo */
|
||||
std::unordered_map<std::string, SrcScreenInfo> srcScreenInfoMap_;
|
||||
LocalTouchScreenInfo localTouchScreenInfo_;
|
||||
std::mutex srcMapMutex_;
|
||||
std::mutex sinkMapMutex_;
|
||||
std::mutex localTouchScreenInfoMutex_;
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit_;
|
||||
std::mutex dhFwkKitMutex_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -31,8 +32,14 @@ struct DevInfo {
|
||||
};
|
||||
|
||||
DevInfo GetLocalDeviceInfo();
|
||||
std::string GetLocalNetworkId();
|
||||
uint64_t GetCurrentTime();
|
||||
std::string SetAnonyId(const std::string &message);
|
||||
/* 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 IsUint32(const nlohmann::json& jsonObj, const std::string& key);
|
||||
bool IsUint64(const nlohmann::json& jsonObj, const std::string& key);
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "dinput_context.h"
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "constants.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
@@ -30,22 +31,25 @@ DInputContext::~DInputContext()
|
||||
srcScreenInfoMap_.clear();
|
||||
}
|
||||
|
||||
std::string DInputContext::GetScreenInfoKey(const std::string &devId, const std::string &sourceWinId)
|
||||
std::string DInputContext::GetScreenInfoKey(const std::string &devId, const uint64_t sourceWinId)
|
||||
{
|
||||
return devId + RESOURCE_SEPARATOR + sourceWinId;
|
||||
DHLOGI("GetScreenInfoKey screenInfoKey: %s, sourceWinId: %d", GetAnonyString(devId).c_str(), sourceWinId);
|
||||
return devId + RESOURCE_SEPARATOR + std::to_string(sourceWinId);
|
||||
}
|
||||
|
||||
int32_t DInputContext::RemoveSinkScreenInfo(const std::string &sourceWinId)
|
||||
int32_t DInputContext::RemoveSinkScreenInfo(const std::string &screenInfoKey)
|
||||
{
|
||||
DHLOGI("RemoveSinkScreenInfo screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
std::lock_guard<std::mutex> lock(sinkMapMutex_);
|
||||
sinkScreenInfoMap_.erase(sourceWinId);
|
||||
sinkScreenInfoMap_.erase(screenInfoKey);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DInputContext::UpdateSinkScreenInfo(const std::string &sourceWinId, const SinkScreenInfo &sinkScreenInfo)
|
||||
int32_t DInputContext::UpdateSinkScreenInfo(const std::string &screenInfoKey, const SinkScreenInfo &sinkScreenInfo)
|
||||
{
|
||||
DHLOGI("UpdateSinkScreenInfo screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
std::lock_guard<std::mutex> lock(sinkMapMutex_);
|
||||
if (sinkScreenInfoMap_.count(sourceWinId) <= 0) {
|
||||
if (sinkScreenInfoMap_.count(screenInfoKey) <= 0) {
|
||||
DHLOGE("source window id not exist");
|
||||
return ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST;
|
||||
}
|
||||
@@ -55,20 +59,21 @@ int32_t DInputContext::UpdateSinkScreenInfo(const std::string &sourceWinId, cons
|
||||
DHLOGE("calculate transform infomation failed");
|
||||
}
|
||||
|
||||
sinkScreenInfoMap_[sourceWinId] = tmp;
|
||||
sinkScreenInfoMap_[screenInfoKey] = tmp;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
SinkScreenInfo DInputContext::GetSinkScreenInfo(const std::string &sourceWinId)
|
||||
SinkScreenInfo DInputContext::GetSinkScreenInfo(const std::string &screenInfoKey)
|
||||
{
|
||||
DHLOGI("GetSinkScreenInfo screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
std::lock_guard<std::mutex> lock(sinkMapMutex_);
|
||||
if (sinkScreenInfoMap_.count(sourceWinId) <= 0) {
|
||||
DHLOGE("source window id not exist");
|
||||
if (sinkScreenInfoMap_.count(screenInfoKey) <= 0) {
|
||||
DHLOGE("screenInfoKey not exist");
|
||||
SinkScreenInfo sinkScreenInfo;
|
||||
sinkScreenInfoMap_[sourceWinId] = sinkScreenInfo;
|
||||
sinkScreenInfoMap_[screenInfoKey] = sinkScreenInfo;
|
||||
}
|
||||
|
||||
return sinkScreenInfoMap_[sourceWinId];
|
||||
return sinkScreenInfoMap_[screenInfoKey];
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, SinkScreenInfo>& DInputContext::GetAllSinkScreenInfo()
|
||||
@@ -77,35 +82,38 @@ const std::unordered_map<std::string, SinkScreenInfo>& DInputContext::GetAllSink
|
||||
return sinkScreenInfoMap_;
|
||||
}
|
||||
|
||||
int32_t DInputContext::RemoveSrcScreenInfo(const std::string &sourceWinId)
|
||||
int32_t DInputContext::RemoveSrcScreenInfo(const std::string &screenInfoKey)
|
||||
{
|
||||
DHLOGI("RemoveSrcScreenInfo screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
std::lock_guard<std::mutex> lock(srcMapMutex_);
|
||||
srcScreenInfoMap_.erase(sourceWinId);
|
||||
srcScreenInfoMap_.erase(screenInfoKey);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DInputContext::UpdateSrcScreenInfo(const std::string &sourceWinId, const SrcScreenInfo &srcScreenInfo)
|
||||
int32_t DInputContext::UpdateSrcScreenInfo(const std::string &screenInfoKey, const SrcScreenInfo &srcScreenInfo)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(srcMapMutex_);
|
||||
if (srcScreenInfoMap_.count(sourceWinId) <= 0) {
|
||||
DHLOGI("UpdateSrcScreenInfo screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
if (srcScreenInfoMap_.count(screenInfoKey) <= 0) {
|
||||
DHLOGE("source window id not exist");
|
||||
return ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST;
|
||||
}
|
||||
|
||||
srcScreenInfoMap_[sourceWinId] = srcScreenInfo;
|
||||
srcScreenInfoMap_[screenInfoKey] = srcScreenInfo;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
SrcScreenInfo DInputContext::GetSrcScreenInfo(const std::string &sourceWinId)
|
||||
SrcScreenInfo DInputContext::GetSrcScreenInfo(const std::string &screenInfoKey)
|
||||
{
|
||||
DHLOGI("GetSrcScreenInfo screenInfoKey: %s", GetAnonyString(screenInfoKey).c_str());
|
||||
std::lock_guard<std::mutex> lock(srcMapMutex_);
|
||||
if (srcScreenInfoMap_.count(sourceWinId) <= 0) {
|
||||
if (srcScreenInfoMap_.count(screenInfoKey) <= 0) {
|
||||
DHLOGE("source window id not exist");
|
||||
SrcScreenInfo srcScreenInfo;
|
||||
srcScreenInfoMap_[sourceWinId] = srcScreenInfo;
|
||||
srcScreenInfoMap_[screenInfoKey] = srcScreenInfo;
|
||||
}
|
||||
|
||||
return srcScreenInfoMap_[sourceWinId];
|
||||
return srcScreenInfoMap_[screenInfoKey];
|
||||
}
|
||||
|
||||
void DInputContext::SetLocalTouchScreenInfo(const LocalTouchScreenInfo &localTouchScreenInfo)
|
||||
@@ -153,6 +161,15 @@ int32_t DInputContext::CalculateTransformInfo(SinkScreenInfo &sinkScreenInfo)
|
||||
sinkScreenInfo.transformInfo = transformInfo;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
std::shared_ptr<DistributedHardwareFwkKit> DInputContext::GetDHFwkKit()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dhFwkKitMutex_);
|
||||
if (dhFwkKit_ == nullptr) {
|
||||
dhFwkKit_ = std::make_shared<DistributedHardwareFwkKit>();
|
||||
}
|
||||
return dhFwkKit_;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -15,13 +15,20 @@
|
||||
|
||||
#include "dinput_utils_tool.h"
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <sys/time.h>
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "dinput_softbus_define.h"
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "anonymous_string.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
@@ -47,6 +54,14 @@ DevInfo GetLocalDeviceInfo()
|
||||
return devInfo;
|
||||
}
|
||||
|
||||
std::string GetLocalNetworkId()
|
||||
{
|
||||
if (GetLocalDeviceInfo().networkId.empty()) {
|
||||
DHLOGE("local networkId is empty!");
|
||||
}
|
||||
return GetLocalDeviceInfo().networkId;
|
||||
}
|
||||
|
||||
uint64_t GetCurrentTime()
|
||||
{
|
||||
struct timeval tv;
|
||||
@@ -61,18 +76,45 @@ std::string SetAnonyId(const std::string &message)
|
||||
DHLOGE("jsonObj parse failed!");
|
||||
return "";
|
||||
}
|
||||
if (IsString(jsonObj, DINPUT_SOFTBUS_KEY_DEVICE_ID)) {
|
||||
jsonObj[DINPUT_SOFTBUS_KEY_DEVICE_ID] = GetAnonyString(jsonObj[DINPUT_SOFTBUS_KEY_DEVICE_ID]);
|
||||
}
|
||||
if (IsInt32(jsonObj, DINPUT_SOFTBUS_KEY_SESSION_ID)) {
|
||||
jsonObj[DINPUT_SOFTBUS_KEY_SESSION_ID] = GetAnonyInt32(jsonObj[DINPUT_SOFTBUS_KEY_SESSION_ID]);
|
||||
}
|
||||
if (IsString(jsonObj, DESCRIPTOR)) {
|
||||
jsonObj[DESCRIPTOR] = GetAnonyString(jsonObj[DESCRIPTOR]);
|
||||
}
|
||||
return jsonObj.dump();
|
||||
}
|
||||
|
||||
nlohmann::json jsonStr = nlohmann::json::parse(message);
|
||||
if (jsonStr.contains(DINPUT_SOFTBUS_KEY_DEVICE_ID)) {
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = GetAnonyString(jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID]);
|
||||
}
|
||||
if (jsonStr.contains(DINPUT_SOFTBUS_KEY_SESSION_ID)) {
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = GetAnonyInt32(jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID]);
|
||||
}
|
||||
if (jsonStr.contains(DESCRIPTOR)) {
|
||||
jsonStr[DESCRIPTOR] = GetAnonyString(jsonStr[DESCRIPTOR]);
|
||||
}
|
||||
return jsonStr.dump();
|
||||
bool IsString(const nlohmann::json& jsonObj, const std::string& key)
|
||||
{
|
||||
bool res = jsonObj.contains(key) && jsonObj[key].is_string();
|
||||
DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid");
|
||||
return res;
|
||||
}
|
||||
|
||||
bool IsInt32(const nlohmann::json& jsonObj, const std::string& key)
|
||||
{
|
||||
bool res = jsonObj.contains(key) && jsonObj[key].is_number_integer() && INT32_MIN <= jsonObj[key] &&
|
||||
jsonObj[key] <= INT32_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 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 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;
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -34,6 +34,8 @@ ohos_unittest("distributed_input_utils_test") {
|
||||
"${utils_path}/include",
|
||||
"${utils_path}/test/unittest",
|
||||
"${common_path}/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
]
|
||||
|
||||
sources = [ "dinput_context_test.cpp" ]
|
||||
@@ -55,11 +57,13 @@ ohos_unittest("distributed_input_utils_test") {
|
||||
deps = [
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${fwk_interfaces_path}:libdhfwk_sdk",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"dsoftbus:softbus_client",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-DHILOG_ENABLE" ]
|
||||
|
||||
@@ -47,9 +47,9 @@ void DInputContextTest::TearDownTestCase()
|
||||
HWTEST_F(DInputContextTest, GetSourceWindId001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string devId = "hello";
|
||||
std::string sourceWinId = "hello";
|
||||
uint64_t sourceWinId = 1;
|
||||
std::string ret = DInputContext::GetInstance().GetScreenInfoKey(devId, sourceWinId);
|
||||
EXPECT_EQ("hello###hello", ret);
|
||||
EXPECT_EQ("hello###1", ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DInputContextTest, RemoveSinkScreenInfo001, testing::ext::TestSize.Level0)
|
||||
|
||||
Reference in New Issue
Block a user