motify Devicestatus to DeviceStatus

Signed-off-by: mayunteng_1 <mayunteng@huawei.com>
This commit is contained in:
mayunteng_1 2022-12-03 15:27:46 +08:00
parent 7522aa1b1c
commit 4c2c51bb59
54 changed files with 839 additions and 839 deletions

View File

@ -26,16 +26,16 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusCallbackStub : public IRemoteStub<IdevicestatusCallback> {
class DeviceStatusCallbackStub : public IRemoteStub<IdevicestatusCallback> {
public:
DISALLOW_COPY_AND_MOVE(DevicestatusCallbackStub);
DevicestatusCallbackStub() = default;
virtual ~DevicestatusCallbackStub() = default;
DISALLOW_COPY_AND_MOVE(DeviceStatusCallbackStub);
DeviceStatusCallbackStub() = default;
virtual ~DeviceStatusCallbackStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& __attribute__((unused))value) override {}
void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& __attribute__((unused))value) override {}
private:
int32_t OnDevicestatusChangedStub(MessageParcel& data);
int32_t OnDeviceStatusChangedStub(MessageParcel& data);
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -29,16 +29,16 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DeviceStatusCallback : public DevicestatusCallbackStub {
class DeviceStatusCallback : public DeviceStatusCallbackStub {
public:
explicit DeviceStatusCallback(napi_env env) : env_(env) {}
virtual ~DeviceStatusCallback() {};
void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData &devicestatusData) override;
void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData &devicestatusData) override;
static void EmitOnEvent(uv_work_t *work, int status);
private:
napi_env env_ = { nullptr };
std::mutex mutex_;
DevicestatusDataUtils::DevicestatusData data_;
DeviceStatusDataUtils::DeviceStatusData data_;
};
class DeviceStatusNapi : public DeviceStatusEvent {

View File

@ -22,20 +22,20 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
int32_t DevicestatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, \
int32_t DeviceStatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, \
MessageOption &option)
{
DEV_HILOGD(SERVICE, "cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
std::u16string descriptor = DevicestatusCallbackStub::GetDescriptor();
std::u16string descriptor = DeviceStatusCallbackStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
DEV_HILOGE(SERVICE, "DevicestatusCallbackStub::OnRemoteRequest failed, descriptor mismatch");
DEV_HILOGE(SERVICE, "DeviceStatusCallbackStub::OnRemoteRequest failed, descriptor mismatch");
return E_DEVICESTATUS_GET_SERVICE_FAILED;
}
switch (code) {
case static_cast<int32_t>(IdevicestatusCallback::DEVICESTATUS_CHANGE): {
return OnDevicestatusChangedStub(data);
return OnDeviceStatusChangedStub(data);
}
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@ -43,18 +43,18 @@ int32_t DevicestatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &
return ERR_OK;
}
int32_t DevicestatusCallbackStub::OnDevicestatusChangedStub(MessageParcel& data)
int32_t DeviceStatusCallbackStub::OnDeviceStatusChangedStub(MessageParcel& data)
{
DEV_HILOGD(SERVICE, "Enter");
int32_t type;
int32_t value;
READINT32(data, type, E_DEVICESTATUS_READ_PARCEL_ERROR);
READINT32(data, value, E_DEVICESTATUS_READ_PARCEL_ERROR);
DevicestatusDataUtils::DevicestatusData devicestatusData = {
static_cast<DevicestatusDataUtils::DevicestatusType>(type),
static_cast<DevicestatusDataUtils::DevicestatusValue>(value)
DeviceStatusDataUtils::DeviceStatusData devicestatusData = {
static_cast<DeviceStatusDataUtils::DeviceStatusType>(type),
static_cast<DeviceStatusDataUtils::DeviceStatusValue>(value)
};
OnDevicestatusChanged(devicestatusData);
OnDeviceStatusChanged(devicestatusData);
return ERR_OK;
}
} // namespace DeviceStatus

View File

@ -201,8 +201,8 @@ void DeviceStatusEvent::SendRet(int32_t eventType, int32_t value, napi_value &re
DEV_HILOGE(JS_NAPI, "Failed to set name");
return;
}
if (value >= static_cast<int32_t>(DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID)
&& value <= static_cast<int32_t>(DevicestatusDataUtils::DevicestatusValue::VALUE_EXIT)) {
if (value >= static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID)
&& value <= static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusValue::VALUE_EXIT)) {
status = napi_create_int32(env_, value, &tmpValue);
if (status != napi_ok) {
DEV_HILOGE(JS_NAPI, "Failed to get int32");

View File

@ -42,12 +42,12 @@ std::map<int32_t, sptr<IdevicestatusCallback>> DeviceStatusNapi::callbackMap_;
napi_ref DeviceStatusNapi::devicestatusValueRef_ = nullptr;
struct ResponseEntity {
DevicestatusDataUtils::DevicestatusValue value;
DeviceStatusDataUtils::DeviceStatusValue value;
};
void DeviceStatusCallback::OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusCallback::OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
DEV_HILOGD(JS_NAPI, "OnDevicestatusChanged enter");
DEV_HILOGD(JS_NAPI, "OnDeviceStatusChanged enter");
std::lock_guard<std::mutex> guard(mutex_);
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(env_, &loop);
@ -72,7 +72,7 @@ void DeviceStatusCallback::OnDevicestatusChanged(const DevicestatusDataUtils::De
void DeviceStatusCallback::EmitOnEvent(uv_work_t *work, int status)
{
DevicestatusDataUtils::DevicestatusData* data = static_cast<DevicestatusDataUtils::DevicestatusData*>(work->data);
DeviceStatusDataUtils::DeviceStatusData* data = static_cast<DeviceStatusDataUtils::DeviceStatusData*>(work->data);
delete work;
if (data == nullptr) {
DEV_HILOGE(JS_NAPI, "work->data is nullptr");
@ -127,13 +127,13 @@ void DeviceStatusNapi::OnDeviceStatusChangedDone(int32_t type, int32_t value, bo
int32_t DeviceStatusNapi::ConvertTypeToInt(const std::string &type)
{
if (type == "still") {
return DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL;
return DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL;
} else if (type == "relativeStill") {
return DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL;
return DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL;
} else if (type == "carBluetooth") {
return DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH;
return DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH;
} else {
return DevicestatusDataUtils::DevicestatusType::TYPE_INVALID;
return DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
}
}
@ -259,7 +259,7 @@ napi_value DeviceStatusNapi::SubscribeDeviceStatusCallback(napi_env env, napi_ca
DEV_HILOGE(JS_NAPI, "callback is nullptr");
return nullptr;
}
DevicestatusClient::GetInstance().SubscribeCallback(DevicestatusDataUtils::DevicestatusType(type), callback);
DeviceStatusClient::GetInstance().SubscribeCallback(DeviceStatusDataUtils::DeviceStatusType(type), callback);
auto ret = callbackMap_.insert(std::pair<int32_t, sptr<IdevicestatusCallback>>(type, callback));
if (!ret.second) {
DEV_HILOGE(JS_NAPI, "Failed to insert");
@ -309,8 +309,8 @@ napi_value DeviceStatusNapi::SubscribeDeviceStatus(napi_env env, napi_callback_i
int32_t event = eventMode;
int32_t latency = latencyMode;
DEV_HILOGD(JS_NAPI, "type:%{public}d, event:%{public}d, latency:%{public}d", type, event, latency);
NAPI_ASSERT(env, (type >= DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL) &&
(type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN), "type is illegal");
NAPI_ASSERT(env, (type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL) &&
(type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN), "type is illegal");
return SubscribeDeviceStatusCallback(env, info, args, type, event, latency);
}
@ -338,8 +338,8 @@ napi_value DeviceStatusNapi::UnsubscribeDeviceStatus(napi_env env, napi_callback
return nullptr;
}
int32_t type = ConvertTypeToInt(typeBuf.data());
NAPI_ASSERT(env, (type >= DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL) &&
(type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN), "type is illegal");
NAPI_ASSERT(env, (type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL) &&
(type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN), "type is illegal");
int32_t eventMode = 0;
status = napi_get_value_int32(env, args[ARG_1], &eventMode);
if (status != napi_ok) {
@ -354,7 +354,7 @@ napi_value DeviceStatusNapi::UnsubscribeDeviceStatus(napi_env env, napi_callback
}
auto callbackIter = callbackMap_.find(type);
if (callbackIter != callbackMap_.end()) {
DevicestatusClient::GetInstance().UnsubscribeCallback(DevicestatusDataUtils::DevicestatusType(type),
DeviceStatusClient::GetInstance().UnsubscribeCallback(DeviceStatusDataUtils::DeviceStatusType(type),
callbackIter->second);
callbackMap_.erase(type);
} else {
@ -389,8 +389,8 @@ napi_value DeviceStatusNapi::GetDeviceStatus(napi_env env, napi_callback_info in
return nullptr;
}
int32_t type = ConvertTypeToInt(typeBuf.data());
NAPI_ASSERT(env, (type >= DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL) &&
(type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN), "type is illegal");
NAPI_ASSERT(env, (type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL) &&
(type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN), "type is illegal");
if (g_obj == nullptr) {
g_obj = new (std::nothrow) DeviceStatusNapi(env);
if (g_obj == nullptr) {
@ -410,8 +410,8 @@ napi_value DeviceStatusNapi::GetDeviceStatus(napi_env env, napi_callback_info in
DEV_HILOGE(JS_NAPI, "type:%{public}d already exists", type);
return nullptr;
}
DevicestatusDataUtils::DevicestatusData devicestatusData =
DevicestatusClient::GetInstance().GetDevicestatusData(DevicestatusDataUtils::DevicestatusType(type));
DeviceStatusDataUtils::DeviceStatusData devicestatusData =
DeviceStatusClient::GetInstance().GetDeviceStatusData(DeviceStatusDataUtils::DeviceStatusType(type));
g_obj->OnDeviceStatusChangedDone(devicestatusData.type, devicestatusData.value, true);
g_obj->OffOnce(devicestatusData.type, args[ARG_1]);
return nullptr;

View File

@ -51,7 +51,7 @@ int32_t CoordinationManagerImpl::RegisterCoordinationListener(CoordinationListen
if (!isListeningProcess_) {
FI_HILOGI("Start monitoring");
isListeningProcess_ = true;
return DevicestatusClient::GetInstance().RegisterCoordinationListener();
return DeviceStatusClient::GetInstance().RegisterCoordinationListener();
}
return RET_OK;
}
@ -78,7 +78,7 @@ int32_t CoordinationManagerImpl::UnregisterCoordinationListener(CoordinationList
listenerLabel:
if (isListeningProcess_ && devCoordinationListener_.empty()) {
isListeningProcess_ = false;
return DevicestatusClient::GetInstance().UnregisterCoordinationListener();
return DeviceStatusClient::GetInstance().UnregisterCoordinationListener();
}
return RET_OK;
}
@ -98,7 +98,7 @@ int32_t CoordinationManagerImpl::EnableInputDeviceCoordination(bool enabled, Fun
return RET_ERR;
}
devCoordinationEvent_[userData_] = event;
return DevicestatusClient::GetInstance().EnableInputDeviceCoordination(userData_++, enabled);
return DeviceStatusClient::GetInstance().EnableInputDeviceCoordination(userData_++, enabled);
}
int32_t CoordinationManagerImpl::StartInputDeviceCoordination(const std::string &sinkDeviceId,
@ -117,7 +117,7 @@ int32_t CoordinationManagerImpl::StartInputDeviceCoordination(const std::string
return RET_ERR;
}
devCoordinationEvent_[userData_] = event;
return DevicestatusClient::GetInstance().StartInputDeviceCoordination(
return DeviceStatusClient::GetInstance().StartInputDeviceCoordination(
userData_++, sinkDeviceId, srcInputDeviceId);
}
@ -136,7 +136,7 @@ int32_t CoordinationManagerImpl::StopDeviceCoordination(FuncCoordinationMessage
return RET_ERR;
}
devCoordinationEvent_[userData_] = event;
return DevicestatusClient::GetInstance().StopDeviceCoordination(userData_++);
return DeviceStatusClient::GetInstance().StopDeviceCoordination(userData_++);
}
int32_t CoordinationManagerImpl::GetInputDeviceCoordinationState(
@ -155,7 +155,7 @@ int32_t CoordinationManagerImpl::GetInputDeviceCoordinationState(
return RET_ERR;
}
devCoordinationEvent_[userData_] = event;
return DevicestatusClient::GetInstance().GetInputDeviceCoordinationState(userData_++, deviceId);
return DeviceStatusClient::GetInstance().GetInputDeviceCoordinationState(userData_++, deviceId);
}
void CoordinationManagerImpl::OnDevCoordinationListener(const std::string deviceId, CoordinationMessage msg)

View File

@ -256,12 +256,12 @@ void Client::OnConnected()
int32_t Client::Socket()
{
CALL_DEBUG_ENTER;
int32_t ret = DevicestatusClient::GetInstance().AllocSocketPair(CONNECT_MODULE_TYPE_MMI_CLIENT);
int32_t ret = DeviceStatusClient::GetInstance().AllocSocketPair(CONNECT_MODULE_TYPE_MMI_CLIENT);
if (ret != RET_OK) {
FI_HILOGE("Call AllocSocketPair return %{public}d", ret);
return RET_ERR;
}
fd_ = DevicestatusClient::GetInstance().GetClientSocketFdOfAllocedSocketPair();
fd_ = DeviceStatusClient::GetInstance().GetClientSocketFdOfAllocedSocketPair();
if (fd_ == -1) {
FI_HILOGE("Call GetClientSocketFdOfAllocedSocketPair return invalid fd");
}

View File

@ -23,12 +23,12 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
void DeviceStatusAgent::DeviceStatusAgentCallback::OnDevicestatusChanged(
const DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusAgent::DeviceStatusAgentCallback::OnDeviceStatusChanged(
const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
DEV_HILOGI(INNERKIT, "type=%{public}d, value=%{public}d",
static_cast<DevicestatusDataUtils::DevicestatusType>(devicestatusData.type),
static_cast<DevicestatusDataUtils::DevicestatusValue>(devicestatusData.value));
static_cast<DeviceStatusDataUtils::DeviceStatusType>(devicestatusData.type),
static_cast<DeviceStatusDataUtils::DeviceStatusValue>(devicestatusData.value));
std::shared_ptr<DeviceStatusAgent> agent = agent_.lock();
if (agent == nullptr) {
DEV_HILOGE(SERVICE, "agent is nullptr");
@ -37,7 +37,7 @@ void DeviceStatusAgent::DeviceStatusAgentCallback::OnDevicestatusChanged(
agent->agentEvent_->OnEventResult(devicestatusData);
}
int32_t DeviceStatusAgent::SubscribeAgentEvent(const DevicestatusDataUtils::DevicestatusType& type,
int32_t DeviceStatusAgent::SubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type,
const std::shared_ptr<DeviceStatusAgent::DeviceStatusAgentEvent>& agentEvent)
{
DEV_HILOGI(INNERKIT, "Enter");
@ -45,8 +45,8 @@ int32_t DeviceStatusAgent::SubscribeAgentEvent(const DevicestatusDataUtils::Devi
if (agentEvent == nullptr) {
return ERR_INVALID_VALUE;
}
if (type > DevicestatusDataUtils::DevicestatusType::TYPE_INVALID
&& type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
RegisterServiceEvent(type);
agentEvent_ = agentEvent;
} else {
@ -55,17 +55,17 @@ int32_t DeviceStatusAgent::SubscribeAgentEvent(const DevicestatusDataUtils::Devi
return ERR_OK;
}
int32_t DeviceStatusAgent::UnsubscribeAgentEvent(const DevicestatusDataUtils::DevicestatusType& type)
int32_t DeviceStatusAgent::UnsubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type)
{
if (type > DevicestatusDataUtils::DevicestatusType::TYPE_INVALID
&& type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
UnRegisterServiceEvent(type);
return ERR_OK;
}
return ERR_INVALID_VALUE;
}
void DeviceStatusAgent::RegisterServiceEvent(const DevicestatusDataUtils::DevicestatusType& type)
void DeviceStatusAgent::RegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGI(INNERKIT, "Enter");
callback_ = new (std::nothrow) DeviceStatusAgentCallback(shared_from_this());
@ -73,13 +73,13 @@ void DeviceStatusAgent::RegisterServiceEvent(const DevicestatusDataUtils::Device
DEV_HILOGE(INNERKIT, "callback_ is nullptr");
return;
}
DevicestatusClient::GetInstance().SubscribeCallback(type, callback_);
DeviceStatusClient::GetInstance().SubscribeCallback(type, callback_);
}
void DeviceStatusAgent::UnRegisterServiceEvent(const DevicestatusDataUtils::DevicestatusType& type)
void DeviceStatusAgent::UnRegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGI(INNERKIT, "Enter");
DevicestatusClient::GetInstance().UnsubscribeCallback(type, callback_);
DeviceStatusClient::GetInstance().UnsubscribeCallback(type, callback_);
}
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -25,7 +25,7 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
void DeviceStatusCallbackProxy::OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusCallbackProxy::OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
sptr<IRemoteObject> remote = Remote();
DEVICESTATUS_RETURN_IF(remote == nullptr);

View File

@ -33,11 +33,11 @@ namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DevicestatusClient" };
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DeviceStatusClient" };
} // namespace
DevicestatusClient::DevicestatusClient() {}
DevicestatusClient::~DevicestatusClient()
DeviceStatusClient::DeviceStatusClient() {}
DeviceStatusClient::~DeviceStatusClient()
{
if (devicestatusProxy_ != nullptr) {
auto remoteObject = devicestatusProxy_->AsObject();
@ -47,7 +47,7 @@ DevicestatusClient::~DevicestatusClient()
}
}
ErrCode DevicestatusClient::Connect()
ErrCode DeviceStatusClient::Connect()
{
std::lock_guard<std::mutex> lock(mutex_);
if (devicestatusProxy_ != nullptr) {
@ -67,23 +67,23 @@ ErrCode DevicestatusClient::Connect()
return E_DEVICESTATUS_GET_SERVICE_FAILED;
}
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new DevicestatusDeathRecipient());
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new DeviceStatusDeathRecipient());
if (deathRecipient_ == nullptr) {
DEV_HILOGE(INNERKIT, "Failed to create DevicestatusDeathRecipient");
DEV_HILOGE(INNERKIT, "Failed to create DeviceStatusDeathRecipient");
return ERR_NO_MEMORY;
}
if ((remoteObject_->IsProxyObject()) && (!remoteObject_->AddDeathRecipient(deathRecipient_))) {
DEV_HILOGE(INNERKIT, "Add death recipient to Devicestatus service failed");
DEV_HILOGE(INNERKIT, "Add death recipient to DeviceStatus service failed");
return E_DEVICESTATUS_ADD_DEATH_RECIPIENT_FAILED;
}
devicestatusProxy_ = iface_cast<Idevicestatus>(remoteObject_);
DEV_HILOGD(INNERKIT, "Connecting DevicestatusService success");
DEV_HILOGD(INNERKIT, "Connecting DeviceStatusService success");
return ERR_OK;
}
void DevicestatusClient::ResetProxy(const wptr<IRemoteObject>& remote)
void DeviceStatusClient::ResetProxy(const wptr<IRemoteObject>& remote)
{
std::lock_guard<std::mutex> lock(mutex_);
DEVICESTATUS_RETURN_IF(devicestatusProxy_ == nullptr);
@ -95,18 +95,18 @@ void DevicestatusClient::ResetProxy(const wptr<IRemoteObject>& remote)
}
}
void DevicestatusClient::DevicestatusDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
void DeviceStatusClient::DeviceStatusDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
if (remote == nullptr) {
DEV_HILOGE(INNERKIT, "OnRemoteDied failed, remote is nullptr");
return;
}
DevicestatusClient::GetInstance().ResetProxy(remote);
DeviceStatusClient::GetInstance().ResetProxy(remote);
DEV_HILOGD(INNERKIT, "Recv death notice");
}
void DevicestatusClient::SubscribeCallback(const DevicestatusDataUtils::DevicestatusType& type, \
void DeviceStatusClient::SubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGD(INNERKIT, "Enter");
@ -115,15 +115,15 @@ void DevicestatusClient::SubscribeCallback(const DevicestatusDataUtils::Devicest
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
return;
}
if (type > DevicestatusDataUtils::DevicestatusType::TYPE_INVALID
&& type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
devicestatusProxy_->Subscribe(type, callback);
}
return;
DEV_HILOGD(INNERKIT, "Exit");
}
void DevicestatusClient::UnsubscribeCallback(const DevicestatusDataUtils::DevicestatusType& type, \
void DeviceStatusClient::UnsubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGD(INNERKIT, "Enter");
@ -132,57 +132,57 @@ void DevicestatusClient::UnsubscribeCallback(const DevicestatusDataUtils::Device
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
return;
}
if (type > DevicestatusDataUtils::DevicestatusType::TYPE_INVALID
&& type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
devicestatusProxy_->Unsubscribe(type, callback);
}
return;
DEV_HILOGD(INNERKIT, "Exit");
}
DevicestatusDataUtils::DevicestatusData DevicestatusClient::GetDevicestatusData(const \
DevicestatusDataUtils::DevicestatusType& type)
DeviceStatusDataUtils::DeviceStatusData DeviceStatusClient::GetDeviceStatusData(const \
DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGD(INNERKIT, "Enter");
DevicestatusDataUtils::DevicestatusData devicestatusData;
devicestatusData.type = DevicestatusDataUtils::DevicestatusType::TYPE_INVALID;
devicestatusData.value = DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID;
DeviceStatusDataUtils::DeviceStatusData devicestatusData;
devicestatusData.type = DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
devicestatusData.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), devicestatusData);
if (devicestatusProxy_ == nullptr) {
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
return devicestatusData;
}
if (type > DevicestatusDataUtils::DevicestatusType::TYPE_INVALID
&& type <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
devicestatusData = devicestatusProxy_->GetCache(type);
}
DEV_HILOGD(INNERKIT, "Exit");
return devicestatusData;
}
int32_t DevicestatusClient::RegisterCoordinationListener()
int32_t DeviceStatusClient::RegisterCoordinationListener()
{
CALL_DEBUG_ENTER;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
return devicestatusProxy_->RegisterCoordinationListener();
}
int32_t DevicestatusClient::UnregisterCoordinationListener()
int32_t DeviceStatusClient::UnregisterCoordinationListener()
{
CALL_DEBUG_ENTER;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
return devicestatusProxy_->UnregisterCoordinationListener();
}
int32_t DevicestatusClient::EnableInputDeviceCoordination(int32_t userData, bool enabled)
int32_t DeviceStatusClient::EnableInputDeviceCoordination(int32_t userData, bool enabled)
{
CALL_DEBUG_ENTER;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
return devicestatusProxy_->EnableInputDeviceCoordination(userData, enabled);
}
int32_t DevicestatusClient::StartInputDeviceCoordination(int32_t userData,
int32_t DeviceStatusClient::StartInputDeviceCoordination(int32_t userData,
const std::string &sinkDeviceId, int32_t srcInputDeviceId)
{
CALL_DEBUG_ENTER;
@ -190,14 +190,14 @@ int32_t DevicestatusClient::StartInputDeviceCoordination(int32_t userData,
return devicestatusProxy_->StartInputDeviceCoordination(userData, sinkDeviceId, srcInputDeviceId);
}
int32_t DevicestatusClient::StopDeviceCoordination(int32_t userData)
int32_t DeviceStatusClient::StopDeviceCoordination(int32_t userData)
{
CALL_DEBUG_ENTER;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
return devicestatusProxy_->StopDeviceCoordination(userData);
}
int32_t DevicestatusClient::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
int32_t DeviceStatusClient::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
{
CALL_DEBUG_ENTER;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
@ -205,7 +205,7 @@ int32_t DevicestatusClient::GetInputDeviceCoordinationState(int32_t userData, co
}
int32_t DevicestatusClient::AllocSocketPair(const int32_t moduleType)
int32_t DeviceStatusClient::AllocSocketPair(const int32_t moduleType)
{
CALL_DEBUG_ENTER;
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
@ -226,7 +226,7 @@ int32_t DevicestatusClient::AllocSocketPair(const int32_t moduleType)
return RET_OK;
}
int32_t DevicestatusClient::GetClientSocketFdOfAllocedSocketPair() const
int32_t DeviceStatusClient::GetClientSocketFdOfAllocedSocketPair() const
{
CALL_DEBUG_ENTER;
return socketFd_;

View File

@ -29,10 +29,10 @@ namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DevicestatusSrvProxy" };
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DeviceStatusSrvProxy" };
} // namespace
void DevicestatusSrvProxy::Subscribe(const DevicestatusDataUtils::DevicestatusType& type, \
void DeviceStatusSrvProxy::Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGD(INNERKIT, "Enter");
@ -44,7 +44,7 @@ void DevicestatusSrvProxy::Subscribe(const DevicestatusDataUtils::DevicestatusTy
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
DEV_HILOGE(INNERKIT, "Write descriptor failed");
return;
}
@ -61,7 +61,7 @@ void DevicestatusSrvProxy::Subscribe(const DevicestatusDataUtils::DevicestatusTy
DEV_HILOGD(INNERKIT, "Exit");
}
void DevicestatusSrvProxy::Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type,
void DeviceStatusSrvProxy::Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGD(INNERKIT, "Enter");
@ -73,7 +73,7 @@ void DevicestatusSrvProxy::Unsubscribe(const DevicestatusDataUtils::Devicestatus
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
DEV_HILOGE(INNERKIT, "Write descriptor failed!");
return;
}
@ -91,13 +91,13 @@ void DevicestatusSrvProxy::Unsubscribe(const DevicestatusDataUtils::Devicestatus
DEV_HILOGD(INNERKIT, "Exit");
}
DevicestatusDataUtils::DevicestatusData DevicestatusSrvProxy::GetCache(const \
DevicestatusDataUtils::DevicestatusType& type)
DeviceStatusDataUtils::DeviceStatusData DeviceStatusSrvProxy::GetCache(const \
DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGD(INNERKIT, "Enter");
DevicestatusDataUtils::DevicestatusData devicestatusData;
devicestatusData.type = DevicestatusDataUtils::DevicestatusType::TYPE_INVALID;
devicestatusData.value = DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID;
DeviceStatusDataUtils::DeviceStatusData devicestatusData;
devicestatusData.type = DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
devicestatusData.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
sptr<IRemoteObject> remote = Remote();
DEVICESTATUS_RETURN_IF_WITH_RET((remote == nullptr), devicestatusData);
@ -106,7 +106,7 @@ DevicestatusDataUtils::DevicestatusData DevicestatusSrvProxy::GetCache(const \
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
DEV_HILOGE(INNERKIT, "Write descriptor failed!");
return devicestatusData;
}
@ -123,18 +123,18 @@ DevicestatusDataUtils::DevicestatusData DevicestatusSrvProxy::GetCache(const \
int32_t devicestatusValue = -1;
READINT32(reply, devicestatusType, devicestatusData);
READINT32(reply, devicestatusValue, devicestatusData);
devicestatusData.type = DevicestatusDataUtils::DevicestatusType(devicestatusType);
devicestatusData.value = DevicestatusDataUtils::DevicestatusValue(devicestatusValue);
devicestatusData.type = DeviceStatusDataUtils::DeviceStatusType(devicestatusType);
devicestatusData.value = DeviceStatusDataUtils::DeviceStatusValue(devicestatusValue);
DEV_HILOGD(INNERKIT, "type: %{public}d, value: %{public}d", devicestatusData.type, devicestatusData.value);
DEV_HILOGD(INNERKIT, "Exit");
return devicestatusData;
}
int32_t DevicestatusSrvProxy::RegisterCoordinationListener()
int32_t DeviceStatusSrvProxy::RegisterCoordinationListener()
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
@ -149,11 +149,11 @@ int32_t DevicestatusSrvProxy::RegisterCoordinationListener()
return ret;
}
int32_t DevicestatusSrvProxy::UnregisterCoordinationListener()
int32_t DeviceStatusSrvProxy::UnregisterCoordinationListener()
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
@ -168,11 +168,11 @@ int32_t DevicestatusSrvProxy::UnregisterCoordinationListener()
return ret;
}
int32_t DevicestatusSrvProxy::EnableInputDeviceCoordination(int32_t userData, bool enabled)
int32_t DeviceStatusSrvProxy::EnableInputDeviceCoordination(int32_t userData, bool enabled)
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
@ -189,12 +189,12 @@ int32_t DevicestatusSrvProxy::EnableInputDeviceCoordination(int32_t userData, bo
return ret;
}
int32_t DevicestatusSrvProxy::StartInputDeviceCoordination(int32_t userData, const std::string &sinkDeviceId,
int32_t DeviceStatusSrvProxy::StartInputDeviceCoordination(int32_t userData, const std::string &sinkDeviceId,
int32_t srcInputDeviceId)
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
@ -212,11 +212,11 @@ int32_t DevicestatusSrvProxy::StartInputDeviceCoordination(int32_t userData, con
return ret;
}
int32_t DevicestatusSrvProxy::StopDeviceCoordination(int32_t userData)
int32_t DeviceStatusSrvProxy::StopDeviceCoordination(int32_t userData)
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
@ -232,11 +232,11 @@ int32_t DevicestatusSrvProxy::StopDeviceCoordination(int32_t userData)
return ret;
}
int32_t DevicestatusSrvProxy::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
int32_t DeviceStatusSrvProxy::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
@ -253,12 +253,12 @@ int32_t DevicestatusSrvProxy::GetInputDeviceCoordinationState(int32_t userData,
return ret;
}
int32_t DevicestatusSrvProxy::AllocSocketFd(const std::string &programName, const int32_t moduleType,
int32_t DeviceStatusSrvProxy::AllocSocketFd(const std::string &programName, const int32_t moduleType,
int32_t &socketFd, int32_t &tokenType)
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DevicestatusSrvProxy::GetDescriptor())) {
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}

View File

@ -31,25 +31,25 @@ public:
class DeviceStatusAgentEvent {
public:
virtual ~DeviceStatusAgentEvent() = default;
virtual bool OnEventResult(const DevicestatusDataUtils::DevicestatusData& devicestatusData) = 0;
virtual bool OnEventResult(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) = 0;
};
class DeviceStatusAgentCallback : public DevicestatusCallbackStub {
class DeviceStatusAgentCallback : public DeviceStatusCallbackStub {
public:
explicit DeviceStatusAgentCallback(std::shared_ptr<DeviceStatusAgent> agent) : agent_(agent) {};
virtual ~DeviceStatusAgentCallback() {};
void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
private:
std::weak_ptr<DeviceStatusAgent> agent_;
};
int32_t SubscribeAgentEvent(const DevicestatusDataUtils::DevicestatusType& type,
int32_t SubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type,
const std::shared_ptr<DeviceStatusAgent::DeviceStatusAgentEvent>& agentEvent);
int32_t UnsubscribeAgentEvent(const DevicestatusDataUtils::DevicestatusType& type);
int32_t UnsubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type);
friend class DeviceStatusAgentCallback;
private:
void RegisterServiceEvent(const DevicestatusDataUtils::DevicestatusType& type);
void UnRegisterServiceEvent(const DevicestatusDataUtils::DevicestatusType& type);
void RegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type);
void UnRegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type);
sptr<IdevicestatusCallback> callback_;
std::shared_ptr<DeviceStatusAgentEvent> agentEvent_;
};

View File

@ -31,7 +31,7 @@ public:
: IRemoteProxy<IdevicestatusCallback>(impl) {}
~DeviceStatusCallbackProxy() = default;
DISALLOW_COPY_AND_MOVE(DeviceStatusCallbackProxy);
virtual void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
private:
static inline BrokerDelegator<DeviceStatusCallbackProxy> delegator_;

View File

@ -27,17 +27,17 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusClient final : public DelayedRefSingleton<DevicestatusClient> {
DECLARE_DELAYED_REF_SINGLETON(DevicestatusClient)
class DeviceStatusClient final : public DelayedRefSingleton<DeviceStatusClient> {
DECLARE_DELAYED_REF_SINGLETON(DeviceStatusClient)
public:
DISALLOW_COPY_AND_MOVE(DevicestatusClient);
DISALLOW_COPY_AND_MOVE(DeviceStatusClient);
void SubscribeCallback(const DevicestatusDataUtils::DevicestatusType& type, \
void SubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback);
void UnsubscribeCallback(const DevicestatusDataUtils::DevicestatusType& type, \
void UnsubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback);
DevicestatusDataUtils::DevicestatusData GetDevicestatusData(const DevicestatusDataUtils::DevicestatusType& type);
DeviceStatusDataUtils::DeviceStatusData GetDeviceStatusData(const DeviceStatusDataUtils::DeviceStatusType& type);
int32_t RegisterCoordinationListener();
int32_t UnregisterCoordinationListener();
@ -49,13 +49,13 @@ public:
int32_t AllocSocketPair(const int32_t moduleType);
int32_t GetClientSocketFdOfAllocedSocketPair() const;
private:
class DevicestatusDeathRecipient : public IRemoteObject::DeathRecipient {
class DeviceStatusDeathRecipient : public IRemoteObject::DeathRecipient {
public:
DevicestatusDeathRecipient() = default;
~DevicestatusDeathRecipient() = default;
DeviceStatusDeathRecipient() = default;
~DeviceStatusDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject>& remote);
private:
DISALLOW_COPY_AND_MOVE(DevicestatusDeathRecipient);
DISALLOW_COPY_AND_MOVE(DeviceStatusDeathRecipient);
};
ErrCode Connect();

View File

@ -21,9 +21,9 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusDataUtils {
class DeviceStatusDataUtils {
public:
enum DevicestatusType {
enum DeviceStatusType {
TYPE_INVALID = -1,
TYPE_HIGH_STILL,
TYPE_FINE_STILL,
@ -33,7 +33,7 @@ public:
TYPE_MAX
};
enum DevicestatusValue {
enum DeviceStatusValue {
VALUE_INVALID = -1,
VALUE_ENTER,
VALUE_EXIT
@ -44,9 +44,9 @@ public:
VALID
};
struct DevicestatusData {
DevicestatusType type;
DevicestatusValue value;
struct DeviceStatusData {
DeviceStatusType type;
DeviceStatusValue value;
};
};
@ -56,11 +56,11 @@ typedef struct DeviceStatusJsonData {
}DeviceStatusJsonD;
static DeviceStatusJsonD DeviceStatusJson[] = {
{DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL, "TYPE_HIGH_STILL"},
{DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL, "TYPE_FINE_STILL"},
{DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH, "TYPE_CAR_BLUETOOTH"},
{DevicestatusDataUtils::DevicestatusType::TYPE_STAND, "TYPE_STAND"},
{DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, "TYPE_LID_OPEN"}
{DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, "TYPE_HIGH_STILL"},
{DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL, "TYPE_FINE_STILL"},
{DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH, "TYPE_CAR_BLUETOOTH"},
{DeviceStatusDataUtils::DeviceStatusType::TYPE_STAND, "TYPE_STAND"},
{DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, "TYPE_LID_OPEN"}
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -24,19 +24,19 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusSrvProxy : public IRemoteProxy<Idevicestatus> {
class DeviceStatusSrvProxy : public IRemoteProxy<Idevicestatus> {
public:
explicit DevicestatusSrvProxy(const sptr<IRemoteObject>& impl)
explicit DeviceStatusSrvProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<Idevicestatus>(impl) {}
~DevicestatusSrvProxy() = default;
DISALLOW_COPY_AND_MOVE(DevicestatusSrvProxy);
~DeviceStatusSrvProxy() = default;
DISALLOW_COPY_AND_MOVE(DeviceStatusSrvProxy);
virtual void Subscribe(const DevicestatusDataUtils::DevicestatusType& type, \
virtual void Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback) override;
virtual void Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type, \
virtual void Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback) override;
virtual DevicestatusDataUtils::DevicestatusData GetCache(const \
DevicestatusDataUtils::DevicestatusType& type) override;
virtual DeviceStatusDataUtils::DeviceStatusData GetCache(const \
DeviceStatusDataUtils::DeviceStatusType& type) override;
virtual int32_t RegisterCoordinationListener() override;
virtual int32_t UnregisterCoordinationListener() override;
@ -50,7 +50,7 @@ public:
int32_t &socketFd, int32_t &tokenType) override;
private:
static inline BrokerDelegator<DevicestatusSrvProxy> delegator_;
static inline BrokerDelegator<DeviceStatusSrvProxy> delegator_;
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -40,11 +40,11 @@ public:
ALLOC_SOCKET_FD = 40
};
virtual void Subscribe(const DevicestatusDataUtils::DevicestatusType& type, \
virtual void Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback) = 0;
virtual void Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type, \
virtual void Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
const sptr<IdevicestatusCallback>& callback) = 0;
virtual DevicestatusDataUtils::DevicestatusData GetCache(const DevicestatusDataUtils::DevicestatusType& type) = 0;
virtual DeviceStatusDataUtils::DeviceStatusData GetCache(const DeviceStatusDataUtils::DeviceStatusType& type) = 0;
virtual int32_t RegisterCoordinationListener() = 0;
virtual int32_t UnregisterCoordinationListener() = 0;

View File

@ -25,7 +25,7 @@ namespace Msdp {
namespace DeviceStatus {
class IdevicestatusAlgorithmCallback : public IRemoteBroker {
public:
virtual void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& data) = 0;
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& data) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.IdevicestatusAlgorithmCallback");
};

View File

@ -30,7 +30,7 @@ public:
DEVICESTATUS_CHANGE = 0,
};
virtual void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData) = 0;
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.IdevicestatusCallback");
};

View File

@ -25,14 +25,14 @@ namespace Msdp {
namespace DeviceStatus {
class IdevicestatusStorage : public IRemoteBroker {
public:
struct DevicestatusRecord {
DevicestatusDataUtils::DevicestatusType type;
DevicestatusDataUtils::DevicestatusValue value;
struct DeviceStatusRecord {
DeviceStatusDataUtils::DeviceStatusType type;
DeviceStatusDataUtils::DeviceStatusValue value;
std::string date;
std::string time;
};
virtual bool Save(DevicestatusRecord record) = 0;
virtual bool Save(DeviceStatusRecord record) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.IdevicestatusStorage");
};

View File

@ -40,11 +40,11 @@ class DeviceStatusDataParse {
public:
DeviceStatusDataParse() = default;
~DeviceStatusDataParse() = default;
bool ParseDeviceStatusData(DevicestatusDataUtils::DevicestatusData& data,
DevicestatusDataUtils::DevicestatusType& type);
bool DisableCount(const DevicestatusDataUtils::DevicestatusType& type);
bool DataInit(const std::string& fileData, bool logStatus, DevicestatusDataUtils::DevicestatusType& type,
DevicestatusDataUtils::DevicestatusData& data);
bool ParseDeviceStatusData(DeviceStatusDataUtils::DeviceStatusData& data,
DeviceStatusDataUtils::DeviceStatusType& type);
bool DisableCount(const DeviceStatusDataUtils::DeviceStatusType& type);
bool DataInit(const std::string& fileData, bool logStatus, DeviceStatusDataUtils::DeviceStatusType& type,
DeviceStatusDataUtils::DeviceStatusData& data);
int32_t CreateJsonFile();
private:

View File

@ -29,7 +29,7 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DeviceStatusMsdpMock final : public DevicestatusMsdpInterface {
class DeviceStatusMsdpMock final : public DeviceStatusMsdpInterface {
public:
DeviceStatusMsdpMock() = default;
~DeviceStatusMsdpMock() = default;
@ -47,12 +47,12 @@ public:
int32_t RegisterTimerCallback(const int32_t fd, const EventType et);
void StartThread();
void LoopingThreadEntry();
void Enable(DevicestatusDataUtils::DevicestatusType type) override;
void Disable(DevicestatusDataUtils::DevicestatusType type) override;
void DisableCount(DevicestatusDataUtils::DevicestatusType type) override;
void Enable(DeviceStatusDataUtils::DeviceStatusType type) override;
void Disable(DeviceStatusDataUtils::DeviceStatusType type) override;
void DisableCount(DeviceStatusDataUtils::DeviceStatusType type) override;
void RegisterCallback(std::shared_ptr<MsdpAlgorithmCallback> callback) override;
void UnregisterCallback() override;
ErrCode NotifyMsdpImpl(const DevicestatusDataUtils::DevicestatusData& data);
ErrCode NotifyMsdpImpl(const DeviceStatusDataUtils::DeviceStatusData& data);
void GetDeviceStatusData();
std::shared_ptr<MsdpAlgorithmCallback> GetCallbackImpl()
{

View File

@ -26,29 +26,29 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusMsdpInterface {
class DeviceStatusMsdpInterface {
public:
DevicestatusMsdpInterface() {}
virtual ~DevicestatusMsdpInterface() {}
DeviceStatusMsdpInterface() {}
virtual ~DeviceStatusMsdpInterface() {}
class MsdpAlgorithmCallback {
public:
MsdpAlgorithmCallback() = default;
virtual ~MsdpAlgorithmCallback() = default;
virtual void OnResult(const DevicestatusDataUtils::DevicestatusData& data) = 0;
virtual void OnResult(const DeviceStatusDataUtils::DeviceStatusData& data) = 0;
};
virtual void RegisterCallback(std::shared_ptr<MsdpAlgorithmCallback> callback) = 0;
virtual void UnregisterCallback() = 0;
virtual void Enable(DevicestatusDataUtils::DevicestatusType type) = 0;
virtual void Disable(DevicestatusDataUtils::DevicestatusType type) = 0;
virtual void DisableCount(DevicestatusDataUtils::DevicestatusType type) = 0;
virtual void Enable(DeviceStatusDataUtils::DeviceStatusType type) = 0;
virtual void Disable(DeviceStatusDataUtils::DeviceStatusType type) = 0;
virtual void DisableCount(DeviceStatusDataUtils::DeviceStatusType type) = 0;
};
struct MsdpAlgorithmHandle {
void* handle;
DevicestatusMsdpInterface* (*create)();
void* (*destroy)(DevicestatusMsdpInterface*);
DevicestatusMsdpInterface* pAlgorithm;
DeviceStatusMsdpInterface* (*create)();
void* (*destroy)(DeviceStatusMsdpInterface*);
DeviceStatusMsdpInterface* pAlgorithm;
MsdpAlgorithmHandle() : handle(nullptr), create(nullptr), destroy(nullptr), pAlgorithm(nullptr) {}
~MsdpAlgorithmHandle() {}
void Clear()

View File

@ -27,11 +27,11 @@ const std::string MSDP_DATA_DIR = "/data/msdp";
} // namespace
std::vector<int32_t> DeviceStatusDataParse::tempcount_ =
std::vector<int32_t> (static_cast<int32_t>(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN),
static_cast<int32_t>(DevicestatusDataUtils::Value::INVALID));
std::vector<int32_t> (static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN),
static_cast<int32_t>(DeviceStatusDataUtils::Value::INVALID));
bool DeviceStatusDataParse::ParseDeviceStatusData(DevicestatusDataUtils::DevicestatusData& data,
DevicestatusDataUtils::DevicestatusType& type)
bool DeviceStatusDataParse::ParseDeviceStatusData(DeviceStatusDataUtils::DeviceStatusData& data,
DeviceStatusDataUtils::DeviceStatusType& type)
{
std::string jsonBuf = ReadJsonFile(MSDP_DATA_PATH.c_str());
if (jsonBuf.empty()) {
@ -41,20 +41,20 @@ bool DeviceStatusDataParse::ParseDeviceStatusData(DevicestatusDataUtils::Devices
}
bool DeviceStatusDataParse::DataInit(const std::string& fileData, bool logStatus,
DevicestatusDataUtils::DevicestatusType& type, DevicestatusDataUtils::DevicestatusData& data)
DeviceStatusDataUtils::DeviceStatusType& type, DeviceStatusDataUtils::DeviceStatusData& data)
{
DEV_HILOGD(SERVICE, "Enter");
JsonParser parser;
parser.json_ = cJSON_Parse(fileData.c_str());
data.type = type;
data.value = DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID;
data.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
if (cJSON_IsArray(parser.json_)) {
DEV_HILOGE(SERVICE, "parser is array");
return false;
}
if (type < DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL ||
type >= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type < DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL ||
type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
DEV_HILOGE(SERVICE, "Type error");
return false;
}
@ -70,16 +70,16 @@ bool DeviceStatusDataParse::DataInit(const std::string& fileData, bool logStatus
return false;
}
tempcount_[type]++;
data.value = static_cast<DevicestatusDataUtils::DevicestatusValue>(mockvalue->valueint);
data.value = static_cast<DeviceStatusDataUtils::DeviceStatusValue>(mockvalue->valueint);
DEV_HILOGD(SERVICE, "type:%{public}d, status:%{public}d", data.type, data.value);
return true;
}
bool DeviceStatusDataParse::DisableCount(const DevicestatusDataUtils::DevicestatusType& type)
bool DeviceStatusDataParse::DisableCount(const DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGD(SERVICE, "Enter");
tempcount_[static_cast<int32_t>(type)] =
static_cast<int32_t>(DevicestatusDataUtils::DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID);
static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID);
return true;
}

View File

@ -37,8 +37,8 @@ DeviceStatusMsdpMock* g_msdpMock = nullptr;
} // namespace
std::vector<int32_t> DeviceStatusMsdpMock::enabledType_ =
std::vector<int32_t> (static_cast<int32_t>(DevicestatusDataUtils::DevicestatusType::TYPE_MAX),
static_cast<int32_t>(DevicestatusDataUtils::Value::INVALID));
std::vector<int32_t> (static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusType::TYPE_MAX),
static_cast<int32_t>(DeviceStatusDataUtils::Value::INVALID));
bool DeviceStatusMsdpMock::Init()
{
@ -67,19 +67,19 @@ void DeviceStatusMsdpMock::UnregisterCallback()
callback_ = nullptr;
}
void DeviceStatusMsdpMock::Enable(DevicestatusDataUtils::DevicestatusType type)
void DeviceStatusMsdpMock::Enable(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGD(SERVICE, "Enter");
if (type < DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL ||
type >= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN) {
if (type < DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL ||
type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
DEV_HILOGE(SERVICE, "Type error");
}
enabledType_[type] = static_cast<int32_t>(DevicestatusDataUtils::Value::VALID);
enabledType_[type] = static_cast<int32_t>(DeviceStatusDataUtils::Value::VALID);
Init();
DEV_HILOGD(SERVICE, "Exit");
}
void DeviceStatusMsdpMock::Disable(DevicestatusDataUtils::DevicestatusType type)
void DeviceStatusMsdpMock::Disable(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGD(SERVICE, "Enter");
scFlag_ = false;
@ -87,15 +87,15 @@ void DeviceStatusMsdpMock::Disable(DevicestatusDataUtils::DevicestatusType type)
DEV_HILOGD(SERVICE, "Exit");
}
void DeviceStatusMsdpMock::DisableCount(DevicestatusDataUtils::DevicestatusType type)
void DeviceStatusMsdpMock::DisableCount(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGD(SERVICE, "Enter");
enabledType_[type] = static_cast<int32_t>(DevicestatusDataUtils::Value::INVALID);
enabledType_[type] = static_cast<int32_t>(DeviceStatusDataUtils::Value::INVALID);
dataParse_->DisableCount(type);
DEV_HILOGD(SERVICE, "Exit");
}
ErrCode DeviceStatusMsdpMock::NotifyMsdpImpl(const DevicestatusDataUtils::DevicestatusData& data)
ErrCode DeviceStatusMsdpMock::NotifyMsdpImpl(const DeviceStatusDataUtils::DeviceStatusData& data)
{
DEV_HILOGD(SERVICE, "Enter");
if (g_msdpMock == nullptr) {
@ -177,11 +177,11 @@ void DeviceStatusMsdpMock::TimerCallback()
void DeviceStatusMsdpMock::GetDeviceStatusData()
{
DevicestatusDataUtils::DevicestatusData data;
for (int32_t i = int(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL);
i <= DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN; ++i) {
if (enabledType_[i] == static_cast<int32_t>(DevicestatusDataUtils::Value::VALID)) {
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType(i);
DeviceStatusDataUtils::DeviceStatusData data;
for (int32_t i = int(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL);
i <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN; ++i) {
if (enabledType_[i] == static_cast<int32_t>(DeviceStatusDataUtils::Value::VALID)) {
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType(i);
DEV_HILOGE(SERVICE, "type:%{public}d", type);
if (dataParse_ == nullptr) {
DEV_HILOGE(SERVICE, "dataParse_ is nullptr");
@ -240,14 +240,14 @@ void DeviceStatusMsdpMock::LoopingThreadEntry()
}
}
extern "C" DevicestatusMsdpInterface *Create(void)
extern "C" DeviceStatusMsdpInterface *Create(void)
{
DEV_HILOGI(SERVICE, "Enter");
g_msdpMock = new DeviceStatusMsdpMock();
return g_msdpMock;
}
extern "C" void Destroy(const DevicestatusMsdpInterface* algorithm)
extern "C" void Destroy(const DeviceStatusMsdpInterface* algorithm)
{
DEV_HILOGI(SERVICE, "Enter");
delete algorithm;

View File

@ -46,34 +46,34 @@ struct AppInfo {
int32_t pid = 0;
Security::AccessToken::AccessTokenID tokenId;
std::string packageName;
DevicestatusDataUtils::DevicestatusType type;
DeviceStatusDataUtils::DeviceStatusType type;
sptr<IdevicestatusCallback> callback;
};
struct DeviceStatusRecord {
std::string startTime;
DevicestatusDataUtils::DevicestatusData data;
DeviceStatusDataUtils::DeviceStatusData data;
};
class DevicestatusDumper final : public RefBase,
public Singleton<DevicestatusDumper> {
class DeviceStatusDumper final : public RefBase,
public Singleton<DeviceStatusDumper> {
public:
DevicestatusDumper() = default;
~DevicestatusDumper() = default;
DeviceStatusDumper() = default;
~DeviceStatusDumper() = default;
void ParseCommand(int32_t fd, const std::vector<std::string> &args,
const std::vector<DevicestatusDataUtils::DevicestatusData> &datas);
const std::vector<DeviceStatusDataUtils::DeviceStatusData> &datas);
void DumpHelpInfo(int32_t fd) const;
void DumpDevicestatusSubscriber(int32_t fd);
void DumpDevicestatusChanges(int32_t fd);
void DumpDevicestatusCurrentStatus(int32_t fd,
const std::vector<DevicestatusDataUtils::DevicestatusData> &datas) const;
void DumpDeviceStatusSubscriber(int32_t fd);
void DumpDeviceStatusChanges(int32_t fd);
void DumpDeviceStatusCurrentStatus(int32_t fd,
const std::vector<DeviceStatusDataUtils::DeviceStatusData> &datas) const;
void SaveAppInfo(std::shared_ptr<AppInfo> appInfo);
void RemoveAppInfo(std::shared_ptr<AppInfo> appInfo);
void pushDeviceStatus(const DevicestatusDataUtils::DevicestatusData& data);
void pushDeviceStatus(const DeviceStatusDataUtils::DeviceStatusData& data);
private:
DISALLOW_COPY_AND_MOVE(DevicestatusDumper);
DISALLOW_COPY_AND_MOVE(DeviceStatusDumper);
void DumpCurrentTime(std::string &startTime) const;
std::string GetStatusType(const DevicestatusDataUtils::DevicestatusType &type) const;
std::string GetDeviceState(const DevicestatusDataUtils::DevicestatusValue &type) const;
std::map<DevicestatusDataUtils::DevicestatusType, std::set<std::shared_ptr<AppInfo>>> \
std::string GetStatusType(const DeviceStatusDataUtils::DeviceStatusType &type) const;
std::string GetDeviceState(const DeviceStatusDataUtils::DeviceStatusValue &type) const;
std::map<DeviceStatusDataUtils::DeviceStatusType, std::set<std::shared_ptr<AppInfo>>> \
appInfoMap_;
std::queue<std::shared_ptr<DeviceStatusRecord>> deviceStatusQueue_;
std::mutex mutex_;

View File

@ -31,33 +31,33 @@ namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
using namespace Security::AccessToken;
class DevicestatusService;
class DevicestatusManager {
class DeviceStatusService;
class DeviceStatusManager {
public:
explicit DevicestatusManager(const wptr<DevicestatusService>& ms) : ms_(ms)
explicit DeviceStatusManager(const wptr<DeviceStatusService>& ms) : ms_(ms)
{
DEV_HILOGI(SERVICE, "DevicestatusManager instance is created.");
DEV_HILOGI(SERVICE, "DeviceStatusManager instance is created.");
}
~DevicestatusManager() = default;
~DeviceStatusManager() = default;
class DevicestatusCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
class DeviceStatusCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
public:
DevicestatusCallbackDeathRecipient() = default;
DeviceStatusCallbackDeathRecipient() = default;
virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
virtual ~DevicestatusCallbackDeathRecipient() = default;
virtual ~DeviceStatusCallbackDeathRecipient() = default;
};
bool Init();
bool EnableMock(DevicestatusDataUtils::DevicestatusType type);
bool InitInterface(DevicestatusDataUtils::DevicestatusType type);
bool DisableMock(DevicestatusDataUtils::DevicestatusType type);
bool EnableMock(DeviceStatusDataUtils::DeviceStatusType type);
bool InitInterface(DeviceStatusDataUtils::DeviceStatusType type);
bool DisableMock(DeviceStatusDataUtils::DeviceStatusType type);
bool InitDataCallback();
void NotifyDevicestatusChange(const DevicestatusDataUtils::DevicestatusData& devicestatusData);
void Subscribe(const DevicestatusDataUtils::DevicestatusType& type, const sptr<IdevicestatusCallback>& callback);
void Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type, const sptr<IdevicestatusCallback>& callback);
DevicestatusDataUtils::DevicestatusData GetLatestDevicestatusData(const \
DevicestatusDataUtils::DevicestatusType& type);
int32_t MsdpDataCallback(const DevicestatusDataUtils::DevicestatusData& data);
void NotifyDeviceStatusChange(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData);
void Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, const sptr<IdevicestatusCallback>& callback);
void Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type, const sptr<IdevicestatusCallback>& callback);
DeviceStatusDataUtils::DeviceStatusData GetLatestDeviceStatusData(const \
DeviceStatusDataUtils::DeviceStatusType& type);
int32_t MsdpDataCallback(const DeviceStatusDataUtils::DeviceStatusData& data);
int32_t LoadAlgorithm(bool bCreate);
int32_t UnloadAlgorithm(bool bCreate);
void GetPackageName(AccessTokenID tokenId, std::string &packageName);
@ -69,12 +69,12 @@ private:
return l->AsObject() < r->AsObject();
}
};
const wptr<DevicestatusService> ms_;
const wptr<DeviceStatusService> ms_;
std::mutex mutex_;
sptr<IRemoteObject::DeathRecipient> devicestatusCBDeathRecipient_;
std::unique_ptr<DevicestatusMsdpClientImpl> msdpImpl_;
std::map<DevicestatusDataUtils::DevicestatusType, DevicestatusDataUtils::DevicestatusValue> msdpData_;
std::map<DevicestatusDataUtils::DevicestatusType, std::set<const sptr<IdevicestatusCallback>, classcomp>> \
std::unique_ptr<DeviceStatusMsdpClientImpl> msdpImpl_;
std::map<DeviceStatusDataUtils::DeviceStatusType, DeviceStatusDataUtils::DeviceStatusValue> msdpData_;
std::map<DeviceStatusDataUtils::DeviceStatusType, std::set<const sptr<IdevicestatusCallback>, classcomp>> \
listenerMap_;
};
} // namespace DeviceStatus

View File

@ -38,28 +38,28 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusMsdpClientImpl : public DevicestatusMsdpInterface::MsdpAlgorithmCallback {
class DeviceStatusMsdpClientImpl : public DeviceStatusMsdpInterface::MsdpAlgorithmCallback {
public:
using CallbackManager = std::function<int32_t(const DevicestatusDataUtils::DevicestatusData&)>;
using CallbackManager = std::function<int32_t(const DeviceStatusDataUtils::DeviceStatusData&)>;
ErrCode InitMsdpImpl(DevicestatusDataUtils::DevicestatusType type);
ErrCode DisableMsdpImpl(DevicestatusDataUtils::DevicestatusType type);
ErrCode InitMsdpImpl(DeviceStatusDataUtils::DeviceStatusType type);
ErrCode DisableMsdpImpl(DeviceStatusDataUtils::DeviceStatusType type);
ErrCode RegisterImpl(const CallbackManager& callback);
ErrCode UnregisterImpl();
int32_t MsdpCallback(const DevicestatusDataUtils::DevicestatusData& data);
int32_t MsdpCallback(const DeviceStatusDataUtils::DeviceStatusData& data);
ErrCode RegisterMsdp();
ErrCode UnregisterMsdp(void);
DevicestatusDataUtils::DevicestatusData SaveObserverData(const DevicestatusDataUtils::DevicestatusData& data);
std::map<DevicestatusDataUtils::DevicestatusType, DevicestatusDataUtils::DevicestatusValue> GetObserverData() const;
DeviceStatusDataUtils::DeviceStatusData SaveObserverData(const DeviceStatusDataUtils::DeviceStatusData& data);
std::map<DeviceStatusDataUtils::DeviceStatusType, DeviceStatusDataUtils::DeviceStatusValue> GetObserverData() const;
int32_t LoadAlgorithmLibrary(bool bCreate);
int32_t UnloadAlgorithmLibrary(bool bCreate);
private:
ErrCode ImplCallback(const DevicestatusDataUtils::DevicestatusData& data);
DevicestatusMsdpInterface* GetAlgorithmInst();
ErrCode ImplCallback(const DeviceStatusDataUtils::DeviceStatusData& data);
DeviceStatusMsdpInterface* GetAlgorithmInst();
MsdpAlgorithmHandle mAlgorithm_;
std::mutex mMutex_;
bool notifyManagerFlag_ = false;
void OnResult(const DevicestatusDataUtils::DevicestatusData& data) override;
void OnResult(const DeviceStatusDataUtils::DeviceStatusData& data) override;
};
} // namespace DeviceStatus
} // Msdp

View File

@ -39,12 +39,12 @@ namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
enum class ServiceRunningState {STATE_NOT_START, STATE_RUNNING, STATE_EXIT};
class DevicestatusService final : public IContext,
class DeviceStatusService final : public IContext,
public UDSServer,
public SystemAbility,
public DevicestatusSrvStub {
DECLARE_SYSTEM_ABILITY(DevicestatusService)
DECLARE_DELAYED_SP_SINGLETON(DevicestatusService);
public DeviceStatusSrvStub {
DECLARE_SYSTEM_ABILITY(DeviceStatusService)
DECLARE_DELAYED_SP_SINGLETON(DeviceStatusService);
public:
virtual void OnDump() override;
@ -94,11 +94,11 @@ public:
void SetAbsolutionLocation(double xPercent, double yPercent) override
{}
void Subscribe(const DevicestatusDataUtils::DevicestatusType& type,
void Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback) override;
void Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type,
void Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback) override;
DevicestatusDataUtils::DevicestatusData GetCache(const DevicestatusDataUtils::DevicestatusType& type) override;
DeviceStatusDataUtils::DeviceStatusData GetCache(const DeviceStatusDataUtils::DeviceStatusType& type) override;
int32_t RegisterCoordinationListener() override;
int32_t UnregisterCoordinationListener() override;
@ -109,7 +109,7 @@ public:
int32_t GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId) override;
int Dump(int fd, const std::vector<std::u16string>& args) override;
void ReportMsdpSysEvent(const DevicestatusDataUtils::DevicestatusType& type, bool enable);
void ReportMsdpSysEvent(const DeviceStatusDataUtils::DeviceStatusType& type, bool enable);
int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType,
int32_t &toReturnClientFd, int32_t &tokenType) override;
@ -150,8 +150,8 @@ private:
#ifdef OHOS_BUILD_ENABLE_COOPERATE
CoordinationEventHandler coordinationHandler;
#endif // OHOS_BUILD_ENABLE_COOPERATE
std::shared_ptr<DevicestatusManager> devicestatusManager_;
std::shared_ptr<DevicestatusMsdpClientImpl> msdpImpl_;
std::shared_ptr<DeviceStatusManager> devicestatusManager_;
std::shared_ptr<DeviceStatusMsdpClientImpl> msdpImpl_;
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -26,18 +26,18 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusSrvStub : public IRemoteStub<Idevicestatus> {
class DeviceStatusSrvStub : public IRemoteStub<Idevicestatus> {
public:
DevicestatusSrvStub() = default;
virtual ~DevicestatusSrvStub() = default;
DISALLOW_COPY_AND_MOVE(DevicestatusSrvStub);
DeviceStatusSrvStub() = default;
virtual ~DeviceStatusSrvStub() = default;
DISALLOW_COPY_AND_MOVE(DeviceStatusSrvStub);
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
int32_t StubHandleAllocSocketFd(MessageParcel& data, MessageParcel& reply);
private:
int32_t SubscribeStub(MessageParcel& data);
int32_t UnsubscribeStub(MessageParcel& data);
int32_t GetLatestDevicestatusDataStub(MessageParcel& data, MessageParcel& reply);
int32_t GetLatestDeviceStatusDataStub(MessageParcel& data, MessageParcel& reply);
int32_t StubRegisterCoordinationMonitor(MessageParcel& data, MessageParcel& reply);
int32_t StubUnregisterCoordinationMonitor(MessageParcel& data, MessageParcel& reply);

View File

@ -35,8 +35,8 @@ namespace DeviceStatus {
namespace {
constexpr uint32_t MS_NS = 1000000;
}
void DevicestatusDumper::ParseCommand(int32_t fd, const std::vector<std::string> &args,
const std::vector<DevicestatusDataUtils::DevicestatusData> &datas)
void DeviceStatusDumper::ParseCommand(int32_t fd, const std::vector<std::string> &args,
const std::vector<DeviceStatusDataUtils::DeviceStatusData> &datas)
{
int32_t optionIndex = 0;
struct option dumpOptions[] = {
@ -64,15 +64,15 @@ void DevicestatusDumper::ParseCommand(int32_t fd, const std::vector<std::string>
break;
}
case 's': {
DumpDevicestatusSubscriber(fd);
DumpDeviceStatusSubscriber(fd);
break;
}
case 'l': {
DumpDevicestatusChanges(fd);
DumpDeviceStatusChanges(fd);
break;
}
case 'c': {
DumpDevicestatusCurrentStatus(fd, datas);
DumpDeviceStatusCurrentStatus(fd, datas);
break;
}
default: {
@ -89,7 +89,7 @@ void DevicestatusDumper::ParseCommand(int32_t fd, const std::vector<std::string>
delete[] argv;
}
void DevicestatusDumper::DumpDevicestatusSubscriber(int32_t fd)
void DeviceStatusDumper::DumpDeviceStatusSubscriber(int32_t fd)
{
DEV_HILOGI(SERVICE, "start");
if (appInfoMap_.empty()) {
@ -108,7 +108,7 @@ void DevicestatusDumper::DumpDevicestatusSubscriber(int32_t fd)
}
}
void DevicestatusDumper::DumpDevicestatusChanges(int32_t fd)
void DeviceStatusDumper::DumpDeviceStatusChanges(int32_t fd)
{
DEV_HILOGI(SERVICE, "start");
if (deviceStatusQueue_.empty()) {
@ -134,8 +134,8 @@ void DevicestatusDumper::DumpDevicestatusChanges(int32_t fd)
}
}
void DevicestatusDumper::DumpDevicestatusCurrentStatus(int32_t fd,
const std::vector<DevicestatusDataUtils::DevicestatusData> &datas) const
void DeviceStatusDumper::DumpDeviceStatusCurrentStatus(int32_t fd,
const std::vector<DeviceStatusDataUtils::DeviceStatusData> &datas) const
{
DEV_HILOGI(SERVICE, "start");
std::string startTime;
@ -147,27 +147,27 @@ void DevicestatusDumper::DumpDevicestatusCurrentStatus(int32_t fd,
return;
}
for (auto it = datas.begin(); it != datas.end(); ++it) {
if (it->value == DevicestatusDataUtils::VALUE_INVALID) {
if (it->value == DeviceStatusDataUtils::VALUE_INVALID) {
continue;
}
dprintf(fd, "Device status DevicestatusType is %s , current type state is %s .\n",
dprintf(fd, "Device status DeviceStatusType is %s , current type state is %s .\n",
GetStatusType(it->type).c_str(), GetDeviceState(it->value).c_str());
}
}
std::string DevicestatusDumper::GetDeviceState(const DevicestatusDataUtils::DevicestatusValue &value) const
std::string DeviceStatusDumper::GetDeviceState(const DeviceStatusDataUtils::DeviceStatusValue &value) const
{
std::string state;
switch (value) {
case DevicestatusDataUtils::VALUE_ENTER: {
case DeviceStatusDataUtils::VALUE_ENTER: {
state = "enter";
break;
}
case DevicestatusDataUtils::VALUE_EXIT: {
case DeviceStatusDataUtils::VALUE_EXIT: {
state = "exit";
break;
}
case DevicestatusDataUtils::VALUE_INVALID: {
case DeviceStatusDataUtils::VALUE_INVALID: {
state = "invalid";
break;
}
@ -179,23 +179,23 @@ std::string DevicestatusDumper::GetDeviceState(const DevicestatusDataUtils::Devi
return state;
}
std::string DevicestatusDumper::GetStatusType(const DevicestatusDataUtils::DevicestatusType &type) const
std::string DeviceStatusDumper::GetStatusType(const DeviceStatusDataUtils::DeviceStatusType &type) const
{
std::string stateType;
switch (type) {
case DevicestatusDataUtils::TYPE_HIGH_STILL: {
case DeviceStatusDataUtils::TYPE_HIGH_STILL: {
stateType = "high still";
break;
}
case DevicestatusDataUtils::TYPE_FINE_STILL: {
case DeviceStatusDataUtils::TYPE_FINE_STILL: {
stateType = "fine still";
break;
}
case DevicestatusDataUtils::TYPE_CAR_BLUETOOTH: {
case DeviceStatusDataUtils::TYPE_CAR_BLUETOOTH: {
stateType = "car bluetooth";
break;
}
case DevicestatusDataUtils::TYPE_LID_OPEN: {
case DeviceStatusDataUtils::TYPE_LID_OPEN: {
stateType = "lid open";
break;
}
@ -207,7 +207,7 @@ std::string DevicestatusDumper::GetStatusType(const DevicestatusDataUtils::Devic
return stateType;
}
void DevicestatusDumper::DumpCurrentTime(std::string &startTime) const
void DeviceStatusDumper::DumpCurrentTime(std::string &startTime) const
{
timespec curTime;
clock_gettime(CLOCK_REALTIME, &curTime);
@ -223,7 +223,7 @@ void DevicestatusDumper::DumpCurrentTime(std::string &startTime) const
.append(std::to_string(curTime.tv_nsec / MS_NS));
}
void DevicestatusDumper::DumpHelpInfo(int32_t fd) const
void DeviceStatusDumper::DumpHelpInfo(int32_t fd) const
{
dprintf(fd, "Usage:\n");
dprintf(fd, " -h: dump help\n");
@ -232,7 +232,7 @@ void DevicestatusDumper::DumpHelpInfo(int32_t fd) const
dprintf(fd, " -c: dump the device_status current device status\n");
}
void DevicestatusDumper::SaveAppInfo(std::shared_ptr<AppInfo> appInfo)
void DeviceStatusDumper::SaveAppInfo(std::shared_ptr<AppInfo> appInfo)
{
DEV_HILOGI(SERVICE, "Enter");
DumpCurrentTime(appInfo->startTime);
@ -249,7 +249,7 @@ void DevicestatusDumper::SaveAppInfo(std::shared_ptr<AppInfo> appInfo)
}
}
void DevicestatusDumper::RemoveAppInfo(std::shared_ptr<AppInfo> appInfo)
void DeviceStatusDumper::RemoveAppInfo(std::shared_ptr<AppInfo> appInfo)
{
DEV_HILOGI(SERVICE, "Enter");
if (appInfo->callback == nullptr) {
@ -278,7 +278,7 @@ void DevicestatusDumper::RemoveAppInfo(std::shared_ptr<AppInfo> appInfo)
}
}
void DevicestatusDumper::pushDeviceStatus(const DevicestatusDataUtils::DevicestatusData& data)
void DeviceStatusDumper::pushDeviceStatus(const DeviceStatusDataUtils::DeviceStatusData& data)
{
DEV_HILOGI(SERVICE, "Enter");
std::unique_lock lock(mutex_);

View File

@ -23,7 +23,7 @@ namespace {
constexpr int32_t ERR_OK = 0;
constexpr int32_t ERR_NG = -1;
}
void DevicestatusManager::DevicestatusCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
void DeviceStatusManager::DeviceStatusCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
if (remote == nullptr) {
DEV_HILOGE(SERVICE, "OnRemoteDied failed, remote is nullptr");
@ -32,32 +32,32 @@ void DevicestatusManager::DevicestatusCallbackDeathRecipient::OnRemoteDied(const
DEV_HILOGD(SERVICE, "Recv death notice");
}
bool DevicestatusManager::Init()
bool DeviceStatusManager::Init()
{
DEV_HILOGI(SERVICE, "Enter");
if (devicestatusCBDeathRecipient_ == nullptr) {
devicestatusCBDeathRecipient_ = new (std::nothrow) DevicestatusCallbackDeathRecipient();
devicestatusCBDeathRecipient_ = new (std::nothrow) DeviceStatusCallbackDeathRecipient();
if (devicestatusCBDeathRecipient_ == nullptr) {
DEV_HILOGE(SERVICE, "devicestatusCBDeathRecipient_ is nullptr");
return false;
}
}
msdpImpl_ = std::make_unique<DevicestatusMsdpClientImpl>();
msdpImpl_ = std::make_unique<DeviceStatusMsdpClientImpl>();
LoadAlgorithm(false);
DEV_HILOGI(SERVICE, "Init success");
return true;
}
DevicestatusDataUtils::DevicestatusData DevicestatusManager::GetLatestDevicestatusData(const \
DevicestatusDataUtils::DevicestatusType& type)
DeviceStatusDataUtils::DeviceStatusData DeviceStatusManager::GetLatestDeviceStatusData(const \
DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGI(SERVICE, "Enter");
DevicestatusDataUtils::DevicestatusData data = {type, DevicestatusDataUtils::DevicestatusValue::VALUE_EXIT};
DeviceStatusDataUtils::DeviceStatusData data = {type, DeviceStatusDataUtils::DeviceStatusValue::VALUE_EXIT};
if (msdpImpl_ == nullptr) {
DEV_HILOGI(SERVICE, "GetObserverData func is nullptr,return default!");
data.value = DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID;
data.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
return data;
}
msdpData_ = msdpImpl_->GetObserverData();
@ -68,11 +68,11 @@ DevicestatusDataUtils::DevicestatusData DevicestatusManager::GetLatestDevicestat
}
}
data.value = DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID;
data.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
return data;
}
bool DevicestatusManager::EnableMock(DevicestatusDataUtils::DevicestatusType type)
bool DeviceStatusManager::EnableMock(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGE(SERVICE, "Enter");
if (!InitInterface(type)) {
@ -87,7 +87,7 @@ bool DevicestatusManager::EnableMock(DevicestatusDataUtils::DevicestatusType typ
return true;
}
bool DevicestatusManager::DisableMock(DevicestatusDataUtils::DevicestatusType type)
bool DeviceStatusManager::DisableMock(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGE(SERVICE, "Enter");
if (msdpImpl_ == nullptr) {
@ -108,7 +108,7 @@ bool DevicestatusManager::DisableMock(DevicestatusDataUtils::DevicestatusType ty
return true;
}
bool DevicestatusManager::InitInterface(DevicestatusDataUtils::DevicestatusType type)
bool DeviceStatusManager::InitInterface(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGE(SERVICE, "Enter");
if (msdpImpl_ == nullptr) {
@ -121,28 +121,28 @@ bool DevicestatusManager::InitInterface(DevicestatusDataUtils::DevicestatusType
return true;
}
bool DevicestatusManager::InitDataCallback()
bool DeviceStatusManager::InitDataCallback()
{
DEV_HILOGE(SERVICE, "Enter");
if (msdpImpl_ == nullptr) {
DEV_HILOGE(SERVICE, "msdpImpl_ is nullptr");
return false;
}
DevicestatusMsdpClientImpl::CallbackManager callback =
std::bind(&DevicestatusManager::MsdpDataCallback, this, std::placeholders::_1);
DeviceStatusMsdpClientImpl::CallbackManager callback =
std::bind(&DeviceStatusManager::MsdpDataCallback, this, std::placeholders::_1);
if (msdpImpl_->RegisterImpl(callback) == ERR_NG) {
DEV_HILOGE(SERVICE, "register impl failed");
}
return true;
}
int32_t DevicestatusManager::MsdpDataCallback(const DevicestatusDataUtils::DevicestatusData& data)
int32_t DeviceStatusManager::MsdpDataCallback(const DeviceStatusDataUtils::DeviceStatusData& data)
{
NotifyDevicestatusChange(data);
NotifyDeviceStatusChange(data);
return ERR_OK;
}
void DevicestatusManager::NotifyDevicestatusChange(const DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusManager::NotifyDeviceStatusChange(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
DEV_HILOGI(SERVICE, "Enter");
@ -165,12 +165,12 @@ void DevicestatusManager::NotifyDevicestatusChange(const DevicestatusDataUtils::
DEV_HILOGI(SERVICE, "Listener is nullptr");
return;
}
listener->OnDevicestatusChanged(devicestatusData);
listener->OnDeviceStatusChanged(devicestatusData);
}
DEV_HILOGI(SERVICE, "Exit");
}
void DevicestatusManager::Subscribe(const DevicestatusDataUtils::DevicestatusType& type,
void DeviceStatusManager::Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGI(SERVICE, "Enter");
@ -209,7 +209,7 @@ void DevicestatusManager::Subscribe(const DevicestatusDataUtils::DevicestatusTyp
DEV_HILOGI(SERVICE, "Subscribe success,Exit");
}
void DevicestatusManager::Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type,
void DeviceStatusManager::Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGI(SERVICE, "Enter");
@ -244,7 +244,7 @@ void DevicestatusManager::Unsubscribe(const DevicestatusDataUtils::DevicestatusT
DEV_HILOGI(SERVICE, "Unsubscribe success,Exit");
}
int32_t DevicestatusManager::LoadAlgorithm(bool bCreate)
int32_t DeviceStatusManager::LoadAlgorithm(bool bCreate)
{
DEV_HILOGI(SERVICE, "Enter");
if (msdpImpl_ != nullptr) {
@ -254,7 +254,7 @@ int32_t DevicestatusManager::LoadAlgorithm(bool bCreate)
return ERR_OK;
}
int32_t DevicestatusManager::UnloadAlgorithm(bool bCreate)
int32_t DeviceStatusManager::UnloadAlgorithm(bool bCreate)
{
DEV_HILOGI(SERVICE, "Enter");
if (msdpImpl_ != nullptr) {
@ -264,7 +264,7 @@ int32_t DevicestatusManager::UnloadAlgorithm(bool bCreate)
return ERR_OK;
}
void DevicestatusManager::GetPackageName(AccessTokenID tokenId, std::string &packageName)
void DeviceStatusManager::GetPackageName(AccessTokenID tokenId, std::string &packageName)
{
int32_t tokenType = AccessTokenKit::GetTokenTypeFlag(tokenId);
switch (tokenType) {

View File

@ -35,14 +35,14 @@ constexpr int32_t ERR_OK = 0;
constexpr int32_t ERR_NG = -1;
const std::string DEVICESTATUS_SENSOR_HDI_LIB_PATH = "libdevicestatus_sensorhdi.z.so";
const std::string DEVICESTATUS_MSDP_ALGORITHM_LIB_PATH = "libdevicestatus_msdp.z.so";
std::map<DevicestatusDataUtils::DevicestatusType, DevicestatusDataUtils::DevicestatusValue> g_devicestatusDataMap;
DevicestatusMsdpClientImpl::CallbackManager g_callbacksMgr;
using clientType = DevicestatusDataUtils::DevicestatusType;
using clientValue = DevicestatusDataUtils::DevicestatusValue;
DevicestatusMsdpInterface* g_msdpInterface;
std::map<DeviceStatusDataUtils::DeviceStatusType, DeviceStatusDataUtils::DeviceStatusValue> g_devicestatusDataMap;
DeviceStatusMsdpClientImpl::CallbackManager g_callbacksMgr;
using clientType = DeviceStatusDataUtils::DeviceStatusType;
using clientValue = DeviceStatusDataUtils::DeviceStatusValue;
DeviceStatusMsdpInterface* g_msdpInterface;
}
ErrCode DevicestatusMsdpClientImpl::InitMsdpImpl(DevicestatusDataUtils::DevicestatusType type)
ErrCode DeviceStatusMsdpClientImpl::InitMsdpImpl(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGI(SERVICE, "Enter");
if (g_msdpInterface == nullptr) {
@ -59,7 +59,7 @@ ErrCode DevicestatusMsdpClientImpl::InitMsdpImpl(DevicestatusDataUtils::Devicest
return ERR_OK;
}
ErrCode DevicestatusMsdpClientImpl::DisableMsdpImpl(DevicestatusDataUtils::DevicestatusType type)
ErrCode DeviceStatusMsdpClientImpl::DisableMsdpImpl(DeviceStatusDataUtils::DeviceStatusType type)
{
DEV_HILOGI(SERVICE, "Enter");
if (g_msdpInterface == nullptr) {
@ -72,7 +72,7 @@ ErrCode DevicestatusMsdpClientImpl::DisableMsdpImpl(DevicestatusDataUtils::Devic
return ERR_OK;
}
ErrCode DevicestatusMsdpClientImpl::RegisterImpl(const CallbackManager& callback)
ErrCode DeviceStatusMsdpClientImpl::RegisterImpl(const CallbackManager& callback)
{
DEV_HILOGI(SERVICE, "Enter");
g_callbacksMgr = callback;
@ -90,7 +90,7 @@ ErrCode DevicestatusMsdpClientImpl::RegisterImpl(const CallbackManager& callback
return ERR_OK;
}
ErrCode DevicestatusMsdpClientImpl::UnregisterImpl()
ErrCode DeviceStatusMsdpClientImpl::UnregisterImpl()
{
DEV_HILOGI(SERVICE, "Enter");
if (g_callbacksMgr == nullptr) {
@ -105,7 +105,7 @@ ErrCode DevicestatusMsdpClientImpl::UnregisterImpl()
return ERR_OK;
}
ErrCode DevicestatusMsdpClientImpl::ImplCallback(const DevicestatusDataUtils::DevicestatusData& data)
ErrCode DeviceStatusMsdpClientImpl::ImplCallback(const DeviceStatusDataUtils::DeviceStatusData& data)
{
if (g_callbacksMgr == nullptr) {
DEV_HILOGI(SERVICE, "g_callbacksMgr is nullptr");
@ -116,16 +116,16 @@ ErrCode DevicestatusMsdpClientImpl::ImplCallback(const DevicestatusDataUtils::De
return ERR_OK;
}
void DevicestatusMsdpClientImpl::OnResult(const DevicestatusDataUtils::DevicestatusData& data)
void DeviceStatusMsdpClientImpl::OnResult(const DeviceStatusDataUtils::DeviceStatusData& data)
{
MsdpCallback(data);
}
ErrCode DevicestatusMsdpClientImpl::RegisterMsdp()
ErrCode DeviceStatusMsdpClientImpl::RegisterMsdp()
{
DEV_HILOGI(SERVICE, "Enter");
if (g_msdpInterface != nullptr) {
std::shared_ptr<MsdpAlgorithmCallback> callback = std::make_shared<DevicestatusMsdpClientImpl>();
std::shared_ptr<MsdpAlgorithmCallback> callback = std::make_shared<DeviceStatusMsdpClientImpl>();
g_msdpInterface->RegisterCallback(callback);
}
@ -133,7 +133,7 @@ ErrCode DevicestatusMsdpClientImpl::RegisterMsdp()
return ERR_OK;
}
ErrCode DevicestatusMsdpClientImpl::UnregisterMsdp(void)
ErrCode DeviceStatusMsdpClientImpl::UnregisterMsdp(void)
{
DEV_HILOGI(SERVICE, "Enter");
@ -149,10 +149,10 @@ ErrCode DevicestatusMsdpClientImpl::UnregisterMsdp(void)
return ERR_OK;
}
int32_t DevicestatusMsdpClientImpl::MsdpCallback(const DevicestatusDataUtils::DevicestatusData& data)
int32_t DeviceStatusMsdpClientImpl::MsdpCallback(const DeviceStatusDataUtils::DeviceStatusData& data)
{
DEV_HILOGI(SERVICE, "Enter");
DevicestatusDumper::GetInstance().pushDeviceStatus(data);
DeviceStatusDumper::GetInstance().pushDeviceStatus(data);
SaveObserverData(data);
if (notifyManagerFlag_) {
ImplCallback(data);
@ -162,8 +162,8 @@ int32_t DevicestatusMsdpClientImpl::MsdpCallback(const DevicestatusDataUtils::De
return ERR_OK;
}
DevicestatusDataUtils::DevicestatusData DevicestatusMsdpClientImpl::SaveObserverData(
const DevicestatusDataUtils::DevicestatusData& data)
DeviceStatusDataUtils::DeviceStatusData DeviceStatusMsdpClientImpl::SaveObserverData(
const DeviceStatusDataUtils::DeviceStatusData& data)
{
DEV_HILOGI(SERVICE, "Enter");
for (auto iter = g_devicestatusDataMap.begin(); iter != g_devicestatusDataMap.end(); ++iter) {
@ -180,13 +180,13 @@ DevicestatusDataUtils::DevicestatusData DevicestatusMsdpClientImpl::SaveObserver
return data;
}
std::map<clientType, clientValue> DevicestatusMsdpClientImpl::GetObserverData() const
std::map<clientType, clientValue> DeviceStatusMsdpClientImpl::GetObserverData() const
{
DEV_HILOGI(SERVICE, "Enter");
return g_devicestatusDataMap;
}
int32_t DevicestatusMsdpClientImpl::LoadAlgorithmLibrary(bool bCreate)
int32_t DeviceStatusMsdpClientImpl::LoadAlgorithmLibrary(bool bCreate)
{
DEV_HILOGI(SERVICE, "Enter");
if (mAlgorithm_.handle != nullptr) {
@ -200,9 +200,9 @@ int32_t DevicestatusMsdpClientImpl::LoadAlgorithmLibrary(bool bCreate)
}
DEV_HILOGI(SERVICE, "start create pointer");
mAlgorithm_.create = (DevicestatusMsdpInterface* (*)()) dlsym(mAlgorithm_.handle, "Create");
mAlgorithm_.create = (DeviceStatusMsdpInterface* (*)()) dlsym(mAlgorithm_.handle, "Create");
DEV_HILOGI(SERVICE, "start destroy pointer");
mAlgorithm_.destroy = (void *(*)(DevicestatusMsdpInterface*))dlsym(mAlgorithm_.handle, "Destroy");
mAlgorithm_.destroy = (void *(*)(DeviceStatusMsdpInterface*))dlsym(mAlgorithm_.handle, "Destroy");
if (mAlgorithm_.create == nullptr || mAlgorithm_.destroy == nullptr) {
DEV_HILOGE(SERVICE, "%{public}s dlsym Create or Destroy failed",
@ -221,7 +221,7 @@ int32_t DevicestatusMsdpClientImpl::LoadAlgorithmLibrary(bool bCreate)
return ERR_OK;
}
int32_t DevicestatusMsdpClientImpl::UnloadAlgorithmLibrary(bool bCreate)
int32_t DeviceStatusMsdpClientImpl::UnloadAlgorithmLibrary(bool bCreate)
{
DEV_HILOGI(SERVICE, "Enter");
if (mAlgorithm_.handle == nullptr) {
@ -242,7 +242,7 @@ int32_t DevicestatusMsdpClientImpl::UnloadAlgorithmLibrary(bool bCreate)
return ERR_OK;
}
DevicestatusMsdpInterface* DevicestatusMsdpClientImpl::GetAlgorithmInst()
DeviceStatusMsdpInterface* DeviceStatusMsdpClientImpl::GetAlgorithmInst()
{
DEV_HILOGI(SERVICE, "Enter");
if (mAlgorithm_.handle == nullptr) {

View File

@ -45,8 +45,8 @@ namespace Msdp {
namespace DeviceStatus {
using namespace OHOS::HiviewDFX;
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DevicestatusService" };
auto ms = DelayedSpSingleton<DevicestatusService>::GetInstance();
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DeviceStatusService" };
auto ms = DelayedSpSingleton<DeviceStatusService>::GetInstance();
const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(ms.GetRefPtr());
} // namespace
@ -55,19 +55,19 @@ struct device_status_epoll_event {
EpollEventType event_type { EPOLL_EVENT_BEGIN };
};
DevicestatusService::DevicestatusService() : SystemAbility(MSDP_DEVICESTATUS_SERVICE_ID, true)
DeviceStatusService::DeviceStatusService() : SystemAbility(MSDP_DEVICESTATUS_SERVICE_ID, true)
{
DEV_HILOGD(SERVICE, "Add SystemAbility");
}
DevicestatusService::~DevicestatusService() {}
DeviceStatusService::~DeviceStatusService() {}
void DevicestatusService::OnDump()
void DeviceStatusService::OnDump()
{
DEV_HILOGI(SERVICE, "OnDump");
}
void DevicestatusService::OnStart()
void DeviceStatusService::OnStart()
{
DEV_HILOGI(SERVICE, "Enter");
if (ready_) {
@ -79,17 +79,17 @@ void DevicestatusService::OnStart()
DEV_HILOGE(SERVICE, "OnStart call init fail");
return;
}
if (!Publish(DelayedSpSingleton<DevicestatusService>::GetInstance())) {
if (!Publish(DelayedSpSingleton<DeviceStatusService>::GetInstance())) {
DEV_HILOGE(SERVICE, "OnStart register to system ability manager failed");
return;
}
state_ = ServiceRunningState::STATE_RUNNING;
ready_ = true;
t_ = std::thread(std::bind(&DevicestatusService::OnThread, this));
t_ = std::thread(std::bind(&DeviceStatusService::OnThread, this));
t_.join();
}
void DevicestatusService::OnStop()
void DeviceStatusService::OnStop()
{
DEV_HILOGI(SERVICE, "Enter");
if (!ready_) {
@ -105,29 +105,29 @@ void DevicestatusService::OnStop()
DEV_HILOGI(SERVICE, "unload algorithm library exit");
}
IDelegateTasks& DevicestatusService::GetDelegateTasks()
IDelegateTasks& DeviceStatusService::GetDelegateTasks()
{
return delegateTasks_;
}
IDeviceManager& DevicestatusService::GetDeviceManager()
IDeviceManager& DeviceStatusService::GetDeviceManager()
{
return devMgr_;
}
ITimerManager& DevicestatusService::GetTimerManager()
ITimerManager& DeviceStatusService::GetTimerManager()
{
return timerMgr_;
}
int DevicestatusService::Dump(int fd, const std::vector<std::u16string>& args)
int DeviceStatusService::Dump(int fd, const std::vector<std::u16string>& args)
{
DEV_HILOGI(SERVICE, "dump DeviceStatusServiceInfo");
if (fd < 0) {
DEV_HILOGE(SERVICE, "fd is invalid");
return RET_NG;
}
DevicestatusDumper &deviceStatusDumper = DevicestatusDumper::GetInstance();
DeviceStatusDumper &deviceStatusDumper = DeviceStatusDumper::GetInstance();
if (args.empty()) {
DEV_HILOGE(SERVICE, "param cannot be empty");
dprintf(fd, "param cannot be empty\n");
@ -140,13 +140,13 @@ int DevicestatusService::Dump(int fd, const std::vector<std::u16string>& args)
return Str16ToStr8(arg);
});
DevicestatusDataUtils::DevicestatusType type;
std::vector<DevicestatusDataUtils::DevicestatusData> datas;
for (type = DevicestatusDataUtils::TYPE_HIGH_STILL;
type <= DevicestatusDataUtils::TYPE_LID_OPEN;
type = (DevicestatusDataUtils::DevicestatusType)(type+1)) {
DevicestatusDataUtils::DevicestatusData data = GetCache(type);
if (data.value != DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) {
DeviceStatusDataUtils::DeviceStatusType type;
std::vector<DeviceStatusDataUtils::DeviceStatusData> datas;
for (type = DeviceStatusDataUtils::TYPE_HIGH_STILL;
type <= DeviceStatusDataUtils::TYPE_LID_OPEN;
type = (DeviceStatusDataUtils::DeviceStatusType)(type+1)) {
DeviceStatusDataUtils::DeviceStatusData data = GetCache(type);
if (data.value != DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) {
datas.emplace_back(data);
}
}
@ -154,12 +154,12 @@ int DevicestatusService::Dump(int fd, const std::vector<std::u16string>& args)
return RET_OK;
}
bool DevicestatusService::Init()
bool DeviceStatusService::Init()
{
DEV_HILOGI(SERVICE, "Enter");
if (!devicestatusManager_) {
devicestatusManager_ = std::make_shared<DevicestatusManager>(ms);
devicestatusManager_ = std::make_shared<DeviceStatusManager>(ms);
}
if (!devicestatusManager_->Init()) {
DEV_HILOGE(SERVICE, "OnStart init fail");
@ -190,7 +190,7 @@ INIT_FAIL:
return false;
}
void DevicestatusService::Subscribe(const DevicestatusDataUtils::DevicestatusType& type,
void DeviceStatusService::Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGI(SERVICE, "Enter");
@ -206,14 +206,14 @@ void DevicestatusService::Subscribe(const DevicestatusDataUtils::DevicestatusTyp
devicestatusManager_->GetPackageName(appInfo->tokenId, appInfo->packageName);
appInfo->type = type;
appInfo->callback = callback;
DevicestatusDumper::GetInstance().SaveAppInfo(appInfo);
DeviceStatusDumper::GetInstance().SaveAppInfo(appInfo);
StartTrace(HITRACE_TAG_MSDP, "serviceSubscribeStart");
devicestatusManager_->Subscribe(type, callback);
FinishTrace(HITRACE_TAG_MSDP);
ReportMsdpSysEvent(type, true);
}
void DevicestatusService::Unsubscribe(const DevicestatusDataUtils::DevicestatusType& type,
void DeviceStatusService::Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
const sptr<IdevicestatusCallback>& callback)
{
DEV_HILOGI(SERVICE, "Enter");
@ -229,27 +229,27 @@ void DevicestatusService::Unsubscribe(const DevicestatusDataUtils::DevicestatusT
devicestatusManager_->GetPackageName(appInfo->tokenId, appInfo->packageName);
appInfo->type = type;
appInfo->callback = callback;
DevicestatusDumper::GetInstance().RemoveAppInfo(appInfo);
DeviceStatusDumper::GetInstance().RemoveAppInfo(appInfo);
StartTrace(HITRACE_TAG_MSDP, "serviceUnsubscribeStart");
devicestatusManager_->Unsubscribe(type, callback);
FinishTrace(HITRACE_TAG_MSDP);
ReportMsdpSysEvent(type, false);
}
DevicestatusDataUtils::DevicestatusData DevicestatusService::GetCache(const \
DevicestatusDataUtils::DevicestatusType& type)
DeviceStatusDataUtils::DeviceStatusData DeviceStatusService::GetCache(const \
DeviceStatusDataUtils::DeviceStatusType& type)
{
DEV_HILOGI(SERVICE, "Enter");
if (devicestatusManager_ == nullptr) {
DevicestatusDataUtils::DevicestatusData data = {type, DevicestatusDataUtils::DevicestatusValue::VALUE_EXIT};
data.value = DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID;
DEV_HILOGI(SERVICE, "GetLatestDevicestatusData func is nullptr,return default!");
DeviceStatusDataUtils::DeviceStatusData data = {type, DeviceStatusDataUtils::DeviceStatusValue::VALUE_EXIT};
data.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
DEV_HILOGI(SERVICE, "GetLatestDeviceStatusData func is nullptr,return default!");
return data;
}
return devicestatusManager_->GetLatestDevicestatusData(type);
return devicestatusManager_->GetLatestDeviceStatusData(type);
}
void DevicestatusService::ReportMsdpSysEvent(const DevicestatusDataUtils::DevicestatusType& type, bool enable)
void DeviceStatusService::ReportMsdpSysEvent(const DeviceStatusDataUtils::DeviceStatusType& type, bool enable)
{
auto uid = this->GetCallingUid();
auto callerToken = this->GetCallingTokenID();
@ -264,7 +264,7 @@ void DevicestatusService::ReportMsdpSysEvent(const DevicestatusDataUtils::Device
"UID", uid, "PKGNAME", packageName, "TYPE", type);
}
int32_t DevicestatusService::AllocSocketFd(const std::string &programName, const int32_t moduleType,
int32_t DeviceStatusService::AllocSocketFd(const std::string &programName, const int32_t moduleType,
int32_t &toReturnClientFd, int32_t &tokenType)
{
FI_HILOGD("Enter, programName:%{public}s,moduleType:%{public}d", programName.c_str(), moduleType);
@ -284,18 +284,18 @@ int32_t DevicestatusService::AllocSocketFd(const std::string &programName, const
return RET_OK;
}
void DevicestatusService::OnConnected(SessionPtr s)
void DeviceStatusService::OnConnected(SessionPtr s)
{
CHKPV(s);
FI_HILOGI("fd:%{public}d", s->GetFd());
}
void DevicestatusService::OnDisconnected(SessionPtr s)
void DeviceStatusService::OnDisconnected(SessionPtr s)
{
CHKPV(s);
FI_HILOGW("Enter, session desc:%{public}s, fd:%{public}d", s->GetDescript().c_str(), s->GetFd());
}
int32_t DevicestatusService::AddEpoll(EpollEventType type, int32_t fd)
int32_t DeviceStatusService::AddEpoll(EpollEventType type, int32_t fd)
{
if (!(type >= EPOLL_EVENT_BEGIN && type < EPOLL_EVENT_END)) {
FI_HILOGE("Invalid param type");
@ -327,7 +327,7 @@ int32_t DevicestatusService::AddEpoll(EpollEventType type, int32_t fd)
return RET_OK;
}
int32_t DevicestatusService::DelEpoll(EpollEventType type, int32_t fd)
int32_t DeviceStatusService::DelEpoll(EpollEventType type, int32_t fd)
{
if (!(type >= EPOLL_EVENT_BEGIN && type < EPOLL_EVENT_END)) {
FI_HILOGE("Invalid param type");
@ -346,12 +346,12 @@ int32_t DevicestatusService::DelEpoll(EpollEventType type, int32_t fd)
return RET_OK;
}
bool DevicestatusService::IsRunning() const
bool DeviceStatusService::IsRunning() const
{
return (state_ == ServiceRunningState::STATE_RUNNING);
}
int32_t DevicestatusService::InitDelegateTasks()
int32_t DeviceStatusService::InitDelegateTasks()
{
CALL_DEBUG_ENTER;
if (!delegateTasks_.Init()) {
@ -367,7 +367,7 @@ int32_t DevicestatusService::InitDelegateTasks()
return RET_OK;
}
int32_t DevicestatusService::InitTimerMgr()
int32_t DeviceStatusService::InitTimerMgr()
{
int32_t ret = timerMgr_.Init();
if (ret != RET_OK) {
@ -382,7 +382,7 @@ int32_t DevicestatusService::InitTimerMgr()
return RET_OK;
}
void DevicestatusService::OnThread()
void DeviceStatusService::OnThread()
{
SetThreadName(std::string("mmi_service"));
uint64_t tid = GetThisThreadId();
@ -410,7 +410,7 @@ void DevicestatusService::OnThread()
FI_HILOGD("Main worker thread stop. tid:%{public}" PRId64 "", tid);
}
void DevicestatusService::OnSignalEvent(int32_t signalFd)
void DeviceStatusService::OnSignalEvent(int32_t signalFd)
{
CALL_DEBUG_ENTER;
signalfd_siginfo sigInfo;
@ -440,7 +440,7 @@ void DevicestatusService::OnSignalEvent(int32_t signalFd)
}
}
void DevicestatusService::OnDelegateTask(epoll_event &ev)
void DeviceStatusService::OnDelegateTask(epoll_event &ev)
{
if ((ev.events & EPOLLIN) == 0) {
FI_HILOGW("Not epollin");
@ -456,7 +456,7 @@ void DevicestatusService::OnDelegateTask(epoll_event &ev)
delegateTasks_.ProcessTasks();
}
void DevicestatusService::OnTimeout(epoll_event &ev)
void DeviceStatusService::OnTimeout(epoll_event &ev)
{
if ((ev.events & EPOLLIN) == EPOLLIN) {
uint64_t expiration {};
@ -470,13 +470,13 @@ void DevicestatusService::OnTimeout(epoll_event &ev)
}
}
int32_t DevicestatusService::RegisterCoordinationListener()
int32_t DeviceStatusService::RegisterCoordinationListener()
{
CALL_DEBUG_ENTER;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t pid = GetCallingPid();
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(&DevicestatusService::OnRegisterCoordinationListener, this, pid));
std::bind(&DeviceStatusService::OnRegisterCoordinationListener, this, pid));
if (ret != RET_OK) {
FI_HILOGE("OnRegisterCoordinationListener failed, ret:%{public}d", ret);
return RET_ERR;
@ -485,13 +485,13 @@ int32_t DevicestatusService::RegisterCoordinationListener()
return RET_OK;
}
int32_t DevicestatusService::UnregisterCoordinationListener()
int32_t DeviceStatusService::UnregisterCoordinationListener()
{
CALL_DEBUG_ENTER;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t pid = GetCallingPid();
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(&DevicestatusService::OnUnregisterCoordinationListener, this, pid));
std::bind(&DeviceStatusService::OnUnregisterCoordinationListener, this, pid));
if (ret != RET_OK) {
FI_HILOGE("OnUnregisterCoordinationListener failed, ret:%{public}d", ret);
return RET_ERR;
@ -500,13 +500,13 @@ int32_t DevicestatusService::UnregisterCoordinationListener()
return RET_OK;
}
int32_t DevicestatusService::EnableInputDeviceCoordination(int32_t userData, bool enabled)
int32_t DeviceStatusService::EnableInputDeviceCoordination(int32_t userData, bool enabled)
{
CALL_DEBUG_ENTER;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t pid = GetCallingPid();
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(&DevicestatusService::OnEnableInputDeviceCoordination, this, pid, userData, enabled));
std::bind(&DeviceStatusService::OnEnableInputDeviceCoordination, this, pid, userData, enabled));
if (ret != RET_OK) {
FI_HILOGE("OnEnableInputDeviceCoordination failed, ret:%{public}d", ret);
return ret;
@ -518,14 +518,14 @@ int32_t DevicestatusService::EnableInputDeviceCoordination(int32_t userData, boo
return RET_OK;
}
int32_t DevicestatusService::StartInputDeviceCoordination(int32_t userData,
int32_t DeviceStatusService::StartInputDeviceCoordination(int32_t userData,
const std::string &sinkDeviceId, int32_t srcInputDeviceId)
{
CALL_DEBUG_ENTER;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t pid = GetCallingPid();
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(&DevicestatusService::OnStartInputDeviceCoordination,
std::bind(&DeviceStatusService::OnStartInputDeviceCoordination,
this, pid, userData, sinkDeviceId, srcInputDeviceId));
if (ret != RET_OK) {
FI_HILOGE("OnStartInputDeviceCoordination failed, ret:%{public}d", ret);
@ -539,13 +539,13 @@ int32_t DevicestatusService::StartInputDeviceCoordination(int32_t userData,
return RET_OK;
}
int32_t DevicestatusService::StopDeviceCoordination(int32_t userData)
int32_t DeviceStatusService::StopDeviceCoordination(int32_t userData)
{
CALL_DEBUG_ENTER;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t pid = GetCallingPid();
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(&DevicestatusService::OnStopInputDeviceCoordination, this, pid, userData));
std::bind(&DeviceStatusService::OnStopInputDeviceCoordination, this, pid, userData));
if (ret != RET_OK) {
FI_HILOGE("OnStopInputDeviceCoordination failed, ret:%{public}d", ret);
return ret;
@ -556,13 +556,13 @@ int32_t DevicestatusService::StopDeviceCoordination(int32_t userData)
return RET_OK;
}
int32_t DevicestatusService::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
int32_t DeviceStatusService::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
{
CALL_DEBUG_ENTER;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t pid = GetCallingPid();
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(&DevicestatusService::OnGetInputDeviceCoordinationState, this, pid, userData, deviceId));
std::bind(&DeviceStatusService::OnGetInputDeviceCoordinationState, this, pid, userData, deviceId));
if (ret != RET_OK) {
FI_HILOGE("OnGetInputDeviceCoordinationState failed, ret:%{public}d", ret);
return RET_ERR;
@ -576,7 +576,7 @@ int32_t DevicestatusService::GetInputDeviceCoordinationState(int32_t userData, c
}
#ifdef OHOS_BUILD_ENABLE_COORDINATION
int32_t DevicestatusService::OnRegisterCoordinationListener(int32_t pid)
int32_t DeviceStatusService::OnRegisterCoordinationListener(int32_t pid)
{
CALL_DEBUG_ENTER;
auto sess = GetSession(GetClientFd(pid));
@ -590,7 +590,7 @@ int32_t DevicestatusService::OnRegisterCoordinationListener(int32_t pid)
return RET_OK;
}
int32_t DevicestatusService::OnUnregisterCoordinationListener(int32_t pid)
int32_t DeviceStatusService::OnUnregisterCoordinationListener(int32_t pid)
{
CALL_DEBUG_ENTER;
auto sess = GetSession(GetClientFd(pid));
@ -602,7 +602,7 @@ int32_t DevicestatusService::OnUnregisterCoordinationListener(int32_t pid)
return RET_OK;
}
int32_t DevicestatusService::OnEnableInputDeviceCoordination(int32_t pid, int32_t userData, bool enabled)
int32_t DeviceStatusService::OnEnableInputDeviceCoordination(int32_t pid, int32_t userData, bool enabled)
{
CALL_DEBUG_ENTER;
InputDevCooSM->EnableInputDeviceCooperate(enabled);
@ -624,7 +624,7 @@ int32_t DevicestatusService::OnEnableInputDeviceCoordination(int32_t pid, int32_
return RET_OK;
}
int32_t DevicestatusService::OnStartInputDeviceCoordination(int32_t pid,
int32_t DeviceStatusService::OnStartInputDeviceCoordination(int32_t pid,
int32_t userData, const std::string &sinkDeviceId, int32_t srcInputDeviceId)
{
CALL_DEBUG_ENTER;
@ -646,7 +646,7 @@ int32_t DevicestatusService::OnStartInputDeviceCoordination(int32_t pid,
return RET_OK;
}
int32_t DevicestatusService::OnStopInputDeviceCoordination(int32_t pid, int32_t userData)
int32_t DeviceStatusService::OnStopInputDeviceCoordination(int32_t pid, int32_t userData)
{
CALL_DEBUG_ENTER;
auto sess = GetSession(GetClientFd(pid));
@ -667,7 +667,7 @@ int32_t DevicestatusService::OnStopInputDeviceCoordination(int32_t pid, int32_t
return RET_OK;
}
int32_t DevicestatusService::OnGetInputDeviceCoordinationState(
int32_t DeviceStatusService::OnGetInputDeviceCoordinationState(
int32_t pid, int32_t userData, const std::string &deviceId)
{
CALL_DEBUG_ENTER;

View File

@ -29,17 +29,17 @@ namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DevicestatusSrvStub" };
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DeviceStatusSrvStub" };
} // namespace
int32_t DevicestatusSrvStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, \
int32_t DeviceStatusSrvStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, \
MessageOption &option)
{
DEV_HILOGD(SERVICE, "cmd = %{public}d, flags = %{public}d", code, option.GetFlags());
std::u16string descriptor = DevicestatusSrvStub::GetDescriptor();
std::u16string descriptor = DeviceStatusSrvStub::GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
DEV_HILOGE(SERVICE, "DevicestatusSrvStub::OnRemoteRequest failed, descriptor is not matched");
DEV_HILOGE(SERVICE, "DeviceStatusSrvStub::OnRemoteRequest failed, descriptor is not matched");
return E_DEVICESTATUS_GET_SERVICE_FAILED;
}
@ -51,7 +51,7 @@ int32_t DevicestatusSrvStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
return UnsubscribeStub(data);
}
case static_cast<int32_t>(Idevicestatus::DEVICESTATUS_GETCACHE): {
return GetLatestDevicestatusDataStub(data, reply);
return GetLatestDeviceStatusDataStub(data, reply);
}
case REGISTER_COORDINATION_MONITOR: {
return StubRegisterCoordinationMonitor(data, reply);
@ -81,7 +81,7 @@ int32_t DevicestatusSrvStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
return ERR_OK;
}
int32_t DevicestatusSrvStub::SubscribeStub(MessageParcel& data)
int32_t DeviceStatusSrvStub::SubscribeStub(MessageParcel& data)
{
DEV_HILOGD(SERVICE, "Enter");
int32_t type = -1;
@ -93,11 +93,11 @@ int32_t DevicestatusSrvStub::SubscribeStub(MessageParcel& data)
sptr<IdevicestatusCallback> callback = iface_cast<IdevicestatusCallback>(obj);
DEVICESTATUS_RETURN_IF_WITH_RET((callback == nullptr), E_DEVICESTATUS_READ_PARCEL_ERROR);
DEV_HILOGD(SERVICE, "Read callback successfully");
Subscribe(DevicestatusDataUtils::DevicestatusType(type), callback);
Subscribe(DeviceStatusDataUtils::DeviceStatusType(type), callback);
return ERR_OK;
}
int32_t DevicestatusSrvStub::UnsubscribeStub(MessageParcel& data)
int32_t DeviceStatusSrvStub::UnsubscribeStub(MessageParcel& data)
{
DEV_HILOGD(SERVICE, "Enter");
int32_t type = -1;
@ -106,16 +106,16 @@ int32_t DevicestatusSrvStub::UnsubscribeStub(MessageParcel& data)
DEVICESTATUS_RETURN_IF_WITH_RET((obj == nullptr), E_DEVICESTATUS_READ_PARCEL_ERROR);
sptr<IdevicestatusCallback> callback = iface_cast<IdevicestatusCallback>(obj);
DEVICESTATUS_RETURN_IF_WITH_RET((callback == nullptr), E_DEVICESTATUS_READ_PARCEL_ERROR);
Unsubscribe(DevicestatusDataUtils::DevicestatusType(type), callback);
Unsubscribe(DeviceStatusDataUtils::DeviceStatusType(type), callback);
return ERR_OK;
}
int32_t DevicestatusSrvStub::GetLatestDevicestatusDataStub(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::GetLatestDeviceStatusDataStub(MessageParcel& data, MessageParcel& reply)
{
DEV_HILOGD(SERVICE, "Enter");
int32_t type = -1;
READINT32(data, type, E_DEVICESTATUS_READ_PARCEL_ERROR);
DevicestatusDataUtils::DevicestatusData devicestatusData = GetCache(DevicestatusDataUtils::DevicestatusType(type));
DeviceStatusDataUtils::DeviceStatusData devicestatusData = GetCache(DeviceStatusDataUtils::DeviceStatusType(type));
DEV_HILOGD(SERVICE, "devicestatusData.type: %{public}d", devicestatusData.type);
DEV_HILOGD(SERVICE, "devicestatusData.value: %{public}d", devicestatusData.value);
WRITEINT32(reply, devicestatusData.type, E_DEVICESTATUS_WRITE_PARCEL_ERROR);
@ -124,7 +124,7 @@ int32_t DevicestatusSrvStub::GetLatestDevicestatusDataStub(MessageParcel& data,
return ERR_OK;
}
int32_t DevicestatusSrvStub::StubRegisterCoordinationMonitor(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubRegisterCoordinationMonitor(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;
int32_t ret = RegisterCoordinationListener();
@ -134,7 +134,7 @@ int32_t DevicestatusSrvStub::StubRegisterCoordinationMonitor(MessageParcel& data
return ret;
}
int32_t DevicestatusSrvStub::StubUnregisterCoordinationMonitor(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubUnregisterCoordinationMonitor(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;
int32_t ret = UnregisterCoordinationListener();
@ -144,7 +144,7 @@ int32_t DevicestatusSrvStub::StubUnregisterCoordinationMonitor(MessageParcel& da
return ret;
}
int32_t DevicestatusSrvStub::StubEnableInputDeviceCoordination(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubEnableInputDeviceCoordination(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;
int32_t userData;
@ -158,7 +158,7 @@ int32_t DevicestatusSrvStub::StubEnableInputDeviceCoordination(MessageParcel& da
return ret;
}
int32_t DevicestatusSrvStub::StubStartInputDeviceCoordination(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubStartInputDeviceCoordination(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;
int32_t userData;
@ -174,7 +174,7 @@ int32_t DevicestatusSrvStub::StubStartInputDeviceCoordination(MessageParcel& dat
return ret;
}
int32_t DevicestatusSrvStub::StubStopDeviceCoordination(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubStopDeviceCoordination(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;
int32_t userData;
@ -186,7 +186,7 @@ int32_t DevicestatusSrvStub::StubStopDeviceCoordination(MessageParcel& data, Mes
return ret;
}
int32_t DevicestatusSrvStub::StubGetInputDeviceCoordinationState(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubGetInputDeviceCoordinationState(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;
int32_t userData;
@ -200,7 +200,7 @@ int32_t DevicestatusSrvStub::StubGetInputDeviceCoordinationState(MessageParcel&
return ret;
}
int32_t DevicestatusSrvStub::StubHandleAllocSocketFd(MessageParcel& data, MessageParcel& reply)
int32_t DeviceStatusSrvStub::StubHandleAllocSocketFd(MessageParcel& data, MessageParcel& reply)
{
int32_t pid = GetCallingPid();
if (!IsRunning()) {

View File

@ -199,8 +199,8 @@ void UDSServer::ReleaseSession(int32_t fd, epoll_event& ev)
circleBufMap_.erase(it);
}
close(fd);
auto DevicestatusService = DeviceStatus::DelayedSpSingleton<DeviceStatus::DevicestatusService>::GetInstance();
DevicestatusService->DelEpoll(EPOLL_EVENT_SOCKET, fd);
auto DeviceStatusService = DeviceStatus::DelayedSpSingleton<DeviceStatus::DeviceStatusService>::GetInstance();
DeviceStatusService->DelEpoll(EPOLL_EVENT_SOCKET, fd);
}
void UDSServer::OnPacket(int32_t fd, NetPacket& pkt)

View File

@ -23,14 +23,14 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusModuleTest : public testing::Test {
class DeviceStatusModuleTest : public testing::Test {
public:
class DevicestatusModuleTestCallback : public DevicestatusCallbackStub {
class DeviceStatusModuleTestCallback : public DeviceStatusCallbackStub {
public:
DevicestatusModuleTestCallback() {};
virtual ~DevicestatusModuleTestCallback() {};
virtual void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
DeviceStatusModuleTestCallback() {};
virtual ~DeviceStatusModuleTestCallback() {};
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
};
};
} // namespace DeviceStatus

View File

@ -31,26 +31,26 @@ using namespace OHOS::Msdp::DeviceStatus;
using namespace OHOS;
using namespace std;
void DevicestatusModuleTest::DevicestatusModuleTestCallback::OnDevicestatusChanged(const \
DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusModuleTest::DeviceStatusModuleTestCallback::OnDeviceStatusChanged(const \
DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
GTEST_LOG_(INFO) << "DevicestatusModuleTestCallback type: " << devicestatusData.type;
GTEST_LOG_(INFO) << "DevicestatusModuleTestCallback value: " << devicestatusData.value;
EXPECT_EQ(true, devicestatusData.type == DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL && \
devicestatusData.value == DevicestatusDataUtils::DevicestatusValue::VALUE_ENTER) << \
"DevicestatusModuleTestCallback failed";
GTEST_LOG_(INFO) << "DeviceStatusModuleTestCallback type: " << devicestatusData.type;
GTEST_LOG_(INFO) << "DeviceStatusModuleTestCallback value: " << devicestatusData.value;
EXPECT_EQ(true, devicestatusData.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL && \
devicestatusData.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_ENTER) << \
"DeviceStatusModuleTestCallback failed";
}
/**
* @tc.name: DevicestatusCallbackTest
* @tc.name: DeviceStatusCallbackTest
* @tc.desc: test devicestatus callback in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusModuleTest, DevicestatusCallbackTest, TestSize.Level0)
HWTEST_F (DeviceStatusModuleTest, DeviceStatusCallbackTest, TestSize.Level0)
{
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DevicestatusClient::GetInstance();
sptr<IdevicestatusCallback> cb = new (std::nothrow) DevicestatusModuleTestCallback();
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
sptr<IdevicestatusCallback> cb = new (std::nothrow) DeviceStatusModuleTestCallback();
EXPECT_FALSE(cb == nullptr);
GTEST_LOG_(INFO) << "Start register";
devicestatusClient.SubscribeCallback(type, cb);
@ -59,52 +59,52 @@ HWTEST_F (DevicestatusModuleTest, DevicestatusCallbackTest, TestSize.Level0)
}
/**
* @tc.name: GetDevicestatusDataTest
* @tc.name: GetDeviceStatusDataTest
* @tc.desc: test get devicestatus data in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusModuleTest, GetDevicestatusDataTest001, TestSize.Level0)
HWTEST_F (DeviceStatusModuleTest, GetDeviceStatusDataTest001, TestSize.Level0)
{
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest001 Enter");
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest001 Enter");
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_EQ(true, data.type == DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
EXPECT_EQ(true, data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
}
/**
* @tc.name: GetDevicestatusDataTest
* @tc.name: GetDeviceStatusDataTest
* @tc.desc: test get devicestatus data in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusModuleTest, GetDevicestatusDataTest002, TestSize.Level0)
HWTEST_F (DeviceStatusModuleTest, GetDeviceStatusDataTest002, TestSize.Level0)
{
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest002 Enter");
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest002 Enter");
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_EQ(true, data.type == DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
EXPECT_EQ(true, data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
}
/**
* @tc.name: GetDevicestatusDataTest
* @tc.name: GetDeviceStatusDataTest
* @tc.desc: test get devicestatus data in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusModuleTest, GetDevicestatusDataTest003, TestSize.Level0)
HWTEST_F (DeviceStatusModuleTest, GetDeviceStatusDataTest003, TestSize.Level0)
{
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest003 Enter");
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest003 Enter");
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_EQ(true, data.type == DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
EXPECT_EQ(true, data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
}

View File

@ -63,7 +63,7 @@ ohos_unittest("test_devicestatus_service") {
]
}
ohos_unittest("DevicestatusAgentTest") {
ohos_unittest("DeviceStatusAgentTest") {
module_out_path = module_output_path
include_dirs = [ "${device_status_interfaces_path}/innerkits/include" ]
@ -88,7 +88,7 @@ ohos_unittest("DevicestatusAgentTest") {
]
}
ohos_unittest("DevicestatusClientTest") {
ohos_unittest("DeviceStatusClientTest") {
module_out_path = module_output_path
include_dirs = [ "//base/msdp/devicestatus/interfaces/innerkits/include" ]
@ -119,8 +119,8 @@ group("unittest") {
deps = []
deps += [
":DevicestatusAgentTest",
":DevicestatusClientTest",
":DeviceStatusAgentTest",
":DeviceStatusClientTest",
":test_devicestatus_service",
]
}

View File

@ -24,22 +24,22 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusAgentTest : public testing::Test {
class DeviceStatusAgentTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
class DevicestatusAgentListenerMockFirstClient : public DeviceStatusAgent::DeviceStatusAgentEvent {
class DeviceStatusAgentListenerMockFirstClient : public DeviceStatusAgent::DeviceStatusAgentEvent {
public:
virtual ~DevicestatusAgentListenerMockFirstClient() {};
bool OnEventResult(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
virtual ~DeviceStatusAgentListenerMockFirstClient() {};
bool OnEventResult(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
};
class DevicestatusAgentListenerMockSecondClient : public DeviceStatusAgent::DeviceStatusAgentEvent {
class DeviceStatusAgentListenerMockSecondClient : public DeviceStatusAgent::DeviceStatusAgentEvent {
public:
virtual ~DevicestatusAgentListenerMockSecondClient() {};
bool OnEventResult(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
virtual ~DeviceStatusAgentListenerMockSecondClient() {};
bool OnEventResult(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
};
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -28,7 +28,7 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusClientTest : public testing::Test {
class DeviceStatusClientTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();

View File

@ -24,14 +24,14 @@ namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
const std::u16string ARGS_H = u"-h";
class DevicestatusServiceTest : public testing::Test {
class DeviceStatusServiceTest : public testing::Test {
public:
class DevicestatusServiceTestCallback : public DevicestatusCallbackStub {
class DeviceStatusServiceTestCallback : public DeviceStatusCallbackStub {
public:
DevicestatusServiceTestCallback() {};
virtual ~DevicestatusServiceTestCallback() {};
virtual void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
DeviceStatusServiceTestCallback() {};
virtual ~DeviceStatusServiceTestCallback() {};
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
};
};
} // namespace DeviceStatus

View File

@ -25,307 +25,307 @@ using namespace std;
static std::shared_ptr<DeviceStatusAgent> agent1_;
static std::shared_ptr<DeviceStatusAgent> agent2_;
void DevicestatusAgentTest::SetUpTestCase()
void DeviceStatusAgentTest::SetUpTestCase()
{
}
void DevicestatusAgentTest::TearDownTestCase()
void DeviceStatusAgentTest::TearDownTestCase()
{
}
void DevicestatusAgentTest::SetUp()
void DeviceStatusAgentTest::SetUp()
{
agent1_ = std::make_shared<DeviceStatusAgent>();
agent2_ = std::make_shared<DeviceStatusAgent>();
}
void DevicestatusAgentTest::TearDown()
void DeviceStatusAgentTest::TearDown()
{
}
bool DevicestatusAgentListenerMockFirstClient::OnEventResult(
const DevicestatusDataUtils::DevicestatusData& devicestatusData)
bool DeviceStatusAgentListenerMockFirstClient::OnEventResult(
const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
GTEST_LOG_(INFO) << "agent type: " << devicestatusData.type;
GTEST_LOG_(INFO) << "agent value: " << devicestatusData.value;
EXPECT_TRUE(devicestatusData.type == DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
EXPECT_TRUE(devicestatusData.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
return true;
}
bool DevicestatusAgentListenerMockSecondClient::OnEventResult(
const DevicestatusDataUtils::DevicestatusData& devicestatusData)
bool DeviceStatusAgentListenerMockSecondClient::OnEventResult(
const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
GTEST_LOG_(INFO) << "agent type: " << devicestatusData.type;
GTEST_LOG_(INFO) << "agent value: " << devicestatusData.value;
EXPECT_TRUE(devicestatusData.type == DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
EXPECT_TRUE(devicestatusData.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
return true;
}
namespace {
/**
* @tc.name: DevicestatusAgentTest001
* @tc.name: DeviceStatusAgentTest001
* @tc.desc: test subscribing lid open event
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest001, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest001 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest001 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
GTEST_LOG_(INFO) << "DevicestatusAgentTest001 end";
agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest001 end";
}
/**
* @tc.name: DevicestatusAgentTest002
* @tc.name: DeviceStatusAgentTest002
* @tc.desc: test subscribing lid open event repeatedly
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest002, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest002 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest002 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will not report";
sleep(2);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report again";
sleep(2);
agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
GTEST_LOG_(INFO) << "DevicestatusAgentTest002 end";
agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest002 end";
}
/**
* @tc.name: DevicestatusAgentTest003
* @tc.name: DeviceStatusAgentTest003
* @tc.desc: test subscribing lid open event for 2 client
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest003, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest003 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent1 =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
std::shared_ptr<DevicestatusAgentListenerMockSecondClient> agentEvent2 =
std::make_shared<DevicestatusAgentListenerMockSecondClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent1);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest003 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent1 =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
std::shared_ptr<DeviceStatusAgentListenerMockSecondClient> agentEvent2 =
std::make_shared<DeviceStatusAgentListenerMockSecondClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent1);
EXPECT_TRUE(ret == ERR_OK);
ret = agent2_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent2);
ret = agent2_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent2);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
GTEST_LOG_(INFO) << "Unsubscribe agentEvent1";
agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
sleep(2);
GTEST_LOG_(INFO) << "Unsubscribe agentEvent2";
agent2_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
GTEST_LOG_(INFO) << "DevicestatusAgentTest003 end";
agent2_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest003 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest004, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest004 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest004 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH);
GTEST_LOG_(INFO) << "DevicestatusAgentTest004 end";
agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest004 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest005, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest005 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest005 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL);
GTEST_LOG_(INFO) << "DevicestatusAgentTest005 end";
agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest005 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest006, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest006, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest006 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest006 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL);
GTEST_LOG_(INFO) << "DevicestatusAgentTest006 end";
agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest006 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest007, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest007, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest007 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest007 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID, agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "DevicestatusAgentTest007 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest007 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest008, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest008, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest008 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10), agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest008 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10), agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "DevicestatusAgentTest008 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest008 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest009, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest009, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest009 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest009 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID, agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL, agentEvent);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "DevicestatusAgentTest009 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest009 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest010, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest010, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest010 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest010 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
GTEST_LOG_(INFO) << "DevicestatusAgentTest010 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest010 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest011, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest011, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest011 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent1 = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest011 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent1 = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID, agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL, agentEvent);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->SubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10), agentEvent);
ret = agent1_->SubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10), agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL, agentEvent);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH, agentEvent1);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH, agentEvent1);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->UnsubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10));
ret = agent1_->UnsubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10));
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "DevicestatusAgentTest011 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest011 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest012, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest012, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest012 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent1 = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest012 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent1 = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID, agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL, agentEvent);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->SubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10), agentEvent);
ret = agent1_->SubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10), agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH, agentEvent1);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH, agentEvent1);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->UnsubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10));
ret = agent1_->UnsubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10));
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL);
EXPECT_TRUE(ret == ERR_OK);
GTEST_LOG_(INFO) << "DevicestatusAgentTest012 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest012 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest013, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest013, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest013 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent1 = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest013 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent1 = nullptr;
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID, agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10), agentEvent);
ret = agent1_->SubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10), agentEvent);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL, agentEvent1);
ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, agentEvent1);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "Open and close the lid, and event will report";
sleep(2);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
ret = agent1_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL);
ret = agent1_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL);
EXPECT_TRUE(ret == ERR_OK);
ret = agent1_->UnsubscribeAgentEvent(static_cast<DevicestatusDataUtils::DevicestatusType>(10));
ret = agent1_->UnsubscribeAgentEvent(static_cast<DeviceStatusDataUtils::DeviceStatusType>(10));
EXPECT_TRUE(ret == ERR_INVALID_VALUE);
GTEST_LOG_(INFO) << "DevicestatusAgentTest013 end";
GTEST_LOG_(INFO) << "DeviceStatusAgentTest013 end";
}
HWTEST_F (DevicestatusAgentTest, DevicestatusAgentTest014, TestSize.Level1)
HWTEST_F (DeviceStatusAgentTest, DeviceStatusAgentTest014, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusAgentTest014 start";
std::shared_ptr<DevicestatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DevicestatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest014 start";
std::shared_ptr<DeviceStatusAgentListenerMockFirstClient> agentEvent =
std::make_shared<DeviceStatusAgentListenerMockFirstClient>();
int32_t ret = agent1_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent);
EXPECT_TRUE(ret == ERR_OK);
sptr<IdevicestatusCallback> callback = new DeviceStatusAgent::DeviceStatusAgentCallback(agent1_);
DevicestatusDataUtils::DevicestatusData devicestatusData = {
DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN,
DevicestatusDataUtils::DevicestatusValue::VALUE_ENTER
DeviceStatusDataUtils::DeviceStatusData devicestatusData = {
DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN,
DeviceStatusDataUtils::DeviceStatusValue::VALUE_ENTER
};
callback->OnDevicestatusChanged(devicestatusData);
GTEST_LOG_(INFO) << "DevicestatusAgentTest014 end";
callback->OnDeviceStatusChanged(devicestatusData);
GTEST_LOG_(INFO) << "DeviceStatusAgentTest014 end";
}
}

View File

@ -29,34 +29,34 @@ using namespace std;
static std::shared_ptr<DeviceStatusCallbackProxy> callbackProxy_;
static std::shared_ptr<DeviceStatusAgent> agent_;
void DevicestatusClientTest::SetUpTestCase()
void DeviceStatusClientTest::SetUpTestCase()
{
GTEST_LOG_(INFO) << "SetUpTestCase start";
agent_ = std::make_shared<DeviceStatusAgent>();
GTEST_LOG_(INFO) << "SetUpTestCase end";
}
void DevicestatusClientTest::TearDownTestCase()
void DeviceStatusClientTest::TearDownTestCase()
{
}
void DevicestatusClientTest::SetUp()
void DeviceStatusClientTest::SetUp()
{
}
void DevicestatusClientTest::TearDown()
void DeviceStatusClientTest::TearDown()
{
}
namespace {
/**
* @tc.name: DevicestatusClientTest001
* @tc.name: DeviceStatusClientTest001
* @tc.desc: test OnRemoteDied
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest001, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest001 start";
GTEST_LOG_(INFO) << "DeviceStatusClientTest001 start";
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
GTEST_LOG_(INFO) << "GetSystemAbilityManager failed";
@ -67,25 +67,25 @@ HWTEST_F (DevicestatusClientTest, DevicestatusClientTest001, TestSize.Level1)
GTEST_LOG_(INFO) << "CheckSystemAbility failed";
return;
}
auto& client = DevicestatusClient::GetInstance();
auto& client = DeviceStatusClient::GetInstance();
DEV_HILOGE(INNERKIT, "test OnRemoteDied start");
sptr<IRemoteObject::DeathRecipient> deathRecipient_ =
sptr<IRemoteObject::DeathRecipient>(new DevicestatusClient::DevicestatusDeathRecipient());
sptr<IRemoteObject::DeathRecipient>(new DeviceStatusClient::DeviceStatusDeathRecipient());
deathRecipient_->OnRemoteDied(remoteObject_);
DEV_HILOGE(INNERKIT, "test OnRemoteDied end");
EXPECT_TRUE(client.devicestatusProxy_ == nullptr);
GTEST_LOG_(INFO) << "DevicestatusClientTest001 end";
GTEST_LOG_(INFO) << "DeviceStatusClientTest001 end";
}
/**
* @tc.name: DevicestatusClientTest002
* @tc.desc: test OnDevicestatusChanged
* @tc.name: DeviceStatusClientTest002
* @tc.desc: test OnDeviceStatusChanged
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest002, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest002 start";
GTEST_LOG_(INFO) << "DeviceStatusClientTest002 start";
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
GTEST_LOG_(INFO) << "GetSystemAbilityManager failed";
@ -97,122 +97,122 @@ HWTEST_F (DevicestatusClientTest, DevicestatusClientTest002, TestSize.Level1)
return;
}
callbackProxy_ = std::make_shared<DeviceStatusCallbackProxy>(remoteObject_);
DevicestatusDataUtils::DevicestatusData devicestatusData = {
DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL,
DevicestatusDataUtils::DevicestatusValue::VALUE_ENTER
DeviceStatusDataUtils::DeviceStatusData devicestatusData = {
DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL,
DeviceStatusDataUtils::DeviceStatusValue::VALUE_ENTER
};
DEV_HILOGE(INNERKIT, "test OnDevicestatusChanged start");
callbackProxy_->OnDevicestatusChanged(devicestatusData);
DEV_HILOGE(INNERKIT, "test OnDevicestatusChanged end");
GTEST_LOG_(INFO) << "DevicestatusClientTest002 end";
DEV_HILOGE(INNERKIT, "test OnDeviceStatusChanged start");
callbackProxy_->OnDeviceStatusChanged(devicestatusData);
DEV_HILOGE(INNERKIT, "test OnDeviceStatusChanged end");
GTEST_LOG_(INFO) << "DeviceStatusClientTest002 end";
}
/**
* @tc.name: DevicestatusClientTest003
* @tc.name: DeviceStatusClientTest003
* @tc.desc: test null proxy subscribe
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest003, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest003 start";
GTEST_LOG_(INFO) << "DeviceStatusClientTest003 start";
sptr<IdevicestatusCallback> callback =
sptr<IdevicestatusCallback>(new DeviceStatusAgent::DeviceStatusAgentCallback(agent_));
auto& client = DevicestatusClient::GetInstance();
auto& client = DeviceStatusClient::GetInstance();
client.devicestatusProxy_ = nullptr;
DEV_HILOGE(INNERKIT, "test SubscribeCallback start");
client.SubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, callback);
client.SubscribeCallback(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, callback);
DEV_HILOGE(INNERKIT, "test SubscribeCallback end");
GTEST_LOG_(INFO) << "DevicestatusClientTest003 end";
GTEST_LOG_(INFO) << "DeviceStatusClientTest003 end";
}
/**
* @tc.name: DevicestatusClientTest004
* @tc.name: DeviceStatusClientTest004
* @tc.desc: test null proxy unsubscribe
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest004, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest004 start";
GTEST_LOG_(INFO) << "DeviceStatusClientTest004 start";
sptr<IdevicestatusCallback> callback =
sptr<IdevicestatusCallback>(new DeviceStatusAgent::DeviceStatusAgentCallback(agent_));
auto& client = DevicestatusClient::GetInstance();
auto& client = DeviceStatusClient::GetInstance();
client.devicestatusProxy_ = nullptr;
DEV_HILOGE(INNERKIT, "test UnsubscribeCallback start");
client.UnsubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, callback);
client.UnsubscribeCallback(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, callback);
DEV_HILOGE(INNERKIT, "test UnsubscribeCallback end");
GTEST_LOG_(INFO) << "DevicestatusClientTest004 end";
GTEST_LOG_(INFO) << "DeviceStatusClientTest004 end";
}
/**
* @tc.name: DevicestatusClientTest005
* @tc.name: DeviceStatusClientTest005
* @tc.desc: test null proxy unsubscribe
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest005, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest005 start";
auto& client = DevicestatusClient::GetInstance();
GTEST_LOG_(INFO) << "DeviceStatusClientTest005 start";
auto& client = DeviceStatusClient::GetInstance();
client.devicestatusProxy_ = nullptr;
DEV_HILOGE(INNERKIT, "test GetDevicestatusData start");
auto data = client.GetDevicestatusData(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
DEV_HILOGE(INNERKIT, "test GetDevicestatusData end");
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
GTEST_LOG_(INFO) << "DevicestatusClientTest005 end";
DEV_HILOGE(INNERKIT, "test GetDeviceStatusData start");
auto data = client.GetDeviceStatusData(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
DEV_HILOGE(INNERKIT, "test GetDeviceStatusData end");
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
GTEST_LOG_(INFO) << "DeviceStatusClientTest005 end";
}
/**
* @tc.name: DevicestatusClientTest006
* @tc.name: DeviceStatusClientTest006
* @tc.desc: test null proxy destructor
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest006, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest006, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest006 start";
DevicestatusClient* client1 = new(std::nothrow) DevicestatusClient();
GTEST_LOG_(INFO) << "DeviceStatusClientTest006 start";
DeviceStatusClient* client1 = new(std::nothrow) DeviceStatusClient();
delete client1;
client1 = nullptr;
DevicestatusClient* client2 = new(std::nothrow) DevicestatusClient();
DeviceStatusClient* client2 = new(std::nothrow) DeviceStatusClient();
client2->devicestatusProxy_ = nullptr;
delete client2;
client2 = nullptr;
GTEST_LOG_(INFO) << "DevicestatusClientTest006 end";
GTEST_LOG_(INFO) << "DeviceStatusClientTest006 end";
}
/**
* @tc.name: DevicestatusClientTest007
* @tc.name: DeviceStatusClientTest007
* @tc.desc: test null OnRemoteDied
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest007, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest007, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest007 start";
GTEST_LOG_(INFO) << "DeviceStatusClientTest007 start";
DEV_HILOGE(INNERKIT, "test OnRemoteDied start");
sptr<IRemoteObject::DeathRecipient> deathRecipient_ =
sptr<IRemoteObject::DeathRecipient>(new DevicestatusClient::DevicestatusDeathRecipient());
sptr<IRemoteObject::DeathRecipient>(new DeviceStatusClient::DeviceStatusDeathRecipient());
deathRecipient_->OnRemoteDied(nullptr);
DEV_HILOGE(INNERKIT, "test OnRemoteDied end");
auto& client = DevicestatusClient::GetInstance();
auto& client = DeviceStatusClient::GetInstance();
EXPECT_TRUE(client.devicestatusProxy_ != nullptr);
GTEST_LOG_(INFO) << "DevicestatusClientTest007 end";
GTEST_LOG_(INFO) << "DeviceStatusClientTest007 end";
}
/**
* @tc.name: DevicestatusClientTest008
* @tc.name: DeviceStatusClientTest008
* @tc.desc: test proxy double subscribe
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusClientTest, DevicestatusClientTest008, TestSize.Level1)
HWTEST_F (DeviceStatusClientTest, DeviceStatusClientTest008, TestSize.Level1)
{
GTEST_LOG_(INFO) << "DevicestatusClientTest008 start";
GTEST_LOG_(INFO) << "DeviceStatusClientTest008 start";
sptr<IdevicestatusCallback> callback =
sptr<IdevicestatusCallback>(new (std::nothrow) DeviceStatusAgent::DeviceStatusAgentCallback(agent_));
auto& client = DevicestatusClient::GetInstance();
auto& client = DeviceStatusClient::GetInstance();
DEV_HILOGE(INNERKIT, "test SubscribeCallback start");
client.SubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, callback);
client.SubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, callback);
client.SubscribeCallback(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, callback);
client.SubscribeCallback(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, callback);
DEV_HILOGE(INNERKIT, "test SubscribeCallback end");
GTEST_LOG_(INFO) << "DevicestatusClientTest008 end";
GTEST_LOG_(INFO) << "DeviceStatusClientTest008 end";
}
}

View File

@ -33,26 +33,26 @@ using namespace OHOS::Msdp::DeviceStatus;
using namespace OHOS;
using namespace std;
void DevicestatusServiceTest::DevicestatusServiceTestCallback::OnDevicestatusChanged(const \
DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusServiceTest::DeviceStatusServiceTestCallback::OnDeviceStatusChanged(const \
DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
GTEST_LOG_(INFO) << "DevicestatusServiceTestCallback type: " << devicestatusData.type;
GTEST_LOG_(INFO) << "DevicestatusServiceTestCallback value: " << devicestatusData.value;
EXPECT_TRUE(devicestatusData.type == DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL && \
devicestatusData.value == DevicestatusDataUtils::DevicestatusValue::VALUE_ENTER) << \
"DevicestatusServiceTestCallback failed";
GTEST_LOG_(INFO) << "DeviceStatusServiceTestCallback type: " << devicestatusData.type;
GTEST_LOG_(INFO) << "DeviceStatusServiceTestCallback value: " << devicestatusData.value;
EXPECT_TRUE(devicestatusData.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL && \
devicestatusData.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_ENTER) << \
"DeviceStatusServiceTestCallback failed";
}
/**
* @tc.name: DevicestatusCallbackTest
* @tc.name: DeviceStatusCallbackTest
* @tc.desc: test devicestatus callback in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusServiceTest, DevicestatusCallbackTest, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, DeviceStatusCallbackTest, TestSize.Level0)
{
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DevicestatusClient::GetInstance();
sptr<IdevicestatusCallback> cb = new (std::nothrow) DevicestatusServiceTestCallback();
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
sptr<IdevicestatusCallback> cb = new (std::nothrow) DeviceStatusServiceTestCallback();
EXPECT_FALSE(cb == nullptr);
GTEST_LOG_(INFO) << "Start register";
devicestatusClient.SubscribeCallback(type, cb);
@ -61,110 +61,110 @@ HWTEST_F (DevicestatusServiceTest, DevicestatusCallbackTest, TestSize.Level0)
}
/**
* @tc.name: GetDevicestatusDataTest
* @tc.name: GetDeviceStatusDataTest
* @tc.desc: test get devicestatus data in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest001, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest001, TestSize.Level0)
{
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest001 Enter");
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest001 Enter");
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_HIGH_STILL && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest001 end");
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest001 end");
}
/**
* @tc.name: GetDevicestatusDataTest
* @tc.name: GetDeviceStatusDataTest
* @tc.desc: test get devicestatus data in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest002, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest002, TestSize.Level0)
{
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest002 Enter");
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest002 Enter");
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_FINE_STILL && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest002 end");
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest002 end");
}
/**
* @tc.name: GetDevicestatusDataTest
* @tc.name: GetDeviceStatusDataTest
* @tc.desc: test get devicestatus data in proxy
* @tc.type: FUNC
*/
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest003, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest003, TestSize.Level0)
{
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest003 Enter");
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest003 Enter");
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
DEV_HILOGI(SERVICE, "GetDevicestatusDataTest003 end");
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusData failed";
DEV_HILOGI(SERVICE, "GetDeviceStatusDataTest003 end");
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest004, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest004, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest004 Enter";
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest004 Enter";
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusDataTest004 failed";
GTEST_LOG_(INFO) << "GetDevicestatusDataTest004 end";
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusDataTest004 failed";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest004 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest005, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest005, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest005 Enter";
DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_INVALID;
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest005 Enter";
DeviceStatusDataUtils::DeviceStatusType type = DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_INVALID && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusDataTest005 failed";
GTEST_LOG_(INFO) << "GetDevicestatusDataTest005 end";
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusDataTest005 failed";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest005 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest006, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest006, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest006 Enter";
DevicestatusDataUtils::DevicestatusType type = static_cast<DevicestatusDataUtils::DevicestatusType>(10);
auto& devicestatusClient = DevicestatusClient::GetInstance();
DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest006 Enter";
DeviceStatusDataUtils::DeviceStatusType type = static_cast<DeviceStatusDataUtils::DeviceStatusType>(10);
auto& devicestatusClient = DeviceStatusClient::GetInstance();
DeviceStatusDataUtils::DeviceStatusData data = devicestatusClient.GetDeviceStatusData(type);
GTEST_LOG_(INFO) << "type: " << data.type;
GTEST_LOG_(INFO) << "value: " << data.value;
EXPECT_TRUE(data.type == DevicestatusDataUtils::DevicestatusType::TYPE_INVALID && \
data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusDataTest006 failed";
GTEST_LOG_(INFO) << "GetDevicestatusDataTest006 end";
EXPECT_TRUE(data.type == DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID && \
data.value == DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID) << "GetDeviceStatusDataTest006 failed";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest006 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest007, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest007, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest007 Enter";
auto devicestatusService = DelayedSpSingleton<DevicestatusService>::GetInstance();
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest007 Enter";
auto devicestatusService = DelayedSpSingleton<DeviceStatusService>::GetInstance();
devicestatusService->OnDump();
GTEST_LOG_(INFO) << "GetDevicestatusDataTest007 end";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest007 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest008, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest008, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest008 Enter";
auto devicestatusService = DelayedSpSingleton<DevicestatusService>::GetInstance();
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest008 Enter";
auto devicestatusService = DelayedSpSingleton<DeviceStatusService>::GetInstance();
std::vector<std::u16string> args;
int32_t ret = devicestatusService->Dump(-1, args);
EXPECT_TRUE(ret == RET_NG);
@ -173,50 +173,50 @@ HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest008, TestSize.Level0)
args.emplace_back(ARGS_H);
ret = devicestatusService->Dump(1, args);
EXPECT_TRUE(ret == RET_OK);
GTEST_LOG_(INFO) << "GetDevicestatusDataTest008 end";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest008 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest009, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest009, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest009 Enter";
auto devicestatusCBDeathRecipient = new (std::nothrow) DevicestatusManager::DevicestatusCallbackDeathRecipient();
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest009 Enter";
auto devicestatusCBDeathRecipient = new (std::nothrow) DeviceStatusManager::DeviceStatusCallbackDeathRecipient();
devicestatusCBDeathRecipient->OnRemoteDied(nullptr);
GTEST_LOG_(INFO) << "GetDevicestatusDataTest009 end";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest009 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest010, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest010, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest010 Enter";
auto devicestatusService = DelayedSpSingleton<DevicestatusService>::GetInstance();
auto devicestatusManager = std::make_shared<DevicestatusManager>(devicestatusService);
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest010 Enter";
auto devicestatusService = DelayedSpSingleton<DeviceStatusService>::GetInstance();
auto devicestatusManager = std::make_shared<DeviceStatusManager>(devicestatusService);
Security::AccessToken::AccessTokenID tokenId = static_cast<Security::AccessToken::AccessTokenID>(1);
std::string packageName;
devicestatusManager->GetPackageName(tokenId, packageName);
GTEST_LOG_(INFO) << "GetDevicestatusDataTest010 end";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest010 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest011, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest011, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest011 Enter";
auto devicestatusService = DelayedSpSingleton<DevicestatusService>::GetInstance();
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest011 Enter";
auto devicestatusService = DelayedSpSingleton<DeviceStatusService>::GetInstance();
devicestatusService->OnStop();
devicestatusService->OnStart();
devicestatusService->OnStart();
devicestatusService->OnStop();
GTEST_LOG_(INFO) << "GetDevicestatusDataTest011 end";
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest011 end";
}
HWTEST_F (DevicestatusServiceTest, GetDevicestatusDataTest012, TestSize.Level0)
HWTEST_F (DeviceStatusServiceTest, GetDeviceStatusDataTest012, TestSize.Level0)
{
GTEST_LOG_(INFO) << "GetDevicestatusDataTest012 Enter";
auto devicestatusService = DelayedSpSingleton<DevicestatusService>::GetInstance();
auto devicestatusManager = std::make_shared<DevicestatusManager>(devicestatusService);
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest012 Enter";
auto devicestatusService = DelayedSpSingleton<DeviceStatusService>::GetInstance();
auto devicestatusManager = std::make_shared<DeviceStatusManager>(devicestatusService);
bool result = devicestatusManager->Init();
EXPECT_TRUE(result);
int32_t ret = devicestatusManager->LoadAlgorithm(false);
EXPECT_TRUE(ret == RET_OK);
ret = devicestatusManager->UnloadAlgorithm(false);
EXPECT_TRUE(ret == RET_OK);
DelayedSpSingleton<DevicestatusService>::DestroyInstance();
GTEST_LOG_(INFO) << "GetDevicestatusDataTest012 end";
DelayedSpSingleton<DeviceStatusService>::DestroyInstance();
GTEST_LOG_(INFO) << "GetDeviceStatusDataTest012 end";
}

View File

@ -21,56 +21,56 @@ using namespace OHOS::Msdp::DeviceStatus;
namespace {
const int WAIT_TIME = 1000;
}
static std::shared_ptr<DevicestatusAgentFuzzer::DeviceStatusAgentClient> agentEvent_ =
std::make_shared<DevicestatusAgentFuzzer::DeviceStatusAgentClient>();
static std::shared_ptr<DeviceStatusAgentFuzzer::DeviceStatusAgentClient> agentEvent_ =
std::make_shared<DeviceStatusAgentFuzzer::DeviceStatusAgentClient>();
static std::shared_ptr<DeviceStatusAgent> agent_ = std::make_shared<DeviceStatusAgent>();
bool DevicestatusAgentFuzzer::DeviceStatusAgentClient::OnEventResult(
const DevicestatusDataUtils::DevicestatusData& devicestatusData)
bool DeviceStatusAgentFuzzer::DeviceStatusAgentClient::OnEventResult(
const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
std::cout << "type: " << devicestatusData.type << std::endl;
std::cout << "value: " << devicestatusData.value << std::endl;
return true;
}
void DevicestatusAgentFuzzer::TestSubscribeAgentEvent(const uint8_t* data)
void DeviceStatusAgentFuzzer::TestSubscribeAgentEvent(const uint8_t* data)
{
std::cout << "TestSubscribeAgentEvent: Enter " << std::endl;
agent_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent_);
agent_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeAgentEvent(agent_);
}
void DevicestatusAgentFuzzer::TestUnsubscribeAgentEvent(const std::shared_ptr<DeviceStatusAgent>& agent_)
void DeviceStatusAgentFuzzer::TestUnsubscribeAgentEvent(const std::shared_ptr<DeviceStatusAgent>& agent_)
{
std::cout << "TestUnsubscribeAgentEvent: Enter " << std::endl;
agent_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
agent_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
}
void DevicestatusAgentFuzzer::TestSubscribeAgentEventIsNullptr(const uint8_t* data)
void DeviceStatusAgentFuzzer::TestSubscribeAgentEventIsNullptr(const uint8_t* data)
{
std::cout << "TestSubscribeAgentEventIsNullptr: Enter " << std::endl;
agentEvent_ = nullptr;
agent_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, agentEvent_);
agent_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeAgentEvent(agent_);
}
void DevicestatusAgentFuzzer::TestSubscribeAgentEventTypeIsNullptr(const uint8_t* data)
void DeviceStatusAgentFuzzer::TestSubscribeAgentEventTypeIsNullptr(const uint8_t* data)
{
std::cout << "TestSubscribeAgentEventTypeIsNullptr: Enter " << std::endl;
agent_->SubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID, agentEvent_);
agent_->SubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeAgentEventTypeIsNullptr(agent_);
}
void DevicestatusAgentFuzzer::TestUnsubscribeAgentEventTypeIsNullptr(const std::shared_ptr<DeviceStatusAgent>& agent_)
void DeviceStatusAgentFuzzer::TestUnsubscribeAgentEventTypeIsNullptr(const std::shared_ptr<DeviceStatusAgent>& agent_)
{
std::cout << "TestUnsubscribeAgentEventTypeIsNullptr: Enter " << std::endl;
agent_->UnsubscribeAgentEvent(DevicestatusDataUtils::DevicestatusType::TYPE_INVALID);
agent_->UnsubscribeAgentEvent(DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID);
}
bool DevicestatusAgentFuzzer::DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
bool DeviceStatusAgentFuzzer::DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
int idSize = 8;
if (static_cast<int>(size) > idSize) {
@ -85,6 +85,6 @@ bool DevicestatusAgentFuzzer::DoSomethingInterestingWithMyAPI(const uint8_t* dat
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::Msdp::DeviceStatus::DevicestatusAgentFuzzer::DoSomethingInterestingWithMyAPI(data, size);
OHOS::Msdp::DeviceStatus::DeviceStatusAgentFuzzer::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}

View File

@ -39,7 +39,7 @@ enum class ApiNumber {
NUM_TWO,
NUM_THREE
};
class DevicestatusAgentFuzzer {
class DeviceStatusAgentFuzzer {
public:
static bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size);
static void TestSubscribeAgentEvent(const uint8_t* data);
@ -50,7 +50,7 @@ public:
class DeviceStatusAgentClient : public DeviceStatusAgent::DeviceStatusAgentEvent {
public:
virtual ~DeviceStatusAgentClient() {};
bool OnEventResult(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
bool OnEventResult(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
};
};
} // namespace DeviceStatus

View File

@ -21,45 +21,45 @@
using namespace std;
using namespace OHOS;
using namespace OHOS::Msdp::DeviceStatus;
auto &client_ = DevicestatusClient::GetInstance();
sptr<DevicestatusClientFuzzer::DevicestatusTestCallback> cb = new DevicestatusClientFuzzer::DevicestatusTestCallback();
auto &client_ = DeviceStatusClient::GetInstance();
sptr<DeviceStatusClientFuzzer::DeviceStatusTestCallback> cb = new DeviceStatusClientFuzzer::DeviceStatusTestCallback();
const int WAIT_TIME = 1000;
void DevicestatusClientFuzzer::DevicestatusTestCallback::OnDevicestatusChanged(const \
DevicestatusDataUtils::DevicestatusData& devicestatusData)
void DeviceStatusClientFuzzer::DeviceStatusTestCallback::OnDeviceStatusChanged(const \
DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
{
std::cout << "DevicestatusTestCallback type: " << devicestatusData.type << std::endl;
std::cout << "DevicestatusTestCallback value: " << devicestatusData.value << std::endl;
std::cout << "DeviceStatusTestCallback type: " << devicestatusData.type << std::endl;
std::cout << "DeviceStatusTestCallback value: " << devicestatusData.value << std::endl;
}
void DevicestatusClientFuzzer::TestSubscribeCallback(const uint8_t* data)
void DeviceStatusClientFuzzer::TestSubscribeCallback(const uint8_t* data)
{
std::cout << "TestSubscribeCallback: Enter " << std::endl;
client_.SubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, cb);
client_.SubscribeCallback(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, cb);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestGetDevicestatusData();
TestGetDeviceStatusData();
}
void DevicestatusClientFuzzer::TestGetDevicestatusData()
void DeviceStatusClientFuzzer::TestGetDeviceStatusData()
{
std::cout << "TestGetDevicestatusData: Enter " << std::endl;
client_.GetDevicestatusData(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
std::cout << "TestGetDeviceStatusData: Enter " << std::endl;
client_.GetDeviceStatusData(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeCallback();
}
void DevicestatusClientFuzzer::TestUnsubscribeCallback()
void DeviceStatusClientFuzzer::TestUnsubscribeCallback()
{
std::cout << "TestUnsubscribeCallback: Enter " << std::endl;
client_.UnsubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, cb);
client_.UnsubscribeCallback(DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, cb);
}
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
DevicestatusClientFuzzer::TestSubscribeCallback(data);
DeviceStatusClientFuzzer::TestSubscribeCallback(data);
return true;
}

View File

@ -32,18 +32,18 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusClientFuzzer {
class DeviceStatusClientFuzzer {
public:
static bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size);
static void TestSubscribeCallback(const uint8_t* data);
static void TestGetDevicestatusData();
static void TestGetDeviceStatusData();
static void TestUnsubscribeCallback();
class DevicestatusTestCallback : public DevicestatusCallbackStub {
class DeviceStatusTestCallback : public DeviceStatusCallbackStub {
public:
DevicestatusTestCallback() {};
virtual ~DevicestatusTestCallback() {};
virtual void OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData& devicestatusData) override;
DeviceStatusTestCallback() {};
virtual ~DeviceStatusTestCallback() {};
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
};
};
} // namespace DeviceStatus

View File

@ -140,7 +140,7 @@ namespace DeviceStatus {
} while (0)
template<typename E>
constexpr auto DevicestatusToUnderlying(E e) noexcept
constexpr auto DeviceStatusToUnderlying(E e) noexcept
{
return static_cast<std::underlying_type_t<E>>(e);
}

View File

@ -23,11 +23,11 @@ namespace Msdp {
namespace DeviceStatus {
enum {
/**
* Module type: Devicestatus Service
* Module type: DeviceStatus Service
*/
DEVICESTATUS_MODULE_TYPE_SERVICE = 0,
/**
* Module type: Devicestatus Kit
* Module type: DeviceStatus Kit
*/
DEVICESTATUS_MODULE_TYPE_KIT = 1,
DEVICESTATUS_MODULE_TYPE_CLIENT = 2

View File

@ -56,7 +56,7 @@ namespace DeviceStatus {
#endif
// param of log interface, such as DEV_HILOGF.
enum DevicestatusSubModule {
enum DeviceStatusSubModule {
INNERKIT = 0,
SERVICE,
JS_NAPI,
@ -64,10 +64,10 @@ enum DevicestatusSubModule {
BUTT,
};
// 0xD002220: subsystem:Msdp module:Devicestatus, 8 bits reserved.
// 0xD002220: subsystem:Msdp module:DeviceStatus, 8 bits reserved.
static constexpr unsigned int BASE_MSDP_DOMAIN_ID = 0xD002220;
enum DevicestatusDomainId {
enum DeviceStatusDomainId {
DEVICESTATUS_INNERKIT_DOMAIN = BASE_MSDP_DOMAIN_ID + INNERKIT,
DEVICESTATUS_SERVICE_DOMAIN,
DEVICESTATUS_JS_NAPI,
@ -76,10 +76,10 @@ enum DevicestatusDomainId {
};
static constexpr OHOS::HiviewDFX::HiLogLabel DEVICESTATUS_LABEL[BUTT] = {
{LOG_CORE, DEVICESTATUS_INNERKIT_DOMAIN, "DevicestatusClient"},
{LOG_CORE, DEVICESTATUS_SERVICE_DOMAIN, "DevicestatusService"},
{LOG_CORE, DEVICESTATUS_JS_NAPI, "DevicestatusJsNapi"},
{LOG_CORE, DEVICESTATUS_COMMON, "DevicestatusCommon"},
{LOG_CORE, DEVICESTATUS_INNERKIT_DOMAIN, "DeviceStatusClient"},
{LOG_CORE, DEVICESTATUS_SERVICE_DOMAIN, "DeviceStatusService"},
{LOG_CORE, DEVICESTATUS_JS_NAPI, "DeviceStatusJsNapi"},
{LOG_CORE, DEVICESTATUS_COMMON, "DeviceStatusCommon"},
};
// In order to improve performance, do not check the module range.

View File

@ -21,7 +21,7 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DevicestatusPermission {
class DeviceStatusPermission {
public:
/* check caller's permission by finding pid uid by system */
static bool CheckCallingPermission(const std::string &permissionName);

View File

@ -21,7 +21,7 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
bool DevicestatusPermission::CheckCallingPermission(const string &permissionName)
bool DeviceStatusPermission::CheckCallingPermission(const string &permissionName)
{
Security::AccessToken::AccessTokenID callingToken = IPCSkeleton::GetCallingTokenID();
int32_t auth = Security::AccessToken::TypePermissionState::PERMISSION_DENIED;
@ -34,7 +34,7 @@ bool DevicestatusPermission::CheckCallingPermission(const string &permissionName
}
}
string DevicestatusPermission::GetAppInfo()
string DeviceStatusPermission::GetAppInfo()
{
pid_t pid = IPCSkeleton::GetCallingPid();
uid_t uid = IPCSkeleton::GetCallingUid();