Description:support dynamic load SA

Match-id-abde2643acbee9a6e866fe8f9c964364f6668bb6
This commit is contained in:
xxxx
2022-05-17 16:44:36 +08:00
parent 89a8b0135b
commit c648949626
24 changed files with 354 additions and 25 deletions
+1
View File
@@ -46,6 +46,7 @@
"//foundation/distributedhardware/distributedinput/interfaces/inner_kits:libdinput_sdk",
"//foundation/distributedhardware/distributedinput/sa_profile:distributed_input_source_sa_profile",
"//foundation/distributedhardware/distributedinput/sa_profile:distributed_input_sink_sa_profile",
"//foundation/distributedhardware/distributedinput/sa_profile:dinput.cfg",
"//foundation/distributedhardware/distributedinput/services/source/sourcemanager:libdinput_source",
"//foundation/distributedhardware/distributedinput/services/source/transport:libdinput_source_trans",
"//foundation/distributedhardware/distributedinput/services/source/inputinject:libdinput_inject",
+2
View File
@@ -87,6 +87,8 @@ namespace DistributedInput {
*/
const int32_t INPUT_TYPE_ALL = INPUT_TYPE_MOUSE | INPUT_TYPE_KEYBOARD | INPUT_TYPE_TOUCH;
constexpr int32_t INPUT_LOADSA_TIMEOUT_MS = 10000;
enum class EHandlerMsgType {
DINPUT_SINK_EVENT_HANDLER_MSG = 1,
DINPUT_SOURCE_EVENT_HANDLER_MSG = 2
+30 -5
View File
@@ -14,6 +14,7 @@
*/
#include "input_hub.h"
#include <sys/types.h>
#include <cstring>
#include <dirent.h>
#include <fcntl.h>
@@ -87,7 +88,7 @@ int32_t InputHub::Release()
size_t InputHub::CollectInputEvents(RawEvent* buffer, size_t bufferSize)
{
size_t count;
for ( ; ; ) {
for (; ;) {
if (needToScanDevices_) {
needToScanDevices_ = false;
ScanInputDevices(DEVICE_PATH);
@@ -233,7 +234,7 @@ size_t InputHub::CollectInputHandler(InputDeviceEvent* buffer, size_t bufferSize
{
InputDeviceEvent* event = buffer;
size_t capacity = bufferSize;
for ( ; ; ) {
for (; ;) {
// Report any devices that had last been added/removed.
for (auto it = closingDevices_.begin(); it != closingDevices_.end();) {
std::unique_ptr<Device> device = std::move(*it);
@@ -347,10 +348,34 @@ std::vector<InputDevice> InputHub::GetAllInputDevices()
void InputHub::ScanInputDevices(const std::string& dirname)
{
for (const auto& entry : std::filesystem::directory_iterator(dirname)) {
OpenInputDeviceLocked(entry.path());
char devname[PATH_MAX];
char *filename;
DIR *dir;
struct dirent *de;
dir = opendir(dirname.c_str());
if (dir == nullptr) {
DHLOGE("error opendir dev/input :%{public}s\n", strerror(errno));
return;
}
return;
if (strcpy_s(devname, PATH_MAX, dirname.c_str()) != 0) {
DHLOGE("error strcpy_s :%{public}s\n", strerror(errno));
}
filename = devname + strlen(devname);
*filename++ = '/';
while ((de = readdir(dir))) {
if (de->d_name[0] == '.' &&
(de->d_name[1] == '\0' ||
(de->d_name[1] == '.' && de->d_name[DIR_FILE_NAME_SECOND] == '\0'))) {
continue;
}
if (strcpy_s(filename, sizeof(de->d_name), de->d_name) != 0) {
DHLOGE("error strcpy_s second :%{public}s\n", strerror(errno));
}
DHLOGE("scan dir failed for %{public}s", filename);
OpenInputDeviceLocked(devname);
}
closedir(dir);
}
int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath)
@@ -66,8 +66,15 @@ public:
DInputServerType IsStartDistributedInput(const uint32_t& inputType);
public:
bool HasDInputSourceProxy();
bool SetDInputSourceProxy(const sptr<IRemoteObject> &remoteObject);
bool HasDInputSinkProxy();
bool SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject);
public:
class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub {
public:
RegisterDInputCb() = default;
@@ -340,7 +340,7 @@ bool DistributedInputClient::GetDInputSourceProxy()
if (!systemAbilityManager) {
return false;
}
DHLOGI("%s try get sa: %d", __func__, DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID);
sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(
DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID);
if (!remoteObject) {
@@ -356,6 +356,38 @@ bool DistributedInputClient::GetDInputSourceProxy()
return true;
}
bool DistributedInputClient::HasDInputSourceProxy()
{
return dInputSourceProxy_ != nullptr;
}
bool DistributedInputClient::SetDInputSourceProxy(const sptr<IRemoteObject> &remoteObject)
{
dInputSourceProxy_ = iface_cast<IDistributedSourceInput>(remoteObject);
if ((!dInputSourceProxy_) || (!dInputSourceProxy_->AsObject())) {
DHLOGE("Failed to get dinput source proxy.");
return false;
}
return true;
}
bool DistributedInputClient::HasDInputSinkProxy()
{
return dInputSinkProxy_ != nullptr;
}
bool DistributedInputClient::SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject)
{
dInputSinkProxy_ = iface_cast<IDistributedSinkInput>(remoteObject);
if ((!dInputSinkProxy_) || (!dInputSinkProxy_->AsObject())) {
DHLOGE("Failed to get dinput sink proxy.");
return false;
}
return true;
}
bool DistributedInputClient::GetDInputSinkProxy()
{
if (!dInputSinkProxy_) {
+2 -2
View File
@@ -14,13 +14,13 @@
* limitations under the License.
-->
<info>
<process>dhardware</process>
<process>dinput</process>
<systemability> <!-- Declare a sytem ability and its profile -->
<name>4809</name> <!-- Declare the name of system ability -->
<libpath>libdinput_source.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<run-on-create>false</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
+2 -2
View File
@@ -14,13 +14,13 @@
* limitations under the License.
-->
<info>
<process>dhardware</process>
<process>dinput</process>
<systemability> <!-- Declare a sytem ability and its profile -->
<name>4810</name> <!-- Declare the name of system ability -->
<libpath>libdinput_sink.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<run-on-create>false</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
+7
View File
@@ -29,4 +29,11 @@ ohos_sa_profile("distributed_input_sink_sa_profile") {
]
part_name = "distributed_input"
}
ohos_prebuilt_etc("dinput.cfg") {
relative_install_dir = "init"
source = "dinput.cfg"
part_name = "distributed_input"
subsystem_name = "distributedhardware"
}
+9
View File
@@ -0,0 +1,9 @@
{
"services" : [{
"name" : "dinput",
"path" : ["/system/bin/sa_main", "/system/profile/dinput.xml"],
"uid" : "root",
"gid" : ["system", "uhid", "root"],
"ondemand" : true
}]
}
@@ -41,9 +41,9 @@ namespace DistributedInput {
const uint32_t DEVICE_ID_SIZE_MAX = 65;
const uint32_t INTERCEPT_STRING_LENGTH = 20;
const std::string DINPUT_PKG_NAME = "DBinderBus_" + std::to_string(getpid());
const std::string SESSION_NAME_SOURCE = "DBinderInput_so_";
const std::string SESSION_NAME_SINK = "DBinderInput_si_";
const std::string DINPUT_PKG_NAME = "ohos.dhardware.dinput";
const std::string SESSION_NAME_SOURCE = "ohos.dhardware.dinput.so_";
const std::string SESSION_NAME_SINK = "ohos.dhardware.dinput.si_";
const std::string GROUP_ID = "input_softbus_group_id";
#define DINPUT_SOFTBUS_KEY_CMD_TYPE "dinput_softbus_key_cmd_type"
@@ -157,7 +157,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
// add the input type
if (startRes == SUCCESS) {
sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() | inputTypes);
DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes());
DistributedInputCollector::GetInstance().SetInputTypes(sinkManagerObj_->GetInputTypes());
}
IStartDInputServerCallback *startServerCB = sinkManagerObj_->GetStartDInputServerCback();
@@ -297,6 +297,9 @@ int32_t DistributedInputSinkManager::Release()
}
serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START;
DHLOGI("exit dinput sink sa.");
exit(0);
return SUCCESS;
}
@@ -73,7 +73,7 @@ DistributedInputSinkTransport::~DistributedInputSinkTransport()
{
DHLOGI("~DistributedInputSinkTransport");
sessionDevMap_.clear();
(void)RemoveSessionServer(DH_FWK_PKG_NAME.c_str(), mySessionName_.c_str());
(void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str());
}
DistributedInputSinkTransport::DInputSinkEventHandler::DInputSinkEventHandler(
@@ -123,7 +123,8 @@ int32_t DistributedInputSinkTransport::Init()
DHLOGE("Init unique_ptr localNode nullptr.");
return FAILURE;
}
int32_t retCode = GetLocalNodeDeviceInfo(DH_FWK_PKG_NAME.c_str(), localNode.get());
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
if (retCode != SUCCESS) {
DHLOGE("Init could not get local device id.");
return FAILURE;
@@ -132,7 +133,8 @@ int32_t DistributedInputSinkTransport::Init()
DHLOGI("Init device networkId is %s", networkId.c_str());
mySessionName_ = SESSION_NAME_SINK + networkId.substr(0, INTERCEPT_STRING_LENGTH);
int32_t ret = CreateSessionServer(DH_FWK_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
if (ret != SUCCESS) {
DHLOGE("Init CreateSessionServer failed, error code %d.", ret);
return FAILURE;
@@ -532,6 +532,8 @@ int32_t DistributedInputSourceManager::Release()
callBackHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
serviceRunningState_ = ServiceSourceRunningState::STATE_NOT_START;
DHLOGI("exit dinput source sa.");
exit(0);
return SUCCESS;
}
@@ -91,7 +91,7 @@ int32_t DistributedInputSourceTransport::Init()
};
auto localNode = std::make_unique<NodeBasicInfo>();
int32_t retCode = GetLocalNodeDeviceInfo(DH_FWK_PKG_NAME.c_str(), localNode.get());
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
if (retCode != SUCCESS) {
DHLOGE("Init Could not get local device id.");
return FAILURE;
@@ -100,7 +100,7 @@ int32_t DistributedInputSourceTransport::Init()
DHLOGI("Init device local networkId is %s", networkId.c_str());
mySessionName_ = SESSION_NAME_SOURCE + networkId.substr(0, INTERCEPT_STRING_LENGTH);
int32_t ret = CreateSessionServer(DH_FWK_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener);
if (ret != SUCCESS) {
DHLOGE("Init CreateSessionServer failed, error code %d.", ret);
return FAILURE;
@@ -117,7 +117,7 @@ DistributedInputSourceTransport::~DistributedInputSourceTransport()
sessionDevMap_.clear();
devHardwareMap_.clear();
(void)RemoveSessionServer(DH_FWK_PKG_NAME.c_str(), mySessionName_.c_str());
(void)RemoveSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str());
}
int32_t DistributedInputSourceTransport::CheckDeviceSessionState(const std::string &devId, const std::string &hwId)
+2 -1
View File
@@ -34,7 +34,8 @@ ohos_shared_library("libdinput_sink_handler") {
]
sources = [
"src/distributed_input_sink_handler.cpp"
"src/distributed_input_sink_handler.cpp",
"src/load_d_input_sink_callback.cpp"
]
defines = [
@@ -23,6 +23,7 @@
#include <string>
#include <mutex>
#include <condition_variable>
#include <iservice_registry.h>
#include <system_ability_definition.h>
@@ -36,6 +37,7 @@ public:
int32_t ReleaseSink() override;
int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override;
int32_t UnsubscribeLocalHardware(const std::string& dhId) override;
void FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject);
public:
class SALoadSinkCb : public OHOS::SystemAbilityLoadCallbackStub {
@@ -63,6 +65,9 @@ private:
DistributedInputSinkHandler() = default;
~DistributedInputSinkHandler();
OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSinkCallback = nullptr;
std::mutex proxyMutex_;
std::condition_variable proxyConVar_;
};
#ifdef __cplusplus
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LOAD_D_INPUT_SOURCE_CALLBACK_H
#define LOAD_D_INPUT_SOURCE_CALLBACK_H
#include "system_ability_load_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class LoadDInputSinkCallback : public SystemAbilityLoadCallbackStub {
public:
explicit LoadDInputSinkCallback(const std::string &params);
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const sptr<IRemoteObject> &remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
private:
std::string params_;
};
}
}
}
#endif
@@ -15,6 +15,7 @@
#include "distributed_input_sink_handler.h"
#include "i_distributed_sink_input.h"
#include "load_d_input_sink_callback.h"
#include "distributed_hardware_log.h"
namespace OHOS {
@@ -29,7 +30,40 @@ DistributedInputSinkHandler::~DistributedInputSinkHandler()
int32_t DistributedInputSinkHandler::InitSink(const std::string &params)
{
return DistributedInputClient::GetInstance().InitSink();
DHLOGD("InitSource");
std::unique_lock<std::mutex> lock(proxyMutex_);
if (!DistributedInputClient::GetInstance().HasDInputSinkProxy()) {
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!samgr) {
DHLOGE("Failed to get system ability mgr.");
return FAILURE_DIS;
}
sptr<LoadDInputSinkCallback> loadCallback = new LoadDInputSinkCallback(params);
int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, loadCallback);
if (ret != ERR_OK) {
DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d",
DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, ret);
return FAILURE_DIS;
}
}
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(INPUT_LOADSA_TIMEOUT_MS),
[this]() { return (DistributedInputClient::GetInstance().HasDInputSinkProxy()); });
if (!waitStatus) {
DHLOGE("dinput load sa timeout.");
return FAILURE_DIS;
}
return SUCCESS;
}
void DistributedInputSinkHandler::FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject)
{
DHLOGD("FinishStartSA");
std::unique_lock<std::mutex> lock(proxyMutex_);
DistributedInputClient::GetInstance().SetDInputSinkProxy(remoteObject);
DistributedInputClient::GetInstance().InitSink();
proxyConVar_.notify_all();
}
int32_t DistributedInputSinkHandler::ReleaseSink()
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "load_d_input_sink_callback.h"
#include "distributed_hardware_log.h"
#include "distributed_input_sink_handler.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
LoadDInputSinkCallback::LoadDInputSinkCallback(const std::string &params) : params_(params) {}
void LoadDInputSinkCallback::OnLoadSystemAbilitySuccess(
int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
{
DHLOGI("load dinput SA success, systemAbilityId:%d, remoteObject result:%s",
systemAbilityId, (remoteObject != nullptr) ? "true" : "false");
if (remoteObject == nullptr) {
DHLOGE("remoteObject is nullptr");
return;
}
DistributedInputSinkHandler::GetInstance().FinishStartSA(params_, remoteObject);
}
void LoadDInputSinkCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
DHLOGE("load dinput SA failed, systemAbilityId:%d", systemAbilityId);
}
}
}
}
+2 -1
View File
@@ -34,7 +34,8 @@ ohos_shared_library("libdinput_source_handler") {
]
sources = [
"src/distributed_input_source_handler.cpp"
"src/distributed_input_source_handler.cpp",
"src/load_d_input_source_callback.cpp"
]
defines = [
@@ -24,6 +24,7 @@
#include <string>
#include <mutex>
#include <condition_variable>
#include <iservice_registry.h>
#include <system_ability_definition.h>
@@ -41,6 +42,7 @@ public:
std::shared_ptr<UnregisterCallback> callback) override;
int32_t ConfigDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& key,
const std::string& value) override;
void FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject);
public:
@@ -68,6 +70,9 @@ private:
DistributedInputSourceHandler() = default;
~DistributedInputSourceHandler();
OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSourceCallback = nullptr;
std::mutex proxyMutex_;
std::condition_variable proxyConVar_;
};
#ifdef __cplusplus
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LOAD_D_INPUT_SOURCE_CALLBACK_H
#define LOAD_D_INPUT_SOURCE_CALLBACK_H
#include "system_ability_load_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class LoadDInputSourceCallback : public SystemAbilityLoadCallbackStub {
public:
explicit LoadDInputSourceCallback(const std::string &params);
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
private:
std::string params_;
};
}
}
}
#endif
@@ -14,7 +14,10 @@
*/
#include "distributed_input_source_handler.h"
#include "distributed_hardware_log.h"
#include "i_distributed_source_input.h"
#include "load_d_input_source_callback.h"
namespace OHOS {
namespace DistributedHardware {
@@ -27,7 +30,40 @@ DistributedInputSourceHandler::~DistributedInputSourceHandler()
int32_t DistributedInputSourceHandler::InitSource(const std::string &params)
{
return DistributedInputClient::GetInstance().InitSource();
DHLOGD("InitSource");
std::unique_lock<std::mutex> lock(proxyMutex_);
if (!DistributedInputClient::GetInstance().HasDInputSourceProxy()) {
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!samgr) {
DHLOGE("Failed to get system ability mgr.");
return FAILURE_DIS;
}
sptr<LoadDInputSourceCallback> loadCallback = new LoadDInputSourceCallback(params);
int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, loadCallback);
if (ret != ERR_OK) {
DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d",
DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, ret);
return FAILURE_DIS;
}
}
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(INPUT_LOADSA_TIMEOUT_MS),
[this]() { return (DistributedInputClient::GetInstance().HasDInputSourceProxy()); });
if (!waitStatus) {
DHLOGE("dinput load sa timeout.");
return FAILURE_DIS;
}
return SUCCESS;
}
void DistributedInputSourceHandler::FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject)
{
DHLOGD("FinishStartSA");
std::unique_lock<std::mutex> lock(proxyMutex_);
DistributedInputClient::GetInstance().SetDInputSourceProxy(remoteObject);
DistributedInputClient::GetInstance().InitSource();
proxyConVar_.notify_all();
}
int32_t DistributedInputSourceHandler::ReleaseSource()
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "load_d_input_source_callback.h"
#include "distributed_hardware_log.h"
#include "distributed_input_source_handler.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
LoadDInputSourceCallback::LoadDInputSourceCallback(const std::string &params) : params_(params) {}
void LoadDInputSourceCallback::OnLoadSystemAbilitySuccess(
int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
{
DHLOGI("load dinput SA success, systemAbilityId:%d, remoteObject result:%s",
systemAbilityId, (remoteObject != nullptr) ? "true" : "false");
if (remoteObject == nullptr) {
DHLOGE("remoteObject is nullptr");
return;
}
DistributedInputSourceHandler::GetInstance().FinishStartSA(params_, remoteObject);
}
void LoadDInputSourceCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
DHLOGE("load dinput SA failed, systemAbilityId:%d", systemAbilityId);
}
}
}
}