!248 distributedsche进程内存优化

Merge pull request !248 from majiajun/6-23
This commit is contained in:
openharmony_ci
2022-06-25 13:08:12 +00:00
committed by Gitee
25 changed files with 873 additions and 456 deletions
+18
View File
@@ -42,8 +42,26 @@
"//foundation/distributedschedule/dmsfwk/etc/init:etc",
"//foundation/distributedschedule/dmsfwk/etc/profile:distributedsched_trust",
"//foundation/distributedschedule/dmsfwk/sa_profile:dms_sa_profile",
"//foundation/distributedschedule/dmsfwk/services/dtbabilitymgr:distributed_ability_manager_svr",
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr"
],
"inner_kits": [
{
"header": {
"header_base": "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/dmsbase/include",
"header_files": [
"adapter/dnetwork_adapter.h",
"deviceManager/dms_device_info.h",
"deviceManager/dms_device_listener.h",
"distributed_device_node_listener.h",
"dtbschedmgr_device_info_storage.h",
"dtbschedmgr_log.h",
"parcel_helper.h"
]
},
"name": "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/dmsbase:dmsbaseinner"
}
],
"test": [
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:unittest"
]
+46
View File
@@ -0,0 +1,46 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//build/ohos_var.gni")
config("distributed_sched_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
ohos_shared_library("dmsbaseinner") {
install_enable = true
sources = [
"../../../services/base/src/adapter/dnetwork_adapter.cpp",
"../../../services/base/src/deviceManager/dms_device_info.cpp",
"../../../services/base/src/distributed_device_node_listener.cpp",
"../../../services/base/src/dtbschedmgr_device_info_storage.cpp",
]
configs = [ ":distributed_sched_config" ]
public_configs = [ ":distributed_sched_config" ]
external_deps = [
"device_auth:deviceauth_sdk",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"utils_base:utils",
]
part_name = "dmsfwk_standard"
subsystem_name = "distributedschedule"
}
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_DMS_DEVICE_LISTENER_H
#define OHOS_DISTRIBUTED_DMS_DEVICE_LISTENER_H
#include <string>
namespace OHOS {
namespace DistributedSchedule {
class DmsDeviceListener : public virtual RefBase {
public:
DmsDeviceListener() = default;
virtual ~DmsDeviceListener() = default;
virtual void DeviceOnlineNotify(const std::string& deviceId) = 0;
virtual void DeviceOfflineNotify(const std::string& deviceId) = 0;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif /* OHOS_DISTRIBUTED_DMS_DEVICE_LISTENER_H */
@@ -1,96 +1,99 @@
/*
* Copyright (c) 2021 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 OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
#define OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
#include <set>
#include "adapter/dnetwork_adapter.h"
#include "deviceManager/dms_device_info.h"
#include "distributed_device_node_listener.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "single_instance.h"
namespace OHOS {
namespace DistributedSchedule {
class DnetServiceDeathRecipient : public IRemoteObject::DeathRecipient {
public:
DnetServiceDeathRecipient() = default;
~DnetServiceDeathRecipient() override = default;
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
};
class DtbschedmgrDeviceInfoStorage {
DECLARE_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
public:
bool Init();
void Stop();
bool GetLocalDeviceId(std::string& deviceId);
void DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo);
void DeviceOfflineNotify(const std::string& deviceId);
void OnDeviceInfoChanged(const std::string& deviceId, DeviceInfoType type);
/**
* get device info by device id
*
* @param deviceId, string
* @return shared_ptr<DmsDeviceInfo>
*/
std::shared_ptr<DmsDeviceInfo> GetDeviceInfoById(const std::string& deviceId);
/**
* get uuid by networkId
*
* @param networkId
*/
std::string GetUuidByNetworkId(const std::string& networkId);
/**
* get networkId by uuid
*
* @param uuid
*/
std::string GetNetworkIdByUuid(const std::string& uuid);
/**
* GetDeviceIdSet get all of the device Id in same network
*
* @param deviceIdSet Returns the device set.
*/
void GetDeviceIdSet(std::set<std::string>& deviceIdSet);
private:
bool InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter);
bool ConnectSoftbus();
void ClearAllDevices();
bool WaitForDnetworkReady();
bool GetLocalDeviceFromDnet(std::string& deviceId);
void RegisterUuidNetworkIdMap(const std::string& networkId);
void UnregisterUuidNetworkIdMap(const std::string& networkId);
std::mutex deviceLock_;
std::shared_ptr<DistributedDeviceNodeListener> deviceNodeListener_;
std::map<std::string, std::shared_ptr<DmsDeviceInfo>> remoteDevices_;
std::string deviceId_;
std::map<std::string, std::string> uuidNetworkIdMap_;
std::mutex uuidNetworkIdLock_;
std::shared_ptr<AppExecFwk::EventHandler> initHandler_;
std::shared_ptr<AppExecFwk::EventHandler> networkIdMgrHandler_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
#define OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
#include <set>
#include "adapter/dnetwork_adapter.h"
#include "deviceManager/dms_device_info.h"
#include "deviceManager/dms_device_listener.h"
#include "distributed_device_node_listener.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "single_instance.h"
namespace OHOS {
namespace DistributedSchedule {
class DnetServiceDeathRecipient : public IRemoteObject::DeathRecipient {
public:
DnetServiceDeathRecipient() = default;
~DnetServiceDeathRecipient() override = default;
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
};
class DtbschedmgrDeviceInfoStorage {
DECLARE_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
public:
bool Init();
bool Init(sptr<DmsDeviceListener> listener);
void Stop();
bool GetLocalDeviceId(std::string& deviceId);
void DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo);
void DeviceOfflineNotify(const std::string& deviceId);
void OnDeviceInfoChanged(const std::string& deviceId, DeviceInfoType type);
/**
* get device info by device id
*
* @param deviceId, string
* @return shared_ptr<DmsDeviceInfo>
*/
std::shared_ptr<DmsDeviceInfo> GetDeviceInfoById(const std::string& deviceId);
/**
* get uuid by networkId
*
* @param networkId
*/
std::string GetUuidByNetworkId(const std::string& networkId);
/**
* get networkId by uuid
*
* @param uuid
*/
std::string GetNetworkIdByUuid(const std::string& uuid);
/**
* GetDeviceIdSet get all of the device Id in same network
*
* @param deviceIdSet Returns the device set.
*/
void GetDeviceIdSet(std::set<std::string>& deviceIdSet);
private:
bool InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter);
bool ConnectSoftbus();
void ClearAllDevices();
bool WaitForDnetworkReady();
bool GetLocalDeviceFromDnet(std::string& deviceId);
void RegisterUuidNetworkIdMap(const std::string& networkId);
void UnregisterUuidNetworkIdMap(const std::string& networkId);
sptr<DmsDeviceListener> listener_;
std::mutex deviceLock_;
std::shared_ptr<DistributedDeviceNodeListener> deviceNodeListener_;
std::map<std::string, std::shared_ptr<DmsDeviceInfo>> remoteDevices_;
std::string deviceId_;
std::map<std::string, std::string> uuidNetworkIdMap_;
std::mutex uuidNetworkIdLock_;
std::shared_ptr<AppExecFwk::EventHandler> initHandler_;
std::shared_ptr<AppExecFwk::EventHandler> networkIdMgrHandler_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_DTBSCHEDMGR_DEVICE_INFO_INTERFACE_H
+2 -2
View File
@@ -16,11 +16,11 @@
<process>distributedsched</process>
<systemability> <!--Declare a system ability and its profile-->
<name>1401</name> <!--Declare the name of system ability-->
<libpath>libdistributedschedsvr.z.so</libpath> <!--Declare the path of .so file which includes the system ability; Note: 1 .so file have 1 to N sysytem abilities. -->
<libpath>libdistributed_ability_manager_svr.z.so</libpath> <!--Declare the path of .so file which includes the system ability; Note: 1 .so file have 1 to N sysytem abilities. -->
<!--<depend></depend>--> <!--Declare the name of system abilities which the system ability depends on,using the system ability would start on demand. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are available before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not.-->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
</info>
</info>
@@ -1,325 +1,321 @@
/*
* Copyright (c) 2021 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 "dtbschedmgr_device_info_storage.h"
#include <chrono>
#include <thread>
#include "distributed_device_node_listener.h"
#include "distributed_sched_adapter.h"
#include "dtbschedmgr_log.h"
#include "ipc_object_proxy.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
#include "mission/distributed_sched_mission_manager.h"
#endif
#include "system_ability_definition.h"
using namespace std;
namespace OHOS {
namespace DistributedSchedule {
using namespace std::chrono_literals;
namespace {
constexpr int32_t RETRY_TIMES = 30;
constexpr int32_t CONNECT_SOFTBUS_RETRY_TIMES = 60;
const std::string TAG = "DtbschedmgrDeviceInfoStorage";
}
IMPLEMENT_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
bool DtbschedmgrDeviceInfoStorage::Init()
{
if (initHandler_ == nullptr) {
auto deviceInfoStorageRunner = AppExecFwk::EventRunner::Create("DmsDeviceInfoStorageManager");
initHandler_ = std::make_shared<AppExecFwk::EventHandler>(deviceInfoStorageRunner);
}
auto func = [this]() {
HILOGI("begin connect softbus");
for (int32_t retryTimes = 0; retryTimes <= CONNECT_SOFTBUS_RETRY_TIMES; retryTimes++) {
if (ConnectSoftbus()) {
return;
}
HILOGE("retry connect softbus %{public}d times", retryTimes);
std::this_thread::sleep_for(1s);
}
HILOGE("connect softbus 60times * 30s, error!!");
};
if (!initHandler_->PostTask(func)) {
HILOGE("Init handler postTask failed");
return false;
}
return true;
}
bool DtbschedmgrDeviceInfoStorage::ConnectSoftbus()
{
ClearAllDevices();
bool isReady = WaitForDnetworkReady();
if (!isReady) {
HILOGE("ConnectSoftbus wait Dnetwork failed!");
return false;
}
std::shared_ptr<DnetworkAdapter> dnetworkAdapter = DnetworkAdapter::GetInstance();
if (dnetworkAdapter == nullptr) {
HILOGE("DnetworkAdapter::GetInstance() null");
return false;
}
if (!InitNetworkIdManager(dnetworkAdapter)) {
HILOGE("InitNetworkIdManager failed");
return false;
}
HILOGI("ConnectSoftbus success");
return true;
}
bool DtbschedmgrDeviceInfoStorage::InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter)
{
if (networkIdMgrHandler_ == nullptr) {
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
networkIdMgrHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
deviceNodeListener_ = std::make_shared<DistributedDeviceNodeListener>();
if (!dnetworkAdapter->AddDeviceChangeListener(deviceNodeListener_)) {
deviceNodeListener_ = nullptr;
HILOGE("AddDeviceChangeListener failed!");
return false;
}
return true;
}
void DtbschedmgrDeviceInfoStorage::Stop()
{
ClearAllDevices();
if (deviceNodeListener_ != nullptr) {
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener_);
deviceNodeListener_ = nullptr;
}
}
bool DtbschedmgrDeviceInfoStorage::WaitForDnetworkReady()
{
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
HILOGE("WaitForDnetworkReady failed to get samgr!");
return false;
}
int32_t retryTimeout = RETRY_TIMES;
do {
auto dnetwork = samgr->CheckSystemAbility(SOFTBUS_SERVER_SA_ID);
if (dnetwork != nullptr) {
IPCObjectProxy* proxy = reinterpret_cast<IPCObjectProxy*>(dnetwork.GetRefPtr());
// make sure the proxy is not dead
if (proxy != nullptr && !proxy->IsObjectDead()) {
return true;
}
}
HILOGI("Waiting for dnentwork service...");
std::this_thread::sleep_for(1s);
if (--retryTimeout <= 0) {
HILOGI("Waiting for dnentwork service timeout(30)s");
return false;
}
} while (true);
return false;
}
void DtbschedmgrDeviceInfoStorage::RegisterUuidNetworkIdMap(const std::string& networkId)
{
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
uuidNetworkIdMap_[uuid] = networkId;
}
}
void DtbschedmgrDeviceInfoStorage::UnregisterUuidNetworkIdMap(const std::string& networkId)
{
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
uuidNetworkIdMap_.erase(uuid);
}
}
void DtbschedmgrDeviceInfoStorage::GetDeviceIdSet(std::set<std::string>& deviceIdSet)
{
deviceIdSet.clear();
lock_guard<mutex> autoLock(deviceLock_);
for (const auto& device : remoteDevices_) {
deviceIdSet.emplace(device.first);
}
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& deviceId)
{
return GetLocalDeviceFromDnet(deviceId);
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceFromDnet(std::string& deviceId)
{
auto dnetworkAdapter = DnetworkAdapter::GetInstance();
if (dnetworkAdapter == nullptr) {
HILOGE("GetLocalDeviceFromDnet dnetworkAdapter null");
return false;
}
std::shared_ptr<NodeBasicInfo> localNode = dnetworkAdapter->GetLocalBasicInfo();
if (localNode != nullptr) {
deviceId = localNode->networkId;
HILOGI("get local deviceId from DnetworkAdapter, deviceId = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str());
return true;
}
HILOGE("GetLocalDeviceFromDnet localNode null");
return false;
}
void DtbschedmgrDeviceInfoStorage::ClearAllDevices()
{
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_.clear();
}
std::shared_ptr<DmsDeviceInfo> DtbschedmgrDeviceInfoStorage::GetDeviceInfoById(const string& deviceId)
{
lock_guard<mutex> autoLock(deviceLock_);
auto iter = remoteDevices_.find(deviceId);
if (iter == remoteDevices_.end()) {
return nullptr;
}
return iter->second;
}
std::string DtbschedmgrDeviceInfoStorage::GetUuidByNetworkId(const std::string& networkId)
{
if (networkId.empty()) {
HILOGW("GetUuidByNetworkId networkId empty!");
return "";
}
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
auto iter = uuidNetworkIdMap_.begin();
while (iter != uuidNetworkIdMap_.end()) {
if (iter->second == networkId) {
return iter->first;
} else {
++iter;
}
}
}
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
return uuid;
}
std::string DtbschedmgrDeviceInfoStorage::GetNetworkIdByUuid(const std::string& uuid)
{
if (uuid.empty()) {
HILOGW("GetNetworkIdByUuid uuid empty!");
return "";
}
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
auto iter = uuidNetworkIdMap_.find(uuid);
if (iter != uuidNetworkIdMap_.end()) {
return iter->second;
}
return "";
}
}
void DtbschedmgrDeviceInfoStorage::DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo)
{
if (devInfo == nullptr) {
HILOGE("DeviceOnlineNotify devInfo null");
return;
}
std::string devId = devInfo->GetDeviceId();
HILOGI("DeviceOnlineNotify deviceId = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(devId).c_str());
if (networkIdMgrHandler_ == nullptr) {
HILOGE("DeviceOnlineNotify networkIdMgrHandler null");
return;
}
auto nodeOnline = [this, devInfo]() {
std::string deviceId = devInfo->GetDeviceId();
RegisterUuidNetworkIdMap(deviceId);
std::string uuid = GetUuidByNetworkId(deviceId);
HILOGI("DeviceOnlineNotify process deviceId = %{public}s, uuid = %{public}s, deviceName = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str(),
DnetworkAdapter::AnonymizeDeviceId(uuid).c_str(), devInfo->GetDeviceName().c_str());
DistributedSchedAdapter::GetInstance().DeviceOnline(deviceId);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().UpdateConnCapSupportOsd(deviceId);
DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(deviceId);
#endif
{
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_[deviceId] = devInfo;
}
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().UpdateSwitchValueToRemote();
#endif
};
if (!networkIdMgrHandler_->PostTask(nodeOnline)) {
HILOGE("DeviceOnlineNotify handler postTask failed");
}
}
void DtbschedmgrDeviceInfoStorage::DeviceOfflineNotify(const std::string& deviceId)
{
if (deviceId.empty()) {
HILOGE("DeviceOfflineNotify deviceId empty");
return;
}
HILOGI("DeviceOfflineNotify deviceId = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str());
if (networkIdMgrHandler_ == nullptr) {
HILOGE("DeviceOfflineNotify networkIdMgrHandler null");
return;
}
auto nodeOffline = [this, deviceId]() {
std::string uuid = GetUuidByNetworkId(deviceId);
HILOGI("DeviceOfflineNotify process deviceId = %{public}s, uuid = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str(), DnetworkAdapter::AnonymizeDeviceId(uuid).c_str());
DistributedSchedAdapter::GetInstance().DeviceOffline(deviceId);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(deviceId);
#endif
UnregisterUuidNetworkIdMap(deviceId);
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_.erase(deviceId);
};
if (!networkIdMgrHandler_->PostTask(nodeOffline)) {
HILOGE("DeviceOfflineNotify handler postTask failed");
}
}
void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& deviceId, DeviceInfoType type)
{
HILOGI("OnDeviceInfoChanged called");
}
void DnetServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGI("OnRemoteDied dnetwork service died");
DtbschedmgrDeviceInfoStorage::GetInstance().Init();
}
}
}
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dtbschedmgr_device_info_storage.h"
#include <chrono>
#include <thread>
#include "distributed_device_node_listener.h"
#include "dtbschedmgr_log.h"
#include "ipc_object_proxy.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
using namespace std;
namespace OHOS {
namespace DistributedSchedule {
using namespace std::chrono_literals;
namespace {
constexpr int32_t RETRY_TIMES = 30;
constexpr int32_t CONNECT_SOFTBUS_RETRY_TIMES = 60;
const std::string TAG = "DtbschedmgrDeviceInfoStorage";
}
IMPLEMENT_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage);
bool DtbschedmgrDeviceInfoStorage::Init()
{
if (initHandler_ == nullptr) {
auto deviceInfoStorageRunner = AppExecFwk::EventRunner::Create("DmsDeviceInfoStorageManager");
initHandler_ = std::make_shared<AppExecFwk::EventHandler>(deviceInfoStorageRunner);
}
auto func = [this]() {
HILOGI("begin connect softbus");
for (int32_t retryTimes = 0; retryTimes <= CONNECT_SOFTBUS_RETRY_TIMES; retryTimes++) {
if (ConnectSoftbus()) {
return;
}
HILOGE("retry connect softbus %{public}d times", retryTimes);
std::this_thread::sleep_for(1s);
}
HILOGE("connect softbus 60times * 30s, error!!");
};
if (!initHandler_->PostTask(func)) {
HILOGE("Init handler postTask failed");
return false;
}
return true;
}
bool DtbschedmgrDeviceInfoStorage::Init(sptr<DmsDeviceListener> listener)
{
listener_ = listener;
return Init();
}
bool DtbschedmgrDeviceInfoStorage::ConnectSoftbus()
{
ClearAllDevices();
bool isReady = WaitForDnetworkReady();
if (!isReady) {
HILOGE("ConnectSoftbus wait Dnetwork failed!");
return false;
}
std::shared_ptr<DnetworkAdapter> dnetworkAdapter = DnetworkAdapter::GetInstance();
if (dnetworkAdapter == nullptr) {
HILOGE("DnetworkAdapter::GetInstance() null");
return false;
}
if (!InitNetworkIdManager(dnetworkAdapter)) {
HILOGE("InitNetworkIdManager failed");
return false;
}
HILOGI("ConnectSoftbus success");
return true;
}
bool DtbschedmgrDeviceInfoStorage::InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter)
{
if (networkIdMgrHandler_ == nullptr) {
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
networkIdMgrHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
deviceNodeListener_ = std::make_shared<DistributedDeviceNodeListener>();
if (!dnetworkAdapter->AddDeviceChangeListener(deviceNodeListener_)) {
deviceNodeListener_ = nullptr;
HILOGE("AddDeviceChangeListener failed!");
return false;
}
return true;
}
void DtbschedmgrDeviceInfoStorage::Stop()
{
ClearAllDevices();
if (deviceNodeListener_ != nullptr) {
DnetworkAdapter::GetInstance()->RemoveDeviceChangeListener(deviceNodeListener_);
deviceNodeListener_ = nullptr;
}
}
bool DtbschedmgrDeviceInfoStorage::WaitForDnetworkReady()
{
auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
HILOGE("WaitForDnetworkReady failed to get samgr!");
return false;
}
int32_t retryTimeout = RETRY_TIMES;
do {
auto dnetwork = samgr->CheckSystemAbility(SOFTBUS_SERVER_SA_ID);
if (dnetwork != nullptr) {
IPCObjectProxy* proxy = reinterpret_cast<IPCObjectProxy*>(dnetwork.GetRefPtr());
// make sure the proxy is not dead
if (proxy != nullptr && !proxy->IsObjectDead()) {
return true;
}
}
HILOGI("Waiting for dnentwork service...");
std::this_thread::sleep_for(1s);
if (--retryTimeout <= 0) {
HILOGI("Waiting for dnentwork service timeout(30)s");
return false;
}
} while (true);
return false;
}
void DtbschedmgrDeviceInfoStorage::RegisterUuidNetworkIdMap(const std::string& networkId)
{
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
uuidNetworkIdMap_[uuid] = networkId;
}
}
void DtbschedmgrDeviceInfoStorage::UnregisterUuidNetworkIdMap(const std::string& networkId)
{
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
uuidNetworkIdMap_.erase(uuid);
}
}
void DtbschedmgrDeviceInfoStorage::GetDeviceIdSet(std::set<std::string>& deviceIdSet)
{
deviceIdSet.clear();
lock_guard<mutex> autoLock(deviceLock_);
for (const auto& device : remoteDevices_) {
deviceIdSet.emplace(device.first);
}
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& deviceId)
{
return GetLocalDeviceFromDnet(deviceId);
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceFromDnet(std::string& deviceId)
{
auto dnetworkAdapter = DnetworkAdapter::GetInstance();
if (dnetworkAdapter == nullptr) {
HILOGE("GetLocalDeviceFromDnet dnetworkAdapter null");
return false;
}
std::shared_ptr<NodeBasicInfo> localNode = dnetworkAdapter->GetLocalBasicInfo();
if (localNode != nullptr) {
deviceId = localNode->networkId;
HILOGI("get local deviceId from DnetworkAdapter, deviceId = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str());
return true;
}
HILOGE("GetLocalDeviceFromDnet localNode null");
return false;
}
void DtbschedmgrDeviceInfoStorage::ClearAllDevices()
{
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_.clear();
}
std::shared_ptr<DmsDeviceInfo> DtbschedmgrDeviceInfoStorage::GetDeviceInfoById(const string& deviceId)
{
lock_guard<mutex> autoLock(deviceLock_);
auto iter = remoteDevices_.find(deviceId);
if (iter == remoteDevices_.end()) {
return nullptr;
}
return iter->second;
}
std::string DtbschedmgrDeviceInfoStorage::GetUuidByNetworkId(const std::string& networkId)
{
if (networkId.empty()) {
HILOGW("GetUuidByNetworkId networkId empty!");
return "";
}
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
auto iter = uuidNetworkIdMap_.begin();
while (iter != uuidNetworkIdMap_.end()) {
if (iter->second == networkId) {
return iter->first;
} else {
++iter;
}
}
}
std::string uuid = DnetworkAdapter::GetInstance()->GetUuidByNetworkId(networkId);
return uuid;
}
std::string DtbschedmgrDeviceInfoStorage::GetNetworkIdByUuid(const std::string& uuid)
{
if (uuid.empty()) {
HILOGW("GetNetworkIdByUuid uuid empty!");
return "";
}
{
std::lock_guard<std::mutex> autoLock(uuidNetworkIdLock_);
auto iter = uuidNetworkIdMap_.find(uuid);
if (iter != uuidNetworkIdMap_.end()) {
return iter->second;
}
return "";
}
}
void DtbschedmgrDeviceInfoStorage::DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo)
{
if (devInfo == nullptr) {
HILOGE("DeviceOnlineNotify devInfo null");
return;
}
std::string devId = devInfo->GetDeviceId();
HILOGI("deviceId = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(devId).c_str());
if (networkIdMgrHandler_ == nullptr) {
HILOGE("networkIdMgrHandler null");
return;
}
auto nodeOnline = [this, devInfo]() {
std::string deviceId = devInfo->GetDeviceId();
RegisterUuidNetworkIdMap(deviceId);
std::string uuid = GetUuidByNetworkId(deviceId);
HILOGI("deviceId = %{public}s, uuid = %{public}s, deviceName = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str(),
DnetworkAdapter::AnonymizeDeviceId(uuid).c_str(), devInfo->GetDeviceName().c_str());
{
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_[deviceId] = devInfo;
}
if (listener_!= nullptr) {
listener_->DeviceOnlineNotify(deviceId);
}
};
if (!networkIdMgrHandler_->PostTask(nodeOnline)) {
HILOGE("DeviceOnlineNotify handler postTask failed");
}
}
void DtbschedmgrDeviceInfoStorage::DeviceOfflineNotify(const std::string& deviceId)
{
if (deviceId.empty()) {
HILOGE("DeviceOfflineNotify deviceId empty");
return;
}
HILOGI("DeviceOfflineNotify deviceId = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str());
if (networkIdMgrHandler_ == nullptr) {
HILOGE("DeviceOfflineNotify networkIdMgrHandler null");
return;
}
auto nodeOffline = [this, deviceId]() {
std::string uuid = GetUuidByNetworkId(deviceId);
HILOGI("DeviceOfflineNotify process deviceId = %{public}s, uuid = %{public}s",
DnetworkAdapter::AnonymizeDeviceId(deviceId).c_str(), DnetworkAdapter::AnonymizeDeviceId(uuid).c_str());
if (listener_!= nullptr) {
listener_->DeviceOfflineNotify(deviceId);
}
UnregisterUuidNetworkIdMap(deviceId);
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_.erase(deviceId);
};
if (!networkIdMgrHandler_->PostTask(nodeOffline)) {
HILOGE("DeviceOfflineNotify handler postTask failed");
}
}
void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& deviceId, DeviceInfoType type)
{
HILOGI("OnDeviceInfoChanged called");
}
void DnetServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGI("OnRemoteDied dnetwork service died");
DtbschedmgrDeviceInfoStorage::GetInstance().Init();
}
}
}
+46
View File
@@ -0,0 +1,46 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//build/ohos_var.gni")
config("distributed_ability_manager_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
ohos_shared_library("distributed_ability_manager_svr") {
install_enable = true
sources = [
"src/distributed_ability_manager_service.cpp",
"src/distributed_ability_manager_stub.cpp",
]
configs = [ ":distributed_ability_manager_config" ]
ldflags = [ "-rdynamic" ]
external_deps = [
"dmsfwk_standard:dmsbaseinner",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
"utils_base:utils",
]
part_name = "dmsfwk_standard"
subsystem_name = "distributedschedule"
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_INTERFACE_H
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_INTERFACE_H
#include "iremote_broker.h"
namespace OHOS {
namespace DistributedSchedule {
class IDistributedAbilityManager : public OHOS::IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedSchedule.IDistributedAbilityManager");
virtual int32_t SendRequestToImpl(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option) = 0;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_INTERFACE_H
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H
#include "distributed_ability_manager_stub.h"
#include "deviceManager/dms_device_listener.h"
#include "single_instance.h"
#include "system_ability.h"
namespace OHOS {
namespace DistributedSchedule {
class DistributedAbilityManagerService : public SystemAbility, public DistributedAbilityManagerStub,
public DmsDeviceListener {
DECLARE_SYSTEM_ABILITY(DistributedAbilityManagerService);
public:
DistributedAbilityManagerService(int32_t systemAbilityId, bool runOnCreate);
~DistributedAbilityManagerService() = default;
void OnStart() override;
void OnStop() override;
int32_t SendRequestToImpl(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option) override;
void DeviceOnlineNotify(const std::string& deviceId) override;
void DeviceOfflineNotify(const std::string& deviceId) override;
private:
bool InitDmsImplFunc();
using LibHandle = void*;
LibHandle dmsImplHandle_ = nullptr;
using OnStartFunc = void(*)();
using OnRemoteRequestFunc = int32_t(*)(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option);
using DeviceOnlineNotifyFunc = void(*)(const std::string& deviceId);
using DeviceOfflineNotifyFunc = void(*)(const std::string& deviceId);
OnRemoteRequestFunc onRemoteRequestFunc_ = nullptr;
DeviceOnlineNotifyFunc deviceOnlineNotifyFunc_ = nullptr;
DeviceOfflineNotifyFunc deviceOfflineNotifyFunc_ = nullptr;
std::atomic_bool isLoaded_ = false;
std::mutex libLoadLock_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_STUB_H
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_STUB_H
#include "distributed_ability_manager_interface.h"
#include "ipc_skeleton.h"
#include "iremote_stub.h"
#include "message_parcel.h"
namespace OHOS {
namespace DistributedSchedule {
class DistributedAbilityManagerStub : public IRemoteStub<IDistributedAbilityManager> {
public:
DistributedAbilityManagerStub() = default;
~DistributedAbilityManagerStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option) override;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_STUB_H
@@ -0,0 +1,121 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "distributed_ability_manager_service.h"
#include <chrono>
#include <thread>
#include "adapter/dnetwork_adapter.h"
#include "dlfcn.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
namespace OHOS {
namespace DistributedSchedule {
const std::string TAG = "DistributedAbilityManagerService";
REGISTER_SYSTEM_ABILITY_BY_ID(DistributedAbilityManagerService, DISTRIBUTED_SCHED_SA_ID, true);
DistributedAbilityManagerService::DistributedAbilityManagerService(
int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate)
{
}
void DistributedAbilityManagerService::OnStart()
{
HILOGI("begin");
DnetworkAdapter::GetInstance()->Init();
if (!DtbschedmgrDeviceInfoStorage::GetInstance().Init(this)) {
HILOGW("Init DtbschedmgrDeviceInfoStorage init failed.");
}
Publish(this);
}
void DistributedAbilityManagerService::OnStop()
{
HILOGI("begin");
}
bool DistributedAbilityManagerService::InitDmsImplFunc()
{
std::lock_guard<std::mutex> lock(libLoadLock_);
if (isLoaded_) {
return true;
}
HILOGI("begin");
dmsImplHandle_ = dlopen("libdistributedschedsvr.z.so", RTLD_NOW);
if (dmsImplHandle_ == nullptr) {
HILOGE("dlopen libdistributedschedsvr failed with errno:%s!", dlerror());
return false;
}
onRemoteRequestFunc_ = reinterpret_cast<OnRemoteRequestFunc>(dlsym(dmsImplHandle_, "OnRemoteRequest"));
if (onRemoteRequestFunc_ == nullptr) {
dlclose(dmsImplHandle_);
HILOGE("get OnRemoteRequest function error");
return false;
}
deviceOnlineNotifyFunc_ = reinterpret_cast<DeviceOnlineNotifyFunc>(dlsym(dmsImplHandle_, "DeviceOnlineNotify"));
if (deviceOnlineNotifyFunc_ == nullptr) {
dlclose(dmsImplHandle_);
HILOGE("get DeviceOnlineNotify function error");
return false;
}
deviceOfflineNotifyFunc_ = reinterpret_cast<DeviceOfflineNotifyFunc>(dlsym(dmsImplHandle_, "DeviceOfflineNotify"));
if (deviceOfflineNotifyFunc_ == nullptr) {
dlclose(dmsImplHandle_);
HILOGE("get DeviceOfflineNotify function error");
return false;
}
OnStartFunc onStartFunc = reinterpret_cast<OnStartFunc>(dlsym(dmsImplHandle_, "OnStart"));
if (onStartFunc == nullptr) {
dlclose(dmsImplHandle_);
HILOGE("get OnStart function error");
return false;
}
onStartFunc();
isLoaded_ = true;
HILOGI("end");
return true;
}
int32_t DistributedAbilityManagerService::SendRequestToImpl(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option)
{
if (InitDmsImplFunc()) {
return onRemoteRequestFunc_(code, data, reply, option);
}
return INVALID_PARAMETERS_ERR;
}
void DistributedAbilityManagerService::DeviceOnlineNotify(const std::string& deviceId)
{
if (InitDmsImplFunc()) {
deviceOnlineNotifyFunc_(deviceId);
}
}
void DistributedAbilityManagerService::DeviceOfflineNotify(const std::string& deviceId)
{
if (InitDmsImplFunc()) {
deviceOfflineNotifyFunc_(deviceId);
}
}
} // namespace DistributedSchedule
} // namespace OHOS
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "distributed_ability_manager_stub.h"
namespace OHOS {
namespace DistributedSchedule {
int32_t DistributedAbilityManagerStub::OnRemoteRequest(uint32_t code,
MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
return SendRequestToImpl(code, data, reply, option);
}
} // namespace DistributedSchedule
} // namespace OHOS
+1 -4
View File
@@ -33,11 +33,8 @@ ohos_shared_library("distributedschedsvr") {
sources = [
"src/ability_connection_wrapper_proxy.cpp",
"src/ability_connection_wrapper_stub.cpp",
"src/adapter/dnetwork_adapter.cpp",
"src/bundle/bundle_manager_internal.cpp",
"src/connect_death_recipient.cpp",
"src/deviceManager/dms_device_info.cpp",
"src/distributed_device_node_listener.cpp",
"src/distributed_sched_adapter.cpp",
"src/distributed_sched_continuation.cpp",
"src/distributed_sched_dumper.cpp",
@@ -50,7 +47,6 @@ ohos_shared_library("distributedschedsvr") {
"src/dms_free_install_callback_proxy.cpp",
"src/dms_free_install_callback_stub.cpp",
"src/dms_token_callback.cpp",
"src/dtbschedmgr_device_info_storage.cpp",
]
configs = [ ":distributed_sched_config" ]
@@ -64,6 +60,7 @@ ohos_shared_library("distributedschedsvr") {
"bundle_framework:appexecfwk_core",
"device_auth:deviceauth_sdk",
"distributeddatamgr:distributeddata_inner",
"dmsfwk_standard:dmsbaseinner",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
@@ -31,7 +31,6 @@
#include "nocopyable.h"
#endif
#include "single_instance.h"
#include "system_ability.h"
namespace OHOS {
namespace DistributedSchedule {
@@ -58,15 +57,13 @@ struct ProcessDiedNotifyInfo {
TargetComponent targetComponent;
};
class DistributedSchedService : public SystemAbility, public DistributedSchedStub {
DECLARE_SYSTEM_ABILITY(DistributedSchedService);
class DistributedSchedService : public DistributedSchedStub {
DECLARE_SINGLE_INSTANCE_BASE(DistributedSchedService);
public:
~DistributedSchedService() = default;
void OnStart() override;
void OnStop() override;
void OnStart();
int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
uint32_t accessToken) override;
int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
@@ -30,6 +30,7 @@ public:
~DistributedSchedStub();
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option) override;
protected:
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
virtual std::unique_ptr<Snapshot> GetRemoteSnapshotInfo(const std::u16string& deviceId, int32_t missionId)
+32 -20
View File
@@ -77,11 +77,39 @@ constexpr int32_t DISTRIBUTED_COMPONENT_REMOVE = 2;
constexpr int32_t REPORT_DISTRIBUTED_COMPONENT_CHANGE_CODE = 1;
}
extern "C" {
void OnStart()
{
DistributedSchedService::GetInstance().OnStart();
}
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
return DistributedSchedService::GetInstance().OnRemoteRequest(code, data, reply, option);
}
void DeviceOnlineNotify(const std::string& deviceId)
{
DistributedSchedAdapter::GetInstance().DeviceOnline(deviceId);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(deviceId);
#endif
}
void DeviceOfflineNotify(const std::string& deviceId)
{
DistributedSchedAdapter::GetInstance().DeviceOffline(deviceId);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(deviceId);
#endif
}
}
IMPLEMENT_SINGLE_INSTANCE(DistributedSchedService);
static const sptr<DistributedSchedService> INSTANCE = &DistributedSchedService::GetInstance();
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&DistributedSchedService::GetInstance());
DistributedSchedService::DistributedSchedService() : SystemAbility(DISTRIBUTED_SCHED_SA_ID, true)
DistributedSchedService::DistributedSchedService()
{
}
@@ -114,18 +142,8 @@ bool DistributedSchedService::Init()
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().Init();
#endif
bool ret = Publish(this);
if (!ret) {
HILOGE("Init Publish failed!");
return false;
}
if (!DtbschedmgrDeviceInfoStorage::GetInstance().Init()) {
HILOGE("Init DtbschedmgrDeviceInfoStorage init failed.");
}
HILOGD("Init init success.");
DistributedSchedAdapter::GetInstance().Init();
DnetworkAdapter::GetInstance()->Init();
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().InitDataStorage();
#endif
@@ -140,11 +158,6 @@ bool DistributedSchedService::Init()
return true;
}
void DistributedSchedService::OnStop()
{
HILOGD("OnStop ready to stop service.");
}
int32_t DistributedSchedService::StartRemoteAbility(const OHOS::AAFwk::Want& want,
int32_t callerUid, int32_t requestCode, uint32_t accessToken)
{
@@ -758,8 +771,7 @@ int32_t DistributedSchedService::StartRemoteAbilityByCall(const OHOS::AAFwk::Wan
HILOGE("StartRemoteAbilityByCall check deviceId failed");
return INVALID_PARAMETERS_ERR;
}
CallerInfo callerInfo;
callerInfo = { callerUid, callerPid };
CallerInfo callerInfo = { callerUid, callerPid };
callerInfo.sourceDeviceId = localDeviceId;
callerInfo.accessToken = accessToken;
if (!BundleManagerInternal::GetCallerAppIdFromBms(callerInfo.uid, callerInfo.callerAppId)) {
+1 -4
View File
@@ -37,6 +37,7 @@ dsched_external_deps = [
"bundle_framework:appexecfwk_core",
"device_auth:deviceauth_sdk",
"distributeddatamgr:distributeddata_inner",
"dmsfwk_standard:dmsbaseinner",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
@@ -60,11 +61,8 @@ dsched_public_deps = [
dtbschedmgr_sources = [
"${distributed_service}/dtbschedmgr/src/ability_connection_wrapper_proxy.cpp",
"${distributed_service}/dtbschedmgr/src/ability_connection_wrapper_stub.cpp",
"${distributed_service}/dtbschedmgr/src/adapter/dnetwork_adapter.cpp",
"${distributed_service}/dtbschedmgr/src/bundle/bundle_manager_internal.cpp",
"${distributed_service}/dtbschedmgr/src/connect_death_recipient.cpp",
"${distributed_service}/dtbschedmgr/src/deviceManager/dms_device_info.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_device_node_listener.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_sched_adapter.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_sched_continuation.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_sched_dumper.cpp",
@@ -77,7 +75,6 @@ dtbschedmgr_sources = [
"${distributed_service}/dtbschedmgr/src/dms_free_install_callback_proxy.cpp",
"${distributed_service}/dtbschedmgr/src/dms_free_install_callback_stub.cpp",
"${distributed_service}/dtbschedmgr/src/dms_token_callback.cpp",
"${distributed_service}/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp",
]
if (dmsfwk_standard_mission_manager) {