!147 分布式输入服务测SA崩溃后,SDK客户端无法自动恢复业务注册的回调

Merge pull request !147 from 李尚/master
This commit is contained in:
openharmony_ci
2024-02-06 09:39:45 +00:00
committed by Gitee
4 changed files with 113 additions and 4 deletions
@@ -18,6 +18,7 @@
#include <atomic>
#include <mutex>
#include <set>
#include "i_distributed_source_input.h"
#include "i_distributed_sink_input.h"
@@ -46,6 +47,11 @@ public:
bool HasDInputSinkProxy();
bool SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject);
void RegisterEventHandler(std::shared_ptr<AppExecFwk::EventHandler> handler);
int32_t RestoreRegisterListenerAndCallback();
void AddSimEventListenerToCache(sptr<ISimulationEventListener> listener);
void RemoveSimEventListenerFromCache(sptr<ISimulationEventListener> listener);
void AddSessionStateCbToCache(sptr<ISessionStateCallback> callback);
void RemoveSessionStateCbFromCache();
public:
class SystemAbilityListener : public SystemAbilityStatusChangeStub {
@@ -54,6 +60,12 @@ public:
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
};
private:
std::mutex simEventListenerCacheMtx_;
std::set<sptr<ISimulationEventListener>> simEventListenerCache_;
std::mutex sessionStateCbCacheMtx_;
std::set<sptr<ISessionStateCallback>> sessionStateCbCache_;
private:
DInputSAManager() = default;
~DInputSAManager() = default;
+75 -4
View File
@@ -76,8 +76,8 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb
DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG");
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG, systemAbilityId);
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME,
AppExecFwk::EventQueue::Priority::IMMEDIATE);
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent,
DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
}
@@ -88,8 +88,8 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb
DHLOGI("SendEvent DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG");
AppExecFwk::InnerEvent::Pointer msgEvent =
AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG, systemAbilityId);
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent, DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME,
AppExecFwk::EventQueue::Priority::IMMEDIATE);
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent,
DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
}
DHLOGI("sa %d is added.", systemAbilityId);
@@ -275,6 +275,77 @@ bool DInputSAManager::SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject
}
return true;
}
int32_t DInputSAManager::RestoreRegisterListenerAndCallback()
{
DHLOGI("Restore RegisterPublisherListener");
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("RestoreRegisterSimulationEventListener proxy error, client fail");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
int32_t result = DH_SUCCESS;
{
std::lock_guard<std::mutex> lock(simEventListenerCacheMtx_);
for (const auto& listener : simEventListenerCache_) {
if (listener == nullptr) {
DHLOGE("simEventListenerCache_ is nullptr");
continue;
}
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener);
if (ret != DH_SUCCESS) {
result = ret;
DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret);
}
}
}
{
DHLOGI("Restore RegisterSessionStateCb");
std::lock_guard<std::mutex> lock(sessionStateCbCacheMtx_);
for (const auto& callback : sessionStateCbCache_) {
if (callback == nullptr) {
DHLOGE("sessionStateCbCache_ is nullptr");
continue;
}
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback);
if (ret != DH_SUCCESS) {
result = ret;
DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret);
}
}
}
return result;
}
void DInputSAManager::AddSimEventListenerToCache(sptr<ISimulationEventListener> listener)
{
std::lock_guard<std::mutex> simEventListenerLock(simEventListenerCacheMtx_);
if (listener != nullptr) {
simEventListenerCache_.insert(listener);
}
}
void DInputSAManager::RemoveSimEventListenerFromCache(sptr<ISimulationEventListener> listener)
{
std::lock_guard<std::mutex> simEventListenerLock(simEventListenerCacheMtx_);
if (listener != nullptr) {
simEventListenerCache_.erase(listener);
}
}
void DInputSAManager::AddSessionStateCbToCache(sptr<ISessionStateCallback> callback)
{
std::lock_guard<std::mutex> sessionStateCbLock(sessionStateCbCacheMtx_);
if (callback != nullptr) {
sessionStateCbCache_.insert(callback);
}
}
void DInputSAManager::RemoveSessionStateCbFromCache()
{
std::lock_guard<std::mutex> sessionStateCbLock(sessionStateCbCacheMtx_);
sessionStateCbCache_.clear();
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -28,6 +28,7 @@
#include "input_check_param.h"
#include "softbus_bus_center.h"
#include "white_list_util.h"
#include "dinput_sa_manager.h"
namespace OHOS {
namespace DistributedHardware {
@@ -128,6 +129,10 @@ void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExe
DHLOGI("DInputClientEventHandler ProcessEvent start eventId:%d.", eventId);
if (eventId == DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG) {
DistributedInputClient::GetInstance().CheckSourceRegisterCallback();
int32_t result = DInputSAManager::GetInstance().RestoreRegisterListenerAndCallback();
if (result != DH_SUCCESS) {
DHLOGE("source sa execute RestoreRegisterListenerAndCallback fail, result = %d", result);
}
return;
}
@@ -583,6 +588,7 @@ int32_t DistributedInputClient::RegisterSimulationEventListener(sptr<ISimulation
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener);
if (ret == DH_SUCCESS) {
isSimulationEventCbReg = true;
DInputSAManager::GetInstance().AddSimEventListenerToCache(listener);
} else {
isSimulationEventCbReg = false;
regSimulationEventListener_ = listener;
@@ -607,6 +613,7 @@ int32_t DistributedInputClient::UnregisterSimulationEventListener(sptr<ISimulati
if (ret != DH_SUCCESS) {
DHLOGE("UnregisterSimulationEventListener Failed, ret = %d", ret);
}
DInputSAManager::GetInstance().RemoveSimEventListenerFromCache(listener);
return ret;
}
@@ -749,6 +756,7 @@ int32_t DistributedInputClient::RegisterSessionStateCb(sptr<ISessionStateCallbac
DHLOGE("RegisterSessionStateCb callback is null.");
return ERR_DH_INPUT_CLIENT_REGISTER_SESSION_STATE_FAIL;
}
DInputSAManager::GetInstance().AddSessionStateCbToCache(callback);
return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback);
}
@@ -758,6 +766,7 @@ int32_t DistributedInputClient::UnregisterSessionStateCb()
DHLOGE("DinputStart client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
DInputSAManager::GetInstance().RemoveSessionStateCbFromCache();
return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb();
}
} // namespace DistributedInput
@@ -97,6 +97,23 @@ bool DInputSAManager::SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject
}
return true;
}
int32_t DInputSAManager::RestoreRegisterListenerAndCallback()
{
return DH_SUCCESS;
}
void DInputSAManager::AddSimEventListenerToCache(sptr<ISimulationEventListener> listener)
{}
void DInputSAManager::RemoveSimEventListenerFromCache(sptr<ISimulationEventListener> listener)
{}
void DInputSAManager::AddSessionStateCbToCache(const sptr<ISessionStateCallback> callback)
{}
void DInputSAManager::RemoveSessionStateCbFromCache()
{}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS