修改超大源文件

Signed-off-by: litiangang4 <litiangang4@huawei.com>
This commit is contained in:
litiangang4
2023-08-28 18:04:39 +08:00
parent aeccffeabc
commit d366bfd308
14 changed files with 1246 additions and 1034 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ namespace DistributedInput {
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SIMULATION_EVENT_CALLBACK_ERR = -65037;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_DH_FWK_KIT_IS_NULL = -65038;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_NODE_LISTENER_CALLBACK_ERR = -65039;
constexpr int32_t ERR_DH_INPUT_SRC_MGR_SESSION_STATE_CB_IS_NULL = -65040;
constexpr int32_t ERR_DH_INPUT_SERVER_SOURCE_MANAGER_SESSION_STATE_CB_IS_NULL = -65040;
// handler error code
constexpr int32_t ERR_DH_INPUT_SINK_HANDLER_INIT_SINK_SA_FAIL = -66000;
@@ -569,7 +569,7 @@ int32_t DistributedInputSourceStub::OnRemoteRequest(
} else {
auto iter = memberFuncMap_.find(code);
if (iter != memberFuncMap_.end()) {
DistributedInputSourceFunc &func = iter->second;
const DistributedInputSourceFunc &func = iter->second;
return (this->*func)(data, reply);
}
}
@@ -251,7 +251,6 @@ int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSessio
return DH_SUCCESS;
}
int32_t UnregisterSessionStateCb();
void DInputSourceCallBackTest::TestDInputSourceCallBackStub::OnResult(const std::string &deviceId,
const std::string &strJson)
{
+2
View File
@@ -77,6 +77,8 @@ ohos_shared_library("libdinput_source") {
"${ipc_path}/src/unprepare_d_input_call_back_stub.cpp",
"${ipc_path}/src/unregister_d_input_call_back_proxy.cpp",
"${ipc_path}/src/unregister_d_input_call_back_stub.cpp",
"src/dinput_source_listener.cpp",
"src/dinput_source_manager_event_handler.cpp",
"src/distributed_input_source_event_handler.cpp",
"src/distributed_input_source_manager.cpp",
"src/distributed_input_source_sa_cli_mgr.cpp",
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DINPUT_SOURCE_LISTENER_H
#define DINPUT_SOURCE_LISTENER_H
#include <cstring>
#include <mutex>
#include <set>
#include <unistd.h>
#include <sys/types.h>
#include "event_handler.h"
#include "ipublisher_listener.h"
#include "publisher_listener_stub.h"
#include "singleton.h"
#include "constants_dinput.h"
#include "dinput_context.h"
#include "dinput_source_manager_callback.h"
#include "dinput_source_trans_callback.h"
#include "distributed_input_source_manager.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DistributedInputSourceManager;
class DInputSourceListener : public DInputSourceTransCallback {
public:
explicit DInputSourceListener(DistributedInputSourceManager *manager);
virtual ~DInputSourceListener();
void OnResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId,
bool result) override;
void OnResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) override;
void OnResponseUnprepareRemoteInput(const std::string deviceId, bool result) override;
void OnResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override;
void OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override;
void OnResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override;
void OnResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override;
void OnResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type,
const uint32_t code, const uint32_t value) override;
void OnReceivedEventRemoteInput(const std::string deviceId, const std::string &event) override;
void OnResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result,
const std::string &object) override;
void OnResponseRelayUnprepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result) override;
void OnReceiveRelayPrepareResult(int32_t status, const std::string &srcId, const std::string &sinkId) override;
void OnReceiveRelayUnprepareResult(int32_t status, const std::string &srcId,
const std::string &sinkId) override;
void OnReceiveRelayStartDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId,
const std::string &dhids) override;
void OnReceiveRelayStopDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId,
const std::string &dhids) override;
void OnReceiveRelayStartTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId,
uint32_t inputTypes) override;
void OnReceiveRelayStopTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId,
uint32_t inputTypes) override;
void RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string &path);
private:
DistributedInputSourceManager *sourceManagerObj_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // DINPUT_SOURCE_LISTENER_H
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H
#define DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H
#include <cstring>
#include <mutex>
#include <set>
#include <unistd.h>
#include <sys/types.h>
#include "event_handler.h"
#include "ipublisher_listener.h"
#include "publisher_listener_stub.h"
#include "singleton.h"
#include "constants_dinput.h"
#include "dinput_context.h"
#include "dinput_source_manager_callback.h"
#include "dinput_source_trans_callback.h"
#include "distributed_input_source_manager.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DistributedInputSourceManager;
class DInputSourceManagerEventHandler : public AppExecFwk::EventHandler {
public:
DInputSourceManagerEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
DistributedInputSourceManager *manager);
~DInputSourceManagerEventHandler() override;
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
private:
void NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStartTypeCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStopTypeCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayPrepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayUnprepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event);
using SourceEventFunc = void (DInputSourceManagerEventHandler::*)(
const AppExecFwk::InnerEvent::Pointer &event);
std::map<int32_t, SourceEventFunc> eventFuncMap_;
DistributedInputSourceManager *sourceManagerObj_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // DINPUT_SOURCE_MANAGER_EVENT_HANDLER_H
@@ -39,10 +39,14 @@
#include "distributed_input_source_sa_cli_mgr.h"
#include "distributed_input_source_stub.h"
#include "dinput_state.h"
#include "dinput_source_listener.h"
#include "dinput_source_manager_event_handler.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DInputSourceListener;
class DInputSourceManagerEventHandler;
using EventRunner = OHOS::AppExecFwk::EventRunner;
using EventHandler = OHOS::AppExecFwk::EventHandler;
enum class ServiceSourceRunningState { STATE_NOT_START, STATE_RUNNING };
@@ -189,42 +193,6 @@ public:
sptr<IUnregisterDInputCallback> callback);
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
class DInputSourceListener : public DInputSourceTransCallback {
public:
explicit DInputSourceListener(DistributedInputSourceManager *manager);
virtual ~DInputSourceListener();
void OnResponseRegisterDistributedHardware(const std::string deviceId, const std::string dhId,
bool result) override;
void OnResponsePrepareRemoteInput(const std::string deviceId, bool result, const std::string &object) override;
void OnResponseUnprepareRemoteInput(const std::string deviceId, bool result) override;
void OnResponseStartRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override;
void OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result) override;
void OnResponseStartRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override;
void OnResponseStopRemoteInputDhid(const std::string deviceId, const std::string &dhids, bool result) override;
void OnResponseKeyState(const std::string deviceId, const std::string &dhid, const uint32_t type,
const uint32_t code, const uint32_t value) override;
void OnReceivedEventRemoteInput(const std::string deviceId, const std::string &event) override;
void OnResponseRelayPrepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result,
const std::string &object) override;
void OnResponseRelayUnprepareRemoteInput(int32_t sessionId, const std::string &deviceId, bool result) override;
void OnReceiveRelayPrepareResult(int32_t status, const std::string &srcId, const std::string &sinkId) override;
void OnReceiveRelayUnprepareResult(int32_t status, const std::string &srcId,
const std::string &sinkId) override;
void OnReceiveRelayStartDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId,
const std::string &dhids) override;
void OnReceiveRelayStopDhidResult(int32_t status, const std::string &srcId, const std::string &sinkId,
const std::string &dhids) override;
void OnReceiveRelayStartTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId,
uint32_t inputTypes) override;
void OnReceiveRelayStopTypeResult(int32_t status, const std::string &srcId, const std::string &sinkId,
uint32_t inputTypes) override;
void RecordEventLog(int64_t when, int32_t type, int32_t code, int32_t value, const std::string &path);
private:
DistributedInputSourceManager *sourceManagerObj_;
};
class DInputSrcMgrListener : public DInputSourceManagerCallback {
public:
explicit DInputSrcMgrListener(DistributedInputSourceManager *manager);
@@ -234,43 +202,10 @@ public:
DistributedInputSourceManager *sourceManagerObj_;
};
class DInputSourceManagerEventHandler : public AppExecFwk::EventHandler {
public:
DInputSourceManagerEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
DistributedInputSourceManager *manager);
~DInputSourceManagerEventHandler() override;
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
private:
void NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStartTypeCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayStopTypeCallback(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayPrepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event);
void NotifyRelayUnprepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event);
using SourceEventFunc = void (DInputSourceManagerEventHandler::*)(
const AppExecFwk::InnerEvent::Pointer &event);
std::map<int32_t, SourceEventFunc> eventFuncMap_;
DistributedInputSourceManager *sourceManagerObj_;
};
class StartDScreenListener : public PublisherListenerStub {
public:
StartDScreenListener();
~StartDScreenListener() override;
StartDScreenListener() = default;
~StartDScreenListener() = default;
void OnMessage(const DHTopic topic, const std::string &message) override;
private:
@@ -280,8 +215,8 @@ public:
class StopDScreenListener : public PublisherListenerStub {
public:
StopDScreenListener();
~StopDScreenListener() override;
StopDScreenListener() = default;
~StopDScreenListener() = default;
void OnMessage(const DHTopic topic, const std::string &message) override;
private:
@@ -291,7 +226,7 @@ public:
class DeviceOfflineListener : public PublisherListenerStub {
public:
explicit DeviceOfflineListener(DistributedInputSourceManager *srcManagerContext);
~DeviceOfflineListener() override;
~DeviceOfflineListener() = default;
void OnMessage(const DHTopic topic, const std::string &message) override;
@@ -305,7 +240,7 @@ public:
class DScreenSourceSvrRecipient : public IRemoteObject::DeathRecipient {
public:
DScreenSourceSvrRecipient(const std::string &srcDevId, const std::string &sinkDevId, const uint64_t srcWinId);
~DScreenSourceSvrRecipient() override;
~DScreenSourceSvrRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
private:
@@ -349,6 +284,18 @@ public:
uint32_t GetAllInputTypesMap();
void ClearResourcesStatus();
public:
void RunRelayPrepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t status);
void RunRelayUnprepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t status);
void RunRelayStartDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t status,
const std::string &dhids);
void RunRelayStopDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t status,
const std::string &dhids);
void RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t status,
uint32_t inputTypes);
void RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t status,
uint32_t inputTypes);
private:
struct DInputClientRegistInfo {
std::string devId;
@@ -441,7 +388,7 @@ private:
ServiceSourceRunningState serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START;
DInputServerType isStartTrans_ = DInputServerType::NULL_SERVER_TYPE;
std::shared_ptr<DistributedInputSourceManager::DInputSourceListener> statuslistener_;
std::shared_ptr<DInputSourceListener> statuslistener_;
std::shared_ptr<DistributedInputSourceManager::DInputSrcMgrListener> srcMgrListener_;
std::vector<DInputClientRegistInfo> regCallbacks_;
@@ -483,17 +430,6 @@ private:
std::mutex syncNodeInfoMutex_;
std::map<std::string, std::set<BeRegNodeInfo>> syncNodeInfoMap_;
void RunRelayPrepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status);
void RunRelayUnprepareCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status);
void RunRelayStartDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status,
const std::string &dhids);
void RunRelayStopDhidCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status,
const std::string &dhids);
void RunRelayStartTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status,
uint32_t inputTypes);
void RunRelayStopTypeCallback(const std::string &srcId, const std::string &sinkId, const int32_t &status,
uint32_t inputTypes);
int32_t RelayStartRemoteInputByType(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
sptr<IStartDInputCallback> callback);
int32_t RelayStopRemoteInputByType(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes,
@@ -0,0 +1,540 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dinput_source_listener.h"
#include <algorithm>
#include <cinttypes>
#include <dlfcn.h>
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "nlohmann/json.hpp"
#include "string_ex.h"
#include "ipublisher_listener.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
#include "dinput_log.h"
#include "dinput_utils_tool.h"
#include "dinput_softbus_define.h"
#include "distributed_input_inject.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
DInputSourceListener::DInputSourceListener(DistributedInputSourceManager *manager)
{
sourceManagerObj_ = manager;
DHLOGI("DInputSourceListener init.");
}
DInputSourceListener::~DInputSourceListener()
{
sourceManagerObj_ = nullptr;
DHLOGI("DInputSourceListener destory.");
}
void DInputSourceListener::OnResponseRegisterDistributedHardware(
const std::string deviceId, const std::string dhId, bool result)
{
DHLOGI("OnResponseRegisterDistributedHardware called, deviceId: %s, "
"result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("OnResponseRegisterDistributedHardware sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunRegisterCallback(deviceId, dhId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
DHLOGE("OnResponseRegisterDistributedHardware GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_HWID] = dhId;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_RIGISTER_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponsePrepareRemoteInput(const std::string deviceId,
bool result, const std::string &object)
{
DHLOGI("OnResponsePrepareRemoteInput called, deviceId: %s, result: %s.",
GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("OnResponsePrepareRemoteInput sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunPrepareCallback(deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL, object);
DHLOGE("OnResponsePrepareRemoteInput GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_PREPARE_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseUnprepareRemoteInput(const std::string deviceId, bool result)
{
DHLOGI("OnResponseUnprepareRemoteInput called, deviceId: %s, "
"result: %s.", GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("OnResponseUnprepareRemoteInput sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunUnprepareCallback(deviceId,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
DHLOGE("OnResponseUnprepareRemoteInput GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_UNPREPARE_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseRelayPrepareRemoteInput(int32_t toSrcSessionId,
const std::string &deviceId, bool result, const std::string &object)
{
DHLOGI("OnResponseRelayPrepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result);
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
tmpJson[INPUT_SOURCEMANAGER_KEY_WHITELIST] = object;
tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseRelayUnprepareRemoteInput(int32_t toSrcSessionId,
const std::string &deviceId, bool result)
{
DHLOGI("OnResponseRelayUnprepareRemoteInput deviceId: %s, result: %d.", GetAnonyString(deviceId).c_str(), result);
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
tmpJson[INPUT_SOURCEMANAGER_KEY_SESSIONID] = toSrcSessionId;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseStartRemoteInput(
const std::string deviceId, const uint32_t inputTypes, bool result)
{
DHLOGI("OnResponseStartRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.",
GetAnonyString(deviceId).c_str(), inputTypes, result ? "success" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
sourceManagerObj_->RunStartCallback(deviceId, inputTypes,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
DHLOGE("GetCallbackEventHandler is null.");
return;
}
if (result) {
sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON);
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_START_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseStopRemoteInput(const std::string deviceId, const uint32_t inputTypes, bool result)
{
DHLOGI("OnResponseStopRemoteInput called, deviceId: %s, inputTypes: %d, result: %s.",
GetAnonyString(deviceId).c_str(), inputTypes, result ? "true" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("OnResponseStopRemoteInput sourceManagerObj_ is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("OnResponseStopRemoteInput GetCallbackEventHandler is null.");
sourceManagerObj_->RunStopCallback(deviceId, inputTypes,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_ITP] = inputTypes;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent = AppExecFwk::InnerEvent::Get(
DINPUT_SOURCE_MANAGER_STOP_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseStartRemoteInputDhid(
const std::string deviceId, const std::string &dhids, bool result)
{
DHLOGI("OnResponseStartRemoteInputDhid called, deviceId: %s, result: %s.",
GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("OnResponseStartRemoteInputDhid sourceManagerObj_ is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("OnResponseStartRemoteInputDhid GetCallbackEventHandler is null.");
sourceManagerObj_->RunStartDhidCallback(deviceId, dhids,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
return;
}
if (result) {
sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON);
}
std::vector<std::string> vecStr;
StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_IN, -1);
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_START_DHID_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseStopRemoteInputDhid(
const std::string deviceId, const std::string &dhids, bool result)
{
DHLOGI("OnResponseStopRemoteInputDhid called, deviceId: %s, result: %s.",
GetAnonyString(deviceId).c_str(), result ? "success" : "failed");
if (sourceManagerObj_ == nullptr) {
DHLOGE("OnResponseStopRemoteInputDhid sourceManagerObj_ is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("OnResponseStopRemoteInputDhid GetCallbackEventHandler is null.");
sourceManagerObj_->RunStopDhidCallback(deviceId, dhids,
ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL);
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids;
tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = result;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_STOP_DHID_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnResponseKeyState(const std::string deviceId,
const std::string &dhid, const uint32_t type, const uint32_t code, const uint32_t value)
{
DHLOGI("OnResponseKeyState called, deviceId: %s, dhid: %s.", GetAnonyString(deviceId).c_str(),
GetAnonyString(dhid).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, type, code, value);
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId;
tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhid;
tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = type;
tmpJson[INPUT_SOURCEMANAGER_KEY_CODE] = code;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = value;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_KEY_STATE_MSG, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnReceivedEventRemoteInput(
const std::string deviceId, const std::string &event)
{
nlohmann::json inputData = nlohmann::json::parse(event, nullptr, false);
if (inputData.is_discarded()) {
DHLOGE("inputData parse failed!");
return;
}
size_t jsonSize = inputData.size();
DHLOGI("OnReceivedEventRemoteInput called, deviceId: %s, json size:%d.",
GetAnonyString(deviceId).c_str(), jsonSize);
if (!inputData.is_array()) {
DHLOGE("inputData not vector!");
return;
}
RawEvent mEventBuffer[jsonSize];
int idx = 0;
for (auto it = inputData.begin(); it != inputData.end(); ++it) {
nlohmann::json oneData = (*it);
if (!IsInt64(oneData, INPUT_KEY_WHEN) || !IsUInt32(oneData, INPUT_KEY_TYPE) ||
!IsUInt32(oneData, INPUT_KEY_CODE) || !IsInt32(oneData, INPUT_KEY_VALUE) ||
!IsString(oneData, INPUT_KEY_DESCRIPTOR) || !IsString(oneData, INPUT_KEY_PATH)) {
DHLOGE("The key is invaild.");
continue;
}
mEventBuffer[idx].when = oneData[INPUT_KEY_WHEN];
mEventBuffer[idx].type = oneData[INPUT_KEY_TYPE];
mEventBuffer[idx].code = oneData[INPUT_KEY_CODE];
mEventBuffer[idx].value = oneData[INPUT_KEY_VALUE];
mEventBuffer[idx].descriptor = oneData[INPUT_KEY_DESCRIPTOR];
mEventBuffer[idx].path = oneData[INPUT_KEY_PATH];
RecordEventLog(oneData[INPUT_KEY_WHEN], oneData[INPUT_KEY_TYPE], oneData[INPUT_KEY_CODE],
oneData[INPUT_KEY_VALUE], oneData[INPUT_KEY_PATH]);
++idx;
}
DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer, jsonSize);
}
void DInputSourceListener::OnReceiveRelayPrepareResult(int32_t status,
const std::string &srcId, const std::string &sinkId)
{
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId;
tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnReceiveRelayUnprepareResult(int32_t status,
const std::string &srcId, const std::string &sinkId)
{
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId;
tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnReceiveRelayStartDhidResult(int32_t status,
const std::string &srcId, const std::string &sinkId, const std::string &dhids)
{
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId;
tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status;
tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnReceiveRelayStopDhidResult(int32_t status,
const std::string &srcId, const std::string &sinkId, const std::string &dhids)
{
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId;
tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status;
tmpJson[INPUT_SOURCEMANAGER_KEY_DHID] = dhids;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnReceiveRelayStartTypeResult(int32_t status,
const std::string &srcId, const std::string &sinkId, uint32_t inputTypes)
{
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId;
tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status;
tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = inputTypes;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::OnReceiveRelayStopTypeResult(int32_t status,
const std::string &srcId, const std::string &sinkId, uint32_t inputTypes)
{
DHLOGI("status:%d, srcId: %s, sinkId: %s.", status, GetAnonyString(srcId).c_str(), GetAnonyString(sinkId).c_str());
if (sourceManagerObj_ == nullptr) {
DHLOGE("sourceManagerObj is null.");
return;
}
if (sourceManagerObj_->GetCallbackEventHandler() == nullptr) {
DHLOGE("GetCallbackEventHandler is null.");
return;
}
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
tmpJson[INPUT_SOURCEMANAGER_KEY_SRC_DEVID] = srcId;
tmpJson[INPUT_SOURCEMANAGER_KEY_SINK_DEVID] = sinkId;
tmpJson[INPUT_SOURCEMANAGER_KEY_VALUE] = status;
tmpJson[INPUT_SOURCEMANAGER_KEY_TYPE] = inputTypes;
jsonArrayMsg->push_back(tmpJson);
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI, jsonArrayMsg, 0);
sourceManagerObj_->GetCallbackEventHandler()->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void DInputSourceListener::RecordEventLog(int64_t when, int32_t type, int32_t code,
int32_t value, const std::string &path)
{
std::string eventType = "";
switch (type) {
case EV_KEY:
eventType = "EV_KEY";
break;
case EV_REL:
eventType = "EV_REL";
break;
case EV_ABS:
eventType = "EV_ABS";
break;
default:
eventType = "other type";
break;
}
DHLOGD("3.E2E-Test Source softBus receive event, EventType: %s, Code: %d, Value: %d, Path: %s, When: %" PRId64 "",
eventType.c_str(), code, value, path.c_str(), when);
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,493 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dinput_source_manager_event_handler.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "nlohmann/json.hpp"
#include "string_ex.h"
#include "distributed_hardware_fwk_kit.h"
#include "ipublisher_listener.h"
#include "constants_dinput.h"
#include "dinput_errcode.h"
#include "dinput_log.h"
#include "dinput_utils_tool.h"
#include "dinput_softbus_define.h"
#include "distributed_input_source_transport.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
DInputSourceManagerEventHandler::DInputSourceManagerEventHandler(
const std::shared_ptr<AppExecFwk::EventRunner> &runner, DistributedInputSourceManager *manager)
: AppExecFwk::EventHandler(runner)
{
eventFuncMap_[DINPUT_SOURCE_MANAGER_RIGISTER_MSG] = &DInputSourceManagerEventHandler::NotifyRegisterCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG] = &DInputSourceManagerEventHandler::NotifyUnregisterCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_PREPARE_MSG] = &DInputSourceManagerEventHandler::NotifyPrepareCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_UNPREPARE_MSG] = &DInputSourceManagerEventHandler::NotifyUnprepareCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_START_MSG] = &DInputSourceManagerEventHandler::NotifyStartCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_STOP_MSG] = &DInputSourceManagerEventHandler::NotifyStopCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_START_DHID_MSG] = &DInputSourceManagerEventHandler::NotifyStartDhidCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_STOP_DHID_MSG] = &DInputSourceManagerEventHandler::NotifyStopDhidCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_KEY_STATE_MSG] = &DInputSourceManagerEventHandler::NotifyKeyStateCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_STARTSERVER_MSG] = &DInputSourceManagerEventHandler::NotifyStartServerCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN] =
&DInputSourceManagerEventHandler::NotifyRelayPrepareRemoteInput;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN] =
&DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_MMI] =
&DInputSourceManagerEventHandler::NotifyRelayPrepareCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_MMI] =
&DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI] =
&DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STOPDHID_RESULT_MMI] =
&DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STARTTYPE_RESULT_MMI] =
&DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback;
eventFuncMap_[DINPUT_SOURCE_MANAGER_RELAY_STOPTYPE_RESULT_MMI] =
&DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback;
sourceManagerObj_ = manager;
}
DInputSourceManagerEventHandler::~DInputSourceManagerEventHandler()
{
eventFuncMap_.clear();
sourceManagerObj_ = nullptr;
}
void DInputSourceManagerEventHandler::NotifyRegisterCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_HWID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
DistributedInputSourceManager::InputDeviceId inputDeviceId {deviceId, dhId};
std::vector<DistributedInputSourceManager::InputDeviceId> tmpInputDevId = sourceManagerObj_->GetInputDeviceId();
// Find out if the dh exists
auto devIt = std::find(tmpInputDevId.begin(), tmpInputDevId.end(), inputDeviceId);
if (devIt != tmpInputDevId.end()) {
if (result == false) {
sourceManagerObj_->RemoveInputDeviceId(deviceId, dhId);
}
} else {
DHLOGW("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG the "
"devId: %s, dhId: %s is bad data.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str());
}
sourceManagerObj_->RunRegisterCallback(deviceId, dhId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyUnregisterCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_HWID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
if (result) {
sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF);
}
sourceManagerObj_->RunUnregisterCallback(deviceId, dhId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_WHITELIST)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
sourceManagerObj_->RunPrepareCallback(deviceId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD, object);
}
void DInputSourceManagerEventHandler::NotifyUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
if (result) {
sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF);
}
sourceManagerObj_->RunUnprepareCallback(deviceId,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyStartCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_ITP) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
DHLOGI("Start DInput Recv Callback ret: %s, devId: %s, inputTypes: %d",
result ? "true" : "false", GetAnonyString(deviceId).c_str(), inputTypes);
if (result) {
sourceManagerObj_->SetInputTypesMap(
deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) | inputTypes);
}
sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ?
DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE);
sourceManagerObj_->RunStartCallback(deviceId, inputTypes,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyStopCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_ITP) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
DHLOGI("Stop DInput Recv Callback ret: %B, devId: %s, inputTypes: %d",
result, GetAnonyString(deviceId).c_str(), inputTypes);
if (result && (sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes)) {
sourceManagerObj_->SetInputTypesMap(
deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) -
(sourceManagerObj_->GetInputTypesMap(deviceId) & inputTypes));
}
if (sourceManagerObj_->GetInputTypesMap(deviceId) == 0) {
sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_OFF);
}
// DeviceMap_ all sink device switch is off,call isstart's callback
bool isAllDevSwitchOff = sourceManagerObj_->GetDeviceMapAllDevSwitchOff();
if (isAllDevSwitchOff) {
DHLOGI("All Dev Switch Off");
sourceManagerObj_->SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
}
sourceManagerObj_->RunStopCallback(deviceId, inputTypes,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
sourceManagerObj_->RunStartDhidCallback(deviceId, dhidStr,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
sourceManagerObj_->RunStopDhidCallback(deviceId, dhidStr,
result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_MSG_IS_BAD);
}
void DInputSourceManagerEventHandler::NotifyKeyStateCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_TYPE) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_CODE) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
std::string dhid = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
uint32_t keyType = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE];
uint32_t keyCode = innerMsg[INPUT_SOURCEMANAGER_KEY_CODE];
uint32_t keyValue = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
sourceManagerObj_->RunKeyStateCallback(deviceId, dhid, keyType, keyCode, keyValue);
}
void DInputSourceManagerEventHandler::NotifyStartServerCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
auto it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
DInputServerType startTransFlag = DInputServerType(serType);
sourceManagerObj_->SetStartTransFlag(startTransFlag);
}
void DInputSourceManagerEventHandler::NotifyRelayPrepareCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID];
std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID];
sourceManagerObj_->RunRelayPrepareCallback(srcId, sinkId, status);
}
void DInputSourceManagerEventHandler::NotifyRelayUnprepareCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID];
std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID];
sourceManagerObj_->RunRelayUnprepareCallback(srcId, sinkId, status);
}
void DInputSourceManagerEventHandler::NotifyRelayPrepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_WHITELIST) ||
!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_SESSIONID)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
std::string object = innerMsg[INPUT_SOURCEMANAGER_KEY_WHITELIST];
int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID];
DHLOGI("Device whitelist object: %s", object.c_str());
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
return;
}
// notify to origin sourcesa result.
int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginPrepareResult(toSrcSessionId,
localNetworkId, deviceId, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_MSG_IS_BAD);
if (ret != DH_SUCCESS) {
DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_PREPARE_RESULT_TO_ORIGIN notify is fail.");
return;
}
sourceManagerObj_->RunWhiteListCallback(deviceId, object);
}
void DInputSourceManagerEventHandler::NotifyRelayUnprepareRemoteInput(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DEVID) ||
!IsBoolean(innerMsg, INPUT_SOURCEMANAGER_KEY_RESULT) ||
!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_SESSIONID)) {
DHLOGE("The key is invaild.");
return ;
}
std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID];
bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT];
int32_t toSrcSessionId = innerMsg[INPUT_SOURCEMANAGER_KEY_SESSIONID];
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
return;
}
// notify to origin sourcesa result.
int32_t ret = DistributedInputSourceTransport::GetInstance().NotifyOriginUnprepareResult(toSrcSessionId,
localNetworkId, deviceId, result ? DH_SUCCESS : ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_MSG_IS_BAD);
if (ret != DH_SUCCESS) {
DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_UNPREPARE_RESULT_TO_ORIGIN notify is fail.");
return;
}
}
void DInputSourceManagerEventHandler::NotifyRelayStartDhidCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID];
std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID];
std::string dhids = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
sourceManagerObj_->RunRelayStartDhidCallback(srcId, sinkId, status, dhids);
}
void DInputSourceManagerEventHandler::NotifyRelayStopDhidCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_DHID)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID];
std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID];
std::string dhids = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID];
sourceManagerObj_->RunRelayStopDhidCallback(srcId, sinkId, status, dhids);
}
void DInputSourceManagerEventHandler::NotifyRelayStartTypeCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_TYPE)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID];
std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID];
uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE];
sourceManagerObj_->RunRelayStartTypeCallback(srcId, sinkId, status, inputTypes);
}
void DInputSourceManagerEventHandler::NotifyRelayStopTypeCallback(const AppExecFwk::InnerEvent::Pointer &event)
{
std::shared_ptr<nlohmann::json> dataMsg = event->GetSharedObject<nlohmann::json>();
nlohmann::json::iterator it = dataMsg->begin();
nlohmann::json innerMsg = *it;
if (!IsInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_VALUE) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SRC_DEVID) ||
!IsString(innerMsg, INPUT_SOURCEMANAGER_KEY_SINK_DEVID) ||
!IsUInt32(innerMsg, INPUT_SOURCEMANAGER_KEY_TYPE)) {
DHLOGE("The key is invaild.");
return ;
}
int32_t status = innerMsg[INPUT_SOURCEMANAGER_KEY_VALUE];
std::string srcId = innerMsg[INPUT_SOURCEMANAGER_KEY_SRC_DEVID];
std::string sinkId = innerMsg[INPUT_SOURCEMANAGER_KEY_SINK_DEVID];
uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_TYPE];
sourceManagerObj_->RunRelayStopTypeCallback(srcId, sinkId, status, inputTypes);
}
void DInputSourceManagerEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
{
auto iter = eventFuncMap_.find(event->GetInnerEventId());
if (iter == eventFuncMap_.end()) {
DHLOGE("Event Id %d is undefined.", event->GetInnerEventId());
return;
}
SourceEventFunc &func = iter->second;
(this->*func)(event);
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
File diff suppressed because it is too large Load Diff
@@ -12,8 +12,7 @@
# limitations under the License.
import("//build/test.gni")
import(
"//foundation/distributedhardware/distributed_input/distributedinput.gni")
import("../../../../../distributedinput.gni")
module_out_path = "distributed_input/source_manager"
@@ -86,6 +85,8 @@ ohos_unittest("distributed_input_sourcemanager_test") {
"${services_source_path}/inputinject/src/distributed_input_inject.cpp",
"${services_source_path}/inputinject/src/distributed_input_node_manager.cpp",
"${services_source_path}/inputinject/src/virtual_device.cpp",
"${services_source_path}/sourcemanager/src/dinput_source_listener.cpp",
"${services_source_path}/sourcemanager/src/dinput_source_manager_event_handler.cpp",
"${services_source_path}/sourcemanager/src/distributed_input_source_event_handler.cpp",
"${services_source_path}/sourcemanager/src/distributed_input_source_manager.cpp",
"${services_source_path}/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp",
@@ -49,7 +49,7 @@ namespace {
void DistributedInputSourceManagerTest::SetUp()
{
sourceManager_ = new DistributedInputSourceManager(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, true);
statuslistener_ = std::make_shared<DistributedInputSourceManager::DInputSourceListener>(sourceManager_);
statuslistener_ = std::make_shared<DInputSourceListener>(sourceManager_);
DistributedInputSourceManagerTest::RegisterSourceRespCallback(statuslistener_);
}
@@ -39,6 +39,7 @@
#include "simulation_event_listener_stub.h"
#include "dinput_source_trans_callback.h"
#include "dinput_source_listener.h"
namespace OHOS {
namespace DistributedHardware {
@@ -156,7 +157,7 @@ public:
private:
int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor) const;
DistributedInputSourceManager* sourceManager_;
std::shared_ptr<DistributedInputSourceManager::DInputSourceListener> statuslistener_;
std::shared_ptr<DInputSourceListener> statuslistener_;
std::shared_ptr<DInputSourceTransCallback> callback_;
};
} // namespace DistributedInput
@@ -524,8 +524,8 @@ HWTEST_F(DistributedInputSourceTransTest, NotifyResponsePrepareRemoteInput03, te
std::string remoteId = "f6d4c08647073e02e7a78f09473aa122ff57fc81c00981fcf5be989e7d112591";
DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[remoteId] = sessionId;
DistributedInputSourceManager srcMgr(4810, false);
std::shared_ptr<DistributedInputSourceManager::DInputSourceListener> srcListener =
std::make_shared<DistributedInputSourceManager::DInputSourceListener>(&srcMgr);
std::shared_ptr<DInputSourceListener> srcListener =
std::make_shared<DInputSourceListener>(&srcMgr);
DistributedInputSourceTransport::GetInstance().callback_ = srcListener;
DistributedInputSourceTransport::GetInstance().NotifyResponsePrepareRemoteInput(sessionId, recMsg);
std::string message(MSG_MAX_SIZE + 1, 'a');