adapt stationary module

Signed-off-by: blueyouh <bailiang18@huawei.com>
Change-Id: If0cfc0c8cb8ec4b91832a4a316068107b5b08741
This commit is contained in:
blueyouh 2024-05-04 02:44:57 +00:00
parent 32c1242829
commit 0b43426221
27 changed files with 806 additions and 16 deletions

View File

@ -20,6 +20,9 @@
#include "devicestatus_client.h"
#include "devicestatus_common.h"
#include "devicestatus_define.h"
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
#include "intention_manager.h"
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
namespace OHOS {
namespace Msdp {
@ -35,17 +38,29 @@ StationaryManager *StationaryManager::GetInstance()
int32_t StationaryManager::SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
sptr<IRemoteDevStaCallback> callback)
{
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
return INTER_MGR_IMPL.SubscribeCallback(type, event, latency, callback);
#else
return DeviceStatusClient::GetInstance().SubscribeCallback(type, event, latency, callback);
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
}
int32_t StationaryManager::UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback)
{
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
return INTER_MGR_IMPL.UnsubscribeCallback(type, event, callback);
#else
return DeviceStatusClient::GetInstance().UnsubscribeCallback(type, event, callback);
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
}
Data StationaryManager::GetDeviceStatusData(Type type)
{
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
return INTER_MGR_IMPL.GetDeviceStatusData(type);
#else
return DeviceStatusClient::GetInstance().GetDeviceStatusData(type);
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
}
} // namespace DeviceStatus
} // namespace Msdp

View File

@ -68,6 +68,7 @@ public:
void RemoteStartSuccess(const DSoftbusStartCooperateFinished &event);
void RelayCooperate(const DSoftbusRelayCooperate &event);
void OnPointerEvent(const InputPointerEvent &event);
void UpdateCursorPosition();
void ResetCursorPosition();
bool IsAllowCooperate();

View File

@ -412,6 +412,12 @@ void Context::SetCursorPosition(const Coordinate &cursorPos)
cursorPos.x, cursorPos.y, cursorPos_.x, cursorPos_.y, display->GetWidth(), display->GetHeight());
}
void Context::UpdateCursorPosition()
{
env_->GetInput().SetPointerLocation(cursorPos_.x, cursorPos_.y);
FI_HILOGI("Update cursor position (%{public}d,%{public}d)", cursorPos_.x, cursorPos_.y);
}
void Context::ResetCursorPosition()
{
constexpr Coordinate defaultCursorPos {

View File

@ -220,6 +220,7 @@ void CooperateIn::Initial::OnPointerEvent(Context &context, const CooperateEvent
return;
}
FI_HILOGI("Stop cooperation on operation of local pointer");
context.OnPointerEvent(notice);
parent_.StopCooperate(context, event);
}
@ -315,6 +316,7 @@ void CooperateIn::RelayConfirmation::OnPointerEvent(Context &context, const Coop
return;
}
FI_HILOGI("[relay cooperate] Stop cooperation on operation of local pointer");
context.OnPointerEvent(notice);
parent_.StopCooperate(context, event);
OnReset(context, event);
}
@ -442,6 +444,7 @@ void CooperateIn::StopCooperate(Context &context, const CooperateEvent &event)
{
FI_HILOGI("Stop cooperation with \'%{public}s\'", Utility::Anonymize(context.Peer()));
context.inputEventBuilder_.Disable();
context.UpdateCursorPosition();
DSoftbusStopCooperate notice {};
context.dsoftbus_.StopCooperate(context.Peer(), notice);

View File

@ -267,8 +267,10 @@ void StateMachine::OnPointerEvent(Context &context, const CooperateEvent &event)
{
CALL_DEBUG_ENTER;
InputPointerEvent pointerEvent = std::get<InputPointerEvent>(event.event);
Coordinate cursorPos = context.CursorPosition();
context.OnPointerEvent(pointerEvent);
Transfer(context, event);
pointerEvent.position = cursorPos;
Transfer(context, CooperateEvent { CooperateEventType::INPUT_POINTER_EVENT, pointerEvent });
}
void StateMachine::OnSoftbusSessionClosed(Context &context, const CooperateEvent &event)

View File

@ -13,11 +13,11 @@
import("../../../device_status.gni")
config("intention_client_public_config") {
config("intention_manager_public_config") {
include_dirs = [ "include" ]
}
ohos_source_set("intention_client_public_config") {
ohos_source_set("intention_manager") {
sanitize = {
integer_overflow = true
ubsan = true
@ -38,7 +38,7 @@ ohos_source_set("intention_client_public_config") {
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
]
public_configs = [ ":intention_client_public_config" ]
public_configs = [ ":intention_manager_public_config" ]
external_deps = [ "hilog:libhilog" ]

View File

@ -26,6 +26,7 @@
#include "drag_manager_impl.h"
#include "i_event_listener.h"
#include "socket_client.h"
#include "stationary_client.h"
#include "tunnel_client.h"
namespace OHOS {
@ -36,6 +37,10 @@ class IntentionManager {
public:
DISALLOW_MOVE(IntentionManager);
int32_t SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
sptr<IRemoteDevStaCallback> callback);
int32_t UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback);
Data GetDeviceStatusData(const Type type);
int32_t RegisterCoordinationListener(
std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
int32_t UnregisterCoordinationListener(
@ -86,6 +91,7 @@ private:
std::unique_ptr<SocketClient> client_ { nullptr };
CooperateClient cooperate_;
DragClient drag_;
StationaryClient stationary_;
};
#define INTER_MGR_IMPL OHOS::Singleton<IntentionManager>::GetInstance()

View File

@ -80,6 +80,22 @@ void IntentionManager::InitMsgHandler()
}
}
int32_t IntentionManager::SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
sptr<IRemoteDevStaCallback> callback)
{
return stationary_.SubscribeCallback(*tunnel_, type, event, latency, callback);
}
int32_t IntentionManager::UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback)
{
return stationary_.UnsubscribeCallback(*tunnel_, type, event, callback);
}
Data IntentionManager::GetDeviceStatusData(const Type type)
{
return stationary_.GetDeviceStatusData(*tunnel_, type);
}
int32_t IntentionManager::RegisterCoordinationListener(
std::shared_ptr<ICoordinationListener> listener, bool isCompatible)
{

View File

@ -23,7 +23,9 @@
#include <input_manager.h>
#include "drag_data.h"
#ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
#include "stream_session.h"
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
namespace OHOS {
namespace Msdp {

View File

@ -39,6 +39,7 @@ enum CommonAction : uint32_t {
enum class Intention : uint32_t {
UNKNOWN_INTENTION,
SOCKET,
STATIONARY,
DRAG,
COOPERATE,
};

View File

@ -18,6 +18,7 @@ config("intention_service_config") {
"include",
"${device_status_root_path}/intention/cooperate/server/include",
"${device_status_root_path}/intention/drag/server/include",
"${device_status_root_path}/intention/stationary/server/include",
"${device_status_root_path}/interfaces/innerkits/interaction/include",
]
}
@ -51,6 +52,7 @@ ohos_shared_library("intention_service") {
"${device_status_root_path}/intention/ipc/socket:intention_socket_server",
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_server",
"${device_status_root_path}/intention/prototype:intention_prototype",
"${device_status_root_path}/intention/stationary/server:intention_stationary_server",
"${device_status_root_path}/utils/common:devicestatus_util",
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
]

View File

@ -23,6 +23,7 @@
#include "intention_stub.h"
#include "i_context.h"
#include "socket_server.h"
#include "stationary_server.h"
namespace OHOS {
namespace Msdp {
@ -49,6 +50,7 @@ private:
private:
IContext *context_ { nullptr };
SocketServer socketServer_;
StationaryServer stationary_;
CooperateServer cooperate_;
DragServer drag_;
};

View File

@ -218,6 +218,9 @@ IPlugin* IntentionService::LoadPlugin(Intention intention)
case Intention::SOCKET: {
return &socketServer_;
}
case Intention::STATIONARY: {
return &stationary_;
}
case Intention::COOPERATE: {
return &cooperate_;
}

View File

@ -0,0 +1,65 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../../device_status.gni")
config("intention_stationary_client_public_config") {
include_dirs = [
"include",
"${device_status_root_path}/interfaces/innerkits/include",
]
}
ohos_source_set("intention_stationary_client") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
include_dirs = [
"include",
"${device_status_root_path}/interfaces/innerkits/include",
]
sources = [ "src/stationary_client.cpp" ]
public_configs = [ ":intention_stationary_client_public_config" ]
defines = device_status_default_defines
deps = [
"${device_status_root_path}/intention/data:intention_data",
"${device_status_root_path}/intention/drag/data:intention_drag_data",
"${device_status_root_path}/intention/ipc/socket:intention_socket_connection",
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_client",
"${device_status_root_path}/intention/prototype:intention_prototype",
"${device_status_root_path}/intention/stationary/data:intention_stationary_data",
"${device_status_root_path}/utils/common:devicestatus_util",
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"image_framework:image_native",
]
subsystem_name = "${device_status_subsystem_name}"
part_name = "${device_status_part_name}"
}

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTENTION_STATIONARY_CLIENT_H
#define INTENTION_STATIONARY_CLIENT_H
#include <map>
#include "nocopyable.h"
#include "i_tunnel_client.h"
#include "stationary_callback.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class StationaryClient final {
public:
StationaryClient() = default;
~StationaryClient() = default;
DISALLOW_COPY_AND_MOVE(StationaryClient);
int32_t SubscribeCallback(ITunnelClient &tunnel, Type type, ActivityEvent event,
ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback);
int32_t UnsubscribeCallback(ITunnelClient &tunnel, Type type, ActivityEvent event,
sptr<IRemoteDevStaCallback> callback);
Data GetDeviceStatusData(ITunnelClient &tunnel, Type type);
private:
std::mutex mtx_;
std::map<Type, int32_t> typeMap_;
};
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS
#endif // INTENTION_STATIONARY_CLIENT_H

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stationary_client.h"
#include "default_params.h"
#include "devicestatus_define.h"
#include "stationary_params.h"
#undef LOG_TAG
#define LOG_TAG "StationaryClient"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
int32_t StationaryClient::SubscribeCallback(ITunnelClient &tunnel, Type type, ActivityEvent event,
ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback)
{
SubscribeStationaryParam param { type, event, latency, callback };
DefaultReply reply {};
FI_HILOGI("SubscribeStationary(type:%{public}d,event:%{public}d,latency:%{public}d)", type, event, latency);
int32_t ret = tunnel.AddWatch(Intention::STATIONARY, StationaryRequestID::SUBSCRIBE_STATIONARY, param, reply);
if (ret != RET_OK) {
FI_HILOGE("SubscribeStationary fail, error:%{public}d", ret);
}
return ret;
}
int32_t StationaryClient::UnsubscribeCallback(ITunnelClient &tunnel, Type type, ActivityEvent event,
sptr<IRemoteDevStaCallback> callback)
{
UnsubscribeStationaryParam param { type, event, ReportLatencyNs::Latency_INVALID, callback };
DefaultReply reply {};
FI_HILOGI("UnsubscribeStationary(type:%{public}d,event:%{public}d)", type, event);
int32_t ret = tunnel.RemoveWatch(Intention::STATIONARY, StationaryRequestID::UNSUBSCRIBE_STATIONARY, param, reply);
if (ret != RET_OK) {
FI_HILOGE("UnsubscribeStationary fail, error:%{public}d", ret);
}
return ret;
}
Data StationaryClient::GetDeviceStatusData(ITunnelClient &tunnel, Type type)
{
GetStaionaryDataParam param { type };
GetStaionaryDataReply reply {};
FI_HILOGI("GetDeviceStatusData(type:%{public}d)", type);
int32_t ret = tunnel.GetParam(Intention::STATIONARY, StationaryRequestID::GET_STATIONARY_DATA, param, reply);
if (ret != RET_OK) {
FI_HILOGE("GetStationaryData fail, error:%{public}d", ret);
}
return reply.data_;
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -0,0 +1,50 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../../device_status.gni")
config("intention_stationary_data_public_config") {
include_dirs = [
"include",
"${device_status_root_path}/interfaces/innerkits/include",
]
}
ohos_source_set("intention_stationary_data") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
include_dirs = [
"include",
"${device_status_root_path}/intention/data/include",
"${device_status_root_path}/interfaces/innerkits/include",
]
sources = [ "src/stationary_params.cpp" ]
public_configs = [ ":intention_stationary_data_public_config" ]
deps =
[ "${device_status_root_path}/intention/prototype:intention_prototype" ]
subsystem_name = "${device_status_subsystem_name}"
part_name = "${device_status_part_name}"
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef STATIONARY_PARAMS_H
#define STATIONARY_PARAMS_H
#include "intention_identity.h"
#include "stationary_callback.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
enum StationaryRequestID : uint32_t {
UNKNOWN_STATIONARY_REQUEST,
SUBSCRIBE_STATIONARY,
UNSUBSCRIBE_STATIONARY,
GET_STATIONARY_DATA,
};
struct SubscribeStationaryParam final : public ParamBase {
SubscribeStationaryParam() = default;
SubscribeStationaryParam(Type type, ActivityEvent event,
ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback);
bool Marshalling(MessageParcel &parcel) const override;
bool Unmarshalling(MessageParcel &parcel) override;
Type type_;
ActivityEvent event_;
ReportLatencyNs latency_;
sptr<IRemoteDevStaCallback> callback_;
};
using UnsubscribeStationaryParam = SubscribeStationaryParam;
struct GetStaionaryDataParam final : public ParamBase {
GetStaionaryDataParam() = default;
explicit GetStaionaryDataParam(Type type);
bool Marshalling(MessageParcel &parcel) const override;
bool Unmarshalling(MessageParcel &parcel) override;
Type type_ { Type::TYPE_INVALID };
};
struct GetStaionaryDataReply final : public ParamBase {
GetStaionaryDataReply() = default;
explicit GetStaionaryDataReply(Data data);
bool Marshalling(MessageParcel &parcel) const override;
bool Unmarshalling(MessageParcel &parcel) override;
Data data_ {};
};
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS
#endif // STATIONARY_PARAMS_H

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stationary_params.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
SubscribeStationaryParam::SubscribeStationaryParam(Type type, ActivityEvent event,
ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback)
: type_(type), event_(event), latency_(latency), callback_(callback)
{}
bool SubscribeStationaryParam::Marshalling(MessageParcel &parcel) const
{
return (
parcel.WriteInt32(type_) &&
parcel.WriteInt32(event_) &&
parcel.WriteInt32(latency_) &&
(callback_ != nullptr) &&
parcel.WriteRemoteObject(callback_->AsObject())
);
}
bool SubscribeStationaryParam::Unmarshalling(MessageParcel &parcel)
{
int32_t type {};
int32_t event {};
int32_t latency {};
bool result = parcel.ReadInt32(type) &&
parcel.ReadInt32(event) &&
parcel.ReadInt32(latency);
if (!result) {
return false;
}
type_ = static_cast<Type>(type);
event_ = static_cast<ActivityEvent>(event);
latency_ = static_cast<ReportLatencyNs>(latency);
sptr<IRemoteObject> obj = parcel.ReadRemoteObject();
if (obj == nullptr) {
return false;
}
callback_ = iface_cast<IRemoteDevStaCallback>(obj);
return (callback_ != nullptr);
}
GetStaionaryDataParam::GetStaionaryDataParam(Type type)
: type_(type) {}
bool GetStaionaryDataParam::Marshalling(MessageParcel &parcel) const
{
return parcel.WriteInt32(type_);
}
bool GetStaionaryDataParam::Unmarshalling(MessageParcel &parcel)
{
int32_t type {};
if (!parcel.ReadInt32(type)) {
return false;
}
type_ = static_cast<Type>(type);
return true;
}
GetStaionaryDataReply::GetStaionaryDataReply(Data data)
: data_(data) {}
bool GetStaionaryDataReply::Marshalling(MessageParcel &parcel) const
{
return (
parcel.WriteInt32(data_.type) &&
parcel.WriteInt32(data_.value) &&
parcel.WriteInt32(data_.status) &&
parcel.WriteInt32(data_.action) &&
parcel.WriteDouble(data_.movement)
);
}
bool GetStaionaryDataReply::Unmarshalling(MessageParcel &parcel)
{
int32_t type {};
int32_t value {};
int32_t status {};
int32_t action {};
bool result = parcel.ReadInt32(type) &&
parcel.ReadInt32(value) &&
parcel.ReadInt32(status) &&
parcel.ReadInt32(action) &&
parcel.ReadDouble(data_.movement);
if (!result) {
return false;
}
data_.type = static_cast<Type>(type);
data_.value = static_cast<OnChangedValue>(value);
data_.status = static_cast<Status>(status);
data_.action = static_cast<Action>(action);
return true;
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -0,0 +1,75 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../../device_status.gni")
config("intention_stationary_server_public_config") {
include_dirs = [
"include",
"${device_status_root_path}/interfaces/innerkits/include",
"${device_status_root_path}/libs/interface",
"${device_status_root_path}/services/native/include",
]
}
ohos_source_set("intention_stationary_server") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
include_dirs = [
"include",
"${device_status_root_path}/interfaces/innerkits/include",
"${device_status_root_path}/libs/interface",
"${device_status_root_path}/services/native/include",
]
sources = [
"${device_status_root_path}/services/native/src/devicestatus_dumper.cpp",
"${device_status_root_path}/services/native/src/devicestatus_hisysevent.cpp",
"${device_status_root_path}/services/native/src/devicestatus_manager.cpp",
"${device_status_root_path}/services/native/src/devicestatus_msdp_client_impl.cpp",
"src/stationary_server.cpp",
]
public_configs = [ ":intention_stationary_server_public_config" ]
defines = device_status_default_defines
deps = [
"${device_status_root_path}/intention/data:intention_data",
"${device_status_root_path}/intention/prototype:intention_prototype",
"${device_status_root_path}/intention/stationary/data:intention_stationary_data",
"${device_status_root_path}/utils/common:devicestatus_util",
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
]
external_deps = [
"access_token:libaccesstoken_sdk",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"input:libmmi-client",
"window_manager:libdm",
]
subsystem_name = "${device_status_subsystem_name}"
part_name = "${device_status_part_name}"
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef STATIONARY_SERVER_H
#define STATIONARY_SERVER_H
#include "nocopyable.h"
#include "devicestatus_manager.h"
#include "i_plugin.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class StationaryServer final : public IPlugin {
public:
StationaryServer();
~StationaryServer() = default;
DISALLOW_COPY_AND_MOVE(StationaryServer);
int32_t Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
int32_t Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
int32_t Start(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
int32_t Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
int32_t AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
int32_t RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
int32_t SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
int32_t GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
int32_t Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
private:
void Subscribe(CallingContext &context, Type type, ActivityEvent event,
ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback);
void Unsubscribe(CallingContext &context, Type type, ActivityEvent event,
sptr<IRemoteDevStaCallback> callback);
Data GetCache(CallingContext &context, const Type &type);
void ReportSensorSysEvent(CallingContext &context, int32_t type, bool enable);
DeviceStatusManager manager_;
};
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS
#endif // STATIONARY_SERVER_H

View File

@ -0,0 +1,187 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stationary_server.h"
#include "hisysevent.h"
#include "hitrace_meter.h"
#include "default_params.h"
#include "devicestatus_define.h"
#include "devicestatus_dumper.h"
#include "devicestatus_hisysevent.h"
#include "stationary_params.h"
#undef LOG_TAG
#define LOG_TAG "StationaryServer"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
StationaryServer::StationaryServer()
{
manager_.Init();
}
int32_t StationaryServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
}
int32_t StationaryServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
}
int32_t StationaryServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
}
int32_t StationaryServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
}
int32_t StationaryServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
{
if (id != StationaryRequestID::SUBSCRIBE_STATIONARY) {
FI_HILOGE("Unexpected request ID (%{public}u)", id);
return RET_ERR;
}
SubscribeStationaryParam param {};
if (!param.Unmarshalling(data)) {
FI_HILOGE("SubscribeStationaryParam::Unmarshalling fail");
return RET_ERR;
}
Subscribe(context, param.type_, param.event_, param.latency_, param.callback_);
return RET_OK;
}
int32_t StationaryServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
{
if (id != StationaryRequestID::UNSUBSCRIBE_STATIONARY) {
FI_HILOGE("Unexpected request ID (%{public}u)", id);
return RET_ERR;
}
UnsubscribeStationaryParam param {};
if (!param.Unmarshalling(data)) {
FI_HILOGE("UnsubscribeStationaryParam::Unmarshalling fail");
return RET_ERR;
}
Unsubscribe(context, param.type_, param.event_, param.callback_);
return RET_OK;
}
int32_t StationaryServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
}
int32_t StationaryServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
{
if (id != StationaryRequestID::GET_STATIONARY_DATA) {
FI_HILOGE("Unexpected request ID (%{public}u)", id);
return RET_ERR;
}
GetStaionaryDataParam param {};
if (!param.Unmarshalling(data)) {
FI_HILOGE("GetStaionaryDataParam::Unmarshalling fail");
return RET_ERR;
}
GetStaionaryDataReply dataReply { GetCache(context, param.type_) };
if (!dataReply.Marshalling(reply)) {
FI_HILOGE("GetStaionaryDataReply::Marshalling fail");
return RET_ERR;
}
return RET_OK;
}
int32_t StationaryServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
}
void StationaryServer::Subscribe(CallingContext &context, Type type, ActivityEvent event,
ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback)
{
FI_HILOGI("SubscribeStationary(type:%{public}d,event:%{public}d,latency:%{public}d)", type, event, latency);
auto appInfo = std::make_shared<AppInfo>();
appInfo->uid = context.uid;
appInfo->pid = context.pid;
appInfo->tokenId = context.tokenId;
manager_.GetPackageName(appInfo->tokenId, appInfo->packageName);
appInfo->type = type;
appInfo->callback = callback;
DS_DUMPER->SaveAppInfo(appInfo);
StartTrace(HITRACE_TAG_MSDP, "serviceSubscribeStart");
manager_.Subscribe(type, event, latency, callback);
FinishTrace(HITRACE_TAG_MSDP);
ReportSensorSysEvent(context, type, true);
WriteSubscribeHiSysEvent(appInfo->uid, appInfo->packageName, type);
}
void StationaryServer::Unsubscribe(CallingContext &context, Type type,
ActivityEvent event, sptr<IRemoteDevStaCallback> callback)
{
FI_HILOGI("UnsubscribeStationary(type:%{public}d,event:%{public}d)", type, event);
auto appInfo = std::make_shared<AppInfo>();
appInfo->uid = context.uid;
appInfo->pid = context.pid;
appInfo->tokenId = context.tokenId;
appInfo->packageName = DS_DUMPER->GetPackageName(appInfo->tokenId);
appInfo->type = type;
appInfo->callback = callback;
DS_DUMPER->RemoveAppInfo(appInfo);
StartTrace(HITRACE_TAG_MSDP, "serviceUnSubscribeStart");
manager_.Unsubscribe(type, event, callback);
FinishTrace(HITRACE_TAG_MSDP);
ReportSensorSysEvent(context, type, false);
WriteUnSubscribeHiSysEvent(appInfo->uid, appInfo->packageName, type);
}
Data StationaryServer::GetCache(CallingContext &context, const Type &type)
{
return manager_.GetLatestDeviceStatusData(type);
}
void StationaryServer::ReportSensorSysEvent(CallingContext &context, int32_t type, bool enable)
{
std::string packageName;
manager_.GetPackageName(context.tokenId, packageName);
int32_t ret = HiSysEventWrite(
OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
std::string(enable ? "Subscribe" : "Unsubscribe"),
OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
"UID", context.uid,
"PKGNAME", packageName,
"TYPE", type);
if (ret != 0) {
FI_HILOGE("HiviewDFX write failed, error:%{public}d", ret);
}
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -89,6 +89,7 @@ ohos_shared_library("devicestatus_client") {
"${device_status_root_path}/intention/ipc/socket:intention_socket_connection",
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_client",
"${device_status_root_path}/intention/prototype:intention_prototype",
"${device_status_root_path}/intention/stationary/client:intention_stationary_client",
]
}

View File

@ -31,7 +31,7 @@ using namespace Security::AccessToken;
class DeviceStatusService;
class DeviceStatusManager {
public:
explicit DeviceStatusManager(const wptr<DeviceStatusService> &ms) : ms_(ms) {}
DeviceStatusManager() = default;
~DeviceStatusManager() = default;
class DeviceStatusCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
@ -64,7 +64,6 @@ private:
};
static constexpr int32_t argSize_ { TYPE_MAX };
const wptr<DeviceStatusService> ms_;
std::mutex mutex_;
sptr<IRemoteObject::DeathRecipient> devicestatusCBDeathRecipient_ { nullptr };
std::shared_ptr<DeviceStatusMsdpClientImpl> msdpImpl_ { nullptr };

View File

@ -74,7 +74,6 @@ public:
void Unsubscribe(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback) override;
Data GetCache(const Type &type) override;
bool IsServiceReady() const;
std::shared_ptr<DeviceStatusManager> GetDeviceStatusManager() const;
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
void ReportSensorSysEvent(int32_t type, bool enable);
int32_t RegisterCoordinationListener(bool isCompatible = false) override;

View File

@ -27,12 +27,11 @@
#include "string_ex.h"
#include "unique_fd.h"
#ifdef OHOS_BUILD_ENABLE_COORDINATION
#if defined(OHOS_BUILD_ENABLE_COORDINATION) && !defined(OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK)
#include "coordination_sm.h"
#endif // OHOS_BUILD_ENABLE_COORDINATION
#endif // defined(OHOS_BUILD_ENABLE_COORDINATION) && !defined(OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK)
#include "devicestatus_common.h"
#include "devicestatus_define.h"
#include "drag_manager.h"
#include "include/util.h"
#undef LOG_TAG
@ -124,7 +123,9 @@ void DeviceStatusDumper::ExecutDump(int32_t fd, const std::vector<Data> &datas,
}
case 'o': {
#ifdef OHOS_BUILD_ENABLE_COORDINATION
#ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
COOR_SM->Dump(fd);
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
#else
dprintf(fd, "device coordination is not supported\n");
#endif // OHOS_BUILD_ENABLE_COORDINATION

View File

@ -235,7 +235,7 @@ bool DeviceStatusService::Init()
CALL_DEBUG_ENTER;
if (devicestatusManager_ == nullptr) {
FI_HILOGW("devicestatusManager_ is nullptr");
devicestatusManager_ = std::make_shared<DeviceStatusManager>(this);
devicestatusManager_ = std::make_shared<DeviceStatusManager>();
}
if (!devicestatusManager_->Init()) {
FI_HILOGE("OnStart init failed");
@ -290,11 +290,6 @@ bool DeviceStatusService::IsServiceReady() const
return ready_;
}
std::shared_ptr<DeviceStatusManager> DeviceStatusService::GetDeviceStatusManager() const
{
return devicestatusManager_;
}
void DeviceStatusService::Subscribe(Type type, ActivityEvent event, ReportLatencyNs latency,
sptr<IRemoteDevStaCallback> callback)
{